Skip to content

Commit

Permalink
chore(toolkit): change bundling to have to formal dependency on the a…
Browse files Browse the repository at this point in the history
…ws-cdk package

instead use local file references
also adds a script to publish a "public" version locally
  • Loading branch information
mrgrain committed Jan 17, 2025
1 parent 3e1c437 commit c2c7e5b
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 81 deletions.
5 changes: 4 additions & 1 deletion packages/@aws-cdk/toolkit/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ tsconfig.json
*.tsbuildinfo
junit.xml
jest.config.js
bundle.mjs
build-tools

# Ignore tests
test

# Explicitly allow all required files
!build-info.json
Expand Down
33 changes: 33 additions & 0 deletions packages/@aws-cdk/toolkit/build-tools/bundle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createRequire } from 'node:module';
import * as path from 'node:path';
import * as esbuild from 'esbuild';
import * as fs from 'fs-extra';

const require = createRequire(import.meta.url);

const cliPackage = path.dirname(require.resolve('aws-cdk/package.json'));
let copyFromCli = (from, to = undefined) => {
return fs.copy(path.join(cliPackage, ...from), path.join(process.cwd(), ...(to ?? from)));
};

// This is a build script, we are fine
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
await Promise.all([
copyFromCli(['build-info.json']),
copyFromCli(['/db.json.gz']),
copyFromCli(['lib', 'index_bg.wasm']),
]);

// # Copy all resources that aws_cdk/generate.sh produced, and some othersCall the generator for the
// cp -R $aws_cdk/lib/init-templates ./lib/
// mkdir -p ./lib/api/bootstrap/ && cp $aws_cdk/lib/api/bootstrap/bootstrap-template.yaml ./lib/api/bootstrap/

await esbuild.build({
entryPoints: ['lib/index.ts'],
target: 'node18',
platform: 'node',
packages: 'external',
sourcemap: true,
bundle: true,
outfile: 'lib/main.js',
});
15 changes: 15 additions & 0 deletions packages/@aws-cdk/toolkit/build-tools/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

version=${1:-latest}
reset=0.0.0

# Toolkit package root
cd "$(dirname $(dirname "$0"))"

npm pkg set dependencies.@aws-cdk/cx-api=$version
npm pkg set dependencies.@aws-cdk/cloudformation-diff=$version
npm pkg set dependencies.@aws-cdk/region-info=$version
yarn package --private
npm pkg set dependencies.@aws-cdk/cx-api=$reset
npm pkg set dependencies.@aws-cdk/cloudformation-diff=$reset
npm pkg set dependencies.@aws-cdk/region-info=$reset
44 changes: 0 additions & 44 deletions packages/@aws-cdk/toolkit/bundle.mjs

This file was deleted.

