@pnpm/lockfile.utils 1100.0.4 → 1100.0.6

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.
@@ -1,12 +1,11 @@
1
1
  import url from 'node:url';
2
2
  import * as dp from '@pnpm/deps.path';
3
- import { isGitHostedPkgUrl } from '@pnpm/fetching.pick-fetcher';
4
3
  import getNpmTarballUrl from 'get-npm-tarball-url';
5
4
  import { nameVerFromPkgSnapshot } from './nameVerFromPkgSnapshot.js';
6
5
  export function pkgSnapshotToResolution(depPath, pkgSnapshot, registries) {
7
6
  if (Boolean(pkgSnapshot.resolution.type) ||
8
7
  pkgSnapshot.resolution.tarball?.startsWith('file:') ||
9
- isGitHostedPkgUrl(pkgSnapshot.resolution.tarball ?? '')) {
8
+ pkgSnapshot.resolution.gitHosted === true) {
10
9
  return pkgSnapshot.resolution;
11
10
  }
12
11
  // Recover the tarball field for `file:` snapshots whose resolution lost
@@ -1,46 +1,68 @@
1
- import { isGitHostedPkgUrl } from '@pnpm/fetching.pick-fetcher';
2
1
  import getNpmTarballUrl from 'get-npm-tarball-url';
3
2
  export function toLockfileResolution(pkg, resolution, registry, lockfileIncludeTarballUrl) {
4
3
  if (resolution.type !== undefined || !resolution['integrity']) {
5
4
  return resolution;
6
5
  }
6
+ // Tarball-typed resolutions are guaranteed to carry a tarball URL by the
7
+ // resolver, but guard for unexpected inputs (e.g. resolutions deserialized
8
+ // from external state) so we don't blow up on a missing field.
7
9
  const tarball = resolution['tarball'];
10
+ if (tarball == null) {
11
+ return { integrity: resolution['integrity'] };
12
+ }
13
+ // Honor the resolver-supplied flag, with a URL fallback for resolutions
14
+ // that didn't go through the git resolver (e.g. config-dep migrations or
15
+ // legacy lockfiles read by callers that don't enrich the field).
16
+ const gitHosted = resolution.gitHosted === true ||
17
+ isGitHostedTarballUrl(tarball);
8
18
  if (lockfileIncludeTarballUrl) {
9
- return {
19
+ return preservingGitHosted({
10
20
  integrity: resolution['integrity'],
11
21
  tarball,
12
- };
22
+ }, gitHosted);
13
23
  }
14
24
  // Tarball URLs that cannot be reconstructed from the package name, version,
15
25
  // and registry must always stay in the lockfile, otherwise the package can
16
26
  // no longer be re-fetched. This covers local `file:` tarballs and tarballs
17
27
  // served by git providers (GitHub, GitLab, Bitbucket).
18
- if (tarball != null && (tarball.startsWith('file:') || isGitHostedPkgUrl(tarball))) {
19
- return {
28
+ if (tarball.startsWith('file:') || gitHosted) {
29
+ return preservingGitHosted({
20
30
  integrity: resolution['integrity'],
21
31
  tarball,
22
- };
23
- }
24
- if (lockfileIncludeTarballUrl === false) {
25
- return {
26
- integrity: resolution['integrity'],
27
- };
32
+ }, gitHosted);
28
33
  }
29
34
  // Sometimes packages are hosted under non-standard tarball URLs.
30
35
  // For instance, when they are hosted on npm Enterprise. See https://github.com/pnpm/pnpm/issues/867
31
- // Or in other weird cases, like https://github.com/pnpm/pnpm/issues/1072
36
+ // Or in other weird cases, like https://github.com/pnpm/pnpm/issues/1072.
37
+ // Even when the user explicitly sets `lockfileIncludeTarballUrl: false`, we
38
+ // must preserve such URLs — otherwise the package cannot be re-fetched on a
39
+ // frozen-lockfile install (e.g. GitHub Packages tarballs at
40
+ // `https://npm.pkg.github.com/download/<scope>/<name>/<version>/<hash>`).
41
+ // `lockfileIncludeTarballUrl` only controls whether URLs that *can* be
42
+ // derived from name+version+registry are written.
32
43
  const expectedTarball = getNpmTarballUrl(pkg.name, pkg.version, { registry });
33
44
  const actualTarball = tarball.replaceAll('%2f', '/');
34
45
  if (removeProtocol(expectedTarball) !== removeProtocol(actualTarball)) {
35
- return {
46
+ return preservingGitHosted({
36
47
  integrity: resolution['integrity'],
37
48
  tarball,
38
- };
49
+ }, gitHosted);
39
50
  }
40
51
  return {
41
52
  integrity: resolution['integrity'],
42
53
  };
43
54
  }
55
+ function preservingGitHosted(resolution, gitHosted) {
56
+ return gitHosted ? { ...resolution, gitHosted: true } : resolution;
57
+ }
58
+ // Inlined to avoid pulling @pnpm/fetching.pick-fetcher into the lockfile-utils
59
+ // dep graph. Used as a fallback when callers haven't pre-set the
60
+ // `gitHosted` field on TarballResolution.
61
+ function isGitHostedTarballUrl(url) {
62
+ return (url.startsWith('https://codeload.github.com/') ||
63
+ url.startsWith('https://bitbucket.org/') ||
64
+ url.startsWith('https://gitlab.com/')) && url.includes('tar.gz');
65
+ }
44
66
  function removeProtocol(url) {
45
67
  return url.split('://')[1];
46
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/lockfile.utils",
3
- "version": "1100.0.4",
3
+ "version": "1100.0.6",
4
4
  "description": "Utils for dealing with pnpm-lock.yaml",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -29,12 +29,11 @@
29
29
  "get-npm-tarball-url": "^2.1.0",
30
30
  "ramda": "npm:@pnpm/ramda@0.28.1",
31
31
  "@pnpm/deps.path": "1100.0.2",
32
- "@pnpm/error": "1100.0.0",
33
- "@pnpm/fetching.pick-fetcher": "1100.0.4",
34
- "@pnpm/lockfile.types": "1100.0.3",
35
- "@pnpm/resolving.resolver-base": "1100.1.1",
36
- "@pnpm/hooks.types": "1100.0.4",
37
- "@pnpm/types": "1101.0.0"
32
+ "@pnpm/lockfile.types": "1100.0.4",
33
+ "@pnpm/hooks.types": "1100.0.5",
34
+ "@pnpm/resolving.resolver-base": "1100.1.2",
35
+ "@pnpm/types": "1101.0.0",
36
+ "@pnpm/error": "1100.0.0"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@jest/globals": "30.3.0",
@@ -42,7 +41,7 @@
42
41
  "tempy": "3.0.0",
43
42
  "write-yaml-file": "^6.0.0",
44
43
  "yaml-tag": "1.1.0",
45
- "@pnpm/lockfile.utils": "1100.0.4"
44
+ "@pnpm/lockfile.utils": "1100.0.6"
46
45
  },
47
46
  "engines": {
48
47
  "node": ">=22.13"