Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
ikxin committed Feb 10, 2025
2 parents f3b1e9c + b15e015 commit 1cdbb96
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 85 deletions.
2 changes: 1 addition & 1 deletion docs/3.config/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ Rollup 别名选项。

### `moduleSideEffects`

默认值: `['unenv/runtime/polyfill/', 'node-fetch-native/polyfill']`
默认值: `['unenv/polyfill/', 'node-fetch-native/polyfill']`

Rollup 特定选项。指定具有副作用的模块导入。

Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default unjs({
"**/.output",
"**/.nitro",
"**/.netlify",
"**/.vercel",
"**/.nuxt",
"**/*.gen.*",
"**/dist",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"fs-extra": "^11.3.0",
"globby": "^14.0.2",
"gzip-size": "^7.0.0",
"h3": "^1.14.0",
"h3": "^1.15.0",
"hookable": "^5.5.3",
"httpxy": "^0.1.7",
"ioredis": "^5.4.2",
Expand All @@ -142,6 +142,7 @@
"mime": "^4.0.6",
"mlly": "^1.7.4",
"node-fetch-native": "^1.6.6",
"node-mock-http": "^1.0.0",
"ofetch": "^1.4.1",
"ohash": "^1.1.4",
"openapi-typescript": "^7.6.0",
Expand All @@ -162,7 +163,7 @@
"ultrahtml": "^1.5.3",
"uncrypto": "^0.1.3",
"unctx": "^2.4.1",
"unenv": "^1.10.0",
"unenv": "2.0.0-rc.3",
"unimport": "^4.0.0",
"unstorage": "^1.14.4",
"untyped": "^1.5.2",
Expand Down
40 changes: 24 additions & 16 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions runtime-meta.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const runtimeDependencies = [
"iron-webcrypto",
"klona",
"node-fetch-native",
"node-mock-http",
"ofetch",
"ohash",
"pathe",
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const NitroDefaults: NitroConfig = {
unenv: {},
analyze: false,
moduleSideEffects: [
"unenv/runtime/polyfill/",
"unenv/polyfill/",
"node-fetch-native/polyfill",
"node-fetch-native/dist/polyfill",
resolve(runtimeDir, "polyfill/"),
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/resolvers/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function resolveFetchOptions(options: NitroOptions) {
}
if (!options.experimental.nodeFetchCompat) {
options.alias = {
"node-fetch-native/polyfill": "unenv/runtime/mock/empty",
"node-fetch-native/polyfill": "unenv/mock/empty",
"node-fetch-native": "node-fetch-native/native",
...options.alias,
};
Expand Down
27 changes: 20 additions & 7 deletions src/presets/cloudflare/unenv/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,33 @@ const resolvePresetRuntime = (m: string) => join(presetRuntimeDir, `${m}.mjs`);
export const unenvCfPreset: Preset = {
external: nodeCompatModules.map((m) => `node:${m}`),
alias: {
// <id> => node:<id>
...Object.fromEntries(nodeCompatModules.map((m) => [m, `node:${m}`])),
...Object.fromEntries(hybridNodeCompatModules.map((m) => [m, `node:${m}`])),
// node:<id> => runtime/<id>.mjs (hybrid)
// (native)
...Object.fromEntries(
hybridNodeCompatModules.map((m) => [
`node:${m}`,
resolvePresetRuntime(m === "sys" ? "util" : m),
nodeCompatModules.flatMap((m) => [
[m, `node:${m}`],
[`node:${m}`, `node:${m}`],
])
),
// (hybrid)
...Object.fromEntries(
hybridNodeCompatModules.flatMap((m) => {
const resolved = resolvePresetRuntime(m);
return [
[`node:${m}`, resolved],
[m, resolved],
];
})
),
sys: resolvePresetRuntime("util"),
"node:sys": resolvePresetRuntime("util"),
"node-mock-http/_polyfill/events": "node:events",
"node-mock-http/_polyfill/buffer": "node:buffer",
},
inject: {
// process: "TODO",
// console: "TODO",
Buffer: ["node:buffer", "Buffer"],
"global.Buffer": ["node:buffer", "Buffer"],
"globalThis.Buffer": ["node:buffer", "Buffer"],
},
};
Expand Down
9 changes: 5 additions & 4 deletions src/presets/cloudflare/unenv/runtime/async_hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
import workerdAsyncHooks from "#workerd/node:async_hooks";

import {
// asyncWrapProviders,
asyncWrapProviders,
createHook,
executionAsyncId,
executionAsyncResource,
triggerAsyncId,
} from "unenv/runtime/node/async_hooks/index";
} from "unenv/node/async_hooks";

export {
// asyncWrapProviders,
asyncWrapProviders,
createHook,
executionAsyncId,
executionAsyncResource,
triggerAsyncId,
} from "unenv/runtime/node/async_hooks/index";
} from "unenv/node/async_hooks";

export const { AsyncLocalStorage, AsyncResource } = workerdAsyncHooks;

export default {
asyncWrapProviders,
createHook,
executionAsyncId,
executionAsyncResource,
Expand Down
10 changes: 5 additions & 5 deletions src/presets/cloudflare/unenv/runtime/crypto.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
diffieHellman,
ECDH,
getCipherInfo,
// hash,
hash,
privateDecrypt,
privateEncrypt,
pseudoRandomBytes,
Expand All @@ -29,7 +29,7 @@ import {
webcrypto as unenvCryptoWebcrypto,
Verify,
verify,
} from "unenv/runtime/node/crypto/index";
} from "unenv/node/crypto";

export {
Cipher,
Expand All @@ -47,14 +47,14 @@ export {
createVerify,
diffieHellman,
getCipherInfo,
// hash,
hash,
privateDecrypt,
privateEncrypt,
publicDecrypt,
publicEncrypt,
sign,
verify,
} from "unenv/runtime/node/crypto/index";
} from "unenv/node/crypto";

export const {
Certificate,
Expand Down Expand Up @@ -133,7 +133,7 @@ export default {
createVerify,
diffieHellman,
getCipherInfo,
// hash,
hash,
privateDecrypt,
privateEncrypt,
publicDecrypt,
Expand Down
16 changes: 8 additions & 8 deletions src/presets/cloudflare/unenv/runtime/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
isString,
isSymbol,
isUndefined,
// parseEnv,
// styleText,
} from "unenv/runtime/node/util/index";
parseEnv,
styleText,
} from "unenv/node/util";

export {
_errnoException,
Expand All @@ -48,9 +48,9 @@ export {
isString,
isSymbol,
isUndefined,
// parseEnv,
// styleText,
} from "unenv/runtime/node/util/index";
parseEnv,
styleText,
} from "unenv/node/util";

export const {
MIMEParams,
Expand Down Expand Up @@ -100,8 +100,8 @@ export default {
isString,
isSymbol,
isUndefined,
// parseEnv,
// styleText,
parseEnv,
styleText,
MIMEParams,
MIMEType,
TextDecoder,
Expand Down
2 changes: 1 addition & 1 deletion src/presets/deno/preset-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const denoServerLegacy = defineNitroPreset(
},
unenv: {
inject: {
global: ["unenv/runtime/polyfill/global-this", "default"],
global: ["unenv/polyfill/global-this", "default"],
Buffer: ["node:buffer", "Buffer"],
setTimeout: ["node:timers", "setTimeout"],
clearTimeout: ["node:timers", "clearTimeout"],
Expand Down
Loading

0 comments on commit 1cdbb96

Please sign in to comment.