-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
chore: make terser an optional dependency #8049
Conversation
Probably not "chore" but breaking? |
https://github.com/vitejs/vite/blob/main/.github/commit-convention.md#tldr |
9ed0b77
to
ba7d055
Compare
55c4d94
to
3cbfcfc
Compare
3cbfcfc
to
9f2468a
Compare
BREAKING CHANGE: `terser` must be installed for minification with terser
9f2468a
to
de7f351
Compare
I selected 5.4.0 because #8045 (comment). |
Co-authored-by: patak <matias.capeletto@gmail.com>
Co-authored-by: patak <matias.capeletto@gmail.com>
This commit (925fd58) worked. CI is now happy. 🙌 |
const loadTerserPath = (root: string) => { | ||
if (terserPath) return terserPath | ||
try { | ||
terserPath = requireResolveFromRootWithFallback(root, 'terser') |
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.
I think we can use createRequire
here instead https://nodejs.org/docs/latest-v14.x/api/module.html#module_module_createrequire_filename
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.
Actually the one used in the CSS plugin should be changed to createRequire
too
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.
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.
Instead of
const resolved = require.resolve(name, [root, ...fallbackPaths]);
require(resolved)
I think it's safer to use:
const requireFromRoot = createRequire(path.resolve(root, 'index.cjs'))
requireFromRoot(name)
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.
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.
Wait 🤔 This problem is more complicated than I thought…
To clarify, I'm concerned about the require
method used here is not "clean" (would be interfered with by require.cache
, etc.).
Both require
and require.resolve
should be created from the root path so that we can get a fresh instance of terser
, sass
, etc. The point is that require
should be returned from createRequire(some-file-in-the-root-dir)
too.
Here comes the complexity:
- The above-mentioned refactor will fix a theoretical problem. Though I think it's better, no known issues have been found with the old way.
- But the refactor would break a real-world use case (resolve fallbacks): fix: allow preprocessor to be installed outside of the root directory #3988
- On the other hand, if I understand correctly, the use case seems to already be broken by the ESM refactor: the
_require
used incss.ts
now is a newly created function, which doesn't inheritrequire.resolve.paths
from the framework that wraps Vite https://github.com/sapphi-red/vite/blob/b6ec807e863e0e27cb16846f995c8e3a5c48b9fd/packages/vite/src/node/plugins/css.ts#L1282
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.
Anyway, my original suggestion is to make requireResolveFromRootWithFallback
requireFromRootWithFallback
(that is, put the require
part into the function too).
It's a nice-to-have.
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.
I'm leaving this for now because I tried now but I didn't make it work.
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.
@sodatea do you think we could merge this then? And then work on your request as an enhancement? Or is this still blocking the PR?
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.
Yeah the PR looks good to me. It's not a blocking change.
CI become unhappy now. 😢 Mostly it is failing with this error.
This happened once.
|
Rerunning all CI worked. I'm not sure why rerunning only the failed test didn't work 🤔. |
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.
Minor docs nitpick, but this looks great
@sapphi-red would you check the merge conflicts? |
BREAKING CHANGE:
terser
must be installed for minification with terserDescription
This PR makes terser an optional dependency since it is not a default option now.
This will reduce package size much.
Result of
npm publish --dry-run
Before
After
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).