@pnpm/lockfile-file
Advanced tools
# @pnpm/lockfile-file | ||
## 4.0.0 | ||
### Major Changes | ||
- 97b986fbc: Node.js 10 support is dropped. At least Node.js 12.17 is required for the package to work. | ||
### Minor Changes | ||
- 155e70597: The "resolution" field should always be the first key. This will reduce the number of issues during lockfile merges. | ||
- f7750baed: Add blank lines to the lockfile between items. | ||
The `resolution` object should be written in a single line. | ||
### Patch Changes | ||
- 9c2a878c3: Change order of keys in package snapshot. | ||
- 8b66f26dc: Do not fail when `lockfileVersion` is a string. | ||
- 9c2a878c3: Write engines, os, and cpu to single line. | ||
- Updated dependencies [6871d74b2] | ||
- Updated dependencies [97b986fbc] | ||
- Updated dependencies [6871d74b2] | ||
- Updated dependencies [f2bb5cbeb] | ||
- @pnpm/constants@5.0.0 | ||
- @pnpm/error@2.0.0 | ||
- @pnpm/lockfile-types@3.0.0 | ||
- @pnpm/merge-lockfile-changes@2.0.0 | ||
- @pnpm/types@7.0.0 | ||
## 3.2.1 | ||
@@ -4,0 +32,0 @@ |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const constants_1 = require("@pnpm/constants"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
exports.default = (pkgPath) => new Promise((resolve, reject) => { | ||
fs.access(path.join(pkgPath, constants_1.WANTED_LOCKFILE), (err) => { | ||
if (!err) { | ||
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); | ||
@@ -10,0 +13,0 @@ return; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path = require("path"); | ||
const normalize = require("normalize-path"); | ||
exports.default = (lockfileDir, prefix) => normalize(path.relative(lockfileDir, prefix)) || '.'; | ||
const path_1 = __importDefault(require("path")); | ||
const normalize_path_1 = __importDefault(require("normalize-path")); | ||
exports.default = (lockfileDir, prefix) => (0, normalize_path_1.default)(path_1.default.relative(lockfileDir, prefix)) || '.'; | ||
//# sourceMappingURL=getLockfileImporterId.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
const merge_lockfile_changes_1 = __importDefault(require("@pnpm/merge-lockfile-changes")); | ||
const yaml = require("js-yaml"); | ||
const js_yaml_1 = __importDefault(require("js-yaml")); | ||
const MERGE_CONFLICT_PARENT = '|||||||'; | ||
@@ -16,3 +16,3 @@ const MERGE_CONFLICT_END = '>>>>>>>'; | ||
const { ours, theirs } = parseMergeFile(fileContent); | ||
return merge_lockfile_changes_1.default(yaml.load(ours), yaml.load(theirs)); | ||
return (0, merge_lockfile_changes_1.default)(js_yaml_1.default.load(ours), js_yaml_1.default.load(theirs)); | ||
} | ||
@@ -19,0 +19,0 @@ exports.autofixMergeConflicts = autofixMergeConflicts; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const logger_1 = __importDefault(require("@pnpm/logger")); | ||
exports.default = logger_1.default('lockfile'); | ||
exports.default = (0, logger_1.default)('lockfile'); | ||
//# sourceMappingURL=logger.js.map |
@@ -7,19 +7,21 @@ "use strict"; | ||
exports.createLockfileObject = exports.readWantedLockfile = exports.readWantedLockfileAndAutofixConflicts = exports.readCurrentLockfile = void 0; | ||
const fs_1 = require("fs"); | ||
const path_1 = __importDefault(require("path")); | ||
const constants_1 = require("@pnpm/constants"); | ||
const error_1 = __importDefault(require("@pnpm/error")); | ||
const types_1 = require("@pnpm/types"); | ||
const comver_to_semver_1 = __importDefault(require("comver-to-semver")); | ||
const js_yaml_1 = __importDefault(require("js-yaml")); | ||
const semver_1 = __importDefault(require("semver")); | ||
const strip_bom_1 = __importDefault(require("strip-bom")); | ||
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"); | ||
const stripBom = require("strip-bom"); | ||
const fs = require("mz/fs"); | ||
async function readCurrentLockfile(virtualStoreDir, opts) { | ||
const lockfilePath = path.join(virtualStoreDir, 'lock.yaml'); | ||
const lockfilePath = path_1.default.join(virtualStoreDir, 'lock.yaml'); | ||
return (await _read(lockfilePath, virtualStoreDir, opts)).lockfile; | ||
} | ||
exports.readCurrentLockfile = readCurrentLockfile; | ||
function readWantedLockfileAndAutofixConflicts(pkgPath, opts) { | ||
const lockfilePath = path.join(pkgPath, constants_1.WANTED_LOCKFILE); | ||
async function readWantedLockfileAndAutofixConflicts(pkgPath, opts) { | ||
const lockfilePath = path_1.default.join(pkgPath, constants_1.WANTED_LOCKFILE); | ||
return _read(lockfilePath, pkgPath, { ...opts, autofixMergeConflicts: true }); | ||
@@ -29,3 +31,3 @@ } | ||
async function readWantedLockfile(pkgPath, opts) { | ||
const lockfilePath = path.join(pkgPath, constants_1.WANTED_LOCKFILE); | ||
const lockfilePath = path_1.default.join(pkgPath, constants_1.WANTED_LOCKFILE); | ||
return (await _read(lockfilePath, pkgPath, opts)).lockfile; | ||
@@ -35,5 +37,6 @@ } | ||
async function _read(lockfilePath, prefix, opts) { | ||
var _a; | ||
let lockfileRawContent; | ||
try { | ||
lockfileRawContent = stripBom(await fs.readFile(lockfilePath, 'utf8')); | ||
lockfileRawContent = (0, strip_bom_1.default)(await fs_1.promises.readFile(lockfilePath, 'utf8')); | ||
} | ||
@@ -52,14 +55,14 @@ catch (err) { | ||
try { | ||
lockfile = yaml.load(lockfileRawContent); | ||
lockfile = js_yaml_1.default.load(lockfileRawContent); | ||
hadConflicts = false; | ||
} | ||
catch (err) { | ||
if (!opts.autofixMergeConflicts || !gitMergeFile_1.isDiff(lockfileRawContent)) { | ||
if (!opts.autofixMergeConflicts || !(0, gitMergeFile_1.isDiff)(lockfileRawContent)) { | ||
throw new error_1.default('BROKEN_LOCKFILE', `The lockfile at "${lockfilePath}" is broken: ${err.message}`); | ||
} | ||
hadConflicts = true; | ||
lockfile = gitMergeFile_1.autofixMergeConflicts(lockfileRawContent); | ||
lockfile = (0, gitMergeFile_1.autofixMergeConflicts)(lockfileRawContent); | ||
logger_1.default.info({ | ||
message: `Merge conflict detected in ${constants_1.WANTED_LOCKFILE} and successfully merged`, | ||
prefix: path.dirname(lockfilePath), | ||
prefix: path_1.default.dirname(lockfilePath), | ||
}); | ||
@@ -74,5 +77,5 @@ } | ||
}; | ||
delete lockfile['specifiers']; | ||
delete lockfile.specifiers; | ||
for (const depType of types_1.DEPENDENCIES_FIELDS) { | ||
if (lockfile[depType]) { | ||
if (lockfile[depType] != null) { | ||
lockfile.importers['.'][depType] = lockfile[depType]; | ||
@@ -84,5 +87,6 @@ delete lockfile[depType]; | ||
if (lockfile) { | ||
const lockfileSemver = (0, comver_to_semver_1.default)(((_a = lockfile.lockfileVersion) !== null && _a !== void 0 ? _a : 0).toString()); | ||
/* eslint-enable @typescript-eslint/dot-notation */ | ||
if (typeof opts.wantedVersion !== 'number' || Math.floor(lockfile.lockfileVersion) === Math.floor(opts.wantedVersion)) { | ||
if (typeof opts.wantedVersion === 'number' && lockfile.lockfileVersion > opts.wantedVersion) { | ||
if (typeof opts.wantedVersion !== 'number' || semver_1.default.major(lockfileSemver) === semver_1.default.major((0, comver_to_semver_1.default)(opts.wantedVersion.toString()))) { | ||
if (typeof opts.wantedVersion === 'number' && semver_1.default.gt(lockfileSemver, (0, comver_to_semver_1.default)(opts.wantedVersion.toString()))) { | ||
logger_1.default.warn({ | ||
@@ -94,3 +98,3 @@ message: `Your ${constants_1.WANTED_LOCKFILE} was generated by a newer version of pnpm. ` + | ||
} | ||
return { lockfile, hadConflicts }; | ||
return { lockfile: lockfile, hadConflicts }; | ||
} | ||
@@ -97,0 +101,0 @@ } |
@@ -8,3 +8,3 @@ import { Lockfile, ProjectSnapshot } from '@pnpm/lockfile-types'; | ||
}): Promise<void>; | ||
declare type LockfileFile = Omit<Lockfile, 'importers'> & Partial<ProjectSnapshot> & Partial<Pick<Lockfile, 'importers'>>; | ||
export declare type LockfileFile = Omit<Lockfile, 'importers'> & Partial<ProjectSnapshot> & Partial<Pick<Lockfile, 'importers'>>; | ||
export declare function normalizeLockfile(lockfile: Lockfile, forceSharedFormat: boolean): LockfileFile; | ||
@@ -18,2 +18,1 @@ export default function writeLockfiles(opts: { | ||
}): Promise<void>; | ||
export {}; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -7,21 +26,23 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.normalizeLockfile = exports.writeCurrentLockfile = exports.writeWantedLockfile = void 0; | ||
const logger_1 = __importDefault(require("./logger")); | ||
const fs_1 = require("fs"); | ||
const path_1 = __importDefault(require("path")); | ||
const types_1 = require("@pnpm/types"); | ||
const constants_1 = require("@pnpm/constants"); | ||
const rimraf = require("@zkochan/rimraf"); | ||
const yaml = require("js-yaml"); | ||
const fs = require("mz/fs"); | ||
const path = require("path"); | ||
const R = require("ramda"); | ||
const writeFileAtomicCB = require("write-file-atomic"); | ||
function writeFileAtomic(filename, data) { | ||
return new Promise((resolve, reject) => writeFileAtomicCB(filename, data, {}, (err) => err ? reject(err) : resolve())); | ||
const rimraf_1 = __importDefault(require("@zkochan/rimraf")); | ||
const js_yaml_1 = __importDefault(require("js-yaml")); | ||
const R = __importStar(require("ramda")); | ||
const write_file_atomic_1 = __importDefault(require("write-file-atomic")); | ||
const logger_1 = __importDefault(require("./logger")); | ||
const sortLockfileKeys_1 = require("./sortLockfileKeys"); | ||
async function writeFileAtomic(filename, data) { | ||
return new Promise((resolve, reject) => (0, write_file_atomic_1.default)(filename, data, {}, (err) => (err != null) ? reject(err) : resolve())); | ||
} | ||
const LOCKFILE_YAML_FORMAT = { | ||
blankLines: true, | ||
lineWidth: 1000, | ||
noCompatMode: true, | ||
noRefs: true, | ||
sortKeys: true, | ||
sortKeys: false, | ||
}; | ||
function writeWantedLockfile(pkgPath, wantedLockfile, opts) { | ||
async function writeWantedLockfile(pkgPath, wantedLockfile, opts) { | ||
return writeLockfile(constants_1.WANTED_LOCKFILE, pkgPath, wantedLockfile, opts); | ||
@@ -31,11 +52,11 @@ } | ||
async function writeCurrentLockfile(virtualStoreDir, currentLockfile, opts) { | ||
await fs.mkdir(virtualStoreDir, { recursive: true }); | ||
await fs_1.promises.mkdir(virtualStoreDir, { recursive: true }); | ||
return writeLockfile('lock.yaml', virtualStoreDir, currentLockfile, opts); | ||
} | ||
exports.writeCurrentLockfile = writeCurrentLockfile; | ||
function writeLockfile(lockfileFilename, pkgPath, wantedLockfile, opts) { | ||
const lockfilePath = path.join(pkgPath, lockfileFilename); | ||
async function writeLockfile(lockfileFilename, pkgPath, wantedLockfile, opts) { | ||
const lockfilePath = path_1.default.join(pkgPath, lockfileFilename); | ||
// empty lockfile is not saved | ||
if (isEmptyLockfile(wantedLockfile)) { | ||
return rimraf(lockfilePath); | ||
return (0, rimraf_1.default)(lockfilePath); | ||
} | ||
@@ -46,4 +67,5 @@ const yamlDoc = yamlStringify(wantedLockfile, (opts === null || opts === void 0 ? void 0 : opts.forceSharedFormat) === true); | ||
function yamlStringify(lockfile, forceSharedFormat) { | ||
const normalizedLockfile = normalizeLockfile(lockfile, forceSharedFormat); | ||
return yaml.dump(normalizedLockfile, LOCKFILE_YAML_FORMAT); | ||
let normalizedLockfile = normalizeLockfile(lockfile, forceSharedFormat); | ||
normalizedLockfile = (0, sortLockfileKeys_1.sortLockfileKeys)(normalizedLockfile); | ||
return js_yaml_1.default.dump(normalizedLockfile, LOCKFILE_YAML_FORMAT); | ||
} | ||
@@ -66,3 +88,3 @@ function isEmptyLockfile(lockfile) { | ||
} | ||
if (R.isEmpty(lockfileToSave.packages) || !lockfileToSave.packages) { | ||
if (R.isEmpty(lockfileToSave.packages) || (lockfileToSave.packages == null)) { | ||
delete lockfileToSave.packages; | ||
@@ -89,10 +111,10 @@ } | ||
}; | ||
if (R.isEmpty(lockfileToSave.packages) || !lockfileToSave.packages) { | ||
if (R.isEmpty(lockfileToSave.packages) || (lockfileToSave.packages == null)) { | ||
delete lockfileToSave.packages; | ||
} | ||
} | ||
if (lockfileToSave.overrides && R.isEmpty(lockfileToSave.overrides)) { | ||
if ((lockfileToSave.overrides != null) && R.isEmpty(lockfileToSave.overrides)) { | ||
delete lockfileToSave.overrides; | ||
} | ||
if (lockfileToSave.neverBuiltDependencies) { | ||
if (lockfileToSave.neverBuiltDependencies != null) { | ||
if (R.isEmpty(lockfileToSave.neverBuiltDependencies)) { | ||
@@ -109,9 +131,9 @@ delete lockfileToSave.neverBuiltDependencies; | ||
async function writeLockfiles(opts) { | ||
const wantedLockfilePath = path.join(opts.wantedLockfileDir, constants_1.WANTED_LOCKFILE); | ||
const currentLockfilePath = path.join(opts.currentLockfileDir, 'lock.yaml'); | ||
const wantedLockfilePath = path_1.default.join(opts.wantedLockfileDir, constants_1.WANTED_LOCKFILE); | ||
const currentLockfilePath = path_1.default.join(opts.currentLockfileDir, 'lock.yaml'); | ||
// empty lockfile is not saved | ||
if (isEmptyLockfile(opts.wantedLockfile)) { | ||
await Promise.all([ | ||
rimraf(wantedLockfilePath), | ||
rimraf(currentLockfilePath), | ||
(0, rimraf_1.default)(wantedLockfilePath), | ||
(0, rimraf_1.default)(currentLockfilePath), | ||
]); | ||
@@ -129,3 +151,3 @@ return; | ||
(async () => { | ||
await fs.mkdir(path.dirname(currentLockfilePath), { recursive: true }); | ||
await fs_1.promises.mkdir(path_1.default.dirname(currentLockfilePath), { recursive: true }); | ||
await writeFileAtomic(currentLockfilePath, yamlDoc); | ||
@@ -137,3 +159,3 @@ })(), | ||
logger_1.default.debug({ | ||
message: `\`${constants_1.WANTED_LOCKFILE}\` differs from \`${path.relative(opts.wantedLockfileDir, currentLockfilePath)}\``, | ||
message: `\`${constants_1.WANTED_LOCKFILE}\` differs from \`${path_1.default.relative(opts.wantedLockfileDir, currentLockfilePath)}\``, | ||
prefix: opts.wantedLockfileDir, | ||
@@ -145,3 +167,3 @@ }); | ||
(async () => { | ||
await fs.mkdir(path.dirname(currentLockfilePath), { recursive: true }); | ||
await fs_1.promises.mkdir(path_1.default.dirname(currentLockfilePath), { recursive: true }); | ||
await writeFileAtomic(currentLockfilePath, currentYamlDoc); | ||
@@ -148,0 +170,0 @@ })(), |
{ | ||
"name": "@pnpm/lockfile-file", | ||
"version": "3.2.1", | ||
"version": "4.0.0", | ||
"description": "Read/write pnpm-lock.yaml files", | ||
@@ -8,3 +8,3 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=10.16" | ||
"node": ">=12.17" | ||
}, | ||
@@ -20,3 +20,3 @@ "files": [ | ||
"prepublishOnly": "pnpm run compile", | ||
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build" | ||
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build && pnpm run lint -- --fix" | ||
}, | ||
@@ -29,3 +29,2 @@ "repository": "https://github.com/pnpm/pnpm/blob/master/packages/lockfile-file", | ||
], | ||
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)", | ||
"license": "MIT", | ||
@@ -37,8 +36,7 @@ "bugs": { | ||
"peerDependencies": { | ||
"@pnpm/logger": "^3.2.3" | ||
"@pnpm/logger": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@pnpm/logger": "^3.2.3", | ||
"@pnpm/logger": "^4.0.0", | ||
"@types/js-yaml": "^4.0.0", | ||
"@types/mz": "^2.7.3", | ||
"@types/normalize-path": "^3.0.0", | ||
@@ -48,16 +46,18 @@ "@types/ramda": "^0.27.35", | ||
"tempy": "^1.0.0", | ||
"write-yaml-file": "^4.1.3", | ||
"write-yaml-file": "^4.2.0", | ||
"yaml-tag": "1.1.0" | ||
}, | ||
"dependencies": { | ||
"@pnpm/constants": "4.1.0", | ||
"@pnpm/error": "1.4.0", | ||
"@pnpm/lockfile-types": "2.2.0", | ||
"@pnpm/merge-lockfile-changes": "1.0.1", | ||
"@pnpm/types": "6.4.0", | ||
"@zkochan/rimraf": "^1.0.0", | ||
"js-yaml": "^4.0.0", | ||
"mz": "^2.7.0", | ||
"@pnpm/constants": "5.0.0", | ||
"@pnpm/error": "2.0.0", | ||
"@pnpm/lockfile-types": "3.0.0", | ||
"@pnpm/merge-lockfile-changes": "2.0.0", | ||
"@pnpm/types": "7.0.0", | ||
"@zkochan/rimraf": "^2.0.0", | ||
"comver-to-semver": "^1.0.0", | ||
"js-yaml": "npm:@zkochan/js-yaml@0.0.4", | ||
"normalize-path": "^3.0.0", | ||
"ramda": "^0.27.1", | ||
"semver": "^7.3.4", | ||
"sort-keys": "^4.2.0", | ||
"strip-bom": "^4.0.0", | ||
@@ -64,0 +64,0 @@ "write-file-atomic": "^3.0.3" |
Sorry, the diff of this file is not supported yet
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
33463
21.79%8
-11.11%24
9.09%569
24.24%15
15.38%1
Infinity%4
100%