@farm.js/plugin 0.1.0-beta.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.
Files changed (51) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +11 -0
  3. package/dist/api/index.d.ts +42 -0
  4. package/dist/api/index.d.ts.map +1 -0
  5. package/dist/api/index.js +567 -0
  6. package/dist/context/index.d.ts +61 -0
  7. package/dist/context/index.d.ts.map +1 -0
  8. package/dist/context/index.js +75 -0
  9. package/dist/index.d.ts +43 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +49 -0
  12. package/dist/middleware/index.d.ts +97 -0
  13. package/dist/middleware/index.d.ts.map +1 -0
  14. package/dist/middleware/index.js +469 -0
  15. package/dist/observability/index.d.ts +190 -0
  16. package/dist/observability/index.d.ts.map +1 -0
  17. package/dist/observability/index.js +399 -0
  18. package/dist/rsc/build-paths.d.ts +3 -0
  19. package/dist/rsc/build-paths.d.ts.map +1 -0
  20. package/dist/rsc/build-paths.js +8 -0
  21. package/dist/rsc/entries/client.d.ts +14 -0
  22. package/dist/rsc/entries/client.d.ts.map +1 -0
  23. package/dist/rsc/entries/client.js +283 -0
  24. package/dist/rsc/entries/rsc.d.ts +13 -0
  25. package/dist/rsc/entries/rsc.d.ts.map +1 -0
  26. package/dist/rsc/entries/rsc.js +932 -0
  27. package/dist/rsc/entries/ssr.d.ts +13 -0
  28. package/dist/rsc/entries/ssr.d.ts.map +1 -0
  29. package/dist/rsc/entries/ssr.js +245 -0
  30. package/dist/rsc/index.d.ts +78 -0
  31. package/dist/rsc/index.d.ts.map +1 -0
  32. package/dist/rsc/index.js +1368 -0
  33. package/dist/rsc/nitro-build.d.ts +36 -0
  34. package/dist/rsc/nitro-build.d.ts.map +1 -0
  35. package/dist/rsc/nitro-build.js +396 -0
  36. package/dist/rsc/optimized-boundary.d.ts +20 -0
  37. package/dist/rsc/optimized-boundary.d.ts.map +1 -0
  38. package/dist/rsc/optimized-boundary.js +15 -0
  39. package/dist/rsc/server-fn-transform.d.ts +6 -0
  40. package/dist/rsc/server-fn-transform.d.ts.map +1 -0
  41. package/dist/rsc/server-fn-transform.js +152 -0
  42. package/dist/rsc/types.d.ts +123 -0
  43. package/dist/rsc/types.d.ts.map +1 -0
  44. package/dist/rsc/types.js +1 -0
  45. package/dist/rsc/vite-plugin-nitro.d.ts +33 -0
  46. package/dist/rsc/vite-plugin-nitro.d.ts.map +1 -0
  47. package/dist/rsc/vite-plugin-nitro.js +163 -0
  48. package/package.json +94 -0
  49. package/scripts/build.js +7 -0
  50. package/scripts/clean.js +6 -0
  51. package/scripts/run-nitro.mjs +18 -0
