fix: change the build config to bundle deps correctly, fix #111 #112
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.
Description
#111 is caused by the Rollup (
unbuild
uses Rollup under the hood) incorrectly bundling@npmcli/config
(and its transitive dependencycacache
, which requires its ownpackage.json
).The PR provides a workaround by changing how dists are bundled. A test case has also been added to ensure the CLI itself should never crash.
Linked Issues
#111
Additional context
This is a workaround that works for now. I am still investigating a better solution that solves the issue once and for all.
Here are the backgrounds behind #111 and this PR:
@npmcli/config
requirescacache
, andcacache
requires its ownpackage.json
. This causes@rollup/plugin-commonjs
to panic. Instead of using the correct named exports generated from@rollup/plugin-json
,@rollup/plugin-commonjs
try to wrap the exports with its interop code, causingcacache
to fail.@rollup/plugin-commonjs
'srequireReturnsDefault
toauto
, disable@rollup/plugin-json
'snamedExports
optimization.@npmcli/config
also requiressemver/function/valid
. Since@npmcli/config
is a CJS module,require('semver/function/valid')
works just fine. However, when Rollup bundles the dist, it transformsrequire('semver/function/valid')
intoimport 'semver/function/valid'
which is an invalid ESM import (missing the extname, it should beimport 'semver/function/valid.js'
), causing the error of npx taze@latest throws [ERR_MODULE_NOT_FOUND] #111.semver
as well, preventing transitive dependency from becoming external.semver
would cause another build error, sinceunbuild
includes@types/semver
to be parsed by the rollup.rollup-plugin-dts
'srespectExternal
.