github nubjs/nub v0.11.4
Nub 0.11.4

one hour ago

Nub v0.11.4 installs Yarn lockfiles the way Yarn does, writes pnpm-lock.yaml the way the pinned pnpm does, runs TypeScript written for "module": "commonjs" as CommonJS, and runs workspace packages from source before they're built.

A few changes can surface in an existing project, listed in Upgrading from v0.11.3.

Yarn lockfiles

Projects with a yarn.lock now install the same packages Yarn does (#1154, #1155, #1164). A Yarn 1 lockfile skipped every package's optionalDependencies, so platform bindings never installed and the parent failed:

Cannot find native binding. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828).

What changed:

  • Platform bindings. Yarn 1 and Yarn 2+ lockfiles install the host's binding for @rolldown/binding-*, @esbuild/*, @rollup/rollup-* and the like, and only that one. Yarn 2+ installed every platform's as a required dependency. Fixes #1153.
  • Transitive dependencies. A Yarn 2+ lockfile's transitive dependencies and npm aliases link under the default isolated layout. They failed with Cannot find module.
  • file: dependencies. A Yarn 2+ file: dependency installs, from the root or a workspace member. It was dropped.
  • Peer dependencies. Packages from a Yarn 1 or Yarn 2+ lockfile load their peers under the default isolated layout. require('react-dom/server') failed with Cannot find module 'react'.
  • Conversion to pnpm. A Yarn 2+ lockfile converted with nub import or nub pm use pnpm carries integrity and links its workspace members, so pnpm install --frozen-lockfile accepts it.
  • --no-optional. Omits optional dependencies at every depth, for every lockfile kind. It dropped only the root's own.

pnpm lockfiles and .npmrc

