Skip to content

Commit 94102c1

Browse files
authored
fix(cli): only load sourcemap when --debug flag is enabled (#23752)
Loading the sourcemap file is prohibitively slow. We don't need to do this unless we actually want to debug things. ```console # with inline sourcemap $ time cdk --help cdk --help 6.32s user 1.66s system 106% cpu 7.510 total # with linked sourcemap $ time cdk --help ./bin/cdk --help 4.01s user 0.38s system 113% cpu 3.872 total # without sourcemap $ time cdk --help ./bin/cdk --help 0.65s user 0.12s system 91% cpu 0.839 total ``` Sourcemap support can be tested by running an unknown command: ```console $ cdk unknown -v [12:05:46] Error: Unknown command: unknown at main (/abc/node_modules/aws-cdk/lib/cli.ts:628:15) at exec4 (/abc/node_modules/aws-cdk/lib/cli.ts:384:18) ``` ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a914fc0 commit 94102c1

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

packages/aws-cdk/lib/api/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'source-map-support/register';
2-
31
export * from './aws-auth/credentials';
42
export * from './bootstrap';
53
export * from './deploy-stack';

packages/aws-cdk/lib/cli.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import 'source-map-support/register';
21
import * as cxapi from '@aws-cdk/cx-api';
32
import '@jsii/check-node/run';
43
import * as chalk from 'chalk';
4+
import { install as enableSourceMapSupport } from 'source-map-support';
55

66
import type { Argv } from 'yargs';
77
import { SdkProvider } from '../lib/api/aws-auth';
@@ -285,6 +285,11 @@ if (!process.stdout.isTTY) {
285285

286286
export async function exec(args: string[], synthesizer?: Synthesizer): Promise<number | void> {
287287
const argv = await parseCommandLineArguments(args);
288+
289+
if (argv.debug) {
290+
enableSourceMapSupport();
291+
}
292+
288293
if (argv.verbose) {
289294
setLogLevel(argv.verbose);
290295

packages/aws-cdk/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"test": "bin/cdk --version",
5050
"entryPoints": [
5151
"lib/index.js"
52-
]
52+
],
53+
"sourcemap": "linked"
5354
}
5455
},
5556
"author": {
@@ -71,6 +72,7 @@
7172
"@types/promptly": "^3.0.2",
7273
"@types/semver": "^7.3.13",
7374
"@types/sinon": "^9.0.11",
75+
"@types/source-map-support": "^0.5.6",
7476
"@types/table": "^6.0.0",
7577
"@types/uuid": "^8.3.4",
7678
"@types/wrap-ansi": "^3.0.0",

tools/@aws-cdk/node-bundle/src/api/bundle.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ export interface BundleProps {
7373
* @default - no check.
7474
*/
7575
readonly test?: string;
76+
77+
/**
78+
* Basic sanity check to run against the created bundle.
79+
*
80+
* @default "inline"
81+
*/
82+
readonly sourcemap?: 'linked' | 'inline' | 'external' | 'both';
7683
}
7784

7885
/**
@@ -148,6 +155,7 @@ export class Bundle {
148155
private readonly allowedLicenses: string[];
149156
private readonly dontAttribute?: string;
150157
private readonly test?: string;
158+
private readonly sourcemap?: 'linked' | 'inline' | 'external' | 'both';
151159

152160
private _bundle?: esbuild.BuildResult;
153161
private _dependencies?: Package[];
@@ -165,6 +173,7 @@ export class Bundle {
165173
this.allowedLicenses = props.allowedLicenses ?? DEFAULT_ALLOWED_LICENSES;
166174
this.dontAttribute = props.dontAttribute;
167175
this.entryPoints = {};
176+
this.sourcemap = props.sourcemap;
168177

169178
const entryPoints = props.entryPoints ?? (this.manifest.main ? [this.manifest.main] : []);
170179

@@ -394,7 +403,7 @@ export class Bundle {
394403
bundle: true,
395404
target: 'node14',
396405
platform: 'node',
397-
sourcemap: 'inline',
406+
sourcemap: this.sourcemap ?? 'inline',
398407
metafile: true,
399408
treeShaking: true,
400409
absWorkingDir: this.packageDir,

yarn.lock

+7
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,13 @@
22602260
resolved "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz#bf2e02a3dbd4aecaf95942ecd99b7402e03fad5e"
22612261
integrity sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA==
22622262

2263+
"@types/source-map-support@^0.5.6":
2264+
version "0.5.6"
2265+
resolved "https://registry.npmjs.org/@types/source-map-support/-/source-map-support-0.5.6.tgz#aa4a8c98ec73a1f1f30a813573a9b2154a6eb39a"
2266+
integrity sha512-b2nJ9YyXmkhGaa2b8VLM0kJ04xxwNyijcq12/kDoomCt43qbHBeK2SLNJ9iJmETaAj+bKUT05PQUu3Q66GvLhQ==
2267+
dependencies:
2268+
source-map "^0.6.0"
2269+
22632270
"@types/stack-utils@^2.0.0":
22642271
version "2.0.1"
22652272
resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c"

0 commit comments

Comments
 (0)