@pnpm/lockfile.fs 1001.1.32 → 1100.0.1

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.
Files changed (39) hide show
  1. package/lib/envLockfile.d.ts +4 -0
  2. package/lib/envLockfile.js +72 -0
  3. package/lib/errors/LockfileBreakingChangeError.js +2 -6
  4. package/lib/errors/index.js +1 -5
  5. package/lib/existsWantedLockfile.d.ts +2 -2
  6. package/lib/existsWantedLockfile.js +6 -12
  7. package/lib/getLockfileImporterId.d.ts +1 -1
  8. package/lib/getLockfileImporterId.js +4 -10
  9. package/lib/gitBranchLockfile.js +8 -15
  10. package/lib/gitMergeFile.d.ts +1 -1
  11. package/lib/gitMergeFile.js +6 -13
  12. package/lib/index.d.ts +6 -4
  13. package/lib/index.js +9 -33
  14. package/lib/lockfileFormatConverters.d.ts +1 -1
  15. package/lib/lockfileFormatConverters.js +34 -47
  16. package/lib/lockfileName.js +6 -9
  17. package/lib/logger.js +2 -5
  18. package/lib/read.d.ts +2 -2
  19. package/lib/read.js +52 -63
  20. package/lib/sortLockfileKeys.d.ts +2 -1
  21. package/lib/sortLockfileKeys.js +17 -19
  22. package/lib/write.d.ts +2 -1
  23. package/lib/write.js +64 -56
  24. package/lib/yamlDocuments.d.ts +16 -0
  25. package/lib/yamlDocuments.js +70 -0
  26. package/package.json +30 -30
  27. package/lib/errors/LockfileBreakingChangeError.js.map +0 -1
  28. package/lib/errors/index.js.map +0 -1
  29. package/lib/existsWantedLockfile.js.map +0 -1
  30. package/lib/getLockfileImporterId.js.map +0 -1
  31. package/lib/gitBranchLockfile.js.map +0 -1
  32. package/lib/gitMergeFile.js.map +0 -1
  33. package/lib/index.js.map +0 -1
  34. package/lib/lockfileFormatConverters.js.map +0 -1
  35. package/lib/lockfileName.js.map +0 -1
  36. package/lib/logger.js.map +0 -1
  37. package/lib/read.js.map +0 -1
  38. package/lib/sortLockfileKeys.js.map +0 -1
  39. package/lib/write.js.map +0 -1
