Skip to content

Commit

Permalink
fixup! format
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Nov 27, 2024
1 parent e2e0ccf commit 49e9e81
Show file tree
Hide file tree
Showing 14 changed files with 1,024 additions and 1,034 deletions.
4 changes: 2 additions & 2 deletions packages/unenv-preset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
## Usage

```ts
import { env, nodeless, cloudflare } from "unenv-preset-cloudflare";
import { cloudflare, env, nodeless } from "unenv-preset-cloudflare";

const {
/* ... */
/* ... */
} = env(nodeless, cloudflare);
```
10 changes: 5 additions & 5 deletions packages/unenv-preset/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
declaration: true,
entries: [
"src/index",
{ input: "src/runtime/", outDir: "runtime", format: "esm" },
],
declaration: true,
entries: [
"src/index",
{ input: "src/runtime/", outDir: "runtime", format: "esm" },
],
});
62 changes: 31 additions & 31 deletions packages/unenv-preset/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ import unjs from "eslint-config-unjs";

// https://github.com/unjs/eslint-config
export default unjs(
{
ignores: ["runtime/**"],
rules: {
"@typescript-eslint/no-unused-vars": 0,
"unicorn/no-null": 0,
"unicorn/prefer-math-trunc": 0,
"unicorn/prefer-code-point": 0,
"unicorn/text-encoding-identifier-case": 0,
"prefer-rest-params": 0,
"prefer-spread": 0,
"unicorn/prefer-event-target": 0,
"unicorn/prefer-ternary": 0,
"unicorn/number-literal-case": 0,
"generator-star-spacing": 0,
"unicorn/no-nested-ternary": 0,
"require-await": 0,
"unicorn/switch-case-braces": 0,
"unicorn/prefer-string-replace-all": 0,
"no-empty": 0,
"no-func-assign": 0,
"unicorn/filename-case": 0,
"@typescript-eslint/no-unused-expressions": 0,
},
},
{
languageOptions: {
globals: {
Deno: "readonly",
},
},
},
{
ignores: ["runtime/**"],
rules: {
"@typescript-eslint/no-unused-vars": 0,
"unicorn/no-null": 0,
"unicorn/prefer-math-trunc": 0,
"unicorn/prefer-code-point": 0,
"unicorn/text-encoding-identifier-case": 0,
"prefer-rest-params": 0,
"prefer-spread": 0,
"unicorn/prefer-event-target": 0,
"unicorn/prefer-ternary": 0,
"unicorn/number-literal-case": 0,
"generator-star-spacing": 0,
"unicorn/no-nested-ternary": 0,
"require-await": 0,
"unicorn/switch-case-braces": 0,
"unicorn/prefer-string-replace-all": 0,
"no-empty": 0,
"no-func-assign": 0,
"unicorn/filename-case": 0,
"@typescript-eslint/no-unused-expressions": 0,
},
},
{
languageOptions: {
globals: {
Deno: "readonly",
},
},
}
);
106 changes: 53 additions & 53 deletions packages/unenv-preset/package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
{
"name": "@cloudflare/unenv-preset",
"version": "0.0.0",
"description": "cloudflare preset for unenv",
"keywords": [
"cloudflare",
"workers",
"cloudflare workers",
"Node.js",
"unenv",
"polyfills"
],
"homepage": "https://github.com/cloudflare/workers-sdk#readme",
"bugs": {
"url": "https://github.com/cloudflare/workers-sdk/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/cloudflare/workers-sdk.git",
"directory": "packages/unenv-preset"
},
"license": "MIT OR Apache-2.0",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
},
"./runtime/*": {
"types": "./runtime/*.d.ts",
"import": "./runtime/*.mjs"
}
},
"types": "./dist/index.d.ts",
"files": [
"dist",
"runtime"
],
"scripts": {
"build": "unbuild",
"check:lint": "eslint",
"check:type": "tsc --noEmit"
},
"dependencies": {
"unenv": "npm:[email protected]"
},
"devDependencies": {
"@types/node": "^22.9.3",
"eslint-config-unjs": "^0.4.1",
"typescript": "catalog:default",
"unbuild": "^2.0.0",
"wrangler": "workspace:*"
},
"name": "@cloudflare/unenv-preset",
"version": "0.0.0",
"description": "cloudflare preset for unenv",
"keywords": [
"cloudflare",
"workers",
"cloudflare workers",
"Node.js",
"unenv",
"polyfills"
],
"homepage": "https://github.com/cloudflare/workers-sdk#readme",
"bugs": {
"url": "https://github.com/cloudflare/workers-sdk/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/cloudflare/workers-sdk.git",
"directory": "packages/unenv-preset"
},
"license": "MIT OR Apache-2.0",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
},
"./runtime/*": {
"types": "./runtime/*.d.ts",
"import": "./runtime/*.mjs"
}
},
"types": "./dist/index.d.ts",
"files": [
"dist",
"runtime"
],
"scripts": {
"build": "unbuild",
"check:lint": "eslint",
"check:type": "tsc --noEmit"
},
"dependencies": {
"unenv": "npm:[email protected]"
},
"devDependencies": {
"@types/node": "^22.9.3",
"eslint-config-unjs": "^0.4.1",
"typescript": "catalog:default",
"unbuild": "^2.0.0",
"wrangler": "workspace:*"
},
"peerDependencies": {
"workerd": "^1.20241112.0"
},
Expand All @@ -59,4 +59,4 @@
"optional": true
}
}
}
}
128 changes: 67 additions & 61 deletions packages/unenv-preset/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,80 @@ import type { Preset } from "unenv";
// https://github.com/cloudflare/workerd/tree/main/src/node
// Last checked: 2024-10-22
const cloudflareNodeCompatModules = [
"_stream_duplex",
"_stream_passthrough",
"_stream_readable",
"_stream_transform",
"_stream_writable",
"assert",
"assert/strict",
"buffer",
"diagnostics_channel",
"events",
"path",
"path/posix",
"path/win32",
"querystring",
"stream",
"stream/consumers",
"stream/promises",
"stream/web",
"string_decoder",
"url",
"util/types",
"zlib",
"_stream_duplex",
"_stream_passthrough",
"_stream_readable",
"_stream_transform",
"_stream_writable",
"assert",
"assert/strict",
"buffer",
"diagnostics_channel",
"events",
"path",
"path/posix",
"path/win32",
"querystring",
"stream",
"stream/consumers",
"stream/promises",
"stream/web",
"string_decoder",
"url",
"util/types",
"zlib",
];

