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

fix: yarn argument value identified as a package #166

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 18 additions & 6 deletions src/content/registry/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@ const parsePackageString = (str) => {
};
};

const parseNpmCommand = createParseCommand(
'npm',
(line) => line.match(npmInstall),
(word) => word.length + 1,
parsePackageString
);
const npmOptionWithArgToIgnore = ['--network-timeout', '--network-concurrency'];

//npm
const handleArgument = (argument, restCommandWords) => {
let index = 0;
index += argument.length + 1; // +1 for the space removed by split

if (!npmOptionWithArgToIgnore.includes(argument)) {
return index;
}

if (argument.includes('=')) return index;

index += restCommandWords.shift().length + 1;
return index;
};

const parseNpmCommand = createParseCommand('npm', (line) => line.match(npmInstall), handleArgument, parsePackageString);

// npx
const parseOnlyFirstPackage = (str, argsAndPackagesWords) => {
Expand Down
1 change: 1 addition & 0 deletions src/content/registry/npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('npm', () => {
'npm install -g',
'`npm install node-sass`', // this is not a valid command because of the `
'npm create-react-app my-app',
'yarn add <yourPackage> --network-timeout 100000',
])('should return empty array if no packages found', (command) => {
expect(parseCommand(command)).toStrictEqual([]);
});
Expand Down
10 changes: 10 additions & 0 deletions tests/real-examples/real-examples-results.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/real-examples/real-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ links:
comment: ignore 'npm install -d' & find '/usr/local/bin/npm install jade'
post: answer
registry: npm
https://stackoverflow.com/questions/51508364:
comment: ignore 'yarn add <yourPackage> --network-timeout 100000'
post: answer
registry: npm
yoavsbg marked this conversation as resolved.
Show resolved Hide resolved
https://stackoverflow.com/questions/12008719:
comment: npm install --save
post: answer
Expand Down
Loading