From b00de76efd5efb0214bf05227bf5c9e515a0c842 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Tue, 24 Dec 2024 23:20:23 +0100 Subject: [PATCH] chore(cdk-build-tools): allow packing of private packages for local testing (#32644) ### Reason for this change Sometimes there is a need to pack a private package so it can be tested as a package locally. For example when a package is not released during development. Previously it was not possible to pack a private package with our tooling. ### Description of changes Adds a `--private` flag to the `cdk-package` command to allow force packing of private packages. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes Manually used the new flag to pack a private package. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- tools/@aws-cdk/cdk-build-tools/bin/cdk-package.ts | 6 ++++-- tools/@aws-cdk/cdk-build-tools/lib/package-info.ts | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/@aws-cdk/cdk-build-tools/bin/cdk-package.ts b/tools/@aws-cdk/cdk-build-tools/bin/cdk-package.ts index bc48546f91787..66ae1264f4265 100644 --- a/tools/@aws-cdk/cdk-build-tools/bin/cdk-package.ts +++ b/tools/@aws-cdk/cdk-build-tools/bin/cdk-package.ts @@ -24,6 +24,7 @@ async function main() { }) .option('pre-only', { type: 'boolean', default: false, desc: 'run pre package steps only' }) .option('post-only', { type: 'boolean', default: false, desc: 'run post package steps only' }) + .option('private', { type: 'boolean', default: false, desc: 'Also package private packages for local usage' }) .argv; if (args['pre-only'] && args['post-only']) { @@ -43,8 +44,9 @@ async function main() { const outdir = 'dist'; // if this is a private module, don't package - if (isPrivate()) { - process.stdout.write('No packaging for private modules.\n'); + const packPrivate = args.private || options.private; + if (isPrivate() && !packPrivate) { + process.stdout.write('No packaging for private modules.\nUse --private to force packing private packages for local testing.\n'); return; } diff --git a/tools/@aws-cdk/cdk-build-tools/lib/package-info.ts b/tools/@aws-cdk/cdk-build-tools/lib/package-info.ts index 9657930be27d7..6687cfb497f67 100644 --- a/tools/@aws-cdk/cdk-build-tools/lib/package-info.ts +++ b/tools/@aws-cdk/cdk-build-tools/lib/package-info.ts @@ -205,6 +205,12 @@ export interface CDKPackageOptions { * Should this package be bundled. (and if so, how) */ bundle?: Omit; + + /** + * Also package private packages for local usage. + * @default false + */ + private?: boolean; } /**