diff --git a/packages/@aws-cdk/toolkit/.npmignore b/packages/@aws-cdk/toolkit/.npmignore index 7a0151151d517..5a0c62cc1c01b 100644 --- a/packages/@aws-cdk/toolkit/.npmignore +++ b/packages/@aws-cdk/toolkit/.npmignore @@ -9,6 +9,7 @@ dist coverage .nyc_output *.tgz +docs # Ignore config files .eslintrc.js @@ -16,7 +17,10 @@ tsconfig.json *.tsbuildinfo junit.xml jest.config.js -bundle.mjs +build-tools + +# Ignore tests +test # Explicitly allow all required files !build-info.json @@ -24,7 +28,7 @@ bundle.mjs # !lib/api/bootstrap/bootstrap-template.yaml !*.d.ts !*.d.ts.map -!*.js +!lib/*.js !LICENSE !NOTICE !THIRD_PARTY_LICENSES diff --git a/packages/@aws-cdk/toolkit/build-tools/bundle.mjs b/packages/@aws-cdk/toolkit/build-tools/bundle.mjs new file mode 100644 index 0000000000000..1a5ffd058d9d0 --- /dev/null +++ b/packages/@aws-cdk/toolkit/build-tools/bundle.mjs @@ -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', +}); diff --git a/packages/@aws-cdk/toolkit/build-tools/package.sh b/packages/@aws-cdk/toolkit/build-tools/package.sh new file mode 100755 index 0000000000000..74b2e1d02854c --- /dev/null +++ b/packages/@aws-cdk/toolkit/build-tools/package.sh @@ -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 diff --git a/packages/@aws-cdk/toolkit/bundle.mjs b/packages/@aws-cdk/toolkit/bundle.mjs deleted file mode 100644 index c8905ded69b19..0000000000000 --- a/packages/@aws-cdk/toolkit/bundle.mjs +++ /dev/null @@ -1,44 +0,0 @@ -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))) -} - -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/ - - -let bundleCli = { - name: "bundle-aws-cdk", - setup(build) { - - // Mark all paths inside aws-cdk as internal - build.onResolve({ filter: /^aws-cdk\/lib/ }, (args) => { - return { path: require.resolve(args.path), external: false } - }); - }, -}; - -await esbuild.build({ - entryPoints: ["lib/index.ts"], - target: "node18", - platform: "node", - packages: "external", - plugins: [bundleCli], - sourcemap: true, - bundle: true, - outfile: "lib/main.js", -}); diff --git a/packages/@aws-cdk/toolkit/lib/actions/diff/index.ts b/packages/@aws-cdk/toolkit/lib/actions/diff/index.ts index 3378f31ed8232..a9a4990991945 100644 --- a/packages/@aws-cdk/toolkit/lib/actions/diff/index.ts +++ b/packages/@aws-cdk/toolkit/lib/actions/diff/index.ts @@ -34,7 +34,7 @@ export class DiffMethod { * * This will create, analyze, and subsequently delete a changeset against the CloudFormation stack. */ - public static ChangeSet(options: ChangeSetDiffOptions = {}) { + public static ChangeSet(options: ChangeSetDiffOptions = {}): DiffMethod { return new class extends DiffMethod { public override readonly options: ChangeSetDiffOptions; public constructor(opts: ChangeSetDiffOptions) { @@ -44,7 +44,7 @@ export class DiffMethod { }(options); } - public static TemplateOnly(options: CloudFormationDiffOptions = {}) { + public static TemplateOnly(options: CloudFormationDiffOptions = {}): DiffMethod { return new class extends DiffMethod { public override readonly options: CloudFormationDiffOptions; public constructor(opts: CloudFormationDiffOptions) { @@ -54,7 +54,7 @@ export class DiffMethod { }(options); } - public static LocalFile(path: string) { + public static LocalFile(path: string): DiffMethod { return new class extends DiffMethod { public override readonly options: { path: string }; public constructor(opts: { path: string }) { diff --git a/packages/@aws-cdk/toolkit/lib/api/aws-cdk.ts b/packages/@aws-cdk/toolkit/lib/api/aws-cdk.ts index 1ca477cf66cd1..dde17ebaf9375 100644 --- a/packages/@aws-cdk/toolkit/lib/api/aws-cdk.ts +++ b/packages/@aws-cdk/toolkit/lib/api/aws-cdk.ts @@ -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'; diff --git a/packages/@aws-cdk/toolkit/lib/api/cloud-assembly/private/source-builder.ts b/packages/@aws-cdk/toolkit/lib/api/cloud-assembly/private/source-builder.ts index 0f97d02e1514c..9fe3966d4c5a6 100644 --- a/packages/@aws-cdk/toolkit/lib/api/cloud-assembly/private/source-builder.ts +++ b/packages/@aws-cdk/toolkit/lib/api/cloud-assembly/private/source-builder.ts @@ -19,6 +19,9 @@ export abstract class CloudAssemblySourceBuilder { /** * Create a Cloud Assembly from a Cloud Assembly builder function. + * @param builder the builder function + * @param props additional configuration properties + * @returns the CloudAssembly source */ public async fromAssemblyBuilder( builder: AssemblyBuilder, @@ -52,9 +55,8 @@ export abstract class CloudAssemblySourceBuilder { /** * Creates a Cloud Assembly from an existing assembly directory. - * @param directory the directory of the AWS CDK app. Defaults to the current working directory. - * @param props additional configuration properties - * @returns an instance of `AwsCdkCli` + * @param directory the directory of a already produced Cloud Assembly. + * @returns the CloudAssembly source */ public async fromAssemblyDirectory(directory: string): Promise { const services: ToolkitServices = await this.toolkitServices(); @@ -78,9 +80,8 @@ export abstract class CloudAssemblySourceBuilder { } /** * Use a directory containing an AWS CDK app as source. - * @param directory the directory of the AWS CDK app. Defaults to the current working directory. * @param props additional configuration properties - * @returns an instance of `AwsCdkCli` + * @returns the CloudAssembly source */ public async fromCdkApp(app: string, props: CdkAppSourceProps = {}): Promise { const services: ToolkitServices = await this.toolkitServices(); diff --git a/packages/@aws-cdk/toolkit/lib/api/cloud-assembly/stack-assembly.ts b/packages/@aws-cdk/toolkit/lib/api/cloud-assembly/stack-assembly.ts index f2d0b1e3f0095..296e683ecac49 100644 --- a/packages/@aws-cdk/toolkit/lib/api/cloud-assembly/stack-assembly.ts +++ b/packages/@aws-cdk/toolkit/lib/api/cloud-assembly/stack-assembly.ts @@ -87,7 +87,6 @@ export class StackAssembly extends CloudAssembly implements ICloudAssemblySource /** * Select all stacks that have the validateOnSynth flag et. * - * @param assembly * @returns a `StackCollection` of all stacks that needs to be validated */ public selectStacksForValidation() { diff --git a/packages/@aws-cdk/toolkit/package.json b/packages/@aws-cdk/toolkit/package.json index fcd7a7df090e8..e8bc1c5950683 100644 --- a/packages/@aws-cdk/toolkit/package.json +++ b/packages/@aws-cdk/toolkit/package.json @@ -3,15 +3,15 @@ "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", @@ -19,17 +19,20 @@ "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 2>/dev/null /dev/null 2>/dev/null =17.1.2 < 20", nx@^19.8.6: version "19.8.6" resolved "https://registry.npmjs.org/nx/-/nx-19.8.6.tgz#979a8b6183596a69fcaa975aeb74d01c37294309" @@ -16840,6 +16929,11 @@ proxy-from-env@^1.1.0: resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== +punycode.js@^2.3.1: + version "2.3.1" + resolved "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz#6b53e56ad75588234e79f4affa90972c7dd8cdb7" + integrity sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA== + punycode@1.3.2: version "1.3.2" resolved "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" @@ -17944,7 +18038,7 @@ string-length@^4.0.1: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" -string-width@*, string-width@^1.0.1, "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3, string-width@^5.0.1, string-width@^5.1.2: +string-width@*, "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -17953,6 +18047,24 @@ string-width@*, string-width@^1.0.1, "string-width@^1.0.2 || 2 || 3 || 4", strin is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" +string-width@^1.0.1: + version "1.0.2" + resolved "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" + integrity sha512-0XsVpQLnVCXHJfyEs8tC0zpTVIr5PKKsQtkT29IwupnPTjtPmQ3xT/4yCREF9hYkV/3M3kzcUTSAZT6a6h81tw== + dependencies: + code-point-at "^1.0.0" + is-fullwidth-code-point "^1.0.0" + strip-ansi "^3.0.0" + +string-width@^5.0.1, string-width@^5.1.2: + version "5.1.2" + resolved "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" + integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== + dependencies: + eastasianwidth "^0.2.0" + emoji-regex "^9.2.2" + strip-ansi "^7.0.1" + string.prototype.trim@^1.2.9: version "1.2.9" resolved "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.9.tgz#b6fa326d72d2c78b6df02f7759c73f8f6274faa4" @@ -18016,7 +18128,7 @@ stringify-package@^1.0.1: dependencies: ansi-regex "^5.0.1" -strip-ansi@^3.0.1: +strip-ansi@^3.0.0, strip-ansi@^3.0.1: version "3.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" integrity sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg== @@ -18593,6 +18705,17 @@ typedarray@^0.0.6: resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA== +typedoc@^0.27.6: + version "0.27.6" + resolved "https://registry.npmjs.org/typedoc/-/typedoc-0.27.6.tgz#7e8d067bd5386b7908afcb12c9054a83e8bb326b" + integrity sha512-oBFRoh2Px6jFx366db0lLlihcalq/JzyCVp7Vaq1yphL/tbgx2e+bkpkCgJPunaPvPwoTOXSwasfklWHm7GfAw== + dependencies: + "@gerrit0/mini-shiki" "^1.24.0" + lunr "^2.3.9" + markdown-it "^14.1.0" + minimatch "^9.0.5" + yaml "^2.6.1" + typescript-json-schema@^0.65.1: version "0.65.1" resolved "https://registry.npmjs.org/typescript-json-schema/-/typescript-json-schema-0.65.1.tgz#24840812f69b220b75d86ed87e220b3b3345db2c" @@ -18637,10 +18760,10 @@ typescript@~5.7: resolved "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz#3169cf8c4c8a828cde53ba9ecb3d2b1d5dd67be6" integrity sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg== -uc.micro@^1.0.1, uc.micro@^1.0.5: - version "1.0.6" - resolved "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac" - integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA== +uc.micro@^2.0.0, uc.micro@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz#f8d3f7d0ec4c3dea35a7e3c8efa4cb8b45c9e7ee" + integrity sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A== uglify-js@^3.1.4: version "3.19.3" @@ -19263,6 +19386,11 @@ yaml@2.6.0: resolved "https://registry.npmjs.org/yaml/-/yaml-2.6.0.tgz#14059ad9d0b1680d0f04d3a60fe00f3a857303c3" integrity sha512-a6ae//JvKDEra2kdi1qzCyrJW/WZCgFi8ydDV+eXExl95t+5R+ijnqHJbz9tmMh8FUjx3iv2fCQ4dclAQlO2UQ== +yaml@^2.6.1: + version "2.7.0" + resolved "https://registry.npmjs.org/yaml/-/yaml-2.7.0.tgz#aef9bb617a64c937a9a748803786ad8d3ffe1e98" + integrity sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA== + yargs-parser@21.1.1, yargs-parser@^21.0.1, yargs-parser@^21.1.1: version "21.1.1" resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"