@pnpm/lockfile.fs 1.0.0

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 (48) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +58 -0
  3. package/lib/errors/LockfileBreakingChangeError.d.ts +5 -0
  4. package/lib/errors/LockfileBreakingChangeError.js +12 -0
  5. package/lib/errors/LockfileBreakingChangeError.js.map +1 -0
  6. package/lib/errors/index.d.ts +1 -0
  7. package/lib/errors/index.js +6 -0
  8. package/lib/errors/index.js.map +1 -0
  9. package/lib/existsWantedLockfile.d.ts +6 -0
  10. package/lib/existsWantedLockfile.js +30 -0
  11. package/lib/existsWantedLockfile.js.map +1 -0
  12. package/lib/experiments/InlineSpecifiersLockfile.d.ts +33 -0
  13. package/lib/experiments/InlineSpecifiersLockfile.js +5 -0
  14. package/lib/experiments/InlineSpecifiersLockfile.js.map +1 -0
  15. package/lib/experiments/inlineSpecifiersLockfileConverters.d.ts +7 -0
  16. package/lib/experiments/inlineSpecifiersLockfileConverters.js +237 -0
  17. package/lib/experiments/inlineSpecifiersLockfileConverters.js.map +1 -0
  18. package/lib/getLockfileImporterId.d.ts +2 -0
  19. package/lib/getLockfileImporterId.js +13 -0
  20. package/lib/getLockfileImporterId.js.map +1 -0
  21. package/lib/gitBranchLockfile.d.ts +2 -0
  22. package/lib/gitBranchLockfile.js +23 -0
  23. package/lib/gitBranchLockfile.js.map +1 -0
  24. package/lib/gitMergeFile.d.ts +3 -0
  25. package/lib/gitMergeFile.js +55 -0
  26. package/lib/gitMergeFile.js.map +1 -0
  27. package/lib/index.d.ts +6 -0
  28. package/lib/index.js +31 -0
  29. package/lib/index.js.map +1 -0
  30. package/lib/lockfileFormatConverters.d.ts +7 -0
  31. package/lib/lockfileFormatConverters.js +356 -0
  32. package/lib/lockfileFormatConverters.js.map +1 -0
  33. package/lib/lockfileName.d.ts +5 -0
  34. package/lib/lockfileName.js +23 -0
  35. package/lib/lockfileName.js.map +1 -0
  36. package/lib/logger.d.ts +1 -0
  37. package/lib/logger.js +6 -0
  38. package/lib/logger.js.map +1 -0
  39. package/lib/read.d.ts +27 -0
  40. package/lib/read.js +158 -0
  41. package/lib/read.js.map +1 -0
  42. package/lib/sortLockfileKeys.d.ts +2 -0
  43. package/lib/sortLockfileKeys.js +104 -0
  44. package/lib/sortLockfileKeys.js.map +1 -0
  45. package/lib/write.d.ts +15 -0
  46. package/lib/write.js +110 -0
  47. package/lib/write.js.map +1 -0
  48. package/package.json +72 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2024 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @pnpm/lockfile.fs
