@pnpm/building.policy 1100.0.7 → 1100.0.9

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/lib/index.d.ts CHANGED
@@ -4,3 +4,9 @@ export declare function createAllowBuildFunction(opts: {
4
4
  dangerouslyAllowAllBuilds?: boolean;
5
5
  allowBuilds?: Record<string, boolean | string>;
6
6
  }): undefined | AllowBuild;
7
+ /**
8
+ * The `allowBuilds` key under which an ignored build should be approved:
9
+ * the package name for registry packages, the peer-suffix-free depPath for
10
+ * git/tarball artifacts, whose name alone must not approve builds.
11
+ */
12
+ export declare function allowBuildKeyFromIgnoredBuild(depPath: DepPath): string;
package/lib/index.js CHANGED
@@ -1,37 +1,62 @@
1
1
  import { expandPackageVersionSpecs } from '@pnpm/config.version-policy';
2
2
  import * as dp from '@pnpm/deps.path';
3
3
  export function isBuildExplicitlyDisallowed(depPath, allowBuild) {
4
- if (!allowBuild)
5
- return false;
6
- const { name, version } = dp.parse(depPath);
7
- if (!name || !version)
8
- return false;
9
- return allowBuild(name, version) === false;
4
+ return allowBuild?.(depPath) === false;
10
5
  }
