Skip to content

fix(js): parse pnpm/npm publish JSON containing braces in file paths - #36241

Merged
leosvelperez merged 1 commit into
masterfrom
gh-36236
Jul 14, 2026
Merged

fix(js): parse pnpm/npm publish JSON containing braces in file paths#36241
leosvelperez merged 1 commit into
masterfrom
gh-36236

Conversation

@leosvelperez

@leosvelperez leosvelperez commented Jul 6, 2026

Copy link
Copy Markdown
Member

Current Behavior

nx release publish can mark a publish as failed even after pnpm publish (or npm publish) has already succeeded and pushed the package to the registry. When a published file path contains curly braces, for example a template directory like templates/{{name}}/file.txt, the executor fails with:

The pnpm publish output data could not be extracted. Please report this issue on https://github.com/nrwl/nx

The publish summary was located in stdout with a fixed-depth brace-counting regex. That regex is not JSON-aware: it treats { / } inside a JSON string value (such as a files[].path) as structural braces, so the top-level summary object no longer matches and extraction returns null. The package is published, but the command reports failure.

Expected Behavior

When the package manager exits successfully and emits a valid JSON publish summary, nx release publish parses it and reports success, regardless of whether any files[].path contains curly braces.

Related Issue(s)

Fixes #36236

Implementation Details

extractNpmPublishJsonData no longer uses a regex. It pairs every { with its matching } in one string-aware pass, ignoring braces and quotes that appear inside JSON string literals, then scans the balanced objects left to right and unwraps the summary (flat, or nested one level under the package name for newer npm and for pnpm run from the workspace root).

This removes the fixed-depth limitation: string values may contain any number of braces and the object may nest arbitrarily deep. The summary is interleaved with arbitrary lifecycle-script output, so the scanner treats that surrounding text as opaque: it does not interpret // or /* as comments (a script may legitimately print a glob such as dist/*.js), and it ends a string at a raw newline (which valid JSON never contains) so a stray quote in log text cannot hide the summary. Stray unbalanced braces in that output are also left unpaired.

Added tests cover a files[].path with curly braces, a Windows-style backslash-escaped path, a summary nested under the package name with a brace-carrying path, unbalanced braces and a stray unpaired quote in surrounding lifecycle output, and comment-like text or globs before the summary.


View session information ↗

@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit eb616c0
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a4bb4529421180008e83770
😎 Deploy Preview https://deploy-preview-36241--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit eb616c0
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a4bb452b9542f0008153c85
😎 Deploy Preview https://deploy-preview-36241--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud

nx-cloud Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit eb616c0

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 10m 19s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 5s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 1m 4s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 19s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-06 16:11:47 UTC

@leosvelperez leosvelperez self-assigned this Jul 6, 2026
@leosvelperez
leosvelperez force-pushed the gh-36236 branch 2 times, most recently from a2b25b3 to adce214 Compare July 6, 2026 13:41
nx release publish marked a successful publish as failed when a published
file path contained curly braces (e.g. templates/{{name}}/file.txt). The
publish summary was located with a fixed-depth brace-counting regex that
treated braces inside JSON string values as structure, so the top-level
summary object never matched and extraction returned null, surfacing "The
pnpm publish output data could not be extracted" after the package had
already been published to the registry.

Replace the regex with a scanner that pairs each '{' with its matching '}'
while treating JSON string content as opaque, so braces and quotes inside a
string value no longer affect the pairing. Publish output is plain JSON mixed
with arbitrary lifecycle-script text, so the scanner does not treat '//' or
'/*' as comments and ends a string at a raw newline (which a valid JSON string
never contains); stray quotes, globs, and comment-like text in that output no
longer hide the summary. Balanced objects are scanned left to right and the
summary is unwrapped (flat, or nested one level under the package name).
@leosvelperez
leosvelperez marked this pull request as ready for review July 6, 2026 16:13
@leosvelperez
leosvelperez requested a review from a team as a code owner July 6, 2026 16:13
@leosvelperez
leosvelperez requested a review from AgentEnder July 6, 2026 16:13
@leosvelperez
leosvelperez merged commit 2f2e229 into master Jul 14, 2026
27 of 28 checks passed
@leosvelperez
leosvelperez deleted the gh-36236 branch July 14, 2026 07:29
FrozenPandaz pushed a commit that referenced this pull request Jul 20, 2026
…36241)

## Current Behavior

`nx release publish` can mark a publish as failed even after `pnpm
publish` (or `npm publish`) has already succeeded and pushed the package
to the registry. When a published file path contains curly braces, for
example a template directory like `templates/{{name}}/file.txt`, the
executor fails with:

> The pnpm publish output data could not be extracted. Please report
this issue on https://github.com/nrwl/nx

The publish summary was located in stdout with a fixed-depth
brace-counting regex. That regex is not JSON-aware: it treats `{` / `}`
inside a JSON string value (such as a `files[].path`) as structural
braces, so the top-level summary object no longer matches and extraction
returns `null`. The package is published, but the command reports
failure.

## Expected Behavior

When the package manager exits successfully and emits a valid JSON
publish summary, `nx release publish` parses it and reports success,
regardless of whether any `files[].path` contains curly braces.

## Related Issue(s)

Fixes #36236

## Implementation Details

`extractNpmPublishJsonData` no longer uses a regex. It pairs every `{`
with its matching `}` in one string-aware pass, ignoring braces and
quotes that appear inside JSON string literals, then scans the balanced
objects left to right and unwraps the summary (flat, or nested one level
under the package name for newer npm and for pnpm run from the workspace
root).

This removes the fixed-depth limitation: string values may contain any
number of braces and the object may nest arbitrarily deep. The summary
is interleaved with arbitrary lifecycle-script output, so the scanner
treats that surrounding text as opaque: it does not interpret `//` or
`/*` as comments (a script may legitimately print a glob such as
`dist/*.js`), and it ends a string at a raw newline (which valid JSON
never contains) so a stray quote in log text cannot hide the summary.
Stray unbalanced braces in that output are also left unpaired.

Added tests cover a `files[].path` with curly braces, a Windows-style
backslash-escaped path, a summary nested under the package name with a
brace-carrying path, unbalanced braces and a stray unpaired quote in
surrounding lifecycle output, and comment-like text or globs before the
summary.

<!-- polygraph-session-start -->
---
[View session information
↗](https://app.trypolygraph.com/orgs/6a061dcb561c062131116eca/sessions/gh-36236-bce72e6b)
<!-- polygraph-session-end -->

(cherry picked from commit 2f2e229)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nx release publish misparses pnpm publish JSON when files[].path contains {}

2 participants