Repository navigation
feat: support Yarn Plug'n'Play (PnP) - #27
Merged
Merged
Conversation
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Under Yarn PnP there is no node_modules tree, so nft's resolver missed every external package and its zips, in Yarn's global cache by default, sat outside nft's base. Ask PnP for the package's folder and let nft's own resolver apply exports from there, and trace from the filesystem root under PnP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test bundled lodash, so it passed without any tracing. Leave lodash and a dual import/require package external, check the output runs with plain node and loads the ESM build, and run it in CI. Remove the unused test/vite/test/pnp/index.js fixture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under PnP nft traces from the filesystem root, so the system-path filter also dropped Yarn's virtual, unplugged and local-cache packages of a project in /usr (Docker's WORKDIR /usr/src/app). Drop /usr paths only outside the project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under PnP each package sits in its own zip or unplugged folder, so the node_modules walk never found a package's platform binary (esbuild's @esbuild/linux-x64) and the app crashed on start. Ask PnP for the optional dependency's folder first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the platform optionalDependency (@esbuild/<platform>) that has to be copied from its own unplugged folder under PnP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous commit still dropped Yarn's global cache when it sits under /usr, since the cache is always outside the project. Skip the /usr filter under PnP: every PnP package lives in a Yarn folder, and files outside any package are already skipped. Outside PnP the filter is back to main's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yarn places these outside any node_modules folder, so nft couldn't find them from next to the package and the app crashed on start. Resolve them through PnP with nft's exports conditions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A checkout path with a space split the file: dependencies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolving them through PnP with nft's conditions missed nft's module-sync
handling, and took esbuild's require.resolve('pnpapi') for a package, so
.pnp.cjs was shipped. Let nft resolve the package as importing itself, or
the path inside its folder, and only for a folder with a package.json.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers a package Yarn places outside any node_modules folder, as it does for workspaces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yarn PnP keeps an aliased dependency in the folder of the package it installs, so it was copied under that package's name and a require of the alias (string-width-cjs in @isaacs/cliui) failed at runtime. Resolve the installed package and link the alias name to its copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two packages requiring the same alias name for different versions both got the last one. Link each alias inside its importer's copy, and at the top level only for the app's own imports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… PnP Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l exports under PnP Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…under PnP Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d by under PnP A fork whose package.json keeps the original's name and version no longer shares one output folder with the original. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A name another folder already took falls back to the package's own name, and folders are matched by their real path, so a symlinked portal: keeps its import name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…me is taken under PnP Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er PnP Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n of an npm package Both shared one output folder, so a fork kept at the original's version mixed its files with the npm package's. The local folder is copied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d version of an npm package" Copying only the local folder dropped files the npm package's importers need, which works on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d version under PnP The fork gets a version of its own, so the existing multi-version layout links each importer to its copy. The app's own import takes the top level. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…by that name under PnP An app importing both the fork and the npm package (under an alias) got the npm package for both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… is known The name a folder got depended on which import nft resolved first, so a fork imported as ms and ms2 sometimes lost its ms name to the npm package. It now takes its package.json name when imported by it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mports under PnP A local fork at an older version than the npm package lost the top level to it, so the app's own import got the npm package. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r PnP relocate.ts's fallback resolved every import with require conditions, so a renamed portal: package's require build got bundled into ESM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ckages included The app's npm ms lost the top level to a newer local fork another package imports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…has the same one Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… under Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… only sets "type" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its name Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nder its name Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nitedani-agent
marked this pull request as ready for review
October 29, 2026 10:36
Owner
|
run refactor then merge |
Contributor
Author
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Done in 6085568: This account has read access only, so the merge is yours. CI waits for your approval of the fork's workflow run. I'd approve it and squash-merge once it's green. |
nitedani-agent
added a commit
to nitedani-agent/standaloner
that referenced
this pull request
Oct 30, 2026
…pies PnP's local-fork version suffix now applies before assignCopies, so a fork and the npm package of its name and version never share a copy; the PnP app import and npm: alias links use output copies instead of versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a Yarn PnP project, standaloner leaves every external dependency out of the output, so the build succeeds but the app crashes on start. This PR finds those packages through Yarn and copies them, including from Yarn's global cache.
This supersedes #20 by @rtritto. His seven commits are kept here, rebased on
main, with him as their author. Thank you for starting this!lodashleft external)mainyarn node build.mjs, thennode dist/index.mjsdist/node_modulesstays empty,ERR_MODULE_NOT_FOUND: Cannot find package 'lodash'lodashcopied, the app runsThe old PnP check never ran, because
requireis undefined in this ES module (trace.ts#L93-L98).This PR asks Yarn where each package's folder is and lets Node File Trace (nft) resolve it from there with its usual
exportsrules. It also copies platform binaries such as@esbuild/linux-x64, workspace andportal:packages, andnpm:aliases under their alias name. From #20, asset relocation resolvesrequire()paths from the importing file instead of from standaloner's own folder, in every project.The build has to run through Yarn (
yarn node build.jsoryarn <script>). Alink:folder without its ownpackage.jsonisn't copied, because it has no package name to copy it under. A local package without anameis missed when only itsexportsfield leads to its entry file, because@vercel/nftappliesexportsonly to named packages. Two copies of one package that get different peer dependencies still ship as one, as onmainwithout PnP (#28).Closes #6
What you should see
Each case runs on Node 26, on
main(c46848b) and on this PR (193b056).1.
test/pnp, the new CI test:2. A monorepo app leaving a workspace with
module-syncexports and aportal:package external prints what it prints under Yarn:3. An app under
/usr/src/appwithesbuild,react-domanddebugexternal:Approach: five candidates, C chosen (9/10)
createRequire(parent).resolve(id)when nft misses@vercel/nftA copied nothing with Yarn's global cache on (its default). B had to reimplement nft's
exportshandling (module-syncand its fallback). C keeps nft's own rules, and nft'sresolveoption is the extension point its maintainers chose for PnP (vercel/nft#153). Full record and the decisions made while converging: https://gist.github.com/nitedani-agent/fc43f9ced9b5cfad8f87a899eb3a42f6Loop A: 23 passes on Node 26 and Node 20, the last (on 193b056) found nothing
Each pass ran probes on the head it named. Early passes compared its output with
mainand with the same project undernodeLinker: node-modules. Later ones also compared it with the app run directly under Yarn. After each fix since 0e8905c, an app leavingexpress,@babel/core,eslint,webpackandaws-sdkexternal copied the same 3562 files as withnodeLinker: node-modules(maincopies none). Fixed, by area:/usr(12ef853, ebcf7e3), platform binaries such as@esbuild/linux-x64(8deda65), a workspace withmodule-syncexports and.pnp.cjsshipped (1b55235), files under a nested{"type":"module"}package.json (c928d81).npm:aliases: one alias name at two versions (3ff8901), an app alias whose name a dependency's package also has (18bef03, 193b056).portal:packages (668e665, 34355ec), two local folders with one name (dc3fce0, 65971d6, 0e8905c, 41e7479, 1149d25).importbuild (f078f7a).Below the bar, outside this change: two peer copies of one name and version ship as one, on
maintoo (#28). A local package without anamereached only throughexportsis missed (nft's self-reference rule). Full reports: https://gist.github.com/nitedani-agent/0b5a256b8c5c076735a66bfc13f9c8d3Loop B: 20 review rounds, the last four clean, the last one on 193b056
Fixed: a shell command split on paths with spaces (c820760), one alias link per importing package instead of per name (3ff8901), a refactor that records a package imported under another name in one place (2d74ba9), one that reads each import's copy from the folder it resolved to (591719b), and a test that keeps the app's own local
utilswhen a dependency imports anotherutils(e7bff26). Declined: a CI lane for a project under/usr(it needs root on the runner), and amodule-synctest (nft skipsmodule-syncon Node 20, which CI runs). Full reports: https://gist.github.com/nitedani-agent/7ff89740d0e33cc06ca92636cd794436Fresh read: 7 rounds as nitedani, the last says merge as is (on 193b056)
Code findings fixed: an
npm:alias losing its name (33e0fbb, 39e1619), no test requiring a package with conditional exports from CommonJS (3acb228), a renamedportal:dependency crashing (668e665), and the app'snpm:alias losing to a dependency's local package (18bef03). Two peer copies shipping as one became #28. The other findings were on this description. Outside this change, onmaintoo: Rolldown bundles a package'simportexport overmodule-sync, and a package whoseimportsmap points at another dependency is copied without it. Full reports: https://gist.github.com/nitedani-agent/31131c6e531349a9aae28ee3a7418962Refactor pass: asked for in https://github.com//pull/27#issuecomment-6501158643, one change (6085568)
A fresh pass over the whole diff on 193b056 rated every file and function. Its one finding:
pnpResolvechecked whether a package sits in anode_modulesfolder twice. 6085568 handles an npm package in one early-return branch, and a local package after it, with the same behavior. The re-rating on 6085568 found nothing more. Full reports: https://gist.github.com/nitedani-agent/df0f870446abf38747b3b5c7fda498d1Gates: install, build and the four test suites exit 0 on 6085568, on Node 20 and Node 26
The CI workflow's steps, run locally because this fork PR's CI waits for workflow approval:
pnpm install,pnpm buildtest/vite,test/isolated,test/assets(10, 6 and 24 checks)test/pnp(2 checks)Corepack is disabled on the machine that ran them, so
test/pnpran Yarn 4 throughpnpm dlxbehind acorepackshim.