Skip to content

Commit 6f6f7e4

Browse files
committed
fix(toolkit-lib): ToolkitError type is not exported
1 parent faa2de0 commit 6f6f7e4

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

.projenrc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ const toolkitLib = configureProject(
11761176
tmpToolkitHelpers,
11771177
'aws-cdk-lib',
11781178
'aws-sdk-client-mock',
1179+
'dts-bundle-generator',
11791180
'esbuild',
11801181
'typedoc',
11811182
],

packages/@aws-cdk/toolkit-lib/.projen/deps.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/toolkit-lib/.projen/tasks.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/toolkit-lib/build-tools/bundle.mjs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,53 @@ import { createRequire } from 'node:module';
22
import * as path from 'node:path';
33
import * as esbuild from 'esbuild';
44
import * as fs from 'fs-extra';
5+
import { generateDtsBundle } from 'dts-bundle-generator';
56

7+
// copy files
68
const require = createRequire(import.meta.url);
7-
89
const cliPackage = path.dirname(require.resolve('aws-cdk/package.json'));
9-
let copyFromCli = (from, to = undefined) => {
10+
const copyFromCli = (from, to = undefined) => {
1011
return fs.copy(path.join(cliPackage, ...from), path.join(process.cwd(), ...(to ?? from)));
1112
};
1213

14+
// declaration bundling
15+
const bundleDeclarations = async (entryPoints) => {
16+
const results = generateDtsBundle(entryPoints.map(filePath => ({
17+
filePath,
18+
output: {
19+
noBanner: true,
20+
exportReferencedTypes: false,
21+
},
22+
})), { preferredConfigPath: 'tsconfig.dev.json' });
23+
24+
const files = [];
25+
for (const [idx, declaration] of results.entries()) {
26+
const outputPath = path.format({ ...path.parse(entryPoints[idx]), base: '', ext: '.d.ts' });
27+
files.push(fs.promises.writeFile(outputPath, declaration));
28+
}
29+
30+
return Promise.all(files);
31+
}
32+
33+
1334
// This is a build script, we are fine
1435
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
1536
await Promise.all([
1637
copyFromCli(['build-info.json']),
1738
copyFromCli(['/db.json.gz']),
1839
copyFromCli(['lib', 'index_bg.wasm']),
1940
copyFromCli(['lib', 'api', 'bootstrap', 'bootstrap-template.yaml']),
20-
]);
2141

22-
// # Copy all resources that aws_cdk/generate.sh produced, and some othersCall the generator for the
23-
// cp -R $aws_cdk/lib/init-templates ./lib/
42+
// cdk init is not yet available in the toolkit-lib
43+
// copyFromCli(['lib', 'init-templates']),
44+
]);
2445

46+
// bundle entrypoints from the library packages
2547
await esbuild.build({
2648
outdir: 'lib',
2749
entryPoints: [
2850
'lib/api/aws-cdk.ts',
29-
'lib/api/shared-public.ts',
51+
'lib/api/shared-public.ts',
3052
'lib/private/util.ts',
3153
],
3254
target: 'node18',
@@ -35,3 +57,6 @@ await esbuild.build({
3557
sourcemap: true,
3658
bundle: true,
3759
});
60+
61+
// for the shared public API we also need to bundle the types
62+
await bundleDeclarations(['lib/api/shared-public.ts']);

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yarn.lock

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)