Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for catalog:, npm:, and workspace: protocol #103

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions PJV.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@
v === "" ||
v === "latest" ||
(v.indexOf && v.indexOf("git") === 0) ||
// https://pnpm.io/next/workspaces#workspace-protocol-workspace
/^workspace:((\^|~)?[0-9.x]*|(<=?|>=?)?[0-9.x][\-.+\w]+|\*)?$/.test(v) ||
// https://pnpm.io/next/catalogs
(v.indexOf && v.indexOf("catalog:") === 0) ||
(v.indexOf && v.indexOf("npm:") === 0) ||
false
);
};
Expand Down
18 changes: 18 additions & 0 deletions PJV.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ describe("NPM", () => {
"x-version": "1.2.x",
"tilde-top": "~1",
"caret-top": "^1",
"workspace-package-no-range": "workspace:",
"workspace-package-caret": "workspace:^",
"workspace-package-any": "workspace:*",
"workspace-package-tilde-version": "workspace:~1.2.3",
"workspace-gt-version": "workspace:>1.2.3",
"workspace-pre-release": "workspace:1.2.3-rc.1",
"catalog-package": "catalog:",
"catalog-named-package": "catalog:react19",
"svgo-v1": "npm:[email protected]",
"svgo-v2": "npm:[email protected]",
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
},
devDependencies: {
range: "1.2.3 - 2.3.4",
Expand Down Expand Up @@ -151,13 +161,21 @@ describe("NPM", () => {
const json = getPackageJson({
devDependencies: {
"package-name": "abc123",
"bad-catalog": "catalob:",
"bad-workspace": "workspace:abc123",
"bad-workspace-range": "workspace:^>1.2.3",
"bad-npm": "npm;svgo@^1.2.3",
},
});

const result = PJV.validate(JSON.stringify(json), "npm");

assert.deepStrictEqual(result.errors, [
"Invalid version range for dependency package-name: abc123",
"Invalid version range for dependency bad-catalog: catalob:",
"Invalid version range for dependency bad-workspace: workspace:abc123",
"Invalid version range for dependency bad-workspace-range: workspace:^>1.2.3",
"Invalid version range for dependency bad-npm: npm;svgo@^1.2.3",
]);
});

Expand Down
Loading