Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(toolkit): change bundling to not have a dependency on the aws-cdk package #32989

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/@aws-cdk/toolkit/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ tsconfig.json
*.tsbuildinfo
junit.xml
jest.config.js
bundle.mjs
build-tools

# Ignore tests
test

# Explicitly allow all required files
!build-info.json
!db.json.gz
# !lib/api/bootstrap/bootstrap-template.yaml
!*.d.ts
!*.d.ts.map
!*.js
!lib/*.js
!LICENSE
!NOTICE
!THIRD_PARTY_LICENSES
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/api/aws-cdk.ts'],
target: 'node18',
platform: 'node',
packages: 'external',
sourcemap: true,
bundle: true,
outfile: 'lib/api/aws-cdk.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';
14 changes: 8 additions & 6 deletions packages/@aws-cdk/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,36 @@
"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",
"docs": "typedoc lib/index.ts --excludeExternals --excludePrivate --excludeProtected --excludeInternal",
"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 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
Loading