A fresh resolve writes the same pnpm-lock.yaml keys as the pnpm major the project pins (#1166, #1175, #1176). Under a pnpm 10 pin, a peer named only in peerDependenciesMeta stays out of the key, as pnpm 10 writes it:

-  debug@4.4.3(supports-color@7.2.0):
+  debug@4.4.3:

What changed:

  • Nested peers. A peer segment carries the peer's own peers, as in (storybook@9.1.21(@testing-library/dom@10.4.2)(vite@7.3.8)).
  • Segment order. Segments sort by the whole name@version(…) string, so (react-dom@…) comes before (react@…).
  • Peer cycles. A package on a peer cycle is named bare, eslint-plugin-import@2.32.0, in every key that mentions it.
  • pnpm 9 and 10 pins. Peers named only in peerDependenciesMeta stay out of keys. Unpinned projects and pnpm 11 pins keep pnpm 11's keys.
  • List lines in .npmrc. One key[]=value line per item adds to a list, as npm and pnpm read them (#1172). These lines were ignored.
  • Existing lockfiles keep their keys.

Pruning and partial installs

The nub prune command and partial installs no longer delete packages the tree still uses (#1164). Each command now reads the graph the last install linked instead of working it out again from the lockfile:

echo 'public-hoist-pattern=*eslint*' >> .npmrc
nub install   # links eslint and its plugins into the root node_modules
nub prune     # keeps them; it deleted them before

What changed:

  • Peers. In a project installed from an npm or Bun lockfile, nub prune deleted every package that has a peer.
  • Public hoisting. nub prune deleted every package public-hoist-pattern links into the root node_modules, workspace members included, and the next install reported it up to date.
  • Per-project lockfiles. nub prune at the root of a workspace with shared-workspace-lockfile=false deleted the members' packages.
  • --prod. nub prune --prod left development-only versions in a hoisted tree, and after a hoisted --prod install it deleted transitive dependencies the tree needed.
  • Partial hoisted installs. A hoisted --filter install, or a root install under recursive-install=false, deleted what the other members had hoisted into the root node_modules. It now links every member the last install linked, as pnpm does.
  • Moved versions. A hoisted relink after a version moved between directories kept the old version in the moved one.
  • Optional peers. Under the global virtual store, a package reaches an optional peer its ancestors don't provide, as pnpm's hidden hoist exposes it: debug finds supports-color.

TypeScript compiled to CommonJS

On Node 22.15 and later, a .ts or .tsx file whose tsconfig sets "module": "commonjs" runs as CommonJS, compiled the way tsc emits it (#1157, #1165). It ran as an ES module, so the first __dirname threw:

// tsconfig.json: { "compilerOptions": { "module": "commonjs" } }
import path from "node:path";

console.log(path.join(__dirname, "public"));

What it covers:

  • CommonJS globals. __dirname, __filename, require and module work beside import, as under ts-node and tsx.
  • Packages without "type": "module". The tsconfig wins over "type": "commonjs", where the import was refused before.
  • ES module importers. An .mjs file or an ES module package imports the compiled file and gets its named exports.
  • import(). Returns what tsc's output returns, and stays a real import() for an ES module that uses top-level await or import.meta.
  • Out of scope. .mts and .cts files, "module": "node16" and "nodenext", and Node 22.14 and earlier keep their behavior, as does Node 22.15 to 24.11 or 25.0 to 25.1 with another --import or --loader set.

Unbuilt workspace packages

When a workspace package's main, exports or imports names a file in its tsconfig outDir that doesn't exist yet, Nub loads the matching source under rootDir (#1156, #1170). A monorepo runs before anything is built:

// packages/lib/package.json:  { "name": "lib", "main": "./dist/index.js" }
// packages/lib/tsconfig.json: { "compilerOptions": { "rootDir": "src", "outDir": "dist" } }
import lib from "lib"; // loads packages/lib/src/index.ts

What it covers:

  • Built files first. The fallback runs only after Node fails to find the file, so a built file always loads.
  • Your resolve hooks first. A module.register or registerHooks hook, or a Module._resolveFilename wrapper, sees Node's error before Nub maps it.
  • Extensions. .js maps to .ts or .tsx, .mjs to .mts, .cjs to .cts.
  • The package's own tsconfig, with extends followed. Without rootDir, outputs map from the common directory of the files the tsconfig includes, as tsc infers it, or from the tsconfig's directory.
  • Entry files. Running nub dist/index.js loads src/index.ts.

Upgrading from v0.11.3

  • Run nub install once after upgrading. A tree an earlier Nub linked from an npm, Bun or Yarn lockfile, and any tree in the global virtual store, is linked again by the next install. Until then nub prune refuses:

    node_modules was linked by an older version
    help: run `nub install` before `nub prune`
    
  • TypeScript under "module": "commonjs" runs as CommonJS on Node 22.15 and later. A file that relied on running as an ES module can see these differences, as under tsc's output. Set "module" to "nodenext" to keep the old behavior.

    • An ES module importer gets the exports as they were when the file finished running, not live bindings.
    • A static import of a file with top-level await throws ERR_REQUIRE_ASYNC_MODULE.
    • A cycle between an ES module and a compiled file throws ERR_REQUIRE_CYCLE_MODULE.
    • An ES module that imports an export = file gets only default.
    • __esModule on a compiled file's exports is not enumerable.
  • Comma lists in a pnpm project's .npmrc. Under a pnpm pin, a comma-separated value for a list setting such as public-hoist-pattern is one pattern, as pnpm reads it (#1177). Write one key[]= line per item. The minimumReleaseAgeExclude setting still splits on commas.


What's Changed

  • pm: install transitive optionalDependencies from a yarn v1 lockfile by @colinhacks in #1154
  • pm: link yarn berry transitive deps and filter its platform bindings by @colinhacks in #1155
  • shim: add a remembered --no-modify-path flag by @colinhacks in #1140
  • resolve: run a workspace package's source when its outDir isn't built by @colinhacks in #1156
  • resolve: search a CommonJS bare subpath where Node searches by @colinhacks in #1158
  • runtime: compile .ts to CommonJS under "module": "commonjs" by @colinhacks in #1157
  • runtime: run a program whose --require preload calls module.register by @colinhacks in #1159
  • ci: check Node flag defaults for drift and acknowledge the Node 28 changes by @colinhacks in #1163
  • fix(store): detect missing dependency links in store status by @mvanhorn in #1160
  • resolve: let Node answer first where a CommonJS caller chose the lookup by @colinhacks in #1161
  • pm: link peer dependencies from a yarn.lock by @colinhacks in #1164
  • docs: migrate /docs and /guides to Darjeeling by @colinhacks in #1167
  • pm: write peer suffixes as pnpm does by @colinhacks in #1166
  • runtime: fix what the CommonJS emit broke for "module": "commonjs" by @colinhacks in #1165
  • docs: restore sidebar parity, header/footer actions, collapsible sidebar, and optical alignment by @colinhacks in #1171
  • resolve: fix what the outDir source fallback broke by @colinhacks in #1170
  • pm: read key[]= list lines in .npmrc by @colinhacks in #1172
  • pm: name a package on a peer cycle bare in every key by @colinhacks in #1176
  • pm: follow pnpm 9 and 10 for meta-only optional peers by @colinhacks in #1175
  • pm: keep a pnpm .npmrc list value whole by @colinhacks in #1177
  • pm: split a comma list of age-gate exclusions under pnpm by @colinhacks in #1178
  • runtime: keep Nub's hooks in Node's hook thread by @colinhacks in #1174
  • pm: treat a name in both dependencies and optionalDependencies as optional by @colinhacks in #1179
  • runtime: wait for Node's import of the entry on the loader-worker tier by @colinhacks in #1180
  • runtime: read a CommonJS entry off the module Node runs on the loader-worker tier by @colinhacks in #1183
  • runtime: keep a user's require.cache accessor and serve unpredictable entries on the loader-worker tier by @colinhacks in #1184

New Contributors

Full Changelog: v0.11.3...v0.11.4

Don't miss a new nub release

NewReleases is sending notifications on new releases.