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: expose node-bundle options via CLI #32475

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 0 deletions tools/@aws-cdk/node-bundle/src/api/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ export interface BundleProps {
* @default false
*/
readonly minifySyntax?: boolean;

/**
* Directory to write the tarball to
*
* @default '.'
*/
readonly packDestination?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not.

}

/**
Expand Down
13 changes: 9 additions & 4 deletions tools/@aws-cdk/node-bundle/src/cli-main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import * as yargs from 'yargs';
import { Bundle, BundleProps, BundleValidateOptions } from './api';
import { Bundle, BundlePackOptions, BundleProps, BundleValidateOptions } from './api';

function versionNumber(): string {
return fs.readJSONSync(path.join(__dirname, '..', 'package.json')).version;
Expand All @@ -16,6 +16,8 @@ export async function cliMain(cliArgs: string[]) {
.option('resource', { type: 'array', nargs: 1, default: [], desc: 'List of resources that need to be explicitly copied to the bundle (example: node_modules/proxy-agent/contextify.js:bin/contextify.js)' })
.option('dont-attribute', { type: 'string', desc: 'Dependencies matching this regular expressions wont be added to the notice file' })
.option('test', { type: 'string', desc: 'Validation command to sanity test the bundle after its created' })
.option('minify-whitespace', { type: 'boolean', default: false, desc: 'Minify whitespace' })
.option('pack-destination', { type: 'string', desc: 'Directory to write the tarball to', nargs: 1, requiresArg: true })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this as an option of the pack command instead of global?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I thought we weren't doing that but I should have looked better.

.command('validate', 'Validate the package is ready for bundling', args => args
.option('fix', { type: 'boolean', default: false, alias: 'f', desc: 'Fix any fixable violations' }),
)
Expand Down Expand Up @@ -76,6 +78,7 @@ export async function cliMain(cliArgs: string[]) {
resources: resources,
dontAttribute: argv['dont-attribute'],
test: argv.test,
minifyWhitespace: argv['minify-whitespace'],
};

const bundle = new Bundle(props);
Expand All @@ -91,7 +94,9 @@ export async function cliMain(cliArgs: string[]) {
write(bundle);
break;
case 'pack':
pack(bundle);
pack(bundle, {
target: argv['pack-destination'],
});
break;
default:
throw new Error(`Unknown command: ${command}`);
Expand All @@ -110,6 +115,6 @@ function validate(bundle: Bundle, options: BundleValidateOptions = {}) {
}
}

function pack(bundle: Bundle) {
bundle.pack();
function pack(bundle: Bundle, options?: BundlePackOptions) {
bundle.pack(options);
}
Loading