@powerlines/plugin-cloudflare 0.3.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_index = require('./node_modules/.pnpm/@cloudflare_unenv-preset@2.15.0_unenv@2.0.0-rc.24/node_modules/@cloudflare/unenv-preset/dist/index.cjs');
3
4
  const require_components_cloudflare_builtin = require('./components/cloudflare-builtin.cjs');
4
5
  const require_components_env_builtin = require('./components/env-builtin.cjs');
5
6
  const require_components_worker_entry = require('./components/worker-entry.cjs');
@@ -9,8 +10,11 @@ let _alloy_js_core = require("@alloy-js/core");
9
10
  let _powerlines_plugin_alloy_render = require("@powerlines/plugin-alloy/render");
10
11
  let _powerlines_plugin_env_helpers = require("@powerlines/plugin-env/helpers");
11
12
  let _powerlines_plugin_esbuild_helpers_resolve = require("@powerlines/plugin-esbuild/helpers/resolve");
13
+ let _powerlines_plugin_unenv = require("@powerlines/plugin-unenv");
14
+ _powerlines_plugin_unenv = require_runtime.__toESM(_powerlines_plugin_unenv);
12
15
  let _pulumi_cloudflare = require("@pulumi/cloudflare");
13
16
  _pulumi_cloudflare = require_runtime.__toESM(_pulumi_cloudflare);
17
+ let _stryke_helpers_omit = require("@stryke/helpers/omit");
14
18
  let _stryke_path = require("@stryke/path");
15
19
  let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
16
20
  let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
@@ -22,10 +26,17 @@ defu = require_runtime.__toESM(defu);
22
26
  * A Powerlines plugin to assist in developing other Powerlines plugins.
23
27
  */
24
28
  function plugin(options = {}) {
25
- return [{
29
+ return [(0, _powerlines_plugin_unenv.default)(options.unenv), {
26
30
  name: "cloudflare",
27
31
  config() {
28
- return { cloudflare: (0, defu.default)(options, {}) };
32
+ return {
33
+ cloudflare: (0, defu.default)((0, _stryke_helpers_omit.omit)(options, ["unenv"]), {}),
34
+ resolve: { skipNodeModulesBundle: false },
35
+ unenv: { presets: [require_index.getCloudflarePreset({
36
+ compatibilityDate: this.config.compatibilityDate?.toString(),
37
+ compatibilityFlags: ["nodejs_als"]
38
+ })] }
39
+ };
29
40
  },
30
41
  configResolved() {
31
42
  this.devDependencies["@cloudflare/workers-types"] = "^4.20240616.0";
@@ -42,9 +53,11 @@ function plugin(options = {}) {
42
53
  if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.file}" is missing an input file.`);
43
54
  const workerModule = await (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(this, entry.input);
44
55
  if (!workerModule?.default) throw new Error(`Cloudflare Worker entry "${entry.file}" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \`ExportedHandler\` interface from "@cloudflare/workers-types".`);
56
+ const name = workerModule.metadata?.name || (0, _stryke_path.replaceExtension)(entry.input.file || entry.file) || arr.length > 1 ? `${this.config.name}-${i}` : this.config.name;
45
57
  return {
46
58
  metadata: {
47
- name: workerModule.metadata?.name || (0, _stryke_path.replaceExtension)(entry.input.file || entry.file) || arr.length > 1 ? `${this.config.name}-${i}` : this.config.name,
59
+ name,
60
+ pattern: `${name}.{domain}`,
48
61
  entry
49
62
  },
50
63
  fetch: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.fetch),
@@ -73,29 +86,45 @@ function plugin(options = {}) {
73
86
  else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
74
87
  }
75
88
  await this.pulumi.setConfig("cloudflare:apiToken", { value: apiToken });
89
+ const provider = new _pulumi_cloudflare.Provider("cloudflare-provider", { apiToken });
76
90
  const zone = await _pulumi_cloudflare.getZone({ filter: {
77
91
  account: { id: this.config.cloudflare.accountId },
78
92
  name: this.config.cloudflare.domain
79
- } });
93
+ } }, { provider });
80
94
  const workerScripts = [];
81
95
  const workerRoutes = [];
96
+ const dnsRecords = [];
82
97
  for (const worker of this.workers) {
83
- const workerScript = new _pulumi_cloudflare.WorkersScript(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.worker-script`, {
98
+ const workerScript = new _pulumi_cloudflare.WorkersScript(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.worker-script`, (0, defu.default)({
84
99
  accountId: this.config.cloudflare.accountId,
85
100
  scriptName: worker.metadata.name,
86
- contentFile: (0, _stryke_path.joinPaths)(this.config.output.outputPath, "index.js")
87
- });
101
+ contentFile: (0, _stryke_path.joinPaths)(this.config.output.publishPath, "index.js"),
102
+ module: true
103
+ }, worker.metadata, {
104
+ compatibilityDate: this.config.compatibilityDate?.cloudflare?.toString(),
105
+ compatibilityFlags: ["nodejs_als"]
106
+ }), { provider });
88
107
  workerScripts.push(workerScript);
89
- const workerRoute = new _pulumi_cloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.worker-route`, {
108
+ const workerRoute = new _pulumi_cloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.worker-route`, (0, defu.default)({
90
109
  zoneId: zone.id,
91
- pattern: `hello-world.${this.config.cloudflare.domain}`,
110
+ pattern: worker.metadata.pattern.replace("{domain}", this.config.cloudflare.domain),
92
111
  script: workerScript.scriptName
93
- });
112
+ }, worker.metadata), { provider });
94
113
  workerRoutes.push(workerRoute);
