@harlan-zw/nuxt-cloudflare 0.0.11 → 0.0.13

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.
@@ -17,6 +17,10 @@ interface CloudflareBindingAccessor<Environment extends object> {
17
17
  require: <Name extends BindingName<Environment>>(name: Name, source?: unknown) => Exclude<Environment[Name], undefined>;
18
18
  }
19
19
  declare function resolveCloudflareBindings<Environment extends object = CloudflareBindings>(source?: unknown): Environment | undefined;
20
+ /** Sets the environment used by eventless Cloudflare binding resolution. */
21
+ declare function setCloudflareBindings<Environment extends object>(env: Environment | undefined): void;
22
+ /** Merges binding sources into the eventless environment. Later sources win. */
23
+ declare function mergeCloudflareBindings<Environment extends object = CloudflareBindings>(...sources: Array<Partial<Environment> | undefined>): Environment;
20
24
  /** Creates the event-shaped source required by Nitro runtime config resolution. */
21
25
  declare function runtimeConfigSource<Environment extends object>(env: Environment): CloudflareRuntimeConfigSource<Environment>;
22
26
  /**
@@ -27,5 +31,5 @@ declare function runtimeConfigSource<Environment extends object>(env: Environmen
27
31
  */
28
32
  declare function createCloudflareBindings<Environment extends object = CloudflareBindings>(): CloudflareBindingAccessor<Environment>;
29
33
 
30
- export { createCloudflareBindings, resolveCloudflareBindings, runtimeConfigSource };
34
+ export { createCloudflareBindings, mergeCloudflareBindings, resolveCloudflareBindings, runtimeConfigSource, setCloudflareBindings };
31
35
  export type { CloudflareBindingAccessor, CloudflareRuntimeConfigSource };
package/dist/bindings.mjs CHANGED
@@ -11,6 +11,18 @@ function resolveCloudflareBindings(source) {
11
11
  const globalEnv = asRecord(globalThis.__env__);
12
12
  return sourceEnv ?? globalEnv;
13
13
  }
