@rexezuge/tooling 1.15.0 → 1.17.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/README.md +4 -1
- package/dist/eslint.d.ts.map +1 -1
- package/dist/eslint.js +1 -1
- package/dist/eslint.js.map +2 -2
- package/dist/manifest-validate.d.ts.map +1 -1
- package/dist/manifest-validate.js +1 -1
- package/dist/manifest-validate.js.map +3 -3
- package/dist/manifest.d.ts +16 -0
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js.map +2 -2
- package/dist/scripts/init-secrets.d.ts.map +1 -1
- package/dist/scripts/init-secrets.js +2 -2
- package/dist/scripts/init-secrets.js.map +3 -3
- package/dist/scripts/prepare-wrangler-config.d.ts.map +1 -1
- package/dist/scripts/prepare-wrangler-config.js +1 -1
- package/dist/scripts/prepare-wrangler-config.js.map +3 -3
- package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/patches.js +3 -3
- package/dist/scripts/wrangler-config/patches.js.map +3 -3
- package/dist/scripts/wrangler-config/types.d.ts +13 -3
- package/dist/scripts/wrangler-config/types.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/types.js +1 -1
- package/dist/scripts/wrangler-config/types.js.map +3 -3
- package/package.json +3 -3
- package/schema/manifest.schema.json +18 -0
- package/src/eslint.test.ts +9 -0
- package/src/eslint.ts +13 -6
- package/src/manifest-validate.ts +42 -1
- package/src/manifest.test.ts +12 -0
- package/src/manifest.ts +17 -0
- package/src/scripts/init-secrets.ts +21 -11
- package/src/scripts/prepare-wrangler-config.ts +25 -12
- package/src/scripts/prepare-wrangler.test.ts +50 -0
- package/src/scripts/wrangler-config/patches.ts +7 -7
- package/src/scripts/wrangler-config/types.ts +26 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`}});return
|
|
1
|
+
var A=Object.defineProperty;var o=(e,n)=>A(e,"name",{value:n,configurable:!0});import{copyFileSync as d,readFileSync as l,writeFileSync as h}from"node:fs";import v from"node:path";import{applyEdits as R,modify as N,parse as m}from"jsonc-parser";import{configPath as i,templatePath as s}from"./types.js";function a(){const e=l(i(),"utf8");return{content:e,config:m(e)}}o(a,"readConfig");function f(e,n,r){const t=N(e,n,r,{formattingOptions:{insertSpaces:!0,tabSize:2,eol:`
|
|
2
|
+
`}});return R(e,t)}o(f,"writeConfigValue");function p(e){h(i(),e.endsWith(`
|
|
3
3
|
`)?e:`${e}
|
|
4
|
-
`)}o(p,"writeConfig");function
|
|
4
|
+
`)}o(p,"writeConfig");function S(){return g(process.env.WRANGLER_PATCH_JSON,"WRANGLER_PATCH_JSON","a JSON object")}o(S,"parseTopLevelPatch");function _(){const e=g(process.env.WRANGLER_VARS_PATCH_JSON,"WRANGLER_VARS_PATCH_JSON","a JSON object of string values");if(e===void 0)return;const n={};for(const[r,t]of Object.entries(e)){if(!r.trim())throw new Error("WRANGLER_VARS_PATCH_JSON contains an empty variable name.");if(typeof t!="string")throw new TypeError(`WRANGLER_VARS_PATCH_JSON value for ${r} must be a string.`);n[r]=t}return n}o(_,"parseVarsPatch");function g(e,n,r){if(e===void 0||!e.trim())return;let t;try{t=JSON.parse(e)}catch{throw new Error(`${n} must be ${r}.`)}if(t===null||typeof t!="object"||Array.isArray(t))throw new Error(`${n} must be ${r}.`);return t}o(g,"parseJsonObject");function u(e){return v.relative(process.cwd(),e)||e}o(u,"displayPath");function C(){const e=process.env.WRANGLER_JSONC;if(e?.trim()){p(e),console.log("Wrote wrangler.jsonc from WRANGLER_JSONC repository variable.");return}d(s(),i()),console.log(`WRANGLER_JSONC is empty; copied ${u(s())} to ${u(i())}.`)}o(C,"prepareConfigFile");function J(){const e=m(l(s(),"utf8"));if(typeof e.$minimumVersion!="number")return;const{config:n}=a(),r=n.$version;if(typeof r!="number"||r<e.$minimumVersion)throw new Error(`wrangler.jsonc version (${typeof r=="number"?r:"missing"}) is below minimum template version (${e.$minimumVersion}). Regenerate it from ${u(s())}.`)}o(J,"ensureMinimumConfigVersion");function W(){const e=S(),n=Object.entries(e??{});if(n.length===0)return;let{content:r}=a();for(const[t,c]of n)r=f(r,[t],c);p(r),console.log(`Applied ${n.length} Wrangler top-level patch entr${n.length===1?"y":"ies"}.`)}o(W,"applyTopLevelPatch");function P(){const e=_(),n=Object.entries(e??{});if(n.length===0)return;const r=a();let t=r.content;if(r.config.vars!==void 0&&(r.config.vars===null||typeof r.config.vars!="object"||Array.isArray(r.config.vars)))throw new Error("wrangler.jsonc vars must be an object before applying WRANGLER_VARS_PATCH_JSON.");r.config.vars===void 0&&(t=f(t,["vars"],{}));for(const[c,y]of n)t=f(t,["vars",c],y);p(t),console.log(`Applied ${n.length} Wrangler vars patch entr${n.length===1?"y":"ies"}.`)}o(P,"applyVarsPatch");export{W as applyTopLevelPatch,P as applyVarsPatch,J as ensureMinimumConfigVersion,S as parseTopLevelPatch,_ as parseVarsPatch,C as prepareConfigFile,a as readConfig,p as writeConfig,f as writeConfigValue};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/scripts/wrangler-config/patches.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Reading, writing and patching `wrangler.jsonc`.\n *\n * Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/patches.ts`.\n *\n * The config is JSONC — `//` comments and trailing commas — so it is edited\n * through jsonc-parser's `modify`/`applyEdits` rather than parsed and re-serialized.\n * A round trip through `JSON.parse` would drop every comment and reformat the\n * file, which is a diff nobody can review and a reason to regenerate the config by\n * hand instead.\n */\n\nimport { copyFileSync, readFileSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { applyEdits, modify, parse } from 'jsonc-parser';\nimport {
|
|
5
|
-
"mappings": "+EAYA,OAAS,gBAAAA,EAAc,gBAAAC,EAAc,iBAAAC,MAAqB,UAC1D,OAAOC,MAAU,YACjB,OAAS,cAAAC,EAAY,UAAAC,EAAQ,SAAAC,MAAa,eAC1C,OAAS,
|
|
6
|
-
"names": ["copyFileSync", "readFileSync", "writeFileSync", "path", "applyEdits", "modify", "parse", "
|
|
4
|
+
"sourcesContent": ["/**\n * Reading, writing and patching `wrangler.jsonc`.\n *\n * Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/patches.ts`.\n *\n * The config is JSONC — `//` comments and trailing commas — so it is edited\n * through jsonc-parser's `modify`/`applyEdits` rather than parsed and re-serialized.\n * A round trip through `JSON.parse` would drop every comment and reformat the\n * file, which is a diff nobody can review and a reason to regenerate the config by\n * hand instead.\n */\n\nimport { copyFileSync, readFileSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { applyEdits, modify, parse } from 'jsonc-parser';\nimport { configPath, templatePath, type WranglerConfig } from './types.ts';\n\n/**\nThe config's current text and its parsed form.\n*/\nexport interface ConfigFile {\n content: string;\n config: WranglerConfig;\n}\n\nexport function readConfig(): ConfigFile {\n const content = readFileSync(configPath(), 'utf8');\n return { content, config: parse(content) as WranglerConfig };\n}\n\n/**\n * Apply one edit to the config text, preserving comments and formatting.\n */\nexport function writeConfigValue(content: string, path: Array<string | number>, value: unknown): string {\n const edits = modify(content, path, value, { formattingOptions: { insertSpaces: true, tabSize: 2, eol: '\\n' } });\n return applyEdits(content, edits);\n}\n\n/**\nWrite the config, guaranteeing a trailing newline so Prettier sees a fixed point.\n*/\nexport function writeConfig(content: string): void {\n writeFileSync(configPath(), content.endsWith('\\n') ? content : `${content}\\n`);\n}\n\n/**\n * The top-level keys a caller wants to merge into the config, from the environment.\n *\n * `WRANGLER_PATCH_JSON` is how a repository variable supplies per-environment\n * settings without a second file: a repo with one worker and three environments\n * patches the routes and the vars rather than keeping three templates in step.\n */\nexport function parseTopLevelPatch(): Record<string, unknown> | undefined {\n return parseJsonObject(process.env['WRANGLER_PATCH_JSON'], 'WRANGLER_PATCH_JSON', 'a JSON object');\n}\n\n/**\nThe `vars` entries a caller wants to merge, from the environment.\n*/\nexport function parseVarsPatch(): Record<string, string> | undefined {\n const parsed = parseJsonObject(process.env['WRANGLER_VARS_PATCH_JSON'], 'WRANGLER_VARS_PATCH_JSON', 'a JSON object of string values');\n if (parsed === undefined) {\n return undefined;\n }\n const patch: Record<string, string> = {};\n for (const [key, value] of Object.entries(parsed)) {\n if (!key.trim()) {\n throw new Error('WRANGLER_VARS_PATCH_JSON contains an empty variable name.');\n }\n if (typeof value !== 'string') {\n throw new TypeError(`WRANGLER_VARS_PATCH_JSON value for ${key} must be a string.`);\n }\n patch[key] = value;\n }\n return patch;\n}\n\nfunction parseJsonObject(raw: string | undefined, name: string, expected: string): Record<string, unknown> | undefined {\n if (raw === undefined || !raw.trim()) {\n return undefined;\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw) as unknown;\n } catch {\n throw new Error(`${name} must be ${expected}.`);\n }\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new Error(`${name} must be ${expected}.`);\n }\n return parsed as Record<string, unknown>;\n}\n\n/**\n * A path as a log line should name it: relative to the working directory the\n * script was invoked from, which is the repo root in every consumer.\n */\nfunction displayPath(filePath: string): string {\n return path.relative(process.cwd(), filePath) || filePath;\n}\n\n/**\n * Materialize the config: the repository variable when it is set, otherwise the\n * committed template.\n */\nexport function prepareConfigFile(): void {\n const dumpedConfig = process.env['WRANGLER_JSONC'];\n if (dumpedConfig?.trim()) {\n writeConfig(dumpedConfig);\n console.log('Wrote wrangler.jsonc from WRANGLER_JSONC repository variable.');\n return;\n }\n copyFileSync(templatePath(), configPath());\n console.log(`WRANGLER_JSONC is empty; copied ${displayPath(templatePath())} to ${displayPath(configPath())}.`);\n}\n\n/**\n * Refuse a config older than the template requires.\n *\n * The template is the one file in the repo that says which wrangler behaviour the\n * worker was written against, and a config written by an older template can name\n * bindings the worker no longer reads. Failing here rather than at deploy time is\n * the whole reason the check exists.\n */\nexport function ensureMinimumConfigVersion(): void {\n const template = parse(readFileSync(templatePath(), 'utf8')) as { $minimumVersion?: unknown };\n if (typeof template.$minimumVersion !== 'number') {\n return;\n }\n const { config } = readConfig();\n const currentVersion = config.$version;\n if (typeof currentVersion !== 'number' || currentVersion < template.$minimumVersion) {\n throw new Error(\n `wrangler.jsonc version (${typeof currentVersion === 'number' ? currentVersion : 'missing'}) is below minimum template version (${template.$minimumVersion}). Regenerate it from ${displayPath(templatePath())}.`,\n );\n }\n}\n\nexport function applyTopLevelPatch(): void {\n const patch = parseTopLevelPatch();\n const entries = Object.entries(patch ?? {});\n if (entries.length === 0) {\n return;\n }\n let { content } = readConfig();\n for (const [key, value] of entries) {\n content = writeConfigValue(content, [key], value);\n }\n writeConfig(content);\n console.log(`Applied ${entries.length} Wrangler top-level patch entr${entries.length === 1 ? 'y' : 'ies'}.`);\n}\n\nexport function applyVarsPatch(): void {\n const patch = parseVarsPatch();\n const entries = Object.entries(patch ?? {});\n if (entries.length === 0) {\n return;\n }\n const prepared = readConfig();\n let content = prepared.content;\n if (\n prepared.config.vars !== undefined &&\n (prepared.config.vars === null || typeof prepared.config.vars !== 'object' || Array.isArray(prepared.config.vars))\n ) {\n throw new Error('wrangler.jsonc vars must be an object before applying WRANGLER_VARS_PATCH_JSON.');\n }\n // `null` needs no branch here: the guard above throws for it, so by this\n // line `vars` is either absent or an object.\n if (prepared.config.vars === undefined) {\n content = writeConfigValue(content, ['vars'], {});\n }\n for (const [key, value] of entries) {\n content = writeConfigValue(content, ['vars', key], value);\n }\n writeConfig(content);\n console.log(`Applied ${entries.length} Wrangler vars patch entr${entries.length === 1 ? 'y' : 'ies'}.`);\n}\n"],
|
|
5
|
+
"mappings": "+EAYA,OAAS,gBAAAA,EAAc,gBAAAC,EAAc,iBAAAC,MAAqB,UAC1D,OAAOC,MAAU,YACjB,OAAS,cAAAC,EAAY,UAAAC,EAAQ,SAAAC,MAAa,eAC1C,OAAS,cAAAC,EAAY,gBAAAC,MAAyC,aAUxD,SAAUC,GAAU,CACxB,MAAMC,EAAUT,EAAaM,EAAU,EAAI,MAAM,EACjD,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AAYL,CAAO,EACnB,QAAQ,IAAI,WAAWwB,EAAQ,MAAM,iCAAiCA,EAAQ,SAAW,EAAI,IAAM,KAAK,GAAG,CAC7G,CAZgBvB,EAAAsB,EAAA,sBAcV,SAAUE,GAAc,CAC5B,MAAMf,EAAQF,EAAc,EACtBgB,EAAU,OAAO,QAAQd,GAAS,CAAA,CAAE,EAC1C,GAAIc,EAAQ,SAAW,EACrB,OAEF,MAAME,EAAW3B,EAAU,EAC3B,IAAIC,EAAU0B,EAAS,QACvB,GACEA,EAAS,OAAO,OAAS,SACxBA,EAAS,OAAO,OAAS,MAAQ,OAAOA,EAAS,OAAO,MAAS,UAAY,MAAM,QAAQA,EAAS,OAAO,IAAI,GAEhH,MAAM,IAAI,MAAM,iFAAiF,EAI/FA,EAAS,OAAO,OAAS,SAC3B1B,EAAUE,EAAiBF,EAAS,CAAC,MAAM,EAAG,CAAA,CAAE,GAElD,SAAW,CAACW,EAAKR,CAAK,IAAKqB,EACzBxB,EAAUE,EAAiBF,EAAS,CAAC,OAAQW,CAAG,EAAGR,CAAK,EAE1DE,EAAYL,CAAO,EACnB,QAAQ,IAAI,WAAWwB,EAAQ,MAAM,4BAA4BA,EAAQ,SAAW,EAAI,IAAM,KAAK,GAAG,CACxG,CAxBgBvB,EAAAwB,EAAA",
|
|
6
|
+
"names": ["copyFileSync", "readFileSync", "writeFileSync", "path", "applyEdits", "modify", "parse", "configPath", "templatePath", "readConfig", "content", "__name", "writeConfigValue", "value", "edits", "writeConfig", "parseTopLevelPatch", "parseJsonObject", "parseVarsPatch", "parsed", "patch", "key", "raw", "name", "expected", "displayPath", "filePath", "prepareConfigFile", "dumpedConfig", "ensureMinimumConfigVersion", "template", "config", "currentVersion", "applyTopLevelPatch", "entries", "applyVarsPatch", "prepared"]
|
|
7
7
|
}
|
|
@@ -11,14 +11,24 @@
|
|
|
11
11
|
* / `WRANGLER_TEMPLATE_PATH` override them for a caller that is not in the repo
|
|
12
12
|
* root, which is the one case the cwd default gets wrong.
|
|
13
13
|
*/
|
|
14
|
+
export declare const DEFAULT_TEMPLATE = "apps/api/wrangler.template.jsonc";
|
|
15
|
+
export declare const DEFAULT_CONFIG = "wrangler.jsonc";
|
|
14
16
|
/**
|
|
15
|
-
|
|
17
|
+
* Run `work` with the template and config of one manifest worker (`features.workers`). Resolution order for each
|
|
18
|
+
* path: this override, the `WRANGLER_*_PATH` environment variable, the default.
|
|
19
|
+
*/
|
|
20
|
+
export declare function withWranglerPaths<T>(paths: {
|
|
21
|
+
template?: string;
|
|
22
|
+
config?: string;
|
|
23
|
+
}, work: () => T): T;
|
|
24
|
+
/**
|
|
25
|
+
The config the deploy targets. Resolved on each call, so a manifest worker can change it.
|
|
16
26
|
*/
|
|
17
|
-
export declare
|
|
27
|
+
export declare function configPath(): string;
|
|
18
28
|
/**
|
|
19
29
|
The committed template the config is materialized from.
|
|
20
30
|
*/
|
|
21
|
-
export declare
|
|
31
|
+
export declare function templatePath(): string;
|
|
22
32
|
/**
|
|
23
33
|
* The id a template carries for a D1 database that does not exist yet.
|
|
24
34
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/scripts/wrangler-config/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/scripts/wrangler-config/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,eAAO,MAAM,gBAAgB,qCAAqC,CAAC;AACnE,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAI/C;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAQpG;AAED;;EAEE;AACF,wBAAgB,UAAU,IAAI,MAA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AC;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACtC,CAAC;IACF,SAAS,CAAC,EAAE,KAAK,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ;AAED;;EAEE;AACF,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;EAEE;AACF,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;EAEE;AACF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var s=Object.defineProperty;var t=(o,r)=>s(o,"name",{value:r,configurable:!0});import E from"node:path";const c="apps/api/wrangler.template.jsonc",p="wrangler.jsonc";let e={};function a(o,r){const n=e;e=o;try{return r()}finally{e=n}}t(a,"withWranglerPaths");function R(){return E.resolve(process.cwd(),e.config??process.env.WRANGLER_CONFIG_PATH??p)}t(R,"configPath");function l(){return E.resolve(process.cwd(),e.template??process.env.WRANGLER_TEMPLATE_PATH??c)}t(l,"templatePath");const L="00000000-0000-0000-0000-000000000000",N="00000000000000000000000000000000",i="default",A=process.env.WRANGLER_WORKER_NAME??"my-worker",x={CACHE:`${A}-cache`},D=1024;export{p as DEFAULT_CONFIG,N as DEFAULT_HEX_ID,x as DEFAULT_KV_NAMESPACE_NAMES,i as DEFAULT_SECRET_STORE_NAME,c as DEFAULT_TEMPLATE,L as DEFAULT_UUID,A as DEFAULT_WORKER_NAME,D as VECTORIZE_DIMENSIONS,R as configPath,l as templatePath,a as withWranglerPaths};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/scripts/wrangler-config/types.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Shared paths, placeholders and shape definitions for the wrangler config helpers.\n *\n * Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/types.ts`.\n * Every script that reads or writes `wrangler.jsonc` resolves it here, so the\n * backup workflow cannot end up inspecting a different file than the deploy\n * materialized.\n *\n * The paths default to `process.cwd()`, which is the repo root in every consumer:\n * the scripts run as `pnpm exec tsx scripts/deploy/…` from there. `WRANGLER_CONFIG_PATH`\n * / `WRANGLER_TEMPLATE_PATH` override them for a caller that is not in the repo\n * root, which is the one case the cwd default gets wrong.\n */\n\nimport path from 'node:path';\n\n/**\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["path", "
|
|
4
|
+
"sourcesContent": ["/**\n * Shared paths, placeholders and shape definitions for the wrangler config helpers.\n *\n * Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/types.ts`.\n * Every script that reads or writes `wrangler.jsonc` resolves it here, so the\n * backup workflow cannot end up inspecting a different file than the deploy\n * materialized.\n *\n * The paths default to `process.cwd()`, which is the repo root in every consumer:\n * the scripts run as `pnpm exec tsx scripts/deploy/…` from there. `WRANGLER_CONFIG_PATH`\n * / `WRANGLER_TEMPLATE_PATH` override them for a caller that is not in the repo\n * root, which is the one case the cwd default gets wrong.\n */\n\nimport path from 'node:path';\n\nexport const DEFAULT_TEMPLATE = 'apps/api/wrangler.template.jsonc';\nexport const DEFAULT_CONFIG = 'wrangler.jsonc';\n\nlet override: { template?: string; config?: string } = {};\n\n/**\n * Run `work` with the template and config of one manifest worker (`features.workers`). Resolution order for each\n * path: this override, the `WRANGLER_*_PATH` environment variable, the default.\n */\nexport function withWranglerPaths<T>(paths: { template?: string; config?: string }, work: () => T): T {\n const previous = override;\n override = paths;\n try {\n return work();\n } finally {\n override = previous;\n }\n}\n\n/**\nThe config the deploy targets. Resolved on each call, so a manifest worker can change it.\n*/\nexport function configPath(): string {\n return path.resolve(process.cwd(), override.config ?? process.env['WRANGLER_CONFIG_PATH'] ?? DEFAULT_CONFIG);\n}\n\n/**\nThe committed template the config is materialized from.\n*/\nexport function templatePath(): string {\n return path.resolve(process.cwd(), override.template ?? process.env['WRANGLER_TEMPLATE_PATH'] ?? DEFAULT_TEMPLATE);\n}\n\n/**\n * The id a template carries for a D1 database that does not exist yet.\n *\n * `provisionWranglerResources` replaces it with a real id; the backup scripts\n * refuse to export while it is still in place, because a database that was just\n * created holds no user data.\n */\nexport const DEFAULT_UUID = '00000000-0000-0000-0000-000000000000';\n\n/**\nThe placeholder for a KV namespace id and for a Secrets Store id.\n*/\nexport const DEFAULT_HEX_ID = '00000000000000000000000000000000';\n\n/**\nThe Secrets Store name a deployment uses.\n*/\nexport const DEFAULT_SECRET_STORE_NAME = 'default';\n\n/**\n * Fallback when the config declares no `name`, used to derive resource names.\n *\n * Overridable per consumer with `WRANGLER_WORKER_NAME`, which keeps the default\n * honest rather than baking one repo's name into the kit.\n */\nexport const DEFAULT_WORKER_NAME = process.env['WRANGLER_WORKER_NAME'] ?? 'my-worker';\n\n/**\n * KV bindings a deployment always needs, and the namespace each maps to.\n *\n * The default for `provisionWranglerResources`'s `namespaceNames` argument: a\n * consumer whose worker has no cache binding passes an empty map, and one whose\n * namespaces predate this convention passes its own map.\n */\nexport const DEFAULT_KV_NAMESPACE_NAMES: Record<string, string> = {\n CACHE: `${DEFAULT_WORKER_NAME}-cache`,\n};\n\n/**\nDimensions of a Vectorize index this kit provisions.\n*/\nexport const VECTORIZE_DIMENSIONS = 1024;\n\n/**\n * The parsed shape of a wrangler config.\n *\n * `vars` is widened with `null` on purpose: jsonc-parser yields `null` for an\n * explicit `vars: null`, and the vars-patch path must be able to reject that\n * rather than treat the field as absent.\n */\nexport interface WranglerConfig {\n name?: string;\n $version?: number;\n vars?: Record<string, unknown> | null;\n d1_databases?: Array<{\n binding?: string;\n database_id?: string;\n database_name?: string;\n }>;\n kv_namespaces?: Array<{\n binding?: string;\n id?: string;\n }>;\n secrets_store_secrets?: Array<{\n binding?: string;\n store_id?: string;\n secret_name?: string;\n }>;\n queues?: {\n producers?: Array<{ binding: string; queue: string }>;\n consumers?: Array<{ queue: string }>;\n };\n vectorize?: Array<{\n binding: string;\n index_name: string;\n }>;\n}\n\n/**\nA D1 database as `wrangler d1 list --json` reports one.\n*/\nexport interface D1Database {\n name?: string;\n uuid?: string;\n id?: string;\n database_id?: string;\n}\n\n/**\nA KV namespace as `wrangler kv namespace list` reports one.\n*/\nexport interface KVNamespace {\n title?: string;\n name?: string;\n id?: string;\n}\n\n/**\nA Secrets Store as `wrangler secrets-store store list` reports one.\n*/\nexport interface SecretStore {\n name: string;\n id: string;\n}\n"],
|
|
5
|
+
"mappings": "+EAcA,OAAOA,MAAU,YAEV,MAAMC,EAAmB,mCACnBC,EAAiB,iBAE9B,IAAIC,EAAmD,CAAA,EAMjD,SAAUC,EAAqBC,EAA+CC,EAAa,CAC/F,MAAMC,EAAWJ,EACjBA,EAAWE,EACX,GAAI,CACF,OAAOC,EAAI,CACb,SACEH,EAAWI,CACb,CACF,CARgBC,EAAAJ,EAAA,qBAaV,SAAUK,GAAU,CACxB,OAAOT,EAAK,QAAQ,QAAQ,IAAG,EAAIG,EAAS,QAAU,QAAQ,IAAI,sBAA2BD,CAAc,CAC7G,CAFgBM,EAAAC,EAAA,cAOV,SAAUC,GAAY,CAC1B,OAAOV,EAAK,QAAQ,QAAQ,IAAG,EAAIG,EAAS,UAAY,QAAQ,IAAI,wBAA6BF,CAAgB,CACnH,CAFgBO,EAAAE,EAAA,gBAWT,MAAMC,EAAe,uCAKfC,EAAiB,mCAKjBC,EAA4B,UAQ5BC,EAAsB,QAAQ,IAAI,sBAA2B,YAS7DC,EAAqD,CAChE,MAAO,GAAGD,CAAmB,UAMlBE,EAAuB",
|
|
6
|
+
"names": ["path", "DEFAULT_TEMPLATE", "DEFAULT_CONFIG", "override", "withWranglerPaths", "paths", "work", "previous", "__name", "configPath", "templatePath", "DEFAULT_UUID", "DEFAULT_HEX_ID", "DEFAULT_SECRET_STORE_NAME", "DEFAULT_WORKER_NAME", "DEFAULT_KV_NAMESPACE_NAMES", "VECTORIZE_DIMENSIONS"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexezuge/tooling",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"presets"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@rexezuge/d1": "1.
|
|
52
|
-
"@rexezuge/testing": "1.
|
|
51
|
+
"@rexezuge/d1": "1.17.0",
|
|
52
|
+
"@rexezuge/testing": "1.17.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"eslint": "^10.0.0",
|
|
@@ -38,6 +38,24 @@
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
+
"workers": {
|
|
42
|
+
"type": "array",
|
|
43
|
+
"minItems": 1,
|
|
44
|
+
"description": "Workers prepare-wrangler materializes: a committed template and the config written from it. Absent: apps/api/wrangler.template.jsonc to wrangler.jsonc. List each config in worker-cd.yml's worker-configs too.",
|
|
45
|
+
"items": {
|
|
46
|
+
"type": "object",
|
|
47
|
+
"additionalProperties": false,
|
|
48
|
+
"required": ["template"],
|
|
49
|
+
"properties": {
|
|
50
|
+
"template": { "type": "string", "minLength": 1, "description": "Repo-relative path of the committed template." },
|
|
51
|
+
"config": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"minLength": 1,
|
|
54
|
+
"description": "Repo-relative path of the config written from it. Default wrangler.jsonc; unique across workers."
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
41
59
|
"web": {
|
|
42
60
|
"type": "object",
|
|
43
61
|
"additionalProperties": false,
|
package/src/eslint.test.ts
CHANGED
|
@@ -123,6 +123,15 @@ describe('defineRepoLintConfig', () => {
|
|
|
123
123
|
expect(browser).toContain('process');
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
+
it('omits the browser-globals block when the manifest has no browser dirs', () => {
|
|
127
|
+
const apiOnly = defineRepoLintConfig({ scope: '@fixture', manifest: { scope: '@fixture', name: 'fixture', features: {} } as never });
|
|
128
|
+
for (const entry of apiOnly) {
|
|
129
|
+
if (entry.files !== undefined) expect(entry.files.length).toBeGreaterThan(0);
|
|
130
|
+
}
|
|
131
|
+
const globalNames = apiOnly.flatMap((entry) => Object.keys(entry.languageOptions?.globals ?? {}));
|
|
132
|
+
expect(globalNames).not.toContain('document');
|
|
133
|
+
});
|
|
134
|
+
|
|
126
135
|
it('keeps the three plugin families on', () => {
|
|
127
136
|
// sonarjs / unicorn / regexp are each a preset spread into the array; a preset
|
|
128
137
|
// that failed to import would leave the array without their rule blocks.
|
package/src/eslint.ts
CHANGED
|
@@ -238,12 +238,19 @@ export function defineRepoLintConfig(options: RepoLintConfigOptions): FlatConfig
|
|
|
238
238
|
// config runs those suites under jsdom; the lint environment should agree
|
|
239
239
|
// with the environment the code is executed in, or the rule is reporting
|
|
240
240
|
// something untrue about how the file behaves.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
//
|
|
242
|
+
// Omitted when the repo has no browser dirs: a block with `files: []` is
|
|
243
|
+
// rejected by ESLint ("Expected value to be a non-empty array").
|
|
244
|
+
...(browserDirs.length === 0
|
|
245
|
+
? []
|
|
246
|
+
: [
|
|
247
|
+
{
|
|
248
|
+
files: browserDirs.map((dir) => `${dir}/**/*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}`),
|
|
249
|
+
languageOptions: {
|
|
250
|
+
globals: { ...globals.node, ...globals.browser },
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
]),
|
|
247
254
|
|
|
248
255
|
// --- Test suite ---
|
|
249
256
|
//
|
package/src/manifest-validate.ts
CHANGED
|
@@ -74,10 +74,50 @@ function checkKv(c: Check, value: unknown): void {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
function checkRepoPath(c: Check, at: string, value: unknown): value is string {
|
|
78
|
+
if (!c.str(at, value)) return false;
|
|
79
|
+
if (/[*?{}]/.test(value) || value.startsWith('/') || value.split('/').includes('..')) {
|
|
80
|
+
c.fail(at, `${JSON.stringify(value)} must be a repo-relative file path without globs or '..'`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function checkWorkers(c: Check, value: unknown): void {
|
|
87
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
88
|
+
c.fail('features.workers', 'must be a non-empty array');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const configs = new Set<string>();
|
|
92
|
+
value.forEach((entry: unknown, index) => {
|
|
93
|
+
const at = `features.workers[${index}]`;
|
|
94
|
+
const worker = c.obj(at, entry);
|
|
95
|
+
if (!worker) return;
|
|
96
|
+
c.keys(at, worker, ['template', 'config']);
|
|
97
|
+
checkRepoPath(c, `${at}.template`, worker.template);
|
|
98
|
+
const config = worker.config === undefined ? 'wrangler.jsonc' : worker.config;
|
|
99
|
+
if (worker.config !== undefined && !checkRepoPath(c, `${at}.config`, worker.config)) return;
|
|
100
|
+
if (configs.has(config as string)) c.fail(`${at}.config`, `${JSON.stringify(config)} is written by another worker`);
|
|
101
|
+
configs.add(config as string);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
77
105
|
function checkFeatures(c: Check, value: unknown): void {
|
|
78
106
|
const features = c.obj('features', value);
|
|
79
107
|
if (!features) return;
|
|
80
|
-
c.keys('features', features, [
|
|
108
|
+
c.keys('features', features, [
|
|
109
|
+
'd1',
|
|
110
|
+
'kv',
|
|
111
|
+
'workers',
|
|
112
|
+
'web',
|
|
113
|
+
'background',
|
|
114
|
+
'backupD1',
|
|
115
|
+
'durableObjects',
|
|
116
|
+
'queues',
|
|
117
|
+
'workflows',
|
|
118
|
+
'email',
|
|
119
|
+
'android',
|
|
120
|
+
]);
|
|
81
121
|
if (features.d1 !== undefined) {
|
|
82
122
|
const d1 = c.obj('features.d1', features.d1);
|
|
83
123
|
if (d1) {
|
|
@@ -88,6 +128,7 @@ function checkFeatures(c: Check, value: unknown): void {
|
|
|
88
128
|
}
|
|
89
129
|
}
|
|
90
130
|
if (features.kv !== undefined) checkKv(c, features.kv);
|
|
131
|
+
if (features.workers !== undefined) checkWorkers(c, features.workers);
|
|
91
132
|
if (features.web !== undefined) {
|
|
92
133
|
const web = c.obj('features.web', features.web);
|
|
93
134
|
if (web) {
|
package/src/manifest.test.ts
CHANGED
|
@@ -25,6 +25,18 @@ function errorsOf(input: unknown): string[] {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
describe('validateManifest', () => {
|
|
28
|
+
it('validates features.workers', () => {
|
|
29
|
+
const workers = (value: unknown): string[] => errorsOf({ ...MINIMAL, features: { workers: value } });
|
|
30
|
+
expect(
|
|
31
|
+
workers([{ template: 'apps/api/wrangler.template.jsonc' }, { template: 'apps/b/t.jsonc', config: 'apps/b/wrangler.jsonc' }]),
|
|
32
|
+
).toEqual([]);
|
|
33
|
+
expect(workers([])).toEqual([expect.stringContaining('features.workers: must be a non-empty array')]);
|
|
34
|
+
expect(workers([{}])).toEqual([expect.stringContaining('features.workers[0].template')]);
|
|
35
|
+
expect(workers([{ template: '../x.jsonc' }])).toEqual([expect.stringContaining('repo-relative')]);
|
|
36
|
+
expect(workers([{ template: 'a.jsonc', extra: 1 }])).toEqual([expect.stringContaining('unknown key')]);
|
|
37
|
+
expect(workers([{ template: 'a.jsonc' }, { template: 'b.jsonc' }])).toEqual([expect.stringContaining('written by another worker')]);
|
|
38
|
+
});
|
|
39
|
+
|
|
28
40
|
it('accepts the minimal manifest and a full one', () => {
|
|
29
41
|
expect(validateManifest(MINIMAL).ok).toBe(true);
|
|
30
42
|
const full = {
|
package/src/manifest.ts
CHANGED
|
@@ -69,9 +69,26 @@ export interface ManifestWeb {
|
|
|
69
69
|
readonly pagesProject?: string;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* One worker `prepare-wrangler` materializes: the committed template and the config it writes. Declared as
|
|
74
|
+
* `features.workers`; absent means one worker (`apps/api/wrangler.template.jsonc` to `wrangler.jsonc`). List every
|
|
75
|
+
* entry's `config` in `worker-cd.yml`'s `worker-configs` input as well, so each one is also deployed.
|
|
76
|
+
*/
|
|
77
|
+
export interface ManifestWorker {
|
|
78
|
+
/**
|
|
79
|
+
Repo-relative path of the committed template.
|
|
80
|
+
*/
|
|
81
|
+
readonly template: string;
|
|
82
|
+
/**
|
|
83
|
+
Repo-relative path of the config written from it. Defaults to `wrangler.jsonc`; unique across `workers`.
|
|
84
|
+
*/
|
|
85
|
+
readonly config?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
72
88
|
export interface ManifestFeatures {
|
|
73
89
|
readonly d1?: ManifestD1;
|
|
74
90
|
readonly kv?: ManifestKv;
|
|
91
|
+
readonly workers?: readonly ManifestWorker[];
|
|
75
92
|
readonly web?: ManifestWeb;
|
|
76
93
|
readonly background?: boolean;
|
|
77
94
|
readonly backupD1?: boolean;
|
|
@@ -49,7 +49,8 @@ import { parse } from 'jsonc-parser';
|
|
|
49
49
|
import { isEntrypoint } from './lib/entrypoint.ts';
|
|
50
50
|
import { fail } from './lib/github-actions.ts';
|
|
51
51
|
import { isEmptySecretsStoreListing, parseWranglerNames } from './lib/wrangler-table.ts';
|
|
52
|
-
import {
|
|
52
|
+
import { loadManifest } from '../manifest.ts';
|
|
53
|
+
import { configPath, withWranglerPaths, type WranglerConfig } from './wrangler-config/types.ts';
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* The secret names the AES-GCM key generator produces, matched by **shape**.
|
|
@@ -143,17 +144,17 @@ function wrangler(args: readonly string[], input?: string): string {
|
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
function parseWranglerConfig(): WranglerConfig {
|
|
146
|
-
if (!existsSync(
|
|
147
|
+
if (!existsSync(configPath())) {
|
|
147
148
|
throw new Error(
|
|
148
|
-
`${
|
|
149
|
+
`${configPath()} not found. Run scripts/prepare-wrangler-config.ts first — it is what creates the file this script reads.`,
|
|
149
150
|
);
|
|
150
151
|
}
|
|
151
152
|
// `parse` is error-tolerant and returns a partial object, so an empty result means
|
|
152
153
|
// malformed JSON rather than "no secrets declared". Treating that as an empty list
|
|
153
154
|
// would report success having created nothing.
|
|
154
|
-
const config = parse(readFileSync(
|
|
155
|
+
const config = parse(readFileSync(configPath(), 'utf8')) as WranglerConfig;
|
|
155
156
|
if (config.secrets_store_secrets === undefined && Object.keys(config).length === 0) {
|
|
156
|
-
throw new Error(`${
|
|
157
|
+
throw new Error(`${configPath()} is empty or not valid JSONC. Run scripts/prepare-wrangler-config.ts to regenerate it.`);
|
|
157
158
|
}
|
|
158
159
|
return config;
|
|
159
160
|
}
|
|
@@ -232,12 +233,22 @@ function createSecret(storeId: string, secretName: string, secretValue: string):
|
|
|
232
233
|
|
|
233
234
|
export async function main(): Promise<void> {
|
|
234
235
|
console.log('Initializing Cloudflare secrets...');
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
// One pass per manifest worker (`features.workers`), or the one default config.
|
|
237
|
+
const workers = loadManifest(process.cwd())?.features?.workers ?? [{}];
|
|
238
|
+
let planned = 0;
|
|
239
|
+
for (const worker of workers) planned += await withWranglerPaths(worker, initializeOne);
|
|
240
|
+
if (planned === 0) {
|
|
239
241
|
throw new Error('wrangler.jsonc declares no secrets_store_secrets entries, so there is nothing to initialize.');
|
|
240
242
|
}
|
|
243
|
+
console.log('Secret initialization complete');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Initialize the secrets one config declares; returns how many it declares.
|
|
248
|
+
*/
|
|
249
|
+
async function initializeOne(): Promise<number> {
|
|
250
|
+
const config = parseWranglerConfig();
|
|
251
|
+
const plan = planSecrets(config);
|
|
241
252
|
|
|
242
253
|
const listedByStore = new Map<string, Set<string> | undefined>();
|
|
243
254
|
|
|
@@ -258,8 +269,7 @@ export async function main(): Promise<void> {
|
|
|
258
269
|
createSecret(storeId, secretName, await generatorFor(secretName)());
|
|
259
270
|
existing.add(secretName);
|
|
260
271
|
}
|
|
261
|
-
|
|
262
|
-
console.log('Secret initialization complete');
|
|
272
|
+
return plan.length;
|
|
263
273
|
}
|
|
264
274
|
|
|
265
275
|
// Top-level await rather than `.catch(console.error)`, so a rejected `main` surfaces
|
|
@@ -30,11 +30,14 @@
|
|
|
30
30
|
* - `WRANGLER_PATCH_JSON` — top-level keys merged into the config.
|
|
31
31
|
* - `WRANGLER_VARS_PATCH_JSON` — `vars` entries merged into the config.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
33
|
+
* Templates come from the manifest's `features.workers` (`template`, and `config` to write; default
|
|
34
|
+
* `apps/api/wrangler.template.jsonc` to `wrangler.jsonc`). KV bindings come from the manifest's `features.kv` (none declared: none added).
|
|
34
35
|
*/
|
|
35
36
|
import { loadManifest } from '../manifest.ts';
|
|
37
|
+
import type { FamilyManifest } from '../manifest.ts';
|
|
36
38
|
import { setOutput } from './lib/github-actions.ts';
|
|
37
39
|
import { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches.ts';
|
|
40
|
+
import { withWranglerPaths } from './wrangler-config/types.ts';
|
|
38
41
|
import { provisionWranglerResources } from './wrangler-config/resources.ts';
|
|
39
42
|
import { isEntrypoint } from './lib/entrypoint.ts';
|
|
40
43
|
|
|
@@ -44,16 +47,13 @@ import { isEntrypoint } from './lib/entrypoint.ts';
|
|
|
44
47
|
* directory must do so before importing this module). Returns the created resources.
|
|
45
48
|
*/
|
|
46
49
|
export function main(): string[] {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const created =
|
|
54
|
-
namespaceNames: { ...kv?.namespaceNames },
|
|
55
|
-
requiredKvBindings: kv?.bindings ?? [],
|
|
56
|
-
});
|
|
50
|
+
// Manifest-driven: each `features.workers` entry is prepared in turn; none declared is the one default worker.
|
|
51
|
+
const manifest = loadManifest(process.cwd());
|
|
52
|
+
const workers = manifest?.features?.workers ?? [{}];
|
|
53
|
+
if (workers.length > 1 && process.env['WRANGLER_JSONC']?.trim()) {
|
|
54
|
+
throw new Error('WRANGLER_JSONC holds one config, but features.workers declares several; use WRANGLER_PATCH_JSON instead.');
|
|
55
|
+
}
|
|
56
|
+
const created = workers.flatMap((worker) => withWranglerPaths(worker, () => prepareOne(manifest)));
|
|
57
57
|
|
|
58
58
|
// Published as a step output rather than only printed. The backup workflow needs
|
|
59
59
|
// to know whether the D1 database *existed* or was created moments ago: a fresh one
|
|
@@ -61,11 +61,24 @@ export function main(): string[] {
|
|
|
61
61
|
// of safety. The alternative — re-reading the placeholder id out of
|
|
62
62
|
// `wrangler.jsonc` — is unreachable, because `provisionWranglerResources` patches
|
|
63
63
|
// the placeholder away before the reader ever runs.
|
|
64
|
-
setOutput('created', created.join(','));
|
|
64
|
+
setOutput('created', [...new Set(created)].join(','));
|
|
65
65
|
console.log('Wrangler configuration is ready.');
|
|
66
66
|
return created;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
function prepareOne(manifest: FamilyManifest | null): string[] {
|
|
70
|
+
prepareConfigFile();
|
|
71
|
+
ensureMinimumConfigVersion();
|
|
72
|
+
applyTopLevelPatch();
|
|
73
|
+
applyVarsPatch();
|
|
74
|
+
// KV is manifest-driven: a repo that declares no `features.kv` gets no KV binding and no namespace (no phantom CACHE).
|
|
75
|
+
const kv = manifest?.features?.kv;
|
|
76
|
+
return provisionWranglerResources({
|
|
77
|
+
namespaceNames: { ...kv?.namespaceNames },
|
|
78
|
+
requiredKvBindings: kv?.bindings ?? [],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
69
82
|
if (isEntrypoint(import.meta.url)) {
|
|
70
83
|
main();
|
|
71
84
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { main } from './prepare-wrangler-config.ts';
|
|
6
|
+
|
|
7
|
+
const original = process.cwd();
|
|
8
|
+
|
|
9
|
+
function repo(manifestFeatures: unknown, files: Record<string, string>): string {
|
|
10
|
+
const root = mkdtempSync(path.join(tmpdir(), 'prepare-wrangler-'));
|
|
11
|
+
writeFileSync(path.join(root, '.rexezuge.jsonc'), JSON.stringify({ name: 'x', scope: '@x', features: manifestFeatures }));
|
|
12
|
+
for (const [file, content] of Object.entries(files)) {
|
|
13
|
+
mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
|
14
|
+
writeFileSync(path.join(root, file), content);
|
|
15
|
+
}
|
|
16
|
+
process.chdir(root);
|
|
17
|
+
return root;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
process.chdir(original);
|
|
22
|
+
vi.restoreAllMocks();
|
|
23
|
+
vi.unstubAllEnvs();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('prepare-wrangler main', () => {
|
|
27
|
+
it('copies the default template when the manifest declares no workers', () => {
|
|
28
|
+
vi.spyOn(console, 'log').mockImplementation(vi.fn());
|
|
29
|
+
const root = repo({}, { 'apps/api/wrangler.template.jsonc': '{ "name": "api" }\n' });
|
|
30
|
+
main();
|
|
31
|
+
expect(readFileSync(path.join(root, 'wrangler.jsonc'), 'utf8')).toContain('"api"');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('prepares each features.workers entry from its own template into its own config', () => {
|
|
35
|
+
vi.spyOn(console, 'log').mockImplementation(vi.fn());
|
|
36
|
+
const root = repo(
|
|
37
|
+
{ workers: [{ template: 'apps/a/t.jsonc' }, { template: 'apps/b/t.jsonc', config: 'apps/b/wrangler.jsonc' }] },
|
|
38
|
+
{ 'apps/a/t.jsonc': '{ "name": "a" }\n', 'apps/b/t.jsonc': '{ "name": "b" }\n' },
|
|
39
|
+
);
|
|
40
|
+
main();
|
|
41
|
+
expect(readFileSync(path.join(root, 'wrangler.jsonc'), 'utf8')).toContain('"a"');
|
|
42
|
+
expect(readFileSync(path.join(root, 'apps/b/wrangler.jsonc'), 'utf8')).toContain('"b"');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('refuses one WRANGLER_JSONC for several workers', () => {
|
|
46
|
+
repo({ workers: [{ template: 'a.jsonc' }, { template: 'b.jsonc', config: 'b.out.jsonc' }] }, {});
|
|
47
|
+
vi.stubEnv('WRANGLER_JSONC', '{}');
|
|
48
|
+
expect(() => main()).toThrow(/several/);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
import { applyEdits, modify, parse } from 'jsonc-parser';
|
|
16
|
-
import {
|
|
16
|
+
import { configPath, templatePath, type WranglerConfig } from './types.ts';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
The config's current text and its parsed form.
|
|
@@ -24,7 +24,7 @@ export interface ConfigFile {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function readConfig(): ConfigFile {
|
|
27
|
-
const content = readFileSync(
|
|
27
|
+
const content = readFileSync(configPath(), 'utf8');
|
|
28
28
|
return { content, config: parse(content) as WranglerConfig };
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -40,7 +40,7 @@ export function writeConfigValue(content: string, path: Array<string | number>,
|
|
|
40
40
|
Write the config, guaranteeing a trailing newline so Prettier sees a fixed point.
|
|
41
41
|
*/
|
|
42
42
|
export function writeConfig(content: string): void {
|
|
43
|
-
writeFileSync(
|
|
43
|
+
writeFileSync(configPath(), content.endsWith('\n') ? content : `${content}\n`);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -110,8 +110,8 @@ export function prepareConfigFile(): void {
|
|
|
110
110
|
console.log('Wrote wrangler.jsonc from WRANGLER_JSONC repository variable.');
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
|
-
copyFileSync(
|
|
114
|
-
console.log(`WRANGLER_JSONC is empty; copied ${displayPath(
|
|
113
|
+
copyFileSync(templatePath(), configPath());
|
|
114
|
+
console.log(`WRANGLER_JSONC is empty; copied ${displayPath(templatePath())} to ${displayPath(configPath())}.`);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
|
@@ -123,7 +123,7 @@ export function prepareConfigFile(): void {
|
|
|
123
123
|
* the whole reason the check exists.
|
|
124
124
|
*/
|
|
125
125
|
export function ensureMinimumConfigVersion(): void {
|
|
126
|
-
const template = parse(readFileSync(
|
|
126
|
+
const template = parse(readFileSync(templatePath(), 'utf8')) as { $minimumVersion?: unknown };
|
|
127
127
|
if (typeof template.$minimumVersion !== 'number') {
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
@@ -131,7 +131,7 @@ export function ensureMinimumConfigVersion(): void {
|
|
|
131
131
|
const currentVersion = config.$version;
|
|
132
132
|
if (typeof currentVersion !== 'number' || currentVersion < template.$minimumVersion) {
|
|
133
133
|
throw new Error(
|
|
134
|
-
`wrangler.jsonc version (${typeof currentVersion === 'number' ? currentVersion : 'missing'}) is below minimum template version (${template.$minimumVersion}). Regenerate it from ${displayPath(
|
|
134
|
+
`wrangler.jsonc version (${typeof currentVersion === 'number' ? currentVersion : 'missing'}) is below minimum template version (${template.$minimumVersion}). Regenerate it from ${displayPath(templatePath())}.`,
|
|
135
135
|
);
|
|
136
136
|
}
|
|
137
137
|
}
|