Skip to content

Commit

Permalink
fix(core): not parse hex to number (#27515)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #26889

(cherry picked from commit ec53f31)
  • Loading branch information
xiongemi authored and FrozenPandaz committed Aug 23, 2024
1 parent b32a571 commit be620eb
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 be620eb

Please sign in to comment.