114
+ const dnsRecord = new _pulumi_cloudflare.DnsRecord(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.dns-record`, {
115
+ name: workerRoute.pattern,
116
+ type: "A",
117
+ content: "192.0.2.1",
118
+ zoneId: zone.id,
119
+ proxied: true,
120
+ ttl: 1
121
+ }, { provider });
122
+ dnsRecords.push(dnsRecord);
95
123
  }
96
124
  return {
97
125
  workerScripts,
98
- workerRoutes
126
+ workerRoutes,
127
+ dnsRecords
99
128
  };
100
129
  }
101
130
  }];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA0CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAgJJ,MAAA,CAAO,QAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA6CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAgNJ,MAAA,CAAO,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA0CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAgJJ,MAAA,CAAO,QAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA6CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAgNJ,MAAA,CAAO,QAAA"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { getCloudflarePreset } from "./node_modules/.pnpm/@cloudflare_unenv-preset@2.15.0_unenv@2.0.0-rc.24/node_modules/@cloudflare/unenv-preset/dist/index.mjs";
1
2
  import { CloudflareBuiltin } from "./components/cloudflare-builtin.mjs";
2
3
  import { CloudflareEnvBuiltin } from "./components/env-builtin.mjs";
3
4
  import { WorkerEntry } from "./components/worker-entry.mjs";
@@ -7,7 +8,9 @@ import { For } from "@alloy-js/core";
7
8
  import { render } from "@powerlines/plugin-alloy/render";
8
9
  import { readEnvTypeReflection } from "@powerlines/plugin-env/helpers";
9
10
  import { resolveModule } from "@powerlines/plugin-esbuild/helpers/resolve";
11
+ import unenv from "@powerlines/plugin-unenv";
10
12
  import * as pulumiCloudflare from "@pulumi/cloudflare";
13
+ import { omit } from "@stryke/helpers/omit";
11
14
  import { joinPaths, replaceExtension } from "@stryke/path";
12
15
  import { kebabCase } from "@stryke/string-format/kebab-case";
13
16
  import { isFunction } from "@stryke/type-checks/is-function";
@@ -18,10 +21,17 @@ import defu from "defu";
18
21
  * A Powerlines plugin to assist in developing other Powerlines plugins.
19
22
  */
20
23
  function plugin(options = {}) {
21
- return [{
24
+ return [unenv(options.unenv), {
22
25
  name: "cloudflare",
23
26
  config() {
24
- return { cloudflare: defu(options, {}) };
27
+ return {
28
+ cloudflare: defu(omit(options, ["unenv"]), {}),
29
+ resolve: { skipNodeModulesBundle: false },
30
+ unenv: { presets: [getCloudflarePreset({
31
+ compatibilityDate: this.config.compatibilityDate?.toString(),
32
+ compatibilityFlags: ["nodejs_als"]
33
+ })] }
34
+ };
25
35
  },
26
36
  configResolved() {
27
37
  this.devDependencies["@cloudflare/workers-types"] = "^4.20240616.0";
@@ -38,9 +48,11 @@ function plugin(options = {}) {
38
48
  if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.file}" is missing an input file.`);
39
49
  const workerModule = await resolveModule(this, entry.input);
40
50
  if (!workerModule?.default) throw new Error(`Cloudflare Worker entry "${entry.file}" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \`ExportedHandler\` interface from "@cloudflare/workers-types".`);
51
+ const name = workerModule.metadata?.name || replaceExtension(entry.input.file || entry.file) || arr.length > 1 ? `${this.config.name}-${i}` : this.config.name;
41
52
  return {
42
53
  metadata: {
43
- name: workerModule.metadata?.name || replaceExtension(entry.input.file || entry.file) || arr.length > 1 ? `${this.config.name}-${i}` : this.config.name,
54
+ name,
55
+ pattern: `${name}.{domain}`,
44
56
  entry
45
57
  },
46
58
  fetch: isFunction(workerModule.default.fetch),
@@ -69,29 +81,45 @@ function plugin(options = {}) {
69
81
  else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
70
82
  }
71
83
  await this.pulumi.setConfig("cloudflare:apiToken", { value: apiToken });
84
+ const provider = new pulumiCloudflare.Provider("cloudflare-provider", { apiToken });
72
85
  const zone = await pulumiCloudflare.getZone({ filter: {
73
86
  account: { id: this.config.cloudflare.accountId },
74
87
  name: this.config.cloudflare.domain
75
- } });
88
+ } }, { provider });
76
89
  const workerScripts = [];
77
90
  const workerRoutes = [];
