@aikidosec/safe-chain 1.0.17 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/safe-chain.js +1 -1
- package/package.json +14 -15
- package/src/packagemanager/npm/parsing/parsePackagesFromInstallArgs.js +3 -1
- package/src/packagemanager/npx/parsing/parsePackagesFromArguments.js +3 -1
- package/src/packagemanager/pnpm/createPackageManager.js +1 -0
- package/src/packagemanager/yarn/parsing/parsePackagesFromArguments.js +3 -1
- package/src/shell-integration/helpers.js +26 -2
- package/.editorconfig +0 -8
- package/eslint.config.js +0 -26
- package/src/packagemanager/npm/parsing/parseNpmInstallDryRunOutput.spec.js +0 -134
- package/src/packagemanager/npm/parsing/parsePackagesFromInstallArgs.spec.js +0 -176
- package/src/packagemanager/npx/parsing/parsePackagesFromArguments.spec.js +0 -147
- package/src/packagemanager/pnpm/parsing/parsePackagesFromArguments.spec.js +0 -138
- package/src/packagemanager/yarn/parsing/parsePackagesFromArguments.spec.js +0 -126
- package/src/scanning/index.scanCommand.spec.js +0 -180
- package/src/scanning/index.shouldScanCommand.spec.js +0 -47
- package/src/shell-integration/supported-shells/bash.spec.js +0 -199
- package/src/shell-integration/supported-shells/fish.spec.js +0 -183
- package/src/shell-integration/supported-shells/powershell.spec.js +0 -200
- package/src/shell-integration/supported-shells/windowsPowershell.spec.js +0 -200
- package/src/shell-integration/supported-shells/zsh.spec.js +0 -226
package/bin/safe-chain.js
CHANGED
|
@@ -46,7 +46,7 @@ function writeHelp() {
|
|
|
46
46
|
ui.writeInformation(
|
|
47
47
|
`- ${chalk.cyan(
|
|
48
48
|
"safe-chain setup"
|
|
49
|
-
)}: This will setup your shell to wrap safe-chain around npm, npx and
|
|
49
|
+
)}: This will setup your shell to wrap safe-chain around npm, npx, yarn, pnpm and pnpx.`
|
|
50
50
|
);
|
|
51
51
|
ui.writeInformation(
|
|
52
52
|
`- ${chalk.cyan(
|
package/package.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aikidosec/safe-chain",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"test": "node --test --experimental-test-module-mocks 'src/**/*.spec.js'",
|
|
6
6
|
"test:watch": "node --test --watch --experimental-test-module-mocks 'src/**/*.spec.js'",
|
|
7
7
|
"lint": "eslint ."
|
|
8
8
|
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/AikidoSec/safe-chain.git"
|
|
12
|
-
},
|
|
13
9
|
"bin": {
|
|
14
10
|
"aikido-npm": "bin/aikido-npm.js",
|
|
15
11
|
"aikido-npx": "bin/aikido-npx.js",
|
|
@@ -19,6 +15,14 @@
|
|
|
19
15
|
"safe-chain": "bin/safe-chain.js"
|
|
20
16
|
},
|
|
21
17
|
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"default": "./src/main.js"
|
|
21
|
+
},
|
|
22
|
+
"./scanning": {
|
|
23
|
+
"default": "./src/scanning/audit/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
22
26
|
"keywords": [],
|
|
23
27
|
"author": "Aikido Security",
|
|
24
28
|
"license": "AGPL-3.0-or-later",
|
|
@@ -31,19 +35,14 @@
|
|
|
31
35
|
"ora": "^8.2.0",
|
|
32
36
|
"semver": "^7.7.2"
|
|
33
37
|
},
|
|
34
|
-
"
|
|
35
|
-
"@eslint/js": "^9.26.0",
|
|
36
|
-
"eslint": "^9.26.0",
|
|
37
|
-
"eslint-plugin-import": "^2.31.0",
|
|
38
|
-
"globals": "^16.1.0",
|
|
39
|
-
"typescript-eslint": "^8.32.0"
|
|
40
|
-
},
|
|
41
|
-
"main": "eslint.config.js",
|
|
38
|
+
"main": "src/main.js",
|
|
42
39
|
"bugs": {
|
|
43
40
|
"url": "https://github.com/AikidoSec/safe-chain/issues"
|
|
44
41
|
},
|
|
45
42
|
"homepage": "https://github.com/AikidoSec/safe-chain#readme",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/AikidoSec/safe-chain.git",
|
|
46
|
+
"directory": "packages/safe-chain"
|
|
48
47
|
}
|
|
49
48
|
}
|
|
@@ -86,7 +86,9 @@ function parsePackagename(arg) {
|
|
|
86
86
|
const lastAtIndex = arg.lastIndexOf("@");
|
|
87
87
|
|
|
88
88
|
let name, version;
|
|
89
|
-
|
|
89
|
+
// The index of the last "@" should be greater than 0
|
|
90
|
+
// If the index is 0, it means the package name starts with "@" (eg: "@vercel/otel")
|
|
91
|
+
if (lastAtIndex > 0) {
|
|
90
92
|
name = arg.slice(0, lastAtIndex);
|
|
91
93
|
version = arg.slice(lastAtIndex + 1);
|
|
92
94
|
} else {
|
|
@@ -81,7 +81,9 @@ function parsePackagename(arg, defaultTag) {
|
|
|
81
81
|
const lastAtIndex = arg.lastIndexOf("@");
|
|
82
82
|
|
|
83
83
|
let name, version;
|
|
84
|
-
|
|
84
|
+
// The index of the last "@" should be greater than 0
|
|
85
|
+
// If the index is 0, it means the package name starts with "@" (eg: "@vercel/otel")
|
|
86
|
+
if (lastAtIndex > 0) {
|
|
85
87
|
name = arg.slice(0, lastAtIndex);
|
|
86
88
|
version = arg.slice(lastAtIndex + 1);
|
|
87
89
|
} else {
|
|
@@ -13,6 +13,7 @@ export function createPnpmPackageManager() {
|
|
|
13
13
|
matchesCommand(args, "update") ||
|
|
14
14
|
matchesCommand(args, "upgrade") ||
|
|
15
15
|
matchesCommand(args, "up") ||
|
|
16
|
+
matchesCommand(args, "install") ||
|
|
16
17
|
// dlx does not always come in the first position
|
|
17
18
|
// eg: pnpm --package=yo --package=generator-webapp dlx yo webapp
|
|
18
19
|
// documentation: https://pnpm.io/cli/dlx#--package-name
|
|
@@ -77,7 +77,9 @@ function parsePackagename(arg, defaultTag) {
|
|
|
77
77
|
const lastAtIndex = arg.lastIndexOf("@");
|
|
78
78
|
|
|
79
79
|
let name, version;
|
|
80
|
-
|
|
80
|
+
// The index of the last "@" should be greater than 0
|
|
81
|
+
// If the index is 0, it means the package name starts with "@" (eg: "@vercel/otel")
|
|
82
|
+
if (lastAtIndex > 0) {
|
|
81
83
|
name = arg.slice(0, lastAtIndex);
|
|
82
84
|
version = arg.slice(lastAtIndex + 1);
|
|
83
85
|
} else {
|
|
@@ -28,11 +28,35 @@ export function removeLinesMatchingPattern(filePath, pattern) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
31
|
-
const lines = fileContent.split(
|
|
32
|
-
const updatedLines = lines.filter((line) => !
|
|
31
|
+
const lines = fileContent.split(/[\r\n\u2028\u2029]+/);
|
|
32
|
+
const updatedLines = lines.filter((line) => !shouldRemoveLine(line, pattern));
|
|
33
33
|
fs.writeFileSync(filePath, updatedLines.join(os.EOL), "utf-8");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const maxLineLength = 100;
|
|
37
|
+
function shouldRemoveLine(line, pattern) {
|
|
38
|
+
const isPatternMatch = pattern.test(line);
|
|
39
|
+
|
|
40
|
+
if (!isPatternMatch) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (line.length > maxLineLength) {
|
|
45
|
+
// safe-chain only adds lines shorter than maxLineLength
|
|
46
|
+
// so if the line is longer, it must be from a different
|
|
47
|
+
// source and could be dangerous to remove
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (line.includes("\n") || line.includes("\r") || line.includes("\u2028") || line.includes("\u2029")) {
|
|
52
|
+
// If the line contains newlines, something has gone wrong in splitting
|
|
53
|
+
// \u2028 and \u2029 are Unicode line separator characters (line and paragraph separators)
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
36
60
|
export function addLineToFile(filePath, line) {
|
|
37
61
|
if (!fs.existsSync(filePath)) {
|
|
38
62
|
fs.writeFileSync(filePath, "", "utf-8");
|
package/.editorconfig
DELETED
package/eslint.config.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import js from "@eslint/js";
|
|
2
|
-
import { defineConfig, globalIgnores } from "@eslint/config-helpers";
|
|
3
|
-
import globals from "globals";
|
|
4
|
-
import importPlugin from "eslint-plugin-import";
|
|
5
|
-
|
|
6
|
-
export default defineConfig([
|
|
7
|
-
{
|
|
8
|
-
files: ["**/*.{js,mjs,cjs,ts}"],
|
|
9
|
-
plugins: { js },
|
|
10
|
-
extends: ["js/recommended"],
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
files: ["**/*.{js,mjs,cjs,ts}"],
|
|
14
|
-
languageOptions: { globals: globals.node },
|
|
15
|
-
},
|
|
16
|
-
importPlugin.flatConfigs.recommended,
|
|
17
|
-
{
|
|
18
|
-
files: ["**/*.{js,mjs,cjs}"],
|
|
19
|
-
languageOptions: {
|
|
20
|
-
ecmaVersion: "latest",
|
|
21
|
-
sourceType: "module",
|
|
22
|
-
},
|
|
23
|
-
rules: {},
|
|
24
|
-
},
|
|
25
|
-
globalIgnores(['test/e2e']),
|
|
26
|
-
]);
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "node:test";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import { parseDryRunOutput } from "./parseNpmInstallDryRunOutput.js";
|
|
4
|
-
|
|
5
|
-
describe("parseNpmInstallDryRunOutput", () => {
|
|
6
|
-
it("should parse added packages", () => {
|
|
7
|
-
const output = `
|
|
8
|
-
add @jest/transform 29.7.0
|
|
9
|
-
add @jest/test-result 29.7.0
|
|
10
|
-
add @jest/reporters 29.7.0
|
|
11
|
-
add @jest/console 29.7.0
|
|
12
|
-
add jest-cli 29.7.0
|
|
13
|
-
add import-local 3.2.0
|
|
14
|
-
add @jest/types 29.6.3
|
|
15
|
-
add @jest/core 29.7.0
|
|
16
|
-
add jest 29.7.0
|
|
17
|
-
|
|
18
|
-
added 267 packages in 831ms
|
|
19
|
-
|
|
20
|
-
32 packages are looking for funding
|
|
21
|
-
run \`npm fund\` for details`;
|
|
22
|
-
|
|
23
|
-
const expected = [
|
|
24
|
-
{ name: "@jest/transform", version: "29.7.0", type: "add" },
|
|
25
|
-
{ name: "@jest/test-result", version: "29.7.0", type: "add" },
|
|
26
|
-
{ name: "@jest/reporters", version: "29.7.0", type: "add" },
|
|
27
|
-
{ name: "@jest/console", version: "29.7.0", type: "add" },
|
|
28
|
-
{ name: "jest-cli", version: "29.7.0", type: "add" },
|
|
29
|
-
{ name: "import-local", version: "3.2.0", type: "add" },
|
|
30
|
-
{ name: "@jest/types", version: "29.6.3", type: "add" },
|
|
31
|
-
{ name: "@jest/core", version: "29.7.0", type: "add" },
|
|
32
|
-
{ name: "jest", version: "29.7.0", type: "add" },
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const result = parseDryRunOutput(output);
|
|
36
|
-
|
|
37
|
-
assert.deepEqual(result, expected);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("should parse removed packages", () => {
|
|
41
|
-
const output = `
|
|
42
|
-
remove react 19.1.0
|
|
43
|
-
|
|
44
|
-
removed 1 package in 115ms`;
|
|
45
|
-
|
|
46
|
-
const expected = [{ name: "react", version: "19.1.0", type: "remove" }];
|
|
47
|
-
|
|
48
|
-
const result = parseDryRunOutput(output);
|
|
49
|
-
|
|
50
|
-
assert.deepEqual(result, expected);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("should parse changed packages", () => {
|
|
54
|
-
const output = `
|
|
55
|
-
change react 19.0.0 => 19.1.0
|
|
56
|
-
|
|
57
|
-
changed 1 package in 204ms`;
|
|
58
|
-
|
|
59
|
-
const expected = [
|
|
60
|
-
{
|
|
61
|
-
name: "react",
|
|
62
|
-
version: "19.1.0",
|
|
63
|
-
oldVersion: "19.0.0",
|
|
64
|
-
type: "change",
|
|
65
|
-
},
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
const result = parseDryRunOutput(output);
|
|
69
|
-
|
|
70
|
-
assert.deepEqual(result, expected);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should parse mixed package changes", () => {
|
|
74
|
-
const output = `
|
|
75
|
-
add @jest/transform 29.7.0
|
|
76
|
-
add @jest/test-result 29.7.0
|
|
77
|
-
add @jest/reporters 29.7.0
|
|
78
|
-
add @jest/console 29.7.0
|
|
79
|
-
add jest-cli 29.7.0
|
|
80
|
-
add import-local 3.2.0
|
|
81
|
-
add @jest/types 29.6.3
|
|
82
|
-
add @jest/core 29.7.0
|
|
83
|
-
add jest 29.7.0
|
|
84
|
-
remove react 19.1.0
|
|
85
|
-
change lodash 4.17.0 => 4.18.0
|
|
86
|
-
|
|
87
|
-
removed 1 package in 115ms`;
|
|
88
|
-
|
|
89
|
-
const expected = [
|
|
90
|
-
{ name: "@jest/transform", version: "29.7.0", type: "add" },
|
|
91
|
-
{ name: "@jest/test-result", version: "29.7.0", type: "add" },
|
|
92
|
-
{ name: "@jest/reporters", version: "29.7.0", type: "add" },
|
|
93
|
-
{ name: "@jest/console", version: "29.7.0", type: "add" },
|
|
94
|
-
{ name: "jest-cli", version: "29.7.0", type: "add" },
|
|
95
|
-
{ name: "import-local", version: "3.2.0", type: "add" },
|
|
96
|
-
{ name: "@jest/types", version: "29.6.3", type: "add" },
|
|
97
|
-
{ name: "@jest/core", version: "29.7.0", type: "add" },
|
|
98
|
-
{ name: "jest", version: "29.7.0", type: "add" },
|
|
99
|
-
{ name: "react", version: "19.1.0", type: "remove" },
|
|
100
|
-
{
|
|
101
|
-
name: "lodash",
|
|
102
|
-
version: "4.18.0",
|
|
103
|
-
oldVersion: "4.17.0",
|
|
104
|
-
type: "change",
|
|
105
|
-
},
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
const result = parseDryRunOutput(output);
|
|
109
|
-
|
|
110
|
-
assert.deepEqual(result, expected);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("should work with npm v22.0.0", () => {
|
|
114
|
-
const output = `
|
|
115
|
-
add @jest/types 29.6.3
|
|
116
|
-
add @jest/core 29.7.0
|
|
117
|
-
add jest 29.7.0
|
|
118
|
-
|
|
119
|
-
added 257 packages in 791ms
|
|
120
|
-
|
|
121
|
-
44 packages are looking for funding
|
|
122
|
-
run \`npm fund\` for details`;
|
|
123
|
-
|
|
124
|
-
const expected = [
|
|
125
|
-
{ name: "@jest/types", version: "29.6.3", type: "add" },
|
|
126
|
-
{ name: "@jest/core", version: "29.7.0", type: "add" },
|
|
127
|
-
{ name: "jest", version: "29.7.0", type: "add" },
|
|
128
|
-
];
|
|
129
|
-
|
|
130
|
-
const result = parseDryRunOutput(output);
|
|
131
|
-
|
|
132
|
-
assert.deepEqual(result, expected);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "node:test";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import { parsePackagesFromInstallArgs } from "./parsePackagesFromInstallArgs.js";
|
|
4
|
-
|
|
5
|
-
describe("parsePackagesFromInstallArgs", () => {
|
|
6
|
-
it("should return an empty array for no changes", () => {
|
|
7
|
-
const args = ["install"];
|
|
8
|
-
|
|
9
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
10
|
-
|
|
11
|
-
assert.deepEqual(result, []);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("should return an array of changes for one package", () => {
|
|
15
|
-
const args = ["install", "@jest/transform@29.7.0"];
|
|
16
|
-
|
|
17
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
18
|
-
|
|
19
|
-
assert.deepEqual(result, [{ name: "@jest/transform", version: "29.7.0" }]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should return an array of changes for multiple packages", () => {
|
|
23
|
-
const args = ["install", "express@4.17.1", "lodash@4.17.21"];
|
|
24
|
-
|
|
25
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
26
|
-
|
|
27
|
-
assert.deepEqual(result, [
|
|
28
|
-
{ name: "express", version: "4.17.1" },
|
|
29
|
-
{ name: "lodash", version: "4.17.21" },
|
|
30
|
-
]);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should ignore options and return an array of changes", () => {
|
|
34
|
-
const args = [
|
|
35
|
-
"install",
|
|
36
|
-
"--save-dev",
|
|
37
|
-
"express@4.17.1",
|
|
38
|
-
"--save-exact",
|
|
39
|
-
"lodash@4.17.21",
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
43
|
-
|
|
44
|
-
assert.deepEqual(result, [
|
|
45
|
-
{ name: "express", version: "4.17.1" },
|
|
46
|
-
{ name: "lodash", version: "4.17.21" },
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should ignore options with parameters and return an array of changes", () => {
|
|
51
|
-
const args = [
|
|
52
|
-
"install",
|
|
53
|
-
"--save-dev",
|
|
54
|
-
"express@4.17.1",
|
|
55
|
-
"--loglevel",
|
|
56
|
-
"error",
|
|
57
|
-
"lodash@4.17.21",
|
|
58
|
-
];
|
|
59
|
-
|
|
60
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
61
|
-
|
|
62
|
-
assert.deepEqual(result, [
|
|
63
|
-
{ name: "express", version: "4.17.1" },
|
|
64
|
-
{ name: "lodash", version: "4.17.21" },
|
|
65
|
-
]);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("should not ignore the next argument if it is passed directly with the option", () => {
|
|
69
|
-
const args = [
|
|
70
|
-
"install",
|
|
71
|
-
"--save-dev",
|
|
72
|
-
"express@4.17.1",
|
|
73
|
-
"--loglevel=error",
|
|
74
|
-
"lodash@4.17.21",
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
78
|
-
|
|
79
|
-
assert.deepEqual(result, [
|
|
80
|
-
{ name: "express", version: "4.17.1" },
|
|
81
|
-
{ name: "lodash", version: "4.17.21" },
|
|
82
|
-
]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should set the default tag for packages", () => {
|
|
86
|
-
const args = ["install", "express", "lodash@4.17.21"];
|
|
87
|
-
|
|
88
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
89
|
-
|
|
90
|
-
assert.deepEqual(result, [
|
|
91
|
-
{ name: "express", version: "latest" },
|
|
92
|
-
{ name: "lodash", version: "4.17.21" },
|
|
93
|
-
]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should set the default tag for packages with a specific tag", () => {
|
|
97
|
-
const args = ["install", "express", "lodash@4.17.21", "--tag", "beta"];
|
|
98
|
-
|
|
99
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
100
|
-
|
|
101
|
-
assert.deepEqual(result, [
|
|
102
|
-
{ name: "express", version: "beta" },
|
|
103
|
-
{ name: "lodash", version: "4.17.21" },
|
|
104
|
-
]);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("should ignore alias", () => {
|
|
108
|
-
const args = ["install", "express@npm:express@4.17.1"];
|
|
109
|
-
|
|
110
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
111
|
-
|
|
112
|
-
assert.deepEqual(result, [{ name: "express", version: "4.17.1" }]);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("should parse version even for aliased packages", () => {
|
|
116
|
-
const args = ["install", "express@npm:express@4.17.1"];
|
|
117
|
-
|
|
118
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
119
|
-
|
|
120
|
-
assert.deepEqual(result, [{ name: "express", version: "4.17.1" }]);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should parse scoped packages", () => {
|
|
124
|
-
const args = ["install", "@scope/package@1.0.0"];
|
|
125
|
-
|
|
126
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
127
|
-
|
|
128
|
-
assert.deepEqual(result, [{ name: "@scope/package", version: "1.0.0" }]);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("should parse packages with version ranges", () => {
|
|
132
|
-
const args = ["install", "express@^4.17.1"];
|
|
133
|
-
|
|
134
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
135
|
-
|
|
136
|
-
assert.deepEqual(result, [{ name: "express", version: "^4.17.1" }]);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("should parse package folders", () => {
|
|
140
|
-
const args = ["install", "./local-package"];
|
|
141
|
-
|
|
142
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
143
|
-
|
|
144
|
-
assert.deepEqual(result, [{ name: "./local-package", version: "latest" }]);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("should parse tarballs", () => {
|
|
148
|
-
const args = ["install", "file:./local-package.tgz"];
|
|
149
|
-
|
|
150
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
151
|
-
|
|
152
|
-
assert.deepEqual(result, [
|
|
153
|
-
{ name: "file:./local-package.tgz", version: "latest" },
|
|
154
|
-
]);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("should parse tarball URLs", () => {
|
|
158
|
-
const args = ["install", "https://example.com/local-package.tgz"];
|
|
159
|
-
|
|
160
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
161
|
-
|
|
162
|
-
assert.deepEqual(result, [
|
|
163
|
-
{ name: "https://example.com/local-package.tgz", version: "latest" },
|
|
164
|
-
]);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("should parse git URLs", () => {
|
|
168
|
-
const args = ["install", "git://github.com/npm/cli.git"];
|
|
169
|
-
|
|
170
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
171
|
-
|
|
172
|
-
assert.deepEqual(result, [
|
|
173
|
-
{ name: "git://github.com/npm/cli.git", version: "latest" },
|
|
174
|
-
]);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "node:test";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import { parsePackagesFromArguments } from "./parsePackagesFromArguments.js";
|
|
4
|
-
|
|
5
|
-
describe("parsePackagesFromArguments", () => {
|
|
6
|
-
it("should return an empty array for no changes", () => {
|
|
7
|
-
const args = [];
|
|
8
|
-
|
|
9
|
-
const result = parsePackagesFromArguments(args);
|
|
10
|
-
|
|
11
|
-
assert.deepEqual(result, []);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("should return an array of changes for one package", () => {
|
|
15
|
-
const args = ["http-server@14.1.1"];
|
|
16
|
-
|
|
17
|
-
const result = parsePackagesFromArguments(args);
|
|
18
|
-
|
|
19
|
-
assert.deepEqual(result, [{ name: "http-server", version: "14.1.1" }]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should return the package with latest tag if absent", () => {
|
|
23
|
-
const args = ["http-server"];
|
|
24
|
-
|
|
25
|
-
const result = parsePackagesFromArguments(args);
|
|
26
|
-
|
|
27
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should ignore double --", () => {
|
|
31
|
-
const args = ["--", "http-server"];
|
|
32
|
-
|
|
33
|
-
const result = parsePackagesFromArguments(args);
|
|
34
|
-
|
|
35
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should only return the first package", () => {
|
|
39
|
-
const args = ["http-server", "jest"];
|
|
40
|
-
|
|
41
|
-
const result = parsePackagesFromArguments(args);
|
|
42
|
-
|
|
43
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should return package with -p option", () => {
|
|
47
|
-
const args = ["-p", "http-server"];
|
|
48
|
-
|
|
49
|
-
const result = parsePackagesFromArguments(args);
|
|
50
|
-
|
|
51
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should return package with --package option", () => {
|
|
55
|
-
const args = ["--package", "http-server"];
|
|
56
|
-
|
|
57
|
-
const result = parsePackagesFromArguments(args);
|
|
58
|
-
|
|
59
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should return package with --package=x option", () => {
|
|
63
|
-
const args = ["--package=http-server"];
|
|
64
|
-
|
|
65
|
-
const result = parsePackagesFromArguments(args);
|
|
66
|
-
|
|
67
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("should return package with --package=x@version option", () => {
|
|
71
|
-
const args = ["--package=http-server@1.0.0"];
|
|
72
|
-
|
|
73
|
-
const result = parsePackagesFromArguments(args);
|
|
74
|
-
|
|
75
|
-
assert.deepEqual(result, [{ name: "http-server", version: "1.0.0" }]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("should ignore options with parameters and return an array of changes", () => {
|
|
79
|
-
const args = ["--loglevel", "error", "http-server@14.1.1"];
|
|
80
|
-
|
|
81
|
-
const result = parsePackagesFromArguments(args);
|
|
82
|
-
|
|
83
|
-
assert.deepEqual(result, [{ name: "http-server", version: "14.1.1" }]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("should parse version even for aliased packages", () => {
|
|
87
|
-
const args = ["server@npm:http-server@14.1.1"];
|
|
88
|
-
|
|
89
|
-
const result = parsePackagesFromArguments(args);
|
|
90
|
-
|
|
91
|
-
assert.deepEqual(result, [{ name: "http-server", version: "14.1.1" }]);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("should parse scoped packages", () => {
|
|
95
|
-
const args = ["@scope/package@1.0.0"];
|
|
96
|
-
|
|
97
|
-
const result = parsePackagesFromArguments(args);
|
|
98
|
-
|
|
99
|
-
assert.deepEqual(result, [{ name: "@scope/package", version: "1.0.0" }]);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("should parse packages with version ranges", () => {
|
|
103
|
-
const args = ["http-server@^14.1.1"];
|
|
104
|
-
|
|
105
|
-
const result = parsePackagesFromArguments(args);
|
|
106
|
-
|
|
107
|
-
assert.deepEqual(result, [{ name: "http-server", version: "^14.1.1" }]);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("should parse package folders", () => {
|
|
111
|
-
const args = ["./local-package"];
|
|
112
|
-
|
|
113
|
-
const result = parsePackagesFromArguments(args);
|
|
114
|
-
|
|
115
|
-
assert.deepEqual(result, [{ name: "./local-package", version: "latest" }]);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should parse tarballs", () => {
|
|
119
|
-
const args = ["file:./local-package.tgz"];
|
|
120
|
-
|
|
121
|
-
const result = parsePackagesFromArguments(args);
|
|
122
|
-
|
|
123
|
-
assert.deepEqual(result, [
|
|
124
|
-
{ name: "file:./local-package.tgz", version: "latest" },
|
|
125
|
-
]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("should parse tarball URLs", () => {
|
|
129
|
-
const args = ["https://example.com/local-package.tgz"];
|
|
130
|
-
|
|
131
|
-
const result = parsePackagesFromArguments(args);
|
|
132
|
-
|
|
133
|
-
assert.deepEqual(result, [
|
|
134
|
-
{ name: "https://example.com/local-package.tgz", version: "latest" },
|
|
135
|
-
]);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("should parse git URLs", () => {
|
|
139
|
-
const args = ["git://github.com/http-party/http-server"];
|
|
140
|
-
|
|
141
|
-
const result = parsePackagesFromArguments(args);
|
|
142
|
-
|
|
143
|
-
assert.deepEqual(result, [
|
|
144
|
-
{ name: "git://github.com/http-party/http-server", version: "latest" },
|
|
145
|
-
]);
|
|
146
|
-
});
|
|
147
|
-
});
|