@@ -0,0 +1,4 @@
1
+ import type { EnvLockfile } from '@pnpm/lockfile.types';
2
+ export declare function createEnvLockfile(): EnvLockfile;
3
+ export declare function readEnvLockfile(rootDir: string): Promise<EnvLockfile | null>;
4
+ export declare function writeEnvLockfile(rootDir: string, lockfile: EnvLockfile): Promise<void>;
@@ -0,0 +1,72 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ import util from 'node:util';
4
+ import { LOCKFILE_VERSION, WANTED_LOCKFILE } from '@pnpm/constants';
5
+ import yaml from 'js-yaml';
6
+ import writeFileAtomic from 'write-file-atomic';
7
+ import { sortLockfileKeys } from './sortLockfileKeys.js';
8
+ import { lockfileYamlDump } from './write.js';
9
+ import { extractMainDocument, streamReadFirstYamlDocument } from './yamlDocuments.js';
10
+ export function createEnvLockfile() {
11
+ return {
12
+ lockfileVersion: LOCKFILE_VERSION,
13
+ importers: {
14
+ '.': {
15
+ configDependencies: {},
16
+ },
17
+ },
18
+ packages: {},
19
+ snapshots: {},
20
+ };
21
+ }
22
+ export async function readEnvLockfile(rootDir) {
23
+ const lockfilePath = path.join(rootDir, WANTED_LOCKFILE);
24
+ const rawContent = await streamReadFirstYamlDocument(lockfilePath);
25
+ if (rawContent == null) {
26
+ return null;
27
+ }
28
+ const parsed = yaml.load(rawContent);
29
+ if (parsed == null || typeof parsed !== 'object') {
30
+ return null;
31
+ }
32
+ const lockfile = parsed;
33
+ if (typeof lockfile.lockfileVersion !== 'string') {
34
+ return null;
35
+ }
36
+ if (lockfile.importers == null || typeof lockfile.importers !== 'object') {
37
+ return null;
38
+ }
39
+ if (lockfile.packages == null || typeof lockfile.packages !== 'object') {
40
+ return null;
41
+ }
42
+ if (lockfile.snapshots == null || typeof lockfile.snapshots !== 'object') {
43
+ return null;
44
+ }
45
+ const envLockfile = parsed;
46
+ if (!envLockfile.importers['.']) {
47
+ envLockfile.importers['.'] = { configDependencies: {} };
48
+ }
49
+ else if (!envLockfile.importers['.'].configDependencies) {
50
+ envLockfile.importers['.'].configDependencies = {};
51
+ }
52
+ return envLockfile;
53
+ }
54
+ export async function writeEnvLockfile(rootDir, lockfile) {
55
+ const lockfilePath = path.join(rootDir, WANTED_LOCKFILE);
56
+ const sorted = sortLockfileKeys(lockfile);
57
+ const envYaml = lockfileYamlDump(sorted);
58
+ // Read existing main lockfile document to preserve it
59
+ let mainDoc = '';
60
+ try {
61
+ const existing = await fs.readFile(lockfilePath, 'utf8');
62
+ mainDoc = extractMainDocument(existing);
63
+ }
64
+ catch (err) {
65
+ if (!(util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT')) {
66
+ throw err;
67
+ }
68
+ }
69
+ const combined = `---\n${envYaml}\n---\n${mainDoc}`;
70
+ return writeFileAtomic(lockfilePath, combined);
71
+ }
72
+ //# sourceMappingURL=envLockfile.js.map
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LockfileBreakingChangeError = void 0;
4
- const error_1 = require("@pnpm/error");
5
- class LockfileBreakingChangeError extends error_1.PnpmError {
1
+ import { PnpmError } from '@pnpm/error';
2
+ export class LockfileBreakingChangeError extends PnpmError {
6
3
  filename;
7
4
  constructor(filename) {
8
5
  super('LOCKFILE_BREAKING_CHANGE', `Lockfile ${filename} not compatible with current pnpm`);
9
6
  this.filename = filename;
10
7
  }
11
8
  }
12
- exports.LockfileBreakingChangeError = LockfileBreakingChangeError;
13
9
  //# sourceMappingURL=LockfileBreakingChangeError.js.map
@@ -1,6 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LockfileBreakingChangeError = void 0;
4
- var LockfileBreakingChangeError_js_1 = require("./LockfileBreakingChangeError.js");
5
- Object.defineProperty(exports, "LockfileBreakingChangeError", { enumerable: true, get: function () { return LockfileBreakingChangeError_js_1.LockfileBreakingChangeError; } });
1
+ export { LockfileBreakingChangeError } from './LockfileBreakingChangeError.js';
6
2
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
- interface existsNonEmptyWantedLockfileOptions {
1
+ interface ExistsNonEmptyWantedLockfileOptions {
2
2
  useGitBranchLockfile?: boolean;
3
3
  mergeGitBranchLockfiles?: boolean;
4
4
  }
5
- export declare function existsNonEmptyWantedLockfile(pkgPath: string, opts?: existsNonEmptyWantedLockfileOptions): Promise<boolean>;
5
+ export declare function existsNonEmptyWantedLockfile(pkgPath: string, opts?: ExistsNonEmptyWantedLockfileOptions): Promise<boolean>;
6
6
  export {};
@@ -1,19 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.existsNonEmptyWantedLockfile = existsNonEmptyWantedLockfile;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const lockfileName_js_1 = require("./lockfileName.js");
10
- async function existsNonEmptyWantedLockfile(pkgPath, opts = {
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { getWantedLockfileName } from './lockfileName.js';
4
+ export async function existsNonEmptyWantedLockfile(pkgPath, opts = {
11
5
  useGitBranchLockfile: false,
12
6
  mergeGitBranchLockfiles: false,
13
7
  }) {
14
- const wantedLockfile = await (0, lockfileName_js_1.getWantedLockfileName)(opts);
8
+ const wantedLockfile = await getWantedLockfileName(opts);
15
9
  return new Promise((resolve, reject) => {
16
- fs_1.default.access(path_1.default.join(pkgPath, wantedLockfile), (err) => {
10
+ fs.access(path.join(pkgPath, wantedLockfile), (err) => {
17
11
  if (err == null) {
18
12
  resolve(true);
19
13
  return;
@@ -1,2 +1,2 @@
1
- import { type ProjectId } from '@pnpm/types';
1
+ import type { ProjectId } from '@pnpm/types';
2
2
  export declare function getLockfileImporterId(lockfileDir: string, prefix: string): ProjectId;
@@ -1,12 +1,6 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getLockfileImporterId = getLockfileImporterId;
7
- const path_1 = __importDefault(require("path"));
8
- const normalize_path_1 = __importDefault(require("normalize-path"));
9
- function getLockfileImporterId(lockfileDir, prefix) {
10
- return ((0, normalize_path_1.default)(path_1.default.relative(lockfileDir, prefix)) || '.');
1
+ import path from 'node:path';
2
+ import normalize from 'normalize-path';
3
+ export function getLockfileImporterId(lockfileDir, prefix) {
4
+ return (normalize(path.relative(lockfileDir, prefix)) || '.');
11
5
  }
12
6
  //# sourceMappingURL=getLockfileImporterId.js.map
@@ -1,23 +1,16 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getGitBranchLockfileNames = getGitBranchLockfileNames;
7
- exports.cleanGitBranchLockfiles = cleanGitBranchLockfiles;
8
- const fs_1 = require("fs");
9
- const path_1 = __importDefault(require("path"));
10
- async function getGitBranchLockfileNames(lockfileDir) {
11
- const files = await fs_1.promises.readdir(lockfileDir);
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ export async function getGitBranchLockfileNames(lockfileDir) {
4
+ const files = await fs.readdir(lockfileDir);
12
5
  // eslint-disable-next-line regexp/no-useless-non-capturing-group
13
6
  const gitBranchLockfileNames = files.filter(file => file.match(/^pnpm-lock.(?:.*).yaml$/));
14
7
  return gitBranchLockfileNames;
15
8
  }
16
- async function cleanGitBranchLockfiles(lockfileDir) {
9
+ export async function cleanGitBranchLockfiles(lockfileDir) {
17
10
  const gitBranchLockfiles = await getGitBranchLockfileNames(lockfileDir);
18
- await Promise.all(gitBranchLockfiles.map(async (file) => {
19
- const filepath = path_1.default.join(lockfileDir, file);
20
- await fs_1.promises.unlink(filepath);
11
+ await Promise.all(gitBranchLockfiles.map(async file => {
12
+ const filepath = path.join(lockfileDir, file);
13
+ await fs.unlink(filepath);
21
14
  }));
22
15
  }
23
16
  //# sourceMappingURL=gitBranchLockfile.js.map
@@ -1,3 +1,3 @@
1
- import { type LockfileObject } from '@pnpm/lockfile.types';
1
+ import type { LockfileObject } from '@pnpm/lockfile.types';
2
2
  export declare function autofixMergeConflicts(fileContent: string): LockfileObject;
3
3
  export declare function isDiff(fileContent: string): boolean;
@@ -1,20 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.autofixMergeConflicts = autofixMergeConflicts;
7
- exports.isDiff = isDiff;
8
- const lockfile_merger_1 = require("@pnpm/lockfile.merger");
9
- const js_yaml_1 = __importDefault(require("js-yaml"));
10
- const lockfileFormatConverters_js_1 = require("./lockfileFormatConverters.js");
1
+ import { mergeLockfileChanges } from '@pnpm/lockfile.merger';
2
+ import yaml from 'js-yaml';
3
+ import { convertToLockfileObject } from './lockfileFormatConverters.js';
11
4
  const MERGE_CONFLICT_PARENT = '|||||||';
12
5
  const MERGE_CONFLICT_END = '>>>>>>>';
13
6
  const MERGE_CONFLICT_THEIRS = '=======';
14
7
  const MERGE_CONFLICT_OURS = '<<<<<<<';
15
- function autofixMergeConflicts(fileContent) {
8
+ export function autofixMergeConflicts(fileContent) {
16
9
  const { ours, theirs } = parseMergeFile(fileContent);
17
- return (0, lockfile_merger_1.mergeLockfileChanges)((0, lockfileFormatConverters_js_1.convertToLockfileObject)(js_yaml_1.default.load(ours)), (0, lockfileFormatConverters_js_1.convertToLockfileObject)(js_yaml_1.default.load(theirs)));
10
+ return mergeLockfileChanges(convertToLockfileObject(yaml.load(ours)), convertToLockfileObject(yaml.load(theirs)));
18
11
  }
19
12
  function parseMergeFile(fileContent) {
20
13
  const lines = fileContent.split(/[\n\r]+/);
@@ -46,7 +39,7 @@ function parseMergeFile(fileContent) {
46
39
  }
47
40
  return { ours: ours.join('\n'), theirs: theirs.join('\n') };
48
41
  }
49
- function isDiff(fileContent) {
42
+ export function isDiff(fileContent) {
50
43
  return fileContent.includes(MERGE_CONFLICT_OURS) &&
51
44
  fileContent.includes(MERGE_CONFLICT_THEIRS) &&
52
45
  fileContent.includes(MERGE_CONFLICT_END);
package/lib/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- export { isEmptyLockfile, writeLockfiles, writeCurrentLockfile, writeWantedLockfile, writeLockfileFile, } from './write.js';
1
+ export { createEnvLockfile, readEnvLockfile, writeEnvLockfile } from './envLockfile.js';
2
2
  export { existsNonEmptyWantedLockfile } from './existsWantedLockfile.js';
3
3
  export { getLockfileImporterId } from './getLockfileImporterId.js';
4
- export * from '@pnpm/lockfile.types';
5
- export * from './read.js';
6
4
  export { cleanGitBranchLockfiles } from './gitBranchLockfile.js';
7
- export { convertToLockfileFile } from './lockfileFormatConverters.js';
5
+ export { convertToLockfileFile, convertToLockfileObject } from './lockfileFormatConverters.js';
6
+ export * from './read.js';
7
+ export { isEmptyLockfile, writeCurrentLockfile, writeLockfileFile, writeLockfiles, writeWantedLockfile, } from './write.js';
8
+ export { extractMainDocument } from './yamlDocuments.js';
9
+ export * from '@pnpm/lockfile.types';
package/lib/index.js CHANGED
@@ -1,34 +1,10 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.convertToLockfileFile = exports.cleanGitBranchLockfiles = exports.getLockfileImporterId = exports.existsNonEmptyWantedLockfile = exports.writeLockfileFile = exports.writeWantedLockfile = exports.writeCurrentLockfile = exports.writeLockfiles = exports.isEmptyLockfile = void 0;
18
- var write_js_1 = require("./write.js");
19
- Object.defineProperty(exports, "isEmptyLockfile", { enumerable: true, get: function () { return write_js_1.isEmptyLockfile; } });
20
- Object.defineProperty(exports, "writeLockfiles", { enumerable: true, get: function () { return write_js_1.writeLockfiles; } });
21
- Object.defineProperty(exports, "writeCurrentLockfile", { enumerable: true, get: function () { return write_js_1.writeCurrentLockfile; } });
22
- Object.defineProperty(exports, "writeWantedLockfile", { enumerable: true, get: function () { return write_js_1.writeWantedLockfile; } });
23
- Object.defineProperty(exports, "writeLockfileFile", { enumerable: true, get: function () { return write_js_1.writeLockfileFile; } });
24
- var existsWantedLockfile_js_1 = require("./existsWantedLockfile.js");
25
- Object.defineProperty(exports, "existsNonEmptyWantedLockfile", { enumerable: true, get: function () { return existsWantedLockfile_js_1.existsNonEmptyWantedLockfile; } });
26
- var getLockfileImporterId_js_1 = require("./getLockfileImporterId.js");
27
- Object.defineProperty(exports, "getLockfileImporterId", { enumerable: true, get: function () { return getLockfileImporterId_js_1.getLockfileImporterId; } });
28
- __exportStar(require("@pnpm/lockfile.types"), exports);
29
- __exportStar(require("./read.js"), exports);
30
- var gitBranchLockfile_js_1 = require("./gitBranchLockfile.js");
31
- Object.defineProperty(exports, "cleanGitBranchLockfiles", { enumerable: true, get: function () { return gitBranchLockfile_js_1.cleanGitBranchLockfiles; } });
32
- var lockfileFormatConverters_js_1 = require("./lockfileFormatConverters.js");
33
- Object.defineProperty(exports, "convertToLockfileFile", { enumerable: true, get: function () { return lockfileFormatConverters_js_1.convertToLockfileFile; } });
1
+ export { createEnvLockfile, readEnvLockfile, writeEnvLockfile } from './envLockfile.js';
2
+ export { existsNonEmptyWantedLockfile } from './existsWantedLockfile.js';
3
+ export { getLockfileImporterId } from './getLockfileImporterId.js';
4
+ export { cleanGitBranchLockfiles } from './gitBranchLockfile.js';
5
+ export { convertToLockfileFile, convertToLockfileObject } from './lockfileFormatConverters.js';
6
+ export * from './read.js';
7
+ export { isEmptyLockfile, writeCurrentLockfile, writeLockfileFile, writeLockfiles, writeWantedLockfile, } from './write.js';
8
+ export { extractMainDocument } from './yamlDocuments.js';
9
+ export * from '@pnpm/lockfile.types';
34
10
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- import { type LockfileObject, type LockfileFile } from '@pnpm/lockfile.types';
1
+ import type { LockfileFile, LockfileObject } from '@pnpm/lockfile.types';
2
2
  export declare function convertToLockfileFile(lockfile: LockfileObject): LockfileFile;
3
3
  export declare function convertToLockfileObject(lockfile: LockfileFile): LockfileObject;
@@ -1,32 +1,21 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.convertToLockfileFile = convertToLockfileFile;
7
- exports.convertToLockfileObject = convertToLockfileObject;
8
- const dependency_path_1 = require("@pnpm/dependency-path");
9
- const types_1 = require("@pnpm/types");
10
- const isEmpty_1 = __importDefault(require("ramda/src/isEmpty"));
11
- const map_1 = __importDefault(require("ramda/src/map"));
12
- const omit_1 = __importDefault(require("ramda/src/omit"));
13
- const pickBy_1 = __importDefault(require("ramda/src/pickBy"));
14
- const pick_1 = __importDefault(require("ramda/src/pick"));
15
- const constants_1 = require("@pnpm/constants");
16
- function convertToLockfileFile(lockfile) {
1
+ import { LOCKFILE_VERSION } from '@pnpm/constants';
2
+ import { refToRelative, removeSuffix } from '@pnpm/deps.path';
3
+ import { DEPENDENCIES_FIELDS } from '@pnpm/types';
4
+ import { isEmpty, map as _mapValues, omit, pick, pickBy } from 'ramda';
5
+ export function convertToLockfileFile(lockfile) {
17
6
  const packages = {};
18
7
  const snapshots = {};
19
8
  for (const [depPath, pkg] of Object.entries(lockfile.packages ?? {})) {
20
- snapshots[depPath] = (0, pick_1.default)([
9
+ snapshots[depPath] = pick([
21
10
  'dependencies',
22
11
  'optionalDependencies',
23
12
  'transitivePeerDependencies',
24
13
  'optional',
25
14
  'id',
26
15
  ], pkg);
27
- const pkgId = (0, dependency_path_1.removeSuffix)(depPath);
16
+ const pkgId = removeSuffix(depPath);
28
17
  if (!packages[pkgId]) {
29
- packages[pkgId] = (0, pick_1.default)([
18
+ packages[pkgId] = pick([
30
19
  'bundledDependencies',
31
20
  'cpu',
32
21
  'deprecated',
@@ -46,11 +35,11 @@ function convertToLockfileFile(lockfile) {
46
35
  ...lockfile,
47
36
  snapshots,
48
37
  packages,
49
- lockfileVersion: constants_1.LOCKFILE_VERSION,
38
+ lockfileVersion: LOCKFILE_VERSION,
50
39
  importers: mapValues(lockfile.importers, convertProjectSnapshotToInlineSpecifiersFormat),
51
40
  };
52
41
  if (newLockfile.settings?.peersSuffixMaxLength === 1000) {
53
- newLockfile.settings = (0, omit_1.default)(['peersSuffixMaxLength'], newLockfile.settings);
42
+ newLockfile.settings = omit(['peersSuffixMaxLength'], newLockfile.settings);
54
43
  }
55
44
  if (newLockfile.settings?.injectWorkspacePackages === false) {
56
45
  delete newLockfile.settings.injectWorkspacePackages;
@@ -60,13 +49,13 @@ function convertToLockfileFile(lockfile) {
60
49
  function normalizeLockfile(lockfile) {
61
50
  const lockfileToSave = {
62
51
  ...lockfile,
63
- importers: (0, map_1.default)((importer) => {
52
+ importers: _mapValues((importer) => {
64
53
  const normalizedImporter = {};
65
- if (importer.dependenciesMeta != null && !(0, isEmpty_1.default)(importer.dependenciesMeta)) {
54
+ if (importer.dependenciesMeta != null && !isEmpty(importer.dependenciesMeta)) {
66
55
  normalizedImporter.dependenciesMeta = importer.dependenciesMeta;
67
56
  }
68
- for (const depType of types_1.DEPENDENCIES_FIELDS) {
69
- if (!(0, isEmpty_1.default)(importer[depType] ?? {})) {
57
+ for (const depType of DEPENDENCIES_FIELDS) {
58
+ if (!isEmpty(importer[depType] ?? {})) {
70
59
  normalizedImporter[depType] = importer[depType];
71
60
  }
72
61
  }
@@ -76,22 +65,22 @@ function normalizeLockfile(lockfile) {
76
65
  return normalizedImporter;
77
66
  }, lockfile.importers ?? {}),
78
67
  };
79
- if ((0, isEmpty_1.default)(lockfileToSave.packages) || (lockfileToSave.packages == null)) {
68
+ if (isEmpty(lockfileToSave.packages) || (lockfileToSave.packages == null)) {
80
69
  delete lockfileToSave.packages;
81
70
  }
82
- if ((0, isEmpty_1.default)(lockfileToSave.snapshots) || (lockfileToSave.snapshots == null)) {
71
+ if (isEmpty(lockfileToSave.snapshots) || (lockfileToSave.snapshots == null)) {
83
72
  delete lockfileToSave.snapshots;
84
73
  }
85
74
  if (lockfileToSave.time) {
86
75
  lockfileToSave.time = pruneTimeInLockfile(lockfileToSave.time, lockfile.importers ?? {});
87
76
  }
88
- if ((lockfileToSave.catalogs != null) && (0, isEmpty_1.default)(lockfileToSave.catalogs)) {
77
+ if ((lockfileToSave.catalogs != null) && isEmpty(lockfileToSave.catalogs)) {
89
78
  delete lockfileToSave.catalogs;
90
79
  }
91
- if ((lockfileToSave.overrides != null) && (0, isEmpty_1.default)(lockfileToSave.overrides)) {
80
+ if ((lockfileToSave.overrides != null) && isEmpty(lockfileToSave.overrides)) {
92
81
  delete lockfileToSave.overrides;
93
82
  }
94
- if ((lockfileToSave.patchedDependencies != null) && (0, isEmpty_1.default)(lockfileToSave.patchedDependencies)) {
83
+ if ((lockfileToSave.patchedDependencies != null) && isEmpty(lockfileToSave.patchedDependencies)) {
95
84
  delete lockfileToSave.patchedDependencies;
96
85
  }
97
86
  if (!lockfileToSave.packageExtensionsChecksum) {
@@ -108,7 +97,7 @@ function normalizeLockfile(lockfile) {
108
97
  function pruneTimeInLockfile(time, importers) {
109
98
  const rootDepPaths = new Set();
110
99
  for (const importer of Object.values(importers)) {
111
- for (const depType of types_1.DEPENDENCIES_FIELDS) {
100
+ for (const depType of DEPENDENCIES_FIELDS) {
112
101
  for (const [depName, ref] of Object.entries(importer[depType] ?? {})) {
113
102
  const suffixStart = ref.version.indexOf('(');
114
103
  const refWithoutPeerDepGraphHash = suffixStart === -1 ? ref.version : ref.version.slice(0, suffixStart);
@@ -119,33 +108,31 @@ function pruneTimeInLockfile(time, importers) {
119
108
  }
120
109
  }
121
110
  }
122
- return (0, pickBy_1.default)((_, depPath) => rootDepPaths.has(depPath), time);
111
+ return pickBy((_, depPath) => rootDepPaths.has(depPath), time);
123
112
  }
124
- function refToRelative(reference, pkgName) {
125
- if (reference.startsWith('link:')) {
126
- return null;
127
- }
128
- if (reference.startsWith('file:')) {
129
- return reference;
130
- }
131
- if (!reference.includes('/') || !reference.replace(/(?:\([^)]+\))+$/, '').includes('/')) {
132
- return `/${pkgName}@${reference}`;
133
- }
134
- return reference;
135
- }
136
- function convertToLockfileObject(lockfile) {
113
+ export function convertToLockfileObject(lockfile) {
137
114
  const { importers, ...rest } = lockfile;
138
115
  const packages = {};
139
116
  for (const [depPath, pkg] of Object.entries(lockfile.snapshots ?? {})) {
140
- const pkgId = (0, dependency_path_1.removeSuffix)(depPath);
117
+ const pkgId = removeSuffix(depPath);
141
118
  packages[depPath] = Object.assign(pkg, lockfile.packages?.[pkgId]);
142
119
  }
143
120
  return {
144
- ...(0, omit_1.default)(['snapshots'], rest),
121
+ ...omit(['snapshots'], rest),
122
+ patchedDependencies: migratePatchedDependencies(rest.patchedDependencies),
145
123
  packages,
146
124
  importers: mapValues(importers ?? {}, revertProjectSnapshot),
147
125
  };
148
126
  }
127
+ function migratePatchedDependencies(patchedDependencies) {
128
+ if (!patchedDependencies)
129
+ return undefined;
130
+ const result = {};
131
+ for (const [key, value] of Object.entries(patchedDependencies)) {
132
+ result[key] = typeof value === 'string' ? value : value.hash;
133
+ }
134
+ return result;
135
+ }
149
136
  function convertProjectSnapshotToInlineSpecifiersFormat(projectSnapshot) {
150
137
  const { specifiers, ...rest } = projectSnapshot;
151
138
  if (specifiers == null)
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWantedLockfileName = getWantedLockfileName;
4
- const constants_1 = require("@pnpm/constants");
5
- const git_utils_1 = require("@pnpm/git-utils");
6
- async function getWantedLockfileName(opts = { useGitBranchLockfile: false, mergeGitBranchLockfiles: false }) {
1
+ import { WANTED_LOCKFILE } from '@pnpm/constants';
2
+ import { getCurrentBranch } from '@pnpm/network.git-utils';
3
+ export async function getWantedLockfileName(opts = { useGitBranchLockfile: false, mergeGitBranchLockfiles: false }) {
7
4
  if (opts.useGitBranchLockfile && !opts.mergeGitBranchLockfiles) {
8
- const currentBranchName = await (0, git_utils_1.getCurrentBranch)();
5
+ const currentBranchName = await getCurrentBranch();
9
6
  if (currentBranchName) {
10
- return constants_1.WANTED_LOCKFILE.replace('.yaml', `.${stringifyBranchName(currentBranchName)}.yaml`);
7
+ return WANTED_LOCKFILE.replace('.yaml', `.${stringifyBranchName(currentBranchName)}.yaml`);
11
8
  }
12
9
  }
13
- return constants_1.WANTED_LOCKFILE;
10
+ return WANTED_LOCKFILE;
14
11
  }
15
12
  /**
16
13
  * 1. Git branch name may contains slashes, which is not allowed in filenames
package/lib/logger.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lockfileLogger = void 0;
4
- const logger_1 = require("@pnpm/logger");
5
- exports.lockfileLogger = (0, logger_1.logger)('lockfile');
1
+ import { logger } from '@pnpm/logger';
2
+ export const lockfileLogger = logger('lockfile');
6
3
  //# sourceMappingURL=logger.js.map
package/lib/read.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type LockfileObject } from '@pnpm/lockfile.types';
2
- import { type ProjectId } from '@pnpm/types';
1
+ import type { LockfileObject } from '@pnpm/lockfile.types';
2
+ import type { ProjectId } from '@pnpm/types';
3
3
  export declare function readCurrentLockfile(pnpmInternalDir: string, opts: {
4
4
  wantedVersions?: string[];
5
5
  ignoreIncompatible: boolean;