@@ -0,0 +1,123 @@
1
+ import type { FarmServerActionsConfig, ResolvedFarmServerActionsConfig } from "@farm.js/core/server-action-security";
2
+ /**
3
+ * Configuration options for the Farm.js RSC plugin.
4
+ */
5
+ export interface FarmRscPluginOptions {
6
+ /** Security policy applied to server action requests. */
7
+ serverActions?: FarmServerActionsConfig;
8
+ /** Build identifier used to reject requests from stale browser deployments. */
9
+ deploymentId?: string;
10
+ /**
11
+ * Override the auto-generated virtual entries with custom files.
12
+ * If not provided, virtual entries are generated automatically based on
13
+ * the user's project structure.
14
+ */
15
+ entries?: {
16
+ /** Custom RSC environment entry file */
17
+ rsc?: string;
18
+ /** Custom SSR environment entry file */
19
+ ssr?: string;
20
+ /** Custom client environment entry file */
21
+ client?: string;
22
+ };
23
+ /**
24
+ * Enable encryption for server action bound arguments.
25
+ * This prevents exposing sensitive closure data in the client bundle.
26
+ * @default true
27
+ */
28
+ encryptActions?: boolean;
29
+ /**
30
+ * Subdirectory within srcDir containing route files.
31
+ * If empty, routes are discovered directly in srcDir.
32
+ * @default 'app'
33
+ */
34
+ routesDir?: string;
35
+ /**
36
+ * Custom CSS injection function.
37
+ * If not provided, uses import.meta.viteRsc.loadCss().
38
+ */
39
+ cssLoader?: string;
40
+ /**
41
+ * Enable verbose logging for debugging.
42
+ * @default false
43
+ */
44
+ debug?: boolean;
45
+ }
46
+ /**
47
+ * Internal context passed to entry generators.
48
+ * Contains resolved configuration values needed to generate entry files.
49
+ */
50
+ export interface EntryContext {
51
+ /** User's source directory, e.g. 'src' */
52
+ srcDir: string;
53
+ /** Build output directory, e.g. 'dist' */
54
+ outDir: string;
55
+ /** Base URL path, e.g. '/' */
56
+ basePath: string;
57
+ /** Route files subdirectory within srcDir */
58
+ routesDir?: string;
59
+ /** Root-relative Vite URL for an existing global stylesheet. */
60
+ globalCssPath?: string;
61
+ /** Ordered route roots. Modules from later roots override matching earlier modules. */
62
+ routeRoots?: Array<{
63
+ name: string;
64
+ base: string;
65
+ glob: string;
66
+ }>;
67
+ /** Whether server actions are enabled */
68
+ actionsEnabled: boolean;
69
+ /** Normalized server action request security policy. */
70
+ serverActions: ResolvedFarmServerActionsConfig;
71
+ /** Resolved build identifier embedded into the server and browser entries. */
72
+ deploymentId: string;
73
+ /** Whether debug mode is enabled */
74
+ debug: boolean;
75
+ }
76
+ /**
77
+ * Matched route information from the file-based router.
78
+ */
79
+ export interface MatchedRoute {
80
+ /** The page component's default export */
81
+ Page: React.ComponentType<any>;
82
+ /** The file pattern that matched, e.g. '/src/about/page.tsx' */
83
+ pattern: string;
84
+ /** Dynamic route parameters, e.g. { slug: 'my-post' } */
85
+ params: Record<string, string>;
86
+ }
87
+ /**
88
+ * RSC payload structure sent from server to client.
89
+ */
90
+ export interface RscPayload {
91
+ /** The root React element tree (full document for SSR) */
92
+ root: React.ReactElement;
93
+ /** Content for div#root only (for client hydration to avoid double/repeated content) */
94
+ rootContent?: React.ReactElement;
95
+ /** Serializable document metadata used during client-side navigation. */
96
+ metadata?: {
97
+ title?: string;
98
+ description?: string;
99
+ };
100
+ /** Server action return value (if action was executed) */
101
+ returnValue?: {
102
+ ok: boolean;
103
+ data: unknown;
104
+ };
105
+ /** Form state for progressive enhancement */
106
+ formState?: unknown;
107
+ }
108
+ /**
109
+ * Vite RSC module augmentation for import.meta.
110
+ */
111
+ declare global {
112
+ interface ImportMeta {
113
+ readonly viteRsc: {
114
+ /** Load CSS for server components */
115
+ loadCss(): React.ReactElement[];
116
+ /** Load a module from another environment */
117
+ loadModule<T = unknown>(env: string, entry: string): Promise<T>;
118
+ /** Load bootstrap script content for hydration */
119
+ loadBootstrapScriptContent(entry: string): Promise<string>;
120
+ };
121
+ }
122
+ }
123
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/rsc/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,+BAA+B,EAChC,MAAM,sCAAsC,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,yDAAyD;IACzD,aAAa,CAAC,EAAE,uBAAuB,CAAC;IAExC,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,wCAAwC;QACxC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,wCAAwC;QACxC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,2CAA2C;QAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IAEf,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IAEf,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IAEjB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,uFAAuF;IACvF,UAAU,CAAC,EAAE,KAAK,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IAEH,yCAAyC;IACzC,cAAc,EAAE,OAAO,CAAC;IAExB,wDAAwD;IACxD,aAAa,EAAE,+BAA+B,CAAC;IAE/C,8EAA8E;IAC9E,YAAY,EAAE,MAAM,CAAC;IAErB,oCAAoC;IACpC,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAE/B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAEhB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0DAA0D;IAC1D,IAAI,EAAE,KAAK,CAAC,YAAY,CAAC;IAEzB,wFAAwF;IACxF,WAAW,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAEjC,yEAAyE;IACzE,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IAEF,0DAA0D;IAC1D,WAAW,CAAC,EAAE;QACZ,EAAE,EAAE,OAAO,CAAC;QACZ,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IAEF,6CAA6C;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB,QAAQ,CAAC,OAAO,EAAE;YAChB,qCAAqC;YACrC,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YAEhC,6CAA6C;YAC7C,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAEhE,kDAAkD;YAClD,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC5D,CAAC;KACH;CACF"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Vite plugin to run Nitro after RSC build (single "vite build", no post script).
3
+ * Implements the Nitro RSC deployment pipeline:
4
+ * - Step 1: Force per-environment output dirs to .nitro/vite/dist/${name} so Nitro can locate artifacts.
5
+ * - Step 2: Capture the server (RSC) Rollup bundle in writeBundle.
6
+ * - Step 3: Find the SSR entry chunk from the bundle.
7
+ * - Step 4: Compute renderer path and pass to Nitro with client publicDir.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import nitro from '@farm.js/plugin/rsc/vite-plugin-nitro'
12
+ * export default defineConfig({
13
+ * plugins: [rsc(), react(), nitro({ server: { environmentName: 'rsc' }, config: { preset: 'vercel' } })],
14
+ * })
15
+ * ```
16
+ */
17
+ import type { Plugin } from "vite";
18
+ export interface NitroPluginOptions {
19
+ server?: {
20
+ environmentName?: string;
21
+ /** Entry name in rollupOptions.input (default: 'index'). */
22
+ entryName?: string;
23
+ };
24
+ config?: {
25
+ preset?: string;
26
+ };
27
+ /** Base output dir when not using .nitro/vite/dist (fallback). */
28
+ outDir?: string;
29
+ }
30
+ export default function nitro(options?: NitroPluginOptions): Plugin;
31
+ /** Called by RSC plugin buildApp (post) to run Nitro with the captured bundle. */
32
+ export declare function runNitroFromBuildApp(): Promise<void>;
33
+ //# sourceMappingURL=vite-plugin-nitro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-nitro.d.ts","sourceRoot":"","sources":["../../src/rsc/vite-plugin-nitro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAenC,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE;QACP,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,4DAA4D;QAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAWD,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAoHtE;AAED,kFAAkF;AAClF,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CA+C1D"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Vite plugin to run Nitro after RSC build (single "vite build", no post script).
3
+ * Implements the Nitro RSC deployment pipeline:
4
+ * - Step 1: Force per-environment output dirs to .nitro/vite/dist/${name} so Nitro can locate artifacts.
5
+ * - Step 2: Capture the server (RSC) Rollup bundle in writeBundle.
6
+ * - Step 3: Find the SSR entry chunk from the bundle.
7
+ * - Step 4: Compute renderer path and pass to Nitro with client publicDir.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import nitro from '@farm.js/plugin/rsc/vite-plugin-nitro'
12
+ * export default defineConfig({
13
+ * plugins: [rsc(), react(), nitro({ server: { environmentName: 'rsc' }, config: { preset: 'vercel' } })],
14
+ * })
15
+ * ```
16
+ */
17
+ import path from "path";
18
+ import { buildRscNitro } from "./nitro-build.js";
19
+ import { waitForRscOutputs } from "./nitro-build.js";
20
+ import { resolveRscBuildOutputPath } from "./build-paths.js";
21
+ let nitroRunScheduled = false;
22
+ /** Stored RSC (server) bundle from writeBundle so we can find the entry chunk. */
23
+ let serverBundle = null;
24
+ const NITRO_VITE_DIST = ".nitro/vite/dist";
25
+ export default function nitro(options = {}) {
26
+ const serverEnvName = options.server?.environmentName ?? "rsc";
27
+ const serverEntryName = options.server?.entryName ?? "index";
28
+ let resolvedRoot = process.cwd();
29
+ let rscOutDir = path.join(NITRO_VITE_DIST, "rsc");
30
+ let ssrOutDir = path.join(NITRO_VITE_DIST, "ssr");
31
+ let clientOutDir = path.join(NITRO_VITE_DIST, "client");
32
+ let baseOutDir = NITRO_VITE_DIST;
33
+ return {
34
+ name: "vite-plugin-nitro",
35
+ apply: "build",
36
+ // Step 1: Force per-environment output dirs so Nitro can locate artifacts.
37
+ config() {
38
+ return {
39
+ environments: {
40
+ rsc: { build: { outDir: path.join(NITRO_VITE_DIST, "rsc") } },
41
+ ssr: { build: { outDir: path.join(NITRO_VITE_DIST, "ssr") } },
42
+ client: { build: { outDir: path.join(NITRO_VITE_DIST, "client") } },
43
+ },
44
+ };
45
+ },
46
+ configResolved(config) {
47
+ resolvedRoot = path.resolve(config.root ?? process.cwd());
48
+ const envs = config.environments;
49
+ if (envs?.rsc?.build?.outDir && envs?.ssr?.build?.outDir && envs?.client?.build?.outDir) {
50
+ rscOutDir = envs.rsc.build.outDir;
51
+ ssrOutDir = envs.ssr.build.outDir;
52
+ clientOutDir = envs.client.build.outDir;
53
+ const dir = path.dirname(rscOutDir);
54
+ baseOutDir = path.isAbsolute(dir) ? path.relative(resolvedRoot, dir) || "." : dir;
55
+ }
56
+ else {
57
+ baseOutDir = options.outDir ?? "dist";
58
+ rscOutDir = path.join(baseOutDir, "rsc");
59
+ ssrOutDir = path.join(baseOutDir, "ssr");
60
+ clientOutDir = path.join(baseOutDir, "client");
61
+ }
62
+ },
63
+ // Step 2: Capture the server (RSC) Rollup bundle when that environment writes.
64
+ writeBundle(_options, bundle) {
65
+ if (this.environment?.name === serverEnvName) {
66
+ serverBundle = bundle;
67
+ globalThis.__FARM_NITRO_SERVER_BUNDLE = bundle;
68
+ globalThis.__FARM_NITRO_PATHS = {
69
+ root: resolvedRoot,
70
+ rscOutDir,
71
+ ssrOutDir,
72
+ clientOutDir,
73
+ serverEntryName,
74
+ preset: options.config?.preset ?? process.env.NITRO_PRESET ?? "vercel",
75
+ };
76
+ }
77
+ },
78
+ // Run Nitro once all env outputs exist (after step 5). buildEnd runs after each env; only run when all exist.
79
+ async buildEnd() {
80
+ if (nitroRunScheduled)
81
+ return;
82
+ const root = path.resolve(resolvedRoot);
83
+ const { existsSync } = await import("fs");
84
+ await new Promise((r) => setTimeout(r, 800));
85
+ const baseOutDir = rscOutDir.includes(".nitro/vite/dist")
86
+ ? NITRO_VITE_DIST
87
+ : path.isAbsolute(path.dirname(rscOutDir))
88
+ ? path.relative(root, path.dirname(rscOutDir)) || "."
89
+ : path.dirname(rscOutDir);
90
+ const rscOk = existsSync(resolveRscBuildOutputPath(root, baseOutDir, "rsc", "index.js"));
91
+ const ssrOk = existsSync(resolveRscBuildOutputPath(root, baseOutDir, "ssr", "index.js"));
92
+ const clientOk = existsSync(resolveRscBuildOutputPath(root, baseOutDir, "client", "assets"));
93
+ if (!rscOk || !ssrOk || !clientOk)
94
+ return;
95
+ nitroRunScheduled = true;
96
+ const preset = options.config?.preset ?? process.env.NITRO_PRESET ?? "vercel";
97
+ const run = async () => {
98
+ await waitForRscOutputs(root, baseOutDir, { timeoutMs: 20_000 }).catch(() => {
99
+ // Outputs already verified; proceed (nitro-build stubs manifest if missing)
100
+ });
101
+ let rendererPath = resolveRscBuildOutputPath(root, rscOutDir, "index.js");
102
+ if (serverBundle) {
103
+ const serverEntryChunks = [];
104
+ for (const chunk of Object.values(serverBundle)) {
105
+ if (chunk.type === "chunk" && chunk.isEntry && chunk.fileName) {
106
+ serverEntryChunks.push(chunk);
107
+ }
108
+ }
109
+ const selected = serverEntryName
110
+ ? serverEntryChunks.find((c) => (c.name ?? c.fileName) === serverEntryName)
111
+ : serverEntryChunks[0];
112
+ if (selected?.fileName) {
113
+ rendererPath = resolveRscBuildOutputPath(root, rscOutDir, selected.fileName);
114
+ }
115
+ }
116
+ await buildRscNitro({
117
+ root,
118
+ rendererPath,
119
+ publicDir: resolveRscBuildOutputPath(root, clientOutDir),
120
+ ssrPath: resolveRscBuildOutputPath(root, ssrOutDir, "index.js"),
121
+ assetsDir: undefined,
122
+ preset,
123
+ });
124
+ globalThis.__FARM_NITRO_PLUGIN_RAN = true;
125
+ };
126
+ await run();
127
+ },
128
+ };
129
+ }
130
+ /** Called by RSC plugin buildApp (post) to run Nitro with the captured bundle. */
131
+ export async function runNitroFromBuildApp() {
132
+ const paths = globalThis.__FARM_NITRO_PATHS;
133
+ const bundle = globalThis.__FARM_NITRO_SERVER_BUNDLE;
134
+ if (!paths)
135
+ return;
136
+ const root = paths.root;
137
+ const preset = paths.preset;
138
+ const baseOutDir = path.dirname(paths.rscOutDir);
139
+ await waitForRscOutputs(root, baseOutDir, { timeoutMs: 25_000 });
140
+ let rendererPath = resolveRscBuildOutputPath(root, paths.rscOutDir, "index.js");
141
+ if (bundle) {
142
+ const serverEntryChunks = [];
143
+ for (const chunk of Object.values(bundle)) {
144
+ if (chunk.type === "chunk" && chunk.isEntry && chunk.fileName) {
145
+ serverEntryChunks.push(chunk);
146
+ }
147
+ }
148
+ const selected = paths.serverEntryName
149
+ ? serverEntryChunks.find((c) => (c.name ?? c.fileName) === paths.serverEntryName)
150
+ : serverEntryChunks[0];
151
+ if (selected?.fileName) {
152
+ rendererPath = resolveRscBuildOutputPath(root, paths.rscOutDir, selected.fileName);
153
+ }
154
+ }
155
+ await buildRscNitro({
156
+ root,
157
+ rendererPath,
158
+ publicDir: resolveRscBuildOutputPath(root, paths.clientOutDir),
159
+ ssrPath: resolveRscBuildOutputPath(root, paths.ssrOutDir, "index.js"),
160
+ assetsDir: undefined,
161
+ preset,
162
+ });
163
+ }
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@farm.js/plugin",
3
+ "version": "0.1.0-beta.0",
4
+ "description": "Official plugins for Farm.js framework",
5
+ "license": "MIT",
6
+ "author": "Farm.js Team",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/farming-labs/farm.js",
10
+ "directory": "packages/farmjs-plugin"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "scripts"
15
+ ],
16
+ "type": "module",
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./rsc": {
26
+ "types": "./dist/rsc/index.d.ts",
27
+ "import": "./dist/rsc/index.js"
28
+ },
29
+ "./rsc/optimized-boundary": {
30
+ "types": "./dist/rsc/optimized-boundary.d.ts",
31
+ "import": "./dist/rsc/optimized-boundary.js"
32
+ },
33
+ "./rsc/vite-plugin-nitro": {
34
+ "types": "./dist/rsc/vite-plugin-nitro.d.ts",
35
+ "import": "./dist/rsc/vite-plugin-nitro.js"
36
+ },
37
+ "./middleware": {
38
+ "types": "./dist/middleware/index.d.ts",
39
+ "import": "./dist/middleware/index.js"
40
+ },
41
+ "./api": {
42
+ "types": "./dist/api/index.d.ts",
43
+ "import": "./dist/api/index.js"
44
+ },
45
+ "./observability": {
46
+ "types": "./dist/observability/index.d.ts",
47
+ "import": "./dist/observability/index.js"
48
+ },
49
+ "./context": {
50
+ "types": "./dist/context/index.d.ts",
51
+ "import": "./dist/context/index.js"
52
+ }
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "dependencies": {
58
+ "@farming-labs/strata": "0.1.2",
59
+ "better-call": "^1.0.19",
60
+ "es-module-lexer": "2.0.0",
61
+ "nitro": "3.0.1-alpha.0",
62
+ "picocolors": "^1.0.0",
63
+ "rsc-html-stream": "^0.0.4",
64
+ "@farm.js/core": "0.1.0-beta.0"
65
+ },
66
+ "devDependencies": {
67
+ "@types/node": "^20.19.21",
68
+ "@types/react": "^19.0.0",
69
+ "@types/react-dom": "^19.0.0",
70
+ "@vitejs/plugin-rsc": "^0.5.18",
71
+ "tsdown": "^0.15.7",
72
+ "typescript": "^5.5.3",
73
+ "vite": "^6.0.0",
74
+ "vitest": "^1.1.0"
75
+ },
76
+ "peerDependencies": {
77
+ "@vitejs/plugin-rsc": ">=0.5.0",
78
+ "react": ">=19.0.0",
79
+ "react-dom": ">=19.0.0",
80
+ "vite": ">=6.0.0",
81
+ "@farm.js/core": "0.1.0-beta.0"
82
+ },
83
+ "peerDependenciesMeta": {
84
+ "@vitejs/plugin-rsc": {
85
+ "optional": true
86
+ }
87
+ },
88
+ "scripts": {
89
+ "build": "node scripts/clean.js && tsc && node scripts/build.js",
90
+ "dev": "tsc --watch",
91
+ "typecheck": "tsc --noEmit",
92
+ "test": "vitest run"
93
+ }
94
+ }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ // The TypeScript compiler emits ESM with .js extensions.
3
+
4
+ console.log("Post-processing build output...");
5
+
6
+ // Nothing to do for now - TypeScript handles ESM output
7
+ console.log("Build complete!");
@@ -0,0 +1,6 @@
1
+ import { rmSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ const distDirectory = fileURLToPath(new URL("../dist", import.meta.url));
5
+
6
+ rmSync(distDirectory, { recursive: true, force: true });
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Run Nitro after Vite build. Use in package.json: "build": "vite build && node node_modules/@farm.js/plugin/scripts/run-nitro.mjs"
4
+ * Resolves from project root (cwd) so dist/ and .output are in the right place.
5
+ */
6
+ import path from "node:path";
7
+ import { buildRscNitro } from "../dist/rsc/nitro-build.js";
8
+
9
+ const root = process.cwd();
10
+ const outDir = process.env.RSC_OUT_DIR || "dist";
11
+
12
+ await buildRscNitro({
13
+ root,
14
+ rendererPath: path.join(root, outDir, "rsc", "index.js"),
15
+ publicDir: path.join(root, outDir, "client"),
16
+ ssrPath: path.join(root, outDir, "ssr", "index.js"),
17
+ preset: process.env.NITRO_PRESET || "vercel",
18
+ });