Skip to content

fix: handle CRLF line endings in extractMainLockfileDocument - #35840

Closed
godfengliang wants to merge 1 commit into
nrwl:masterfrom
godfengliang:fix-crlf-lockfile
Closed

fix: handle CRLF line endings in extractMainLockfileDocument#35840
godfengliang wants to merge 1 commit into
nrwl:masterfrom
godfengliang:fix-crlf-lockfile

Conversation

@godfengliang

Copy link
Copy Markdown

Problem

On Windows, pnpm lockfile content may have CRLF line endings, but uses LF-only strings to find YAML document separators. This causes to fail on Windows.

Fix

Normalize line endings to LF at the start of .

Fixes #35828

On Windows, pnpm lockfile content may have CRLF (
) line endings,
but extractMainLockfileDocument uses LF-only strings (
---
) to find
YAML document separators. This causes the function to fail on Windows.

Normalize line endings to LF at the start of the function.

Fixes nrwl#35828
@godfengliang
godfengliang requested a review from a team as a code owner June 1, 2026 09:46
@godfengliang
godfengliang requested a review from FrozenPandaz June 1, 2026 09:46
@netlify

netlify Bot commented Jun 1, 2026

Copy link
Copy Markdown

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit fdf16bb

@netlify

netlify Bot commented Jun 1, 2026

Copy link
Copy Markdown

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit fdf16bb

@FrozenPandaz FrozenPandaz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to recommit this with the escape sequences /r/n and /n. Otherwise, this does not compile.

@@ -69,6 +69,12 @@ const YAML_DOCUMENT_SEPARATOR = '\n---\n';
// always read the workspace document.
// https://github.com/pnpm/pnpm/blob/main/lockfile/fs/src/yamlDocuments.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remote url has been updated:

Suggested change
// https://github.com/pnpm/pnpm/blob/main/lockfile/fs/src/yamlDocuments.ts
// https://github.com/pnpm/pnpm/blob/main/pnpm11/lockfile/fs/src/yamlDocuments.ts

Comment on lines +75 to +77
content = content.replace(/
/g, '
');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per pnpm lockfile example

Suggested change
content = content.replace(/
/g, '
');
content = content.replace(/\r\n/g, '\n')

FrozenPandaz added a commit that referenced this pull request Jul 29, 2026
…36419)

## Current Behavior

`extractMainLockfileDocument` matches the pnpm multi-document markers
with LF-only strings (`'---\n'` and `'\n---\n'`). When `pnpm-lock.yaml`
is written with CRLF line endings (common on Windows), the markers never
match: `startsWith('---\n')` is false, so the raw two-document content
flows into YAML parsing and project-graph construction fails with
`expected a single document in the stream, but found more`.

## Expected Behavior

Line endings are normalized to LF before the document markers are
matched, so multi-document lockfiles written with CRLF are split
correctly and the workspace lock document is parsed on Windows. A CRLF
variant of the multi-document lockfile test pins the behavior.

## Related Issue(s)

Fixes #35828

Closes #35840

<!-- polygraph-session-start -->
---
[View session information
↗](https://app.trypolygraph.com/orgs/6a061dcb561c062131116eca/sessions/Fix-CRLF-pnpm-lockfile-parsing-on-Windows-0e926b99)
<!-- polygraph-session-end -->

---------

Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
(cherry picked from commit b8dca5e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extractMainLockfileDocument is broken on Windows

3 participants