14
+ function setCloudflareBindings(env) {
15
+ const host = globalThis;
16
+ if (env === void 0)
17
+ delete host.__env__;
18
+ else
19
+ host.__env__ = env;
20
+ }
21
+ function mergeCloudflareBindings(...sources) {
22
+ const merged = Object.assign({}, ...sources.filter((source) => source !== void 0));
23
+ setCloudflareBindings(merged);
24
+ return merged;
25
+ }
14
26
  function runtimeConfigSource(env) {
15
27
  return {
16
28
  context: {
@@ -37,4 +49,4 @@ function createCloudflareBindings() {
37
49
  };
38
50
  }
39
51
 
40
- export { createCloudflareBindings, resolveCloudflareBindings, runtimeConfigSource };
52
+ export { createCloudflareBindings, mergeCloudflareBindings, resolveCloudflareBindings, runtimeConfigSource, setCloudflareBindings };
@@ -1,10 +1,10 @@
1
- import { readFile, mkdir, writeFile } from 'node:fs/promises';
2
- import { parseTOML, parseJSONC, parseJSON } from 'confbox';
3
- import { extname, resolve } from 'pathe';
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import { resolve } from 'pathe';
4
3
  import { experimental_generateTypes } from 'wrangler';
5
4
  import { d as discoverWranglerSourceConfigs } from '../shared/nuxt-cloudflare.6X-qzF_b.mjs';
5
+ import { readWranglerConfigFile } from '../wrangler.mjs';
6
6
  import 'node:fs';
7
- import '../wrangler.mjs';
7
+ import 'confbox';
8
8
 
9
9
  const COMPUTED_WRANGLER_KEYS = /* @__PURE__ */ new Set([
10
10
  "configPath",
@@ -74,13 +74,12 @@ async function readAuthoredConfig(rootDir) {
74
74
  const [path] = discoverWranglerSourceConfigs(rootDir);
75
75
  if (!path)
76
76
  return {};
77
- const source = await readFile(path, "utf8");
78
- const extension = extname(path);
79
- if (extension === ".toml")
80
- return parseTOML(source);
81
- if (extension === ".jsonc")
82
- return parseJSONC(source);
83
- return parseJSON(source);
77
+ const loaded = readWranglerConfigFile(path);
78
+ if (loaded._tag === "loaded")
79
+ return loaded.config;
80
+ if (loaded._tag === "missing")
81
+ return {};
82
+ throw new SyntaxError(`Invalid Wrangler config "${path}": ${loaded.reason}`);
84
83
  }
85
84
  async function generateCloudflareBindingTypes(options) {
86
85
  const directory = resolve(options.buildDir, "nuxt-cloudflare");
@@ -1,6 +1,9 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { resolve, dirname } from 'pathe';
3
3
  import { unstable_readConfig } from 'wrangler';
4
+ import { findProjectWranglerConfig } from '../wrangler.mjs';
5
+ import 'node:fs/promises';
6
+ import 'confbox';
4
7
 
5
8
  function errorMessage(error) {
6
9
  return error instanceof Error ? error.message : String(error);
@@ -24,26 +27,12 @@ function findUpFile(cwd, relativePath) {
24
27
  directory = parent;
25
28
  }
26
29
  }
27
- function findUpWranglerConfig(cwd) {
28
- let directory = resolve(cwd);
29
- while (true) {
30
- for (const name of ["wrangler.json", "wrangler.jsonc", "wrangler.toml"]) {
31
- const candidate = resolve(directory, name);
32
- if (existsSync(candidate))
33
- return candidate;
34
- }
35
- const parent = dirname(directory);
36
- if (parent === directory)
37
- return void 0;
38
- directory = parent;
39
- }
40
- }
41
30
  function resolveNitroDeployConfig(cwd) {
42
31
  const redirectPath = findUpFile(cwd, ".wrangler/deploy/config.json");
43
32
  if (!redirectPath)
44
33
  return void 0;
45
34
  const redirectProjectDirectory = dirname(dirname(dirname(redirectPath)));
46
- const authoredConfigPath = findUpWranglerConfig(cwd);
35
+ const authoredConfigPath = findProjectWranglerConfig(cwd);
47
36
  if (authoredConfigPath && dirname(authoredConfigPath) !== redirectProjectDirectory)
48
37
  return void 0;
49
38
  const parsed = JSON.parse(readFileSync(redirectPath, "utf8"));
@@ -7,6 +7,7 @@ import { diagnoseWranglerConfig, formatWranglerDiagnostics } from '../wrangler.m
7
7
  import { readProjectWranglerConfig } from '../chunks/wrangler-reader.mjs';
8
8
  import 'node:fs';
9
9
  import 'node:fs/promises';
10
+ import 'confbox';
10
11
  import 'wrangler';
11
12
 
12
13
  function diagnoseWranglerProject(options) {
@@ -103,7 +104,7 @@ const doctor = defineCommand({
103
104
  const main = defineCommand({
104
105
  meta: {
105
106
  name: "nuxt-cloudflare",
106
- version: "0.0.11",
107
+ version: "0.0.13",
107
108
  description: "Cloudflare deployment defaults and diagnostics for Nuxt"
108
109
  },
109
110
  subCommands: { doctor }
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.5.0"
6
6
  },
7
- "version": "0.0.11",
7
+ "version": "0.0.13",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -5,13 +5,11 @@ import { a as diagnoseWranglerSourceConfigs, d as discoverWranglerSourceConfigs,
5
5
  import { readWranglerJsonFile, diagnoseWranglerConfig, formatWranglerDiagnostics, applyCloudflareDefaults } from './wrangler.mjs';
6
6
  import 'node:fs';
7
7
  import 'node:fs/promises';
8
+ import 'confbox';
8
9
 
9
10
  const NON_HTML_ROUTE_PREFIXES = [
10
11
  "/.well-known",
11
12
  "/api",
12
- "/_ipx",
13
- "/_nuxt",
14
- "/_og",
15
13
  "/assets",
16
14
  "/fonts",
17
15
  "/images",
@@ -46,7 +44,7 @@ function hasHtmlContentType(headers) {
46
44
  return typeof contentType === "string" && HTML_CONTENT_TYPE_RE.test(contentType);
47
45
  }
48
46
  function isHtmlCapableRoute(route, value) {
49
- if (NON_HTML_EXTENSION_RE.test(route) || hasExplicitNonHtmlContentType(value))
47
+ if (route.startsWith("/_") || NON_HTML_EXTENSION_RE.test(route) || hasExplicitNonHtmlContentType(value))
50
48
  return false;
51
49
  return !NON_HTML_ROUTE_PREFIXES.some((prefix) => route === prefix || route.startsWith(`${prefix}/`));
52
50
  }
@@ -1,3 +1,18 @@
1
+ type WranglerConfigFileResult = {
2
+ _tag: 'loaded';
3
+ config: WranglerConfigInput;
4
+ path: string;
5
+ } | {
6
+ _tag: 'missing';
7
+ path: string;
8
+ } | {
9
+ _tag: 'invalid';
10
+ path: string;
11
+ reason: string;
12
+ };
13
+ declare function readWranglerConfigFile(path: string): WranglerConfigFileResult;
14
+ declare function findProjectWranglerConfig(cwd: string): string | undefined;
15
+
1
16
  interface WranglerAssetsInput {
2
17
  directory?: string;
3
18
  binding?: string;
@@ -135,5 +150,5 @@ declare function diagnoseWranglerConfig(config: WranglerConfigInput, options?: W
135
150
  declare function formatWranglerDiagnostics(diagnostics: readonly WranglerDiagnostic[]): string;
136
151
  declare function readWranglerJsonFile(path: string): Promise<WranglerJsonFileResult>;
137
152
 
138
- export { WRANGLER_DIAGNOSTIC_CODES, applyCloudflareDefaults, diagnoseWranglerConfig, formatWranglerDiagnostics, readWranglerJsonFile };
139
- export type { CloudflareDefaultOptions, WorkersCachePolicy, WranglerAssetsInput, WranglerConfigInput, WranglerContainerInput, WranglerDiagnostic, WranglerDiagnosticCode, WranglerDiagnosticOptions, WranglerJsonFileResult, WranglerObservabilityInput, WranglerPlacementInput, WranglerRemoteBindingInput, WranglerWorkersCacheInput };
153
+ export { WRANGLER_DIAGNOSTIC_CODES, applyCloudflareDefaults, diagnoseWranglerConfig, findProjectWranglerConfig, formatWranglerDiagnostics, readWranglerConfigFile, readWranglerJsonFile };
154
+ export type { CloudflareDefaultOptions, WorkersCachePolicy, WranglerAssetsInput, WranglerConfigFileResult, WranglerConfigInput, WranglerContainerInput, WranglerDiagnostic, WranglerDiagnosticCode, WranglerDiagnosticOptions, WranglerJsonFileResult, WranglerObservabilityInput, WranglerPlacementInput, WranglerRemoteBindingInput, WranglerWorkersCacheInput };
package/dist/wrangler.mjs CHANGED
@@ -1,4 +1,53 @@
1
1
  import { readFile } from 'node:fs/promises';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { parseTOML, parseJSONC, parseJSON } from 'confbox';
4
+ import { resolve, dirname, extname } from 'pathe';
5
+
6
+ function errorMessage(error) {
7
+ return error instanceof Error ? error.message : String(error);
8
+ }
9
+ function parseWranglerConfigSource(path, source) {
10
+ const extension = extname(path);
11
+ if (extension === ".toml")
12
+ return parseTOML(source);
13
+ if (extension === ".jsonc") {
14
+ const errors = [];
15
+ const config = parseJSONC(source, { errors });
16
+ if (errors.length > 0) {
17
+ const { error, offset } = errors[0];
18
+ throw new SyntaxError(`JSONC parse error ${error} at offset ${offset}`);
19
+ }
20
+ return config;
21
+ }
22
+ return parseJSON(source);
23
+ }
24
+ function readWranglerConfigFile(path) {
25
+ if (!existsSync(path))
26
+ return { _tag: "missing", path };
27
+ try {
28
+ return {
29
+ _tag: "loaded",
30
+ config: parseWranglerConfigSource(path, readFileSync(path, "utf8")),
31
+ path
32
+ };
33
+ } catch (error) {
34
+ return { _tag: "invalid", path, reason: errorMessage(error) };
35
+ }
36
+ }
37
+ function findProjectWranglerConfig(cwd) {
38
+ let directory = resolve(cwd);
39
+ while (true) {
40
+ for (const name of ["wrangler.json", "wrangler.jsonc", "wrangler.toml"]) {
41
+ const candidate = resolve(directory, name);
42
+ if (existsSync(candidate))
43
+ return candidate;
44
+ }
45
+ const parent = dirname(directory);
46
+ if (parent === directory)
47
+ return void 0;
48
+ directory = parent;
49
+ }
50
+ }
2
51
 
3
52
  const WRANGLER_DIAGNOSTIC_CODES = [
4
53
  "assets-worker-first",
@@ -849,4 +898,4 @@ async function readWranglerJsonFile(path) {
849
898
  });
850
899
  }
851
900
 
852
- export { WRANGLER_DIAGNOSTIC_CODES, applyCloudflareDefaults, diagnoseWranglerConfig, formatWranglerDiagnostics, readWranglerJsonFile };
901
+ export { WRANGLER_DIAGNOSTIC_CODES, applyCloudflareDefaults, diagnoseWranglerConfig, findProjectWranglerConfig, formatWranglerDiagnostics, readWranglerConfigFile, readWranglerJsonFile };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@harlan-zw/nuxt-cloudflare",
3
3
  "type": "module",
4
- "version": "0.0.11",
4
+ "version": "0.0.13",
5
5
  "description": "Opinionated Cloudflare deployment defaults and diagnostics for Nuxt.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",