@rexezuge/tooling 1.8.0 → 1.8.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAKH,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;KAAE,KAAK,MAAM,GAAG,SAAS,CAAC;CAC/G;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;;;;OASG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACtD;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;IACnC;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAA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AM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACtD;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;IACnC;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AA4DD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,IAAI,CAAA;CAAE,CA0BhG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,cAAc,CActF"}
package/dist/vite.js CHANGED
@@ -1,3 +1,3 @@
1
- var l=Object.defineProperty;var t=(e,n)=>l(e,"name",{value:n,configurable:!0});import{existsSync as f,mkdirSync as p,readFileSync as c,writeFileSync as h}from"node:fs";import m from"node:path";import{fileURLToPath as i,pathToFileURL as x}from"node:url";import{defineConfig as a}from"vitest/config";function u(e){return typeof e=="string"?x(e):e}t(u,"toUrl");function y(e){const n=u(e);return n.href.endsWith("/")?n:new URL(`${n.href}/`)}t(y,"toDirUrl");function g(e){return{name:"spa-shell-embed",closeBundle(){const n=y(e.root??process.cwd()),r=i(new URL(e.path,n)),o=e.distIndex===void 0?i(new URL("dist/index.html",n)):i(u(e.distIndex));if(!f(o)){console.warn("spa-shell-embed: dist/index.html not found, skipping");return}const d=c(o,"utf8"),s=`// Auto-generated by Vite build plugin - DO NOT EDIT.
1
+ var l=Object.defineProperty;var t=(e,n)=>l(e,"name",{value:n,configurable:!0});import{existsSync as f,mkdirSync as p,readFileSync as c,writeFileSync as h}from"node:fs";import m from"node:path";import{fileURLToPath as i,pathToFileURL as x}from"node:url";import{defineConfig as a}from"vitest/config";function s(e){return e instanceof URL?e:e.startsWith("file:")?new URL(e):x(e)}t(s,"toUrl");function y(e){const n=s(e);return n.href.endsWith("/")?n:new URL(`${n.href}/`)}t(y,"toDirUrl");function S(e){return{name:"spa-shell-embed",closeBundle(){const n=y(e.root??process.cwd()),r=i(new URL(e.path,n)),o=e.distIndex===void 0?i(new URL("dist/index.html",n)):i(s(e.distIndex));if(!f(o)){console.warn("spa-shell-embed: dist/index.html not found, skipping");return}const d=c(o,"utf8"),u=`// Auto-generated by Vite build plugin - DO NOT EDIT.
2
2
  export const SPA_HTML: string = ${JSON.stringify(d)};
3
- `;p(m.dirname(r),{recursive:!0}),h(r,s)}}}t(g,"spaShellEmbedPlugin");function L(e={}){const n=[...e.plugins??[]];return e.spaShell!==void 0&&n.push(g(e.spaShell)),a({...n.length>0&&{plugins:n},...e.proxy!==void 0&&{server:{proxy:{...e.proxy}}},build:{outDir:e.outDir??"dist",emptyOutDir:!0}})}t(L,"defineWebViteConfig");export{L as defineWebViteConfig,g as spaShellEmbedPlugin};
3
+ `;p(m.dirname(r),{recursive:!0}),h(r,u)}}}t(S,"spaShellEmbedPlugin");function R(e={}){const n=[...e.plugins??[]];return e.spaShell!==void 0&&n.push(S(e.spaShell)),a({...n.length>0&&{plugins:n},...e.proxy!==void 0&&{server:{proxy:{...e.proxy}}},build:{outDir:e.outDir??"dist",emptyOutDir:!0}})}t(R,"defineWebViteConfig");export{R as defineWebViteConfig,S as spaShellEmbedPlugin};
package/dist/vite.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/vite.ts"],
4
- "sourcesContent": ["/**\n * The SPA's Vite config.\n *\n * Provenance: converged from the `apps/web/vite.config.ts` of the eight repos\n * that build a Vite SPA. They are one file with three variables: the plugin list\n * (`@vitejs/plugin-react` + `@tailwindcss/vite`), the dev-server proxy target,\n * and the `spa-shell-embed` plugin that copies `dist/index.html` into\n * `apps/api/src/generated/spa-shell.ts`.\n *\n * Canonical decisions:\n *\n * 1. **The plugins are passed in, not imported.** The kit stays zero-dependency:\n * `react`, `@vitejs/plugin-react` and `@tailwindcss/vite` belong to the app\n * that uses them, and importing them here would make the tooling package\n * undownloadable for a consumer without a React SPA.\n * 2. **The `spa-shell-embed` hook stays per-repo, and is passed in.** It is the\n * one genuinely repo-specific piece: each repo names its own worker and its\n * own generated-module path. What the kit provides is the *contract* — see\n * `spaShellEmbedPlugin`, which is the converged body of all eight copies.\n * 3. **`server.proxy` is data, not code.** The paths differ per repo\n * (`/user` + `/rest` in Edge-Sonic, `/api` in CalDAV-Bridge, `/tracker` in\n * ChordDHT-Tracker) but the shape never does, so it is an option with a\n * default.\n * 4. **`build.emptyOutDir: true`** is the default, because a stale asset in\n * `dist/` is served as a live bundle — the same half-refreshed build\n * `scripts/verify-spa-shell.ts` rejects.\n *\n * The consumer's `apps/web/vite.config.ts` becomes a handful of lines — see the\n * README.\n */\n\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { defineConfig, type Plugin, type ViteUserConfig } from 'vitest/config';\n\n/**\n * One dev-server proxy entry, as Vite's `server.proxy` accepts it.\n */\nexport interface ProxyEntry {\n readonly target: string;\n readonly changeOrigin?: boolean;\n readonly bypass?: (request: { headers: Record<string, string | string[] | undefined> }) => string | undefined;\n}\n\n/**\n * Where the SPA's built `index.html` is copied to, and under what module name.\n */\nexport interface SpaShellTarget {\n /**\n * Path of the generated module, relative to the repository root.\n *\n * `apps/api/src/generated/spa-shell.ts` in every repo that embeds a shell; the\n * parameter exists because the path is the one thing that genuinely differs.\n */\n readonly path: string;\n /**\n * The repository root the path is resolved against, as a file URL or a path.\n *\n * Defaults to the directory the build runs in (`process.cwd()`), which is the\n * repo root when the build is `pnpm --filter @scope/web build`. Passed in by the\n * Vite config, not derived from `import.meta.url`: this plugin object is created\n * inside the kit's own module, so a URL relative to it points into\n * `node_modules/@rexezuge/tooling` and writes the shell somewhere no compiler\n * will ever look.\n */\n readonly root?: string | URL;\n /**\n * The built `index.html`, as a path or file URL.\n *\n * Defaults to `dist/index.html` under the same root. Vite's `closeBundle` runs\n * after the bundle is written, so this is the file the build just produced.\n */\n readonly distIndex?: string | URL;\n}\n\n/**\n * What `defineWebViteConfig` accepts.\n */\nexport interface WebViteConfigOptions {\n /**\n * The SPA's plugins — `react()`, `tailwindcss()`, and anything else the app\n * needs. Applied before the spa-shell plugin so the shell is written after the\n * bundle exists.\n */\n readonly plugins?: readonly Plugin[];\n /**\n * Dev-server proxy entries. Keyed by path prefix.\n */\n readonly proxy?: Readonly<Record<string, ProxyEntry>>;\n /**\n * Where the built shell is embedded. Omit to skip the embedding entirely.\n */\n readonly spaShell?: SpaShellTarget;\n /**\n * The build output directory.\n */\n readonly outDir?: string;\n /**\n * The directory this config is resolved from, as a file URL. Defaults to the\n * caller's location.\n */\n readonly root?: string;\n}\n\n/**\n * The `spa-shell-embed` plugin, converged from all eight copies.\n *\n * It exists because the API worker serves `SPA_HTML` from a module in its own\n * source tree, and both that module and `dist/` are gitignored — so a fresh\n * clone gets an empty stub from `postinstall` and every `GET /` returns a blank\n * page until someone runs a build. This plugin is what makes the build write the\n * real artefact, and `scripts/verify-spa-shell.ts` is what refuses to deploy\n * without it.\n *\n * Written as a factory rather than inlined so the exit conditions are in one\n * place: the `closeBundle` hook runs on every build, including the ones where\n * `dist/index.html` was never produced, and a plugin that throws there fails\n * builds that legitimately emit nothing.\n */\n/**\n * Normalise a path-or-URL option to a URL, so `new URL(...)` can be used on it.\n *\n * Small, and here because two options accept either form: a path is what a consumer\n * naturally writes in a config, and a URL is what `import.meta.url` hands them.\n * Accepting both is one line and saves a `fileURLToPath` at every call site.\n */\nfunction toUrl(value: string | URL): URL {\n return typeof value === 'string' ? pathToFileURL(value) : value;\n}\n\n/**\n * The same, as a **directory** URL — with the trailing separator `new URL(rel, base)`\n * needs.\n *\n * `new URL('apps/api/x.ts', 'file:///repo')` resolves to `/apps/api/x.ts`, silently\n * dropping the base. The base has to end in a separator, and a path from\n * `process.cwd()` never does, so this is where the plugin would otherwise write the\n * shell into the filesystem root.\n */\nfunction toDirUrl(value: string | URL): URL {\n const url = toUrl(value);\n return url.href.endsWith('/') ? url : new URL(`${url.href}/`);\n}\n\nexport function spaShellEmbedPlugin(target: SpaShellTarget): Plugin & { closeBundle: () => void } {\n return {\n name: 'spa-shell-embed',\n closeBundle() {\n // Resolved from the directory the build runs in, never from this module's own\n // URL: the plugin object is created here but executes in the consumer's Vite\n // process, and `new URL(path, import.meta.url)` would resolve against\n // `node_modules/@rexezuge/tooling`. `process.cwd()` is the repo root for\n // `pnpm --filter @scope/web build`, which is how every consumer runs it.\n const root = toDirUrl(target.root ?? process.cwd());\n const outputPath = fileURLToPath(new URL(target.path, root));\n const indexPath =\n target.distIndex === undefined ? fileURLToPath(new URL('dist/index.html', root)) : fileURLToPath(toUrl(target.distIndex));\n\n if (!existsSync(indexPath)) {\n console.warn('spa-shell-embed: dist/index.html not found, skipping');\n return;\n }\n\n const html = readFileSync(indexPath, 'utf8');\n const output = `// Auto-generated by Vite build plugin - DO NOT EDIT.\\nexport const SPA_HTML: string = ${JSON.stringify(html)};\\n`;\n\n mkdirSync(path.dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, output);\n },\n };\n}\n\n/**\n * Build the SPA's Vite config.\n *\n * ```ts\n * // apps/web/vite.config.ts\n * import react from '@vitejs/plugin-react';\n * import { defineWebViteConfig, spaShellEmbedPlugin } from '@rexezuge/tooling/vite';\n *\n * export default defineWebViteConfig({\n * plugins: [react()],\n * proxy: { '/user': { target: 'http://localhost:8787', changeOrigin: true } },\n * spaShell: { path: '../../apps/api/src/generated/spa-shell.ts' },\n * });\n * ```\n */\nexport function defineWebViteConfig(options: WebViteConfigOptions = {}): ViteUserConfig {\n const plugins: Plugin[] = [...(options.plugins ?? [])];\n if (options.spaShell !== undefined) {\n plugins.push(spaShellEmbedPlugin(options.spaShell));\n }\n\n return defineConfig({\n ...(plugins.length > 0 && { plugins }),\n ...(options.proxy !== undefined && { server: { proxy: { ...options.proxy } } }),\n build: {\n outDir: options.out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,KAAKT,EAAoBQ,EAAQ,QAAQ,CAAC,EAG7Cd,EAAa,CAClB,GAAIe,EAAQ,OAAS,GAAK,CAAE,QAAAA,CAAO,EACnC,GAAID,EAAQ,QAAU,QAAa,CAAE,OAAQ,CAAE,MAAO,CAAE,GAAGA,EAAQ,KAAK,CAAE,CAAE,EAC5E,MAAO,CACL,OAAQA,EAAQ,QAAU,OAC1B,YAAa,IAEhB,CACH,CAdgBX,EAAAU,EAAA",
4
+ "sourcesContent": ["/**\n * The SPA's Vite config.\n *\n * Provenance: converged from the `apps/web/vite.config.ts` of the eight repos\n * that build a Vite SPA. They are one file with three variables: the plugin list\n * (`@vitejs/plugin-react` + `@tailwindcss/vite`), the dev-server proxy target,\n * and the `spa-shell-embed` plugin that copies `dist/index.html` into\n * `apps/api/src/generated/spa-shell.ts`.\n *\n * Canonical decisions:\n *\n * 1. **The plugins are passed in, not imported.** The kit stays zero-dependency:\n * `react`, `@vitejs/plugin-react` and `@tailwindcss/vite` belong to the app\n * that uses them, and importing them here would make the tooling package\n * undownloadable for a consumer without a React SPA.\n * 2. **The `spa-shell-embed` hook stays per-repo, and is passed in.** It is the\n * one genuinely repo-specific piece: each repo names its own worker and its\n * own generated-module path. What the kit provides is the *contract* — see\n * `spaShellEmbedPlugin`, which is the converged body of all eight copies.\n * 3. **`server.proxy` is data, not code.** The paths differ per repo\n * (`/user` + `/rest` in Edge-Sonic, `/api` in CalDAV-Bridge, `/tracker` in\n * ChordDHT-Tracker) but the shape never does, so it is an option with a\n * default.\n * 4. **`build.emptyOutDir: true`** is the default, because a stale asset in\n * `dist/` is served as a live bundle — the same half-refreshed build\n * `scripts/verify-spa-shell.ts` rejects.\n *\n * The consumer's `apps/web/vite.config.ts` becomes a handful of lines — see the\n * README.\n */\n\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { defineConfig, type Plugin, type ViteUserConfig } from 'vitest/config';\n\n/**\n * One dev-server proxy entry, as Vite's `server.proxy` accepts it.\n */\nexport interface ProxyEntry {\n readonly target: string;\n readonly changeOrigin?: boolean;\n readonly bypass?: (request: { headers: Record<string, string | string[] | undefined> }) => string | undefined;\n}\n\n/**\n * Where the SPA's built `index.html` is copied to, and under what module name.\n */\nexport interface SpaShellTarget {\n /**\n * Path of the generated module, relative to the repository root.\n *\n * `apps/api/src/generated/spa-shell.ts` in every repo that embeds a shell; the\n * parameter exists because the path is the one thing that genuinely differs.\n */\n readonly path: string;\n /**\n * The repository root the path is resolved against, as a file URL or a path.\n *\n * Defaults to the directory the build runs in (`process.cwd()`), which is the\n * repo root when the build is `pnpm --filter @scope/web build`. Passed in by the\n * Vite config, not derived from `import.meta.url`: this plugin object is created\n * inside the kit's own module, so a URL relative to it points into\n * `node_modules/@rexezuge/tooling` and writes the shell somewhere no compiler\n * will ever look.\n */\n readonly root?: string | URL;\n /**\n * The built `index.html`, as a path or file URL.\n *\n * Defaults to `dist/index.html` under the same root. Vite's `closeBundle` runs\n * after the bundle is written, so this is the file the build just produced.\n */\n readonly distIndex?: string | URL;\n}\n\n/**\n * What `defineWebViteConfig` accepts.\n */\nexport interface WebViteConfigOptions {\n /**\n * The SPA's plugins — `react()`, `tailwindcss()`, and anything else the app\n * needs. Applied before the spa-shell plugin so the shell is written after the\n * bundle exists.\n */\n readonly plugins?: readonly Plugin[];\n /**\n * Dev-server proxy entries. Keyed by path prefix.\n */\n readonly proxy?: Readonly<Record<string, ProxyEntry>>;\n /**\n * Where the built shell is embedded. Omit to skip the embedding entirely.\n */\n readonly spaShell?: SpaShellTarget;\n /**\n * The build output directory.\n */\n readonly outDir?: string;\n /**\n * The directory this config is resolved from, as a file URL. Defaults to the\n * caller's location.\n */\n readonly root?: string;\n}\n\n/**\n * The `spa-shell-embed` plugin, converged from all eight copies.\n *\n * It exists because the API worker serves `SPA_HTML` from a module in its own\n * source tree, and both that module and `dist/` are gitignored — so a fresh\n * clone gets an empty stub from `postinstall` and every `GET /` returns a blank\n * page until someone runs a build. This plugin is what makes the build write the\n * real artefact, and `scripts/verify-spa-shell.ts` is what refuses to deploy\n * without it.\n *\n * Written as a factory rather than inlined so the exit conditions are in one\n * place: the `closeBundle` hook runs on every build, including the ones where\n * `dist/index.html` was never produced, and a plugin that throws there fails\n * builds that legitimately emit nothing.\n */\n/**\n * Normalise a path-or-URL option to a URL, so `new URL(...)` can be used on it.\n *\n * Small, and here because two options accept either form: a path is what a consumer\n * naturally writes in a config, and a URL is what `import.meta.url` hands them.\n * Accepting both is one line and saves a `fileURLToPath` at every call site.\n */\n/**\n * Normalise `string | URL` to a `URL`.\n *\n * A string that is **already a file URL** must be parsed, not converted:\n * `pathToFileURL('file:///srv/app')` treats its argument as a filesystem path\n * and produces `file:///<cwd>/file:/srv/app`, so every path built on top of it\n * silently resolves into a directory named after the scheme.\n *\n * The failure this prevented is not loud. `spaShellEmbedPlugin` then reports\n * \"dist/index.html not found, skipping\" — which is also what a genuinely fresh\n * checkout prints on its first build — and the consumer's worker keeps serving\n * the *previous* shell, so the SPA ships yesterday's JavaScript with no error\n * anywhere in the build log. Both `root` and `distIndex` are documented as\n * \"a file URL or a path\", and `new URL('.', import.meta.url).href` — the shape\n * every config file reaches for first — is a file-URL string, so this is the\n * path most callers take.\n */\nfunction toUrl(value: string | URL): URL {\n if (value instanceof URL) return value;\n return value.startsWith('file:') ? new URL(value) : pathToFileURL(value);\n}\n\n/**\n * The same, as a **directory** URL — with the trailing separator `new URL(rel, base)`\n * needs.\n *\n * `new URL('apps/api/x.ts', 'file:///repo')` resolves to `/apps/api/x.ts`, silently\n * dropping the base. The base has to end in a separator, and a path from\n * `process.cwd()` never does, so this is where the plugin would otherwise write the\n * shell into the filesystem root.\n */\nfunction toDirUrl(value: string | URL): URL {\n const url = toUrl(value);\n return url.href.endsWith('/') ? url : new URL(`${url.href}/`);\n}\n\nexport function spaShellEmbedPlugin(target: SpaShellTarget): Plugin & { closeBundle: () => void } {\n return {\n name: 'spa-shell-embed',\n closeBundle() {\n // Resolved from the directory the build runs in, never from this module's own\n // URL: the plugin object is created here but executes in the consumer's Vite\n // process, and `new URL(path, import.meta.url)` would resolve against\n // `node_modules/@rexezuge/tooling`. `process.cwd()` is the repo root for\n // `pnpm --filter @scope/web build`, which is how every consumer runs it.\n const root = toDirUrl(target.root ?? process.cwd());\n const outputPath = fileURLToPath(new URL(target.path, root));\n const indexPath =\n target.distIndex === undefined ? fileURLToPath(new URL('dist/index.html', root)) : fileURLToPath(toUrl(target.distIndex));\n\n if (!existsSync(indexPath)) {\n console.warn('spa-shell-embed: dist/index.html not found, skipping');\n return;\n }\n\n const html = readFileSync(indexPath, 'utf8');\n const output = `// Auto-generated by Vite build plugin - DO NOT EDIT.\\nexport const SPA_HTML: string = ${JSON.stringify(html)};\\n`;\n\n mkdirSync(path.dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, output);\n },\n };\n}\n\n/**\n * Build the SPA's Vite config.\n *\n * ```ts\n * // apps/web/vite.config.ts\n * import react from '@vitejs/plugin-react';\n * import { defineWebViteConfig, spaShellEmbedPlugin } from '@rexezuge/tooling/vite';\n *\n * export default defineWebViteConfig({\n * plugins: [react()],\n * proxy: { '/user': { target: 'http://localhost:8787', changeOrigin: true } },\n * spaShell: { path: '../../apps/api/src/generated/spa-shell.ts' },\n * });\n * ```\n */\nexport function defineWebViteConfig(options: WebViteConfigOptions = {}): ViteUserConfig {\n const plugins: Plugin[] = [...(options.plugins ?? [])];\n if (options.spaShell !== undefined) {\n plugins.push(spaShellEmbedPlugin(options.spaShell));\n }\n\n return defineConfig({\n ...(plugins.length > 0 && { plugins }),\n ...(options.proxy !== undefined && { server: { proxy: { ...options.proxy } } }),\n build: {\n outDir: options.outDir ?? 'dist',\n emptyOutDir: true,\n },\n });\n}\n"],
5
+ "mappings": "+EA+BA,OAAS,cAAAA,EAAY,aAAAC,EAAW,gBAAAC,EAAc,iBAAAC,MAAqB,UACnE,OAAOC,MAAU,YACjB,OAAS,i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,GAAID,EAAQ,QAAU,QAAa,CAAE,OAAQ,CAAE,MAAO,CAAE,GAAGA,EAAQ,KAAK,CAAE,CAAE,EAC5E,MAAO,CACL,OAAQA,EAAQ,QAAU,OAC1B,YAAa,IAEhB,CACH,CAdgBX,EAAAU,EAAA",
6
6
  "names": ["existsSync", "mkdirSync", "readFileSync", "writeFileSync", "path", "fileURLToPath", "pathToFileURL", "defineConfig", "toUrl", "value", "__name", "toDirUrl", "url", "spaShellEmbedPlugin", "target", "root", "outputPath", "indexPath", "html", "output", "defineWebViteConfig", "options", "plugins"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexezuge/tooling",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "src"
39
39
  ],
40
40
  "dependencies": {
41
- "@rexezuge/d1": "1.8.0"
41
+ "@rexezuge/d1": "1.8.1"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "eslint": "^10.0.0",
package/src/vite.test.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
+ import { pathToFileURL } from 'node:url';
3
4
  import path from 'node:path';
4
5
  import { afterAll, describe, expect, it } from 'vitest';
5
6
  import { defineWebViteConfig, spaShellEmbedPlugin } from './vite.ts';
@@ -91,4 +92,48 @@ describe('spaShellEmbedPlugin', () => {
91
92
  // The kit's own directory must not gain a generated file from a consumer's build.
92
93
  expect(existsSync(path.join(process.cwd(), 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
93
94
  });
95
+
96
+ describe('root and distIndex accept a file URL as well as a path', () => {
97
+ // `root` and `distIndex` are typed `string | URL` and documented as "a file
98
+ // URL or a path", and `new URL('.', import.meta.url).href` — the shape a
99
+ // config file reaches for first — is a file-URL *string*. Treating that as a
100
+ // filesystem path nests it under the cwd as `file:///<cwd>/file:/…`, after
101
+ // which the plugin reports "dist/index.html not found, skipping" — the same
102
+ // message a genuinely fresh checkout prints — and the consumer's worker
103
+ // keeps serving the previous shell with nothing in the log to say so.
104
+
105
+ it('accepts a file-URL string for root', async () => {
106
+ const root = tempRoot();
107
+ writeBuild(root);
108
+
109
+ const plugin = spaShellEmbedPlugin({ path: 'apps/api/src/generated/spa-shell.ts', root: pathToFileURL(root).href });
110
+ await plugin.closeBundle?.();
111
+
112
+ expect(existsSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
113
+ });
114
+
115
+ it('accepts a file-URL string for distIndex', async () => {
116
+ const root = tempRoot();
117
+ writeBuild(root);
118
+
119
+ const plugin = spaShellEmbedPlugin({
120
+ path: 'apps/api/src/generated/spa-shell.ts',
121
+ root,
122
+ distIndex: pathToFileURL(path.join(root, 'dist/index.html')).href,
123
+ });
124
+ await plugin.closeBundle?.();
125
+
126
+ expect(readFileSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'), 'utf8')).toContain('SPA_HTML');
127
+ });
128
+
129
+ it('still treats a plain filesystem path as a path', async () => {
130
+ const root = tempRoot();
131
+ writeBuild(root);
132
+
133
+ const plugin = spaShellEmbedPlugin({ path: 'apps/api/src/generated/spa-shell.ts', root });
134
+ await plugin.closeBundle?.();
135
+
136
+ expect(existsSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
137
+ });
138
+ });
94
139
  });
package/src/vite.ts CHANGED
@@ -125,8 +125,26 @@ export interface WebViteConfigOptions {
125
125
  * naturally writes in a config, and a URL is what `import.meta.url` hands them.
126
126
  * Accepting both is one line and saves a `fileURLToPath` at every call site.
127
127
  */
128
+ /**
129
+ * Normalise `string | URL` to a `URL`.
130
+ *
131
+ * A string that is **already a file URL** must be parsed, not converted:
132
+ * `pathToFileURL('file:///srv/app')` treats its argument as a filesystem path
133
+ * and produces `file:///<cwd>/file:/srv/app`, so every path built on top of it
134
+ * silently resolves into a directory named after the scheme.
135
+ *
136
+ * The failure this prevented is not loud. `spaShellEmbedPlugin` then reports
137
+ * "dist/index.html not found, skipping" — which is also what a genuinely fresh
138
+ * checkout prints on its first build — and the consumer's worker keeps serving
139
+ * the *previous* shell, so the SPA ships yesterday's JavaScript with no error
140
+ * anywhere in the build log. Both `root` and `distIndex` are documented as
141
+ * "a file URL or a path", and `new URL('.', import.meta.url).href` — the shape
142
+ * every config file reaches for first — is a file-URL string, so this is the
143
+ * path most callers take.
144
+ */
128
145
  function toUrl(value: string | URL): URL {
129
- return typeof value === 'string' ? pathToFileURL(value) : value;
146
+ if (value instanceof URL) return value;
147
+ return value.startsWith('file:') ? new URL(value) : pathToFileURL(value);
130
148
  }
131
149
 
132
150
  /**