Skip to content

Commit

Permalink
fix(core): fix not parse hex to number
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Aug 23, 2024
1 parent add4183 commit a57da5e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 16 deletions.
80 changes: 80 additions & 0 deletions packages/nx/src/command-line/yargs-utils/shared-options.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as yargs from 'yargs';

import { withAffectedOptions, withRunManyOptions } from './shared-options';

const argv = yargs.default([]);

describe('shared-options', () => {
describe('withAffectedOptions', () => {
const command = withAffectedOptions(argv);

it('should parse files to array', () => {
const result = command.parseSync([
'affected',
'--files',
'file1',
'--files',
'file2',
'--tag',
'81919e4',
'--parallel',
'3',
'--maxParallel',
'2',
]);
expect(result).toEqual(
expect.objectContaining({
_: ['affected', '--tag', '81919e4'],
files: ['file1', 'file2'],
parallel: '3',
maxParallel: 2,
})
);
});

it('should parse head and base', () => {
const result = command.parseSync([
'affected',
'--head',
'head',
'--base',
'base',
]);
expect(result).toEqual(
expect.objectContaining({
_: ['affected'],
head: 'head',
base: 'base',
})
);
});
});

describe('withRunManyOptions', () => {
const command = withRunManyOptions(argv);

it('should parse projects to array', () => {
const result = command.parseSync([
'run-many',
'--projects',
'project1',
'--projects',
'project2',
'--tag',
'81919e4',
'--parallel',
'3',
'--maxParallel',
'2',
]);
expect(result).toEqual(
expect.objectContaining({
_: ['run-many', '--tag', '81919e4'],
projects: ['project1', 'project2'],
parallel: '3',
maxParallel: 2,
})
);
});
});
});
29 changes: 13 additions & 16 deletions packages/nx/src/command-line/yargs-utils/shared-options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { Argv } from 'yargs';
import { Argv, ParserConfigurationOptions } from 'yargs';

interface ExcludeOptions {
exclude: string[];
}

export const defaultYargsParserConfiguration: Partial<ParserConfigurationOptions> =
{
'strip-dashed': true,
'unknown-options-as-args': true,
'populate--': true,
'parse-numbers': false,
'parse-positional-numbers': false,
};

export function withExcludeOption(yargs: Argv): Argv<ExcludeOptions> {
return yargs.option('exclude', {
describe: 'Exclude certain projects from being processed',
Expand Down Expand Up @@ -151,11 +160,7 @@ export function withBatch(yargs: Argv) {

export function withAffectedOptions(yargs: Argv) {
return withExcludeOption(yargs)
.parserConfiguration({
'strip-dashed': true,
'unknown-options-as-args': true,
'populate--': true,
})
.parserConfiguration(defaultYargsParserConfiguration)
.option('files', {
describe:
'Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces',
Expand Down Expand Up @@ -210,11 +215,7 @@ export function withRunManyOptions<T>(
yargs: Argv<T>
): Argv<T & RunManyOptions> {
return withRunOptions(yargs)
.parserConfiguration({
'strip-dashed': true,
'unknown-options-as-args': true,
'populate--': true,
})
.parserConfiguration(defaultYargsParserConfiguration)
.option('projects', {
type: 'string',
alias: 'p',
Expand Down Expand Up @@ -287,11 +288,7 @@ export function withRunOneOptions(yargs: Argv) {
const res = withRunOptions(
withOutputStyleOption(withConfiguration(yargs), allOutputStyles)
)
.parserConfiguration({
'strip-dashed': true,
'unknown-options-as-args': true,
'populate--': true,
})
.parserConfiguration(defaultYargsParserConfiguration)
.option('project', {
describe: 'Target project',
type: 'string',
Expand Down

0 comments on commit a57da5e

Please sign in to comment.