@pnpm/lockfile-file
Advanced tools
Comparing version 5.0.4 to 5.1.0
@@ -1,2 +0,6 @@ | ||
declare const _default: (pkgPath: string) => Promise<unknown>; | ||
interface ExistsWantedLockfileOptions { | ||
useGitBranchLockfile?: boolean; | ||
mergeGitBranchLockfiles?: boolean; | ||
} | ||
declare const _default: (pkgPath: string, opts?: ExistsWantedLockfileOptions) => Promise<unknown>; | ||
export default _default; |
@@ -8,16 +8,22 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const constants_1 = require("@pnpm/constants"); | ||
exports.default = async (pkgPath) => new Promise((resolve, reject) => { | ||
fs_1.default.access(path_1.default.join(pkgPath, constants_1.WANTED_LOCKFILE), (err) => { | ||
if (err == null) { | ||
resolve(true); | ||
return; | ||
} | ||
if (err.code === 'ENOENT') { | ||
resolve(false); | ||
return; | ||
} | ||
reject(err); | ||
const lockfileName_1 = require("./lockfileName"); | ||
exports.default = async (pkgPath, opts = { | ||
useGitBranchLockfile: false, | ||
mergeGitBranchLockfiles: false, | ||
}) => { | ||
const wantedLockfile = await (0, lockfileName_1.getWantedLockfileName)(opts); | ||
return new Promise((resolve, reject) => { | ||
fs_1.default.access(path_1.default.join(pkgPath, wantedLockfile), (err) => { | ||
if (err == null) { | ||
resolve(true); | ||
return; | ||
} | ||
if (err.code === 'ENOENT') { | ||
resolve(false); | ||
return; | ||
} | ||
reject(err); | ||
}); | ||
}); | ||
}); | ||
}; | ||
//# sourceMappingURL=existsWantedLockfile.js.map |
@@ -7,1 +7,2 @@ import existsWantedLockfile from './existsWantedLockfile'; | ||
export { existsWantedLockfile, getLockfileImporterId, writeLockfiles, writeCurrentLockfile, writeWantedLockfile, }; | ||
export { cleanGitBranchLockfiles } from './gitBranchLockfile'; |
@@ -32,3 +32,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.writeWantedLockfile = exports.writeCurrentLockfile = exports.writeLockfiles = exports.getLockfileImporterId = exports.existsWantedLockfile = void 0; | ||
exports.cleanGitBranchLockfiles = exports.writeWantedLockfile = exports.writeCurrentLockfile = exports.writeLockfiles = exports.getLockfileImporterId = exports.existsWantedLockfile = void 0; | ||
const existsWantedLockfile_1 = __importDefault(require("./existsWantedLockfile")); | ||
@@ -44,2 +44,4 @@ exports.existsWantedLockfile = existsWantedLockfile_1.default; | ||
__exportStar(require("./read"), exports); | ||
var gitBranchLockfile_1 = require("./gitBranchLockfile"); | ||
Object.defineProperty(exports, "cleanGitBranchLockfiles", { enumerable: true, get: function () { return gitBranchLockfile_1.cleanGitBranchLockfiles; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -9,2 +9,4 @@ import { Lockfile } from '@pnpm/lockfile-types'; | ||
ignoreIncompatible: boolean; | ||
useGitBranchLockfile?: boolean; | ||
mergeGitBranchLockfiles?: boolean; | ||
}): Promise<{ | ||
@@ -17,2 +19,4 @@ lockfile: Lockfile | null; | ||
ignoreIncompatible: boolean; | ||
useGitBranchLockfile?: boolean; | ||
mergeGitBranchLockfiles?: boolean; | ||
}): Promise<Lockfile | null>; | ||
@@ -19,0 +23,0 @@ export declare function createLockfileObject(importerIds: string[], opts: { |
@@ -11,2 +11,3 @@ "use strict"; | ||
const error_1 = __importDefault(require("@pnpm/error")); | ||
const merge_lockfile_changes_1 = __importDefault(require("@pnpm/merge-lockfile-changes")); | ||
const types_1 = require("@pnpm/types"); | ||
@@ -20,2 +21,4 @@ const comver_to_semver_1 = __importDefault(require("comver-to-semver")); | ||
const logger_1 = __importDefault(require("./logger")); | ||
const lockfileName_1 = require("./lockfileName"); | ||
const gitBranchLockfile_1 = require("./gitBranchLockfile"); | ||
async function readCurrentLockfile(virtualStoreDir, opts) { | ||
@@ -27,9 +30,10 @@ const lockfilePath = path_1.default.join(virtualStoreDir, 'lock.yaml'); | ||
async function readWantedLockfileAndAutofixConflicts(pkgPath, opts) { | ||
const lockfilePath = path_1.default.join(pkgPath, constants_1.WANTED_LOCKFILE); | ||
return _read(lockfilePath, pkgPath, { ...opts, autofixMergeConflicts: true }); | ||
return _readWantedLockfile(pkgPath, { | ||
...opts, | ||
autofixMergeConflicts: true, | ||
}); | ||
} | ||
exports.readWantedLockfileAndAutofixConflicts = readWantedLockfileAndAutofixConflicts; | ||
async function readWantedLockfile(pkgPath, opts) { | ||
const lockfilePath = path_1.default.join(pkgPath, constants_1.WANTED_LOCKFILE); | ||
return (await _read(lockfilePath, pkgPath, opts)).lockfile; | ||
return (await _readWantedLockfile(pkgPath, opts)).lockfile; | ||
} | ||
@@ -107,2 +111,40 @@ exports.readWantedLockfile = readWantedLockfile; | ||
exports.createLockfileObject = createLockfileObject; | ||
async function _readWantedLockfile(pkgPath, opts) { | ||
const lockfileNames = [constants_1.WANTED_LOCKFILE]; | ||
if (opts.useGitBranchLockfile) { | ||
const gitBranchLockfileName = await (0, lockfileName_1.getWantedLockfileName)(opts); | ||
if (gitBranchLockfileName !== constants_1.WANTED_LOCKFILE) { | ||
lockfileNames.unshift(gitBranchLockfileName); | ||
} | ||
} | ||
let result = { lockfile: null, hadConflicts: false }; | ||
for (const lockfileName of lockfileNames) { | ||
result = await _read(path_1.default.join(pkgPath, lockfileName), pkgPath, { ...opts, autofixMergeConflicts: true }); | ||
if (result.lockfile) { | ||
if (opts.mergeGitBranchLockfiles) { | ||
result.lockfile = await _mergeGitBranchLockfiles(result.lockfile, pkgPath, pkgPath, opts); | ||
} | ||
break; | ||
} | ||
} | ||
return result; | ||
} | ||
async function _mergeGitBranchLockfiles(lockfile, lockfileDir, prefix, opts) { | ||
if (!lockfile) { | ||
return lockfile; | ||
} | ||
const gitBranchLockfiles = (await _readGitBranchLockfiles(lockfileDir, prefix, opts)).map(({ lockfile }) => lockfile); | ||
let mergedLockfile = lockfile; | ||
for (const gitBranchLockfile of gitBranchLockfiles) { | ||
if (!gitBranchLockfile) { | ||
continue; | ||
} | ||
mergedLockfile = (0, merge_lockfile_changes_1.default)(mergedLockfile, gitBranchLockfile); | ||
} | ||
return mergedLockfile; | ||
} | ||
async function _readGitBranchLockfiles(lockfileDir, prefix, opts) { | ||
const files = await (0, gitBranchLockfile_1.getGitBranchLockfileNames)(lockfileDir); | ||
return Promise.all(files.map((file) => _read(path_1.default.join(lockfileDir, file), prefix, opts))); | ||
} | ||
/** | ||
@@ -109,0 +151,0 @@ * Reverts changes from the "forceSharedFormat" write option if necessary. |
import { Lockfile, ProjectSnapshot } from '@pnpm/lockfile-types'; | ||
export declare function writeWantedLockfile(pkgPath: string, wantedLockfile: Lockfile, opts?: { | ||
forceSharedFormat?: boolean; | ||
useGitBranchLockfile?: boolean; | ||
mergeGitBranchLockfiles?: boolean; | ||
}): Promise<void>; | ||
@@ -16,2 +18,4 @@ export declare function writeCurrentLockfile(virtualStoreDir: string, currentLockfile: Lockfile, opts?: { | ||
currentLockfileDir: string; | ||
useGitBranchLockfile?: boolean; | ||
mergeGitBranchLockfiles?: boolean; | ||
}): Promise<void>; |
@@ -18,2 +18,3 @@ "use strict"; | ||
const sortLockfileKeys_1 = require("./sortLockfileKeys"); | ||
const lockfileName_1 = require("./lockfileName"); | ||
async function writeFileAtomic(filename, data) { | ||
@@ -30,3 +31,4 @@ return new Promise((resolve, reject) => (0, write_file_atomic_1.default)(filename, data, {}, (err) => (err != null) ? reject(err) : resolve())); | ||
async function writeWantedLockfile(pkgPath, wantedLockfile, opts) { | ||
return writeLockfile(constants_1.WANTED_LOCKFILE, pkgPath, wantedLockfile, opts); | ||
const wantedLockfileName = await (0, lockfileName_1.getWantedLockfileName)(opts); | ||
return writeLockfile(wantedLockfileName, pkgPath, wantedLockfile, opts); | ||
} | ||
@@ -118,3 +120,4 @@ exports.writeWantedLockfile = writeWantedLockfile; | ||
async function writeLockfiles(opts) { | ||
const wantedLockfilePath = path_1.default.join(opts.wantedLockfileDir, constants_1.WANTED_LOCKFILE); | ||
const wantedLockfileName = await (0, lockfileName_1.getWantedLockfileName)(opts); | ||
const wantedLockfilePath = path_1.default.join(opts.wantedLockfileDir, wantedLockfileName); | ||
const currentLockfilePath = path_1.default.join(opts.currentLockfileDir, 'lock.yaml'); | ||
@@ -121,0 +124,0 @@ // empty lockfile is not saved |
{ | ||
"name": "@pnpm/lockfile-file", | ||
"version": "5.0.4", | ||
"version": "5.1.0", | ||
"description": "Read/write pnpm-lock.yaml files", | ||
@@ -8,3 +8,3 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=14.19" | ||
"node": ">=14.6" | ||
}, | ||
@@ -31,3 +31,3 @@ "files": [ | ||
"devDependencies": { | ||
"@pnpm/lockfile-file": "5.0.4", | ||
"@pnpm/lockfile-file": "5.1.0", | ||
"@pnpm/logger": "^4.0.0", | ||
@@ -46,5 +46,6 @@ "@types/js-yaml": "^4.0.0", | ||
"@pnpm/error": "3.0.1", | ||
"@pnpm/lockfile-types": "4.0.2", | ||
"@pnpm/merge-lockfile-changes": "3.0.2", | ||
"@pnpm/types": "8.1.0", | ||
"@pnpm/git-utils": "0.1.0", | ||
"@pnpm/lockfile-types": "4.0.3", | ||
"@pnpm/merge-lockfile-changes": "3.0.3", | ||
"@pnpm/types": "8.2.0", | ||
"@zkochan/rimraf": "^2.1.2", | ||
@@ -51,0 +52,0 @@ "comver-to-semver": "^1.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52963
39
692
16
5
+ Added@pnpm/git-utils@0.1.0
+ Added@pnpm/git-utils@0.1.0(transitive)
+ Added@pnpm/lockfile-types@4.0.3(transitive)
+ Added@pnpm/merge-lockfile-changes@3.0.3(transitive)
+ Added@pnpm/types@8.2.0(transitive)
+ Added@zkochan/which@2.0.3(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedexeca@5.1.1(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedhuman-signals@2.1.0(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednpm-run-path@4.0.1(transitive)
+ Addedonetime@5.1.2(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-name@1.0.0(transitive)
+ Addedsafe-execa@0.1.4(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedstrip-final-newline@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
- Removed@pnpm/lockfile-types@4.0.2(transitive)
- Removed@pnpm/merge-lockfile-changes@3.0.2(transitive)
- Removed@pnpm/types@8.1.0(transitive)
Updated@pnpm/lockfile-types@4.0.3
Updated@pnpm/types@8.2.0