Skip to content

Commit d86b672

Browse files
authored
refactor: update unenv to v2 rc.4 (#3084)
1 parent 69b73ad commit d86b672

4 files changed

Lines changed: 54 additions & 34 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
"ultrahtml": "^1.5.3",
163163
"uncrypto": "^0.1.3",
164164
"unctx": "^2.4.1",
165-
"unenv": "2.0.0-rc.3",
165+
"unenv": "2.0.0-rc.4",
166166
"unimport": "^4.0.0",
167167
"unplugin-utils": "^0.2.3",
168168
"unstorage": "^1.14.4",

pnpm-lock.yaml

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

src/rollup/config.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { Plugin } from "rollup";
2121
import { visualizer } from "rollup-plugin-visualizer";
2222
import { isTest, isWindows } from "std-env";
2323
import { defineEnv } from "unenv";
24-
import type { Preset } from "unenv";
24+
import * as unenvPresets from "./unenv";
2525
import unimportPlugin from "unimport/unplugin";
2626
import { rollup as unwasm } from "unwasm/plugin";
2727
import { appConfig } from "./plugins/app-config";
@@ -60,36 +60,12 @@ export const getRollupConfig = (nitro: Nitro): RollupConfig => {
6060
nodeCompat: isNodeless,
6161
resolve: true,
6262
presets: [
63-
isNodeless
64-
? {
65-
// Backward compatibility (remove in v2)
66-
// https://github.com/unjs/unenv/pull/427
67-
inject: {
68-
performance: "unenv/polyfill/performance",
69-
},
70-
polyfill: [
71-
"unenv/polyfill/globalthis-global",
72-
"unenv/polyfill/process",
73-
"unenv/polyfill/performance",
74-
],
75-
}
76-
: {},
63+
unenvPresets.common,
64+
isNodeless ? unenvPresets.nodeless : unenvPresets.node,
7765
nitro.options.unenv,
7866
],
7967
overrides: {
8068
alias: {
81-
// General
82-
...(nitro.options.dev
83-
? {}
84-
: {
85-
debug: "unenv/npm/debug",
86-
}),
87-
...(isNodeless
88-
? {}
89-
: {
90-
"node-mock-http/_polyfill/events": "node:events",
91-
"node-mock-http/_polyfill/buffer": "node:buffer",
92-
}),
9369
...nitro.options.alias,
9470
},
9571
},
@@ -178,7 +154,7 @@ export const getRollupConfig = (nitro: Nitro): RollupConfig => {
178154
return relativePath.includes("node_modules");
179155
},
180156
},
181-
external: env.external,
157+
external: [...env.external],
182158
plugins: [],
183159
onwarn(warning, rollupWarn) {
184160
if (

src/rollup/unenv.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { Preset } from "unenv";
2+
3+
export const common: Preset = {
4+
alias: {
5+
"node-fetch": "unenv/npm/node-fetch",
6+
"cross-fetch": "unenv/npm/cross-fetch",
7+
"cross-fetch/polyfill": "unenv/mock/empty",
8+
"isomorphic-fetch": "unenv/mock/empty",
9+
debug: "unenv/npm/debug",
10+
// buffer (npm)
11+
buffer: "node:buffer",
12+
"buffer/": "node:buffer",
13+
"buffer/index": "node:buffer",
14+
"buffer/index.js": "node:buffer",
15+
},
16+
};
17+
18+
export const node: Preset = {
19+
alias: {
20+
"node-mock-http/_polyfill/events": "node:events",
21+
"node-mock-http/_polyfill/buffer": "node:buffer",
22+
},
23+
};
24+
25+
export const nodeless: Preset = {
26+
alias: {
27+
fsevents: "unenv/npm/fsevents",
28+
inherits: "unenv/npm/inherits",
29+
"whatwg-url": "unenv/npm/whatwg-url",
30+
},
31+
inject: {
32+
performance: "unenv/polyfill/performance",
33+
global: "unenv/polyfill/globalthis",
34+
process: "unenv/node/process",
35+
Buffer: ["unenv/node/buffer", "Buffer"],
36+
},
37+
polyfill: [
38+
// Backward compatibility (remove in v2)
39+
// https://github.com/unjs/unenv/pull/427
40+
"unenv/polyfill/globalthis-global",
41+
"unenv/polyfill/process",
42+
"unenv/polyfill/performance",
43+
],
44+
};

0 commit comments

Comments
 (0)