effective-rsc 0.1.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 (220) hide show
  1. package/LICENSE +21 -0
  2. package/LLMS.md +382 -0
  3. package/README.md +235 -0
  4. package/bin/ersc.js +3 -0
  5. package/dist/application/component.d.ts +15 -0
  6. package/dist/application/component.js +20 -0
  7. package/dist/application/component.js.map +1 -0
  8. package/dist/application/definition.d.ts +31 -0
  9. package/dist/application/definition.js +57 -0
  10. package/dist/application/definition.js.map +1 -0
  11. package/dist/application/ersc-identity.d.ts +25 -0
  12. package/dist/application/ersc-identity.js +23 -0
  13. package/dist/application/ersc-identity.js.map +1 -0
  14. package/dist/application/ersc.d.ts +28 -0
  15. package/dist/application/ersc.js +72 -0
  16. package/dist/application/ersc.js.map +1 -0
  17. package/dist/application/layout.d.ts +18 -0
  18. package/dist/application/layout.js +17 -0
  19. package/dist/application/layout.js.map +1 -0
  20. package/dist/application/loading.d.ts +17 -0
  21. package/dist/application/loading.js +14 -0
  22. package/dist/application/loading.js.map +1 -0
  23. package/dist/application/middleware.d.ts +36 -0
  24. package/dist/application/middleware.js +46 -0
  25. package/dist/application/middleware.js.map +1 -0
  26. package/dist/application/page.d.ts +58 -0
  27. package/dist/application/page.js +50 -0
  28. package/dist/application/page.js.map +1 -0
  29. package/dist/application/render-runtime.d.ts +9 -0
  30. package/dist/application/render-runtime.js +28 -0
  31. package/dist/application/render-runtime.js.map +1 -0
  32. package/dist/application/route-graph.d.ts +22 -0
  33. package/dist/application/route-graph.js +68 -0
  34. package/dist/application/route-graph.js.map +1 -0
  35. package/dist/application/route-path.d.ts +31 -0
  36. package/dist/application/route-path.js +67 -0
  37. package/dist/application/route-path.js.map +1 -0
  38. package/dist/application/routes.d.ts +66 -0
  39. package/dist/application/routes.js +159 -0
  40. package/dist/application/routes.js.map +1 -0
  41. package/dist/application/server-fn.d.ts +30 -0
  42. package/dist/application/server-fn.js +58 -0
  43. package/dist/application/server-fn.js.map +1 -0
  44. package/dist/build/build.d.ts +26 -0
  45. package/dist/build/build.js +59 -0
  46. package/dist/build/build.js.map +1 -0
  47. package/dist/build/compiled-server.d.ts +53 -0
  48. package/dist/build/compiled-server.js +77 -0
  49. package/dist/build/compiled-server.js.map +1 -0
  50. package/dist/build/contract.d.ts +23 -0
  51. package/dist/build/contract.js +41 -0
  52. package/dist/build/contract.js.map +1 -0
  53. package/dist/build/dev-channel.d.ts +20 -0
  54. package/dist/build/dev-channel.js +71 -0
  55. package/dist/build/dev-channel.js.map +1 -0
  56. package/dist/build/dev.d.ts +41 -0
  57. package/dist/build/dev.js +186 -0
  58. package/dist/build/dev.js.map +1 -0
  59. package/dist/build/rsc-entry.d.ts +4 -0
  60. package/dist/build/rsc-entry.js +17 -0
  61. package/dist/build/rsc-entry.js.map +1 -0
  62. package/dist/build/rspack-config.d.ts +17 -0
  63. package/dist/build/rspack-config.js +259 -0
  64. package/dist/build/rspack-config.js.map +1 -0
  65. package/dist/build/rspack.d.ts +45 -0
  66. package/dist/build/rspack.js +231 -0
  67. package/dist/build/rspack.js.map +1 -0
  68. package/dist/build/terminal.d.ts +9 -0
  69. package/dist/build/terminal.js +17 -0
  70. package/dist/build/terminal.js.map +1 -0
  71. package/dist/cli.d.ts +14 -0
  72. package/dist/cli.js +116 -0
  73. package/dist/cli.js.map +1 -0
  74. package/dist/client/application.d.ts +2 -0
  75. package/dist/client/application.js +73 -0
  76. package/dist/client/application.js.map +1 -0
  77. package/dist/client/browser-capabilities.d.ts +9 -0
  78. package/dist/client/browser-capabilities.js +20 -0
  79. package/dist/client/browser-capabilities.js.map +1 -0
  80. package/dist/client/browser-effect-runner.d.ts +13 -0
  81. package/dist/client/browser-effect-runner.js +13 -0
  82. package/dist/client/browser-effect-runner.js.map +1 -0
  83. package/dist/client/browser-renderer.d.ts +70 -0
  84. package/dist/client/browser-renderer.js +159 -0
  85. package/dist/client/browser-renderer.js.map +1 -0
  86. package/dist/client/browser-screen.d.ts +2 -0
  87. package/dist/client/browser-screen.js +215 -0
  88. package/dist/client/browser-screen.js.map +1 -0
  89. package/dist/client/call-server.d.ts +8 -0
  90. package/dist/client/call-server.js +151 -0
  91. package/dist/client/call-server.js.map +1 -0
  92. package/dist/client/client-router.d.ts +6 -0
  93. package/dist/client/client-router.js +588 -0
  94. package/dist/client/client-router.js.map +1 -0
  95. package/dist/client/entry.d.ts +1 -0
  96. package/dist/client/entry.js +12 -0
  97. package/dist/client/entry.js.map +1 -0
  98. package/dist/client/flight-client.d.ts +83 -0
  99. package/dist/client/flight-client.js +146 -0
  100. package/dist/client/flight-client.js.map +1 -0
  101. package/dist/client/initial-flight-stream.d.ts +18 -0
  102. package/dist/client/initial-flight-stream.js +60 -0
  103. package/dist/client/initial-flight-stream.js.map +1 -0
  104. package/dist/client/navigation-api.d.ts +34 -0
  105. package/dist/client/navigation-api.js +25 -0
  106. package/dist/client/navigation-api.js.map +1 -0
  107. package/dist/client/navigation-routing.d.ts +3 -0
  108. package/dist/client/navigation-routing.js +8 -0
  109. package/dist/client/navigation-routing.js.map +1 -0
  110. package/dist/client/react-dom-renderer.d.ts +20 -0
  111. package/dist/client/react-dom-renderer.js +101 -0
  112. package/dist/client/react-dom-renderer.js.map +1 -0
  113. package/dist/client/route-loader.d.ts +81 -0
  114. package/dist/client/route-loader.js +128 -0
  115. package/dist/client/route-loader.js.map +1 -0
  116. package/dist/client/route-refresh.d.ts +31 -0
  117. package/dist/client/route-refresh.js +132 -0
  118. package/dist/client/route-refresh.js.map +1 -0
  119. package/dist/client/route-tree.d.ts +7 -0
  120. package/dist/client/route-tree.js +34 -0
  121. package/dist/client/route-tree.js.map +1 -0
  122. package/dist/dev/channel.d.ts +18 -0
  123. package/dist/dev/channel.js +30 -0
  124. package/dist/dev/channel.js.map +1 -0
  125. package/dist/dev/client.d.ts +3 -0
  126. package/dist/dev/client.js +132 -0
  127. package/dist/dev/client.js.map +1 -0
  128. package/dist/dev/hmr-update.d.ts +20 -0
  129. package/dist/dev/hmr-update.js +28 -0
  130. package/dist/dev/hmr-update.js.map +1 -0
  131. package/dist/dev/panel.d.ts +41 -0
  132. package/dist/dev/panel.js +9946 -0
  133. package/dist/dev/panel.js.map +1 -0
  134. package/dist/dev/runtime-failure.d.ts +11 -0
  135. package/dist/dev/runtime-failure.js +32 -0
  136. package/dist/dev/runtime-failure.js.map +1 -0
  137. package/dist/index.d.ts +1 -0
  138. package/dist/index.js +6 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/rsc/flight.d.ts +16 -0
  141. package/dist/rsc/flight.js +6 -0
  142. package/dist/rsc/flight.js.map +1 -0
  143. package/dist/rsc/render-route-tree.d.ts +11 -0
  144. package/dist/rsc/render-route-tree.js +52 -0
  145. package/dist/rsc/render-route-tree.js.map +1 -0
  146. package/dist/rsc/route-tree.d.ts +6 -0
  147. package/dist/rsc/route-tree.js +5 -0
  148. package/dist/rsc/route-tree.js.map +1 -0
  149. package/dist/server/application.d.ts +17 -0
  150. package/dist/server/application.js +178 -0
  151. package/dist/server/application.js.map +1 -0
  152. package/dist/server/flight-html-stream.d.ts +19 -0
  153. package/dist/server/flight-html-stream.js +193 -0
  154. package/dist/server/flight-html-stream.js.map +1 -0
  155. package/dist/server/flight-renderer.d.ts +31 -0
  156. package/dist/server/flight-renderer.js +47 -0
  157. package/dist/server/flight-renderer.js.map +1 -0
  158. package/dist/server/html-renderer.d.ts +28 -0
  159. package/dist/server/html-renderer.js +82 -0
  160. package/dist/server/html-renderer.js.map +1 -0
  161. package/dist/server/request-outcome.d.ts +8 -0
  162. package/dist/server/request-outcome.js +5 -0
  163. package/dist/server/request-outcome.js.map +1 -0
  164. package/dist/server/server-config.d.ts +17 -0
  165. package/dist/server/server-config.js +18 -0
  166. package/dist/server/server-config.js.map +1 -0
  167. package/dist/server/server-fn-outcome.d.ts +13 -0
  168. package/dist/server/server-fn-outcome.js +24 -0
  169. package/dist/server/server-fn-outcome.js.map +1 -0
  170. package/dist/server/server-fn-request.d.ts +24 -0
  171. package/dist/server/server-fn-request.js +160 -0
  172. package/dist/server/server-fn-request.js.map +1 -0
  173. package/dist/unsupported.d.ts +0 -0
  174. package/dist/unsupported.js +5 -0
  175. package/dist/unsupported.js.map +1 -0
  176. package/docs/01-getting-started/01_first-application.tsx +26 -0
  177. package/docs/01-getting-started/20_styling.tsx +6 -0
  178. package/docs/01-getting-started/index.md +27 -0
  179. package/docs/01-getting-started/styles.css +1 -0
  180. package/docs/02-guides/01-server-functions/10_ersc.ts +6 -0
  181. package/docs/02-guides/01-server-functions/20_follow-author.ts +15 -0
  182. package/docs/02-guides/01-server-functions/30_follow-author-button.tsx +19 -0
  183. package/docs/02-guides/01-server-functions/40_application.tsx +30 -0
  184. package/docs/02-guides/01-server-functions/index.md +19 -0
  185. package/docs/02-guides/02-services/10_catalog.ts +22 -0
  186. package/docs/02-guides/02-services/20_application.tsx +44 -0
  187. package/docs/02-guides/02-services/index.md +17 -0
  188. package/docs/02-guides/03-routing/10_ersc.ts +6 -0
  189. package/docs/02-guides/03-routing/10_layouts.tsx +36 -0
  190. package/docs/02-guides/03-routing/20_pages.tsx +23 -0
  191. package/docs/02-guides/03-routing/30_routes.tsx +17 -0
  192. package/docs/02-guides/03-routing/40_application.ts +7 -0
  193. package/docs/02-guides/03-routing/index.md +22 -0
  194. package/docs/02-guides/04-middleware/10_auth.ts +27 -0
  195. package/docs/02-guides/04-middleware/20_account-page.tsx +13 -0
  196. package/docs/02-guides/04-middleware/30_update-profile.ts +16 -0
  197. package/docs/02-guides/04-middleware/40_application.tsx +20 -0
  198. package/docs/02-guides/04-middleware/index.md +25 -0
  199. package/docs/02-guides/05-http/10_application-layer.tsx +60 -0
  200. package/docs/02-guides/05-http/index.md +23 -0
  201. package/docs/02-guides/index.md +11 -0
  202. package/docs/03-advanced/01-request-runtime-and-lifetimes/index.md +13 -0
  203. package/docs/03-advanced/02-client-navigation/index.md +61 -0
  204. package/docs/03-advanced/03-server-function-execution-and-refresh/index.md +17 -0
  205. package/docs/03-advanced/index.md +11 -0
  206. package/docs/04-api-reference/01-application/index.md +8 -0
  207. package/docs/04-api-reference/02-page/index.md +12 -0
  208. package/docs/04-api-reference/03-layout/index.md +4 -0
  209. package/docs/04-api-reference/04-loading/index.md +4 -0
  210. package/docs/04-api-reference/05-component/10_component.tsx +18 -0
  211. package/docs/04-api-reference/05-component/index.md +10 -0
  212. package/docs/04-api-reference/06-middleware/index.md +33 -0
  213. package/docs/04-api-reference/07-routes/index.md +20 -0
  214. package/docs/04-api-reference/08-server-fn/index.md +43 -0
  215. package/docs/04-api-reference/index.md +17 -0
  216. package/docs/environment.d.ts +1 -0
  217. package/docs/index.md +15 -0
  218. package/logo-dark.svg +6 -0
  219. package/logo.svg +6 -0
  220. package/package.json +87 -0