// Modules implemented via a mix of workerd APIs and polyfills.
// See `src/runtime/node/<module name>/$cloudflare.ts`.
const hybridNodeCompatModules = [
"async_hooks",
"console",
"crypto",
"module",
"process",
"timers",
"util",
"async_hooks",
"console",
"crypto",
"module",
"process",
"timers",
"util",
];

export const cloudflare: Preset = {
alias: {
...Object.fromEntries(
cloudflareNodeCompatModules.flatMap((p) => [
[p, p],
[`node:${p}`, `node:${p}`],
]),
),
alias: {
...Object.fromEntries(
cloudflareNodeCompatModules.flatMap((p) => [
[p, p],
[`node:${p}`, `node:${p}`],
])
),

// The `node:sys` module is just a deprecated alias for `node:util`
// Keep this until util is a full compat module.
sys: "@cloudflare/unenv-preset/runtime/node/util/$cloudflare",
"node:sys": "@cloudflare/unenv-preset/runtime/node/util/$cloudflare",
// The `node:sys` module is just a deprecated alias for `node:util`
// Keep this until util is a full compat module.
sys: "@cloudflare/unenv-preset/runtime/node/util/$cloudflare",
"node:sys": "@cloudflare/unenv-preset/runtime/node/util/$cloudflare",

// define aliases for hybrid modules
...Object.fromEntries(
hybridNodeCompatModules.flatMap((m) => [
[m, `@cloudflare/unenv-preset/runtime/node/${m}/$cloudflare`],
[`node:${m}`, `@cloudflare/unenv-preset/runtime/node/${m}/$cloudflare`],
]),
),
},
inject: {
// workerd already defines `global` and `Buffer`
// override the previous presets so that we use the native implementation
Buffer: false,
global: false,
console: "@cloudflare/unenv-preset/runtime/node/console/$cloudflare",
process: "@cloudflare/unenv-preset/runtime/node/process/$cloudflare",
setImmediate: ["@cloudflare/unenv-preset/runtime/node/timers/$cloudflare", "setImmediate"],
clearImmediate: ["@cloudflare/unenv-preset/runtime/node/timers/$cloudflare", "clearImmediate"],
},
polyfill: [],
external: cloudflareNodeCompatModules.flatMap((p) => [p, `node:${p}`]),
};
// define aliases for hybrid modules
...Object.fromEntries(
hybridNodeCompatModules.flatMap((m) => [
[m, `@cloudflare/unenv-preset/runtime/node/${m}/$cloudflare`],
[`node:${m}`, `@cloudflare/unenv-preset/runtime/node/${m}/$cloudflare`],
])
),
},
inject: {
// workerd already defines `global` and `Buffer`
// override the previous presets so that we use the native implementation
Buffer: false,
global: false,
console: "@cloudflare/unenv-preset/runtime/node/console/$cloudflare",
process: "@cloudflare/unenv-preset/runtime/node/process/$cloudflare",
setImmediate: [
"@cloudflare/unenv-preset/runtime/node/timers/$cloudflare",
"setImmediate",
],
clearImmediate: [
"@cloudflare/unenv-preset/runtime/node/timers/$cloudflare",
"clearImmediate",
],
},
polyfill: [],
external: cloudflareNodeCompatModules.flatMap((p) => [p, `node:${p}`]),
};
Loading

0 comments on commit 49e9e81

Please sign in to comment.