mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Fix undefined error when adding scoped package on yarn, npm or npx
This commit is contained in:
parent
b57cc11157
commit
9e1c90a914
7 changed files with 41 additions and 3 deletions
|
|
@ -86,7 +86,9 @@ function parsePackagename(arg) {
|
||||||
const lastAtIndex = arg.lastIndexOf("@");
|
const lastAtIndex = arg.lastIndexOf("@");
|
||||||
|
|
||||||
let name, version;
|
let name, version;
|
||||||
if (lastAtIndex !== -1) {
|
// The index of the last "@" should be greater than 0
|
||||||
|
// If the index is 0, it means the package name starts with "@" (eg: "@vercel/otel")
|
||||||
|
if (lastAtIndex > 0) {
|
||||||
name = arg.slice(0, lastAtIndex);
|
name = arg.slice(0, lastAtIndex);
|
||||||
version = arg.slice(lastAtIndex + 1);
|
version = arg.slice(lastAtIndex + 1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,14 @@ describe("parsePackagesFromInstallArgs", () => {
|
||||||
assert.deepEqual(result, [{ name: "@jest/transform", version: "29.7.0" }]);
|
assert.deepEqual(result, [{ name: "@jest/transform", version: "29.7.0" }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return the package in the format @vercel/otel", () => {
|
||||||
|
const args = ["install", "@vercel/otel"];
|
||||||
|
|
||||||
|
const result = parsePackagesFromInstallArgs(args);
|
||||||
|
|
||||||
|
assert.deepEqual(result, [{ name: "@vercel/otel", version: "latest" }]);
|
||||||
|
});
|
||||||
|
|
||||||
it("should return an array of changes for multiple packages", () => {
|
it("should return an array of changes for multiple packages", () => {
|
||||||
const args = ["install", "express@4.17.1", "lodash@4.17.21"];
|
const args = ["install", "express@4.17.1", "lodash@4.17.21"];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,9 @@ function parsePackagename(arg, defaultTag) {
|
||||||
const lastAtIndex = arg.lastIndexOf("@");
|
const lastAtIndex = arg.lastIndexOf("@");
|
||||||
|
|
||||||
let name, version;
|
let name, version;
|
||||||
if (lastAtIndex !== -1) {
|
// The index of the last "@" should be greater than 0
|
||||||
|
// If the index is 0, it means the package name starts with "@" (eg: "@vercel/otel")
|
||||||
|
if (lastAtIndex > 0) {
|
||||||
name = arg.slice(0, lastAtIndex);
|
name = arg.slice(0, lastAtIndex);
|
||||||
version = arg.slice(lastAtIndex + 1);
|
version = arg.slice(lastAtIndex + 1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,14 @@ describe("parsePackagesFromArguments", () => {
|
||||||
assert.deepEqual(result, [{ name: "http-server", version: "14.1.1" }]);
|
assert.deepEqual(result, [{ name: "http-server", version: "14.1.1" }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return the package in the format @vercel/otel", () => {
|
||||||
|
const args = ["@vercel/otel"];
|
||||||
|
|
||||||
|
const result = parsePackagesFromArguments(args);
|
||||||
|
|
||||||
|
assert.deepEqual(result, [{ name: "@vercel/otel", version: "latest" }]);
|
||||||
|
});
|
||||||
|
|
||||||
it("should return the package with latest tag if absent", () => {
|
it("should return the package with latest tag if absent", () => {
|
||||||
const args = ["http-server"];
|
const args = ["http-server"];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,14 @@ describe("standardPnpmArgumentParser", () => {
|
||||||
assert.deepEqual(result, [{ name: "axios", version: "latest" }]);
|
assert.deepEqual(result, [{ name: "axios", version: "latest" }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return the package in the format @vercel/otel", () => {
|
||||||
|
const args = ["@vercel/otel"];
|
||||||
|
|
||||||
|
const result = parsePackagesFromArguments(args);
|
||||||
|
|
||||||
|
assert.deepEqual(result, [{ name: "@vercel/otel", version: "latest" }]);
|
||||||
|
});
|
||||||
|
|
||||||
it("should return the package with latest tag if the version is absent and package starts with @", () => {
|
it("should return the package with latest tag if the version is absent and package starts with @", () => {
|
||||||
const args = ["@aikidosec/package-name"];
|
const args = ["@aikidosec/package-name"];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,9 @@ function parsePackagename(arg, defaultTag) {
|
||||||
const lastAtIndex = arg.lastIndexOf("@");
|
const lastAtIndex = arg.lastIndexOf("@");
|
||||||
|
|
||||||
let name, version;
|
let name, version;
|
||||||
if (lastAtIndex !== -1) {
|
// The index of the last "@" should be greater than 0
|
||||||
|
// If the index is 0, it means the package name starts with "@" (eg: "@vercel/otel")
|
||||||
|
if (lastAtIndex > 0) {
|
||||||
name = arg.slice(0, lastAtIndex);
|
name = arg.slice(0, lastAtIndex);
|
||||||
version = arg.slice(lastAtIndex + 1);
|
version = arg.slice(lastAtIndex + 1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,14 @@ describe("standardYarnArgumentParser", () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return the package in the format @vercel/otel", () => {
|
||||||
|
const args = ["add", "@vercel/otel"];
|
||||||
|
|
||||||
|
const result = parsePackagesFromArguments(args);
|
||||||
|
|
||||||
|
assert.deepEqual(result, [{ name: "@vercel/otel", version: "latest" }]);
|
||||||
|
});
|
||||||
|
|
||||||
it("should ignore options with parameters and return an array of changes", () => {
|
it("should ignore options with parameters and return an array of changes", () => {
|
||||||
const args = ["add", "--proxy", "http://localhost", "axios@1.9.0"];
|
const args = ["add", "--proxy", "http://localhost", "axios@1.9.0"];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue