@rsc-kit/core 0.40.0 → 0.41.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.
@@ -1 +1 @@
1
- {"version":3,"file":"typegen.js","sourceRoot":"","sources":["../src/typegen.ts"],"names":[],"mappings":";AACA,gEAAgE;AAChE,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,sEAAsE;AACtE,2EAA2E;AAC3E,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAE9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQzC,KAAK,UAAU,OAAO,CAAC,MAAe;IACpC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC;IAE3B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAEhF,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAmB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,KAAK,GAAG,KAAK;IACvD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,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AAC;IAE9C,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE1B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["#!/usr/bin/env node\n// rsc-kit-typegen: write the route types without starting Vite.\n//\n// The types - every url the app has, for <Link href> and redirect() - are\n// written when the dev server or a build starts, and again when a dev server\n// sees a route added. A typecheck run with neither, by an agent or in CI,\n// read the types from the last start: a route added since failed with\n// '\"/admin\"' is not assignable to type Route until something started Vite.\n//\n// The app's own vite.config is loaded, through the app's own Vite, so the\n// plugin's options - sourceDir, outDir, a host's route file - are the ones it\n// builds with. Only the plugin's config step runs, which is what writes them.\n\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { basename, join, relative } from \"node:path\";\nimport { cwd, exit, stderr, stdout } from \"node:process\";\nimport { pathToFileURL } from \"node:url\";\n\ninterface PluginLike {\n name?: string;\n config?: (config: object, env: { command: string; mode: string }) => unknown;\n api?: { generatedFiles?: () => string[]; info?: () => Record<string, unknown> };\n}\n\nasync function flatten(option: unknown): Promise<PluginLike[]> {\n const value = await option;\n\n if (Array.isArray(value)) return (await Promise.all(value.map(flatten))).flat();\n\n return value && typeof value === \"object\" ? [value as PluginLike] : [];\n}\n\n/**\n * Write the types; or, with `check`, say which committed generated files are\n * not what the backend and the route tree produce now, and change nothing.\n *\n * For CI: `rsc-kit-typegen --check` fails when rsc-host.json or the types were\n * committed and the backend has moved on since. Only files that were already\n * there are compared - one that is not committed is written fresh by every\n * build and cannot be stale - and every one is put back as it was.\n */\nexport async function typegen(root = cwd(), check = false): Promise<string[]> {\n const local = createRequire(join(root, \"package.json\"));\n let vitePath: string;\n\n try {\n vitePath = local.resolve(\"vite\");\n } catch {\n throw new Error(\"No vite installed in \" + root + \". Run this from the app's directory.\");\n }\n\n const vite = (await import(pathToFileURL(vitePath).href)) as {\n loadConfigFromFile: (\n env: { command: string; mode: string },\n file?: string,\n root?: string,\n ) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n\n // As a build would: a manifest command that fails is a failure, not a\n // warning, when the question is whether what is committed is current.\n const env = check ? { command: \"build\", mode: \"production\" } : { command: \"serve\", mode: \"development\" };\n const loaded = await vite.loadConfigFromFile(env, undefined, root);\n\n if (!loaded) throw new Error(\"No vite.config found in \" + root + \".\");\n\n const plugin = (await flatten(loaded.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n\n if (!plugin?.config) throw new Error(\"The vite.config in \" + root + \" does not use rscKit().\");\n\n if (!check) {\n await plugin.config({}, env);\n\n return [];\n }\n\n const files = plugin.api?.generatedFiles?.() ?? [];\n const before = new Map(files.filter((f) => existsSync(f)).map((f) => [f, readFileSync(f, \"utf-8\")]));\n\n try {\n await plugin.config({}, env);\n\n return [...before].filter(([f, text]) => !existsSync(f) || readFileSync(f, \"utf-8\") !== text).map(([f]) => f);\n } finally {\n for (const [f, text] of before) writeFileSync(f, text);\n }\n}\n\n// Run as a command, not when imported.\nif (import.meta.url === pathToFileURL(process.argv[1] ?? \"\").href || process.argv[1]?.endsWith(\"rsc-kit-typegen\")) {\n const check = process.argv.includes(\"--check\");\n\n typegen(cwd(), check)\n .then((stale) => {\n if (!check) {\n stdout.write(\"rsc-kit: route types written\\n\");\n\n return;\n }\n\n if (stale.length === 0) {\n stdout.write(\"rsc-kit: generated files are current\\n\");\n\n return;\n }\n\n stderr.write(\n \"rsc-kit-typegen --check: these are committed and no longer what the backend and the routes produce:\\n\" +\n stale.map((f) => \" \" + relative(cwd(), f)).join(\"\\n\") +\n \"\\nRun rsc-kit-typegen and commit the result.\\n\",\n );\n exit(1);\n })\n .catch((error: unknown) => {\n stderr.write(\"rsc-kit-typegen: \" + (error instanceof Error ? error.message : String(error)) + \"\\n\");\n exit(1);\n });\n}\n\n/**\n * What a build of the app in `root` will produce - `{ output: \"server\", ... }`\n * or `{ output: \"export\", dir }` - read before building, from the app's own\n * Vite config, evaluated the way a build evaluates it. A value computed in\n * the config, or RSC_OUTPUT in the environment, resolves exactly as the build\n * resolves it, because it is the same code deciding.\n */\nexport async function appInfo(root = cwd()): Promise<Record<string, unknown>> {\n const local = createRequire(join(root, \"package.json\"));\n let vitePath: string;\n\n try {\n vitePath = local.resolve(\"vite\");\n } catch {\n throw new Error(\"No vite installed in \" + root + \". Run this from the app's directory.\");\n }\n\n const vite = (await import(pathToFileURL(vitePath).href)) as {\n loadConfigFromFile: (\n env: { command: string; mode: string },\n file?: string,\n root?: string,\n ) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n // From inside the app, as a build runs: rscKit() takes its project root\n // from the working directory when the config creates it.\n const from = cwd();\n\n process.chdir(root);\n\n try {\n const loaded = await vite.loadConfigFromFile({ command: \"build\", mode: \"production\" }, undefined, root);\n\n if (!loaded) throw new Error(\"No vite.config found in \" + root + \".\");\n\n const plugin = (await flatten(loaded.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n\n if (!plugin?.api?.info) throw new Error(\"The vite.config in \" + root + \" does not use rscKit().\");\n\n return plugin.api.info();\n } finally {\n process.chdir(from);\n }\n}\n\n\n/** A form's name from its action's: contactSend is contact-send. */\nfunction formName(action: string): string {\n return action.replace(/([a-z0-9])([A-Z])/g, \"$1-$2\").toLowerCase();\n}\n\n/**\n * Write `<sourceDir>/forms/<name>.ts`: a public form drawn from a backend\n * action, the way the docs write it by hand. The backend is asked first, as a\n * dev server start asks it, so an action added a moment ago is there.\n *\n * The file is the app's to edit afterwards - a theme, labels, `done` - and is\n * never overwritten unless `force` says so.\n */\nexport async function makeForm(\n root: string,\n action: string,\n options: { name?: string; force?: boolean } = {},\n): Promise<string> {\n await typegen(root);\n\n const local = createRequire(join(root, \"package.json\"));\n const vite = (await import(pathToFileURL(local.resolve(\"vite\")).href)) as {\n loadConfigFromFile: (env: { command: string; mode: string }, file?: string, root?: string) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n const loaded = await vite.loadConfigFromFile({ command: \"serve\", mode: \"development\" }, undefined, root);\n const plugin = (await flatten(loaded?.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n const files = plugin?.api?.generatedFiles?.() ?? [];\n const manifestFile = files.find((f) => f.endsWith(\"rsc-host.json\"));\n const actionsFile = files.find((f) => f.endsWith(\"server-actions.generated.ts\"));\n\n if (!manifestFile || !actionsFile || !existsSync(manifestFile)) {\n throw new Error(\"No rsc-host.json: this app has no backend that describes its actions (rscKit({ hostManifest }) or a Go registry).\");\n }\n\n const manifest = JSON.parse(readFileSync(manifestFile, \"utf-8\")) as {\n actions?: Record<string, string>;\n types?: Record<string, { params?: unknown[] }>;\n };\n const actions = manifest.actions ?? {};\n const target = actions[action];\n\n if (!target) {\n const known = Object.keys(actions);\n\n throw new Error(\n `The backend has no action named ${action}.` +\n (known.length ? ` It has: ${known.join(\", \")}.` : \" It has none: a form posts to an action, which is a class in app/Rsc/Actions in Laravel, or reg.HandleAction in Go.\"),\n );\n }\n\n const name = options.name ?? formName(action).replace(/-(send|submit|store|create)$/, \"\");\n\n if (!/^[a-z0-9-]+$/.test(name)) throw new Error(`A form's name is lowercase letters, digits and dashes: ${name}`);\n\n const sourceDir = join(actionsFile, \"..\");\n const file = join(sourceDir, \"forms\", name + \".ts\");\n\n if (existsSync(file) && !options.force) throw new Error(`${relative(root, file)} is already there. Pass --force to write over it.`);\n\n const exported = name.replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase());\n const text = `import { defineBlueprint } from '@rsc-kit/press/forms'\nimport { shadcn } from '@rsc-kit/press/shadcn'\nimport { ${action} } from '../${basename(actionsFile, \".ts\")}'\n\n// The fields and every check are ${target}'s: the backend says what it takes,\n// and its refusals land under the fields. Place it in any page: <${exported}.Form />.\n// Add actions.update to edit a record with it too: <${exported}.Form id={...} values={...} />.\nexport const ${exported} = defineBlueprint({\n name: '${name}',\n actions: { create: ${action} },\n theme: shadcn,\n})\n`;\n\n const { mkdirSync } = await import(\"node:fs\");\n\n mkdirSync(join(sourceDir, \"forms\"), { recursive: true });\n writeFileSync(file, text);\n\n return file;\n}\n"]}
1
+ {"version":3,"file":"typegen.js","sourceRoot":"","sources":["../src/typegen.ts"],"names":[],"mappings":";AACA,gEAAgE;AAChE,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,sEAAsE;AACtE,2EAA2E;AAC3E,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAE9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQzC,KAAK,UAAU,OAAO,CAAC,MAAe;IACpC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC;IAE3B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAEhF,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAmB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,EAAE,KAAK,GAAG,KAAK;IACvD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;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QAAQ;uDACrB,QAAQ;eAChD,QAAQ;WACZ,IAAI;uBACQ,SAAS;;;CAG/B,CAAC;IAEA,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IAE9C,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE1B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["#!/usr/bin/env node\n// rsc-kit-typegen: write the route types without starting Vite.\n//\n// The types - every url the app has, for <Link href> and redirect() - are\n// written when the dev server or a build starts, and again when a dev server\n// sees a route added. A typecheck run with neither, by an agent or in CI,\n// read the types from the last start: a route added since failed with\n// '\"/admin\"' is not assignable to type Route until something started Vite.\n//\n// The app's own vite.config is loaded, through the app's own Vite, so the\n// plugin's options - sourceDir, outDir, a host's route file - are the ones it\n// builds with. Only the plugin's config step runs, which is what writes them.\n\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { join, relative } from \"node:path\";\nimport { cwd, exit, stderr, stdout } from \"node:process\";\nimport { pathToFileURL } from \"node:url\";\n\ninterface PluginLike {\n name?: string;\n config?: (config: object, env: { command: string; mode: string }) => unknown;\n api?: { generatedFiles?: () => string[]; info?: () => Record<string, unknown>; sourceDir?: () => string };\n}\n\nasync function flatten(option: unknown): Promise<PluginLike[]> {\n const value = await option;\n\n if (Array.isArray(value)) return (await Promise.all(value.map(flatten))).flat();\n\n return value && typeof value === \"object\" ? [value as PluginLike] : [];\n}\n\n/**\n * Write the types; or, with `check`, say which committed generated files are\n * not what the backend and the route tree produce now, and change nothing.\n *\n * For CI: `rsc-kit-typegen --check` fails when rsc-host.json or the types were\n * committed and the backend has moved on since. Only files that were already\n * there are compared - one that is not committed is written fresh by every\n * build and cannot be stale - and every one is put back as it was.\n */\nexport async function typegen(root = cwd(), check = false): Promise<string[]> {\n const local = createRequire(join(root, \"package.json\"));\n let vitePath: string;\n\n try {\n vitePath = local.resolve(\"vite\");\n } catch {\n throw new Error(\"No vite installed in \" + root + \". Run this from the app's directory.\");\n }\n\n const vite = (await import(pathToFileURL(vitePath).href)) as {\n loadConfigFromFile: (\n env: { command: string; mode: string },\n file?: string,\n root?: string,\n ) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n\n // As a build would: a manifest command that fails is a failure, not a\n // warning, when the question is whether what is committed is current.\n const env = check ? { command: \"build\", mode: \"production\" } : { command: \"serve\", mode: \"development\" };\n const loaded = await vite.loadConfigFromFile(env, undefined, root);\n\n if (!loaded) throw new Error(\"No vite.config found in \" + root + \".\");\n\n const plugin = (await flatten(loaded.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n\n if (!plugin?.config) throw new Error(\"The vite.config in \" + root + \" does not use rscKit().\");\n\n if (!check) {\n await plugin.config({}, env);\n\n return [];\n }\n\n const files = plugin.api?.generatedFiles?.() ?? [];\n const before = new Map(files.filter((f) => existsSync(f)).map((f) => [f, readFileSync(f, \"utf-8\")]));\n\n try {\n await plugin.config({}, env);\n\n return [...before].filter(([f, text]) => !existsSync(f) || readFileSync(f, \"utf-8\") !== text).map(([f]) => f);\n } finally {\n for (const [f, text] of before) writeFileSync(f, text);\n }\n}\n\n// Run as a command, not when imported.\nif (import.meta.url === pathToFileURL(process.argv[1] ?? \"\").href || process.argv[1]?.endsWith(\"rsc-kit-typegen\")) {\n const check = process.argv.includes(\"--check\");\n\n typegen(cwd(), check)\n .then((stale) => {\n if (!check) {\n stdout.write(\"rsc-kit: route types written\\n\");\n\n return;\n }\n\n if (stale.length === 0) {\n stdout.write(\"rsc-kit: generated files are current\\n\");\n\n return;\n }\n\n stderr.write(\n \"rsc-kit-typegen --check: these are committed and no longer what the backend and the routes produce:\\n\" +\n stale.map((f) => \" \" + relative(cwd(), f)).join(\"\\n\") +\n \"\\nRun rsc-kit-typegen and commit the result.\\n\",\n );\n exit(1);\n })\n .catch((error: unknown) => {\n stderr.write(\"rsc-kit-typegen: \" + (error instanceof Error ? error.message : String(error)) + \"\\n\");\n exit(1);\n });\n}\n\n/**\n * What a build of the app in `root` will produce - `{ output: \"server\", ... }`\n * or `{ output: \"export\", dir }` - read before building, from the app's own\n * Vite config, evaluated the way a build evaluates it. A value computed in\n * the config, or RSC_OUTPUT in the environment, resolves exactly as the build\n * resolves it, because it is the same code deciding.\n */\nexport async function appInfo(root = cwd()): Promise<Record<string, unknown>> {\n const local = createRequire(join(root, \"package.json\"));\n let vitePath: string;\n\n try {\n vitePath = local.resolve(\"vite\");\n } catch {\n throw new Error(\"No vite installed in \" + root + \". Run this from the app's directory.\");\n }\n\n const vite = (await import(pathToFileURL(vitePath).href)) as {\n loadConfigFromFile: (\n env: { command: string; mode: string },\n file?: string,\n root?: string,\n ) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n // From inside the app, as a build runs: rscKit() takes its project root\n // from the working directory when the config creates it.\n const from = cwd();\n\n process.chdir(root);\n\n try {\n const loaded = await vite.loadConfigFromFile({ command: \"build\", mode: \"production\" }, undefined, root);\n\n if (!loaded) throw new Error(\"No vite.config found in \" + root + \".\");\n\n const plugin = (await flatten(loaded.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n\n if (!plugin?.api?.info) throw new Error(\"The vite.config in \" + root + \" does not use rscKit().\");\n\n return plugin.api.info();\n } finally {\n process.chdir(from);\n }\n}\n\n\n/** A form's name from its action's: contactSend is contact-send. */\nfunction formName(action: string): string {\n return action.replace(/\\./g, \"-\").replace(/([a-z0-9])([A-Z])/g, \"$1-$2\").toLowerCase();\n}\n\n/**\n * Write `<sourceDir>/forms/<name>.ts`: a public form drawn from a backend\n * action, the way the docs write it by hand. The backend is asked first, as a\n * dev server start asks it, so an action added a moment ago is there.\n *\n * The file is the app's to edit afterwards - a theme, labels, `done` - and is\n * never overwritten unless `force` says so.\n */\nexport async function makeForm(\n root: string,\n action: string,\n options: { name?: string; force?: boolean } = {},\n): Promise<string> {\n await typegen(root);\n\n const local = createRequire(join(root, \"package.json\"));\n const vite = (await import(pathToFileURL(local.resolve(\"vite\")).href)) as {\n loadConfigFromFile: (env: { command: string; mode: string }, file?: string, root?: string) => Promise<{ config: { plugins?: unknown[] } } | null>;\n };\n const loaded = await vite.loadConfigFromFile({ command: \"serve\", mode: \"development\" }, undefined, root);\n const plugin = (await flatten(loaded?.config.plugins ?? [])).find((p) => p.name === \"rsc-kit\");\n const files = plugin?.api?.generatedFiles?.() ?? [];\n const manifestFile = files.find((f) => f.endsWith(\"rsc-host.json\"));\n\n if (!manifestFile || !existsSync(manifestFile)) {\n throw new Error(\"No rsc-host.json: this app has no backend that describes its actions (rscKit({ hostManifest }) or a Go registry).\");\n }\n\n const manifest = JSON.parse(readFileSync(manifestFile, \"utf-8\")) as {\n actions?: Record<string, Record<string, string>>;\n types?: Record<string, { params?: unknown[] }>;\n };\n // Named as rpc() names it - Contact.send - and found in whichever module\n // the backend put it.\n const all = Object.entries(manifest.actions ?? {}).flatMap(([module, exports]) =>\n Object.entries(exports).map(([name, target]) => ({ module, name, target })),\n );\n const found = all.find((a) => a.target === action);\n const target = found?.target;\n\n if (!found || !target) {\n const known = all.map((a) => a.target);\n\n throw new Error(\n `The backend has no action named ${action}.` +\n (known.length ? ` It has: ${known.join(\", \")}.` : \" It has none: a form posts to an action, which is a class in app/Rsc/Actions in Laravel, or reg.HandleAction in Go.\"),\n );\n }\n\n const name = options.name ?? formName(action).replace(/-(send|submit|store|create)$/, \"\");\n const from = \"../server-actions/\" + found.module;\n\n if (!/^[a-z0-9-]+$/.test(name)) throw new Error(`A form's name is lowercase letters, digits and dashes: ${name}`);\n\n const sourceDir = plugin?.api?.sourceDir?.() ?? join(root, \"src\");\n const file = join(sourceDir, \"forms\", name + \".ts\");\n\n if (existsSync(file) && !options.force) throw new Error(`${relative(root, file)} is already there. Pass --force to write over it.`);\n\n const exported = name.replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase());\n // The action under its own name - send - unless that is the form's, or a\n // word JavaScript keeps (delete): then send + Action. A default is named\n // after its module.\n const own = found.name === \"default\" ? found.module.split(\"/\").pop()!.replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase()) : found.name;\n const usable = (id: string) => {\n try {\n new Function(`let ${id}`);\n return id !== exported;\n } catch {\n return false;\n }\n };\n const reference = usable(own) ? own : own + \"Action\";\n const imported =\n found.name === \"default\"\n ? `import ${reference} from '${from}'`\n : `import { ${reference === found.name ? reference : `${found.name} as ${reference}`} } from '${from}'`;\n const text = `import { defineBlueprint } from '@rsc-kit/press/forms'\nimport { shadcn } from '@rsc-kit/press/shadcn'\n${imported}\n\n// The fields and every check are ${target}'s: the backend says what it takes,\n// and its refusals land under the fields. Place it in any page: <${exported}.Form />.\n// Add actions.update to edit a record with it too: <${exported}.Form id={...} values={...} />.\nexport const ${exported} = defineBlueprint({\n name: '${name}',\n actions: { create: ${reference} },\n theme: shadcn,\n})\n`;\n\n const { mkdirSync } = await import(\"node:fs\");\n\n mkdirSync(join(sourceDir, \"forms\"), { recursive: true });\n writeFileSync(file, text);\n\n return file;\n}\n"]}
package/dist/vite.d.ts CHANGED
@@ -336,17 +336,22 @@ export interface RscKitOptions {
336
336
  dynamicPattern: RegExp;
337
337
  };
338
338
  /**
339
- * Functions the host exposes to the app, as `{ exportedName: target }`.
340
- *
341
- * The build writes a "use server" module of stubs for these, each one
342
- * calling the host global with its target — so app code imports an ordinary
343
- * async function and never names the transport. Discovery belongs to the
344
- * host, whose functions these are; only the rendering is here, because the
345
- * module has to land beside the app's source and that path is the build's.
339
+ * Functions the host exposes to the app as server actions, by module and
340
+ * then by export: `{ "orders": { "create": "Orders.create" },
341
+ * "send-invite": { "default": "SendInvite" } }`.
342
+ *
343
+ * The build writes a "use server" module for each under `server-actions/`
344
+ * in the source directory - `server-actions/orders.ts` exporting `create` -
345
+ * each export calling the host global with its target, so app code imports
346
+ * an ordinary async function and never names the transport:
347
+ * `import * as orders from './server-actions/orders'`, then `orders.create`.
348
+ * Discovery belongs to the host, whose functions these are; only the
349
+ * rendering is here, because the modules land beside the app's source and
350
+ * that path is the build's.
346
351
  *
347
352
  * A host whose functions are already JavaScript passes nothing.
348
353
  */
349
- hostActions?: Record<string, string>;
354
+ hostActions?: HostActions;
350
355
  /**
351
356
  * The backend's command that writes its manifest, run as dev or a build
352
357
  * starts so the manifest cannot go stale:
@@ -371,6 +376,8 @@ export interface RscKitOptions {
371
376
  watch?: string[];
372
377
  };
373
378
  }
379
+ /** The backend's actions by module - its path under server-actions/ - and then by export. */
380
+ export type HostActions = Record<string, Record<string, string>>;
374
381
  /**
375
382
  * rscKit({ headers }), in the case the contract spells each name. Refused at
376
383
  * build, never trimmed at runtime: a header that was asked for and quietly not
package/dist/vite.js CHANGED
@@ -388,8 +388,58 @@ function envRouteConfig() {
388
388
  }
389
389
  /** The file a backend writes its action names into. */
390
390
  const HOST_FILE = "rsc-host.json";
391
- /** The "use server" module of the backend's action stubs, written beside the app. */
392
- const HOST_ACTIONS_MODULE = "server-actions.generated.ts";
391
+ /**
392
+ * The folder of "use server" modules of the backend's action stubs, in the
393
+ * source directory: one module per class, `server-actions/billing/invoices.ts`
394
+ * for `Billing/Invoices`. The build's own - it writes every file in it and
395
+ * removes the ones a backend no longer has.
396
+ */
397
+ const HOST_ACTIONS_DIR = "server-actions";
398
+ /** What every module the build writes there starts with - and what it removes by. */
399
+ const HOST_ACTIONS_HEADER = "// @generated — do not edit. Written by the RSC build from the host action map.";
400
+ const HOST_MODULE_PATH = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/;
401
+ const JS_IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
402
+ // Fine as a property - orders.delete - and not as a function's name, so
403
+ // these are declared under another and exported under their own.
404
+ const JS_RESERVED = new Set(("break case catch class const continue debugger default delete do else enum export extends false finally for " +
405
+ "function if import in instanceof new null return super switch this throw true try typeof var void while with " +
406
+ "yield let static implements interface package private protected public await arguments eval").split(" "));
407
+ /**
408
+ * The action map, checked: a module path of lowercase words, and exports that
409
+ * are identifiers or `default`. The flat `{ jsName: target }` of before is
410
+ * named as such - read as modules it would write nothing and say nothing.
411
+ */
412
+ function checkHostActions(actions, from) {
413
+ const isMap = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
414
+ if (!isMap(actions))
415
+ throw new Error(`[rsc-kit] ${from}: "actions" must be an object of { module: { export: "Function.name" } }.`);
416
+ for (const [module, exports] of Object.entries(actions)) {
417
+ if (typeof exports === "string") {
418
+ throw new Error(`[rsc-kit] ${from} lists actions the old way ({ "${module}": "${exports}" }). Actions are one module per class now - ` +
419
+ `{ "orders": { "create": "Orders.create" } } - so update the backend's adapter and run its manifest command.`);
420
+ }
421
+ if (!HOST_MODULE_PATH.test(module)) {
422
+ throw new Error(`[rsc-kit] ${from}: "${module}" is not a module path - lowercase words joined by dashes, folders by slashes.`);
423
+ }
424
+ if (!isMap(exports))
425
+ throw new Error(`[rsc-kit] ${from}: actions["${module}"] must be an object of { export: "Function.name" }.`);
426
+ for (const [name, target] of Object.entries(exports)) {
427
+ if (!JS_IDENTIFIER.test(name))
428
+ throw new Error(`[rsc-kit] ${from}: "${name}" in "${module}" is not a name JavaScript can export.`);
429
+ if (typeof target !== "string")
430
+ throw new Error(`[rsc-kit] ${from}: actions["${module}"]["${name}"] must be a function name.`);
431
+ }
432
+ }
433
+ return actions;
434
+ }
435
+ /** The `.ts` files under a folder, at any depth. */
436
+ function tsFilesUnder(dir) {
437
+ if (!existsSync(dir))
438
+ return [];
439
+ return readdirSync(dir, { recursive: true, encoding: "utf-8" })
440
+ .filter((f) => f.endsWith(".ts"))
441
+ .map((f) => join(dir, f));
442
+ }
393
443
  function fileHostManifest(root) {
394
444
  const path = join(root, HOST_FILE);
395
445
  if (!existsSync(path)) {
@@ -408,10 +458,7 @@ function fileHostManifest(root) {
408
458
  }
409
459
  // An empty list is an empty map: PHP's json_encode writes an empty array
410
460
  // as [] whatever it was declared as.
411
- const actions = Array.isArray(parsed?.actions) && parsed.actions.length === 0 ? {} : parsed?.actions ?? {};
412
- if (typeof actions !== "object" || actions === null || Array.isArray(actions)) {
413
- throw new Error(`[rsc-kit] ${HOST_FILE}: "actions" must be an object of { jsName: "Function.name" }.`);
414
- }
461
+ const actions = checkHostActions(Array.isArray(parsed?.actions) && parsed.actions.length === 0 ? {} : parsed?.actions ?? {}, HOST_FILE);
415
462
  const functions = parsed?.functions;
416
463
  if (functions !== undefined && (!Array.isArray(functions) || functions.some((n) => typeof n !== "string"))) {
417
464
  throw new Error(`[rsc-kit] ${HOST_FILE}: "functions" must be an array of names.`);
@@ -424,7 +471,7 @@ function fileHostManifest(root) {
424
471
  return {
425
472
  types: isMap(parsed?.types) ? parsed.types : {},
426
473
  defs: isMap(parsed?.defs) ? parsed.defs : {},
427
- actions: actions,
474
+ actions,
428
475
  // The reserved guard call is the engine's to make, not the app's.
429
476
  functions: functions ? functions.filter((n) => !n.startsWith("__rsc.")).sort() : null,
430
477
  validates: validates ?? [],
@@ -770,7 +817,7 @@ function resolvePaths(options) {
770
817
  screenshots: foundAssets.screenshots.map((shot) => shot.href),
771
818
  };
772
819
  }
773
- loadHostManifest(options);
820
+ loadHostManifest(options, true);
774
821
  }
775
822
  /**
776
823
  * rsc-host.json as this process last read it, null when there was none. The
@@ -788,10 +835,22 @@ function hostFileOnDisk() {
788
835
  return null;
789
836
  }
790
837
  }
791
- function loadHostManifest(options) {
838
+ function loadHostManifest(options, before = false) {
792
839
  hostFileText = hostFileOnDisk();
793
- const manifest = fileHostManifest(projectRoot);
794
- hostActions = options.hostActions ?? manifest.actions;
840
+ let manifest;
841
+ try {
842
+ manifest = fileHostManifest(projectRoot);
843
+ }
844
+ catch (error) {
845
+ // Read as the plugin is made, before the backend's command has run: a
846
+ // file it is about to write over - the old shape, from before an
847
+ // upgrade - is not yet the backend's answer. The command's is, and is
848
+ // checked when it lands.
849
+ if (!before || !options.hostManifest)
850
+ throw error;
851
+ manifest = { actions: {}, functions: null, types: {}, defs: {}, validates: [] };
852
+ }
853
+ hostActions = options.hostActions ? checkHostActions(options.hostActions, "rscKit({ hostActions })") : manifest.actions;
795
854
  hostFunctions = manifest.functions;
796
855
  hostTypes = manifest.types;
797
856
  hostDefs = manifest.defs;
@@ -1182,15 +1241,45 @@ function writeHostBindings(manifest) {
1182
1241
  // which typechecks a server and fails a prerender script.
1183
1242
  writeGenerated(join(typesDir, "rsc-engine.d.ts"), ENGINE_TYPES);
1184
1243
  warnIfTypesUnreachable();
1185
- const target = join(sourceDir, HOST_ACTIONS_MODULE);
1186
- // A host with no functions of its own leaves no file behind: kept, its
1187
- // stubs would go on naming targets the host has stopped answering for.
1188
- if (Object.keys(hostActions).length === 0) {
1189
- if (existsSync(target))
1190
- rmSync(target);
1191
- return;
1244
+ writeHostActions();
1245
+ }
1246
+ /**
1247
+ * One "use server" module per backend class, under server-actions/. A module
1248
+ * the backend no longer has is removed - kept, its stubs would go on naming
1249
+ * targets the host has stopped answering for - and so is the single module
1250
+ * the build wrote before. Only files the build wrote: anything else in the
1251
+ * folder is the app's, and is left alone or, in the way, named.
1252
+ */
1253
+ function writeHostActions() {
1254
+ const dir = join(sourceDir, HOST_ACTIONS_DIR);
1255
+ const wanted = new Map(Object.keys(hostActions).map((module) => [join(dir, module + ".ts"), module]));
1256
+ const ours = (file) => readFileSync(file, "utf-8").slice(0, 200).includes("@generated");
1257
+ const flat = join(sourceDir, "server-actions.generated.ts");
1258
+ if (existsSync(flat) && ours(flat))
1259
+ rmSync(flat);
1260
+ for (const file of tsFilesUnder(dir)) {
1261
+ if (wanted.has(file) || !ours(file))
1262
+ continue;
1263
+ rmSync(file);
1264
+ }
1265
+ for (const [file, module] of wanted) {
1266
+ if (existsSync(file) && !ours(file)) {
1267
+ throw new Error(`[rsc-kit] ${relative(projectRoot, file)} is the app's, and the backend's ${module} actions are written there. ` +
1268
+ `${HOST_ACTIONS_DIR}/ is the build's: move the file out of it.`);
1269
+ }
1270
+ mkdirSync(dirname(file), { recursive: true });
1271
+ writeGenerated(file, renderHostActions(module));
1272
+ }
1273
+ // Folders a removed module leaves empty, deepest first.
1274
+ if (existsSync(dir)) {
1275
+ const folders = readdirSync(dir, { recursive: true, encoding: "utf-8" })
1276
+ .map((f) => join(dir, f))
1277
+ .filter((f) => statSync(f).isDirectory())
1278
+ .sort((a, b) => b.length - a.length);
1279
+ for (const folder of [...folders, dir])
1280
+ if (readdirSync(folder).length === 0)
1281
+ rmSync(folder, { recursive: true });
1192
1282
  }
1193
- writeGenerated(target, renderHostActions());
1194
1283
  }
1195
1284
  /**
1196
1285
  * The generated engine bundle, as the type its callers expect.
@@ -2226,7 +2315,7 @@ async function prerenderAfterBundles(bundle, staticDir, assetsDir, knownActions
2226
2315
  // on who calls it runs there - Laravel's guards, Go's middleware - where
2227
2316
  // this build cannot see it. Counted, they made every backend action look
2228
2317
  // unguarded: "11 actions run no middleware" for an API that checks them all.
2229
- const bare = audited.filter((a) => !a.client && basename(a.file) !== HOST_ACTIONS_MODULE);
2318
+ const bare = audited.filter((a) => !a.client && !/(^|[\\/])server-actions[\\/]/.test(a.file));
2230
2319
  if (bare.length > 0) {
2231
2320
  const byFile = new Map();
2232
2321
  for (const a of bare)
@@ -2767,19 +2856,34 @@ const FORM_ARGS = `function formArgs(args: unknown[], schemas: (Record<string, a
2767
2856
  return [...args.slice(0, at), out]
2768
2857
  }
2769
2858
  `;
2770
- /** The "use server" module exposing each host function as a plain async call. */
2771
- function renderHostActions() {
2772
- const lines = [
2773
- '"use server";',
2774
- "// @generated — do not edit. Written by the RSC build from the host action map.",
2775
- "",
2776
- ];
2859
+ /**
2860
+ * One class's "use server" module: each host function a plain async call. An
2861
+ * __invoke is the default export, and a method JavaScript reserves the name
2862
+ * of - delete, new - is declared under another and exported under its own.
2863
+ */
2864
+ function renderHostActions(module) {
2865
+ const lines = [HOST_ACTIONS_HEADER, '"use server";', ""];
2866
+ const exportsOf = hostActions[module] ?? {};
2867
+ const taken = new Set(Object.keys(exportsOf));
2868
+ const renamed = [];
2777
2869
  // Type-only, so the module stays what "use server" allows: functions.
2778
2870
  lines.push('import type { Redirected } from "@rsc-kit/core/errors";');
2779
2871
  lines.push('import type { FormFields } from "@rsc-kit/core/form";', "");
2780
2872
  lines.push(FORM_ARGS);
2781
- for (const [name, target] of Object.entries(hostActions)) {
2873
+ for (const [exported, target] of Object.entries(exportsOf)) {
2782
2874
  const sig = hostTypes[target];
2875
+ // The default's own name is the module's - send-invite, sendInvite - so a
2876
+ // stack trace says which action it was.
2877
+ const own = exported === "default" ? module.split("/").pop().replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase()) : exported;
2878
+ const plain = exported !== "default" && !JS_RESERVED.has(exported);
2879
+ let name = own;
2880
+ if (!plain) {
2881
+ while (JS_RESERVED.has(name) || taken.has(name))
2882
+ name = "_" + name;
2883
+ taken.add(name);
2884
+ renamed.push(name + " as " + exported);
2885
+ }
2886
+ const declare = plain ? "export async function " : "async function ";
2783
2887
  // Typed where the backend described it: its own parameters, or the form
2784
2888
  // that posts to it, and what it returns. Untyped otherwise, as before.
2785
2889
  if (sig) {
@@ -2788,16 +2892,16 @@ function renderHostActions() {
2788
2892
  // with where the visitor is going. A type that said T let callers read
2789
2893
  // it as data.
2790
2894
  const result = "Promise<" + (sig.result ? tsOf(sig.result) : "void") + " | Redirected>";
2791
- lines.push("export async function " + name + "(" + tsParams(sig) + "): " + result + ";");
2895
+ lines.push(declare + name + "(" + tsParams(sig) + "): " + result + ";");
2792
2896
  // The form overload is last, which is the one `stub.bind(null, team)`
2793
2897
  // reads: bound, it is `(form: FormFields<…>) => …`, so a form's action
2794
2898
  // keeps the struct's field names. Leading parameters are the ones the
2795
2899
  // form does not fill; any after the struct are left to the backend.
2796
2900
  const at = formParam(sig);
2797
2901
  const leading = at > 0 ? sig.params.slice(0, at).map((p, i) => "arg" + (i + 1) + ": " + tsOf(p)) : [];
2798
- lines.push("export async function " + name + "(" + [...leading, "form: " + formType(sig)].join(", ") + "): " + result + ";");
2902
+ lines.push(declare + name + "(" + [...leading, "form: " + formType(sig)].join(", ") + "): " + result + ";");
2799
2903
  }
2800
- lines.push("export async function " + name + "(...args: unknown[]) {");
2904
+ lines.push(declare + name + "(...args: unknown[]) {");
2801
2905
  lines.push(" return await (globalThis as any)." +
2802
2906
  hostGlobal +
2803
2907
  "(" +
@@ -2808,6 +2912,8 @@ function renderHostActions() {
2808
2912
  lines.push("}");
2809
2913
  lines.push("");
2810
2914
  }
2915
+ if (renamed.length > 0)
2916
+ lines.push("export { " + renamed.join(", ") + " };", "");
2811
2917
  return lines.join("\n");
2812
2918
  }
2813
2919
  /** Ambient declaration for the host global, written beside the app's source. */
@@ -3797,11 +3903,11 @@ import { SlotBoundary } from ${JSON.stringify(join(packageDir, "js/SlotBoundary"
3797
3903
  import { RouteErrorBoundary } from ${JSON.stringify(join(packageDir, "js/RouteErrorBoundary"))}
3798
3904
  import __rsc_assets from 'virtual:vite-rsc/assets-manifest'
3799
3905
  ${
3800
- // The backend's actions, so defineBlueprint({ actions: { create: contactSend } }) can tell
3906
+ // The backend's actions, so defineBlueprint({ actions: { create: contact.send } }) can tell
3801
3907
  // which backend function a stub calls: the stub is the key, by identity.
3802
- Object.keys(hostActions).length > 0
3803
- ? `import * as __rsc_host_actions from ${JSON.stringify(join(sourceDir, HOST_ACTIONS_MODULE))}\n`
3804
- : ""}import { isSharedSection, sectionComponent } from ${JSON.stringify(join(packageDir, "js/section"))}
3908
+ Object.keys(hostActions)
3909
+ .map((module, i) => `import * as __rsc_host_actions_${i} from ${JSON.stringify(join(sourceDir, HOST_ACTIONS_DIR, module + ".ts"))}\n`)
3910
+ .join("")}import { isSharedSection, sectionComponent } from ${JSON.stringify(join(packageDir, "js/section"))}
3805
3911
  import { shareRender } from ${JSON.stringify(join(packageDir, "sharedRenders"))}
3806
3912
  import { PathnameProvider } from ${JSON.stringify(join(packageDir, "js/PathnameProvider"))}
3807
3913
  import { DefaultRouteError } from ${JSON.stringify(join(packageDir, "js/DefaultRouteError"))}
@@ -4206,7 +4312,11 @@ const HOST_GLOBAL = ${JSON.stringify(hostGlobal)}
4206
4312
  // which time this entry has run.
4207
4313
  ;(globalThis as Record<symbol, unknown>)[Symbol.for('rsc-kit.host-forms')] = {
4208
4314
  actions: new Map<unknown, string>(${Object.keys(hostActions).length > 0
4209
- ? `Object.entries(${JSON.stringify(hostActions)}).map(([name, target]) => [(__rsc_host_actions as Record<string, unknown>)[name], target])`
4315
+ ? "[" +
4316
+ Object.entries(hostActions)
4317
+ .flatMap(([, exports], i) => Object.entries(exports).map(([name, target]) => `[__rsc_host_actions_${i}[${JSON.stringify(name)}], ${JSON.stringify(target)}]`))
4318
+ .join(", ") +
4319
+ "]"
4210
4320
  : ""}),
4211
4321
  inputs: ${JSON.stringify(formInputs(hostTypes, hostDefs))},
4212
4322
  // Which of them the backend can check without running - see checkOnly().
@@ -7812,16 +7922,16 @@ export const SERVER_ONLY = {
7812
7922
  "js/section": "section",
7813
7923
  "js/refreshOn": "section",
7814
7924
  host: "host",
7815
- hostCalls: "host-calls",
7925
+ hostCalls: "adapter/host-calls",
7816
7926
  commands: "commands",
7817
7927
  prerender: "prerender",
7818
7928
  export: "export",
7819
7929
  files: "files",
7820
- "build-rsc-vite": "build",
7821
- runtime: "runtime",
7930
+ "build-rsc-vite": "internal/build",
7931
+ runtime: "internal/runtime",
7822
7932
  embed: "embed",
7823
- typegen: "typegen",
7824
- conformance: "conformance",
7933
+ typegen: "internal/typegen",
7934
+ conformance: "adapter/conformance",
7825
7935
  testing: "testing",
7826
7936
  vite: "vite",
7827
7937
  };
@@ -8247,10 +8357,14 @@ export function rscKit(options = {}) {
8247
8357
  ? { version: PACKAGE_VERSION, output: "export", dir: relative(projectRoot, exportPath) }
8248
8358
  : { version: PACKAGE_VERSION, output: "server", ...compileStep(projectRoot) };
8249
8359
  },
8360
+ /** Where the app's source is: forms/ and server-actions/ are under it. */
8361
+ sourceDir() {
8362
+ return sourceDir;
8363
+ },
8250
8364
  generatedFiles() {
8251
8365
  return [
8252
8366
  join(projectRoot, HOST_FILE),
8253
- join(sourceDir, HOST_ACTIONS_MODULE),
8367
+ ...tsFilesUnder(join(sourceDir, HOST_ACTIONS_DIR)),
8254
8368
  // The type declarations only: the folder also holds the build's
8255
8369
  // own output - the route table, its report, the server entries -
8256
8370
  // which nobody commits and --check has no business comparing.