@@ -0,0 +1,186 @@
1
+ import { Deferred, Effect, Fiber, FileSystem, Layer, Path, Ref, Schema, ScopedRef, Stream } from "effect";
2
+ import { HttpRouter, HttpServer } from "effect/unstable/http";
3
+ import package_0 from "../../package.json" with {"type":"json"};
4
+ import { DevChannelPath } from "../dev/channel.js";
5
+ import { resolveApplicationBuild } from "./build.js";
6
+ import { loadServerBundle, makeRunnableHttpLayer } from "./compiled-server.js";
7
+ import { DevOutputDir, EnvironmentConfig } from "./contract.js";
8
+ import { makeDevChannel } from "./dev-channel.js";
9
+ import { Rspack } from "./rspack.js";
10
+ import { makeRspackDevConfig } from "./rspack-config.js";
11
+ import { Terminal, formatDuration } from "./terminal.js";
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ class DevGenerationError extends Schema.TaggedError()('DevGenerationError', {
36
+ message: Schema.String,
37
+ cause: Schema.Defect()
38
+ }) {
39
+ }
40
+ const acquireDevGeneration = Effect.fnUntraced(function*({ compilation, hostname, port, root }) {
41
+ const path = yield* Path.Path;
42
+ const bundle = yield* loadServerBundle(path.resolve(compilation.serverBundle.outputPath, compilation.serverBundle.filename));
43
+ const HttpLayer = yield* makeRunnableHttpLayer({
44
+ bundle,
45
+ clientAssetsCacheControl: EnvironmentConfig.development.clientAssetsCacheControl,
46
+ clientOutputDir: EnvironmentConfig.development.clientOutputDir,
47
+ hostname,
48
+ port,
49
+ root
50
+ });
51
+ const httpEffect = yield* HttpRouter.toHttpEffect(HttpLayer).pipe(Effect.mapError((cause)=>new DevGenerationError({
52
+ message: `Failed to start development generation ${compilation.hash}.`,
53
+ cause
54
+ })));
55
+ return {
56
+ hash: compilation.hash,
57
+ httpEffect
58
+ };
59
+ });
60
+ const makeDevGenerationStore = Effect.fnUntraced(function*(options) {
61
+ const generation = yield* ScopedRef.make(()=>({
62
+ _tag: 'Unavailable'
63
+ }));
64
+ const initialCompilation = yield* Deferred.make();
65
+ const compilation = yield* Ref.make(initialCompilation);
66
+ const update = Effect.fnUntraced(function*(event) {
67
+ const current = yield* Ref.get(compilation);
68
+ switch(event._tag){
69
+ case 'Building':
70
+ {
71
+ const compilationCompleted = yield* Deferred.isDone(current);
72
+ if (compilationCompleted) {
73
+ const next = yield* Deferred.make();
74
+ yield* Ref.set(compilation, next);
75
+ }
76
+ return;
77
+ }
78
+ case 'Failed':
79
+ {
80
+ yield* Deferred.fail(current, event.error);
81
+ return;
82
+ }
83
+ case 'Compiled':
84
+ {
85
+ yield* ScopedRef.set(generation, acquireDevGeneration({
86
+ ...options,
87
+ compilation: event
88
+ }).pipe(Effect.map((ready)=>({
89
+ _tag: 'Ready',
90
+ generation: ready
91
+ })), Effect.tapError((error)=>Deferred.fail(current, error))));
92
+ const ready = yield* ScopedRef.get(generation);
93
+ if (ready._tag === 'Unavailable') {
94
+ return yield* Effect.die(new TypeError('Expected the completed development generation to be available.'));
95
+ }
96
+ yield* Deferred.succeed(current, ready.generation);
97
+ }
98
+ }
99
+ });
100
+ const httpEffect = Ref.get(compilation).pipe(Effect.flatMap(Deferred["await"]), Effect.flatMap((ready)=>ready.httpEffect));
101
+ return {
102
+ httpEffect,
103
+ update
104
+ };
105
+ });
106
+ const makeDevApplication = Effect.fnUntraced(function*({ hostname, port, root }) {
107
+ const { applicationRoot, entries } = yield* resolveApplicationBuild({
108
+ root
109
+ });
110
+ const fileSystem = yield* FileSystem.FileSystem;
111
+ const path = yield* Path.Path;
112
+ const rspack = yield* Rspack;
113
+ const channel = yield* makeDevChannel;
114
+ yield* fileSystem.remove(path.join(applicationRoot, DevOutputDir), {
115
+ force: true,
116
+ recursive: true
117
+ });
118
+ const generationStore = yield* makeDevGenerationStore({
119
+ hostname,
120
+ port,
121
+ root: applicationRoot
122
+ });
123
+ const update = Effect.fnUntraced(function*(event) {
124
+ switch(event._tag){
125
+ case 'Building':
126
+ {
127
+ yield* generationStore.update(event);
128
+ const firstChangedFile = event.changedFiles.find((file)=>path.basename(file).includes('.')) ?? event.changedFiles[0];
129
+ const changedPath = firstChangedFile === undefined ? undefined : path.relative(applicationRoot, firstChangedFile);
130
+ const subject = changedPath ?? 'application';
131
+ yield* Effect.logInfo(`${Terminal.cyan('●')} Compiling ${subject}...`);
132
+ return;
133
+ }
134
+ case 'Failed':
135
+ {
136
+ yield* generationStore.update(event);
137
+ yield* channel.publishBuildFailure(event.diagnostics);
138
+ yield* Effect.logError(event.error);
139
+ return;
140
+ }
141
+ case 'Compiled':
142
+ {
143
+ if (event.warnings !== undefined) {
144
+ yield* Effect.logWarning(event.warnings);
145
+ }
146
+ yield* generationStore.update(event).pipe(Effect.andThen(channel.publishCompilation(event.clientHash)), Effect.tap(()=>{
147
+ const duration = event.duration === undefined ? '' : ` in ${formatDuration(event.duration)}`;
148
+ const compilers = event.compilers.map(({ duration, name })=>duration === undefined ? name : `${name} ${formatDuration(duration)}`).join(' · ');
149
+ const details = compilers.length === 0 ? '' : ` ${Terminal.dim(compilers)}`;
150
+ return Effect.logInfo(`${Terminal.green('✓')} Ready${duration}${details}`);
151
+ }), Effect["catch"]((error)=>Effect.logError(error)));
152
+ }
153
+ }
154
+ });
155
+ const watch = rspack.watch(makeRspackDevConfig(applicationRoot, entries, {
156
+ onCompilationStart: channel.onCompilationStart,
157
+ onServerComponentChanges: channel.onServerComponentChanges
158
+ })).pipe(Stream.runForEach(update));
159
+ const httpEffect = yield* HttpRouter.toHttpEffect(HttpRouter.addAll([
160
+ HttpRouter.route('GET', DevChannelPath, channel.httpEffect),
161
+ HttpRouter.route('*', '/*', generationStore.httpEffect)
162
+ ]));
163
+ return {
164
+ closeDevChannel: channel.close,
165
+ httpEffect,
166
+ watch
167
+ };
168
+ });
169
+ const launchDevApplication = Effect.fnUntraced(function*(application) {
170
+ return yield* Effect.scoped(Effect.gen(function*() {
171
+ const server = yield* Layer.launch(HttpServer.serve(application.httpEffect)).pipe(Effect.forkScoped({
172
+ startImmediately: true
173
+ }));
174
+ yield* Effect.addFinalizer(()=>application.closeDevChannel);
175
+ const watch = HttpServer.addressFormattedWith((address)=>Effect.logInfo(`${Terminal.magenta('▌')} effective-rsc ${Terminal.dim(package_0.version)} ${address}`)).pipe(Effect.andThen(application.watch));
176
+ return yield* Effect.raceFirst(watch, Fiber.join(server));
177
+ }));
178
+ });
179
+ const devApplication = Effect.fn('ersc/build/devApplication')(function*(options) {
180
+ const application = yield* makeDevApplication(options).pipe(Effect.provide(Rspack.layer));
181
+ return yield* launchDevApplication(application);
182
+ });
183
+
184
+ export { DevGenerationError, acquireDevGeneration, devApplication, launchDevApplication, makeDevApplication, makeDevGenerationStore };
185
+
186
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build/dev.js","sources":["../../src/build/dev.ts"],"sourcesContent":["import {\n Deferred,\n Effect,\n Fiber,\n FileSystem,\n Layer,\n Path,\n Ref,\n Schema,\n ScopedRef,\n Stream,\n} from 'effect';\nimport { HttpRouter, HttpServer } from 'effect/unstable/http';\n\nimport PackageJson from '../../package.json' with { type: 'json' };\nimport { DevChannelPath } from '../dev/channel';\nimport { resolveApplicationBuild } from './build';\nimport { loadServerBundle, makeRunnableHttpLayer } from './compiled-server';\nimport { DevOutputDir, EnvironmentConfig } from './contract';\nimport { makeDevChannel } from './dev-channel';\nimport { Rspack, type RspackError, type RspackWatchEvent } from './rspack';\nimport { makeRspackDevConfig } from './rspack-config';\nimport { formatDuration, Terminal } from './terminal';\n\ntype RspackCompilation = Extract<RspackWatchEvent, { readonly _tag: 'Compiled' }>;\n\nexport class DevGenerationError extends Schema.TaggedError<DevGenerationError>()(\n 'DevGenerationError',\n {\n message: Schema.String,\n cause: Schema.Defect(),\n },\n) {}\n\ntype AcquireDevGenerationOptions = {\n readonly compilation: RspackCompilation;\n readonly hostname: string;\n readonly port: number;\n readonly root: string;\n};\n\ntype DevGenerationOptions = Omit<AcquireDevGenerationOptions, 'compilation'>;\n\nexport type DevApplicationOptions = DevGenerationOptions;\n\nexport const acquireDevGeneration = Effect.fnUntraced(function* ({\n compilation,\n hostname,\n port,\n root,\n}: AcquireDevGenerationOptions) {\n const path = yield* Path.Path;\n const bundle = yield* loadServerBundle(\n path.resolve(compilation.serverBundle.outputPath, compilation.serverBundle.filename),\n );\n const HttpLayer = yield* makeRunnableHttpLayer({\n bundle,\n clientAssetsCacheControl: EnvironmentConfig.development.clientAssetsCacheControl,\n clientOutputDir: EnvironmentConfig.development.clientOutputDir,\n hostname,\n port,\n root,\n });\n const httpEffect = yield* HttpRouter.toHttpEffect(HttpLayer).pipe(\n Effect.mapError(\n (cause) =>\n new DevGenerationError({\n message: `Failed to start development generation ${compilation.hash}.`,\n cause,\n }),\n ),\n );\n\n return {\n hash: compilation.hash,\n httpEffect,\n };\n});\n\ntype DevGeneration = Effect.Success<ReturnType<typeof acquireDevGeneration>>;\ntype DevGenerationFailure = Effect.Error<ReturnType<typeof acquireDevGeneration>> | RspackError;\n\ntype DevGenerationState =\n | { readonly _tag: 'Unavailable' }\n | { readonly _tag: 'Ready'; readonly generation: DevGeneration };\n\nexport const makeDevGenerationStore = Effect.fnUntraced(function* (options: DevGenerationOptions) {\n const generation = yield* ScopedRef.make<DevGenerationState>(() => ({ _tag: 'Unavailable' }));\n const initialCompilation = yield* Deferred.make<DevGeneration, DevGenerationFailure>();\n const compilation = yield* Ref.make(initialCompilation);\n const update = Effect.fnUntraced(function* (event: RspackWatchEvent) {\n const current = yield* Ref.get(compilation);\n\n switch (event._tag) {\n case 'Building': {\n const compilationCompleted = yield* Deferred.isDone(current);\n if (compilationCompleted) {\n const next = yield* Deferred.make<DevGeneration, DevGenerationFailure>();\n yield* Ref.set(compilation, next);\n }\n return;\n }\n case 'Failed': {\n yield* Deferred.fail(current, event.error);\n return;\n }\n case 'Compiled': {\n yield* ScopedRef.set(\n generation,\n acquireDevGeneration({ ...options, compilation: event }).pipe(\n Effect.map((ready): DevGenerationState => ({\n _tag: 'Ready',\n generation: ready,\n })),\n Effect.tapError((error) => Deferred.fail(current, error)),\n ),\n );\n const ready = yield* ScopedRef.get(generation);\n if (ready._tag === 'Unavailable') {\n return yield* Effect.die(\n new TypeError('Expected the completed development generation to be available.'),\n );\n }\n yield* Deferred.succeed(current, ready.generation);\n }\n }\n });\n const httpEffect = Ref.get(compilation).pipe(\n Effect.flatMap(Deferred.await),\n Effect.flatMap((ready) => ready.httpEffect),\n );\n\n return {\n httpEffect,\n update,\n };\n});\n\nexport const makeDevApplication = Effect.fnUntraced(function* ({\n hostname,\n port,\n root,\n}: DevApplicationOptions) {\n const { applicationRoot, entries } = yield* resolveApplicationBuild({ root });\n const fileSystem = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const rspack = yield* Rspack;\n const channel = yield* makeDevChannel;\n\n yield* fileSystem.remove(path.join(applicationRoot, DevOutputDir), {\n force: true,\n recursive: true,\n });\n\n const generationStore = yield* makeDevGenerationStore({\n hostname,\n port,\n root: applicationRoot,\n });\n const update = Effect.fnUntraced(function* (event: RspackWatchEvent) {\n switch (event._tag) {\n case 'Building': {\n yield* generationStore.update(event);\n const firstChangedFile =\n event.changedFiles.find((file) => path.basename(file).includes('.')) ??\n event.changedFiles[0];\n const changedPath =\n firstChangedFile === undefined\n ? undefined\n : path.relative(applicationRoot, firstChangedFile);\n const subject = changedPath ?? 'application';\n\n yield* Effect.logInfo(`${Terminal.cyan('●')} Compiling ${subject}...`);\n return;\n }\n case 'Failed': {\n yield* generationStore.update(event);\n yield* channel.publishBuildFailure(event.diagnostics);\n yield* Effect.logError(event.error);\n return;\n }\n case 'Compiled': {\n if (event.warnings !== undefined) {\n yield* Effect.logWarning(event.warnings);\n }\n yield* generationStore.update(event).pipe(\n Effect.andThen(channel.publishCompilation(event.clientHash)),\n Effect.tap(() => {\n const duration =\n event.duration === undefined ? '' : ` in ${formatDuration(event.duration)}`;\n const compilers = event.compilers\n .map(({ duration, name }) =>\n duration === undefined ? name : `${name} ${formatDuration(duration)}`,\n )\n .join(' · ');\n const details = compilers.length === 0 ? '' : ` ${Terminal.dim(compilers)}`;\n\n return Effect.logInfo(`${Terminal.green('✓')} Ready${duration}${details}`);\n }),\n Effect.catch((error) => Effect.logError(error)),\n );\n }\n }\n });\n const watch = rspack\n .watch(\n makeRspackDevConfig(applicationRoot, entries, {\n onCompilationStart: channel.onCompilationStart,\n onServerComponentChanges: channel.onServerComponentChanges,\n }),\n )\n .pipe(Stream.runForEach(update));\n const httpEffect = yield* HttpRouter.toHttpEffect(\n HttpRouter.addAll([\n HttpRouter.route('GET', DevChannelPath, channel.httpEffect),\n HttpRouter.route('*', '/*', generationStore.httpEffect),\n ]),\n );\n\n return {\n closeDevChannel: channel.close,\n httpEffect,\n watch,\n };\n});\n\ntype DevApplication = Effect.Success<ReturnType<typeof makeDevApplication>>;\n\nexport const launchDevApplication = Effect.fnUntraced(function* (application: DevApplication) {\n return yield* Effect.scoped(\n Effect.gen(function* () {\n const server = yield* Layer.launch(HttpServer.serve(application.httpEffect)).pipe(\n Effect.forkScoped({ startImmediately: true }),\n );\n yield* Effect.addFinalizer(() => application.closeDevChannel);\n const watch = HttpServer.addressFormattedWith((address) =>\n Effect.logInfo(\n `${Terminal.magenta('▌')} effective-rsc ${Terminal.dim(PackageJson.version)} ${address}`,\n ),\n ).pipe(Effect.andThen(application.watch));\n\n return yield* Effect.raceFirst(watch, Fiber.join(server));\n }),\n );\n});\n\nexport const devApplication = Effect.fn('ersc/build/devApplication')(function* (\n options: DevApplicationOptions,\n) {\n const application = yield* makeDevApplication(options).pipe(Effect.provide(Rspack.layer));\n\n return yield* launchDevApplication(application);\n});\n"],"names":["Deferred","Effect","Fiber","FileSystem","Layer","Path","Ref","Schema","ScopedRef","Stream","HttpRouter","HttpServer","PackageJson","DevChannelPath","resolveApplicationBuild","loadServerBundle","makeRunnableHttpLayer","DevOutputDir","EnvironmentConfig","makeDevChannel","Rspack","makeRspackDevConfig","formatDuration","Terminal","DevGenerationError","acquireDevGeneration","compilation","hostname","port","root","path","bundle","HttpLayer","httpEffect","cause","makeDevGenerationStore","options","generation","initialCompilation","update","event","current","compilationCompleted","next","ready","error","TypeError","makeDevApplication","applicationRoot","entries","fileSystem","rspack","channel","generationStore","firstChangedFile","file","changedPath","undefined","subject","duration","compilers","name","details","watch","launchDevApplication","application","server","address","devApplication"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWgB;AAC8C;AAEK;AACnB;AACE;AAC0B;AACf;AACd;AAC4B;AACrB;AACA;AAI/C,MAAMwB,kBAAkBA,SAASjB,kBAAkB,GACxD,sBACA;IACE,SAASA,aAAa;IACtB,OAAOA,aAAa;AACtB;AACC;AAaI,MAAMkB,oBAAoBA,GAAGxB,iBAAiB,CAAC,UAAW,EAC/DyB,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,IAAI,EACwB;IAC5B,MAAMC,OAAO,OAAOzB,SAAS;IAC7B,MAAM0B,SAAS,OAAOhB,gBAAgBA,CACpCe,KAAK,OAAO,CAACJ,YAAY,YAAY,CAAC,UAAU,EAAEA,YAAY,YAAY,CAAC,QAAQ;IAErF,MAAMM,YAAY,OAAOhB,qBAAqBA,CAAC;QAC7Ce;QACA,0BAA0Bb,sDAAsD;QAChF,iBAAiBA,6CAA6C;QAC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U;QAC1D1C,gBAAgB,CAAC,KAAK,MAAM2C,gBAAgB,UAAU;KACvD;IAGH,OAAO;QACL,iBAAiBD,QAAQ,KAAK;QAC9BnB;QACA8B;IACF;AACF,GAAG;AAII,MAAMC,oBAAoBA,GAAG/D,iBAAiB,CAAC,UAAWgE,WAA2B;IAC1F,OAAO,OAAOhE,aAAa,CACzBA,UAAU,CAAC;QACT,MAAMiE,SAAS,OAAO9D,YAAY,CAACO,gBAAgB,CAACsD,YAAY,UAAU,GAAG,IAAI,CAC/EhE,iBAAiB,CAAC;YAAE,kBAAkB;QAAK;QAE7C,OAAOA,mBAAmB,CAAC,IAAMgE,YAAY,eAAe;QAC5D,MAAMF,QAAQpD,+BAA+B,CAAC,CAACwD,UAC7ClE,cAAc,CACZ,GAAGsB,gBAAgB,CAAC,KAAK,eAAe,EAAEA,YAAY,CAACX,iBAAmB,EAAE,EAAE,EAAEuD,SAAS,GAE3F,IAAI,CAAClE,cAAc,CAACgE,YAAY,KAAK;QAEvC,OAAO,OAAOhE,gBAAgB,CAAC8D,OAAO7D,UAAU,CAACgE;IACnD;AAEJ,GAAG;AAEI,MAAME,cAAcA,GAAGnE,SAAS,CAAC,6BAA6B,UACnEmC,OAA8B;IAE9B,MAAM6B,cAAc,OAAOlB,kBAAkBA,CAACX,SAAS,IAAI,CAACnC,cAAc,CAACmB,YAAY;IAEvF,OAAO,OAAO4C,oBAAoBA,CAACC;AACrC,GAAG"}
@@ -0,0 +1,4 @@
1
+ import App from 'effective-rsc/application-entry';
2
+ export default App;
3
+ export declare const HttpLayer: import("../server/application.js").HttpApplicationLayer<never>;
4
+ export declare const ServerLayer: import("../server/application.js").ServerApplicationLayer<never>;
@@ -0,0 +1,17 @@
1
+ "use server-entry"
2
+ import application_entry from "effective-rsc/application-entry";
3
+ import { ServerApplication } from "../server/application.js";
4
+
5
+
6
+
7
+
8
+
9
+
10
+ /* export default */ const rsc_entry = (application_entry);
11
+ const HttpLayer = ServerApplication.httpLayer(application_entry);
12
+ const ServerLayer = ServerApplication.serverLayer(application_entry);
13
+
14
+ export { HttpLayer, ServerLayer };
15
+ export default rsc_entry;
16
+
17
+ //# sourceMappingURL=rsc-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build/rsc-entry.js","sources":["../../src/build/rsc-entry.ts"],"sourcesContent":["'use server-entry';\n\nimport App from 'effective-rsc/application-entry';\n\nimport { ServerApplication } from '../server/application';\n\nexport default App;\n\nexport const HttpLayer = ServerApplication.httpLayer(App);\nexport const ServerLayer = ServerApplication.serverLayer(App);\n"],"names":["App","ServerApplication","HttpLayer","ServerLayer"],"mappings":";;;;;;AAAmB;AAE+B;AAEQ;AAE1D,wCAAeA,iBAAGA,EAAC;AAEZ,MAAME,SAASA,GAAGD,2BAA2B,CAACD,iBAAGA,EAAE;AACnD,MAAMG,WAAWA,GAAGF,6BAA6B,CAACD,iBAAGA,EAAE"}
@@ -0,0 +1,17 @@
1
+ export type RspackEntries = {
2
+ readonly application: string;
3
+ readonly client: string;
4
+ readonly rsc: string;
5
+ readonly ssr: string;
6
+ };
7
+ export type RspackDevConfigOptions = {
8
+ readonly onCompilationStart?: () => void;
9
+ readonly onServerComponentChanges?: () => void | Promise<void>;
10
+ };
11
+ export type ExternalsRequest = {
12
+ readonly request?: string;
13
+ };
14
+ export declare const externalizeServerModule: ({ request }: ExternalsRequest) => string | false;
15
+ export declare const guardBrowserModule: ({ request }: ExternalsRequest) => false;
16
+ export declare const makeRspackBuildConfig: (root: string, entries: RspackEntries) => readonly import("@rspack/core").RspackOptions[];
17
+ export declare const makeRspackDevConfig: (root: string, entries: RspackEntries, options?: RspackDevConfigOptions) => readonly import("@rspack/core").RspackOptions[];
@@ -0,0 +1,259 @@
1
+ import { createRequire } from "node:module";
2
+ import core from "@rspack/core";
3
+ import { ReactRefreshRspackPlugin } from "@rspack/plugin-react-refresh";
4
+ import { FrameworkAssetPrefix } from "../application/route-path.js";
5
+ import { ApplicationEntrySpecifier, ClientEntryName, EnvironmentConfig, ServerEntryName } from "./contract.js";
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ const rspack_config_require = createRequire(import.meta.url);
18
+ const TailwindLoaderPath = rspack_config_require.resolve('@tailwindcss/webpack');
19
+ const SupportedBrowserTargets = [
20
+ 'chrome >= 141',
21
+ 'edge >= 141',
22
+ 'firefox >= 147'
23
+ ];
24
+ const BunModulePrefix = 'bun:';
25
+ const BunPlatformPackage = '@effect/platform-bun';
26
+ const EffectModuleName = 'effect';
27
+ const EffectModulePrefix = `${EffectModuleName}/`;
28
+ const EffectPackagePrefix = '@effect/';
29
+ const isBunModule = (request)=>request !== undefined && request.startsWith(BunModulePrefix);
30
+ const isBunPlatformModule = (request)=>request === BunPlatformPackage || request?.startsWith(`${BunPlatformPackage}/`) === true;
31
+ const isEffectModule = (request)=>request === EffectModuleName || request?.startsWith(EffectModulePrefix) === true || request?.startsWith(EffectPackagePrefix) === true;
32
+ const externalizeServerModule = ({ request })=>isBunModule(request) || isEffectModule(request) ? `module ${request}` : false;
33
+ const guardBrowserModule = ({ request })=>{
34
+ if (isBunModule(request) || isBunPlatformModule(request)) {
35
+ throw new TypeError(`"${request}" runs only on Bun and cannot enter the browser module graph. Move the import behind a Server Component, Layout, Page, or ServerFn boundary so it stays in the server graph.`);
36
+ }
37
+ return false;
38
+ };
39
+ const makeSwcRule = (target, mode)=>({
40
+ test: /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
41
+ type: 'javascript/auto',
42
+ use: [
43
+ {
44
+ loader: 'builtin:swc-loader',
45
+ options: {
46
+ detectSyntax: 'auto',
47
+ isModule: 'unknown',
48
+ jsc: {
49
+ experimental: {
50
+ keepImportAttributes: true
51
+ },
52
+ parser: {
53
+ decorators: true
54
+ },
55
+ transform: {
56
+ react: {
57
+ development: mode === 'development',
58
+ refresh: target === 'browser' && mode === 'development',
59
+ runtime: 'automatic'
60
+ },
61
+ ...target === 'browser' ? {
62
+ reactCompiler: true
63
+ } : {}
64
+ }
65
+ },
66
+ rspackExperiments: {
67
+ reactServerComponents: true
68
+ }
69
+ }
70
+ }
71
+ ]
72
+ });
73
+ const makeCssRule = (root, mode)=>({
74
+ test: /\.css$/i,
75
+ type: 'css/auto',
76
+ use: [
77
+ {
78
+ loader: TailwindLoaderPath,
79
+ options: {
80
+ base: root,
81
+ optimize: mode === 'production' ? {
82
+ minify: true
83
+ } : false
84
+ }
85
+ }
86
+ ]
87
+ });
88
+ const makeResolve = (root)=>({
89
+ extensionAlias: {
90
+ '.js': [
91
+ '.js',
92
+ '.ts',
93
+ '.tsx'
94
+ ],
95
+ '.jsx': [
96
+ '.jsx',
97
+ '.tsx'
98
+ ]
99
+ },
100
+ extensions: [
101
+ '.ts',
102
+ '.tsx',
103
+ '.mjs',
104
+ '.js',
105
+ '.jsx',
106
+ '.json'
107
+ ],
108
+ tsConfig: {
109
+ configFile: `${root}/tsconfig.json`,
110
+ references: 'auto'
111
+ }
112
+ });
113
+ const makeCompilationStartPlugin = (onCompilationStart)=>({
114
+ apply (compiler) {
115
+ compiler.hooks.watchRun.tap('ersc:dev', onCompilationStart);
116
+ }
117
+ });
118
+ const makeRspackConfig = (root, entries, mode, devOptions)=>{
119
+ const { ClientPlugin, ServerPlugin } = core.experiments.rsc.createPlugins();
120
+ const { Layers } = core.experiments.rsc;
121
+ const development = mode === 'development';
122
+ const config = EnvironmentConfig[mode];
123
+ const client = {
124
+ context: root,
125
+ devtool: development ? 'cheap-module-source-map' : false,
126
+ entry: {
127
+ [ClientEntryName]: entries.client
128
+ },
129
+ externals: [
130
+ guardBrowserModule
131
+ ],
132
+ mode,
133
+ module: {
134
+ rules: [
135
+ makeCssRule(root, mode),
136
+ makeSwcRule('browser', mode)
137
+ ]
138
+ },
139
+ name: 'client',
140
+ optimization: {
141
+ emitOnErrors: !development,
142
+ splitChunks: {
143
+ cacheGroups: {
144
+ react: {
145
+ name: 'lib-react',
146
+ priority: 0,
147
+ test: /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/
148
+ }
149
+ },
150
+ chunks: 'all'
151
+ }
152
+ },
153
+ output: {
154
+ chunkFilename: config.clientJsFilename,
155
+ clean: !development,
156
+ cssChunkFilename: config.clientCssFilename,
157
+ cssFilename: config.clientCssFilename,
158
+ filename: config.clientJsFilename,
159
+ path: `${root}/${config.clientOutputDir}`,
160
+ publicPath: FrameworkAssetPrefix
161
+ },
162
+ plugins: [
163
+ new ClientPlugin(),
164
+ ...development ? [
165
+ new core.HotModuleReplacementPlugin(),
166
+ new ReactRefreshRspackPlugin()
167
+ ] : []
168
+ ],
169
+ resolve: makeResolve(root),
170
+ target: `browserslist:${SupportedBrowserTargets.join(', ')}`
171
+ };
172
+ const server = {
173
+ context: root,
174
+ devtool: 'source-map',
175
+ entry: {
176
+ [ServerEntryName]: entries.rsc
177
+ },
178
+ externals: [
179
+ externalizeServerModule
180
+ ],
181
+ mode,
182
+ module: {
183
+ rules: [
184
+ makeCssRule(root, mode),
185
+ makeSwcRule('server', mode),
186
+ {
187
+ resource: entries.rsc,
188
+ layer: Layers.rsc,
189
+ resolve: {
190
+ conditionNames: [
191
+ 'react-server',
192
+ '...'
193
+ ]
194
+ }
195
+ },
196
+ {
197
+ resource: entries.ssr,
198
+ layer: Layers.ssr
199
+ },
200
+ {
201
+ exclude: entries.ssr,
202
+ issuerLayer: Layers.rsc,
203
+ resolve: {
204
+ conditionNames: [
205
+ 'react-server',
206
+ '...'
207
+ ]
208
+ }
209
+ }
210
+ ]
211
+ },
212
+ name: 'server',
213
+ optimization: {
214
+ emitOnErrors: !development,
215
+ minimize: false,
216
+ splitChunks: {
217
+ chunks: 'all'
218
+ }
219
+ },
220
+ output: {
221
+ chunkFilename: config.serverJsFilename,
222
+ chunkFormat: 'module',
223
+ chunkLoading: 'import',
224
+ clean: !development,
225
+ filename: config.serverJsFilename,
226
+ library: {
227
+ type: 'module'
228
+ },
229
+ module: true,
230
+ path: `${root}/${config.serverOutputDir}`,
231
+ publicPath: '/'
232
+ },
233
+ plugins: [
234
+ ...devOptions?.onCompilationStart === undefined ? [] : [
235
+ makeCompilationStartPlugin(devOptions.onCompilationStart)
236
+ ],
237
+ devOptions?.onServerComponentChanges === undefined ? new ServerPlugin() : new ServerPlugin({
238
+ onServerComponentChanges: devOptions.onServerComponentChanges
239
+ })
240
+ ],
241
+ resolve: {
242
+ ...makeResolve(root),
243
+ alias: {
244
+ [ApplicationEntrySpecifier]: entries.application
245
+ }
246
+ },
247
+ target: 'node26'
248
+ };
249
+ return [
250
+ client,
251
+ server
252
+ ];
253
+ };
254
+ const makeRspackBuildConfig = (root, entries)=>makeRspackConfig(root, entries, 'production');
255
+ const makeRspackDevConfig = (root, entries, options)=>makeRspackConfig(root, entries, 'development', options);
256
+
257
+ export { externalizeServerModule, guardBrowserModule, makeRspackBuildConfig, makeRspackDevConfig };
258
+
259
+ //# sourceMappingURL=rspack-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build/rspack-config.js","sources":["../../src/build/rspack-config.ts"],"sourcesContent":["import { createRequire } from 'node:module';\n\nimport rspack, { type Compiler, type Configuration, type RuleSetRule } from '@rspack/core';\nimport { ReactRefreshRspackPlugin } from '@rspack/plugin-react-refresh';\n\nimport { FrameworkAssetPrefix } from '../application/route-path';\nimport {\n ApplicationEntrySpecifier,\n ClientEntryName,\n type Environment,\n EnvironmentConfig,\n ServerEntryName,\n} from './contract';\n\nexport type RspackEntries = {\n readonly application: string;\n readonly client: string;\n readonly rsc: string;\n readonly ssr: string;\n};\n\nexport type RspackDevConfigOptions = {\n readonly onCompilationStart?: () => void;\n readonly onServerComponentChanges?: () => void | Promise<void>;\n};\n\nconst require = createRequire(import.meta.url);\nconst TailwindLoaderPath = require.resolve('@tailwindcss/webpack');\n\nconst SupportedBrowserTargets = ['chrome >= 141', 'edge >= 141', 'firefox >= 147'] as const;\n\nconst BunModulePrefix = 'bun:';\nconst BunPlatformPackage = '@effect/platform-bun';\nconst EffectModuleName = 'effect';\nconst EffectModulePrefix = `${EffectModuleName}/`;\nconst EffectPackagePrefix = '@effect/';\n\nexport type ExternalsRequest = {\n readonly request?: string;\n};\n\nconst isBunModule = (request: string | undefined): request is string =>\n request !== undefined && request.startsWith(BunModulePrefix);\n\nconst isBunPlatformModule = (request: string | undefined): request is string =>\n request === BunPlatformPackage || request?.startsWith(`${BunPlatformPackage}/`) === true;\n\nconst isEffectModule = (request: string | undefined): request is string =>\n request === EffectModuleName ||\n request?.startsWith(EffectModulePrefix) === true ||\n request?.startsWith(EffectPackagePrefix) === true;\n\nexport const externalizeServerModule = ({ request }: ExternalsRequest): string | false =>\n isBunModule(request) || isEffectModule(request) ? `module ${request}` : false;\n\nexport const guardBrowserModule = ({ request }: ExternalsRequest): false => {\n if (isBunModule(request) || isBunPlatformModule(request)) {\n throw new TypeError(\n `\"${request}\" runs only on Bun and cannot enter the browser module graph. Move the import behind a Server Component, Layout, Page, or ServerFn boundary so it stays in the server graph.`,\n );\n }\n\n return false;\n};\n\nconst makeSwcRule = (target: 'browser' | 'server', mode: Environment): RuleSetRule => ({\n test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,\n type: 'javascript/auto',\n use: [\n {\n loader: 'builtin:swc-loader',\n options: {\n detectSyntax: 'auto',\n isModule: 'unknown',\n jsc: {\n experimental: {\n keepImportAttributes: true,\n },\n parser: {\n decorators: true,\n },\n transform: {\n react: {\n development: mode === 'development',\n refresh: target === 'browser' && mode === 'development',\n runtime: 'automatic',\n },\n ...(target === 'browser' ? { reactCompiler: true } : {}),\n },\n },\n rspackExperiments: {\n reactServerComponents: true,\n },\n },\n },\n ],\n});\n\nconst makeCssRule = (root: string, mode: Environment): RuleSetRule => ({\n test: /\\.css$/i,\n type: 'css/auto',\n use: [\n {\n loader: TailwindLoaderPath,\n options: {\n base: root,\n optimize: mode === 'production' ? { minify: true } : false,\n },\n },\n ],\n});\n\nconst makeResolve = (root: string): NonNullable<Configuration['resolve']> => ({\n extensionAlias: {\n '.js': ['.js', '.ts', '.tsx'],\n '.jsx': ['.jsx', '.tsx'],\n },\n extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json'],\n tsConfig: {\n configFile: `${root}/tsconfig.json`,\n references: 'auto',\n },\n});\n\nconst makeCompilationStartPlugin = (onCompilationStart: () => void) => ({\n apply(compiler: Compiler) {\n compiler.hooks.watchRun.tap('ersc:dev', onCompilationStart);\n },\n});\n\nconst makeRspackConfig = (\n root: string,\n entries: RspackEntries,\n mode: Environment,\n devOptions?: RspackDevConfigOptions,\n): ReadonlyArray<Configuration> => {\n const { ClientPlugin, ServerPlugin } = rspack.experiments.rsc.createPlugins();\n const { Layers } = rspack.experiments.rsc;\n const development = mode === 'development';\n const config = EnvironmentConfig[mode];\n\n const client: Configuration = {\n context: root,\n devtool: development ? 'cheap-module-source-map' : false,\n entry: {\n [ClientEntryName]: entries.client,\n },\n externals: [guardBrowserModule],\n mode,\n module: {\n rules: [makeCssRule(root, mode), makeSwcRule('browser', mode)],\n },\n name: 'client',\n optimization: {\n emitOnErrors: !development,\n splitChunks: {\n cacheGroups: {\n react: {\n name: 'lib-react',\n priority: 0,\n test: /node_modules[\\\\/](?:react|react-dom|scheduler)[\\\\/]/,\n },\n },\n chunks: 'all',\n },\n },\n output: {\n chunkFilename: config.clientJsFilename,\n clean: !development,\n cssChunkFilename: config.clientCssFilename,\n cssFilename: config.clientCssFilename,\n filename: config.clientJsFilename,\n path: `${root}/${config.clientOutputDir}`,\n publicPath: FrameworkAssetPrefix,\n },\n plugins: [\n new ClientPlugin(),\n ...(development\n ? [new rspack.HotModuleReplacementPlugin(), new ReactRefreshRspackPlugin()]\n : []),\n ],\n resolve: makeResolve(root),\n target: `browserslist:${SupportedBrowserTargets.join(', ')}`,\n };\n\n const server: Configuration = {\n context: root,\n devtool: 'source-map',\n entry: {\n [ServerEntryName]: entries.rsc,\n },\n externals: [externalizeServerModule],\n mode,\n module: {\n rules: [\n makeCssRule(root, mode),\n makeSwcRule('server', mode),\n {\n resource: entries.rsc,\n layer: Layers.rsc,\n resolve: {\n conditionNames: ['react-server', '...'],\n },\n },\n {\n resource: entries.ssr,\n layer: Layers.ssr,\n },\n {\n exclude: entries.ssr,\n issuerLayer: Layers.rsc,\n resolve: {\n conditionNames: ['react-server', '...'],\n },\n },\n ],\n },\n name: 'server',\n optimization: {\n emitOnErrors: !development,\n minimize: false,\n splitChunks: {\n chunks: 'all',\n },\n },\n output: {\n chunkFilename: config.serverJsFilename,\n chunkFormat: 'module',\n chunkLoading: 'import',\n clean: !development,\n filename: config.serverJsFilename,\n library: {\n type: 'module',\n },\n module: true,\n path: `${root}/${config.serverOutputDir}`,\n publicPath: '/',\n },\n plugins: [\n ...(devOptions?.onCompilationStart === undefined\n ? []\n : [makeCompilationStartPlugin(devOptions.onCompilationStart)]),\n devOptions?.onServerComponentChanges === undefined\n ? new ServerPlugin()\n : new ServerPlugin({\n onServerComponentChanges: devOptions.onServerComponentChanges,\n }),\n ],\n resolve: {\n ...makeResolve(root),\n alias: {\n [ApplicationEntrySpecifier]: entries.application,\n },\n },\n target: 'node26',\n };\n\n return [client, server];\n};\n\nexport const makeRspackBuildConfig = (root: string, entries: RspackEntries) =>\n makeRspackConfig(root, entries, 'production');\n\nexport const makeRspackDevConfig = (\n root: string,\n entries: RspackEntries,\n options?: RspackDevConfigOptions,\n) => makeRspackConfig(root, entries, 'development', options);\n"],"names":["createRequire","rspack","ReactRefreshRspackPlugin","FrameworkAssetPrefix","ApplicationEntrySpecifier","ClientEntryName","EnvironmentConfig","ServerEntryName","require","TailwindLoaderPath","SupportedBrowserTargets","BunModulePrefix","BunPlatformPackage","EffectModuleName","EffectModulePrefix","EffectPackagePrefix","isBunModule","request","undefined","isBunPlatformModule","isEffectModule","externalizeServerModule","guardBrowserModule","TypeError","makeSwcRule","target","mode","makeCssRule","root","makeResolve","makeCompilationStartPlugin","onCompilationStart","compiler","makeRspackConfig","entries","devOptions","ClientPlugin","ServerPlugin","Layers","development","config","client","server","makeRspackBuildConfig","makeRspackD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,GAAG;oBACvB,SAAS;wBACP,gBAAgB;4BAAC;4BAAgB;yBAAM;oBACzC;gBACF;aACD;QACH;QACA,MAAM;QACN,cAAc;YACZ,cAAc,CAACC;YACf,UAAU;YACV,aAAa;gBACX,QAAQ;YACV;QACF;QACA,QAAQ;YACN,eAAeC,OAAO,gBAAgB;YACtC,aAAa;YACb,cAAc;YACd,OAAO,CAACD;YACR,UAAUC,OAAO,gBAAgB;YACjC,SAAS;gBACP,MAAM;YACR;YACA,QAAQ;YACR,MAAM,GAAGZ,KAAK,CAAC,EAAEY,OAAO,eAAe,EAAE;YACzC,YAAY;QACd;QACA,SAAS;eACHL,YAAY,uBAAuBjB,YACnC,EAAE,GACF;gBAACY,0BAA0BA,CAACK,WAAW,kBAAkB;aAAE;YAC/DA,YAAY,6BAA6BjB,YACrC,IAAImB,iBACJ,IAAIA,aAAa;gBACf,0BAA0BF,WAAW,wBAAwB;YAC/D;SACL;QACD,SAAS;YACP,GAAGN,WAAWA,CAACD,KAAK;YACpB,OAAO;gBACL,CAACxB,yBAAyBA,CAAC,EAAE8B,QAAQ,WAAW;YAClD;QACF;QACA,QAAQ;IACV;IAEA,OAAO;QAACO;QAAQC;KAAO;AACzB;AAEO,MAAMC,qBAAqBA,GAAG,CAACf,MAAcM,UAClDD,gBAAgBA,CAACL,MAAMM,SAAS,cAAc;AAEzC,MAAMU,mBAAmBA,GAAG,CACjChB,MACAM,SACAW,UACGZ,gBAAgBA,CAACL,MAAMM,SAAS,eAAeW,SAAS"}
@@ -0,0 +1,45 @@
1
+ import { type Configuration } from '@rspack/core';
2
+ import { Context, Effect, Layer, Schema, Stream } from 'effect';
3
+ declare const RspackError_base: Schema.Class<RspackError, Schema.TaggedStruct<"RspackError", {
4
+ readonly message: Schema.String;
5
+ readonly cause: Schema.Defect;
6
+ readonly reason: Schema.Literals<readonly ["CreateFailed", "CompileFailed", "BuildFailed", "CloseFailed"]>;
7
+ }>, import("effect/Cause").YieldableError>;
8
+ export declare class RspackError extends RspackError_base {
9
+ }
10
+ export type RspackWatchEvent = {
11
+ readonly _tag: 'Building';
12
+ readonly changedFiles: ReadonlyArray<string>;
13
+ } | {
14
+ readonly _tag: 'Compiled';
15
+ readonly clientHash: string;
16
+ readonly compilers: ReadonlyArray<{
17
+ readonly duration?: number;
18
+ readonly name: string;
19
+ }>;
20
+ readonly duration?: number;
21
+ readonly hash: string;
22
+ readonly serverBundle: {
23
+ readonly filename: string;
24
+ readonly outputPath: string;
25
+ };
26
+ readonly warnings?: string;
27
+ } | {
28
+ readonly _tag: 'Failed';
29
+ readonly diagnostics: string;
30
+ readonly error: RspackError;
31
+ };
32
+ declare const watchCompiler: (configs: ReadonlyArray<Configuration>) => Stream.Stream<RspackWatchEvent, RspackError, never>;
33
+ declare const Rspack_base: Context.ServiceClass<Rspack, "ersc/build/Rspack", {
34
+ build: (configs: readonly import("@rspack/core").RspackOptions[]) => Effect.Effect<void, RspackError, import("effect/Scope").Scope>;
35
+ watch: typeof watchCompiler;
36
+ }> & {
37
+ readonly make: Effect.Effect<{
38
+ build: (configs: readonly import("@rspack/core").RspackOptions[]) => Effect.Effect<void, RspackError, import("effect/Scope").Scope>;
39
+ watch: typeof watchCompiler;
40
+ }, never, never>;
41
+ };
42
+ export declare class Rspack extends Rspack_base {
43
+ static readonly layer: Layer.Layer<Rspack, never, never>;
44
+ }
45
+ export {};