2
+
3
+ > Read/write pnpm-lock.yaml files
4
+
5
+ Reads and writes the wanted (`pnpm-lock.yaml`) and current (`node_modules/.pnpm-lock.yaml`) lockfile files of pnpm.
6
+ Lockfile files are the state files of the `node_modules` installed via pnpm. They are like
7
+ the `package-lock.json` of npm or the `yarn.lock` of Yarn.
8
+
9
+ ## Install
10
+
11
+ ```
12
+ pnpm add @pnpm/lockfile.fs
13
+ ```
14
+
15
+ ## API
16
+
17
+ ### `readWantedLockfile(pkgPath, opts) => Promise<Lockfile>`
18
+
19
+ Reads the `pnpm-lock.yaml` file from the root of the package.
20
+
21
+ #### Arguments
22
+
23
+ * `pkgPath` - *Path* - the path to the project
24
+ * `opts.ignoreIncompatible` - *Boolean* - `false` by default. If `true`, throws an error
25
+ if the lockfile file format is not compatible with the current library.
26
+
27
+ ### `readCurrentLockfile(virtualStoreDir, opts) => Promise<Lockfile>`
28
+
29
+ Reads the lockfile file from `<virtualStoreDir>/lock.yaml`.
30
+
31
+ ### `existsNonEmptyWantedLockfile(pkgPath) => Promise<Boolean>`
32
+
33
+ Returns `true` if a `pnpm-lock.yaml` exists in the root of the package.
34
+
35
+ ### `writeLockfiles(opts) => Promise<void>`
36
+
37
+ Writes the wanted/current lockfile files. When they are empty, removes them.
38
+
39
+ #### Arguments
40
+
41
+ * `opts.wantedLockfile`
42
+ * `opts.wantedLockfileDir`
43
+ * `opts.currentLockfile`
44
+ * `opts.currentLockfileDir`
45
+ * `[opts.forceSharedFormat]`
46
+
47
+ ### `writeWantedLockfile(pkgPath, wantedLockfile) => Promise<void>`
48
+
49
+ Writes the wanted lockfile file only. Sometimes it is needed just to update the wanted lockfile
50
+ without touching `node_modules`.
51
+
52
+ ### `writeCurrentLockfile(virtualStoreDir, currentLockfile) => Promise<void>`
53
+
54
+ Writes the current lockfile file only.
55
+
56
+ ## License
57
+
58
+ [MIT](LICENSE)
@@ -0,0 +1,5 @@
1
+ import { PnpmError } from '@pnpm/error';
2
+ export declare class LockfileBreakingChangeError extends PnpmError {
3
+ filename: string;
4
+ constructor(filename: string);
5
+ }
@@ -0,0 +1,12 @@
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 {
6
+ constructor(filename) {
7
+ super('LOCKFILE_BREAKING_CHANGE', `Lockfile ${filename} not compatible with current pnpm`);
8
+ this.filename = filename;
9
+ }
10
+ }
11
+ exports.LockfileBreakingChangeError = LockfileBreakingChangeError;
12
+ //# sourceMappingURL=LockfileBreakingChangeError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LockfileBreakingChangeError.js","sourceRoot":"","sources":["../../src/errors/LockfileBreakingChangeError.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AAEvC,MAAa,2BAA4B,SAAQ,iBAAS;IAExD,YAAa,QAAgB;QAC3B,KAAK,CAAC,0BAA0B,EAAE,YAAY,QAAQ,mCAAmC,CAAC,CAAA;QAC1F,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF;AAND,kEAMC"}
@@ -0,0 +1 @@
1
+ export { LockfileBreakingChangeError } from './LockfileBreakingChangeError';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LockfileBreakingChangeError = void 0;
4
+ var LockfileBreakingChangeError_1 = require("./LockfileBreakingChangeError");
5
+ Object.defineProperty(exports, "LockfileBreakingChangeError", { enumerable: true, get: function () { return LockfileBreakingChangeError_1.LockfileBreakingChangeError; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,6EAA2E;AAAlE,0IAAA,2BAA2B,OAAA"}
@@ -0,0 +1,6 @@
1
+ interface existsNonEmptyWantedLockfileOptions {
2
+ useGitBranchLockfile?: boolean;
3
+ mergeGitBranchLockfiles?: boolean;
4
+ }
5
+ export declare function existsNonEmptyWantedLockfile(pkgPath: string, opts?: existsNonEmptyWantedLockfileOptions): Promise<boolean>;
6
+ export {};
@@ -0,0 +1,30 @@
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 = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const lockfileName_1 = require("./lockfileName");
10
+ async function existsNonEmptyWantedLockfile(pkgPath, opts = {
11
+ useGitBranchLockfile: false,
12
+ mergeGitBranchLockfiles: false,
13
+ }) {
14
+ const wantedLockfile = await (0, lockfileName_1.getWantedLockfileName)(opts);
15
+ return new Promise((resolve, reject) => {
16
+ fs_1.default.access(path_1.default.join(pkgPath, wantedLockfile), (err) => {
17
+ if (err == null) {
18
+ resolve(true);
19
+ return;
20
+ }
21
+ if (err.code === 'ENOENT') {
22
+ resolve(false);
23
+ return;
24
+ }
25
+ reject(err);
26
+ });
27
+ });
28
+ }
29
+ exports.existsNonEmptyWantedLockfile = existsNonEmptyWantedLockfile;
30
+ //# sourceMappingURL=existsWantedLockfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"existsWantedLockfile.js","sourceRoot":"","sources":["../src/existsWantedLockfile.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,iDAAsD;AAO/C,KAAK,UAAU,4BAA4B,CAAE,OAAe,EAAE,OAA4C;IAC/G,oBAAoB,EAAE,KAAK;IAC3B,uBAAuB,EAAE,KAAK;CAC/B;IACC,MAAM,cAAc,GAAW,MAAM,IAAA,oCAAqB,EAAC,IAAI,CAAC,CAAA;IAChE,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,YAAE,CAAC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;YACpD,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;gBAChB,OAAO,CAAC,IAAI,CAAC,CAAA;gBACb,OAAM;YACR,CAAC;YACD,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC1B,OAAO,CAAC,KAAK,CAAC,CAAA;gBACd,OAAM;YACR,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,CAAA;QACb,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAlBD,oEAkBC"}
@@ -0,0 +1,33 @@
1
+ import type { Lockfile } from '@pnpm/lockfile-types';
2
+ import type { DependenciesMeta } from '@pnpm/types';
3
+ export declare const INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX = "-inlineSpecifiers";
4
+ /**
5
+ * Similar to the current Lockfile importers format (lockfile version 5.4 at
6
+ * time of writing), but specifiers are moved to each ResolvedDependencies block
7
+ * instead of being declared on its own dictionary.
8
+ *
9
+ * This is an experiment to reduce one flavor of merge conflicts in lockfiles.
10
+ * For more info: https://github.com/pnpm/pnpm/issues/4725.
11
+ */
12
+ export interface InlineSpecifiersLockfile extends Omit<Lockfile, 'lockfileVersion' | 'importers'> {
13
+ lockfileVersion: string;
14
+ importers: Record<string, InlineSpecifiersProjectSnapshot>;
15
+ }
16
+ /**
17
+ * Similar to the current ProjectSnapshot interface, but omits the "specifiers"
18
+ * field in favor of inlining each specifier next to its version resolution in
19
+ * dependency blocks.
20
+ */
21
+ export interface InlineSpecifiersProjectSnapshot {
22
+ dependencies?: InlineSpecifiersResolvedDependencies;
23
+ devDependencies?: InlineSpecifiersResolvedDependencies;
24
+ optionalDependencies?: InlineSpecifiersResolvedDependencies;
25
+ dependenciesMeta?: DependenciesMeta;
26
+ }
27
+ export interface InlineSpecifiersResolvedDependencies {
28
+ [depName: string]: SpecifierAndResolution;
29
+ }
30
+ export interface SpecifierAndResolution {
31
+ specifier: string;
32
+ version: string;
33
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX = void 0;
4
+ exports.INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX = '-inlineSpecifiers';
5
+ //# sourceMappingURL=InlineSpecifiersLockfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InlineSpecifiersLockfile.js","sourceRoot":"","sources":["../../src/experiments/InlineSpecifiersLockfile.ts"],"names":[],"mappings":";;;AAGa,QAAA,gDAAgD,GAAG,mBAAmB,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { Lockfile } from '@pnpm/lockfile-types';
2
+ import { type InlineSpecifiersLockfile } from './InlineSpecifiersLockfile';
3
+ export declare function isExperimentalInlineSpecifiersFormat(lockfile: InlineSpecifiersLockfile | Lockfile): lockfile is InlineSpecifiersLockfile;
4
+ export declare function convertToInlineSpecifiersFormat(lockfile: Lockfile): InlineSpecifiersLockfile;
5
+ export declare function revertFromInlineSpecifiersFormatIfNecessary(lockfile: Lockfile | InlineSpecifiersLockfile): Lockfile;
6
+ export declare function revertFromInlineSpecifiersFormat(lockfile: InlineSpecifiersLockfile): Lockfile;
7
+ export declare function convertLockfileV6DepPathToV5DepPath(newDepPath: string): string;
@@ -0,0 +1,237 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.convertLockfileV6DepPathToV5DepPath = exports.revertFromInlineSpecifiersFormat = exports.revertFromInlineSpecifiersFormatIfNecessary = exports.convertToInlineSpecifiersFormat = exports.isExperimentalInlineSpecifiersFormat = void 0;
27
+ const dp = __importStar(require("@pnpm/dependency-path"));
28
+ const InlineSpecifiersLockfile_1 = require("./InlineSpecifiersLockfile");
29
+ function isExperimentalInlineSpecifiersFormat(lockfile) {
30
+ const { lockfileVersion } = lockfile;
31
+ return lockfileVersion.toString().startsWith('6.') || typeof lockfileVersion === 'string' && lockfileVersion.endsWith(InlineSpecifiersLockfile_1.INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX);
32
+ }
33
+ exports.isExperimentalInlineSpecifiersFormat = isExperimentalInlineSpecifiersFormat;
34
+ function convertToInlineSpecifiersFormat(lockfile) {
35
+ let importers = lockfile.importers;
36
+ let packages = lockfile.packages;
37
+ if (lockfile.lockfileVersion.toString().startsWith('6.')) {
38
+ importers = Object.fromEntries(Object.entries(lockfile.importers ?? {})
39
+ .map(([importerId, pkgSnapshot]) => {
40
+ const newSnapshot = { ...pkgSnapshot };
41
+ if (newSnapshot.dependencies != null) {
42
+ newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertOldRefToNewRef);
43
+ }
44
+ if (newSnapshot.optionalDependencies != null) {
45
+ newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertOldRefToNewRef);
46
+ }
47
+ if (newSnapshot.devDependencies != null) {
48
+ newSnapshot.devDependencies = mapValues(newSnapshot.devDependencies, convertOldRefToNewRef);
49
+ }
50
+ return [importerId, newSnapshot];
51
+ }));
52
+ packages = Object.fromEntries(Object.entries(lockfile.packages ?? {})
53
+ .map(([depPath, pkgSnapshot]) => {
54
+ const newSnapshot = { ...pkgSnapshot };
55
+ if (newSnapshot.dependencies != null) {
56
+ newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertOldRefToNewRef);
57
+ }
58
+ if (newSnapshot.optionalDependencies != null) {
59
+ newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertOldRefToNewRef);
60
+ }
61
+ return [convertOldDepPathToNewDepPath(depPath), newSnapshot];
62
+ }));
63
+ }
64
+ const newLockfile = {
65
+ ...lockfile,
66
+ packages,
67
+ lockfileVersion: lockfile.lockfileVersion.toString().startsWith('6.')
68
+ ? lockfile.lockfileVersion.toString()
69
+ : (lockfile.lockfileVersion.toString().endsWith(InlineSpecifiersLockfile_1.INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX)
70
+ ? lockfile.lockfileVersion.toString()
71
+ : `${lockfile.lockfileVersion}${InlineSpecifiersLockfile_1.INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX}`),
72
+ importers: mapValues(importers, convertProjectSnapshotToInlineSpecifiersFormat),
73
+ };
74
+ if (lockfile.lockfileVersion.toString().startsWith('6.') && newLockfile.time) {
75
+ newLockfile.time = Object.fromEntries(Object.entries(newLockfile.time)
76
+ .map(([depPath, time]) => [convertOldDepPathToNewDepPath(depPath), time]));
77
+ }
78
+ return newLockfile;
79
+ }
80
+ exports.convertToInlineSpecifiersFormat = convertToInlineSpecifiersFormat;
81
+ function convertOldDepPathToNewDepPath(oldDepPath) {
82
+ const parsedDepPath = dp.parse(oldDepPath);
83
+ if (!parsedDepPath.name || !parsedDepPath.version)
84
+ return oldDepPath;
85
+ let newDepPath = `/${parsedDepPath.name}@${parsedDepPath.version}`;
86
+ if (parsedDepPath.peersSuffix) {
87
+ if (parsedDepPath.peersSuffix.startsWith('(')) {
88
+ newDepPath += parsedDepPath.peersSuffix;
89
+ }
90
+ else {
91
+ newDepPath += `_${parsedDepPath.peersSuffix}`;
92
+ }
93
+ }
94
+ if (parsedDepPath.host) {
95
+ newDepPath = `${parsedDepPath.host}${newDepPath}`;
96
+ }
97
+ return newDepPath;
98
+ }
99
+ function convertOldRefToNewRef(oldRef) {
100
+ if (oldRef.startsWith('link:') || oldRef.startsWith('file:')) {
101
+ return oldRef;
102
+ }
103
+ if (oldRef.includes('/')) {
104
+ return convertOldDepPathToNewDepPath(oldRef);
105
+ }
106
+ return oldRef;
107
+ }
108
+ function revertFromInlineSpecifiersFormatIfNecessary(lockfile) {
109
+ return isExperimentalInlineSpecifiersFormat(lockfile)
110
+ ? revertFromInlineSpecifiersFormat(lockfile)
111
+ : lockfile;
112
+ }
113
+ exports.revertFromInlineSpecifiersFormatIfNecessary = revertFromInlineSpecifiersFormatIfNecessary;
114
+ function revertFromInlineSpecifiersFormat(lockfile) {
115
+ const { lockfileVersion, importers, ...rest } = lockfile;
116
+ const originalVersionStr = lockfileVersion.replace(InlineSpecifiersLockfile_1.INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX, '');
117
+ const originalVersion = Number(originalVersionStr);
118
+ if (isNaN(originalVersion)) {
119
+ throw new Error(`Unable to revert lockfile from inline specifiers format. Invalid version parsed: ${originalVersionStr}`);
120
+ }
121
+ let revertedImporters = mapValues(importers, revertProjectSnapshot);
122
+ let packages = lockfile.packages;
123
+ if (originalVersionStr.startsWith('6.')) {
124
+ revertedImporters = Object.fromEntries(Object.entries(revertedImporters ?? {})
125
+ .map(([importerId, pkgSnapshot]) => {
126
+ const newSnapshot = { ...pkgSnapshot };
127
+ if (newSnapshot.dependencies != null) {
128
+ newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertNewRefToOldRef);
129
+ }
130
+ if (newSnapshot.optionalDependencies != null) {
131
+ newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertNewRefToOldRef);
132
+ }
133
+ if (newSnapshot.devDependencies != null) {
134
+ newSnapshot.devDependencies = mapValues(newSnapshot.devDependencies, convertNewRefToOldRef);
135
+ }
136
+ return [importerId, newSnapshot];
137
+ }));
138
+ packages = Object.fromEntries(Object.entries(lockfile.packages ?? {})
139
+ .map(([depPath, pkgSnapshot]) => {
140
+ const newSnapshot = { ...pkgSnapshot };
141
+ if (newSnapshot.dependencies != null) {
142
+ newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertNewRefToOldRef);
143
+ }
144
+ if (newSnapshot.optionalDependencies != null) {
145
+ newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertNewRefToOldRef);
146
+ }
147
+ return [convertLockfileV6DepPathToV5DepPath(depPath), newSnapshot];
148
+ }));
149
+ }
150
+ const newLockfile = {
151
+ ...rest,
152
+ lockfileVersion: lockfileVersion.endsWith(InlineSpecifiersLockfile_1.INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX) ? originalVersion : lockfileVersion,
153
+ packages,
154
+ importers: revertedImporters,
155
+ };
156
+ if (originalVersionStr.startsWith('6.') && newLockfile.time) {
157
+ newLockfile.time = Object.fromEntries(Object.entries(newLockfile.time)
158
+ .map(([depPath, time]) => [convertLockfileV6DepPathToV5DepPath(depPath), time]));
159
+ }
160
+ return newLockfile;
161
+ }
162
+ exports.revertFromInlineSpecifiersFormat = revertFromInlineSpecifiersFormat;
163
+ function convertLockfileV6DepPathToV5DepPath(newDepPath) {
164
+ if (!newDepPath.includes('@', 2) || newDepPath.startsWith('file:'))
165
+ return newDepPath;
166
+ const index = newDepPath.indexOf('@', newDepPath.indexOf('/@') + 2);
167
+ if (newDepPath.includes('(') && index > dp.indexOfPeersSuffix(newDepPath))
168
+ return newDepPath;
169
+ return `${newDepPath.substring(0, index)}/${newDepPath.substring(index + 1)}`;
170
+ }
171
+ exports.convertLockfileV6DepPathToV5DepPath = convertLockfileV6DepPathToV5DepPath;
172
+ function convertNewRefToOldRef(oldRef) {
173
+ if (oldRef.startsWith('link:') || oldRef.startsWith('file:')) {
174
+ return oldRef;
175
+ }
176
+ if (oldRef.includes('@')) {
177
+ return convertLockfileV6DepPathToV5DepPath(oldRef);
178
+ }
179
+ return oldRef;
180
+ }
181
+ function convertProjectSnapshotToInlineSpecifiersFormat(projectSnapshot) {
182
+ const { specifiers, ...rest } = projectSnapshot;
183
+ const convertBlock = (block) => block != null
184
+ ? convertResolvedDependenciesToInlineSpecifiersFormat(block, { specifiers })
185
+ : block;
186
+ return {
187
+ ...rest,
188
+ dependencies: convertBlock(projectSnapshot.dependencies),
189
+ optionalDependencies: convertBlock(projectSnapshot.optionalDependencies),
190
+ devDependencies: convertBlock(projectSnapshot.devDependencies),
191
+ };
192
+ }
193
+ function convertResolvedDependenciesToInlineSpecifiersFormat(resolvedDependencies, { specifiers }) {
194
+ return mapValues(resolvedDependencies, (version, depName) => ({
195
+ specifier: specifiers[depName],
196
+ version,
197
+ }));
198
+ }
199
+ function revertProjectSnapshot(from) {
200
+ const specifiers = {};
201
+ function moveSpecifiers(from) {
202
+ const resolvedDependencies = {};
203
+ for (const [depName, { specifier, version }] of Object.entries(from)) {
204
+ const existingValue = specifiers[depName];
205
+ if (existingValue != null && existingValue !== specifier) {
206
+ throw new Error(`Project snapshot lists the same dependency more than once with conflicting versions: ${depName}`);
207
+ }
208
+ specifiers[depName] = specifier;
209
+ resolvedDependencies[depName] = version;
210
+ }
211
+ return resolvedDependencies;
212
+ }
213
+ const dependencies = from.dependencies == null
214
+ ? from.dependencies
215
+ : moveSpecifiers(from.dependencies);
216
+ const devDependencies = from.devDependencies == null
217
+ ? from.devDependencies
218
+ : moveSpecifiers(from.devDependencies);
219
+ const optionalDependencies = from.optionalDependencies == null
220
+ ? from.optionalDependencies
221
+ : moveSpecifiers(from.optionalDependencies);
222
+ return {
223
+ ...from,
224
+ specifiers,
225
+ dependencies,
226
+ devDependencies,
227
+ optionalDependencies,
228
+ };
229
+ }
230
+ function mapValues(obj, mapper) {
231
+ const result = {};
232
+ for (const [key, value] of Object.entries(obj)) {
233
+ result[key] = mapper(value, key);
234
+ }
235
+ return result;
236
+ }
237
+ //# sourceMappingURL=inlineSpecifiersLockfileConverters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inlineSpecifiersLockfileConverters.js","sourceRoot":"","sources":["../../src/experiments/inlineSpecifiersLockfileConverters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA2C;AAE3C,yEAKmC;AAEnC,SAAgB,oCAAoC,CAClD,QAA6C;IAE7C,MAAM,EAAE,eAAe,EAAE,GAAG,QAAQ,CAAA;IACpC,OAAO,eAAe,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,OAAO,eAAe,KAAK,QAAQ,IAAI,eAAe,CAAC,QAAQ,CAAC,2EAAgD,CAAC,CAAA;AACzK,CAAC;AALD,oFAKC;AAED,SAAgB,+BAA+B,CAAE,QAAkB;IACjE,IAAI,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAA;IAClC,IAAI,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAA;IAChC,IAAI,QAAQ,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzD,SAAS,GAAG,MAAM,CAAC,WAAW,CAC5B,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC;aACrC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,WAAW,CAA4B,EAAE,EAAE;YAC5D,MAAM,WAAW,GAAG,EAAE,GAAG,WAAW,EAAE,CAAA;YACtC,IAAI,WAAW,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC;gBACrC,WAAW,CAAC,YAAY,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,EAAE,qBAAqB,CAAC,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AAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { type ProjectId } from '@pnpm/types';
2
+ export declare function getLockfileImporterId(lockfileDir: string, prefix: string): ProjectId;
@@ -0,0 +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.getLockfileImporterId = void 0;
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)) || '.');
11
+ }
12
+ exports.getLockfileImporterId = getLockfileImporterId;
13
+ //# sourceMappingURL=getLockfileImporterId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLockfileImporterId.js","sourceRoot":"","sources":["../src/getLockfileImporterId.ts"],"names":[],"mappings":";;;;;;AACA,gDAAuB;AACvB,oEAAsC;AAEtC,SAAgB,qBAAqB,CAAE,WAAmB,EAAE,MAAc;IACxE,OAAO,CAAC,IAAA,wBAAS,EAAC,cAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,IAAI,GAAG,CAAc,CAAA;AAC5E,CAAC;AAFD,sDAEC"}
@@ -0,0 +1,2 @@
1
+ export declare function getGitBranchLockfileNames(lockfileDir: string): Promise<string[]>;
2
+ export declare function cleanGitBranchLockfiles(lockfileDir: string): Promise<void>;
@@ -0,0 +1,23 @@
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.cleanGitBranchLockfiles = exports.getGitBranchLockfileNames = void 0;
7
+ const fs_1 = require("fs");
8
+ const path_1 = __importDefault(require("path"));
9
+ async function getGitBranchLockfileNames(lockfileDir) {
10
+ const files = await fs_1.promises.readdir(lockfileDir);
11
+ const gitBranchLockfileNames = files.filter(file => file.match(/^pnpm-lock.(?:.*).yaml$/));
12
+ return gitBranchLockfileNames;
13
+ }
14
+ exports.getGitBranchLockfileNames = getGitBranchLockfileNames;
15
+ async function cleanGitBranchLockfiles(lockfileDir) {
16
+ const gitBranchLockfiles = await getGitBranchLockfileNames(lockfileDir);
17
+ await Promise.all(gitBranchLockfiles.map(async (file) => {
18
+ const filepath = path_1.default.join(lockfileDir, file);
19
+ await fs_1.promises.unlink(filepath);
20
+ }));
21
+ }
22
+ exports.cleanGitBranchLockfiles = cleanGitBranchLockfiles;
23
+ //# sourceMappingURL=gitBranchLockfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitBranchLockfile.js","sourceRoot":"","sources":["../src/gitBranchLockfile.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAmC;AACnC,gDAAuB;AAEhB,KAAK,UAAU,yBAAyB,CAAE,WAAmB;IAClE,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC3C,MAAM,sBAAsB,GAAa,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC,CAAA;IACpG,OAAO,sBAAsB,CAAA;AAC/B,CAAC;AAJD,8DAIC;AAEM,KAAK,UAAU,uBAAuB,CAAE,WAAmB;IAChE,MAAM,kBAAkB,GAAa,MAAM,yBAAyB,CAAC,WAAW,CAAC,CAAA;IACjF,MAAM,OAAO,CAAC,GAAG,CACf,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAC,IAAI,EAAC,EAAE;QAClC,MAAM,QAAQ,GAAW,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QACrD,MAAM,aAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC3B,CAAC,CAAC,CACH,CAAA;AACH,CAAC;AARD,0DAQC"}
@@ -0,0 +1,3 @@
1
+ import { type Lockfile } from '@pnpm/lockfile.types';
2
+ export declare function autofixMergeConflicts(fileContent: string): Lockfile;
3
+ export declare function isDiff(fileContent: string): boolean;
@@ -0,0 +1,55 @@
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.isDiff = exports.autofixMergeConflicts = void 0;
7
+ const lockfile_merger_1 = require("@pnpm/lockfile.merger");
8
+ const js_yaml_1 = __importDefault(require("js-yaml"));
9
+ const lockfileFormatConverters_1 = require("./lockfileFormatConverters");
10
+ const MERGE_CONFLICT_PARENT = '|||||||';
11
+ const MERGE_CONFLICT_END = '>>>>>>>';
12
+ const MERGE_CONFLICT_THEIRS = '=======';
13
+ const MERGE_CONFLICT_OURS = '<<<<<<<';
14
+ function autofixMergeConflicts(fileContent) {
15
+ const { ours, theirs } = parseMergeFile(fileContent);
16
+ return (0, lockfile_merger_1.mergeLockfileChanges)((0, lockfileFormatConverters_1.convertToLockfileObject)(js_yaml_1.default.load(ours)), (0, lockfileFormatConverters_1.convertToLockfileObject)(js_yaml_1.default.load(theirs)));
17
+ }
18
+ exports.autofixMergeConflicts = autofixMergeConflicts;
19
+ function parseMergeFile(fileContent) {
20
+ const lines = fileContent.split(/[\n\r]+/g);
21
+ let state = 'top';
22
+ const ours = [];
23
+ const theirs = [];
24
+ while (lines.length > 0) {
25
+ const line = lines.shift();
26
+ if (line.startsWith(MERGE_CONFLICT_PARENT)) {
27
+ state = 'parent';
28
+ continue;
29
+ }
30
+ if (line.startsWith(MERGE_CONFLICT_OURS)) {
31
+ state = 'ours';
32
+ continue;
33
+ }
34
+ if (line === MERGE_CONFLICT_THEIRS) {
35
+ state = 'theirs';
36
+ continue;
37
+ }
38
+ if (line.startsWith(MERGE_CONFLICT_END)) {
39
+ state = 'top';
40
+ continue;
41
+ }
42
+ if (state === 'top' || state === 'ours')
43
+ ours.push(line);
44
+ if (state === 'top' || state === 'theirs')
45
+ theirs.push(line);
46
+ }
47
+ return { ours: ours.join('\n'), theirs: theirs.join('\n') };
48
+ }
49
+ function isDiff(fileContent) {
50
+ return fileContent.includes(MERGE_CONFLICT_OURS) &&
51
+ fileContent.includes(MERGE_CONFLICT_THEIRS) &&
52
+ fileContent.includes(MERGE_CONFLICT_END);
53
+ }
54
+ exports.isDiff = isDiff;
55
+ //# sourceMappingURL=gitMergeFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitMergeFile.js","sourceRoot":"","sources":["../src/gitMergeFile.ts"],"names":[],"mappings":";;;;;;AACA,2DAA4D;AAC5D,sDAA0B;AAC1B,yEAAoE;AAEpE,MAAM,qBAAqB,GAAG,SAAS,CAAA;AACvC,MAAM,kBAAkB,GAAG,SAAS,CAAA;AACpC,MAAM,qBAAqB,GAAG,SAAS,CAAA;AACvC,MAAM,mBAAmB,GAAG,SAAS,CAAA;AAErC,SAAgB,qBAAqB,CAAE,WAAmB;IACxD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,WAAW,CAAC,CAAA;IACpD,OAAO,IAAA,sCAAoB,EACzB,IAAA,kDAAuB,EAAC,iBAAI,CAAC,IAAI,CAAC,IAAI,CAAiB,CAAC,EACxD,IAAA,kDAAuB,EAAC,iBAAI,CAAC,IAAI,CAAC,MAAM,CAAiB,CAAC,CAC3D,CAAA;AACH,CAAC;AAND,sDAMC;AAOD,SAAS,cAAc,CAAE,WAAmB;IAC1C,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CA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wBAIC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { isEmptyLockfile, writeLockfiles, writeCurrentLockfile, writeWantedLockfile, } from './write';
2
+ export { existsNonEmptyWantedLockfile } from './existsWantedLockfile';
3
+ export { getLockfileImporterId } from './getLockfileImporterId';
4
+ export * from '@pnpm/lockfile.types';
5
+ export * from './read';
6
+ export { cleanGitBranchLockfiles } from './gitBranchLockfile';
package/lib/index.js ADDED
@@ -0,0 +1,31 @@
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.cleanGitBranchLockfiles = exports.getLockfileImporterId = exports.existsNonEmptyWantedLockfile = exports.writeWantedLockfile = exports.writeCurrentLockfile = exports.writeLockfiles = exports.isEmptyLockfile = void 0;
18
+ var write_1 = require("./write");
19
+ Object.defineProperty(exports, "isEmptyLockfile", { enumerable: true, get: function () { return write_1.isEmptyLockfile; } });
20
+ Object.defineProperty(exports, "writeLockfiles", { enumerable: true, get: function () { return write_1.writeLockfiles; } });
21
+ Object.defineProperty(exports, "writeCurrentLockfile", { enumerable: true, get: function () { return write_1.writeCurrentLockfile; } });
22
+ Object.defineProperty(exports, "writeWantedLockfile", { enumerable: true, get: function () { return write_1.writeWantedLockfile; } });
23
+ var existsWantedLockfile_1 = require("./existsWantedLockfile");
24
+ Object.defineProperty(exports, "existsNonEmptyWantedLockfile", { enumerable: true, get: function () { return existsWantedLockfile_1.existsNonEmptyWantedLockfile; } });
25
+ var getLockfileImporterId_1 = require("./getLockfileImporterId");
26
+ Object.defineProperty(exports, "getLockfileImporterId", { enumerable: true, get: function () { return getLockfileImporterId_1.getLockfileImporterId; } });
27
+ __exportStar(require("@pnpm/lockfile.types"), exports);
28
+ __exportStar(require("./read"), exports);
29
+ var gitBranchLockfile_1 = require("./gitBranchLockfile");
30
+ Object.defineProperty(exports, "cleanGitBranchLockfiles", { enumerable: true, get: function () { return gitBranchLockfile_1.cleanGitBranchLockfiles; } });
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAKgB;AAJd,wGAAA,eAAe,OAAA;AACf,uGAAA,cAAc,OAAA;AACd,6GAAA,oBAAoB,OAAA;AACpB,4GAAA,mBAAmB,OAAA;AAErB,+DAAqE;AAA5D,oIAAA,4BAA4B,OAAA;AACrC,iEAA+D;AAAtD,8HAAA,qBAAqB,OAAA;AAC9B,uDAAoC;AACpC,yCAAsB;AACtB,yDAA6D;AAApD,4HAAA,uBAAuB,OAAA"}