Repository navigation
Conversation
The entry point moves from `index.js` to `src/index.js`, next to the rest of the code that was in `lib/`.
cross-spawn is now an ES module with named exports only, `spawn` and
`spawnSync`, like cross-spawn-esm. CommonJS code can still load it with
`require()`, which Node.js 22.13 and later support without a warning.
The package now has an `exports` map, so only the package itself and its
`package.json` can be imported. Internal modules use named exports too,
and `readShebang.js` and `resolveCommand.js` are renamed to `shebang.js`
and `command.js`.
BREAKING CHANGE: there's no default export anymore, and `spawn.sync()` is
now `spawnSync()`. Use `import { spawn, spawnSync } from 'cross-spawn'` or
`const { spawn, spawnSync } = require('cross-spawn')`. Internal files, such
as `cross-spawn/lib/parse`, can't be imported anymore.
`spawn` and `spawnSync` have the same types as Node's, so `@types/cross-spawn` isn't needed anymore. `SpawnOptions` and `SpawnSyncOptions` are exported too, like cross-spawn-esm does. The types are checked with `npm run typecheck`, which compiles type tests for ES modules and CommonJS with TypeScript, including exact comparisons with Node's types. CI runs it with the lint.
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.
Rewrites cross-spawn as an ES module for v8, with named exports only, like cross-spawn-esm, and ships TypeScript types.
Commits
lib/becomessrc/, andindex.jsmoves tosrc/index.js."type": "module", and anexportsmap with only.and./package.json.spawnandspawnSync(wasspawn.sync), no default export, including internal modules.readShebang.jsandresolveCommand.jsare renamed toshebang.jsandcommand.js.path-keyis imported normally, instead ofrequire('path-key').default.src/index.d.ts:spawnandspawnSynctyped as Node's own (typeof childProcess.spawn/spawnSync), plusSpawnOptionsandSpawnSyncOptions.test/types/(ESM.mtsand CommonJS.cts), checked withnpm run typecheck(TypeScript 7,@types/node22 for the minimum Node.js version), which CI runs with the lint. They include exact type comparisons with Node's types, and@ts-expect-errorchecks, e.g. that there's no default export and thatspawn.sync()is gone. Breaking the types on purpose makes them fail.CommonJS
const { spawn, spawnSync } = require('cross-spawn')keeps working, since Node.js 22.13+ canrequire()ES modules without a warning. New tests check, by package name, that the package can be imported from ESM, required from CommonJS without warnings, and that internal files are not exported. The worker thread tests stillrequire()the package.Known costs of ESM-only, checked separately:
--experimental-vm-modules, or with a transform.jest.mock()with a factory still works.require()returns is a read-only module namespace, so stubbingrequire('cross-spawn').spawnno longer works.module: nodenextneed TypeScript 5.8+ to import it.BREAKING CHANGES
spawn.sync()is nowspawnSync().cross-spawn/lib/parse, can't be imported anymore.