@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,78 @@
|
|
|
1
|
+
export type Pattern = string | RegExp;
|
|
2
|
+
export declare function dedupePatterns(patterns: Array<Pattern>): Array<Pattern>;
|
|
3
|
+
export interface FileMatchers {
|
|
4
|
+
files: Array<{
|
|
5
|
+
pattern: Pattern;
|
|
6
|
+
test: (value: string) => boolean;
|
|
7
|
+
}>;
|
|
8
|
+
excludeFiles: Array<{
|
|
9
|
+
pattern: Pattern;
|
|
10
|
+
test: (value: string) => boolean;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export declare function isFileExcluded(
|
|
14
|
+
relativePath: string,
|
|
15
|
+
matchers: Pick<FileMatchers, 'excludeFiles'>,
|
|
16
|
+
): boolean;
|
|
17
|
+
export declare function checkFileDenial(
|
|
18
|
+
relativePath: string,
|
|
19
|
+
matchers: FileMatchers,
|
|
20
|
+
): FileMatchers['files'][number] | undefined;
|
|
21
|
+
export declare function dedupeViolationKey(info: {
|
|
22
|
+
type: string;
|
|
23
|
+
importer: string;
|
|
24
|
+
specifier: string;
|
|
25
|
+
resolved?: string;
|
|
26
|
+
}): string;
|
|
27
|
+
/** Strip both `?query` and `#hash` from a module ID. */
|
|
28
|
+
export declare function stripQueryAndHash(id: string): string;
|
|
29
|
+
export declare function normalizeFilePath(id: string): string;
|
|
30
|
+
/** Clear the memoization cache (call from buildStart to bound growth). */
|
|
31
|
+
export declare function clearNormalizeFilePathCache(): void;
|
|
32
|
+
/** Get a value from a Map, creating it with `factory` if absent. */
|
|
33
|
+
export declare function getOrCreate<TKey, TValue>(
|
|
34
|
+
map: Map<TKey, TValue>,
|
|
35
|
+
key: TKey,
|
|
36
|
+
factory: () => TValue,
|
|
37
|
+
): TValue;
|
|
38
|
+
/** Make a path relative to `root`, keeping non-rooted paths as-is. */
|
|
39
|
+
export declare function relativizePath(p: string, root: string): string;
|
|
40
|
+
/** Log import-protection debug output when debug mode is enabled. */
|
|
41
|
+
export declare function debugLog(...args: Array<unknown>): void;
|
|
42
|
+
/** Check if any value matches the configured debug filter (if present). */
|
|
43
|
+
export declare function matchesDebugFilter(...values: Array<string>): boolean;
|
|
44
|
+
/** Strip `?query` (but not `#hash`) from a module ID. */
|
|
45
|
+
export declare function stripQuery(id: string): string;
|
|
46
|
+
export declare function withoutKnownExtension(id: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Check whether `filePath` is contained inside `directory` using a
|
|
49
|
+
* boundary-safe comparison. A naïve `filePath.startsWith(directory)`
|
|
50
|
+
* would incorrectly treat `/app/src2/foo.ts` as inside `/app/src`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isInsideDirectory(filePath: string, directory: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Decide whether a violation should be deferred for later verification
|
|
55
|
+
* rather than reported immediately.
|
|
56
|
+
*
|
|
57
|
+
* Build mode: always defer — generateBundle checks tree-shaking.
|
|
58
|
+
* Dev mock mode: always defer — edge-survival verifies whether the Start
|
|
59
|
+
* compiler strips the import (factory-safe pattern). All violation
|
|
60
|
+
* types and specifier formats are handled uniformly by the
|
|
61
|
+
* edge-survival mechanism in processPendingViolations.
|
|
62
|
+
* Dev error mode: never defer — throw immediately (no mock fallback).
|
|
63
|
+
*/
|
|
64
|
+
export declare function shouldDeferViolation(opts: {
|
|
65
|
+
isBuild: boolean;
|
|
66
|
+
isDevMock: boolean;
|
|
67
|
+
}): boolean;
|
|
68
|
+
export declare function buildSourceCandidates(
|
|
69
|
+
source: string,
|
|
70
|
+
resolved: string | undefined,
|
|
71
|
+
root: string,
|
|
72
|
+
): Set<string>;
|
|
73
|
+
export declare function buildResolutionCandidates(id: string): Array<string>;
|
|
74
|
+
export declare function canonicalizeResolvedId(
|
|
75
|
+
id: string,
|
|
76
|
+
root: string,
|
|
77
|
+
resolveExtensionlessAbsoluteId: (value: string) => string,
|
|
78
|
+
): string;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { normalizePath } from '../utils.js';
|
|
2
|
+
import {
|
|
3
|
+
IMPORT_PROTECTION_DEBUG,
|
|
4
|
+
IMPORT_PROTECTION_DEBUG_FILTER,
|
|
5
|
+
KNOWN_SOURCE_EXTENSIONS,
|
|
6
|
+
} from './constants.js';
|
|
7
|
+
import { extname, isAbsolute, relative, resolve } from 'node:path';
|
|
8
|
+
//#region src/import-protection/utils.ts
|
|
9
|
+
function dedupePatterns(patterns) {
|
|
10
|
+
const out = [];
|
|
11
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12
|
+
for (const p of patterns) {
|
|
13
|
+
const key = typeof p === 'string' ? `s:${p}` : `r:${p.toString()}`;
|
|
14
|
+
if (seen.has(key)) continue;
|
|
15
|
+
seen.add(key);
|
|
16
|
+
out.push(p);
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
function isFileExcluded(relativePath, matchers) {
|
|
21
|
+
return (
|
|
22
|
+
matchers.excludeFiles.length > 0 &&
|
|
23
|
+
matchers.excludeFiles.some((matcher) => matcher.test(relativePath))
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function checkFileDenial(relativePath, matchers) {
|
|
27
|
+
if (isFileExcluded(relativePath, matchers)) return;
|
|
28
|
+
return matchers.files.find((matcher) => matcher.test(relativePath));
|
|
29
|
+
}
|
|
30
|
+
function dedupeViolationKey(info) {
|
|
31
|
+
return `${info.type}:${info.importer}:${info.specifier}:${info.resolved ?? ''}`;
|
|
32
|
+
}
|
|
33
|
+
/** Strip both `?query` and `#hash` from a module ID. */
|
|
34
|
+
function stripQueryAndHash(id) {
|
|
35
|
+
const q = id.indexOf('?');
|
|
36
|
+
const h = id.indexOf('#');
|
|
37
|
+
if (q === -1 && h === -1) return id;
|
|
38
|
+
if (q === -1) return id.slice(0, h);
|
|
39
|
+
if (h === -1) return id.slice(0, q);
|
|
40
|
+
return id.slice(0, Math.min(q, h));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Strip Vite query/hash parameters and normalize the path in one step.
|
|
44
|
+
*
|
|
45
|
+
* Results are memoized because the same module IDs are processed many
|
|
46
|
+
* times across resolveId, transform, and trace-building hooks.
|
|
47
|
+
*/
|
|
48
|
+
var normalizeFilePathCache = /* @__PURE__ */ new Map();
|
|
49
|
+
function normalizeFilePath(id) {
|
|
50
|
+
let result = normalizeFilePathCache.get(id);
|
|
51
|
+
if (result === void 0) {
|
|
52
|
+
result = normalizePath(stripQueryAndHash(id));
|
|
53
|
+
normalizeFilePathCache.set(id, result);
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
/** Clear the memoization cache (call from buildStart to bound growth). */
|
|
58
|
+
function clearNormalizeFilePathCache() {
|
|
59
|
+
normalizeFilePathCache.clear();
|
|
60
|
+
}
|
|
61
|
+
/** Get a value from a Map, creating it with `factory` if absent. */
|
|
62
|
+
function getOrCreate(map, key, factory) {
|
|
63
|
+
let value = map.get(key);
|
|
64
|
+
if (value === void 0) {
|
|
65
|
+
value = factory();
|
|
66
|
+
map.set(key, value);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
/** Make a path relative to `root`, keeping non-rooted paths as-is. */
|
|
71
|
+
function relativizePath(p, root) {
|
|
72
|
+
if (!p.startsWith(root)) return p;
|
|
73
|
+
const ch = p.charCodeAt(root.length);
|
|
74
|
+
if (ch !== 47 && !Number.isNaN(ch)) return p;
|
|
75
|
+
return ch === 47 ? p.slice(root.length + 1) : p.slice(root.length);
|
|
76
|
+
}
|
|
77
|
+
/** Log import-protection debug output when debug mode is enabled. */
|
|
78
|
+
function debugLog(...args) {
|
|
79
|
+
if (!IMPORT_PROTECTION_DEBUG) return;
|
|
80
|
+
console.warn('[import-protection:debug]', ...args);
|
|
81
|
+
}
|
|
82
|
+
/** Check if any value matches the configured debug filter (if present). */
|
|
83
|
+
function matchesDebugFilter(...values) {
|
|
84
|
+
const debugFilter = IMPORT_PROTECTION_DEBUG_FILTER;
|
|
85
|
+
if (!debugFilter) return true;
|
|
86
|
+
return values.some((v) => v.includes(debugFilter));
|
|
87
|
+
}
|
|
88
|
+
/** Strip `?query` (but not `#hash`) from a module ID. */
|
|
89
|
+
function stripQuery(id) {
|
|
90
|
+
const queryIndex = id.indexOf('?');
|
|
91
|
+
return queryIndex === -1 ? id : id.slice(0, queryIndex);
|
|
92
|
+
}
|
|
93
|
+
function withoutKnownExtension(id) {
|
|
94
|
+
const ext = extname(id);
|
|
95
|
+
return KNOWN_SOURCE_EXTENSIONS.has(ext) ? id.slice(0, -ext.length) : id;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check whether `filePath` is contained inside `directory` using a
|
|
99
|
+
* boundary-safe comparison. A naïve `filePath.startsWith(directory)`
|
|
100
|
+
* would incorrectly treat `/app/src2/foo.ts` as inside `/app/src`.
|
|
101
|
+
*/
|
|
102
|
+
function isInsideDirectory(filePath, directory) {
|
|
103
|
+
const rel = relative(resolve(directory), resolve(filePath));
|
|
104
|
+
return rel.length > 0 && !rel.startsWith('..') && !isAbsolute(rel);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Decide whether a violation should be deferred for later verification
|
|
108
|
+
* rather than reported immediately.
|
|
109
|
+
*
|
|
110
|
+
* Build mode: always defer — generateBundle checks tree-shaking.
|
|
111
|
+
* Dev mock mode: always defer — edge-survival verifies whether the Start
|
|
112
|
+
* compiler strips the import (factory-safe pattern). All violation
|
|
113
|
+
* types and specifier formats are handled uniformly by the
|
|
114
|
+
* edge-survival mechanism in processPendingViolations.
|
|
115
|
+
* Dev error mode: never defer — throw immediately (no mock fallback).
|
|
116
|
+
*/
|
|
117
|
+
function shouldDeferViolation(opts) {
|
|
118
|
+
return opts.isBuild || opts.isDevMock;
|
|
119
|
+
}
|
|
120
|
+
function buildSourceCandidates(source, resolved, root) {
|
|
121
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
122
|
+
const push = (value) => {
|
|
123
|
+
if (!value) return;
|
|
124
|
+
candidates.add(value);
|
|
125
|
+
candidates.add(stripQuery(value));
|
|
126
|
+
candidates.add(withoutKnownExtension(stripQuery(value)));
|
|
127
|
+
};
|
|
128
|
+
push(source);
|
|
129
|
+
if (resolved) {
|
|
130
|
+
push(resolved);
|
|
131
|
+
const relativeResolved = relativizePath(resolved, root);
|
|
132
|
+
push(relativeResolved);
|
|
133
|
+
push(`./${relativeResolved}`);
|
|
134
|
+
push(`/${relativeResolved}`);
|
|
135
|
+
}
|
|
136
|
+
return candidates;
|
|
137
|
+
}
|
|
138
|
+
function buildResolutionCandidates(id) {
|
|
139
|
+
const normalized = normalizeFilePath(id);
|
|
140
|
+
const stripped = stripQuery(normalized);
|
|
141
|
+
return [...new Set([id, normalized, stripped])];
|
|
142
|
+
}
|
|
143
|
+
function canonicalizeResolvedId(id, root, resolveExtensionlessAbsoluteId) {
|
|
144
|
+
let normalized = normalizeFilePath(stripQuery(id));
|
|
145
|
+
if (
|
|
146
|
+
!isAbsolute(normalized) &&
|
|
147
|
+
!normalized.startsWith('.') &&
|
|
148
|
+
!normalized.startsWith('\0') &&
|
|
149
|
+
!/^[a-zA-Z]+:/.test(normalized)
|
|
150
|
+
)
|
|
151
|
+
normalized = normalizeFilePath(resolve(root, normalized));
|
|
152
|
+
return resolveExtensionlessAbsoluteId(normalized);
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
export {
|
|
156
|
+
buildResolutionCandidates,
|
|
157
|
+
buildSourceCandidates,
|
|
158
|
+
canonicalizeResolvedId,
|
|
159
|
+
checkFileDenial,
|
|
160
|
+
clearNormalizeFilePathCache,
|
|
161
|
+
debugLog,
|
|
162
|
+
dedupePatterns,
|
|
163
|
+
dedupeViolationKey,
|
|
164
|
+
getOrCreate,
|
|
165
|
+
isFileExcluded,
|
|
166
|
+
isInsideDirectory,
|
|
167
|
+
matchesDebugFilter,
|
|
168
|
+
normalizeFilePath,
|
|
169
|
+
relativizePath,
|
|
170
|
+
shouldDeferViolation,
|
|
171
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MARKER_PREFIX,
|
|
3
|
+
MOCK_BUILD_PREFIX,
|
|
4
|
+
MOCK_EDGE_PREFIX,
|
|
5
|
+
MOCK_MODULE_ID,
|
|
6
|
+
MOCK_RUNTIME_PREFIX,
|
|
7
|
+
} from './constants.js';
|
|
8
|
+
import { ViolationInfo } from './trace.js';
|
|
9
|
+
type MockAccessMode = 'error' | 'warn' | 'off';
|
|
10
|
+
export declare const RUNTIME_SUGGESTION_TEXT: string;
|
|
11
|
+
export declare function mockRuntimeModuleIdFromViolation(
|
|
12
|
+
info: ViolationInfo,
|
|
13
|
+
mode: MockAccessMode,
|
|
14
|
+
root: string,
|
|
15
|
+
): string;
|
|
16
|
+
export declare function makeMockEdgeModuleId(exports: Array<string>, runtimeId: string): string;
|
|
17
|
+
export declare function loadSilentMockModule(): {
|
|
18
|
+
code: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function generateSelfContainedMockModule(exportNames: Array<string>): {
|
|
21
|
+
code: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function generateDevSelfDenialModule(
|
|
24
|
+
exportNames: Array<string>,
|
|
25
|
+
runtimeId: string,
|
|
26
|
+
): {
|
|
27
|
+
code: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function loadMockEdgeModule(encodedPayload: string): {
|
|
30
|
+
code: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function loadMockRuntimeModule(encodedPayload: string): {
|
|
33
|
+
code: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function loadMarkerModule(): {
|
|
36
|
+
code: string;
|
|
37
|
+
};
|
|
38
|
+
export { MARKER_PREFIX, MOCK_BUILD_PREFIX, MOCK_EDGE_PREFIX, MOCK_MODULE_ID, MOCK_RUNTIME_PREFIX };
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { MOCK_EDGE_PREFIX, MOCK_MODULE_ID, MOCK_RUNTIME_PREFIX } from './constants.js';
|
|
2
|
+
import { relativizePath } from './utils.js';
|
|
3
|
+
import { CLIENT_ENV_SUGGESTIONS } from './trace.js';
|
|
4
|
+
import { isValidExportName } from './analysis.js';
|
|
5
|
+
//#region src/import-protection/virtualModules.ts
|
|
6
|
+
function toBase64Url(input) {
|
|
7
|
+
return Buffer.from(input, 'utf8').toString('base64url');
|
|
8
|
+
}
|
|
9
|
+
function fromBase64Url(input) {
|
|
10
|
+
return Buffer.from(input, 'base64url').toString('utf8');
|
|
11
|
+
}
|
|
12
|
+
var RUNTIME_SUGGESTION_TEXT =
|
|
13
|
+
'Fix: ' +
|
|
14
|
+
CLIENT_ENV_SUGGESTIONS.join('. ') +
|
|
15
|
+
'. To disable these runtime diagnostics, set importProtection.mockAccess: "off".';
|
|
16
|
+
function mockRuntimeModuleIdFromViolation(info, mode, root) {
|
|
17
|
+
if (mode === 'off') return MOCK_MODULE_ID;
|
|
18
|
+
if (info.env !== 'client') return MOCK_MODULE_ID;
|
|
19
|
+
const rel = (p) => relativizePath(p, root);
|
|
20
|
+
const trace = info.trace.map((s) => {
|
|
21
|
+
const file = rel(s.file);
|
|
22
|
+
if (s.line == null) return file;
|
|
23
|
+
return `${file}:${s.line}:${s.column ?? 1}`;
|
|
24
|
+
});
|
|
25
|
+
const payload = {
|
|
26
|
+
env: info.env,
|
|
27
|
+
importer: info.importer,
|
|
28
|
+
specifier: info.specifier,
|
|
29
|
+
trace,
|
|
30
|
+
mode,
|
|
31
|
+
};
|
|
32
|
+
return `${MOCK_RUNTIME_PREFIX}${toBase64Url(JSON.stringify(payload))}`;
|
|
33
|
+
}
|
|
34
|
+
function makeMockEdgeModuleId(exports, runtimeId) {
|
|
35
|
+
return `${MOCK_EDGE_PREFIX}${toBase64Url(
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
exports,
|
|
38
|
+
runtimeId,
|
|
39
|
+
}),
|
|
40
|
+
)}`;
|
|
41
|
+
}
|
|
42
|
+
function generateMockCode(diagnostics) {
|
|
43
|
+
const fnName = diagnostics ? '__createMock' : 'createMock';
|
|
44
|
+
const hasDiag = !!diagnostics;
|
|
45
|
+
return `
|
|
46
|
+
${
|
|
47
|
+
hasDiag
|
|
48
|
+
? `const __meta = ${JSON.stringify(diagnostics.meta)};
|
|
49
|
+
const __mode = ${JSON.stringify(diagnostics.mode)};
|
|
50
|
+
|
|
51
|
+
const __seen = new Set();
|
|
52
|
+
function __report(action, accessPath) {
|
|
53
|
+
if (__mode === 'off') return;
|
|
54
|
+
const key = action + ':' + accessPath;
|
|
55
|
+
if (__seen.has(key)) return;
|
|
56
|
+
__seen.add(key);
|
|
57
|
+
|
|
58
|
+
const traceLines = Array.isArray(__meta.trace) && __meta.trace.length
|
|
59
|
+
? "\\n\\nTrace:\\n" + __meta.trace.map((t, i) => ' ' + (i + 1) + '. ' + String(t)).join('\\n')
|
|
60
|
+
: '';
|
|
61
|
+
|
|
62
|
+
const msg =
|
|
63
|
+
'[import-protection] Mocked import used in dev client\\n\\n' +
|
|
64
|
+
'Denied import: "' + __meta.specifier + '"\\n' +
|
|
65
|
+
'Importer: ' + __meta.importer + '\\n' +
|
|
66
|
+
'Access: ' + accessPath + ' (' + action + ')' +
|
|
67
|
+
traceLines +
|
|
68
|
+
'\\n\\n' + ${JSON.stringify(RUNTIME_SUGGESTION_TEXT)};
|
|
69
|
+
|
|
70
|
+
const err = new Error(msg);
|
|
71
|
+
if (__mode === 'warn') {
|
|
72
|
+
console.warn(err);
|
|
73
|
+
} else {
|
|
74
|
+
console.error(err);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`
|
|
78
|
+
: ''
|
|
79
|
+
}/* @__NO_SIDE_EFFECTS__ */
|
|
80
|
+
function ${fnName}(name) {
|
|
81
|
+
const fn = function () {};
|
|
82
|
+
fn.prototype.name = name;
|
|
83
|
+
const children = Object.create(null);
|
|
84
|
+
const proxy = new Proxy(fn, {
|
|
85
|
+
get(_target, prop) {
|
|
86
|
+
if (prop === '__esModule') return true;
|
|
87
|
+
if (prop === 'default') return proxy;
|
|
88
|
+
if (prop === 'caller') return null;
|
|
89
|
+
if (prop === 'then') return (f) => Promise.resolve(f(proxy));
|
|
90
|
+
if (prop === 'catch') return () => Promise.resolve(proxy);
|
|
91
|
+
if (prop === 'finally') return (f) => { f(); return Promise.resolve(proxy); };${`
|
|
92
|
+
if (prop === Symbol.toPrimitive) {
|
|
93
|
+
return () => {
|
|
94
|
+
${hasDiag ? `__report('toPrimitive', name);` : ''}
|
|
95
|
+
return '[import-protection mock]';
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (prop === 'toString' || prop === 'valueOf' || prop === 'toJSON') {
|
|
99
|
+
return () => {
|
|
100
|
+
${hasDiag ? `__report(String(prop), name);` : ''}
|
|
101
|
+
return '[import-protection mock]';
|
|
102
|
+
};
|
|
103
|
+
}`}
|
|
104
|
+
if (typeof prop === 'symbol') return undefined;
|
|
105
|
+
if (!(prop in children)) {
|
|
106
|
+
children[prop] = ${fnName}(name + '.' + prop);
|
|
107
|
+
}
|
|
108
|
+
return children[prop];
|
|
109
|
+
},
|
|
110
|
+
apply() {
|
|
111
|
+
${
|
|
112
|
+
hasDiag
|
|
113
|
+
? `__report('call', name + '()');
|
|
114
|
+
return ${fnName}(name + '()');`
|
|
115
|
+
: `return ${fnName}(name + '()');`
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
construct() {
|
|
119
|
+
${
|
|
120
|
+
hasDiag
|
|
121
|
+
? `__report('construct', 'new ' + name);
|
|
122
|
+
return ${fnName}('new ' + name);`
|
|
123
|
+
: `return ${fnName}('new ' + name);`
|
|
124
|
+
}
|
|
125
|
+
},${
|
|
126
|
+
hasDiag
|
|
127
|
+
? `
|
|
128
|
+
set(_target, prop) {
|
|
129
|
+
__report('set', name + '.' + String(prop));
|
|
130
|
+
return true;
|
|
131
|
+
},`
|
|
132
|
+
: ''
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return proxy;
|
|
136
|
+
}
|
|
137
|
+
const mock = /* @__PURE__ */ ${fnName}('mock');
|
|
138
|
+
export default mock;
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
function loadSilentMockModule() {
|
|
142
|
+
return { code: generateMockCode() };
|
|
143
|
+
}
|
|
144
|
+
function filterExportNames(exports) {
|
|
145
|
+
return exports.filter((n) => n.length > 0 && n !== 'default');
|
|
146
|
+
}
|
|
147
|
+
function generateExportLines(names) {
|
|
148
|
+
const lines = [];
|
|
149
|
+
const stringExports = [];
|
|
150
|
+
for (let i = 0; i < names.length; i++) {
|
|
151
|
+
const n = names[i];
|
|
152
|
+
if (isValidExportName(n)) lines.push(`export const ${n} = mock.${n};`);
|
|
153
|
+
else {
|
|
154
|
+
const alias = `__tss_str_${i}`;
|
|
155
|
+
lines.push(`const ${alias} = mock[${JSON.stringify(n)}];`);
|
|
156
|
+
stringExports.push({
|
|
157
|
+
alias,
|
|
158
|
+
name: n,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (stringExports.length > 0) {
|
|
163
|
+
const reexports = stringExports
|
|
164
|
+
.map((s) => `${s.alias} as ${JSON.stringify(s.name)}`)
|
|
165
|
+
.join(', ');
|
|
166
|
+
lines.push(`export { ${reexports} };`);
|
|
167
|
+
}
|
|
168
|
+
return lines;
|
|
169
|
+
}
|
|
170
|
+
function generateSelfContainedMockModule(exportNames) {
|
|
171
|
+
return {
|
|
172
|
+
code: `${generateMockCode()}
|
|
173
|
+
${generateExportLines(filterExportNames(exportNames)).join('\n')}
|
|
174
|
+
`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function generateDevSelfDenialModule(exportNames, runtimeId) {
|
|
178
|
+
const exportLines = generateExportLines(filterExportNames(exportNames));
|
|
179
|
+
return {
|
|
180
|
+
code: `import mock from ${JSON.stringify(runtimeId)};
|
|
181
|
+
${exportLines.join('\n')}
|
|
182
|
+
export default mock;
|
|
183
|
+
`,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function loadMockEdgeModule(encodedPayload) {
|
|
187
|
+
let payload;
|
|
188
|
+
try {
|
|
189
|
+
payload = JSON.parse(fromBase64Url(encodedPayload));
|
|
190
|
+
} catch {
|
|
191
|
+
payload = { exports: [] };
|
|
192
|
+
}
|
|
193
|
+
const names = filterExportNames(payload.exports ?? []);
|
|
194
|
+
const runtimeId =
|
|
195
|
+
typeof payload.runtimeId === 'string' && payload.runtimeId.length > 0
|
|
196
|
+
? payload.runtimeId
|
|
197
|
+
: MOCK_MODULE_ID;
|
|
198
|
+
const exportLines = generateExportLines(names);
|
|
199
|
+
return {
|
|
200
|
+
code: `import mock from ${JSON.stringify(runtimeId)};
|
|
201
|
+
${exportLines.join('\n')}
|
|
202
|
+
export default mock;
|
|
203
|
+
`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function loadMockRuntimeModule(encodedPayload) {
|
|
207
|
+
let payload;
|
|
208
|
+
try {
|
|
209
|
+
payload = JSON.parse(fromBase64Url(encodedPayload));
|
|
210
|
+
} catch {
|
|
211
|
+
payload = {};
|
|
212
|
+
}
|
|
213
|
+
const mode = payload.mode === 'warn' || payload.mode === 'off' ? payload.mode : 'error';
|
|
214
|
+
return {
|
|
215
|
+
code: generateMockCode({
|
|
216
|
+
meta: {
|
|
217
|
+
env: String(payload.env ?? ''),
|
|
218
|
+
importer: String(payload.importer ?? ''),
|
|
219
|
+
specifier: String(payload.specifier ?? ''),
|
|
220
|
+
trace: Array.isArray(payload.trace) ? payload.trace : [],
|
|
221
|
+
},
|
|
222
|
+
mode,
|
|
223
|
+
}),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
var MARKER_MODULE_RESULT = { code: 'export {}' };
|
|
227
|
+
function loadMarkerModule() {
|
|
228
|
+
return MARKER_MODULE_RESULT;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
export {
|
|
232
|
+
RUNTIME_SUGGESTION_TEXT,
|
|
233
|
+
generateDevSelfDenialModule,
|
|
234
|
+
generateSelfContainedMockModule,
|
|
235
|
+
loadMarkerModule,
|
|
236
|
+
loadMockEdgeModule,
|
|
237
|
+
loadMockRuntimeModule,
|
|
238
|
+
loadSilentMockModule,
|
|
239
|
+
makeMockEdgeModuleId,
|
|
240
|
+
mockRuntimeModuleIdFromViolation,
|
|
241
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { TanStackStartInputConfig } from './schema.js';
|
|
2
|
+
export type {
|
|
3
|
+
StartCompilerImportTransform,
|
|
4
|
+
StartCompilerTransformCandidate,
|
|
5
|
+
StartCompilerTransformContext,
|
|
6
|
+
TanStackStartCoreOptions,
|
|
7
|
+
} from './types.js';
|
|
8
|
+
export { START_ENVIRONMENT_NAMES } from './constants.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TanStackStartOutputConfig } from './schema.js';
|
|
2
|
+
import {
|
|
3
|
+
NormalizedBasePaths,
|
|
4
|
+
NormalizedOutputDirectories,
|
|
5
|
+
TanStackStartCoreOptions,
|
|
6
|
+
} from './types.js';
|
|
7
|
+
export interface ResolvedStartEntryPlan {
|
|
8
|
+
srcDirectory: string;
|
|
9
|
+
startFilePath: string | undefined;
|
|
10
|
+
routerFilePath: string;
|
|
11
|
+
entryPaths: {
|
|
12
|
+
client: string;
|
|
13
|
+
server: string;
|
|
14
|
+
start: string;
|
|
15
|
+
router: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare function normalizePublicBase(base: string | undefined): string;
|
|
19
|
+
export declare function deriveRouterBasepath(opts: {
|
|
20
|
+
configuredBasepath: string | undefined;
|
|
21
|
+
publicBase: string;
|
|
22
|
+
}): string;
|
|
23
|
+
export declare function shouldRewriteDevBasepath(opts: {
|
|
24
|
+
command: 'serve' | 'build';
|
|
25
|
+
middlewareMode: boolean | undefined;
|
|
26
|
+
routerBasepath: string;
|
|
27
|
+
publicBase: string;
|
|
28
|
+
}): boolean;
|
|
29
|
+
export declare function createNormalizedBasePaths(opts: {
|
|
30
|
+
publicBase: string;
|
|
31
|
+
}): NormalizedBasePaths;
|
|
32
|
+
export declare function createNormalizedOutputDirectories(opts: {
|
|
33
|
+
client: string;
|
|
34
|
+
server: string;
|
|
35
|
+
}): NormalizedOutputDirectories;
|
|
36
|
+
export declare function createServerFnBasePath(opts: {
|
|
37
|
+
routerBasepath: string;
|
|
38
|
+
serverFnBase: string;
|
|
39
|
+
}): string;
|
|
40
|
+
export declare function resolveStartEntryPlan(opts: {
|
|
41
|
+
root: string;
|
|
42
|
+
startConfig: TanStackStartOutputConfig;
|
|
43
|
+
defaultEntryPaths: TanStackStartCoreOptions['defaultEntryPaths'];
|
|
44
|
+
}): ResolvedStartEntryPlan;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { resolveEntry } from './resolve-entries.js';
|
|
2
|
+
import { joinPaths } from '@tanstack/router-core';
|
|
3
|
+
import { join } from 'pathe';
|
|
4
|
+
//#region src/planning.ts
|
|
5
|
+
function normalizePublicBase(base) {
|
|
6
|
+
const resolvedBase = base ?? '/';
|
|
7
|
+
if (isFullUrl(resolvedBase)) return resolvedBase;
|
|
8
|
+
return joinPaths(['/', resolvedBase, '/']);
|
|
9
|
+
}
|
|
10
|
+
function deriveRouterBasepath(opts) {
|
|
11
|
+
if (opts.configuredBasepath !== void 0) return opts.configuredBasepath;
|
|
12
|
+
if (isFullUrl(opts.publicBase)) return '/';
|
|
13
|
+
return opts.publicBase.replace(/^\/|\/$/g, '');
|
|
14
|
+
}
|
|
15
|
+
function shouldRewriteDevBasepath(opts) {
|
|
16
|
+
if (opts.command !== 'serve' || opts.middlewareMode) return false;
|
|
17
|
+
return !joinPaths(['/', opts.routerBasepath, '/']).startsWith(
|
|
18
|
+
joinPaths(['/', opts.publicBase, '/']),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
function createNormalizedBasePaths(opts) {
|
|
22
|
+
return {
|
|
23
|
+
publicBase: opts.publicBase,
|
|
24
|
+
assetBase: {
|
|
25
|
+
dev: opts.publicBase,
|
|
26
|
+
build: opts.publicBase,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createNormalizedOutputDirectories(opts) {
|
|
31
|
+
return {
|
|
32
|
+
client: opts.client,
|
|
33
|
+
server: opts.server,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createServerFnBasePath(opts) {
|
|
37
|
+
return joinPaths(['/', opts.routerBasepath, opts.serverFnBase, '/']);
|
|
38
|
+
}
|
|
39
|
+
function resolveStartEntryPlan(opts) {
|
|
40
|
+
const srcDirectory = join(opts.root, opts.startConfig.srcDirectory);
|
|
41
|
+
const startFilePath = resolveEntry({
|
|
42
|
+
type: 'start entry',
|
|
43
|
+
configuredEntry: opts.startConfig.start.entry,
|
|
44
|
+
defaultEntry: 'start',
|
|
45
|
+
resolvedSrcDirectory: srcDirectory,
|
|
46
|
+
required: false,
|
|
47
|
+
});
|
|
48
|
+
const routerFilePath = resolveEntry({
|
|
49
|
+
type: 'router entry',
|
|
50
|
+
configuredEntry: opts.startConfig.router.entry,
|
|
51
|
+
defaultEntry: 'router',
|
|
52
|
+
resolvedSrcDirectory: srcDirectory,
|
|
53
|
+
required: true,
|
|
54
|
+
});
|
|
55
|
+
const clientEntryPath = resolveEntry({
|
|
56
|
+
type: 'client entry',
|
|
57
|
+
configuredEntry: opts.startConfig.client.entry,
|
|
58
|
+
defaultEntry: 'client',
|
|
59
|
+
resolvedSrcDirectory: srcDirectory,
|
|
60
|
+
required: false,
|
|
61
|
+
});
|
|
62
|
+
const serverEntryPath = resolveEntry({
|
|
63
|
+
type: 'server entry',
|
|
64
|
+
configuredEntry: opts.startConfig.server.entry,
|
|
65
|
+
defaultEntry: 'server',
|
|
66
|
+
resolvedSrcDirectory: srcDirectory,
|
|
67
|
+
required: false,
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
srcDirectory,
|
|
71
|
+
startFilePath,
|
|
72
|
+
routerFilePath,
|
|
73
|
+
entryPaths: {
|
|
74
|
+
client: clientEntryPath ?? opts.defaultEntryPaths.client,
|
|
75
|
+
server: serverEntryPath ?? opts.defaultEntryPaths.server,
|
|
76
|
+
start: startFilePath ?? opts.defaultEntryPaths.start,
|
|
77
|
+
router: routerFilePath,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function isFullUrl(str) {
|
|
82
|
+
try {
|
|
83
|
+
new URL(str);
|
|
84
|
+
return true;
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
export {
|
|
91
|
+
createNormalizedBasePaths,
|
|
92
|
+
createNormalizedOutputDirectories,
|
|
93
|
+
createServerFnBasePath,
|
|
94
|
+
deriveRouterBasepath,
|
|
95
|
+
normalizePublicBase,
|
|
96
|
+
resolveStartEntryPlan,
|
|
97
|
+
shouldRewriteDevBasepath,
|
|
98
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TanStackStartOutputConfig } from './schema.js';
|
|
2
|
+
export interface StartPostBuildAdapter {
|
|
3
|
+
getClientOutputDirectory: () => string;
|
|
4
|
+
prerender: (startConfig: TanStackStartOutputConfig) => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare function postBuild({
|
|
7
|
+
startConfig,
|
|
8
|
+
adapter,
|
|
9
|
+
}: {
|
|
10
|
+
startConfig: TanStackStartOutputConfig;
|
|
11
|
+
adapter: StartPostBuildAdapter;
|
|
12
|
+
}): Promise<void>;
|