91
+ const dnsRecords = [];
78
92
  for (const worker of this.workers) {
79
- const workerScript = new pulumiCloudflare.WorkersScript(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}.${kebabCase(worker.metadata.name)}`}.worker-script`, {
93
+ const workerScript = new pulumiCloudflare.WorkersScript(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}.${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.worker-script`, defu({
80
94
  accountId: this.config.cloudflare.accountId,
81
95
  scriptName: worker.metadata.name,
82
- contentFile: joinPaths(this.config.output.outputPath, "index.js")
83
- });
96
+ contentFile: joinPaths(this.config.output.publishPath, "index.js"),
97
+ module: true
98
+ }, worker.metadata, {
99
+ compatibilityDate: this.config.compatibilityDate?.cloudflare?.toString(),
100
+ compatibilityFlags: ["nodejs_als"]
101
+ }), { provider });
84
102
  workerScripts.push(workerScript);
85
- const workerRoute = new pulumiCloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}-${kebabCase(worker.metadata.name)}`}.worker-route`, {
103
+ const workerRoute = new pulumiCloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}-${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.worker-route`, defu({
86
104
  zoneId: zone.id,
87
- pattern: `hello-world.${this.config.cloudflare.domain}`,
105
+ pattern: worker.metadata.pattern.replace("{domain}", this.config.cloudflare.domain),
88
106
  script: workerScript.scriptName
89
- });
107
+ }, worker.metadata), { provider });
90
108
  workerRoutes.push(workerRoute);
