@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,11 @@
|
|
|
1
|
+
import { Config } from '../config.js';
|
|
2
|
+
type FrameworkOptions = {
|
|
3
|
+
package: string;
|
|
4
|
+
idents: {
|
|
5
|
+
createFileRoute: string;
|
|
6
|
+
lazyFn: string;
|
|
7
|
+
lazyRouteComponent: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare function getFrameworkOptions(framework: Config['target']): FrameworkOptions;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { OCTANE_ROUTER_PACKAGE } from '#tanstack-start/package-names';
|
|
2
|
+
//#region src/core/code-splitter/framework-options.ts
|
|
3
|
+
var frameworkOptions = {
|
|
4
|
+
react: {
|
|
5
|
+
package: '@tanstack/react-router',
|
|
6
|
+
idents: {
|
|
7
|
+
createFileRoute: 'createFileRoute',
|
|
8
|
+
lazyFn: 'lazyFn',
|
|
9
|
+
lazyRouteComponent: 'lazyRouteComponent',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
solid: {
|
|
13
|
+
package: '@tanstack/solid-router',
|
|
14
|
+
idents: {
|
|
15
|
+
createFileRoute: 'createFileRoute',
|
|
16
|
+
lazyFn: 'lazyFn',
|
|
17
|
+
lazyRouteComponent: 'lazyRouteComponent',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
vue: {
|
|
21
|
+
package: '@tanstack/vue-router',
|
|
22
|
+
idents: {
|
|
23
|
+
createFileRoute: 'createFileRoute',
|
|
24
|
+
lazyFn: 'lazyFn',
|
|
25
|
+
lazyRouteComponent: 'lazyRouteComponent',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
octane: {
|
|
29
|
+
package: OCTANE_ROUTER_PACKAGE,
|
|
30
|
+
idents: {
|
|
31
|
+
createFileRoute: 'createFileRoute',
|
|
32
|
+
lazyFn: 'lazyFn',
|
|
33
|
+
lazyRouteComponent: 'lazyRouteComponent',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
function getFrameworkOptions(framework) {
|
|
38
|
+
return frameworkOptions[framework];
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { getFrameworkOptions };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReferenceRouteCompilerPlugin, VirtualRouteCompilerPlugin } from '../plugins.js';
|
|
2
|
+
import { Config, HmrStyle } from '../../config.js';
|
|
3
|
+
export declare function getReferenceRouteCompilerPlugins(opts: {
|
|
4
|
+
targetFramework: Config['target'];
|
|
5
|
+
addHmr?: boolean;
|
|
6
|
+
hmrStyle?: HmrStyle;
|
|
7
|
+
}): Array<ReferenceRouteCompilerPlugin> | undefined;
|
|
8
|
+
export declare function getVirtualRouteCompilerPlugins(opts: {
|
|
9
|
+
targetFramework: Config['target'];
|
|
10
|
+
addHmr?: boolean;
|
|
11
|
+
hmrStyle?: HmrStyle;
|
|
12
|
+
}): Array<VirtualRouteCompilerPlugin> | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createReactRefreshIgnoredRouteExportsPlugin } from './react-refresh-ignored-route-exports.js';
|
|
2
|
+
import { createReactRefreshRouteComponentsPlugin } from './react-refresh-route-components.js';
|
|
3
|
+
import { createStableHmrSplitRouteComponentsPlugin } from './react-stable-hmr-split-route-components.js';
|
|
4
|
+
import { createOctaneSplitRouteComponentsPlugin } from './octane-split-route-components.js';
|
|
5
|
+
import { createOctaneHmrSplitRouteComponentsPlugin } from './octane-hmr-split-route-components.js';
|
|
6
|
+
//#region src/core/code-splitter/plugins/framework-plugins.ts
|
|
7
|
+
function getReferenceRouteCompilerPlugins(opts) {
|
|
8
|
+
switch (opts.targetFramework) {
|
|
9
|
+
case 'react':
|
|
10
|
+
if (opts.addHmr) {
|
|
11
|
+
const hmrStyle = opts.hmrStyle ?? 'vite';
|
|
12
|
+
return [
|
|
13
|
+
...(hmrStyle === 'vite' ? [createReactRefreshIgnoredRouteExportsPlugin()] : []),
|
|
14
|
+
createReactRefreshRouteComponentsPlugin(),
|
|
15
|
+
createStableHmrSplitRouteComponentsPlugin({ hmrStyle }),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
case 'octane':
|
|
20
|
+
return [
|
|
21
|
+
createOctaneSplitRouteComponentsPlugin(),
|
|
22
|
+
...(opts.addHmr
|
|
23
|
+
? [createStableHmrSplitRouteComponentsPlugin({ hmrStyle: opts.hmrStyle ?? 'vite' })]
|
|
24
|
+
: []),
|
|
25
|
+
];
|
|
26
|
+
default:
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function getVirtualRouteCompilerPlugins(opts) {
|
|
31
|
+
if (opts.targetFramework !== 'octane' || !opts.addHmr) return;
|
|
32
|
+
return [createOctaneHmrSplitRouteComponentsPlugin({ hmrStyle: opts.hmrStyle ?? 'vite' })];
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { getReferenceRouteCompilerPlugins, getVirtualRouteCompilerPlugins };
|
package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { getUniqueProgramIdentifier } from '../../utils.js';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
import * as template from '@babel/template';
|
|
4
|
+
//#region src/core/code-splitter/plugins/octane-hmr-split-route-components.ts
|
|
5
|
+
var buildViteHmrStatements = template.statements(
|
|
6
|
+
`
|
|
7
|
+
const %%candidateIdent%% = %%hmrIdent%%(%%componentIdent%%)
|
|
8
|
+
const %%hotIdent%% = import.meta.hot
|
|
9
|
+
const %%hotDataIdent%% = %%hotIdent%% ? (%%hotIdent%%.data ??= {}) : undefined
|
|
10
|
+
let %%stableIdent%% = %%candidateIdent%%
|
|
11
|
+
if (%%hotDataIdent%%?.[%%hotDataKey%%]) {
|
|
12
|
+
%%hotDataIdent%%[%%hotDataKey%%][%%hmrSymbolIdent%%].update(%%candidateIdent%%)
|
|
13
|
+
%%stableIdent%% = %%hotDataIdent%%[%%hotDataKey%%]
|
|
14
|
+
}
|
|
15
|
+
%%stableIdent%%.$$singleRoot = %%componentIdent%%.$$singleRoot
|
|
16
|
+
try { %%stableIdent%%.__oct_loc = %%componentIdent%%.__oct_loc } catch {}
|
|
17
|
+
if (%%hotIdent%%) {
|
|
18
|
+
%%hotDataIdent%%[%%hotDataKey%%] = %%stableIdent%%
|
|
19
|
+
import.meta.hot.accept()
|
|
20
|
+
}
|
|
21
|
+
`,
|
|
22
|
+
{ syntacticPlaceholders: true },
|
|
23
|
+
);
|
|
24
|
+
var buildWebpackHmrStatements = template.statements(
|
|
25
|
+
`
|
|
26
|
+
const %%candidateIdent%% = %%hmrIdent%%(%%componentIdent%%)
|
|
27
|
+
const %%hotIdent%% = import.meta.webpackHot
|
|
28
|
+
let %%stableIdent%% = %%candidateIdent%%
|
|
29
|
+
if (%%hotIdent%%?.data?.[%%hotDataKey%%]) {
|
|
30
|
+
%%hotIdent%%.data[%%hotDataKey%%][%%hmrSymbolIdent%%].update(%%candidateIdent%%)
|
|
31
|
+
%%stableIdent%% = %%hotIdent%%.data[%%hotDataKey%%]
|
|
32
|
+
}
|
|
33
|
+
%%stableIdent%%.$$singleRoot = %%componentIdent%%.$$singleRoot
|
|
34
|
+
try { %%stableIdent%%.__oct_loc = %%componentIdent%%.__oct_loc } catch {}
|
|
35
|
+
if (%%hotIdent%%) {
|
|
36
|
+
%%hotIdent%%.dispose((data) => {
|
|
37
|
+
data[%%hotDataKey%%] = %%stableIdent%%
|
|
38
|
+
})
|
|
39
|
+
%%hotIdent%%.accept()
|
|
40
|
+
}
|
|
41
|
+
`,
|
|
42
|
+
{ syntacticPlaceholders: true },
|
|
43
|
+
);
|
|
44
|
+
function capitalizeIdentifier(value) {
|
|
45
|
+
return value[0].toUpperCase() + value.slice(1);
|
|
46
|
+
}
|
|
47
|
+
function createOctaneHmrSplitRouteComponentsPlugin(opts) {
|
|
48
|
+
let hmrIdent;
|
|
49
|
+
let hmrSymbolIdent;
|
|
50
|
+
return {
|
|
51
|
+
name: 'octane-hmr-split-route-components',
|
|
52
|
+
onExportSplitRouteProperty(ctx) {
|
|
53
|
+
if (ctx.splitNodeMeta.splitStrategy !== 'lazyRouteComponent') return;
|
|
54
|
+
if (!hmrIdent || !hmrSymbolIdent) {
|
|
55
|
+
hmrIdent = getUniqueProgramIdentifier(ctx.programPath, 'TSROctaneHmr');
|
|
56
|
+
hmrSymbolIdent = getUniqueProgramIdentifier(ctx.programPath, 'TSROctaneHmrSymbol');
|
|
57
|
+
ctx.programPath.unshiftContainer(
|
|
58
|
+
'body',
|
|
59
|
+
t.importDeclaration(
|
|
60
|
+
[
|
|
61
|
+
t.importSpecifier(hmrIdent, t.identifier('hmr')),
|
|
62
|
+
t.importSpecifier(hmrSymbolIdent, t.identifier('HMR')),
|
|
63
|
+
],
|
|
64
|
+
t.stringLiteral('octane'),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const exportName = ctx.splitNodeMeta.exporterIdent;
|
|
69
|
+
const name = capitalizeIdentifier(exportName);
|
|
70
|
+
const componentIdent = t.identifier(ctx.localExporterIdent);
|
|
71
|
+
const candidateIdent = getUniqueProgramIdentifier(
|
|
72
|
+
ctx.programPath,
|
|
73
|
+
`TSROctane${name}Candidate`,
|
|
74
|
+
);
|
|
75
|
+
const stableIdent = getUniqueProgramIdentifier(ctx.programPath, `TSROctane${name}`);
|
|
76
|
+
const hotIdent = getUniqueProgramIdentifier(ctx.programPath, `TSROctane${name}Hot`);
|
|
77
|
+
const hotDataIdent = getUniqueProgramIdentifier(ctx.programPath, `TSROctane${name}HotData`);
|
|
78
|
+
const hotDataKey = t.stringLiteral(`tsr-octane-split-component:${exportName}`);
|
|
79
|
+
const statements =
|
|
80
|
+
opts.hmrStyle === 'webpack'
|
|
81
|
+
? buildWebpackHmrStatements({
|
|
82
|
+
candidateIdent,
|
|
83
|
+
componentIdent,
|
|
84
|
+
hmrIdent,
|
|
85
|
+
hmrSymbolIdent,
|
|
86
|
+
hotDataKey,
|
|
87
|
+
hotIdent,
|
|
88
|
+
stableIdent,
|
|
89
|
+
})
|
|
90
|
+
: buildViteHmrStatements({
|
|
91
|
+
candidateIdent,
|
|
92
|
+
componentIdent,
|
|
93
|
+
hmrIdent,
|
|
94
|
+
hmrSymbolIdent,
|
|
95
|
+
hotDataIdent,
|
|
96
|
+
hotDataKey,
|
|
97
|
+
hotIdent,
|
|
98
|
+
stableIdent,
|
|
99
|
+
});
|
|
100
|
+
ctx.programPath.pushContainer('body', statements);
|
|
101
|
+
return stableIdent;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { createOctaneHmrSplitRouteComponentsPlugin };
|
package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReferenceRouteCompilerPlugin } from '../plugins.js';
|
|
2
|
+
/**
|
|
3
|
+
* Octane emits component metadata as adjacent top-level statements. Once the
|
|
4
|
+
* component binding moves to a virtual route module, those statements must
|
|
5
|
+
* move with it instead of evaluating against a missing binding in the
|
|
6
|
+
* reference module.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createOctaneSplitRouteComponentsPlugin(): ReferenceRouteCompilerPlugin;
|
package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
//#region src/core/code-splitter/plugins/octane-split-route-components.ts
|
|
3
|
+
function isStaticMember(node, objectName, propertyName) {
|
|
4
|
+
return (
|
|
5
|
+
t.isMemberExpression(node) &&
|
|
6
|
+
!node.computed &&
|
|
7
|
+
t.isIdentifier(node.object, { name: objectName }) &&
|
|
8
|
+
t.isIdentifier(node.property, { name: propertyName })
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
function isOctaneSingleRootStamp(statement, componentName) {
|
|
12
|
+
if (!t.isExpressionStatement(statement)) return false;
|
|
13
|
+
const expression = statement.expression;
|
|
14
|
+
return (
|
|
15
|
+
t.isAssignmentExpression(expression, { operator: '=' }) &&
|
|
16
|
+
isStaticMember(expression.left, componentName, '$$singleRoot') &&
|
|
17
|
+
t.isBooleanLiteral(expression.right, { value: true })
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function isOctaneWarmPlan(statement, componentName) {
|
|
21
|
+
if (!t.isExpressionStatement(statement)) return false;
|
|
22
|
+
const expression = statement.expression;
|
|
23
|
+
return (
|
|
24
|
+
t.isAssignmentExpression(expression, { operator: '=' }) &&
|
|
25
|
+
isStaticMember(expression.left, componentName, '__warm') &&
|
|
26
|
+
t.isArrowFunctionExpression(expression.right) &&
|
|
27
|
+
!expression.right.async &&
|
|
28
|
+
expression.right.params.length === 1 &&
|
|
29
|
+
t.isIdentifier(expression.right.params[0], { name: '__wp' })
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function isOctaneLocationStamp(statement, componentName) {
|
|
33
|
+
if (
|
|
34
|
+
!t.isTryStatement(statement) ||
|
|
35
|
+
statement.finalizer ||
|
|
36
|
+
!statement.handler ||
|
|
37
|
+
statement.handler.param ||
|
|
38
|
+
statement.block.body.length !== 1 ||
|
|
39
|
+
statement.handler.body.body.length !== 0 ||
|
|
40
|
+
!statement.handler.body.innerComments?.some(
|
|
41
|
+
(comment) => comment.value.trim() === 'frozen component',
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
return false;
|
|
45
|
+
const [bodyStatement] = statement.block.body;
|
|
46
|
+
if (!t.isExpressionStatement(bodyStatement)) return false;
|
|
47
|
+
const expression = bodyStatement.expression;
|
|
48
|
+
if (
|
|
49
|
+
!t.isAssignmentExpression(expression, { operator: '=' }) ||
|
|
50
|
+
!isStaticMember(expression.left, componentName, '__oct_loc')
|
|
51
|
+
)
|
|
52
|
+
return false;
|
|
53
|
+
return (
|
|
54
|
+
(t.isStringLiteral(expression.right) && /:\d+:\d+$/.test(expression.right.value)) ||
|
|
55
|
+
(t.isMemberExpression(expression.right) &&
|
|
56
|
+
!expression.right.computed &&
|
|
57
|
+
t.isIdentifier(expression.right.property, { name: '__oct_loc' }))
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function isOctaneCompilerCompanion(statement, componentName) {
|
|
61
|
+
return (
|
|
62
|
+
isOctaneSingleRootStamp(statement, componentName) ||
|
|
63
|
+
isOctaneWarmPlan(statement, componentName) ||
|
|
64
|
+
isOctaneLocationStamp(statement, componentName)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Octane emits component metadata as adjacent top-level statements. Once the
|
|
69
|
+
* component binding moves to a virtual route module, those statements must
|
|
70
|
+
* move with it instead of evaluating against a missing binding in the
|
|
71
|
+
* reference module.
|
|
72
|
+
*/
|
|
73
|
+
function createOctaneSplitRouteComponentsPlugin() {
|
|
74
|
+
return {
|
|
75
|
+
name: 'octane-split-route-components',
|
|
76
|
+
onSplitRouteProperty(ctx) {
|
|
77
|
+
if (!t.isIdentifier(ctx.prop.value)) return;
|
|
78
|
+
const componentName = ctx.prop.value.name;
|
|
79
|
+
for (const statementPath of ctx.programPath.get('body'))
|
|
80
|
+
if (isOctaneCompilerCompanion(statementPath.node, componentName)) statementPath.remove();
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { createOctaneSplitRouteComponentsPlugin };
|
package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { getUniqueProgramIdentifier } from '../../utils.js';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
import * as template from '@babel/template';
|
|
4
|
+
//#region src/core/code-splitter/plugins/react-refresh-ignored-route-exports.ts
|
|
5
|
+
var buildReactRefreshIgnoredRouteExportsStatements = template.statements(
|
|
6
|
+
`
|
|
7
|
+
const hot = import.meta.hot
|
|
8
|
+
if (hot && typeof window !== 'undefined') {
|
|
9
|
+
hot.data ??= {}
|
|
10
|
+
const tsrReactRefresh = window.__TSR_REACT_REFRESH__ ??= (() => {
|
|
11
|
+
const ignoredExportsById = new Map()
|
|
12
|
+
const previousGetIgnoredExports = window.__getReactRefreshIgnoredExports
|
|
13
|
+
|
|
14
|
+
window.__getReactRefreshIgnoredExports = (ctx) => {
|
|
15
|
+
const ignoredExports = previousGetIgnoredExports?.(ctx) ?? []
|
|
16
|
+
const moduleIgnored = ignoredExportsById.get(ctx.id) ?? []
|
|
17
|
+
return [...ignoredExports, ...moduleIgnored]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
ignoredExportsById,
|
|
22
|
+
}
|
|
23
|
+
})()
|
|
24
|
+
|
|
25
|
+
tsrReactRefresh.ignoredExportsById.set(%%moduleId%%, ['Route'])
|
|
26
|
+
}
|
|
27
|
+
`,
|
|
28
|
+
{ syntacticPlaceholders: true },
|
|
29
|
+
);
|
|
30
|
+
/**
|
|
31
|
+
* A trivial component-shaped export that gives `@vitejs/plugin-react` a valid
|
|
32
|
+
* Fast Refresh boundary. Without at least one non-ignored component export,
|
|
33
|
+
* the module would be invalidated (full page reload) on every update even
|
|
34
|
+
* though our custom route HMR handler already manages the update.
|
|
35
|
+
*/
|
|
36
|
+
var buildRefreshAnchorStatement = template.statement(
|
|
37
|
+
`export function %%anchorName%%() { return null }`,
|
|
38
|
+
{ syntacticPlaceholders: true },
|
|
39
|
+
);
|
|
40
|
+
function createReactRefreshIgnoredRouteExportsPlugin() {
|
|
41
|
+
return {
|
|
42
|
+
name: 'react-refresh-ignored-route-exports',
|
|
43
|
+
onAddHmr(ctx) {
|
|
44
|
+
const anchorName = getUniqueProgramIdentifier(ctx.programPath, 'TSRFastRefreshAnchor');
|
|
45
|
+
ctx.programPath.pushContainer(
|
|
46
|
+
'body',
|
|
47
|
+
buildReactRefreshIgnoredRouteExportsStatements({ moduleId: t.stringLiteral(ctx.opts.id) }),
|
|
48
|
+
);
|
|
49
|
+
ctx.programPath.pushContainer('body', buildRefreshAnchorStatement({ anchorName }));
|
|
50
|
+
return { modified: true };
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { createReactRefreshIgnoredRouteExportsPlugin };
|
package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getObjectPropertyKeyName, getUniqueProgramIdentifier } from '../../utils.js';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
//#region src/core/code-splitter/plugins/react-refresh-route-components.ts
|
|
4
|
+
var REACT_REFRESH_ROUTE_COMPONENT_IDENTS = new Set([
|
|
5
|
+
'component',
|
|
6
|
+
'shellComponent',
|
|
7
|
+
'pendingComponent',
|
|
8
|
+
'errorComponent',
|
|
9
|
+
'notFoundComponent',
|
|
10
|
+
]);
|
|
11
|
+
function hoistInlineRouteComponents(ctx) {
|
|
12
|
+
const hoistedDeclarations = [];
|
|
13
|
+
ctx.routeOptions.properties.forEach((prop) => {
|
|
14
|
+
if (!t.isObjectProperty(prop)) return;
|
|
15
|
+
const key = getObjectPropertyKeyName(prop);
|
|
16
|
+
if (!key || !REACT_REFRESH_ROUTE_COMPONENT_IDENTS.has(key)) return;
|
|
17
|
+
if (!t.isArrowFunctionExpression(prop.value) && !t.isFunctionExpression(prop.value)) return;
|
|
18
|
+
const hoistedIdentifier = getUniqueProgramIdentifier(
|
|
19
|
+
ctx.programPath,
|
|
20
|
+
`TSR${key[0].toUpperCase()}${key.slice(1)}`,
|
|
21
|
+
);
|
|
22
|
+
hoistedDeclarations.push(
|
|
23
|
+
t.variableDeclaration('const', [
|
|
24
|
+
t.variableDeclarator(hoistedIdentifier, t.cloneNode(prop.value, true)),
|
|
25
|
+
]),
|
|
26
|
+
);
|
|
27
|
+
prop.value = t.cloneNode(hoistedIdentifier);
|
|
28
|
+
});
|
|
29
|
+
if (hoistedDeclarations.length === 0) return false;
|
|
30
|
+
ctx.insertionPath.insertBefore(hoistedDeclarations);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
function createReactRefreshRouteComponentsPlugin() {
|
|
34
|
+
return {
|
|
35
|
+
name: 'react-refresh-route-components',
|
|
36
|
+
getStableRouteOptionKeys() {
|
|
37
|
+
return [...REACT_REFRESH_ROUTE_COMPONENT_IDENTS];
|
|
38
|
+
},
|
|
39
|
+
onUnsplittableRoute(ctx) {
|
|
40
|
+
if (!ctx.opts.addHmr) return;
|
|
41
|
+
if (hoistInlineRouteComponents(ctx)) return { modified: true };
|
|
42
|
+
},
|
|
43
|
+
onAddHmr(ctx) {
|
|
44
|
+
if (!ctx.opts.addHmr) return;
|
|
45
|
+
if (hoistInlineRouteComponents(ctx)) return { modified: true };
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { createReactRefreshRouteComponentsPlugin };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getUniqueProgramIdentifier } from '../../utils.js';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
import * as template from '@babel/template';
|
|
4
|
+
//#region src/core/code-splitter/plugins/react-stable-hmr-split-route-components.ts
|
|
5
|
+
function capitalizeIdentifier(str) {
|
|
6
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
7
|
+
}
|
|
8
|
+
function createHotDataKey(exportName) {
|
|
9
|
+
return `tsr-split-component:${exportName}`;
|
|
10
|
+
}
|
|
11
|
+
var buildStableSplitComponentStatements = template.statements(
|
|
12
|
+
`
|
|
13
|
+
const %%stableComponentIdent%% = (() => {
|
|
14
|
+
const hot = %%hotExpression%%
|
|
15
|
+
const hotData = hot ? (hot.data ??= {}) : undefined
|
|
16
|
+
return hotData?.[%%hotDataKey%%] ?? %%lazyRouteComponentIdent%%(%%localImporterIdent%%, %%exporterIdent%%)
|
|
17
|
+
})()
|
|
18
|
+
if (%%hotExpression%%) {
|
|
19
|
+
((%%hotExpression%%).data ??= {})[%%hotDataKey%%] = %%stableComponentIdent%%
|
|
20
|
+
}
|
|
21
|
+
`,
|
|
22
|
+
{ syntacticPlaceholders: true },
|
|
23
|
+
);
|
|
24
|
+
function hotExpressionAstFor(hmrStyle) {
|
|
25
|
+
return template.expression.ast(
|
|
26
|
+
hmrStyle === 'webpack' ? 'import.meta.webpackHot' : 'import.meta.hot',
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function createStableHmrSplitRouteComponentsPlugin(opts) {
|
|
30
|
+
return {
|
|
31
|
+
name: 'react-stable-hmr-split-route-components',
|
|
32
|
+
onSplitRouteProperty(ctx) {
|
|
33
|
+
if (ctx.splitNodeMeta.splitStrategy !== 'lazyRouteComponent') return;
|
|
34
|
+
const stableComponentIdent = getUniqueProgramIdentifier(
|
|
35
|
+
ctx.programPath,
|
|
36
|
+
`TSRSplit${capitalizeIdentifier(ctx.splitNodeMeta.exporterIdent)}`,
|
|
37
|
+
);
|
|
38
|
+
const hotDataKey = createHotDataKey(ctx.splitNodeMeta.exporterIdent);
|
|
39
|
+
ctx.insertionPath.insertBefore(
|
|
40
|
+
buildStableSplitComponentStatements({
|
|
41
|
+
stableComponentIdent,
|
|
42
|
+
hotDataKey: t.stringLiteral(hotDataKey),
|
|
43
|
+
hotExpression: hotExpressionAstFor(opts.hmrStyle),
|
|
44
|
+
lazyRouteComponentIdent: t.identifier(ctx.lazyRouteComponentIdent),
|
|
45
|
+
localImporterIdent: t.identifier(ctx.splitNodeMeta.localImporterIdent),
|
|
46
|
+
exporterIdent: t.stringLiteral(ctx.splitNodeMeta.exporterIdent),
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
return t.identifier(stableComponentIdent.name);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { createStableHmrSplitRouteComponentsPlugin };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { default as babel } from '@babel/core';
|
|
2
|
+
import { Config, DeletableNodes, HmrStyle } from '../config.js';
|
|
3
|
+
import { CodeSplitGroupings } from '../constants.js';
|
|
4
|
+
import { SplitNodeMeta } from './types.js';
|
|
5
|
+
import type * as t from '@babel/types';
|
|
6
|
+
export type CompileCodeSplitReferenceRouteOptions = {
|
|
7
|
+
codeSplitGroupings: CodeSplitGroupings;
|
|
8
|
+
deleteNodes?: Set<DeletableNodes>;
|
|
9
|
+
targetFramework: Config['target'];
|
|
10
|
+
filename: string;
|
|
11
|
+
id: string;
|
|
12
|
+
addHmr?: boolean;
|
|
13
|
+
hmrStyle?: HmrStyle;
|
|
14
|
+
hmrRouteId?: string;
|
|
15
|
+
sharedBindings?: Set<string>;
|
|
16
|
+
};
|
|
17
|
+
export type ReferenceRouteCompilerPluginContext = {
|
|
18
|
+
programPath: babel.NodePath<t.Program>;
|
|
19
|
+
callExpressionPath: babel.NodePath<t.CallExpression>;
|
|
20
|
+
insertionPath: babel.NodePath;
|
|
21
|
+
routeOptions: t.ObjectExpression;
|
|
22
|
+
createRouteFn: string;
|
|
23
|
+
opts: CompileCodeSplitReferenceRouteOptions;
|
|
24
|
+
};
|
|
25
|
+
export type ReferenceRouteSplitPropertyCompilerPluginContext = {
|
|
26
|
+
programPath: babel.NodePath<t.Program>;
|
|
27
|
+
callExpressionPath: babel.NodePath<t.CallExpression>;
|
|
28
|
+
insertionPath: babel.NodePath;
|
|
29
|
+
routeOptions: t.ObjectExpression;
|
|
30
|
+
prop: t.ObjectProperty;
|
|
31
|
+
splitNodeMeta: SplitNodeMeta;
|
|
32
|
+
lazyRouteComponentIdent: string;
|
|
33
|
+
opts: CompileCodeSplitReferenceRouteOptions;
|
|
34
|
+
};
|
|
35
|
+
export type ReferenceRouteCompilerPluginResult = {
|
|
36
|
+
modified?: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type ReferenceRouteCompilerPlugin = {
|
|
39
|
+
name: string;
|
|
40
|
+
getStableRouteOptionKeys?: () => Array<string>;
|
|
41
|
+
onRouteOptions?: (
|
|
42
|
+
ctx: ReferenceRouteCompilerPluginContext,
|
|
43
|
+
) => void | ReferenceRouteCompilerPluginResult;
|
|
44
|
+
onAddHmr?: (
|
|
45
|
+
ctx: ReferenceRouteCompilerPluginContext,
|
|
46
|
+
) => void | ReferenceRouteCompilerPluginResult;
|
|
47
|
+
onUnsplittableRoute?: (
|
|
48
|
+
ctx: ReferenceRouteCompilerPluginContext,
|
|
49
|
+
) => void | ReferenceRouteCompilerPluginResult;
|
|
50
|
+
onSplitRouteProperty?: (
|
|
51
|
+
ctx: ReferenceRouteSplitPropertyCompilerPluginContext,
|
|
52
|
+
) => void | t.Expression;
|
|
53
|
+
};
|
|
54
|
+
export type VirtualRouteCompilerPluginContext = {
|
|
55
|
+
programPath: babel.NodePath<t.Program>;
|
|
56
|
+
splitNodeMeta: SplitNodeMeta;
|
|
57
|
+
localExporterIdent: string;
|
|
58
|
+
};
|
|
59
|
+
export type VirtualRouteCompilerPlugin = {
|
|
60
|
+
name: string;
|
|
61
|
+
onExportSplitRouteProperty?: (ctx: VirtualRouteCompilerPluginContext) => void | t.Identifier;
|
|
62
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SplitRouteIdentNodes } from '../constants.js';
|
|
2
|
+
export type SplitStrategy = 'lazyFn' | 'lazyRouteComponent';
|
|
3
|
+
export type SplitNodeMeta = {
|
|
4
|
+
routeIdent: SplitRouteIdentNodes;
|
|
5
|
+
splitStrategy: SplitStrategy;
|
|
6
|
+
localImporterIdent: string;
|
|
7
|
+
exporterIdent: string;
|
|
8
|
+
localExporterIdent: string;
|
|
9
|
+
};
|