Skip to content

Commit

Permalink
fix: yarn argument value identified as a package (#166)
Browse files Browse the repository at this point in the history
Fixes #156

In case of Number, handle it as Argument and skip this word.
After the fix:
![Screen Shot 2024-02-18 at 21 42
13](https://github.com/os-scar/overlay/assets/6542413/02c26ac7-62d4-4ba0-886b-3a3b1ec0df6b)

---------

Co-authored-by: Baruch Odem (Rothkoff) <baruchiro@gmail.com>
  • Loading branch information
yoavsbg and baruchiro committed Feb 21, 2024
1 parent 218acc9 commit 53be4e7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
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
https://stackoverflow.com/questions/12008719:
comment: npm install --save
post: answer
Expand Down

0 comments on commit 53be4e7

Please sign in to comment.