-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: change the build config to bundle deps correctly, fix #111 #112
Conversation
@@ -31,7 +31,7 @@ | |||
"typecheck": "tsc", | |||
"prepublishOnly": "nr build", | |||
"release": "bumpp && pnpm publish --no-git-checks", | |||
"test": "vitest" | |||
"test": "unbuild && vitest" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new test case is against the dist
, so the dist
needs to be built before the test happens.
@@ -67,6 +66,7 @@ | |||
"npm-package-arg": "^11.0.2", | |||
"npm-registry-fetch": "^16.2.1", | |||
"rimraf": "^5.0.5", | |||
"semver": "^7.6.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semver
is a CommonJS module and a dependency of both taze
and taze
's dependency.
Rollup has trouble handling a CommonJS external from a transitive dependency, so let's bundle semver
as well.
@@ -3,7 +3,7 @@ import type { Argv } from 'yargs' | |||
import yargs from 'yargs' | |||
import { hideBin } from 'yargs/helpers' | |||
import c from 'picocolors' | |||
import { version } from '../package.json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we've disabled the @rollup/plugin-json
's namedExports
optimization, we can't use named import here.
Thanks for the detailed explaination! |
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
.