@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,208 @@
|
|
|
1
|
+
import { START_ENVIRONMENT_NAMES } from '../constants.js';
|
|
2
|
+
import {
|
|
3
|
+
createServerFnBasePath,
|
|
4
|
+
normalizePublicBase,
|
|
5
|
+
shouldRewriteDevBasepath,
|
|
6
|
+
} from '../planning.js';
|
|
7
|
+
import {
|
|
8
|
+
applyResolvedBaseAndOutput,
|
|
9
|
+
applyResolvedRouterBasepath,
|
|
10
|
+
createStartConfigContext,
|
|
11
|
+
} from '../config-context.js';
|
|
12
|
+
import { importProtectionPlugin } from './import-protection-plugin/plugin.js';
|
|
13
|
+
import { startCompilerPlugin } from './start-compiler-plugin/plugin.js';
|
|
14
|
+
import { loadEnvPlugin } from './load-env-plugin/plugin.js';
|
|
15
|
+
import {
|
|
16
|
+
buildStartViteEnvironments,
|
|
17
|
+
createViteConfigPlan,
|
|
18
|
+
createViteDefineConfig,
|
|
19
|
+
createViteResolvedEntryAliases,
|
|
20
|
+
} from './planning.js';
|
|
21
|
+
import { devServerPlugin } from './dev-server-plugin/plugin.js';
|
|
22
|
+
import { getClientOutputDirectory, getServerOutputDirectory } from './output-directory.js';
|
|
23
|
+
import { previewServerPlugin } from './preview-server-plugin/plugin.js';
|
|
24
|
+
import {
|
|
25
|
+
createDevBaseRewritePlugin,
|
|
26
|
+
createDevClientEntryPlugin,
|
|
27
|
+
createPostBuildPlugin,
|
|
28
|
+
} from './plugins.js';
|
|
29
|
+
import { parseStartConfig } from './schema.js';
|
|
30
|
+
import { startManifestPlugin } from './start-manifest-plugin/plugin.js';
|
|
31
|
+
import { tanStackStartRouter } from './start-router-plugin/plugin.js';
|
|
32
|
+
import { postServerBuild } from './post-server-build.js';
|
|
33
|
+
import { serializationAdaptersPlugin } from './serialization-adapters-plugin.js';
|
|
34
|
+
import { crawlFrameworkPkgs } from 'vitefu';
|
|
35
|
+
import { getStartPackage } from '#tanstack-start/package-names';
|
|
36
|
+
//#region src/vite/plugin.ts
|
|
37
|
+
function tanStackStartVite(corePluginOpts, startPluginOpts) {
|
|
38
|
+
const normalizedStartPluginOpts = startPluginOpts ?? {};
|
|
39
|
+
const configContext = createStartConfigContext({
|
|
40
|
+
corePluginOpts,
|
|
41
|
+
startPluginOpts: normalizedStartPluginOpts,
|
|
42
|
+
parseConfig: parseStartConfig,
|
|
43
|
+
});
|
|
44
|
+
const { getConfig, resolvedStartConfig } = configContext;
|
|
45
|
+
const serverFnProviderEnv = corePluginOpts.providerEnvironmentName;
|
|
46
|
+
const ssrIsProvider = corePluginOpts.ssrIsProvider;
|
|
47
|
+
let needsDevBaseRewrite = false;
|
|
48
|
+
const environments = [
|
|
49
|
+
{
|
|
50
|
+
name: START_ENVIRONMENT_NAMES.client,
|
|
51
|
+
type: 'client',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: START_ENVIRONMENT_NAMES.server,
|
|
55
|
+
type: 'server',
|
|
56
|
+
getServerFnById:
|
|
57
|
+
corePluginOpts.ssrResolverStrategy.type === 'vite-rsc-forward'
|
|
58
|
+
? createViteRscForwarder(corePluginOpts.ssrResolverStrategy)
|
|
59
|
+
: void 0,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
if (
|
|
63
|
+
serverFnProviderEnv !== START_ENVIRONMENT_NAMES.server &&
|
|
64
|
+
!environments.find((e) => e.name === serverFnProviderEnv)
|
|
65
|
+
)
|
|
66
|
+
environments.push({
|
|
67
|
+
name: serverFnProviderEnv,
|
|
68
|
+
type: 'server',
|
|
69
|
+
});
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
name: 'tanstack-start-core:config',
|
|
73
|
+
enforce: 'pre',
|
|
74
|
+
async config(viteConfig, { command }) {
|
|
75
|
+
const publicBase = normalizePublicBase(viteConfig.base);
|
|
76
|
+
applyResolvedBaseAndOutput({
|
|
77
|
+
resolvedStartConfig,
|
|
78
|
+
root: viteConfig.root || process.cwd(),
|
|
79
|
+
publicBase,
|
|
80
|
+
clientOutputDirectory: getClientOutputDirectory(viteConfig),
|
|
81
|
+
serverOutputDirectory: getServerOutputDirectory(viteConfig),
|
|
82
|
+
});
|
|
83
|
+
const { startConfig } = getConfig();
|
|
84
|
+
const routerBasepath = applyResolvedRouterBasepath({
|
|
85
|
+
resolvedStartConfig,
|
|
86
|
+
startConfig,
|
|
87
|
+
});
|
|
88
|
+
if (
|
|
89
|
+
shouldRewriteDevBasepath({
|
|
90
|
+
command,
|
|
91
|
+
middlewareMode: Boolean(viteConfig.server?.middlewareMode),
|
|
92
|
+
routerBasepath,
|
|
93
|
+
publicBase: resolvedStartConfig.basePaths.publicBase,
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
needsDevBaseRewrite = true;
|
|
97
|
+
const TSS_SERVER_FN_BASE = createServerFnBasePath({
|
|
98
|
+
routerBasepath,
|
|
99
|
+
serverFnBase: startConfig.serverFns.base,
|
|
100
|
+
});
|
|
101
|
+
const entryAliases = createViteResolvedEntryAliases({
|
|
102
|
+
entryPaths: configContext.resolveEntries().entryPaths,
|
|
103
|
+
});
|
|
104
|
+
const startPackageName = getStartPackage(corePluginOpts.framework);
|
|
105
|
+
const crawlFrameworkPkgsResult = await crawlFrameworkPkgs({
|
|
106
|
+
root: process.cwd(),
|
|
107
|
+
isBuild: command === 'build',
|
|
108
|
+
isFrameworkPkgByJson(pkgJson) {
|
|
109
|
+
const peerDependencies = pkgJson['peerDependencies'];
|
|
110
|
+
if (peerDependencies) {
|
|
111
|
+
if (
|
|
112
|
+
startPackageName in peerDependencies ||
|
|
113
|
+
'@tanstack/start-client-core' in peerDependencies
|
|
114
|
+
)
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
const viteConfigPlan = createViteConfigPlan({
|
|
121
|
+
viteConfig,
|
|
122
|
+
command,
|
|
123
|
+
framework: corePluginOpts.framework,
|
|
124
|
+
entryAliases,
|
|
125
|
+
clientOutputDirectory: resolvedStartConfig.outputDirectories.client,
|
|
126
|
+
serverOutputDirectory: resolvedStartConfig.outputDirectories.server,
|
|
127
|
+
serverFnProviderEnv,
|
|
128
|
+
optimizeDepsExclude: crawlFrameworkPkgsResult.optimizeDeps.exclude,
|
|
129
|
+
noExternal: crawlFrameworkPkgsResult.ssr.noExternal.sort(),
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
appType: viteConfig.appType ?? 'custom',
|
|
133
|
+
environments: viteConfigPlan.environments,
|
|
134
|
+
resolve: viteConfigPlan.resolve,
|
|
135
|
+
define: createViteDefineConfig({
|
|
136
|
+
command,
|
|
137
|
+
mode: viteConfig.mode,
|
|
138
|
+
serverFnBase: TSS_SERVER_FN_BASE,
|
|
139
|
+
routerBasepath,
|
|
140
|
+
spaEnabled: startConfig.spa?.enabled,
|
|
141
|
+
devSsrStylesEnabled: startConfig.dev.ssrStyles.enabled,
|
|
142
|
+
devSsrStylesBasepath:
|
|
143
|
+
startConfig.dev.ssrStyles.basepath ?? resolvedStartConfig.basePaths.publicBase,
|
|
144
|
+
inlineCssEnabled: command === 'build' && startConfig.server.build.inlineCss.enabled,
|
|
145
|
+
staticNodeEnv: startConfig.server.build.staticNodeEnv,
|
|
146
|
+
disableCsrfMiddlewareWarning: startConfig.serverFns.disableCsrfMiddlewareWarning,
|
|
147
|
+
}),
|
|
148
|
+
builder: {
|
|
149
|
+
sharedPlugins: true,
|
|
150
|
+
async buildApp(builder) {
|
|
151
|
+
await buildStartViteEnvironments({
|
|
152
|
+
builder,
|
|
153
|
+
providerEnvironmentName: serverFnProviderEnv,
|
|
154
|
+
ssrIsProvider,
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
createPostBuildPlugin({
|
|
162
|
+
getConfig,
|
|
163
|
+
postServerBuild,
|
|
164
|
+
}),
|
|
165
|
+
startCompilerPlugin({
|
|
166
|
+
framework: corePluginOpts.framework,
|
|
167
|
+
environments,
|
|
168
|
+
generateFunctionId: normalizedStartPluginOpts.serverFns?.generateFunctionId,
|
|
169
|
+
compilerTransforms: corePluginOpts.compilerTransforms,
|
|
170
|
+
serverFnProviderModuleDirectives: corePluginOpts.serverFnProviderModuleDirectives,
|
|
171
|
+
providerEnvName: serverFnProviderEnv,
|
|
172
|
+
}),
|
|
173
|
+
importProtectionPlugin({
|
|
174
|
+
getConfig,
|
|
175
|
+
framework: corePluginOpts.framework,
|
|
176
|
+
environments,
|
|
177
|
+
providerEnvName: serverFnProviderEnv,
|
|
178
|
+
}),
|
|
179
|
+
tanStackStartRouter(normalizedStartPluginOpts, getConfig, corePluginOpts),
|
|
180
|
+
loadEnvPlugin(),
|
|
181
|
+
createDevClientEntryPlugin({
|
|
182
|
+
framework: corePluginOpts.framework,
|
|
183
|
+
getClientEntry: () => configContext.resolveEntries().entryPaths.client,
|
|
184
|
+
}),
|
|
185
|
+
startManifestPlugin({ getConfig }),
|
|
186
|
+
createDevBaseRewritePlugin({
|
|
187
|
+
shouldRewriteDevBase: () => needsDevBaseRewrite,
|
|
188
|
+
resolvedStartConfig,
|
|
189
|
+
}),
|
|
190
|
+
devServerPlugin({
|
|
191
|
+
getConfig,
|
|
192
|
+
devSsrStylesEnabled: normalizedStartPluginOpts.dev?.ssrStyles?.enabled ?? true,
|
|
193
|
+
installDevServerMiddleware: normalizedStartPluginOpts.vite?.installDevServerMiddleware,
|
|
194
|
+
}),
|
|
195
|
+
previewServerPlugin(),
|
|
196
|
+
...(corePluginOpts.serializationAdapters?.length
|
|
197
|
+
? [serializationAdaptersPlugin({ adapters: corePluginOpts.serializationAdapters })]
|
|
198
|
+
: []),
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
function createViteRscForwarder(strategy) {
|
|
202
|
+
return `export async function getServerFnById(id, access) {
|
|
203
|
+
const m = await import.meta.viteRsc.loadModule(${JSON.stringify(strategy.sourceEnvironmentName)}, ${JSON.stringify(strategy.sourceEntry)})
|
|
204
|
+
return m[${JSON.stringify(strategy.exportName)}](id, access)
|
|
205
|
+
}`;
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { tanStackStartVite };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CompileStartFrameworkOptions, GetConfigFn, ResolvedStartConfig } from '../types.js';
|
|
2
|
+
import { PluginOption, ViteBuilder } from 'vite';
|
|
3
|
+
export declare function createDevClientEntryPlugin(opts: {
|
|
4
|
+
framework: CompileStartFrameworkOptions;
|
|
5
|
+
getClientEntry: () => string;
|
|
6
|
+
}): PluginOption;
|
|
7
|
+
export declare function createPostBuildPlugin(opts: {
|
|
8
|
+
getConfig: GetConfigFn;
|
|
9
|
+
postServerBuild: (opts: {
|
|
10
|
+
startConfig: ReturnType<GetConfigFn>['startConfig'];
|
|
11
|
+
builder: ViteBuilder;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
}): PluginOption;
|
|
14
|
+
export declare function createDevBaseRewritePlugin(opts: {
|
|
15
|
+
shouldRewriteDevBase: () => boolean;
|
|
16
|
+
resolvedStartConfig: ResolvedStartConfig;
|
|
17
|
+
}): PluginOption;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DEV_CLIENT_ENTRY } from '../constants.js';
|
|
2
|
+
import { createVirtualModule } from './createVirtualModule.js';
|
|
3
|
+
import { normalizePath } from 'vite';
|
|
4
|
+
//#region src/vite/plugins.ts
|
|
5
|
+
function createDevClientEntryPlugin(opts) {
|
|
6
|
+
return createVirtualModule({
|
|
7
|
+
name: 'tanstack-start-core:dev-client-entry',
|
|
8
|
+
moduleId: DEV_CLIENT_ENTRY,
|
|
9
|
+
enforce: 'pre',
|
|
10
|
+
async load() {
|
|
11
|
+
const clientEntry = JSON.stringify(
|
|
12
|
+
normalizePath(opts.getClientEntry()).replaceAll('\\', '/'),
|
|
13
|
+
);
|
|
14
|
+
if (shouldInjectReactRefreshPreamble(this.environment, opts.framework)) {
|
|
15
|
+
const reactRefresh = await this.resolve?.('/@react-refresh');
|
|
16
|
+
if (!reactRefresh)
|
|
17
|
+
throw new Error(
|
|
18
|
+
'TanStack Start React dev mode requires the React Refresh runtime, but /@react-refresh could not be resolved. Add @vitejs/plugin-react or another compatible React Refresh Vite plugin to your Vite config.',
|
|
19
|
+
);
|
|
20
|
+
return getReactRefreshPreambleCode(reactRefresh.id) + `\nawait import(${clientEntry})`;
|
|
21
|
+
}
|
|
22
|
+
return `import ${clientEntry}`;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function shouldInjectReactRefreshPreamble(environment, framework) {
|
|
27
|
+
const config = environment?.config;
|
|
28
|
+
return (
|
|
29
|
+
framework === 'react' &&
|
|
30
|
+
config?.command === 'serve' &&
|
|
31
|
+
config.consumer === 'client' &&
|
|
32
|
+
config.server?.hmr !== false
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
function getReactRefreshPreambleCode(reactRefreshId) {
|
|
36
|
+
return `import { injectIntoGlobalHook } from ${JSON.stringify(reactRefreshId)};
|
|
37
|
+
injectIntoGlobalHook(window);
|
|
38
|
+
window.$RefreshReg$ = () => {};
|
|
39
|
+
window.$RefreshSig$ = () => (type) => type;
|
|
40
|
+
window.__vite_plugin_react_preamble_installed__ = true;`;
|
|
41
|
+
}
|
|
42
|
+
function createPostBuildPlugin(opts) {
|
|
43
|
+
return {
|
|
44
|
+
name: 'tanstack-start-core:post-build',
|
|
45
|
+
enforce: 'post',
|
|
46
|
+
buildApp: {
|
|
47
|
+
order: 'post',
|
|
48
|
+
async handler(builder) {
|
|
49
|
+
const { startConfig } = opts.getConfig();
|
|
50
|
+
await opts.postServerBuild({
|
|
51
|
+
builder,
|
|
52
|
+
startConfig,
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function createDevBaseRewritePlugin(opts) {
|
|
59
|
+
return {
|
|
60
|
+
name: 'tanstack-start-core:dev-base-rewrite',
|
|
61
|
+
configureServer(server) {
|
|
62
|
+
if (!opts.shouldRewriteDevBase()) return;
|
|
63
|
+
const basePrefix = opts.resolvedStartConfig.basePaths.publicBase.replace(/\/$/, '');
|
|
64
|
+
server.middlewares.use((req, _res, next) => {
|
|
65
|
+
if (req.url && !req.url.startsWith(basePrefix)) req.url = basePrefix + req.url;
|
|
66
|
+
next();
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { createDevBaseRewritePlugin, createDevClientEntryPlugin, createPostBuildPlugin };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getClientOutputDirectory } from './output-directory.js';
|
|
2
|
+
import { postBuild } from '../post-build.js';
|
|
3
|
+
import { prerenderWithVite } from './prerender.js';
|
|
4
|
+
//#region src/vite/post-server-build.ts
|
|
5
|
+
async function postServerBuild({ builder, startConfig }) {
|
|
6
|
+
await postBuild({
|
|
7
|
+
startConfig,
|
|
8
|
+
adapter: {
|
|
9
|
+
getClientOutputDirectory() {
|
|
10
|
+
return getClientOutputDirectory(builder.config);
|
|
11
|
+
},
|
|
12
|
+
prerender(startConfig) {
|
|
13
|
+
return prerenderWithVite({
|
|
14
|
+
startConfig,
|
|
15
|
+
builder,
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { postServerBuild };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { VITE_ENVIRONMENT_NAMES } from '../constants.js';
|
|
2
|
+
import { prerender } from '../prerender.js';
|
|
3
|
+
//#region src/vite/prerender.ts
|
|
4
|
+
async function prerenderWithVite({ startConfig, builder }) {
|
|
5
|
+
const serverEnv = builder.environments[VITE_ENVIRONMENT_NAMES.server];
|
|
6
|
+
if (!serverEnv)
|
|
7
|
+
throw new Error(`Vite's "${VITE_ENVIRONMENT_NAMES.server}" environment not found`);
|
|
8
|
+
const clientEnv = builder.environments[VITE_ENVIRONMENT_NAMES.client];
|
|
9
|
+
if (!clientEnv)
|
|
10
|
+
throw new Error(`Vite's "${VITE_ENVIRONMENT_NAMES.client}" environment not found`);
|
|
11
|
+
const outputDir = clientEnv.config.build.outDir;
|
|
12
|
+
process.env.TSS_PRERENDERING = 'true';
|
|
13
|
+
process.env.TSS_CLIENT_OUTPUT_DIR = outputDir;
|
|
14
|
+
const previewServer = await startPreviewServer(serverEnv.config);
|
|
15
|
+
const baseUrl = getResolvedUrl(previewServer);
|
|
16
|
+
return prerender({
|
|
17
|
+
startConfig,
|
|
18
|
+
handler: {
|
|
19
|
+
getClientOutputDirectory() {
|
|
20
|
+
return outputDir;
|
|
21
|
+
},
|
|
22
|
+
request(path, options) {
|
|
23
|
+
const url = new URL(path, baseUrl);
|
|
24
|
+
return fetch(new Request(url, options));
|
|
25
|
+
},
|
|
26
|
+
close() {
|
|
27
|
+
return previewServer.close();
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async function startPreviewServer(viteConfig) {
|
|
33
|
+
const vite = await import('vite');
|
|
34
|
+
try {
|
|
35
|
+
return await vite.preview({
|
|
36
|
+
configFile: viteConfig.configFile,
|
|
37
|
+
preview: {
|
|
38
|
+
port: 0,
|
|
39
|
+
open: false,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw new Error('Failed to start the Vite preview server for prerendering', { cause: error });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function getResolvedUrl(previewServer) {
|
|
47
|
+
const baseUrl = previewServer.resolvedUrls?.local[0];
|
|
48
|
+
if (!baseUrl) throw new Error('No resolved URL is available from the Vite preview server');
|
|
49
|
+
return new URL(baseUrl);
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { prerenderWithVite };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { VITE_ENVIRONMENT_NAMES } from '../../constants.js';
|
|
2
|
+
import { getBundlerOptions } from '../../utils.js';
|
|
3
|
+
import { getServerOutputDirectory } from '../output-directory.js';
|
|
4
|
+
import { basename, extname, join } from 'pathe';
|
|
5
|
+
import { NodeRequest, sendNodeResponse } from 'srvx/node';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import { joinURL } from 'ufo';
|
|
8
|
+
//#region src/vite/preview-server-plugin/plugin.ts
|
|
9
|
+
function previewServerPlugin() {
|
|
10
|
+
return {
|
|
11
|
+
name: 'tanstack-start-core:preview-server',
|
|
12
|
+
configurePreviewServer: {
|
|
13
|
+
order: 'post',
|
|
14
|
+
handler(server) {
|
|
15
|
+
return () => {
|
|
16
|
+
let serverBuild = null;
|
|
17
|
+
server.middlewares.use(async (req, res, next) => {
|
|
18
|
+
try {
|
|
19
|
+
if (!serverBuild) {
|
|
20
|
+
const serverEnv = server.config.environments[VITE_ENVIRONMENT_NAMES.server];
|
|
21
|
+
const serverInput = getBundlerOptions(serverEnv?.build)?.input ?? 'server';
|
|
22
|
+
if (typeof serverInput !== 'string')
|
|
23
|
+
throw new Error('Invalid server input. Expected a string.');
|
|
24
|
+
const outputFilename = `${basename(serverInput, extname(serverInput))}.js`;
|
|
25
|
+
serverBuild = (
|
|
26
|
+
await import(
|
|
27
|
+
pathToFileURL(
|
|
28
|
+
join(getServerOutputDirectory(server.config), outputFilename),
|
|
29
|
+
).toString()
|
|
30
|
+
)
|
|
31
|
+
).default;
|
|
32
|
+
}
|
|
33
|
+
req.url = joinURL(server.config.base, req.url ?? '/');
|
|
34
|
+
const webReq = new NodeRequest({
|
|
35
|
+
req,
|
|
36
|
+
res,
|
|
37
|
+
});
|
|
38
|
+
const webRes = await serverBuild.fetch(webReq);
|
|
39
|
+
if (webRes.headers.get('content-type')?.startsWith('text/html'))
|
|
40
|
+
res.setHeader('content-encoding', 'identity');
|
|
41
|
+
res.setHeaders(webRes.headers);
|
|
42
|
+
res.writeHead(webRes.status, webRes.statusText);
|
|
43
|
+
return sendNodeResponse(res, webRes);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
next(error);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { previewServerPlugin };
|