Skip to content
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!: update rollup commonjs plugin to v22 #8743

Merged
merged 13 commits into from Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/LICENSE.md
Expand Up @@ -2197,7 +2197,7 @@ Repository: unjs/mlly

> MIT License
>
> Copyright (c) 2022 UnJS
> Copyright (c) 2021
sodatea marked this conversation as resolved.
Show resolved Hide resolved
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Expand Up @@ -71,7 +71,7 @@
"@babel/types": "^7.18.4",
"@jridgewell/trace-mapping": "^0.3.13",
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-dynamic-import-vars": "^1.4.3",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "13.3.0",
Expand Down
27 changes: 20 additions & 7 deletions packages/vite/rollup.config.ts
Expand Up @@ -134,15 +134,13 @@ function createNodePlugins(
},
// postcss-load-config calls require after register ts-node
'postcss-load-config/src/index.js': {
src: `require(configFile)`,
replacement: `__require(configFile)`
},
// @rollup/plugin-commonjs uses incorrect esm
'@rollup/plugin-commonjs/dist/index.es.js': {
src: `import { sync } from 'resolve';`,
replacement: `import __resolve from 'resolve';const sync = __resolve.sync;`
pattern: /require(?=\((configFile|'ts-node')\))/g,
replacement: `eval('require')`
}
}),

buildTimeImportMetaUrl(),

commonjs({
extensions: ['.js'],
// Optional peer deps of ws. Native deps that are mostly for performance.
Expand Down Expand Up @@ -287,6 +285,21 @@ function shimDepsPlugin(deps: Record<string, ShimOptions>): Plugin {
}
}

// The use of `import.meta.url` in source code is not reliable after bundling.
// For example, it is affected by the `isEntry` bug brought in by the Rollup CJS plugin
// https://github.com/rollup/plugins/pull/1180
// The better way is to resolve it at build time.
function buildTimeImportMetaUrl(): Plugin {
return {
name: 'buildTimeImportMetaUrl',
resolveImportMeta: (property, chunk) => {
if (property === 'url') {
return `'file://${chunk.moduleId}'`
}
}
}
}

function licensePlugin() {
return license({
thirdParty(dependencies) {
Expand Down
22 changes: 19 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.