@aikidosec/safe-chain 1.0.18 → 1.0.20
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/pnpm/createPackageManager.js +2 -0
- package/src/shell-integration/supported-shells/bash.js +49 -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 -184
- package/src/packagemanager/npx/parsing/parsePackagesFromArguments.spec.js +0 -155
- package/src/packagemanager/pnpm/parsing/parsePackagesFromArguments.spec.js +0 -146
- package/src/packagemanager/yarn/parsing/parsePackagesFromArguments.spec.js +0 -134
- package/src/scanning/index.scanCommand.spec.js +0 -180
- package/src/scanning/index.shouldScanCommand.spec.js +0 -47
- package/src/shell-integration/helpers.spec.js +0 -113
- 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.20",
|
|
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
|
}
|
|
@@ -13,6 +13,8 @@ export function createPnpmPackageManager() {
|
|
|
13
13
|
matchesCommand(args, "update") ||
|
|
14
14
|
matchesCommand(args, "upgrade") ||
|
|
15
15
|
matchesCommand(args, "up") ||
|
|
16
|
+
matchesCommand(args, "install") ||
|
|
17
|
+
matchesCommand(args, "i") ||
|
|
16
18
|
// dlx does not always come in the first position
|
|
17
19
|
// eg: pnpm --package=yo --package=generator-webapp dlx yo webapp
|
|
18
20
|
// documentation: https://pnpm.io/cli/dlx#--package-name
|
|
@@ -3,7 +3,8 @@ import {
|
|
|
3
3
|
doesExecutableExistOnSystem,
|
|
4
4
|
removeLinesMatchingPattern,
|
|
5
5
|
} from "../helpers.js";
|
|
6
|
-
import { execSync } from "child_process";
|
|
6
|
+
import { execSync, spawnSync } from "child_process";
|
|
7
|
+
import * as os from "os";
|
|
7
8
|
|
|
8
9
|
const shellName = "Bash";
|
|
9
10
|
const executableName = "bash";
|
|
@@ -43,10 +44,12 @@ function setup() {
|
|
|
43
44
|
|
|
44
45
|
function getStartupFile() {
|
|
45
46
|
try {
|
|
46
|
-
|
|
47
|
+
var path = execSync(startupFileCommand, {
|
|
47
48
|
encoding: "utf8",
|
|
48
49
|
shell: executableName,
|
|
49
50
|
}).trim();
|
|
51
|
+
|
|
52
|
+
return windowsFixPath(path);
|
|
50
53
|
} catch (error) {
|
|
51
54
|
throw new Error(
|
|
52
55
|
`Command failed: ${startupFileCommand}. Error: ${error.message}`
|
|
@@ -54,6 +57,50 @@ function getStartupFile() {
|
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
function windowsFixPath(path) {
|
|
61
|
+
try {
|
|
62
|
+
if (os.platform() !== "win32") {
|
|
63
|
+
return path;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// On windows cygwin bash, paths are returned in format /c/user/..., but we need it in format C:\user\...
|
|
67
|
+
// To convert, the cygpath -w command can be used to convert to the desired format.
|
|
68
|
+
// Cygpath only exists on Cygwin, so we first check if the command is available.
|
|
69
|
+
// If it is, we use it to convert the path.
|
|
70
|
+
if (hasCygpath()) {
|
|
71
|
+
return cygpathw(path);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return path;
|
|
75
|
+
} catch {
|
|
76
|
+
return path;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function hasCygpath() {
|
|
81
|
+
try {
|
|
82
|
+
var result = spawnSync("where", ["cygpath"], { shell: executableName });
|
|
83
|
+
return result.status === 0;
|
|
84
|
+
} catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function cygpathw(path) {
|
|
90
|
+
try {
|
|
91
|
+
var result = spawnSync("cygpath", ["-w", path], {
|
|
92
|
+
encoding: "utf8",
|
|
93
|
+
shell: executableName,
|
|
94
|
+
});
|
|
95
|
+
if (result.status === 0) {
|
|
96
|
+
return result.stdout.trim();
|
|
97
|
+
}
|
|
98
|
+
return path;
|
|
99
|
+
} catch {
|
|
100
|
+
return path;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
57
104
|
export default {
|
|
58
105
|
name: shellName,
|
|
59
106
|
isInstalled,
|
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,184 +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 the package in the format @vercel/otel", () => {
|
|
23
|
-
const args = ["install", "@vercel/otel"];
|
|
24
|
-
|
|
25
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
26
|
-
|
|
27
|
-
assert.deepEqual(result, [{ name: "@vercel/otel", version: "latest" }]);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should return an array of changes for multiple packages", () => {
|
|
31
|
-
const args = ["install", "express@4.17.1", "lodash@4.17.21"];
|
|
32
|
-
|
|
33
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
34
|
-
|
|
35
|
-
assert.deepEqual(result, [
|
|
36
|
-
{ name: "express", version: "4.17.1" },
|
|
37
|
-
{ name: "lodash", version: "4.17.21" },
|
|
38
|
-
]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("should ignore options and return an array of changes", () => {
|
|
42
|
-
const args = [
|
|
43
|
-
"install",
|
|
44
|
-
"--save-dev",
|
|
45
|
-
"express@4.17.1",
|
|
46
|
-
"--save-exact",
|
|
47
|
-
"lodash@4.17.21",
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
51
|
-
|
|
52
|
-
assert.deepEqual(result, [
|
|
53
|
-
{ name: "express", version: "4.17.1" },
|
|
54
|
-
{ name: "lodash", version: "4.17.21" },
|
|
55
|
-
]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should ignore options with parameters and return an array of changes", () => {
|
|
59
|
-
const args = [
|
|
60
|
-
"install",
|
|
61
|
-
"--save-dev",
|
|
62
|
-
"express@4.17.1",
|
|
63
|
-
"--loglevel",
|
|
64
|
-
"error",
|
|
65
|
-
"lodash@4.17.21",
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
69
|
-
|
|
70
|
-
assert.deepEqual(result, [
|
|
71
|
-
{ name: "express", version: "4.17.1" },
|
|
72
|
-
{ name: "lodash", version: "4.17.21" },
|
|
73
|
-
]);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("should not ignore the next argument if it is passed directly with the option", () => {
|
|
77
|
-
const args = [
|
|
78
|
-
"install",
|
|
79
|
-
"--save-dev",
|
|
80
|
-
"express@4.17.1",
|
|
81
|
-
"--loglevel=error",
|
|
82
|
-
"lodash@4.17.21",
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
86
|
-
|
|
87
|
-
assert.deepEqual(result, [
|
|
88
|
-
{ name: "express", version: "4.17.1" },
|
|
89
|
-
{ name: "lodash", version: "4.17.21" },
|
|
90
|
-
]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("should set the default tag for packages", () => {
|
|
94
|
-
const args = ["install", "express", "lodash@4.17.21"];
|
|
95
|
-
|
|
96
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
97
|
-
|
|
98
|
-
assert.deepEqual(result, [
|
|
99
|
-
{ name: "express", version: "latest" },
|
|
100
|
-
{ name: "lodash", version: "4.17.21" },
|
|
101
|
-
]);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("should set the default tag for packages with a specific tag", () => {
|
|
105
|
-
const args = ["install", "express", "lodash@4.17.21", "--tag", "beta"];
|
|
106
|
-
|
|
107
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
108
|
-
|
|
109
|
-
assert.deepEqual(result, [
|
|
110
|
-
{ name: "express", version: "beta" },
|
|
111
|
-
{ name: "lodash", version: "4.17.21" },
|
|
112
|
-
]);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("should ignore alias", () => {
|
|
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 version even for aliased packages", () => {
|
|
124
|
-
const args = ["install", "express@npm:express@4.17.1"];
|
|
125
|
-
|
|
126
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
127
|
-
|
|
128
|
-
assert.deepEqual(result, [{ name: "express", version: "4.17.1" }]);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("should parse scoped packages", () => {
|
|
132
|
-
const args = ["install", "@scope/package@1.0.0"];
|
|
133
|
-
|
|
134
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
135
|
-
|
|
136
|
-
assert.deepEqual(result, [{ name: "@scope/package", version: "1.0.0" }]);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("should parse packages with version ranges", () => {
|
|
140
|
-
const args = ["install", "express@^4.17.1"];
|
|
141
|
-
|
|
142
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
143
|
-
|
|
144
|
-
assert.deepEqual(result, [{ name: "express", version: "^4.17.1" }]);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("should parse package folders", () => {
|
|
148
|
-
const args = ["install", "./local-package"];
|
|
149
|
-
|
|
150
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
151
|
-
|
|
152
|
-
assert.deepEqual(result, [{ name: "./local-package", version: "latest" }]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("should parse tarballs", () => {
|
|
156
|
-
const args = ["install", "file:./local-package.tgz"];
|
|
157
|
-
|
|
158
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
159
|
-
|
|
160
|
-
assert.deepEqual(result, [
|
|
161
|
-
{ name: "file:./local-package.tgz", version: "latest" },
|
|
162
|
-
]);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should parse tarball URLs", () => {
|
|
166
|
-
const args = ["install", "https://example.com/local-package.tgz"];
|
|
167
|
-
|
|
168
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
169
|
-
|
|
170
|
-
assert.deepEqual(result, [
|
|
171
|
-
{ name: "https://example.com/local-package.tgz", version: "latest" },
|
|
172
|
-
]);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("should parse git URLs", () => {
|
|
176
|
-
const args = ["install", "git://github.com/npm/cli.git"];
|
|
177
|
-
|
|
178
|
-
const result = parsePackagesFromInstallArgs(args);
|
|
179
|
-
|
|
180
|
-
assert.deepEqual(result, [
|
|
181
|
-
{ name: "git://github.com/npm/cli.git", version: "latest" },
|
|
182
|
-
]);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
@@ -1,155 +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 in the format @vercel/otel", () => {
|
|
23
|
-
const args = ["@vercel/otel"];
|
|
24
|
-
|
|
25
|
-
const result = parsePackagesFromArguments(args);
|
|
26
|
-
|
|
27
|
-
assert.deepEqual(result, [{ name: "@vercel/otel", version: "latest" }]);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should return the package with latest tag if absent", () => {
|
|
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 ignore double --", () => {
|
|
39
|
-
const args = ["--", "http-server"];
|
|
40
|
-
|
|
41
|
-
const result = parsePackagesFromArguments(args);
|
|
42
|
-
|
|
43
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should only return the first package", () => {
|
|
47
|
-
const args = ["http-server", "jest"];
|
|
48
|
-
|
|
49
|
-
const result = parsePackagesFromArguments(args);
|
|
50
|
-
|
|
51
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should return package with -p option", () => {
|
|
55
|
-
const args = ["-p", "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 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 option", () => {
|
|
71
|
-
const args = ["--package=http-server"];
|
|
72
|
-
|
|
73
|
-
const result = parsePackagesFromArguments(args);
|
|
74
|
-
|
|
75
|
-
assert.deepEqual(result, [{ name: "http-server", version: "latest" }]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("should return package with --package=x@version option", () => {
|
|
79
|
-
const args = ["--package=http-server@1.0.0"];
|
|
80
|
-
|
|
81
|
-
const result = parsePackagesFromArguments(args);
|
|
82
|
-
|
|
83
|
-
assert.deepEqual(result, [{ name: "http-server", version: "1.0.0" }]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("should ignore options with parameters and return an array of changes", () => {
|
|
87
|
-
const args = ["--loglevel", "error", "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 version even for aliased packages", () => {
|
|
95
|
-
const args = ["server@npm:http-server@14.1.1"];
|
|
96
|
-
|
|
97
|
-
const result = parsePackagesFromArguments(args);
|
|
98
|
-
|
|
99
|
-
assert.deepEqual(result, [{ name: "http-server", version: "14.1.1" }]);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("should parse scoped packages", () => {
|
|
103
|
-
const args = ["@scope/package@1.0.0"];
|
|
104
|
-
|
|
105
|
-
const result = parsePackagesFromArguments(args);
|
|
106
|
-
|
|
107
|
-
assert.deepEqual(result, [{ name: "@scope/package", version: "1.0.0" }]);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("should parse packages with version ranges", () => {
|
|
111
|
-
const args = ["http-server@^14.1.1"];
|
|
112
|
-
|
|
113
|
-
const result = parsePackagesFromArguments(args);
|
|
114
|
-
|
|
115
|
-
assert.deepEqual(result, [{ name: "http-server", version: "^14.1.1" }]);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should parse package folders", () => {
|
|
119
|
-
const args = ["./local-package"];
|
|
120
|
-
|
|
121
|
-
const result = parsePackagesFromArguments(args);
|
|
122
|
-
|
|
123
|
-
assert.deepEqual(result, [{ name: "./local-package", version: "latest" }]);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should parse tarballs", () => {
|
|
127
|
-
const args = ["file:./local-package.tgz"];
|
|
128
|
-
|
|
129
|
-
const result = parsePackagesFromArguments(args);
|
|
130
|
-
|
|
131
|
-
assert.deepEqual(result, [
|
|
132
|
-
{ name: "file:./local-package.tgz", version: "latest" },
|
|
133
|
-
]);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("should parse tarball URLs", () => {
|
|
137
|
-
const args = ["https://example.com/local-package.tgz"];
|
|
138
|
-
|
|
139
|
-
const result = parsePackagesFromArguments(args);
|
|
140
|
-
|
|
141
|
-
assert.deepEqual(result, [
|
|
142
|
-
{ name: "https://example.com/local-package.tgz", version: "latest" },
|
|
143
|
-
]);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("should parse git URLs", () => {
|
|
147
|
-
const args = ["git://github.com/http-party/http-server"];
|
|
148
|
-
|
|
149
|
-
const result = parsePackagesFromArguments(args);
|
|
150
|
-
|
|
151
|
-
assert.deepEqual(result, [
|
|
152
|
-
{ name: "git://github.com/http-party/http-server", version: "latest" },
|
|
153
|
-
]);
|
|
154
|
-
});
|
|
155
|
-
});
|