Skip to content

Commit 53be4e7

Browse files
yoavsbgbaruchiro
andauthored
fix: yarn argument value identified as a package (#166)
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>
1 parent 218acc9 commit 53be4e7

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

src/content/registry/npm.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ const parsePackageString = (str) => {
2020
};
2121
};
2222

23-
const parseNpmCommand = createParseCommand(
24-
'npm',
25-
(line) => line.match(npmInstall),
26-
(word) => word.length + 1,
27-
parsePackageString
28-
);
23+
const npmOptionWithArgToIgnore = ['--network-timeout', '--network-concurrency'];
24+
25+
//npm
26+
const handleArgument = (argument, restCommandWords) => {
27+
let index = 0;
28+
index += argument.length + 1; // +1 for the space removed by split
29+
30+
if (!npmOptionWithArgToIgnore.includes(argument)) {
31+
return index;
32+
}
33+
34+
if (argument.includes('=')) return index;
35+
36+
index += restCommandWords.shift().length + 1;
37+
return index;
38+
};
39+
40+
const parseNpmCommand = createParseCommand('npm', (line) => line.match(npmInstall), handleArgument, parsePackageString);
2941

3042
// npx
3143
const parseOnlyFirstPackage = (str, argsAndPackagesWords) => {

src/content/registry/npm.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('npm', () => {
2020
'npm install -g',
2121
'`npm install node-sass`', // this is not a valid command because of the `
2222
'npm create-react-app my-app',
23+
'yarn add <yourPackage> --network-timeout 100000',
2324
])('should return empty array if no packages found', (command) => {
2425
expect(parseCommand(command)).toStrictEqual([]);
2526
});

tests/real-examples/real-examples-results.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/real-examples/real-examples.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ links:
2727
comment: ignore 'npm install -d' & find '/usr/local/bin/npm install jade'
2828
post: answer
2929
registry: npm
30+
https://stackoverflow.com/questions/51508364:
31+
comment: ignore 'yarn add <yourPackage> --network-timeout 100000'
32+
post: answer
33+
registry: npm
3034
https://stackoverflow.com/questions/12008719:
3135
comment: npm install --save
3236
post: answer

0 commit comments

Comments
 (0)