53 changes: 26 additions & 27 deletions packages/@aws-cdk/toolkit/lib/api/aws-cdk.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/* eslint-disable import/no-extraneous-dependencies */
export { DEFAULT_TOOLKIT_STACK_NAME, SdkProvider } from 'aws-cdk/lib';
export type { SuccessfulDeployStackResult } from 'aws-cdk/lib';
export { formatSdkLoggerContent } from 'aws-cdk/lib/api/aws-auth/sdk-logger';
export { CloudAssembly, sanitizePatterns, StackCollection, ExtendedStackSelection } from 'aws-cdk/lib/api/cxapp/cloud-assembly';
export { prepareDefaultEnvironment, prepareContext, spaceAvailableForContext } from 'aws-cdk/lib/api/cxapp/exec';
export { Deployments } from 'aws-cdk/lib/api/deployments';
export { HotswapMode } from 'aws-cdk/lib/api/hotswap/common';
export { StackActivityProgress } from 'aws-cdk/lib/api/util/cloudformation/stack-activity-monitor';
export { RWLock } from 'aws-cdk/lib/api/util/rwlock';
export type { ILock } from 'aws-cdk/lib/api/util/rwlock';
export { formatTime } from 'aws-cdk/lib/api/util/string-manipulation';
export * as contextproviders from 'aws-cdk/lib/context-providers';
export { ResourceMigrator } from 'aws-cdk/lib/migrator';
export { obscureTemplate, serializeStructure } from 'aws-cdk/lib/serialize';
export { Context, Settings, PROJECT_CONTEXT } from 'aws-cdk/lib/settings';
export { tagsForStack } from 'aws-cdk/lib/tags';
export { CliIoHost } from 'aws-cdk/lib/toolkit/cli-io-host';
export { loadTree, some } from 'aws-cdk/lib/tree';
export { splitBySize } from 'aws-cdk/lib/util';
export { validateSnsTopicArn } from 'aws-cdk/lib/util/validate-notification-arn';
export { WorkGraph } from 'aws-cdk/lib/util/work-graph';
export type { Concurrency } from 'aws-cdk/lib/util/work-graph';
export { WorkGraphBuilder } from 'aws-cdk/lib/util/work-graph-builder';
export type { AssetBuildNode, AssetPublishNode, StackNode } from 'aws-cdk/lib/util/work-graph-types';
export { versionNumber } from 'aws-cdk/lib/version';
export { guessExecutable } from 'aws-cdk/lib/api/cxapp/exec';
export { DEFAULT_TOOLKIT_STACK_NAME, SdkProvider } from '../../../../aws-cdk/lib';
export type { SuccessfulDeployStackResult } from '../../../../aws-cdk/lib';
export { formatSdkLoggerContent } from '../../../../aws-cdk/lib/api/aws-auth/sdk-logger';
export { CloudAssembly, sanitizePatterns, StackCollection, ExtendedStackSelection } from '../../../../aws-cdk/lib/api/cxapp/cloud-assembly';
export { prepareDefaultEnvironment, prepareContext, spaceAvailableForContext } from '../../../../aws-cdk/lib/api/cxapp/exec';
export { Deployments } from '../../../../aws-cdk/lib/api/deployments';
export { HotswapMode } from '../../../../aws-cdk/lib/api/hotswap/common';
export { StackActivityProgress } from '../../../../aws-cdk/lib/api/util/cloudformation/stack-activity-monitor';
export { RWLock } from '../../../../aws-cdk/lib/api/util/rwlock';
export type { ILock } from '../../../../aws-cdk/lib/api/util/rwlock';
export { formatTime } from '../../../../aws-cdk/lib/api/util/string-manipulation';
export * as contextproviders from '../../../../aws-cdk/lib/context-providers';
export { ResourceMigrator } from '../../../../aws-cdk/lib/migrator';
export { obscureTemplate, serializeStructure } from '../../../../aws-cdk/lib/serialize';
export { Context, Settings, PROJECT_CONTEXT } from '../../../../aws-cdk/lib/settings';
export { tagsForStack } from '../../../../aws-cdk/lib/tags';
export { CliIoHost } from '../../../../aws-cdk/lib/toolkit/cli-io-host';
export { loadTree, some } from '../../../../aws-cdk/lib/tree';
export { splitBySize } from '../../../../aws-cdk/lib/util';
export { validateSnsTopicArn } from '../../../../aws-cdk/lib/util/validate-notification-arn';
export { WorkGraph } from '../../../../aws-cdk/lib/util/work-graph';
export type { Concurrency } from '../../../../aws-cdk/lib/util/work-graph';
export { WorkGraphBuilder } from '../../../../aws-cdk/lib/util/work-graph-builder';
export type { AssetBuildNode, AssetPublishNode, StackNode } from '../../../../aws-cdk/lib/util/work-graph-types';
export { versionNumber } from '../../../../aws-cdk/lib/version';
export { guessExecutable } from '../../../../aws-cdk/lib/api/cxapp/exec';
15 changes: 8 additions & 7 deletions packages/@aws-cdk/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
"description": "AWS CDK Programmatic Toolkit Library",
"private": true,
"version": "0.0.0",
"main": "./lib/main.js",
"type": "commonjs",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"default": "./lib/main.js"
"default": "./lib/index.js"
}
},
"types": "./lib/index.d.ts",
"type": "commonjs",
"scripts": {
"awslint": "cdk-awslint",
"build": "cdk-build",
"build+test": "yarn build && yarn test",
"build+test+package": "yarn build+test && yarn package",
"build+extract": "yarn build",
"build+test+extract": "yarn build+test",
"bundle": "node bundle.mjs",
"bundle": "node build-tools/bundle.mjs",
"lint": "cdk-lint",
"package": "cdk-package",
"pkglint": "pkglint -f",
"publish-local": "./build-tools/package.sh",
"test": "cdk-test",
"watch": "cdk-watch"
},
"cdk-build": {
"post": [
"yarn bundle",
"node ./lib/main.js >/dev/null 2>/dev/null </dev/null"
"node ./lib/index.js >/dev/null 2>/dev/null </dev/null",
"node ./lib/api/aws-cdk.js >/dev/null 2>/dev/null </dev/null"
]
},
"author": {
Expand All @@ -45,7 +47,6 @@
"@types/fs-extra": "^9.0.13",
"@types/jest": "^29.5.14",
"@types/node": "^18.18.14",
"aws-cdk": "0.0.0",
"aws-cdk-lib": "0.0.0",
"esbuild": "^0.24.0",
"jest": "^29.7.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/toolkit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"esModuleInterop": false,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"allowJs": false,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
Expand All @@ -20,7 +20,7 @@
"composite": true,
"tsBuildInfoFile": "tsconfig.tsbuildinfo"
},
"include": ["**/*.ts"],
"include": ["**/*.ts", "build-tools/*.mjs"],
"exclude": ["node_modules", "**/*.d.ts", "dist"],
"references": [
{ "path": "../cx-api" },
Expand Down

0 comments on commit c2c7e5b

Please sign in to comment.