fix(scripts): reject short flag shrinkwrap refs

This commit is contained in:
Vincent Koc
2026-06-21 22:36:15 +02:00
parent ab8dc3af52
commit 75a997dd7c
2 changed files with 16 additions and 3 deletions

View File

@@ -1170,7 +1170,7 @@ function listCheckChangedPaths() {
}
}
function resolvePackageDirs(args) {
export function resolvePackageDirs(args) {
const packageDirs = [];
const check = args.includes("--check");
const all = args.includes("--all");
@@ -1199,7 +1199,7 @@ function resolvePackageDirs(args) {
}
if (arg === "--package-dir") {
const value = args[index + 1];
if (!value || value.startsWith("--")) {
if (!value || value.startsWith("-")) {
throw new Error("--package-dir requires a package directory.");
}
packageDirs.push(path.resolve(ROOT_DIR, value));
@@ -1208,7 +1208,7 @@ function resolvePackageDirs(args) {
}
if (arg === "--base" || arg === "--head") {
const value = args[index + 1];
if (!value || value.startsWith("--")) {
if (!value || value.startsWith("-")) {
throw new Error(`${arg} requires a git ref.`);
}
index += 1;

View File

@@ -16,6 +16,7 @@ import {
pnpmLockOverrideVersionForVersions,
parsePnpmPackageKey,
parseLockPackagePath,
resolvePackageDirs,
restoreCurrentPnpmLockedPackages,
shouldUseLegacyPeerDepsForShrinkwrap,
shrinkwrapPackageDirsForChangedPaths,
@@ -57,6 +58,18 @@ describe("generate-npm-shrinkwrap", () => {
});
});
it("rejects short flag package selectors before resolving shrinkwrap targets", () => {
expect(() => resolvePackageDirs(["--package-dir", "-h"])).toThrow(
"--package-dir requires a package directory.",
);
expect(() => resolvePackageDirs(["--changed", "--base", "-h"])).toThrow(
"--base requires a git ref.",
);
expect(() => resolvePackageDirs(["--changed", "--head", "-h"])).toThrow(
"--head requires a git ref.",
);
});
it("accepts strict npm shrinkwrap command timeout and buffer overrides", () => {
expect(
createNpmShrinkwrapExecOptions({ command: "npm", args: ["install"] }, "/tmp/package", {