Skip to content

Commit

Permalink
refactor(ngcc): update yargs and typings for yargs (#38502)
Browse files Browse the repository at this point in the history
Updating yargs and typings for the updated yargs module.

PR Close #38502
  • Loading branch information
josephperrott authored and atscott committed Aug 18, 2020
1 parent 847eaa0 commit ce448f4
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/compiler-cli/ngcc/src/command_line_options.ts
Expand Up @@ -20,24 +20,27 @@ export function parseCommandLineOptions(args: string[]): NgccOptions {
alias: 'source',
describe:
'A path (relative to the working directory) of the `node_modules` folder to process.',
default: './node_modules'
default: './node_modules',
type: 'string',
})
.option('f', {alias: 'formats', hiddentrue, array: true})
.option('f', {alias: 'formats', hiddentrue, array: true, type: 'string'})
.option('p', {
alias: 'properties',
array: true,
describe:
'An array of names of properties in package.json to compile (e.g. `module` or `main`)\n' +
'Each of these properties should hold the path to a bundle-format.\n' +
'If provided, only the specified properties are considered for processing.\n' +
'If not provided, all the supported format properties (e.g. fesm2015, fesm5, es2015, esm2015, esm5, main, module) in the package.json are considered.'
'If not provided, all the supported format properties (e.g. fesm2015, fesm5, es2015, esm2015, esm5, main, module) in the package.json are considered.',
type: 'string',
})
.option('t', {
alias: 'target',
describe:
'A relative path (from the `source` path) to a single entry-point to process (plus its dependencies).\n' +
'If this property is provided then `error-on-failed-entry-point` is forced to true.\n' +
'This option overrides the `--use-program-dependencies` option.',
type: 'string',
})
.option('use-program-dependencies', {
type: 'boolean',
Expand All @@ -48,7 +51,7 @@ export function parseCommandLineOptions(args: string[]): NgccOptions {
.option('first-only', {
describe:
'If specified then only the first matching package.json property will be compiled.',
type: 'boolean'
type: 'boolean',
})
.option('create-ivy-entry-points', {
describe:
Expand Down Expand Up @@ -79,6 +82,7 @@ export function parseCommandLineOptions(args: string[]): NgccOptions {
alias: 'loglevel',
describe: 'The lowest severity logging message that should be output.',
choices: ['debug', 'info', 'warn', 'error'],
type: 'string',
})
.option('invalidate-entry-point-manifest', {
describe:
Expand Down Expand Up @@ -106,28 +110,28 @@ export function parseCommandLineOptions(args: string[]): NgccOptions {
.help()
.parse(args);

if (options['f'] && options['f'].length) {
if (options.f?.length) {
console.error(
'The formats option (-f/--formats) has been removed. Consider the properties option (-p/--properties) instead.');
process.exit(1);
}

setFileSystem(new NodeJSFileSystem());

const baseSourcePath = resolve(options['s'] || './node_modules');
const propertiesToConsider: string[] = options['p'];
const targetEntryPointPath = options['t'] ? options['t'] : undefined;
const baseSourcePath = resolve(options.s || './node_modules');
const propertiesToConsider = options.p;
const targetEntryPointPath = options.t;
const compileAllFormats = !options['first-only'];
const createNewEntryPointFormats = options['create-ivy-entry-points'];
const logLevel = options['l'] as keyof typeof LogLevel | undefined;
const logLevel = options.l as keyof typeof LogLevel | undefined;
const enableI18nLegacyMessageIdFormat = options['legacy-message-ids'];
const invalidateEntryPointManifest = options['invalidate-entry-point-manifest'];
const errorOnFailedEntryPoint = options['error-on-failed-entry-point'];
const findEntryPointsFromTsConfigProgram = options['use-program-dependencies'];
// yargs is not so great at mixed string+boolean types, so we have to test tsconfig against a
// string "false" to capture the `tsconfig=false` option.
// And we have to convert the option to a string to handle `no-tsconfig`, which will be `false`.
const tsConfigPath = `${options['tsconfig']}` === 'false' ? null : options['tsconfig'];
const tsConfigPath = `${options.tsconfig}` === 'false' ? null : options.tsconfig;

const logger = logLevel && new ConsoleLogger(LogLevel[logLevel]);

Expand All @@ -139,7 +143,7 @@ export function parseCommandLineOptions(args: string[]): NgccOptions {
createNewEntryPointFormats,
logger,
enableI18nLegacyMessageIdFormat,
async: options['async'],
async: options.async,
invalidateEntryPointManifest,
errorOnFailedEntryPoint,
tsConfigPath,
Expand Down

0 comments on commit ce448f4

Please sign in to comment.