Skip to content

Commit d16482f

Browse files
authored
chore(toolkit): change bundling to not have a dependency on the aws-cdk package (#32989)
Instead use local file references. We still have it listed as a dev dependency, because we do need the cli build in the monorepo before the toolkit. Also adds a script to publish a "public" version locally ### Describe any new or updated permissions being added n/a ### Description of how you validated changes It builds and the "published" package can be used successfully ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 88fe797 commit d16482f

File tree

7 files changed

+89
-81
lines changed

7 files changed

+89
-81
lines changed

packages/@aws-cdk/toolkit/.npmignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ tsconfig.json
1717
*.tsbuildinfo
1818
junit.xml
1919
jest.config.js
20-
bundle.mjs
20+
build-tools
21+
22+
# Ignore tests
23+
test
2124

2225
# Explicitly allow all required files
2326
!build-info.json
2427
!db.json.gz
2528
# !lib/api/bootstrap/bootstrap-template.yaml
2629
!*.d.ts
2730
!*.d.ts.map
28-
!*.js
31+
!lib/*.js
2932
!LICENSE
3033
!NOTICE
3134
!THIRD_PARTY_LICENSES
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { createRequire } from 'node:module';
2+
import * as path from 'node:path';
3+
import * as esbuild from 'esbuild';
4+
import * as fs from 'fs-extra';
5+
6+
const require = createRequire(import.meta.url);
7+
8+
const cliPackage = path.dirname(require.resolve('aws-cdk/package.json'));
9+
let copyFromCli = (from, to = undefined) => {
10+
return fs.copy(path.join(cliPackage, ...from), path.join(process.cwd(), ...(to ?? from)));
11+
};
12+
13+
// This is a build script, we are fine
14+
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
15+
await Promise.all([
16+
copyFromCli(['build-info.json']),
17+
copyFromCli(['/db.json.gz']),
18+
copyFromCli(['lib', 'index_bg.wasm']),
19+
]);
20+
21+
// # Copy all resources that aws_cdk/generate.sh produced, and some othersCall the generator for the
22+
// cp -R $aws_cdk/lib/init-templates ./lib/
23+
// mkdir -p ./lib/api/bootstrap/ && cp $aws_cdk/lib/api/bootstrap/bootstrap-template.yaml ./lib/api/bootstrap/
24+
25+
await esbuild.build({
26+
entryPoints: ['lib/api/aws-cdk.ts'],
27+
target: 'node18',
28+
platform: 'node',
29+
packages: 'external',
30+
sourcemap: true,
31+
bundle: true,
32+
outfile: 'lib/api/aws-cdk.js',
33+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
version=${1:-latest}
4+
reset=0.0.0
5+
6+
# Toolkit package root
7+
cd "$(dirname $(dirname "$0"))"
8+
9+
npm pkg set dependencies.@aws-cdk/cx-api=$version
10+
npm pkg set dependencies.@aws-cdk/cloudformation-diff=$version
11+
npm pkg set dependencies.@aws-cdk/region-info=$version
12+
yarn package --private
13+
npm pkg set dependencies.@aws-cdk/cx-api=$reset
14+
npm pkg set dependencies.@aws-cdk/cloudformation-diff=$reset
15+
npm pkg set dependencies.@aws-cdk/region-info=$reset

packages/@aws-cdk/toolkit/bundle.mjs

-44
This file was deleted.
+26-27
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
/* eslint-disable import/no-extraneous-dependencies */
2-
export { DEFAULT_TOOLKIT_STACK_NAME, SdkProvider } from 'aws-cdk/lib';
3-
export type { SuccessfulDeployStackResult } from 'aws-cdk/lib';
4-
export { formatSdkLoggerContent } from 'aws-cdk/lib/api/aws-auth/sdk-logger';
5-
export { CloudAssembly, sanitizePatterns, StackCollection, ExtendedStackSelection } from 'aws-cdk/lib/api/cxapp/cloud-assembly';
6-
export { prepareDefaultEnvironment, prepareContext, spaceAvailableForContext } from 'aws-cdk/lib/api/cxapp/exec';
7-
export { Deployments } from 'aws-cdk/lib/api/deployments';
8-
export { HotswapMode } from 'aws-cdk/lib/api/hotswap/common';
9-
export { StackActivityProgress } from 'aws-cdk/lib/api/util/cloudformation/stack-activity-monitor';
10-
export { RWLock } from 'aws-cdk/lib/api/util/rwlock';
11-
export type { ILock } from 'aws-cdk/lib/api/util/rwlock';
12-
export { formatTime } from 'aws-cdk/lib/api/util/string-manipulation';
13-
export * as contextproviders from 'aws-cdk/lib/context-providers';
14-
export { ResourceMigrator } from 'aws-cdk/lib/migrator';
15-
export { obscureTemplate, serializeStructure } from 'aws-cdk/lib/serialize';
16-
export { Context, Settings, PROJECT_CONTEXT } from 'aws-cdk/lib/settings';
17-
export { tagsForStack } from 'aws-cdk/lib/tags';
18-
export { CliIoHost } from 'aws-cdk/lib/toolkit/cli-io-host';
19-
export { loadTree, some } from 'aws-cdk/lib/tree';
20-
export { splitBySize } from 'aws-cdk/lib/util';
21-
export { validateSnsTopicArn } from 'aws-cdk/lib/util/validate-notification-arn';
22-
export { WorkGraph } from 'aws-cdk/lib/util/work-graph';
23-
export type { Concurrency } from 'aws-cdk/lib/util/work-graph';
24-
export { WorkGraphBuilder } from 'aws-cdk/lib/util/work-graph-builder';
25-
export type { AssetBuildNode, AssetPublishNode, StackNode } from 'aws-cdk/lib/util/work-graph-types';
26-
export { versionNumber } from 'aws-cdk/lib/version';
27-
export { guessExecutable } from 'aws-cdk/lib/api/cxapp/exec';
1+
export { DEFAULT_TOOLKIT_STACK_NAME, SdkProvider } from '../../../../aws-cdk/lib';
2+
export type { SuccessfulDeployStackResult } from '../../../../aws-cdk/lib';
3+
export { formatSdkLoggerContent } from '../../../../aws-cdk/lib/api/aws-auth/sdk-logger';
4+
export { CloudAssembly, sanitizePatterns, StackCollection, ExtendedStackSelection } from '../../../../aws-cdk/lib/api/cxapp/cloud-assembly';
5+
export { prepareDefaultEnvironment, prepareContext, spaceAvailableForContext } from '../../../../aws-cdk/lib/api/cxapp/exec';
6+
export { Deployments } from '../../../../aws-cdk/lib/api/deployments';
7+
export { HotswapMode } from '../../../../aws-cdk/lib/api/hotswap/common';
8+
export { StackActivityProgress } from '../../../../aws-cdk/lib/api/util/cloudformation/stack-activity-monitor';
9+
export { RWLock } from '../../../../aws-cdk/lib/api/util/rwlock';
10+
export type { ILock } from '../../../../aws-cdk/lib/api/util/rwlock';
11+
export { formatTime } from '../../../../aws-cdk/lib/api/util/string-manipulation';
12+
export * as contextproviders from '../../../../aws-cdk/lib/context-providers';
13+
export { ResourceMigrator } from '../../../../aws-cdk/lib/migrator';
14+
export { obscureTemplate, serializeStructure } from '../../../../aws-cdk/lib/serialize';
15+
export { Context, Settings, PROJECT_CONTEXT } from '../../../../aws-cdk/lib/settings';
16+
export { tagsForStack } from '../../../../aws-cdk/lib/tags';
17+
export { CliIoHost } from '../../../../aws-cdk/lib/toolkit/cli-io-host';
18+
export { loadTree, some } from '../../../../aws-cdk/lib/tree';
19+
export { splitBySize } from '../../../../aws-cdk/lib/util';
20+
export { validateSnsTopicArn } from '../../../../aws-cdk/lib/util/validate-notification-arn';
21+
export { WorkGraph } from '../../../../aws-cdk/lib/util/work-graph';
22+
export type { Concurrency } from '../../../../aws-cdk/lib/util/work-graph';
23+
export { WorkGraphBuilder } from '../../../../aws-cdk/lib/util/work-graph-builder';
24+
export type { AssetBuildNode, AssetPublishNode, StackNode } from '../../../../aws-cdk/lib/util/work-graph-types';
25+
export { versionNumber } from '../../../../aws-cdk/lib/version';
26+
export { guessExecutable } from '../../../../aws-cdk/lib/api/cxapp/exec';

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,36 @@
33
"description": "AWS CDK Programmatic Toolkit Library",
44
"private": true,
55
"version": "0.0.0",
6-
"main": "./lib/main.js",
6+
"type": "commonjs",
7+
"main": "./lib/index.js",
8+
"types": "./lib/index.d.ts",
79
"exports": {
810
".": {
911
"types": "./lib/index.d.ts",
10-
"default": "./lib/main.js"
12+
"default": "./lib/index.js"
1113
}
1214
},
13-
"types": "./lib/index.d.ts",
14-
"type": "commonjs",
1515
"scripts": {
1616
"awslint": "cdk-awslint",
1717
"build": "cdk-build",
1818
"build+test": "yarn build && yarn test",
1919
"build+test+package": "yarn build+test && yarn package",
2020
"build+extract": "yarn build",
2121
"build+test+extract": "yarn build+test",
22-
"bundle": "node bundle.mjs",
22+
"bundle": "node build-tools/bundle.mjs",
2323
"docs": "typedoc lib/index.ts --excludeExternals --excludePrivate --excludeProtected --excludeInternal",
2424
"lint": "cdk-lint",
2525
"package": "cdk-package",
2626
"pkglint": "pkglint -f",
27+
"publish-local": "./build-tools/package.sh",
2728
"test": "cdk-test",
2829
"watch": "cdk-watch"
2930
},
3031
"cdk-build": {
3132
"post": [
3233
"yarn bundle",
33-
"node ./lib/main.js >/dev/null 2>/dev/null </dev/null"
34+
"node ./lib/index.js >/dev/null 2>/dev/null </dev/null",
35+
"node ./lib/api/aws-cdk.js >/dev/null 2>/dev/null </dev/null"
3436
]
3537
},
3638
"author": {

packages/@aws-cdk/toolkit/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"esModuleInterop": false,
44
"skipLibCheck": true,
55
"target": "es2022",
6-
"allowJs": true,
6+
"allowJs": false,
77
"resolveJsonModule": true,
88
"moduleDetection": "force",
99
"isolatedModules": true,
@@ -20,7 +20,7 @@
2020
"composite": true,
2121
"tsBuildInfoFile": "tsconfig.tsbuildinfo"
2222
},
23-
"include": ["**/*.ts"],
23+
"include": ["**/*.ts", "build-tools/*.mjs"],
2424
"exclude": ["node_modules", "**/*.d.ts", "dist"],
2525
"references": [
2626
{ "path": "../cx-api" },

0 commit comments

Comments
 (0)