@octanejs/tanstack-start 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.
- package/LICENSE +22 -0
- package/README.md +52 -0
- package/THIRD_PARTY_NOTICES.md +11 -0
- package/package.json +149 -0
- package/src/client-only.d.ts +1 -0
- package/src/client-only.js +0 -0
- package/src/client-rpc.d.ts +1 -0
- package/src/client-rpc.js +1 -0
- package/src/client.d.ts +3 -0
- package/src/client.js +2 -0
- package/src/default-entry/client.js +12 -0
- package/src/default-entry/server.js +13 -0
- package/src/default-entry/start.js +1 -0
- package/src/default-entry-paths.d.ts +5 -0
- package/src/default-entry-paths.js +11 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +22 -0
- package/src/internal/README.md +15 -0
- package/src/internal/router-generator/config.d.ts +255 -0
- package/src/internal/router-generator/config.js +134 -0
- package/src/internal/router-generator/filesystem/physical/getRouteNodes.d.ts +53 -0
- package/src/internal/router-generator/filesystem/physical/getRouteNodes.js +335 -0
- package/src/internal/router-generator/filesystem/physical/rootPathId.d.ts +1 -0
- package/src/internal/router-generator/filesystem/physical/rootPathId.js +4 -0
- package/src/internal/router-generator/filesystem/virtual/config.d.ts +3 -0
- package/src/internal/router-generator/filesystem/virtual/config.js +36 -0
- package/src/internal/router-generator/filesystem/virtual/getRouteNodes.d.ts +31 -0
- package/src/internal/router-generator/filesystem/virtual/getRouteNodes.js +272 -0
- package/src/internal/router-generator/filesystem/virtual/loadConfigFile.d.ts +1 -0
- package/src/internal/router-generator/filesystem/virtual/loadConfigFile.js +10 -0
- package/src/internal/router-generator/generator.d.ts +119 -0
- package/src/internal/router-generator/generator.js +1080 -0
- package/src/internal/router-generator/index.d.ts +40 -0
- package/src/internal/router-generator/index.js +49 -0
- package/src/internal/router-generator/logger.d.ts +8 -0
- package/src/internal/router-generator/logger.js +30 -0
- package/src/internal/router-generator/plugin/types.d.ts +37 -0
- package/src/internal/router-generator/template.d.ts +38 -0
- package/src/internal/router-generator/template.js +220 -0
- package/src/internal/router-generator/transform/transform.d.ts +8 -0
- package/src/internal/router-generator/transform/transform.js +385 -0
- package/src/internal/router-generator/transform/types.d.ts +34 -0
- package/src/internal/router-generator/types.d.ts +73 -0
- package/src/internal/router-generator/utils.d.ts +270 -0
- package/src/internal/router-generator/utils.js +864 -0
- package/src/internal/router-generator/validate-route-params.d.ts +13 -0
- package/src/internal/router-generator/validate-route-params.js +75 -0
- package/src/internal/router-plugin/context.d.ts +2 -0
- package/src/internal/router-plugin/context.js +2 -0
- package/src/internal/router-plugin/core/code-splitter/compilers.d.ts +69 -0
- package/src/internal/router-plugin/core/code-splitter/compilers.js +1042 -0
- package/src/internal/router-plugin/core/code-splitter/framework-options.d.ts +11 -0
- package/src/internal/router-plugin/core/code-splitter/framework-options.js +41 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.d.ts +12 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.js +35 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.d.ts +5 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.js +106 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.d.ts +8 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.js +85 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.ts +2 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.js +55 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.d.ts +2 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.js +50 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.ts +5 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.js +54 -0
- package/src/internal/router-plugin/core/code-splitter/plugins.d.ts +62 -0
- package/src/internal/router-plugin/core/code-splitter/types.d.ts +9 -0
- package/src/internal/router-plugin/core/config.d.ts +294 -0
- package/src/internal/router-plugin/core/config.js +56 -0
- package/src/internal/router-plugin/core/constants.d.ts +12 -0
- package/src/internal/router-plugin/core/constants.js +13 -0
- package/src/internal/router-plugin/core/framework-plugin-order.d.ts +8 -0
- package/src/internal/router-plugin/core/framework-plugin-order.js +78 -0
- package/src/internal/router-plugin/core/hmr/handle-route-update.d.ts +1 -0
- package/src/internal/router-plugin/core/hmr/handle-route-update.js +126 -0
- package/src/internal/router-plugin/core/hmr/index.d.ts +5 -0
- package/src/internal/router-plugin/core/hmr/select-adapter.d.ts +17 -0
- package/src/internal/router-plugin/core/hmr/select-adapter.js +24 -0
- package/src/internal/router-plugin/core/hmr/vite-adapter.d.ts +18 -0
- package/src/internal/router-plugin/core/hmr/vite-adapter.js +73 -0
- package/src/internal/router-plugin/core/hmr/webpack-adapter.d.ts +22 -0
- package/src/internal/router-plugin/core/hmr/webpack-adapter.js +78 -0
- package/src/internal/router-plugin/core/router-code-splitter-plugin.d.ts +10 -0
- package/src/internal/router-plugin/core/router-code-splitter-plugin.js +244 -0
- package/src/internal/router-plugin/core/router-composed-plugin.d.ts +5 -0
- package/src/internal/router-plugin/core/router-composed-plugin.js +62 -0
- package/src/internal/router-plugin/core/router-generator-plugin.d.ts +10 -0
- package/src/internal/router-plugin/core/router-generator-plugin.js +125 -0
- package/src/internal/router-plugin/core/router-hmr-plugin.d.ts +13 -0
- package/src/internal/router-plugin/core/router-hmr-plugin.js +101 -0
- package/src/internal/router-plugin/core/router-plugin-context.d.ts +5 -0
- package/src/internal/router-plugin/core/router-plugin-context.js +6 -0
- package/src/internal/router-plugin/core/utils.d.ts +17 -0
- package/src/internal/router-plugin/core/utils.js +47 -0
- package/src/internal/router-plugin/esbuild.d.ts +197 -0
- package/src/internal/router-plugin/esbuild.js +58 -0
- package/src/internal/router-plugin/index.d.ts +19 -0
- package/src/internal/router-plugin/index.js +17 -0
- package/src/internal/router-plugin/rspack.d.ts +61 -0
- package/src/internal/router-plugin/rspack.js +92 -0
- package/src/internal/router-plugin/vite.d.ts +201 -0
- package/src/internal/router-plugin/vite.js +62 -0
- package/src/internal/router-plugin/webpack.d.ts +50 -0
- package/src/internal/router-plugin/webpack.js +77 -0
- package/src/internal/start-plugin-core/build-sitemap.d.ts +34 -0
- package/src/internal/start-plugin-core/build-sitemap.js +125 -0
- package/src/internal/start-plugin-core/config-context.d.ts +30 -0
- package/src/internal/start-plugin-core/config-context.js +89 -0
- package/src/internal/start-plugin-core/constants.d.ts +20 -0
- package/src/internal/start-plugin-core/constants.js +24 -0
- package/src/internal/start-plugin-core/debug.d.ts +1 -0
- package/src/internal/start-plugin-core/hydrate-when-transform.d.ts +5 -0
- package/src/internal/start-plugin-core/hydrate-when-transform.js +661 -0
- package/src/internal/start-plugin-core/hydration-constants.d.ts +1 -0
- package/src/internal/start-plugin-core/hydration-constants.js +4 -0
- package/src/internal/start-plugin-core/import-protection/adapterUtils.d.ts +40 -0
- package/src/internal/start-plugin-core/import-protection/adapterUtils.js +42 -0
- package/src/internal/start-plugin-core/import-protection/analysis.d.ts +63 -0
- package/src/internal/start-plugin-core/import-protection/analysis.js +533 -0
- package/src/internal/start-plugin-core/import-protection/constants.d.ts +11 -0
- package/src/internal/start-plugin-core/import-protection/constants.js +39 -0
- package/src/internal/start-plugin-core/import-protection/defaults.d.ts +19 -0
- package/src/internal/start-plugin-core/import-protection/defaults.js +34 -0
- package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.d.ts +22 -0
- package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.js +94 -0
- package/src/internal/start-plugin-core/import-protection/matchers.d.ts +18 -0
- package/src/internal/start-plugin-core/import-protection/matchers.js +39 -0
- package/src/internal/start-plugin-core/import-protection/rewrite.d.ts +29 -0
- package/src/internal/start-plugin-core/import-protection/rewrite.js +184 -0
- package/src/internal/start-plugin-core/import-protection/sourceLocation.d.ts +170 -0
- package/src/internal/start-plugin-core/import-protection/sourceLocation.js +376 -0
- package/src/internal/start-plugin-core/import-protection/trace.d.ts +89 -0
- package/src/internal/start-plugin-core/import-protection/trace.js +186 -0
- package/src/internal/start-plugin-core/import-protection/utils.d.ts +78 -0
- package/src/internal/start-plugin-core/import-protection/utils.js +171 -0
- package/src/internal/start-plugin-core/import-protection/virtualModules.d.ts +38 -0
- package/src/internal/start-plugin-core/import-protection/virtualModules.js +241 -0
- package/src/internal/start-plugin-core/index.d.ts +8 -0
- package/src/internal/start-plugin-core/index.js +2 -0
- package/src/internal/start-plugin-core/planning.d.ts +44 -0
- package/src/internal/start-plugin-core/planning.js +98 -0
- package/src/internal/start-plugin-core/post-build.d.ts +12 -0
- package/src/internal/start-plugin-core/post-build.js +40 -0
- package/src/internal/start-plugin-core/prerender.d.ts +17 -0
- package/src/internal/start-plugin-core/prerender.js +172 -0
- package/src/internal/start-plugin-core/queue.d.ts +37 -0
- package/src/internal/start-plugin-core/queue.js +118 -0
- package/src/internal/start-plugin-core/resolve-entries.d.ts +10 -0
- package/src/internal/start-plugin-core/resolve-entries.js +32 -0
- package/src/internal/start-plugin-core/schema.d.ts +1799 -0
- package/src/internal/start-plugin-core/schema.js +252 -0
- package/src/internal/start-plugin-core/serialization-adapters-module.d.ts +18 -0
- package/src/internal/start-plugin-core/serialization-adapters-module.js +37 -0
- package/src/internal/start-plugin-core/start-compiler/compiler.d.ts +181 -0
- package/src/internal/start-plugin-core/start-compiler/compiler.js +1078 -0
- package/src/internal/start-plugin-core/start-compiler/config.d.ts +20 -0
- package/src/internal/start-plugin-core/start-compiler/config.js +84 -0
- package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.d.ts +24 -0
- package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.js +25 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.d.ts +11 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.js +24 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.d.ts +11 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.js +35 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.d.ts +22 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.js +292 -0
- package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.d.ts +14 -0
- package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.js +41 -0
- package/src/internal/start-plugin-core/start-compiler/host.d.ts +44 -0
- package/src/internal/start-plugin-core/start-compiler/host.js +75 -0
- package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.d.ts +10 -0
- package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.js +87 -0
- package/src/internal/start-plugin-core/start-compiler/types.d.ts +119 -0
- package/src/internal/start-plugin-core/start-compiler/utils.d.ts +27 -0
- package/src/internal/start-plugin-core/start-compiler/utils.js +36 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.d.ts +16 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.js +131 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.d.ts +64 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.js +441 -0
- package/src/internal/start-plugin-core/start-router-plugin/constants.d.ts +1 -0
- package/src/internal/start-plugin-core/start-router-plugin/constants.js +4 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.js +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.js +27 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.js +34 -0
- package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.d.ts +11 -0
- package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.js +42 -0
- package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.js +59 -0
- package/src/internal/start-plugin-core/types.d.ts +135 -0
- package/src/internal/start-plugin-core/types.js +4 -0
- package/src/internal/start-plugin-core/utils.d.ts +13 -0
- package/src/internal/start-plugin-core/utils.js +42 -0
- package/src/internal/start-plugin-core/vite/createVirtualModule.d.ts +15 -0
- package/src/internal/start-plugin-core/vite/createVirtualModule.js +27 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.d.ts +26 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.js +165 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.d.ts +11 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.js +170 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.d.ts +4 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.js +1553 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/types.d.ts +103 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.d.ts +40 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.js +68 -0
- package/src/internal/start-plugin-core/vite/index.d.ts +13 -0
- package/src/internal/start-plugin-core/vite/index.js +4 -0
- package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.d.ts +2 -0
- package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.js +13 -0
- package/src/internal/start-plugin-core/vite/output-directory.d.ts +7 -0
- package/src/internal/start-plugin-core/vite/output-directory.js +18 -0
- package/src/internal/start-plugin-core/vite/planning.d.ts +112 -0
- package/src/internal/start-plugin-core/vite/planning.js +152 -0
- package/src/internal/start-plugin-core/vite/plugin.d.ts +7 -0
- package/src/internal/start-plugin-core/vite/plugin.js +208 -0
- package/src/internal/start-plugin-core/vite/plugins.d.ts +17 -0
- package/src/internal/start-plugin-core/vite/plugins.js +72 -0
- package/src/internal/start-plugin-core/vite/post-server-build.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/post-server-build.js +22 -0
- package/src/internal/start-plugin-core/vite/prerender.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/prerender.js +52 -0
- package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.d.ts +2 -0
- package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.js +54 -0
- package/src/internal/start-plugin-core/vite/schema.d.ts +2423 -0
- package/src/internal/start-plugin-core/vite/schema.js +17 -0
- package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.js +63 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.js +14 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.js +25 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.d.ts +29 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.js +380 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.d.ts +11 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.js +114 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.d.ts +3 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.js +103 -0
- package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.js +143 -0
- package/src/internal/start-plugin-core/vite/types.d.ts +17 -0
- package/src/package-names.js +10 -0
- package/src/plugin-vite.d.ts +23 -0
- package/src/plugin-vite.js +62 -0
- package/src/runtime/client/StartClient.d.ts +11 -0
- package/src/runtime/client/StartClient.js +16 -0
- package/src/runtime/client/hydrateStart.d.ts +4 -0
- package/src/runtime/client/hydrateStart.js +30 -0
- package/src/runtime/server/StartServer.d.ts +10 -0
- package/src/runtime/server/StartServer.js +6 -0
- package/src/runtime/server/defaultRenderHandler.d.ts +3 -0
- package/src/runtime/server/defaultRenderHandler.js +11 -0
- package/src/runtime/server/defaultStreamHandler.d.ts +3 -0
- package/src/runtime/server/defaultStreamHandler.js +13 -0
- package/src/server-entry.d.ts +11 -0
- package/src/server-entry.js +13 -0
- package/src/server-only.d.ts +1 -0
- package/src/server-only.js +0 -0
- package/src/server-rpc.d.ts +1 -0
- package/src/server-rpc.js +1 -0
- package/src/server.d.ts +6 -0
- package/src/server.js +4 -0
- package/src/ssr-rpc.d.ts +1 -0
- package/src/ssr-rpc.js +1 -0
- package/src/use-server-fn.d.ts +3 -0
- package/src/use-server-fn.js +18 -0
- package/src/validate-options.js +7 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { GeneratorResult } from '@tanstack/router-utils';
|
|
2
|
+
import { GeneratorPlugin } from '#tanstack-start/router-generator';
|
|
3
|
+
import { TanStackStartOutputConfig } from './schema.js';
|
|
4
|
+
import type * as babel from '@babel/core';
|
|
5
|
+
import type * as t from '@babel/types';
|
|
6
|
+
export declare const startFrameworks: readonly ['react', 'solid', 'vue', 'octane'];
|
|
7
|
+
export type CompileStartFrameworkOptions = (typeof startFrameworks)[number];
|
|
8
|
+
export type ServerFnLookupAccess =
|
|
9
|
+
| {
|
|
10
|
+
origin: 'client';
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
origin: 'server';
|
|
14
|
+
};
|
|
15
|
+
export type SerializationRuntime = 'client' | 'server';
|
|
16
|
+
export interface SerializationAdapterModuleRef {
|
|
17
|
+
module: string;
|
|
18
|
+
export: string;
|
|
19
|
+
isFactory?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export type SerializationAdapterByRuntime = Partial<
|
|
22
|
+
Record<SerializationRuntime, SerializationAdapterModuleRef>
|
|
23
|
+
>;
|
|
24
|
+
export type SerializationAdapterConfig =
|
|
25
|
+
| SerializationAdapterModuleRef
|
|
26
|
+
| SerializationAdapterByRuntime;
|
|
27
|
+
export type StartCompilerEnvironment = 'client' | 'server';
|
|
28
|
+
export interface StartCompilerImportTransformImport {
|
|
29
|
+
libName: string;
|
|
30
|
+
rootExport: string;
|
|
31
|
+
}
|
|
32
|
+
export interface StartCompilerTransformCandidate {
|
|
33
|
+
path: babel.NodePath<t.CallExpression>;
|
|
34
|
+
}
|
|
35
|
+
export interface StartCompilerTransformContext {
|
|
36
|
+
readonly ast: t.File;
|
|
37
|
+
readonly code: string;
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly env: StartCompilerEnvironment;
|
|
40
|
+
readonly envName: string;
|
|
41
|
+
readonly mode: 'dev' | 'build';
|
|
42
|
+
readonly root: string;
|
|
43
|
+
readonly framework: CompileStartFrameworkOptions;
|
|
44
|
+
readonly providerEnvName: string;
|
|
45
|
+
readonly types: typeof t;
|
|
46
|
+
parseExpression: (code: string) => t.Expression;
|
|
47
|
+
warn?: (message: string) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface StartCompilerImportTransform {
|
|
50
|
+
name: string;
|
|
51
|
+
environment?: StartCompilerEnvironment | Array<StartCompilerEnvironment> | undefined;
|
|
52
|
+
imports: Array<StartCompilerImportTransformImport>;
|
|
53
|
+
detect: RegExp;
|
|
54
|
+
order?: 'pre' | 'post' | undefined;
|
|
55
|
+
transform: (
|
|
56
|
+
candidates: Array<StartCompilerTransformCandidate>,
|
|
57
|
+
context: StartCompilerTransformContext,
|
|
58
|
+
) => void;
|
|
59
|
+
}
|
|
60
|
+
export interface StartCompilerTransformResult {
|
|
61
|
+
code: string;
|
|
62
|
+
map?: GeneratorResult['map'] | null;
|
|
63
|
+
}
|
|
64
|
+
export interface StartCompilerVirtualModuleContext {
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly root: string;
|
|
67
|
+
readonly env: StartCompilerEnvironment;
|
|
68
|
+
readonly envName: string;
|
|
69
|
+
readonly code?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface StartCompilerPlugin {
|
|
72
|
+
name: string;
|
|
73
|
+
environment?: StartCompilerEnvironment | Array<StartCompilerEnvironment> | undefined;
|
|
74
|
+
detect?: RegExp | undefined;
|
|
75
|
+
virtualModuleIdPattern?: RegExp | undefined;
|
|
76
|
+
transformAst?: (context: StartCompilerTransformContext) => boolean | null | undefined;
|
|
77
|
+
loadVirtualModule?: (
|
|
78
|
+
context: StartCompilerVirtualModuleContext,
|
|
79
|
+
) => StartCompilerTransformResult | null;
|
|
80
|
+
invalidateModule?: (context: { id: string; envName: string }) => void;
|
|
81
|
+
}
|
|
82
|
+
export interface NormalizedBasePaths {
|
|
83
|
+
publicBase: string;
|
|
84
|
+
assetBase: {
|
|
85
|
+
dev: string;
|
|
86
|
+
build: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export interface NormalizedOutputDirectories {
|
|
90
|
+
client: string;
|
|
91
|
+
server: string;
|
|
92
|
+
}
|
|
93
|
+
export interface NormalizedClientChunk {
|
|
94
|
+
fileName: string;
|
|
95
|
+
isEntry: boolean;
|
|
96
|
+
imports: Array<string>;
|
|
97
|
+
dynamicImports: Array<string>;
|
|
98
|
+
css: Array<string>;
|
|
99
|
+
routeFilePaths: Array<string>;
|
|
100
|
+
hydrationIds: Array<string>;
|
|
101
|
+
}
|
|
102
|
+
export interface NormalizedClientBuild {
|
|
103
|
+
entryChunkFileName: string;
|
|
104
|
+
chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>;
|
|
105
|
+
chunkFileNamesByRouteFilePath: ReadonlyMap<string, ReadonlyArray<string>>;
|
|
106
|
+
cssFilesBySourcePath: ReadonlyMap<string, ReadonlyArray<string>>;
|
|
107
|
+
cssContentByFileName?: ReadonlyMap<string, string>;
|
|
108
|
+
}
|
|
109
|
+
export interface TanStackStartCoreOptions {
|
|
110
|
+
framework: CompileStartFrameworkOptions;
|
|
111
|
+
defaultEntryPaths: {
|
|
112
|
+
client: string;
|
|
113
|
+
server: string;
|
|
114
|
+
start: string;
|
|
115
|
+
};
|
|
116
|
+
providerEnvironmentName: string;
|
|
117
|
+
ssrIsProvider: boolean;
|
|
118
|
+
serializationAdapters?: Array<SerializationAdapterConfig> | undefined;
|
|
119
|
+
compilerTransforms?: Array<StartCompilerImportTransform> | undefined;
|
|
120
|
+
serverFnProviderModuleDirectives?: ReadonlyArray<string> | undefined;
|
|
121
|
+
/** Framework-owned route source adapters and generator extensions. */
|
|
122
|
+
routerGeneratorPlugins?: ReadonlyArray<GeneratorPlugin> | undefined;
|
|
123
|
+
}
|
|
124
|
+
export interface ResolvedStartConfig {
|
|
125
|
+
root: string;
|
|
126
|
+
startFilePath: string | undefined;
|
|
127
|
+
routerFilePath: string;
|
|
128
|
+
srcDirectory: string;
|
|
129
|
+
basePaths: NormalizedBasePaths;
|
|
130
|
+
outputDirectories: NormalizedOutputDirectories;
|
|
131
|
+
}
|
|
132
|
+
export type GetConfigFn = () => {
|
|
133
|
+
startConfig: TanStackStartOutputConfig;
|
|
134
|
+
resolvedStartConfig: ResolvedStartConfig;
|
|
135
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Read `build.rollupOptions` or `build.rolldownOptions` from a build config. */
|
|
2
|
+
export declare function getBundlerOptions(build: any): any;
|
|
3
|
+
export declare function resolveViteId(id: string): string;
|
|
4
|
+
export declare function createIdFilter(ids: Array<string>): RegExp;
|
|
5
|
+
export declare function escapeRegExp(value: string): string;
|
|
6
|
+
export declare function createLogger(prefix: string): {
|
|
7
|
+
log: (...args: any) => void;
|
|
8
|
+
debug: (...args: any) => void;
|
|
9
|
+
info: (...args: any) => void;
|
|
10
|
+
warn: (...args: any) => void;
|
|
11
|
+
error: (...args: any) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare function normalizePath(id: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
var isWindows = typeof process !== 'undefined' && process.platform === 'win32';
|
|
4
|
+
var windowsSlashRE = /\\/g;
|
|
5
|
+
/** Read `build.rollupOptions` or `build.rolldownOptions` from a build config. */
|
|
6
|
+
function getBundlerOptions(build) {
|
|
7
|
+
return build?.rolldownOptions ?? build?.rollupOptions;
|
|
8
|
+
}
|
|
9
|
+
function resolveViteId(id) {
|
|
10
|
+
return `\0${id}`;
|
|
11
|
+
}
|
|
12
|
+
function createIdFilter(ids) {
|
|
13
|
+
return new RegExp(`^(?:${ids.map(escapeRegExp).join('|')})$`);
|
|
14
|
+
}
|
|
15
|
+
function escapeRegExp(value) {
|
|
16
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
17
|
+
}
|
|
18
|
+
function createLogger(prefix) {
|
|
19
|
+
const label = `[${prefix}]`;
|
|
20
|
+
return {
|
|
21
|
+
log: (...args) => console.log(label, ...args),
|
|
22
|
+
debug: (...args) => console.debug(label, ...args),
|
|
23
|
+
info: (...args) => console.info(label, ...args),
|
|
24
|
+
warn: (...args) => console.warn(label, ...args),
|
|
25
|
+
error: (...args) => console.error(label, ...args),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function slash(path) {
|
|
29
|
+
return path.replace(windowsSlashRE, '/');
|
|
30
|
+
}
|
|
31
|
+
function normalizePath(id) {
|
|
32
|
+
return path.posix.normalize(isWindows ? slash(id) : id);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export {
|
|
36
|
+
createIdFilter,
|
|
37
|
+
createLogger,
|
|
38
|
+
escapeRegExp,
|
|
39
|
+
getBundlerOptions,
|
|
40
|
+
normalizePath,
|
|
41
|
+
resolveViteId,
|
|
42
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
type VirtualModuleLoadHandler = (
|
|
3
|
+
this: any,
|
|
4
|
+
id: string,
|
|
5
|
+
) => string | null | undefined | Promise<string | null | undefined>;
|
|
6
|
+
export declare function createVirtualModule(opts: {
|
|
7
|
+
name: string;
|
|
8
|
+
moduleId: string;
|
|
9
|
+
load: VirtualModuleLoadHandler;
|
|
10
|
+
apply?: Plugin['apply'];
|
|
11
|
+
applyToEnvironment?: Plugin['applyToEnvironment'];
|
|
12
|
+
enforce?: Plugin['enforce'];
|
|
13
|
+
sharedDuringBuild?: boolean;
|
|
14
|
+
}): Plugin;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createIdFilter, resolveViteId } from '../utils.js';
|
|
2
|
+
//#region src/vite/createVirtualModule.ts
|
|
3
|
+
function createVirtualModule(opts) {
|
|
4
|
+
const resolvedId = resolveViteId(opts.moduleId.replaceAll('#', '%23'));
|
|
5
|
+
return {
|
|
6
|
+
name: opts.name,
|
|
7
|
+
apply: opts.apply,
|
|
8
|
+
applyToEnvironment: opts.applyToEnvironment,
|
|
9
|
+
enforce: opts.enforce,
|
|
10
|
+
sharedDuringBuild: opts.sharedDuringBuild,
|
|
11
|
+
resolveId: {
|
|
12
|
+
filter: { id: createIdFilter([opts.moduleId]) },
|
|
13
|
+
handler(id) {
|
|
14
|
+
if (id === opts.moduleId) return resolvedId;
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
load: {
|
|
18
|
+
filter: { id: createIdFilter([resolvedId]) },
|
|
19
|
+
handler(id) {
|
|
20
|
+
if (id !== resolvedId) return;
|
|
21
|
+
return opts.load.call(this, id);
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createVirtualModule };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ViteDevServer } from 'vite';
|
|
2
|
+
export declare const CSS_MODULES_REGEX: RegExp;
|
|
3
|
+
export declare function normalizeCssModuleCacheKey(idOrFile: string): string;
|
|
4
|
+
export declare function isCssModulesFile(file: string): boolean;
|
|
5
|
+
export interface CollectDevStylesOptions {
|
|
6
|
+
viteDevServer: ViteDevServer;
|
|
7
|
+
entries: Array<string>;
|
|
8
|
+
/** Cache of CSS modules content captured during transform hook */
|
|
9
|
+
cssModulesCache?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Collect CSS content from the module graph starting from the given entry points.
|
|
13
|
+
*/
|
|
14
|
+
export declare function collectDevStyles(
|
|
15
|
+
opts: CollectDevStylesOptions,
|
|
16
|
+
): Promise<string | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Extract CSS content from Vite's transformed CSS module code.
|
|
19
|
+
*
|
|
20
|
+
* Vite embeds CSS into the module as a JS string via `JSON.stringify(cssContent)`,
|
|
21
|
+
* e.g. `const __vite__css = ${JSON.stringify('...css...')}`.
|
|
22
|
+
*
|
|
23
|
+
* We locate that JSON string literal and run `JSON.parse` on it to reverse the
|
|
24
|
+
* escaping (\\n, \\t, \\", \\\\, \\uXXXX, etc.).
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractCssFromCode(code: string): string | undefined;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
//#region src/vite/dev-server-plugin/dev-styles.ts
|
|
3
|
+
/**
|
|
4
|
+
* CSS collection for dev mode.
|
|
5
|
+
* Crawls the Vite module graph to collect CSS from the router entry and all its dependencies.
|
|
6
|
+
*/
|
|
7
|
+
var CSS_FILE_REGEX = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
8
|
+
var CSS_MODULES_REGEX = /\.module\.(css|less|sass|scss|styl|stylus)(?:$|[?#])/i;
|
|
9
|
+
function normalizeCssModuleCacheKey(idOrFile) {
|
|
10
|
+
return idOrFile.split('?')[0].split('#')[0].replace(/\\/g, '/');
|
|
11
|
+
}
|
|
12
|
+
var CSS_SIDE_EFFECT_FREE_PARAMS = ['url', 'inline', 'raw', 'inline-css'];
|
|
13
|
+
var VITE_CSS_MARKER = 'const __vite__css = ';
|
|
14
|
+
var ESCAPE_CSS_COMMENT_START_REGEX = /\/\*/g;
|
|
15
|
+
var ESCAPE_CSS_COMMENT_END_REGEX = /\*\//g;
|
|
16
|
+
function isCssFile(file) {
|
|
17
|
+
return CSS_FILE_REGEX.test(file);
|
|
18
|
+
}
|
|
19
|
+
function isCssModulesFile(file) {
|
|
20
|
+
return CSS_MODULES_REGEX.test(file);
|
|
21
|
+
}
|
|
22
|
+
function hasCssSideEffectFreeParam(url) {
|
|
23
|
+
const queryString = url.split('?')[1];
|
|
24
|
+
if (!queryString) return false;
|
|
25
|
+
const params = new URLSearchParams(queryString);
|
|
26
|
+
return CSS_SIDE_EFFECT_FREE_PARAMS.some(
|
|
27
|
+
(param) =>
|
|
28
|
+
params.get(param) === '' && !url.includes(`?${param}=`) && !url.includes(`&${param}=`),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve a file path to a Vite dev server URL.
|
|
33
|
+
* Files within the root directory use relative paths, files outside use /@fs prefix.
|
|
34
|
+
*/
|
|
35
|
+
function resolveDevUrl(rootDirectory, filePath) {
|
|
36
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
37
|
+
const relativePath = path.posix.relative(rootDirectory.replace(/\\/g, '/'), normalizedPath);
|
|
38
|
+
if (!relativePath.startsWith('..') && !path.isAbsolute(relativePath))
|
|
39
|
+
return path.posix.join('/', relativePath);
|
|
40
|
+
return path.posix.join('/@fs', normalizedPath);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Collect CSS content from the module graph starting from the given entry points.
|
|
44
|
+
*/
|
|
45
|
+
async function collectDevStyles(opts) {
|
|
46
|
+
const { viteDevServer, entries, cssModulesCache = {} } = opts;
|
|
47
|
+
const styles = /* @__PURE__ */ new Map();
|
|
48
|
+
const visited = /* @__PURE__ */ new Set();
|
|
49
|
+
const rootDirectory = viteDevServer.config.root;
|
|
50
|
+
await Promise.all(
|
|
51
|
+
entries.map((entry) =>
|
|
52
|
+
processEntry(viteDevServer, resolveDevUrl(rootDirectory, entry), visited),
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
const cssPromises = [];
|
|
56
|
+
for (const dep of visited) {
|
|
57
|
+
if (hasCssSideEffectFreeParam(dep.url)) continue;
|
|
58
|
+
if (dep.file && isCssModulesFile(dep.file)) {
|
|
59
|
+
const css = cssModulesCache[normalizeCssModuleCacheKey(dep.file)];
|
|
60
|
+
if (!css) continue;
|
|
61
|
+
styles.set(dep.url, css);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!isCssFile(dep.file ?? dep.url)) continue;
|
|
65
|
+
cssPromises.push(
|
|
66
|
+
fetchCssFromModule(viteDevServer, dep).then((css) => (css ? [dep.url, css] : null)),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const cssResults = await Promise.all(cssPromises);
|
|
70
|
+
for (const result of cssResults) if (result) styles.set(result[0], result[1]);
|
|
71
|
+
if (styles.size === 0) return void 0;
|
|
72
|
+
const parts = [];
|
|
73
|
+
for (const [fileName, css] of styles.entries()) {
|
|
74
|
+
const escapedFileName = fileName
|
|
75
|
+
.replace(ESCAPE_CSS_COMMENT_START_REGEX, '/\\*')
|
|
76
|
+
.replace(ESCAPE_CSS_COMMENT_END_REGEX, '*\\/');
|
|
77
|
+
parts.push(`\n/* ${escapedFileName} */\n${css}`);
|
|
78
|
+
}
|
|
79
|
+
return parts.join('\n');
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Process an entry URL: transform it if needed, get the module node, and crawl its dependencies.
|
|
83
|
+
*/
|
|
84
|
+
async function processEntry(viteDevServer, entryUrl, visited) {
|
|
85
|
+
let node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl);
|
|
86
|
+
if (!node?.ssrTransformResult) {
|
|
87
|
+
try {
|
|
88
|
+
await viteDevServer.transformRequest(entryUrl);
|
|
89
|
+
} catch {}
|
|
90
|
+
node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl);
|
|
91
|
+
}
|
|
92
|
+
if (!node || visited.has(node)) return;
|
|
93
|
+
visited.add(node);
|
|
94
|
+
await findModuleDeps(viteDevServer, node, visited);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Find all module dependencies by crawling the module graph.
|
|
98
|
+
* Uses transformResult.deps for URL-based lookups (parallel) and
|
|
99
|
+
* importedModules for already-resolved nodes (parallel).
|
|
100
|
+
*/
|
|
101
|
+
async function findModuleDeps(viteDevServer, node, visited) {
|
|
102
|
+
const deps = node.ssrTransformResult?.deps ?? node.transformResult?.deps ?? null;
|
|
103
|
+
const importedModules = node.importedModules;
|
|
104
|
+
if ((!deps || deps.length === 0) && importedModules.size === 0) return;
|
|
105
|
+
const branches = [];
|
|
106
|
+
if (deps)
|
|
107
|
+
for (const depUrl of deps) {
|
|
108
|
+
const dep = await viteDevServer.moduleGraph.getModuleByUrl(depUrl);
|
|
109
|
+
if (!dep) continue;
|
|
110
|
+
if (visited.has(dep)) continue;
|
|
111
|
+
visited.add(dep);
|
|
112
|
+
branches.push(findModuleDeps(viteDevServer, dep, visited));
|
|
113
|
+
}
|
|
114
|
+
for (const depNode of importedModules) {
|
|
115
|
+
if (visited.has(depNode)) continue;
|
|
116
|
+
visited.add(depNode);
|
|
117
|
+
branches.push(findModuleDeps(viteDevServer, depNode, visited));
|
|
118
|
+
}
|
|
119
|
+
if (branches.length === 1) {
|
|
120
|
+
await branches[0];
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
await Promise.all(branches);
|
|
124
|
+
}
|
|
125
|
+
async function fetchCssFromModule(viteDevServer, node) {
|
|
126
|
+
const cachedCode = node.transformResult?.code ?? node.ssrTransformResult?.code;
|
|
127
|
+
if (cachedCode) return extractCssFromCode(cachedCode);
|
|
128
|
+
try {
|
|
129
|
+
const transformResult = await viteDevServer.transformRequest(node.url);
|
|
130
|
+
if (!transformResult?.code) return void 0;
|
|
131
|
+
return extractCssFromCode(transformResult.code);
|
|
132
|
+
} catch {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Extract CSS content from Vite's transformed CSS module code.
|
|
138
|
+
*
|
|
139
|
+
* Vite embeds CSS into the module as a JS string via `JSON.stringify(cssContent)`,
|
|
140
|
+
* e.g. `const __vite__css = ${JSON.stringify('...css...')}`.
|
|
141
|
+
*
|
|
142
|
+
* We locate that JSON string literal and run `JSON.parse` on it to reverse the
|
|
143
|
+
* escaping (\\n, \\t, \\", \\\\, \\uXXXX, etc.).
|
|
144
|
+
*/
|
|
145
|
+
function extractCssFromCode(code) {
|
|
146
|
+
const startIdx = code.indexOf(VITE_CSS_MARKER);
|
|
147
|
+
if (startIdx === -1) return void 0;
|
|
148
|
+
const valueStart = startIdx + 20;
|
|
149
|
+
if (code.charCodeAt(valueStart) !== 34) return void 0;
|
|
150
|
+
const codeLength = code.length;
|
|
151
|
+
let i = valueStart + 1;
|
|
152
|
+
while (i < codeLength) {
|
|
153
|
+
const charCode = code.charCodeAt(i);
|
|
154
|
+
if (charCode === 34)
|
|
155
|
+
try {
|
|
156
|
+
return JSON.parse(code.slice(valueStart, i + 1));
|
|
157
|
+
} catch {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (charCode === 92) i += 2;
|
|
161
|
+
else i++;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
export { CSS_MODULES_REGEX, collectDevStyles, normalizeCssModuleCacheKey };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
import { GetConfigFn } from '../../types.js';
|
|
3
|
+
export declare function devServerPlugin({
|
|
4
|
+
getConfig: _getConfig,
|
|
5
|
+
devSsrStylesEnabled,
|
|
6
|
+
installDevServerMiddleware,
|
|
7
|
+
}: {
|
|
8
|
+
getConfig: GetConfigFn;
|
|
9
|
+
devSsrStylesEnabled: boolean;
|
|
10
|
+
installDevServerMiddleware: boolean | undefined;
|
|
11
|
+
}): PluginOption;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from '../../constants.js';
|
|
2
|
+
import { CSS_MODULES_REGEX, collectDevStyles, normalizeCssModuleCacheKey } from './dev-styles.js';
|
|
3
|
+
import { isRunnableDevEnvironment } from 'vite';
|
|
4
|
+
import { NodeRequest, sendNodeResponse } from 'srvx/node';
|
|
5
|
+
//#region src/vite/dev-server-plugin/plugin.ts
|
|
6
|
+
function devServerPlugin({
|
|
7
|
+
getConfig: _getConfig,
|
|
8
|
+
devSsrStylesEnabled,
|
|
9
|
+
installDevServerMiddleware,
|
|
10
|
+
}) {
|
|
11
|
+
let isTest = false;
|
|
12
|
+
const cssModulesCache = {};
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
name: 'tanstack-start-core:dev-server',
|
|
16
|
+
config(_userConfig, { mode }) {
|
|
17
|
+
isTest = isTest ? isTest : mode === 'test';
|
|
18
|
+
},
|
|
19
|
+
transform: {
|
|
20
|
+
filter: { id: CSS_MODULES_REGEX },
|
|
21
|
+
handler(code, id) {
|
|
22
|
+
cssModulesCache[normalizeCssModuleCacheKey(id)] = code;
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
configureServer(viteDevServer) {
|
|
26
|
+
if (isTest) return;
|
|
27
|
+
if (devSsrStylesEnabled)
|
|
28
|
+
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
29
|
+
const url = req.url ?? '';
|
|
30
|
+
if (!url.split('?')[0]?.endsWith('/@tanstack-start/styles.css')) return next();
|
|
31
|
+
try {
|
|
32
|
+
const routesParam = new URL(url, 'http://localhost').searchParams.get('routes');
|
|
33
|
+
const routeIds = routesParam ? routesParam.split(',') : [];
|
|
34
|
+
const entries = [];
|
|
35
|
+
const routesManifest = globalThis.TSS_ROUTES_MANIFEST;
|
|
36
|
+
if (routesManifest && routeIds.length > 0)
|
|
37
|
+
for (const routeId of routeIds) {
|
|
38
|
+
const route = routesManifest[routeId];
|
|
39
|
+
if (route?.filePath) entries.push(route.filePath);
|
|
40
|
+
}
|
|
41
|
+
const css =
|
|
42
|
+
entries.length > 0
|
|
43
|
+
? await collectDevStyles({
|
|
44
|
+
viteDevServer,
|
|
45
|
+
entries,
|
|
46
|
+
cssModulesCache,
|
|
47
|
+
})
|
|
48
|
+
: void 0;
|
|
49
|
+
res.setHeader('Content-Type', 'text/css');
|
|
50
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
51
|
+
res.end(css ?? '');
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error('[tanstack-start] Error collecting dev styles:', e);
|
|
54
|
+
res.setHeader('Content-Type', 'text/css');
|
|
55
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
56
|
+
res.end(
|
|
57
|
+
`/* Error collecting styles: ${e instanceof Error ? e.message : String(e)} */`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (viteDevServer.config.experimental.bundledDev)
|
|
62
|
+
viteDevServer.watcher.add(viteDevServer.config.root);
|
|
63
|
+
return () => {
|
|
64
|
+
const serverEnv = viteDevServer.environments[VITE_ENVIRONMENT_NAMES.server];
|
|
65
|
+
if (!serverEnv)
|
|
66
|
+
throw new Error(`Server environment ${VITE_ENVIRONMENT_NAMES.server} not found`);
|
|
67
|
+
const clientEnv = viteDevServer.environments[VITE_ENVIRONMENT_NAMES.client];
|
|
68
|
+
const installMiddleware = installDevServerMiddleware;
|
|
69
|
+
if (installMiddleware === false) return;
|
|
70
|
+
if (installMiddleware == void 0) {
|
|
71
|
+
if (viteDevServer.config.server.middlewareMode) return;
|
|
72
|
+
if (!isRunnableDevEnvironment(serverEnv) || 'dispatchFetch' in serverEnv) return;
|
|
73
|
+
}
|
|
74
|
+
if (!isRunnableDevEnvironment(serverEnv))
|
|
75
|
+
throw new Error(
|
|
76
|
+
'cannot install vite dev server middleware for TanStack Start since the SSR environment is not a RunnableDevEnvironment',
|
|
77
|
+
);
|
|
78
|
+
viteDevServer.middlewares.use(async (req, res) => {
|
|
79
|
+
if (req.originalUrl) req.url = req.originalUrl;
|
|
80
|
+
const webReq = new NodeRequest({
|
|
81
|
+
req,
|
|
82
|
+
res,
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
const serverRunner = serverEnv.runner;
|
|
86
|
+
/**
|
|
87
|
+
* export default {
|
|
88
|
+
* fetch(req: Request): Promise<Response>
|
|
89
|
+
* }
|
|
90
|
+
*/
|
|
91
|
+
if (viteDevServer.config.experimental.bundledDev) {
|
|
92
|
+
await clientEnv?.devEngine?.ensureLatestBuildOutput?.();
|
|
93
|
+
serverEnv.moduleGraph.invalidateAll();
|
|
94
|
+
serverRunner.clearCache();
|
|
95
|
+
}
|
|
96
|
+
return sendNodeResponse(
|
|
97
|
+
res,
|
|
98
|
+
await (await serverRunner.import(ENTRY_POINTS.server))['default'].fetch(webReq),
|
|
99
|
+
);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error(e);
|
|
102
|
+
try {
|
|
103
|
+
viteDevServer.ssrFixStacktrace(e);
|
|
104
|
+
} catch {}
|
|
105
|
+
if (webReq.headers.get('content-type')?.includes('application/json'))
|
|
106
|
+
return sendNodeResponse(
|
|
107
|
+
res,
|
|
108
|
+
new Response(
|
|
109
|
+
JSON.stringify(
|
|
110
|
+
{
|
|
111
|
+
status: 500,
|
|
112
|
+
error: 'Internal Server Error',
|
|
113
|
+
message: 'An unexpected error occurred. Please try again later.',
|
|
114
|
+
timestamp: /* @__PURE__ */ new Date().toISOString(),
|
|
115
|
+
},
|
|
116
|
+
null,
|
|
117
|
+
2,
|
|
118
|
+
),
|
|
119
|
+
{
|
|
120
|
+
status: 500,
|
|
121
|
+
headers: { 'Content-Type': 'application/json' },
|
|
122
|
+
},
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
return sendNodeResponse(
|
|
126
|
+
res,
|
|
127
|
+
new Response(
|
|
128
|
+
`
|
|
129
|
+
<!DOCTYPE html>
|
|
130
|
+
<html lang="en">
|
|
131
|
+
<head>
|
|
132
|
+
<meta charset="UTF-8" />
|
|
133
|
+
<title>Error</title>
|
|
134
|
+
<script type="module">
|
|
135
|
+
import { ErrorOverlay } from '/@vite/client'
|
|
136
|
+
document.body.appendChild(new ErrorOverlay(${JSON.stringify(prepareError(req, e)).replace(/</g, '\\u003c')}))
|
|
137
|
+
<\/script>
|
|
138
|
+
</head>
|
|
139
|
+
<body>
|
|
140
|
+
</body>
|
|
141
|
+
</html>
|
|
142
|
+
`,
|
|
143
|
+
{
|
|
144
|
+
status: 500,
|
|
145
|
+
headers: { 'Content-Type': 'text/html' },
|
|
146
|
+
},
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Formats error for SSR message in error overlay
|
|
158
|
+
* @param req
|
|
159
|
+
* @param error
|
|
160
|
+
* @returns
|
|
161
|
+
*/
|
|
162
|
+
function prepareError(req, error) {
|
|
163
|
+
const e = error;
|
|
164
|
+
return {
|
|
165
|
+
message: `An error occurred while server rendering ${req.url}:\n\n\t${typeof e === 'string' ? e : e.message} `,
|
|
166
|
+
stack: typeof e === 'string' ? '' : e.stack,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
export { devServerPlugin };
|