Skip to content

Commit f3db430

Browse files
vite-plugin: update unenv preset dependency (#8365)
* update vite-plugin to use the latest unenv-preset * revert side-effect update This should be covered by the field in `dist/runtime/polyfill/package.json`.
1 parent c018844 commit f3db430

File tree

4 files changed

+24
-27
lines changed

4 files changed

+24
-27
lines changed

.changeset/cold-baths-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vite-plugin": patch
3+
---
4+
5+
update vite-plugin to use the latest unenv-preset

packages/vite-plugin-cloudflare/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
"test:watch": "vitest"
4343
},
4444
"dependencies": {
45-
"@cloudflare/unenv-preset": "1.1.1",
45+
"@cloudflare/unenv-preset": "workspace:*",
4646
"@hattip/adapter-node": "^0.0.49",
4747
"miniflare": "workspace:*",
4848
"tinyglobby": "^0.2.12",
49-
"unenv": "2.0.0-rc.1",
49+
"unenv": "2.0.0-rc.15",
5050
"wrangler": "workspace:*",
5151
"ws": "catalog:default"
5252
},

packages/vite-plugin-cloudflare/src/node-js-compat.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ export function injectGlobalCode(id: string, code: string) {
6161
})
6262
.join("\n");
6363

64+
// Some globals are not injected using the approach above but are added to globalThis via side-effect imports of polyfills from the unenv-preset.
65+
const polyfillCode = env.polyfill
66+
.map((polyfillPath) => `import "${polyfillPath}";\n`)
67+
.join("");
68+
6469
const modified = new MagicString(code);
6570
modified.prepend(injectedCode);
71+
modified.prepend(polyfillCode);
6672
return {
6773
code: modified.toString(),
6874
map: modified.generateMap({ hires: "boundary", source: id }),
@@ -100,8 +106,10 @@ export function resolveNodeJSImport(source: string) {
100106
* Gets a set of module specifiers for all possible Node.js compat polyfill entry-points
101107
*/
102108
function getNodeCompatEntries() {
109+
// Include all the alias targets
103110
const entries = new Set<string>(Object.values(env.alias));
104111

112+
// Include all the injection targets
105113
for (const globalInject of Object.values(env.inject)) {
106114
if (typeof globalInject === "string") {
107115
entries.add(globalInject);
@@ -114,6 +122,10 @@ function getNodeCompatEntries() {
114122
}
115123
}
116124

125+
// Include all the polyfills
126+
env.polyfill.forEach((polyfill) => entries.add(polyfill));
127+
128+
// Exclude all the externals
117129
nodeCompatExternals.forEach((external) => entries.delete(external));
118130

119131
return entries;

pnpm-lock.yaml

Lines changed: 5 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)