@pnpm/lockfile-file
Advanced tools
Comparing version 3.0.18 to 3.1.0
# @pnpm/lockfile-file | ||
## 3.1.0 | ||
### Minor Changes | ||
- 3776b5a52: New function added that reads the lockfile and autofixes any merge conflicts. | ||
### Patch Changes | ||
- Updated dependencies [3776b5a52] | ||
- @pnpm/merge-lockfile-changes@1.0.0 | ||
## 3.0.18 | ||
@@ -4,0 +15,0 @@ |
@@ -6,2 +6,9 @@ import { Lockfile } from '@pnpm/lockfile-types'; | ||
}): Promise<Lockfile | null>; | ||
export declare function readWantedLockfileAndAutofixConflicts(pkgPath: string, opts: { | ||
wantedVersion?: number; | ||
ignoreIncompatible: boolean; | ||
}): Promise<{ | ||
lockfile: Lockfile | null; | ||
hadConflicts: boolean; | ||
}>; | ||
export declare function readWantedLockfile(pkgPath: string, opts: { | ||
@@ -8,0 +15,0 @@ wantedVersion?: number; |
@@ -6,23 +6,31 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLockfileObject = exports.readWantedLockfile = exports.readCurrentLockfile = void 0; | ||
exports.createLockfileObject = exports.readWantedLockfile = exports.readWantedLockfileAndAutofixConflicts = exports.readCurrentLockfile = void 0; | ||
const constants_1 = require("@pnpm/constants"); | ||
const types_1 = require("@pnpm/types"); | ||
const read_yaml_file_1 = __importDefault(require("read-yaml-file")); | ||
const errors_1 = require("./errors"); | ||
const gitMergeFile_1 = require("./gitMergeFile"); | ||
const logger_1 = __importDefault(require("./logger")); | ||
const yaml = require("js-yaml"); | ||
const path = require("path"); | ||
function readCurrentLockfile(virtualStoreDir, opts) { | ||
const stripBom = require("strip-bom"); | ||
const fs = require("mz/fs"); | ||
async function readCurrentLockfile(virtualStoreDir, opts) { | ||
const lockfilePath = path.join(virtualStoreDir, 'lock.yaml'); | ||
return _read(lockfilePath, virtualStoreDir, opts); | ||
return (await _read(lockfilePath, virtualStoreDir, opts)).lockfile; | ||
} | ||
exports.readCurrentLockfile = readCurrentLockfile; | ||
function readWantedLockfile(pkgPath, opts) { | ||
function readWantedLockfileAndAutofixConflicts(pkgPath, opts) { | ||
const lockfilePath = path.join(pkgPath, constants_1.WANTED_LOCKFILE); | ||
return _read(lockfilePath, pkgPath, opts); | ||
return _read(lockfilePath, pkgPath, { ...opts, autofixMergeConflicts: true }); | ||
} | ||
exports.readWantedLockfileAndAutofixConflicts = readWantedLockfileAndAutofixConflicts; | ||
async function readWantedLockfile(pkgPath, opts) { | ||
const lockfilePath = path.join(pkgPath, constants_1.WANTED_LOCKFILE); | ||
return (await _read(lockfilePath, pkgPath, opts)).lockfile; | ||
} | ||
exports.readWantedLockfile = readWantedLockfile; | ||
async function _read(lockfilePath, prefix, opts) { | ||
let lockfile; | ||
let lockfileRawContent; | ||
try { | ||
lockfile = await read_yaml_file_1.default(lockfilePath); | ||
lockfileRawContent = stripBom(await fs.readFile(lockfilePath, 'utf8')); | ||
} | ||
@@ -33,4 +41,24 @@ catch (err) { | ||
} | ||
return null; | ||
return { | ||
lockfile: null, | ||
hadConflicts: false, | ||
}; | ||
} | ||
let lockfile; | ||
let hadConflicts; | ||
try { | ||
lockfile = yaml.safeLoad(lockfileRawContent); | ||
hadConflicts = false; | ||
} | ||
catch (err) { | ||
if (!opts.autofixMergeConflicts || !gitMergeFile_1.isDiff(lockfileRawContent)) { | ||
throw err; | ||
} | ||
hadConflicts = true; | ||
lockfile = gitMergeFile_1.autofixMergeConflicts(lockfileRawContent); | ||
logger_1.default.info({ | ||
message: `Merge conflict detected in ${constants_1.WANTED_LOCKFILE} and successfully merged`, | ||
prefix: path.dirname(lockfilePath), | ||
}); | ||
} | ||
/* eslint-disable @typescript-eslint/dot-notation */ | ||
@@ -61,3 +89,3 @@ if (typeof (lockfile === null || lockfile === void 0 ? void 0 : lockfile['specifiers']) !== 'undefined') { | ||
} | ||
return lockfile; | ||
return { lockfile, hadConflicts }; | ||
} | ||
@@ -70,3 +98,3 @@ } | ||
}); | ||
return null; | ||
return { lockfile: null, hadConflicts: false }; | ||
} | ||
@@ -73,0 +101,0 @@ throw new errors_1.LockfileBreakingChangeError(lockfilePath); |
{ | ||
"name": "@pnpm/lockfile-file", | ||
"version": "3.0.18", | ||
"version": "3.1.0", | ||
"description": "Read/write pnpm-lock.yaml files", | ||
@@ -52,2 +52,3 @@ "main": "lib/index.js", | ||
"@pnpm/lockfile-types": "2.1.1", | ||
"@pnpm/merge-lockfile-changes": "^1.0.0", | ||
"@pnpm/types": "6.3.1", | ||
@@ -59,3 +60,3 @@ "@zkochan/rimraf": "^1.0.0", | ||
"ramda": "^0.27.1", | ||
"read-yaml-file": "^2.0.0", | ||
"strip-bom": "^4.0.0", | ||
"write-file-atomic": "^3.0.3" | ||
@@ -62,0 +63,0 @@ }, |
26865
22
473
13
+ Addedstrip-bom@^4.0.0
+ Added@pnpm/lockfile-types@2.2.0(transitive)
+ Added@pnpm/merge-lockfile-changes@1.0.1(transitive)
+ Addedsemver@7.7.0(transitive)
- Removedread-yaml-file@^2.0.0
- Removedargparse@2.0.1(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedread-yaml-file@2.1.0(transitive)