11
6
  export function createAllowBuildFunction(opts) {
12
7
  if (opts.dangerouslyAllowAllBuilds)
13
8
  return () => true;
14
9
  if (opts.allowBuilds != null) {
15
- const allowedBuilds = new Set();
16
- const disallowedBuilds = new Set();
10
+ const allowedPackageBuilds = new Set();
11
+ const disallowedPackageBuilds = new Set();
12
+ const allowedDepPathBuilds = new Set();
13
+ const disallowedDepPathBuilds = new Set();
17
14
  for (const [pkg, value] of Object.entries(opts.allowBuilds)) {
18
15
  switch (value) {
19
16
  case true:
20
- allowedBuilds.add(pkg);
17
+ addAllowBuildRule(pkg, {
18
+ depPaths: allowedDepPathBuilds,
19
+ packageSpecs: allowedPackageBuilds,
20
+ });
21
21
  break;
22
22
  case false:
23
- disallowedBuilds.add(pkg);
23
+ addAllowBuildRule(pkg, {
24
+ depPaths: disallowedDepPathBuilds,
25
+ packageSpecs: disallowedPackageBuilds,
26
+ });
24
27
  break;
25
28
  }
26
29
  }
27
- const expandedAllowed = expandPackageVersionSpecs(Array.from(allowedBuilds));
28
- const expandedDisallowed = expandPackageVersionSpecs(Array.from(disallowedBuilds));
29
- return (pkgName, version) => {
30
- const pkgWithVersion = `${pkgName}@${version}`;
31
- if (expandedDisallowed.has(pkgName) || expandedDisallowed.has(pkgWithVersion)) {
30
+ const expandedAllowed = expandPackageVersionSpecs(Array.from(allowedPackageBuilds));
31
+ const expandedDisallowed = expandPackageVersionSpecs(Array.from(disallowedPackageBuilds));
32
+ return (depPath, context) => {
33
+ const pkgIdWithPatchHash = dp.getPkgIdWithPatchHash(depPath);
34
+ if (disallowedDepPathBuilds.has(pkgIdWithPatchHash)) {
35
+ return false;
36
+ }
37
+ const { name, version, nonSemverVersion } = dp.parse(depPath);
38
+ const nameAtVersion = name != null && version != null ? `${name}@${version}` : undefined;
39
+ if ((name != null && expandedDisallowed.has(name)) ||
40
+ (nameAtVersion != null && expandedDisallowed.has(nameAtVersion))) {
32
41
  return false;
33
42
  }
34
- if (expandedAllowed.has(pkgName) || expandedAllowed.has(pkgWithVersion)) {
43
+ if (allowedDepPathBuilds.has(pkgIdWithPatchHash)) {
44
+ return true;
45
+ }
46
+ // Package-name rules require a trusted package identity. A
47
+ // registry-style depPath (name@semver) is the trust signal: the
48
+ // lockfile verification gate rejects lockfiles where such a key is
49
+ // backed by a non-registry resolution, so by the time scripts can
50
+ // run, the shape proves the artifact came from a registry. The
51
+ // override exists for callers that must evaluate name rules under
52
+ // legacy semantics (e.g. comparing against a policy recorded before
53
+ // identity trust existed).
54
+ const trustPackageIdentity = context?.trustPackageIdentity ??
55
+ (name != null && version != null && nonSemverVersion == null);
56
+ if (!trustPackageIdentity)
57
+ return undefined;
58
+ if ((name != null && expandedAllowed.has(name)) ||
59
+ (nameAtVersion != null && expandedAllowed.has(nameAtVersion))) {
35
60
  return true;
36
61
  }
37
62
  return undefined;
@@ -39,4 +64,39 @@ export function createAllowBuildFunction(opts) {
39
64
  }
40
65
  return undefined;
41
66
  }
67
+ /**
68
+ * The `allowBuilds` key under which an ignored build should be approved:
69
+ * the package name for registry packages, the peer-suffix-free depPath for
70
+ * git/tarball artifacts, whose name alone must not approve builds.
71
+ */
72
+ export function allowBuildKeyFromIgnoredBuild(depPath) {
73
+ const pkgIdWithPatchHash = dp.getPkgIdWithPatchHash(depPath);
74
+ const parsed = dp.parse(pkgIdWithPatchHash);
75
+ if (parsed.nonSemverVersion != null || parsed.name == null)
76
+ return pkgIdWithPatchHash;
77
+ return parsed.name;
78
+ }
79
+ function addAllowBuildRule(pkg, target) {
80
+ if (isDepPathAllowBuildKey(pkg)) {
81
+ target.depPaths.add(dp.removePeersSuffix(pkg));
82
+ }
83
+ else {
84
+ target.packageSpecs.add(pkg);
85
+ }
86
+ }
87
+ function isDepPathAllowBuildKey(pkg) {
88
+ if (dp.removePeersSuffix(pkg) !== pkg)
89
+ return true;
90
+ if (pkg.includes('||'))
91
+ return false;
92
+ const parsed = dp.parse(pkg);
93
+ if (parsed.nonSemverVersion != null)
94
+ return isSourceLikeDepPathVersion(parsed.nonSemverVersion);
95
+ if (parsed.name != null || pkg.startsWith('@'))
96
+ return false;
97
+ return pkg.includes('/') || pkg.includes(':');
98
+ }
99
+ function isSourceLikeDepPathVersion(version) {
100
+ return version.includes(':') || version.includes('/') || version.includes('#');
101
+ }
42
102
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/building.policy",
3
- "version": "1100.0.7",
3
+ "version": "1100.0.9",
4
4
  "description": "Create a function for filtering out dependencies that are not allowed to be built",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -8,7 +8,10 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "funding": "https://opencollective.com/pnpm",
11
- "repository": "https://github.com/pnpm/pnpm/tree/main/building/policy",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/pnpm/pnpm/tree/main/building/policy"
14
+ },
12
15
  "homepage": "https://github.com/pnpm/pnpm/tree/main/building/policy#readme",
13
16
  "bugs": {
14
17
  "url": "https://github.com/pnpm/pnpm/issues"
@@ -24,13 +27,13 @@
24
27
  "!*.map"
25
28
  ],
26
29
  "dependencies": {
27
- "@pnpm/deps.path": "1100.0.5",
28
- "@pnpm/types": "1101.2.0",
29
- "@pnpm/config.version-policy": "1100.1.2"
30
+ "@pnpm/deps.path": "1100.0.7",
31
+ "@pnpm/types": "1101.3.1",
32
+ "@pnpm/config.version-policy": "1100.1.4"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@jest/globals": "30.3.0",
33
- "@pnpm/building.policy": "1100.0.7"
36
+ "@pnpm/building.policy": "1100.0.9"
34
37
  },
35
38
  "engines": {
36
39
  "node": ">=22.13"