@pnpm/lockfile.fs 1100.1.4 → 1100.1.6
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.
- package/lib/gitBranchLockfile.d.ts +1 -0
- package/lib/gitBranchLockfile.js +12 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/lockfileName.d.ts +1 -0
- package/lib/lockfileName.js +2 -2
- package/lib/read.d.ts +1 -1
- package/lib/read.js +2 -2
- package/lib/yamlDocuments.d.ts +1 -1
- package/lib/yamlDocuments.js +45 -30
- package/package.json +13 -13
package/lib/gitBranchLockfile.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { promises as
|
|
1
|
+
import fs, { promises as fsp } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
// Branch lockfiles are written as `pnpm-lock.<branch>.yaml` with literal
|
|
4
|
+
// dots and a non-empty branch segment. Escaping the dots keeps unrelated
|
|
5
|
+
// files out of the matches that feed scanning and `cleanGitBranchLockfiles`.
|
|
6
|
+
const GIT_BRANCH_LOCKFILE_NAME = /^pnpm-lock\..+\.yaml$/;
|
|
3
7
|
export async function getGitBranchLockfileNames(lockfileDir) {
|
|
4
|
-
const files = await
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
const files = await fsp.readdir(lockfileDir);
|
|
9
|
+
return files.filter(file => GIT_BRANCH_LOCKFILE_NAME.test(file));
|
|
10
|
+
}
|
|
11
|
+
export function getGitBranchLockfileNamesSync(lockfileDir) {
|
|
12
|
+
const files = fs.readdirSync(lockfileDir);
|
|
13
|
+
return files.filter(file => GIT_BRANCH_LOCKFILE_NAME.test(file));
|
|
8
14
|
}
|
|
9
15
|
export async function cleanGitBranchLockfiles(lockfileDir) {
|
|
10
16
|
const gitBranchLockfiles = await getGitBranchLockfileNames(lockfileDir);
|
|
11
17
|
await Promise.all(gitBranchLockfiles.map(async (file) => {
|
|
12
18
|
const filepath = path.join(lockfileDir, file);
|
|
13
|
-
await
|
|
19
|
+
await fsp.unlink(filepath);
|
|
14
20
|
}));
|
|
15
21
|
}
|
|
16
22
|
//# sourceMappingURL=gitBranchLockfile.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createEnvLockfile, readEnvLockfile, writeEnvLockfile } from './envLockfile.js';
|
|
2
2
|
export { existsNonEmptyWantedLockfile } from './existsWantedLockfile.js';
|
|
3
3
|
export { getLockfileImporterId } from './getLockfileImporterId.js';
|
|
4
|
-
export { cleanGitBranchLockfiles } from './gitBranchLockfile.js';
|
|
4
|
+
export { cleanGitBranchLockfiles, getGitBranchLockfileNamesSync } from './gitBranchLockfile.js';
|
|
5
5
|
export { convertToLockfileFile, convertToLockfileObject } from './lockfileFormatConverters.js';
|
|
6
6
|
export { getWantedLockfileName } from './lockfileName.js';
|
|
7
7
|
export * from './read.js';
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createEnvLockfile, readEnvLockfile, writeEnvLockfile } from './envLockfile.js';
|
|
2
2
|
export { existsNonEmptyWantedLockfile } from './existsWantedLockfile.js';
|
|
3
3
|
export { getLockfileImporterId } from './getLockfileImporterId.js';
|
|
4
|
-
export { cleanGitBranchLockfiles } from './gitBranchLockfile.js';
|
|
4
|
+
export { cleanGitBranchLockfiles, getGitBranchLockfileNamesSync } from './gitBranchLockfile.js';
|
|
5
5
|
export { convertToLockfileFile, convertToLockfileObject } from './lockfileFormatConverters.js';
|
|
6
6
|
export { getWantedLockfileName } from './lockfileName.js';
|
|
7
7
|
export * from './read.js';
|
package/lib/lockfileName.d.ts
CHANGED
package/lib/lockfileName.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WANTED_LOCKFILE } from '@pnpm/constants';
|
|
2
2
|
import { getCurrentBranch } from '@pnpm/network.git-utils';
|
|
3
|
-
export async function getWantedLockfileName(opts = {
|
|
3
|
+
export async function getWantedLockfileName(opts = {}) {
|
|
4
4
|
if (opts.useGitBranchLockfile && !opts.mergeGitBranchLockfiles) {
|
|
5
|
-
const currentBranchName = await getCurrentBranch();
|
|
5
|
+
const currentBranchName = await getCurrentBranch({ cwd: opts.cwd });
|
|
6
6
|
if (currentBranchName) {
|
|
7
7
|
return WANTED_LOCKFILE.replace('.yaml', `.${stringifyBranchName(currentBranchName)}.yaml`);
|
|
8
8
|
}
|
package/lib/read.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export declare function readWantedLockfileFile(pkgPath: string, opts: {
|
|
|
33
33
|
useGitBranchLockfile?: boolean;
|
|
34
34
|
mergeGitBranchLockfiles?: boolean;
|
|
35
35
|
}): Promise<LockfileFile | null>;
|
|
36
|
-
export declare function wantedLockfileHasMergeConflictsSync(pkgPath: string): boolean;
|
|
36
|
+
export declare function wantedLockfileHasMergeConflictsSync(pkgPath: string, lockfileName?: string): boolean;
|
|
37
37
|
export declare function createLockfileObject(importerIds: ProjectId[], opts: {
|
|
38
38
|
lockfileVersion: string;
|
|
39
39
|
autoInstallPeers: boolean;
|
package/lib/read.js
CHANGED
|
@@ -39,9 +39,9 @@ export async function readWantedLockfile(pkgPath, opts) {
|
|
|
39
39
|
export async function readWantedLockfileFile(pkgPath, opts) {
|
|
40
40
|
return (await _readWantedLockfile(pkgPath, opts)).lockfileFile;
|
|
41
41
|
}
|
|
42
|
-
export function wantedLockfileHasMergeConflictsSync(pkgPath) {
|
|
42
|
+
export function wantedLockfileHasMergeConflictsSync(pkgPath, lockfileName = WANTED_LOCKFILE) {
|
|
43
43
|
try {
|
|
44
|
-
const lockfileRawContent = stripBom(fs.readFileSync(path.join(pkgPath,
|
|
44
|
+
const lockfileRawContent = stripBom(fs.readFileSync(path.join(pkgPath, lockfileName), 'utf8'));
|
|
45
45
|
return isDiff(extractMainDocument(lockfileRawContent));
|
|
46
46
|
}
|
|
47
47
|
catch (err) {
|
package/lib/yamlDocuments.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const YAML_DOCUMENT_START = "---\n";
|
|
|
6
6
|
* Stops reading as soon as the second document separator is found.
|
|
7
7
|
* Returns null if the file doesn't exist or doesn't start with "---\n".
|
|
8
8
|
*/
|
|
9
|
-
export declare function streamReadFirstYamlDocument(filePath: string): Promise<string | null>;
|
|
9
|
+
export declare function streamReadFirstYamlDocument(filePath: string, readBufferSize?: number): Promise<string | null>;
|
|
10
10
|
/**
|
|
11
11
|
* Extracts the main lockfile content (second YAML document) from a combined string.
|
|
12
12
|
* If the file starts with "---\n", returns the content after the separator.
|
package/lib/yamlDocuments.js
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { open } from 'node:fs/promises';
|
|
2
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
2
3
|
import util from 'node:util';
|
|
3
4
|
import stripBom from 'strip-bom';
|
|
4
5
|
export const YAML_DOCUMENT_SEPARATOR = '\n---\n';
|
|
5
6
|
export const YAML_DOCUMENT_START = '---\n';
|
|
7
|
+
const READ_BUFFER_SIZE = 64 * 1024;
|
|
6
8
|
/**
|
|
7
9
|
* Reads the first YAML document from a multi-document YAML file using streaming.
|
|
8
10
|
* The file must start with "---\n" to indicate it contains an env lockfile document.
|
|
9
11
|
* Stops reading as soon as the second document separator is found.
|
|
10
12
|
* Returns null if the file doesn't exist or doesn't start with "---\n".
|
|
11
13
|
*/
|
|
12
|
-
export async function streamReadFirstYamlDocument(filePath) {
|
|
13
|
-
|
|
14
|
-
const chunks = stream[Symbol.asyncIterator]();
|
|
14
|
+
export async function streamReadFirstYamlDocument(filePath, readBufferSize = READ_BUFFER_SIZE) {
|
|
15
|
+
let fileHandle;
|
|
15
16
|
let buffer = '';
|
|
17
|
+
let firstChunk = true;
|
|
16
18
|
try {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
fileHandle = await open(filePath, 'r');
|
|
20
|
+
const decoder = new StringDecoder('utf8');
|
|
21
|
+
const readBuffer = Buffer.allocUnsafe(normalizeReadBufferSize(readBufferSize));
|
|
22
|
+
let position = 0;
|
|
23
|
+
while (true) {
|
|
24
|
+
const { bytesRead } = await fileHandle.read(readBuffer, 0, readBuffer.length, position); // eslint-disable-line no-await-in-loop
|
|
25
|
+
if (bytesRead === 0)
|
|
26
|
+
break;
|
|
27
|
+
position += bytesRead;
|
|
28
|
+
let chunk = decoder.write(readBuffer.subarray(0, bytesRead));
|
|
29
|
+
if (firstChunk && chunk.length > 0) {
|
|
30
|
+
// Strip BOM from the first chunk. Safe because the decoder uses utf8,
|
|
31
|
+
// so the 3-byte BOM is decoded into a single \uFEFF character.
|
|
32
|
+
chunk = stripBom(chunk);
|
|
33
|
+
firstChunk = false;
|
|
26
34
|
}
|
|
35
|
+
buffer += chunk;
|
|
27
36
|
// Normalize CRLF (Windows) to LF so document separator detection works.
|
|
28
37
|
buffer = buffer.replace(/\r\n/g, '\n');
|
|
29
|
-
if (buffer
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!buffer.startsWith(YAML_DOCUMENT_START)) {
|
|
33
|
-
stream.destroy();
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
// Phase 2: find the second "---" separator
|
|
37
|
-
while (true) {
|
|
38
|
+
if (canRejectDocumentStart(buffer)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
38
41
|
const sep = buffer.indexOf(YAML_DOCUMENT_SEPARATOR, YAML_DOCUMENT_START.length);
|
|
39
42
|
if (sep !== -1) {
|
|
40
|
-
stream.destroy();
|
|
41
43
|
return buffer.slice(YAML_DOCUMENT_START.length, sep);
|
|
42
44
|
}
|
|
43
|
-
const chunk = await chunks.next(); // eslint-disable-line no-await-in-loop
|
|
44
|
-
if (chunk.done)
|
|
45
|
-
break;
|
|
46
|
-
// Normalize CRLF (Windows) to LF so the separator search matches on Windows-checked-out files.
|
|
47
|
-
buffer = (buffer + chunk.value).replace(/\r\n/g, '\n');
|
|
48
45
|
}
|
|
46
|
+
const remainder = decoder.end();
|
|
47
|
+
if (remainder.length > 0) {
|
|
48
|
+
buffer += firstChunk ? stripBom(remainder) : remainder;
|
|
49
|
+
buffer = buffer.replace(/\r\n/g, '\n');
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
49
52
|
}
|
|
50
53
|
catch (err) {
|
|
51
54
|
if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {
|
|
@@ -53,8 +56,20 @@ export async function streamReadFirstYamlDocument(filePath) {
|
|
|
53
56
|
}
|
|
54
57
|
throw err;
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
finally {
|
|
60
|
+
await fileHandle?.close().catch(() => { });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function canRejectDocumentStart(buffer) {
|
|
64
|
+
if (buffer.length < YAML_DOCUMENT_START.length)
|
|
65
|
+
return false;
|
|
66
|
+
if (buffer === '---\r')
|
|
67
|
+
return false;
|
|
68
|
+
return !buffer.startsWith(YAML_DOCUMENT_START);
|
|
69
|
+
}
|
|
70
|
+
function normalizeReadBufferSize(readBufferSize) {
|
|
71
|
+
const size = Number.isFinite(readBufferSize) ? Math.floor(readBufferSize) : READ_BUFFER_SIZE;
|
|
72
|
+
return size > 0 ? size : READ_BUFFER_SIZE;
|
|
58
73
|
}
|
|
59
74
|
/**
|
|
60
75
|
* Extracts the main lockfile content (second YAML document) from a combined string.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/lockfile.fs",
|
|
3
|
-
"version": "1100.1.
|
|
3
|
+
"version": "1100.1.6",
|
|
4
4
|
"description": "Read/write pnpm-lock.yaml files",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -34,24 +34,24 @@
|
|
|
34
34
|
"js-yaml": "npm:@zkochan/js-yaml@0.0.11",
|
|
35
35
|
"normalize-path": "^3.0.0",
|
|
36
36
|
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
37
|
-
"semver": "^7.8.
|
|
37
|
+
"semver": "^7.8.4",
|
|
38
38
|
"strip-bom": "^5.0.0",
|
|
39
39
|
"write-file-atomic": "^7.0.1",
|
|
40
|
-
"@pnpm/
|
|
41
|
-
"@pnpm/
|
|
40
|
+
"@pnpm/lockfile.types": "1100.0.11",
|
|
41
|
+
"@pnpm/lockfile.merger": "1100.0.11",
|
|
42
42
|
"@pnpm/error": "1100.0.0",
|
|
43
|
-
"@pnpm/
|
|
44
|
-
"@pnpm/
|
|
45
|
-
"@pnpm/
|
|
46
|
-
"@pnpm/
|
|
47
|
-
"@pnpm/
|
|
48
|
-
"@pnpm/
|
|
43
|
+
"@pnpm/network.git-utils": "1100.0.2",
|
|
44
|
+
"@pnpm/object.key-sorting": "1100.0.1",
|
|
45
|
+
"@pnpm/types": "1101.3.2",
|
|
46
|
+
"@pnpm/lockfile.utils": "1100.0.13",
|
|
47
|
+
"@pnpm/deps.path": "1100.0.8",
|
|
48
|
+
"@pnpm/constants": "1100.0.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@pnpm/logger": "^
|
|
51
|
+
"@pnpm/logger": "^1100.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@jest/globals": "30.
|
|
54
|
+
"@jest/globals": "30.4.1",
|
|
55
55
|
"@types/js-yaml": "^4.0.9",
|
|
56
56
|
"@types/normalize-path": "^3.0.2",
|
|
57
57
|
"@types/ramda": "0.31.1",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"tempy": "3.0.0",
|
|
61
61
|
"write-yaml-file": "^6.0.0",
|
|
62
62
|
"yaml-tag": "1.1.0",
|
|
63
|
-
"@pnpm/lockfile.fs": "1100.1.
|
|
63
|
+
"@pnpm/lockfile.fs": "1100.1.6",
|
|
64
64
|
"@pnpm/logger": "1100.0.0"
|
|
65
65
|
},
|
|
66
66
|
"engines": {
|