Skip to content

Commit a48d3db

Browse files
authored
refactor: move util into shared library (#183)
Mostly moving and import updates. Renamed a couple of functions. Added some more AI generated test cases for utils. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 806d851 commit a48d3db

File tree

86 files changed

+560
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+560
-138
lines changed

.projenrc.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,18 @@ const tmpToolkitHelpers = configureProject(
688688
parent: repo,
689689
name: '@aws-cdk/tmp-toolkit-helpers',
690690
description: 'A temporary package to hold code shared between aws-cdk and @aws-cdk/toolkit-lib',
691-
deps: [],
692691
devDeps: [
693692
cdkBuildTools,
693+
'@types/archiver',
694+
'@types/glob',
695+
'@types/semver',
696+
'fast-check',
697+
],
698+
deps: [
699+
'archiver',
700+
'glob',
701+
'semver',
702+
'yaml@^1',
694703
],
695704
tsconfig: {
696705
compilerOptions: {
@@ -708,6 +717,7 @@ tmpToolkitHelpers.package.addField('exports', {
708717
'.': './lib/index.js',
709718
'./package.json': './package.json',
710719
'./api': './lib/api/index.js',
720+
'./util': './lib/util/index.js',
711721
});
712722

713723
//////////////////////////////////////////////////////////////////////
@@ -1245,6 +1255,8 @@ toolkitLib.postCompileTask.exec('node build-tools/bundle.mjs');
12451255
// Smoke test built JS files
12461256
toolkitLib.postCompileTask.exec('node ./lib/index.js >/dev/null 2>/dev/null </dev/null');
12471257
toolkitLib.postCompileTask.exec('node ./lib/api/aws-cdk.js >/dev/null 2>/dev/null </dev/null');
1258+
toolkitLib.postCompileTask.exec('node ./lib/api/shared-public.js >/dev/null 2>/dev/null </dev/null');
1259+
toolkitLib.postCompileTask.exec('node ./lib/private/util.js >/dev/null 2>/dev/null </dev/null');
12481260

12491261
// Do include all .ts files inside init-templates
12501262
toolkitLib.npmignore?.addPatterns(

packages/@aws-cdk/tmp-toolkit-helpers/.projen/deps.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/tmp-toolkit-helpers/.projen/tasks.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/tmp-toolkit-helpers/package.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './api';
2+
export * from './util';
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as fs from 'fs';
22
import * as os from 'os';
33
import * as path from 'path';
4-
import { ToolkitError } from '../toolkit/error';
54

65
/**
76
* Return a location that will be used as the CDK home directory.
@@ -35,31 +34,3 @@ export function cdkHomeDir() {
3534
export function cdkCacheDir() {
3635
return path.join(cdkHomeDir(), 'cache');
3736
}
38-
39-
/**
40-
* From the current file, find the directory that contains the CLI's package.json
41-
*
42-
* Can't use `__dirname` in production code, as the CLI will get bundled as it's
43-
* released and `__dirname` will refer to a different location in the `.ts` form
44-
* as it will in the final executing form.
45-
*/
46-
export function rootDir(): string;
47-
export function rootDir(fail: true): string;
48-
export function rootDir(fail: false): string | undefined;
49-
export function rootDir(fail?: boolean) {
50-
function _rootDir(dirname: string): string | undefined {
51-
const manifestPath = path.join(dirname, 'package.json');
52-
if (fs.existsSync(manifestPath)) {
53-
return dirname;
54-
}
55-
if (path.dirname(dirname) === dirname) {
56-
if (fail ?? true) {
57-
throw new ToolkitError('Unable to find package manifest');
58-
}
59-
return undefined;
60-
}
61-
return _rootDir(path.dirname(dirname));
62-
}
63-
64-
return _rootDir(__dirname);
65-
}

packages/aws-cdk/lib/util/index.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/util/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export * from './bool';
44
export * from './bytes';
55
export * from './cloudformation';
66
export * from './content-hash';
7+
export * from './directories';
78
export * from './format-error';
9+
export * from './json';
810
export * from './objects';
911
export * from './parallel';
1012
export * from './serialize';

packages/aws-cdk/lib/util/objects.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/util/objects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isArray, isObject, Obj } from './types';
2-
import { ToolkitError } from '../toolkit/error';
2+
import { ToolkitError } from '../api/toolkit-error';
33

44
/**
55
* Return a new object by adding missing keys into another object

packages/aws-cdk/lib/util/serialize.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/util/serialize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-extra';
1+
import * as fs from 'fs/promises';
22
import { formatBytes } from './bytes';
33
import * as yaml_cfn from './yaml-cfn';
44

packages/aws-cdk/lib/util/type-brands.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/util/type-brands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type Branded<T, B> = T & Brand<B>;
3737
* values which are branded by construction (really just an elaborate
3838
* way to write 'as').
3939
*/
40+
/* c8 ignore next 3 */
4041
export function createBranded<A extends Branded<any, any>>(value: TypeUnderlyingBrand<A>): A {
4142
return value as A;
4243
}

packages/aws-cdk/lib/util/version-range.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/util/version-range.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as semver from 'semver';
2-
import { ToolkitError } from '../toolkit/error';
2+
import { ToolkitError } from '../api/toolkit-error';
33

44
// bracket - https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm#MAVEN401
55
// pep - https://www.python.org/dev/peps/pep-0440/#version-specifiers
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function sleep(ms: number) {
2+
return new Promise((ok) => setTimeout(ok, ms));
3+
}

0 commit comments

Comments
 (0)