109
+ const dnsRecord = new pulumiCloudflare.DnsRecord(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}-${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.dns-record`, {
110
+ name: workerRoute.pattern,
111
+ type: "A",
112
+ content: "192.0.2.1",
113
+ zoneId: zone.id,
114
+ proxied: true,
115
+ ttl: 1
116
+ }, { provider });
117
+ dnsRecords.push(dnsRecord);
91
118
  }
92
119
  return {
93
120
  workerScripts,
94
- workerRoutes
121
+ workerRoutes,
122
+ dnsRecords
95
123
  };
96
124
  }
97
125
  }];
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For } from \"@alloy-js/core\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { joinPaths, replaceExtension } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions,\n CloudflareWorkerEntryModule\n} from \"./types/plugin\";\nimport { WorkerModule } from \"./types/worker-module\";\n\nexport * from \"./components\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n cloudflare?: CloudflarePluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CloudflarePluginContext = CloudflarePluginContext\n>(options: CloudflarePluginOptions = {}) {\n return [\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(options, {})\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\n },\n async prepare() {\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <>\n <CloudflareBuiltin />\n <CloudflareEnvBuiltin reflection={result} />\n </>\n );\n },\n build: {\n order: \"pre\",\n async handler() {\n this.workers = await Promise.all(\n this.entry.map(async (entry, i, arr) => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.file}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<WorkerModule>(\n this,\n entry.input\n );\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.file\n }\" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \\`ExportedHandler\\` interface from \"@cloudflare/workers-types\".`\n );\n }\n\n return {\n metadata: {\n name:\n workerModule.metadata?.name ||\n replaceExtension(entry.input.file || entry.file) ||\n arr.length > 1\n ? `${this.config.name}-${i}`\n : this.config.name,\n entry\n },\n fetch: isFunction(workerModule.default.fetch),\n tail: isFunction(workerModule.default.tail),\n trace: isFunction(workerModule.default.trace),\n tailStream: isFunction(workerModule.default.tailStream),\n scheduled: isFunction(workerModule.default.scheduled),\n test: isFunction(workerModule.default.test),\n email: isFunction(workerModule.default.email),\n queue: isFunction(workerModule.default.queue)\n } satisfies CloudflareWorkerEntryModule;\n })\n );\n\n return render(\n this,\n <For each={this.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deployPulumi() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n await this.pulumi.setConfig(\"cloudflare:apiToken\", {\n value: apiToken\n });\n\n const zone = await pulumiCloudflare.getZone({\n filter: {\n account: { id: this.config.cloudflare.accountId },\n name: this.config.cloudflare.domain\n }\n });\n\n const workerScripts = [] as pulumiCloudflare.WorkersScript[];\n const workerRoutes = [] as pulumiCloudflare.WorkersRoute[];\n for (const worker of this.workers) {\n const workerScript = new pulumiCloudflare.WorkersScript(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.worker-script`,\n {\n accountId: this.config.cloudflare.accountId,\n scriptName: worker.metadata.name,\n contentFile: joinPaths(this.config.output.outputPath, \"index.js\")\n }\n );\n workerScripts.push(workerScript);\n\n const workerRoute = new pulumiCloudflare.WorkersRoute(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.worker-route`,\n {\n zoneId: zone.id,\n pattern: `hello-world.${this.config.cloudflare.domain}`,\n script: workerScript.scriptName\n }\n );\n workerRoutes.push(workerRoute);\n }\n\n return {\n workerScripts,\n workerRoutes\n };\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6CA,SAAA,OAAA,UAAA,EAAA,EAAA;;EAEE,MAAA;EACE,SAAC;AACH,UAAA,EACK,YAAS,KAAM,SAAA,EAAA,CAAA,EACpB;;EAEA,iBAAO;AACL,QAAA,gBAAA,+BAAA;;EAEA,MAAE,UAAS;GACT,MAAE,SAAO,MAAA,sBAAA,MAAA,MAAA;AACT,UAAI,OAAU,MAAM,CAAC,gBAAW,mBAAA,EAAA,CAAA,EAAA,gBAAA,sBAAA,EAC9B,YAAC,QACF,CAAA,CAAA,CAAA;;EAEH,OAAI;GACF,OAAC;GACD,MAAM,UAAU;IACd,MAAM,SAAS;;AAEf,SAAM,CAAC,MAAM,MACX,OAAI,IAAA,MAAA,4BAAA,MAAA,KAAA,6BAAA;KAEJ,MAAG,eAAkB,MAAC,cAAA,MAAA,MAAA,MAAA;AACtB,SAAG,CAAA,cAAA,QACD,OAAA,IAAA,MAAA,4BAAA,MAAA,KAAA,gNAAA;AAEL,YAAA;MACK,UAAC;OACC,MAAM,aAAA,UAAA,QAAA,iBAAA,MAAA,MAAA,QAAA,MAAA,KAAA,IAAA,IAAA,SAAA,IAAA,GAAA,KAAA,OAAA,KAAA,GAAA,MAAA,KAAA,OAAA;OACN;OACJ;MACE,OAAK,WAAU,aAAgB,QAAQ,MAAC;MACxC,MAAM,WAAO,aAAO,QAAA,KAAA;MACpB,OAAI,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,GAAA,KAAA,OAAA,eAAA,GAAA,KAAA,OAAA,aAAA,KAAA,KAAA,UAAA,KAAA,OAAA,KAAA,KAAA,UAAA,OAAA,SAAA,KAAA,GAAA,UAAA,KAAA,OAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,GAAA,UAAA,OAAA,SAAA,KAAA,GAAA,gBAAA;KAC7C,QAAG,KAAU;KACb,SAAS,eAAc,KAAA,OAAW,WAAQ;KAC1C,QAAI,aAAU;KACf,CAAC;AACF,iBAAU,KAAQ,YAAY;;AAEhC,UAAM;IACJ;IACA;IACD;;EAEJ,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For } from \"@alloy-js/core\";\nimport { getCloudflarePreset } from \"@cloudflare/unenv-preset\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport unenv from \"@powerlines/plugin-unenv\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths, replaceExtension } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions,\n CloudflareWorkerEntryModule\n} from \"./types/plugin\";\nimport { WorkerModule } from \"./types/worker-module\";\n\nexport * from \"./components\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n cloudflare?: CloudflarePluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CloudflarePluginContext = CloudflarePluginContext\n>(options: CloudflarePluginOptions = {}) {\n return [\n unenv(options.unenv),\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(omit(options, [\"unenv\"]), {}),\n resolve: {\n skipNodeModulesBundle: false\n },\n unenv: {\n presets: [\n getCloudflarePreset({\n compatibilityDate: this.config.compatibilityDate?.toString(),\n compatibilityFlags: [\"nodejs_als\"]\n })\n ]\n }\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\n },\n async prepare() {\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <>\n <CloudflareBuiltin />\n <CloudflareEnvBuiltin reflection={result} />\n </>\n );\n },\n build: {\n order: \"pre\",\n async handler() {\n this.workers = await Promise.all(\n this.entry.map(async (entry, i, arr) => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.file}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<WorkerModule>(\n this,\n entry.input\n );\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.file\n }\" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \\`ExportedHandler\\` interface from \"@cloudflare/workers-types\".`\n );\n }\n\n const name =\n workerModule.metadata?.name ||\n replaceExtension(entry.input.file || entry.file) ||\n arr.length > 1\n ? `${this.config.name}-${i}`\n : this.config.name;\n\n return {\n metadata: {\n name,\n pattern: `${name}.{domain}`,\n entry\n },\n fetch: isFunction(workerModule.default.fetch),\n tail: isFunction(workerModule.default.tail),\n trace: isFunction(workerModule.default.trace),\n tailStream: isFunction(workerModule.default.tailStream),\n scheduled: isFunction(workerModule.default.scheduled),\n test: isFunction(workerModule.default.test),\n email: isFunction(workerModule.default.email),\n queue: isFunction(workerModule.default.queue)\n } satisfies CloudflareWorkerEntryModule;\n })\n );\n\n return render(\n this,\n <For each={this.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deployPulumi() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n await this.pulumi.setConfig(\"cloudflare:apiToken\", {\n value: apiToken\n });\n\n const provider = new pulumiCloudflare.Provider(\"cloudflare-provider\", {\n apiToken\n });\n\n const zone = await pulumiCloudflare.getZone(\n {\n filter: {\n account: { id: this.config.cloudflare.accountId },\n name: this.config.cloudflare.domain\n }\n },\n { provider }\n );\n\n const workerScripts = [] as pulumiCloudflare.WorkersScript[];\n const workerRoutes = [] as pulumiCloudflare.WorkersRoute[];\n const dnsRecords = [] as pulumiCloudflare.DnsRecord[];\n for (const worker of this.workers) {\n const workerScript = new pulumiCloudflare.WorkersScript(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-script`,\n defu(\n {\n accountId: this.config.cloudflare.accountId,\n scriptName: worker.metadata.name,\n contentFile: joinPaths(\n this.config.output.publishPath,\n \"index.js\"\n ),\n module: true\n },\n worker.metadata,\n {\n compatibilityDate:\n this.config.compatibilityDate?.cloudflare?.toString() as string,\n compatibilityFlags: [\"nodejs_als\"]\n }\n ) as pulumiCloudflare.WorkersScriptArgs,\n { provider }\n );\n workerScripts.push(workerScript);\n\n const workerRoute = new pulumiCloudflare.WorkersRoute(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-route`,\n defu(\n {\n zoneId: zone.id,\n pattern: worker.metadata.pattern.replace(\n \"{domain}\",\n this.config.cloudflare.domain\n ),\n script: workerScript.scriptName\n },\n worker.metadata\n ),\n { provider }\n );\n workerRoutes.push(workerRoute);\n\n const dnsRecord = new pulumiCloudflare.DnsRecord(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.dns-record`,\n {\n name: workerRoute.pattern,\n type: \"A\",\n content: \"192.0.2.1\",\n zoneId: zone.id,\n proxied: true,\n ttl: 1\n },\n { provider }\n );\n dnsRecords.push(dnsRecord);\n }\n\n return {\n workerScripts,\n workerRoutes,\n dnsRecords\n };\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAA,OAAA,UAAA,EAAA,EAAA;;EAEE,MAAA;EACE,SAAC;AACH,UAAA;IACK,YAAS,KAAM,KAAA,SAAA,CAAA,QAAA,CAAA,EAAA,EAAA,CAAA;IACpB,SAAS,EACD,uBAAC,OACF;IACL,OAAM,EACN,SAAA,CAAA,oBAAA;KACQ,mBAAY,KAAA,OAAA,mBAAA,UAAA;KAC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KAAA,UAAA,OAAA,SAAA,KAAA,GAAA,UAAA,KAAA,OAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,GAAA,UAAA,OAAA,SAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,gBAAA,KAAA;KACjB,QAAK,KAAO;KACZ,SAAG,OAAA,SAAA,QAAA,QAAA,YAAA,KAAA,OAAA,WAAA,OAAA;KACH,QAAA,aAAA;KACF,EAAA,OAAA,SAAA,EAAA,YAEA,CAAA;AACA,iBAAS,KAAA,YAAA;IACT,MAAE,YAAA,IAAA,iBAAA,UAAA,GAAA,KAAA,OAAA,eAAA,GAAA,KAAA,OAAA,aAAA,KAAA,KAAA,UAAA,KAAA,OAAA,KAAA,KAAA,UAAA,OAAA,SAAA,KAAA,GAAA,UAAA,KAAA,OAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,GAAA,UAAA,OAAA,SAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,cAAA;;KAEF,MAAM;KACJ,SAAA;KACA,QAAA,KAAA;;KAEF,KAAM;KACL,EAAC,EACA,UACD,CAAC;AACF,eAAW,KAAK,UAAQ;;AAE1B,UAAK;IACH;IACA;;IAED;;EAEJ,CAAC"}
@@ -0,0 +1,370 @@
1
+ const require_runtime = require('../../../../../../../_virtual/_rolldown/runtime.cjs');
2
+ let node_url = require("node:url");
3
+ node_url = require_runtime.__toESM(node_url);
4
+ let node_path = require("node:path");
5
+ node_path = require_runtime.__toESM(node_path);
6
+ let node_module = require("node:module");
7
+ node_module = require_runtime.__toESM(node_module);
8
+
9
+ //#region ../../node_modules/.pnpm/@cloudflare+unenv-preset@2.15.0_unenv@2.0.0-rc.24/node_modules/@cloudflare/unenv-preset/dist/index.mjs
10
+ const __filename$1 = node_url.default.fileURLToPath(require("url").pathToFileURL(__filename).href);
11
+ node_path.default.dirname(__filename$1);
12
+ node_module.default.createRequire(require("url").pathToFileURL(__filename).href);
13
+ const version = "2.15.0";
14
+ const defaultNativeModules = [
15
+ "_stream_duplex",
16
+ "_stream_passthrough",
17
+ "_stream_readable",
18
+ "_stream_transform",
19
+ "_stream_writable",
20
+ "_tls_common",
21
+ "_tls_wrap",
22
+ "assert",
23
+ "assert/strict",
24
+ "async_hooks",
25
+ "buffer",
26
+ "constants",
27
+ "crypto",
28
+ "diagnostics_channel",
29
+ "dns",
30
+ "dns/promises",
31
+ "events",
32
+ "net",
33
+ "path",
34
+ "path/posix",
35
+ "path/win32",
36
+ "querystring",
37
+ "module",
38
+ "stream",
39
+ "stream/consumers",
40
+ "stream/promises",
41
+ "stream/web",
42
+ "string_decoder",
43
+ "sys",
44
+ "timers",
45
+ "timers/promises",
46
+ "tls",
47
+ "url",
48
+ "util",
49
+ "util/types",
50
+ "zlib"
51
+ ];
52
+ function getCloudflarePreset({ compatibilityDate = "2024-09-03", compatibilityFlags = [] }) {
53
+ const compat = {
54
+ compatibilityDate,
55
+ compatibilityFlags
56
+ };
57
+ const overrides = [
58
+ getHttpOverrides(compat),
59
+ getHttp2Overrides(compat),
60
+ getOsOverrides(compat),
61
+ getFsOverrides(compat),
62
+ getPunycodeOverrides(compat),
63
+ getClusterOverrides(compat),
64
+ getTraceEventsOverrides(compat),
65
+ getDomainOverrides(compat),
66
+ getWasiOverrides(compat),
67
+ getConsoleOverrides(compat),
68
+ getVmOverrides(compat),
69
+ getInspectorOverrides(compat),
70
+ getSqliteOverrides(compat),
71
+ getDgramOverrides(compat),
72
+ getStreamWrapOverrides(compat),
73
+ getReplOverrides(compat),
74
+ getProcessOverrides(compat),
75
+ getV8Overrides(compat),
76
+ getTtyOverrides(compat),
77
+ getChildProcessOverrides(compat),
78
+ getWorkerThreadsOverrides(compat),
79
+ getReadlineOverrides(compat),
80
+ getPerfHooksOverrides(compat)
81
+ ];
82
+ const nativeModules = [...defaultNativeModules, ...overrides.flatMap((o) => o.nativeModules)];
83
+ const hybridModules = overrides.flatMap((o) => o.hybridModules);
84
+ const injects = Object.assign({}, ...overrides.map((o) => o.inject ?? {}));
85
+ const polyfills = overrides.flatMap((o) => o.polyfills ?? []);
86
+ return {
87
+ meta: {
88
+ name: "unenv:cloudflare",
89
+ version,
90
+ url: __filename$1
91
+ },
92
+ alias: {
93
+ ...Object.fromEntries(nativeModules.flatMap((p) => [[p, p], [`node:${p}`, `node:${p}`]])),
94
+ ...Object.fromEntries(hybridModules.flatMap((m) => [[m, `@cloudflare/unenv-preset/node/${m}`], [`node:${m}`, `@cloudflare/unenv-preset/node/${m}`]]))
95
+ },
96
+ inject: {
97
+ Buffer: false,
98
+ global: false,
99
+ clearImmediate: false,
100
+ setImmediate: false,
101
+ ...injects
102
+ },
103
+ polyfill: polyfills,
104
+ external: nativeModules.flatMap((p) => [p, `node:${p}`])
105
+ };
106
+ }
107
+ function getHttpOverrides({ compatibilityDate, compatibilityFlags }) {
108
+ const httpDisabledByFlag = compatibilityFlags.includes("disable_nodejs_http_modules");
109
+ if (!((compatibilityFlags.includes("enable_nodejs_http_modules") || compatibilityDate >= "2025-08-15") && !httpDisabledByFlag)) return {
110
+ nativeModules: [],
111
+ hybridModules: []
112
+ };
113
+ const httpServerEnabledByFlag = compatibilityFlags.includes("enable_nodejs_http_server_modules");
114
+ const httpServerDisabledByFlag = compatibilityFlags.includes("disable_nodejs_http_server_modules");
115
+ return {
116
+ nativeModules: [
117
+ "_http_agent",
118
+ "_http_client",
119
+ "_http_common",
120
+ "_http_incoming",
121
+ "_http_outgoing",
122
+ ...(httpServerEnabledByFlag || compatibilityDate >= "2025-09-01") && !httpServerDisabledByFlag ? ["_http_server"] : [],
123
+ "http",
124
+ "https"
125
+ ],
126
+ hybridModules: []
127
+ };
128
+ }
129
+ function getHttp2Overrides({ compatibilityDate, compatibilityFlags }) {
130
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_http2_module");
131
+ return (compatibilityFlags.includes("enable_nodejs_http2_module") || compatibilityDate >= "2025-09-01") && !disabledByFlag ? {
132
+ nativeModules: ["http2"],
133
+ hybridModules: []
134
+ } : {
135
+ nativeModules: [],
136
+ hybridModules: []
137
+ };
138
+ }
139
+ function getOsOverrides({ compatibilityDate, compatibilityFlags }) {
140
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_os_module");
141
+ return (compatibilityFlags.includes("enable_nodejs_os_module") || compatibilityDate >= "2025-09-15") && !disabledByFlag ? {
142
+ nativeModules: ["os"],
143
+ hybridModules: []
144
+ } : {
145
+ nativeModules: [],
146
+ hybridModules: []
147
+ };
148
+ }
149
+ function getFsOverrides({ compatibilityDate, compatibilityFlags }) {
150
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_fs_module");
151
+ return (compatibilityFlags.includes("enable_nodejs_fs_module") || compatibilityDate >= "2025-09-15") && !disabledByFlag ? {
152
+ nativeModules: ["fs/promises", "fs"],
153
+ hybridModules: []
154
+ } : {
155
+ nativeModules: [],
156
+ hybridModules: []
157
+ };
158
+ }
159
+ function getPunycodeOverrides({ compatibilityDate, compatibilityFlags }) {
160
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_punycode_module");
161
+ return (compatibilityFlags.includes("enable_nodejs_punycode_module") || compatibilityDate >= "2025-12-04") && !disabledByFlag ? {
162
+ nativeModules: ["punycode"],
163
+ hybridModules: []
164
+ } : {
165
+ nativeModules: [],
166
+ hybridModules: []
167
+ };
168
+ }
169
+ function getClusterOverrides({ compatibilityDate, compatibilityFlags }) {
170
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_cluster_module");
171
+ return (compatibilityFlags.includes("enable_nodejs_cluster_module") || compatibilityDate >= "2025-12-04") && !disabledByFlag ? {
172
+ nativeModules: ["cluster"],
173
+ hybridModules: []
174
+ } : {
175
+ nativeModules: [],
176
+ hybridModules: []
177
+ };
178
+ }
179
+ function getTraceEventsOverrides({ compatibilityDate, compatibilityFlags }) {
180
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_trace_events_module");
181
+ return (compatibilityFlags.includes("enable_nodejs_trace_events_module") || compatibilityDate >= "2025-12-04") && !disabledByFlag ? {
182
+ nativeModules: ["trace_events"],
183
+ hybridModules: []
184
+ } : {
185
+ nativeModules: [],
186
+ hybridModules: []
187
+ };
188
+ }
189
+ function getDomainOverrides({ compatibilityDate, compatibilityFlags }) {
190
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_domain_module");
191
+ return (compatibilityFlags.includes("enable_nodejs_domain_module") || compatibilityDate >= "2025-12-04") && !disabledByFlag ? {
192
+ nativeModules: ["domain"],
193
+ hybridModules: []
194
+ } : {
195
+ nativeModules: [],
196
+ hybridModules: []
197
+ };
198
+ }
199
+ function getWasiOverrides({ compatibilityDate, compatibilityFlags }) {
200
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_wasi_module");
201
+ return (compatibilityFlags.includes("enable_nodejs_wasi_module") || compatibilityDate >= "2025-12-04") && !disabledByFlag ? {
202
+ nativeModules: ["wasi"],
203
+ hybridModules: []
204
+ } : {
205
+ nativeModules: [],
206
+ hybridModules: []
207
+ };
208
+ }
209
+ function getConsoleOverrides({ compatibilityDate, compatibilityFlags }) {
210
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_console_module");
211
+ return (compatibilityFlags.includes("enable_nodejs_console_module") || compatibilityDate >= "2025-09-21") && !disabledByFlag ? {
212
+ nativeModules: ["console"],
213
+ hybridModules: [],
214
+ inject: {}
215
+ } : {
216
+ nativeModules: [],
217
+ hybridModules: ["console"],
218
+ inject: { console: "@cloudflare/unenv-preset/node/console" }
219
+ };
220
+ }
221
+ function getVmOverrides({ compatibilityDate, compatibilityFlags }) {
222
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_vm_module");
223
+ return (compatibilityFlags.includes("enable_nodejs_vm_module") || compatibilityDate >= "2025-10-01") && !disabledByFlag ? {
224
+ nativeModules: ["vm"],
225
+ hybridModules: []
226
+ } : {
227
+ nativeModules: [],
228
+ hybridModules: []
229
+ };
230
+ }
231
+ function getInspectorOverrides({ compatibilityDate, compatibilityFlags }) {
232
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_inspector_module");
233
+ return (compatibilityFlags.includes("enable_nodejs_inspector_module") || compatibilityDate >= "2026-01-29") && !disabledByFlag ? {
234
+ nativeModules: ["inspector/promises", "inspector"],
235
+ hybridModules: []
236
+ } : {
237
+ nativeModules: [],
238
+ hybridModules: []
239
+ };
240
+ }
241
+ function getSqliteOverrides({ compatibilityDate, compatibilityFlags }) {
242
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_sqlite_module");
243
+ return (compatibilityFlags.includes("enable_nodejs_sqlite_module") || compatibilityDate >= "2026-01-29") && !disabledByFlag ? {
244
+ nativeModules: ["sqlite"],
245
+ hybridModules: []
246
+ } : {
247
+ nativeModules: [],
248
+ hybridModules: []
249
+ };
250
+ }
251
+ function getDgramOverrides({ compatibilityDate, compatibilityFlags }) {
252
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_dgram_module");
253
+ return (compatibilityFlags.includes("enable_nodejs_dgram_module") || compatibilityDate >= "2026-01-29") && !disabledByFlag ? {
254
+ nativeModules: ["dgram"],
255
+ hybridModules: []
256
+ } : {
257
+ nativeModules: [],
258
+ hybridModules: []
259
+ };
260
+ }
261
+ function getStreamWrapOverrides({ compatibilityDate, compatibilityFlags }) {
262
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_stream_wrap_module");
263
+ return (compatibilityFlags.includes("enable_nodejs_stream_wrap_module") || compatibilityDate >= "2026-01-29") && !disabledByFlag ? {
264
+ nativeModules: ["_stream_wrap"],
265
+ hybridModules: []
266
+ } : {
267
+ nativeModules: [],
268
+ hybridModules: []
269
+ };
270
+ }
271
+ function getReplOverrides({ compatibilityFlags }) {
272
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_repl_module");
273
+ return compatibilityFlags.includes("enable_nodejs_repl_module") && compatibilityFlags.includes("experimental") && !disabledByFlag ? {
274
+ nativeModules: ["repl"],
275
+ hybridModules: []
276
+ } : {
277
+ nativeModules: [],
278
+ hybridModules: []
279
+ };
280
+ }
281
+ function getProcessOverrides({ compatibilityDate, compatibilityFlags }) {
282
+ const disabledV2ByFlag = compatibilityFlags.includes("disable_nodejs_process_v2");
283
+ const enabledV2ByFlag = compatibilityFlags.includes("enable_nodejs_process_v2");
284
+ const enabledV2ByDate = compatibilityDate >= "2025-09-15";
285
+ return hasFetchIterableFixes({
286
+ compatibilityDate,
287
+ compatibilityFlags
288
+ }) && (enabledV2ByFlag || enabledV2ByDate) && !disabledV2ByFlag ? {
289
+ nativeModules: ["process"],
290
+ hybridModules: [],
291
+ inject: { process: false }
292
+ } : {
293
+ nativeModules: [],
294
+ hybridModules: ["process"],
295
+ inject: { process: "@cloudflare/unenv-preset/node/process" }
296
+ };
297
+ }
298
+ function hasFetchIterableFixes({ compatibilityDate, compatibilityFlags }) {
299
+ const supportEnabledByFlag = compatibilityFlags.includes("fetch_iterable_type_support");
300
+ const supportDisabledByFlag = compatibilityFlags.includes("no_fetch_iterable_type_support");
301
+ if (!((compatibilityDate >= "2026-02-19" || supportEnabledByFlag) && !supportDisabledByFlag)) return false;
302
+ const adjustmentEnabledByFlag = compatibilityFlags.includes("fetch_iterable_type_support_override_adjustment");
303
+ const adjustmentDisabledByFlag = compatibilityFlags.includes("no_fetch_iterable_type_support_override_adjustment");
304
+ return (adjustmentEnabledByFlag || compatibilityDate >= "2026-01-15") && !adjustmentDisabledByFlag;
305
+ }
306
+ function getV8Overrides({ compatibilityFlags }) {
307
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_v8_module");
308
+ return compatibilityFlags.includes("enable_nodejs_v8_module") && compatibilityFlags.includes("experimental") && !disabledByFlag ? {
309
+ nativeModules: ["v8"],
310
+ hybridModules: []
311
+ } : {
312
+ nativeModules: [],
313
+ hybridModules: []
314
+ };
315
+ }
316
+ function getTtyOverrides({ compatibilityFlags }) {
317
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_tty_module");
318
+ return compatibilityFlags.includes("enable_nodejs_tty_module") && compatibilityFlags.includes("experimental") && !disabledByFlag ? {
319
+ nativeModules: ["tty"],
320
+ hybridModules: []
321
+ } : {
322
+ nativeModules: [],
323
+ hybridModules: []
324
+ };
325
+ }
326
+ function getChildProcessOverrides({ compatibilityFlags }) {
327
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_child_process_module");
328
+ return compatibilityFlags.includes("enable_nodejs_child_process_module") && compatibilityFlags.includes("experimental") && !disabledByFlag ? {
329
+ nativeModules: ["child_process"],
330
+ hybridModules: []
331
+ } : {
332
+ nativeModules: [],
333
+ hybridModules: []
334
+ };
335
+ }
336
+ function getWorkerThreadsOverrides({ compatibilityFlags }) {
337
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_worker_threads_module");
338
+ return compatibilityFlags.includes("enable_nodejs_worker_threads_module") && compatibilityFlags.includes("experimental") && !disabledByFlag ? {
339
+ nativeModules: ["worker_threads"],
340
+ hybridModules: []
341
+ } : {
342
+ nativeModules: [],
343
+ hybridModules: []
344
+ };
345
+ }
346
+ function getReadlineOverrides({ compatibilityFlags }) {
347
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_readline_module");
348
+ return compatibilityFlags.includes("enable_nodejs_readline_module") && compatibilityFlags.includes("experimental") && !disabledByFlag ? {
349
+ nativeModules: ["readline", "readline/promises"],
350
+ hybridModules: []
351
+ } : {
352
+ nativeModules: [],
353
+ hybridModules: []
354
+ };
355
+ }
356
+ function getPerfHooksOverrides({ compatibilityFlags }) {
357
+ const disabledByFlag = compatibilityFlags.includes("disable_nodejs_perf_hooks_module");
358
+ return compatibilityFlags.includes("enable_nodejs_perf_hooks_module") && compatibilityFlags.includes("experimental") && !disabledByFlag ? {
359
+ nativeModules: ["perf_hooks"],
360
+ hybridModules: []
361
+ } : {
362
+ nativeModules: [],
363
+ hybridModules: [],
364
+ polyfills: ["@cloudflare/unenv-preset/polyfill/performance"]
365
+ };
366
+ }
367
+ const cloudflare = getCloudflarePreset({});
368
+
369
+ //#endregion
370
+ exports.getCloudflarePreset = getCloudflarePreset;