@tanstack/start-plugin-core 1.167.35 → 1.169.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/esm/import-protection/adapterUtils.d.ts +27 -0
  2. package/dist/esm/import-protection/adapterUtils.js +31 -0
  3. package/dist/esm/import-protection/adapterUtils.js.map +1 -0
  4. package/dist/esm/import-protection/analysis.d.ts +36 -0
  5. package/dist/esm/import-protection/analysis.js +407 -0
  6. package/dist/esm/import-protection/analysis.js.map +1 -0
  7. package/dist/esm/{import-protection-plugin → import-protection}/ast.js +1 -1
  8. package/dist/esm/import-protection/ast.js.map +1 -0
  9. package/dist/esm/import-protection/constants.d.ts +11 -0
  10. package/dist/esm/{import-protection-plugin → import-protection}/constants.js +7 -2
  11. package/dist/esm/import-protection/constants.js.map +1 -0
  12. package/dist/esm/{import-protection-plugin → import-protection}/defaults.js +1 -1
  13. package/dist/esm/import-protection/defaults.js.map +1 -0
  14. package/dist/esm/{import-protection-plugin → import-protection}/extensionlessAbsoluteIdResolver.js +2 -2
  15. package/dist/esm/import-protection/extensionlessAbsoluteIdResolver.js.map +1 -0
  16. package/dist/esm/{import-protection-plugin → import-protection}/matchers.js +1 -1
  17. package/dist/esm/import-protection/matchers.js.map +1 -0
  18. package/dist/esm/{import-protection-plugin/rewriteDeniedImports.d.ts → import-protection/rewrite.d.ts} +0 -4
  19. package/dist/esm/import-protection/rewrite.js +121 -0
  20. package/dist/esm/import-protection/rewrite.js.map +1 -0
  21. package/dist/esm/{import-protection-plugin → import-protection}/sourceLocation.d.ts +32 -3
  22. package/dist/esm/{import-protection-plugin → import-protection}/sourceLocation.js +65 -10
  23. package/dist/esm/import-protection/sourceLocation.js.map +1 -0
  24. package/dist/esm/{import-protection-plugin → import-protection}/trace.d.ts +0 -1
  25. package/dist/esm/{import-protection-plugin → import-protection}/trace.js +1 -1
  26. package/dist/esm/import-protection/trace.js.map +1 -0
  27. package/dist/esm/{import-protection-plugin → import-protection}/utils.d.ts +18 -1
  28. package/dist/esm/{import-protection-plugin → import-protection}/utils.js +13 -20
  29. package/dist/esm/import-protection/utils.js.map +1 -0
  30. package/dist/esm/import-protection/virtualModules.d.ts +25 -0
  31. package/dist/esm/{import-protection-plugin → import-protection}/virtualModules.js +5 -117
  32. package/dist/esm/import-protection/virtualModules.js.map +1 -0
  33. package/dist/esm/index.d.ts +1 -5
  34. package/dist/esm/index.js +2 -4
  35. package/dist/esm/post-build.d.ts +9 -0
  36. package/dist/esm/post-build.js +37 -0
  37. package/dist/esm/post-build.js.map +1 -0
  38. package/dist/esm/prerender.d.ts +11 -0
  39. package/dist/esm/prerender.js +159 -0
  40. package/dist/esm/prerender.js.map +1 -0
  41. package/dist/esm/rsbuild/dev-server.d.ts +21 -0
  42. package/dist/esm/rsbuild/dev-server.js +76 -0
  43. package/dist/esm/rsbuild/dev-server.js.map +1 -0
  44. package/dist/esm/rsbuild/import-protection.d.ts +10 -0
  45. package/dist/esm/rsbuild/import-protection.js +775 -0
  46. package/dist/esm/rsbuild/import-protection.js.map +1 -0
  47. package/dist/esm/rsbuild/index.d.ts +4 -0
  48. package/dist/esm/rsbuild/index.js +3 -0
  49. package/dist/esm/rsbuild/normalized-client-build.d.ts +18 -0
  50. package/dist/esm/rsbuild/normalized-client-build.js +207 -0
  51. package/dist/esm/rsbuild/normalized-client-build.js.map +1 -0
  52. package/dist/esm/rsbuild/planning.d.ts +52 -0
  53. package/dist/esm/rsbuild/planning.js +108 -0
  54. package/dist/esm/rsbuild/planning.js.map +1 -0
  55. package/dist/esm/rsbuild/plugin.d.ts +4 -0
  56. package/dist/esm/rsbuild/plugin.js +344 -0
  57. package/dist/esm/rsbuild/plugin.js.map +1 -0
  58. package/dist/esm/rsbuild/post-build.d.ts +6 -0
  59. package/dist/esm/rsbuild/post-build.js +57 -0
  60. package/dist/esm/rsbuild/post-build.js.map +1 -0
  61. package/dist/esm/rsbuild/schema.d.ts +3372 -0
  62. package/dist/esm/rsbuild/schema.js +12 -0
  63. package/dist/esm/rsbuild/schema.js.map +1 -0
  64. package/dist/esm/rsbuild/start-compiler-host.d.ts +20 -0
  65. package/dist/esm/rsbuild/start-compiler-host.js +150 -0
  66. package/dist/esm/rsbuild/start-compiler-host.js.map +1 -0
  67. package/dist/esm/rsbuild/start-router-plugin.d.ts +18 -0
  68. package/dist/esm/rsbuild/start-router-plugin.js +63 -0
  69. package/dist/esm/rsbuild/start-router-plugin.js.map +1 -0
  70. package/dist/esm/rsbuild/swc-rsc.d.ts +14 -0
  71. package/dist/esm/rsbuild/swc-rsc.js +93 -0
  72. package/dist/esm/rsbuild/swc-rsc.js.map +1 -0
  73. package/dist/esm/rsbuild/types.d.ts +17 -0
  74. package/dist/esm/rsbuild/types.js +0 -0
  75. package/dist/esm/rsbuild/virtual-modules.d.ts +53 -0
  76. package/dist/esm/rsbuild/virtual-modules.js +287 -0
  77. package/dist/esm/rsbuild/virtual-modules.js.map +1 -0
  78. package/dist/esm/schema.d.ts +43 -43
  79. package/dist/esm/start-compiler/compiler.d.ts +1 -1
  80. package/dist/esm/start-compiler/compiler.js +80 -9
  81. package/dist/esm/start-compiler/compiler.js.map +1 -1
  82. package/dist/esm/start-compiler/handleCreateServerFn.js +9 -0
  83. package/dist/esm/start-compiler/handleCreateServerFn.js.map +1 -1
  84. package/dist/esm/start-compiler/host.js +5 -1
  85. package/dist/esm/start-compiler/host.js.map +1 -1
  86. package/dist/esm/start-compiler/types.d.ts +1 -0
  87. package/dist/esm/utils.d.ts +1 -0
  88. package/dist/esm/utils.js +10 -1
  89. package/dist/esm/utils.js.map +1 -1
  90. package/dist/esm/{import-protection-plugin → vite/import-protection-plugin}/plugin.js +41 -92
  91. package/dist/esm/vite/import-protection-plugin/plugin.js.map +1 -0
  92. package/dist/esm/{import-protection-plugin → vite/import-protection-plugin}/types.d.ts +5 -5
  93. package/dist/esm/vite/import-protection-plugin/virtualModules.d.ts +8 -0
  94. package/dist/esm/vite/import-protection-plugin/virtualModules.js +49 -0
  95. package/dist/esm/vite/import-protection-plugin/virtualModules.js.map +1 -0
  96. package/dist/esm/vite/index.d.ts +5 -0
  97. package/dist/esm/vite/index.js +4 -0
  98. package/dist/esm/vite/plugin.js +1 -1
  99. package/dist/esm/vite/plugin.js.map +1 -1
  100. package/dist/esm/vite/post-server-build.js +14 -32
  101. package/dist/esm/vite/post-server-build.js.map +1 -1
  102. package/dist/esm/vite/prerender.d.ts +2 -2
  103. package/dist/esm/vite/prerender.js +17 -147
  104. package/dist/esm/vite/prerender.js.map +1 -1
  105. package/dist/esm/vite/schema.d.ts +23 -23
  106. package/dist/esm/vite/start-compiler-plugin/hot-update.d.ts +2 -0
  107. package/dist/esm/vite/start-compiler-plugin/hot-update.js +16 -0
  108. package/dist/esm/vite/start-compiler-plugin/hot-update.js.map +1 -0
  109. package/dist/esm/vite/start-compiler-plugin/module-specifier.js +9 -4
  110. package/dist/esm/vite/start-compiler-plugin/module-specifier.js.map +1 -1
  111. package/dist/esm/vite/start-compiler-plugin/plugin.js +86 -13
  112. package/dist/esm/vite/start-compiler-plugin/plugin.js.map +1 -1
  113. package/package.json +32 -4
  114. package/src/import-protection/INTERNALS.md +266 -0
  115. package/src/import-protection/adapterUtils.ts +94 -0
  116. package/src/import-protection/analysis.ts +853 -0
  117. package/src/{import-protection-plugin → import-protection}/constants.ts +7 -0
  118. package/src/import-protection/rewrite.ts +229 -0
  119. package/src/{import-protection-plugin → import-protection}/sourceLocation.ts +125 -9
  120. package/src/{import-protection-plugin → import-protection}/trace.ts +0 -1
  121. package/src/{import-protection-plugin → import-protection}/utils.ts +36 -21
  122. package/src/{import-protection-plugin → import-protection}/virtualModules.ts +30 -177
  123. package/src/index.ts +1 -8
  124. package/src/post-build.ts +64 -0
  125. package/src/prerender.ts +292 -0
  126. package/src/rsbuild/INTERNALS-import-protection.md +169 -0
  127. package/src/rsbuild/dev-server.ts +129 -0
  128. package/src/rsbuild/import-protection.ts +1599 -0
  129. package/src/rsbuild/index.ts +4 -0
  130. package/src/rsbuild/normalized-client-build.ts +346 -0
  131. package/src/rsbuild/planning.ts +234 -0
  132. package/src/rsbuild/plugin.ts +754 -0
  133. package/src/rsbuild/post-build.ts +96 -0
  134. package/src/rsbuild/schema.ts +31 -0
  135. package/src/rsbuild/start-compiler-host.ts +250 -0
  136. package/src/rsbuild/start-router-plugin.ts +86 -0
  137. package/src/rsbuild/swc-rsc.ts +166 -0
  138. package/src/rsbuild/types.ts +20 -0
  139. package/src/rsbuild/virtual-modules.ts +565 -0
  140. package/src/start-compiler/compiler.ts +153 -19
  141. package/src/start-compiler/handleCreateServerFn.ts +18 -0
  142. package/src/start-compiler/types.ts +1 -0
  143. package/src/utils.ts +14 -0
  144. package/src/vite/import-protection-plugin/INTERNALS.md +187 -0
  145. package/src/{import-protection-plugin → vite/import-protection-plugin}/plugin.ts +73 -158
  146. package/src/{import-protection-plugin → vite/import-protection-plugin}/types.ts +5 -5
  147. package/src/vite/import-protection-plugin/virtualModules.ts +122 -0
  148. package/src/vite/index.ts +8 -0
  149. package/src/vite/plugin.ts +1 -1
  150. package/src/vite/post-server-build.ts +14 -57
  151. package/src/vite/prerender.ts +19 -260
  152. package/src/vite/start-compiler-plugin/hot-update.ts +24 -0
  153. package/src/vite/start-compiler-plugin/module-specifier.ts +15 -5
  154. package/src/vite/start-compiler-plugin/plugin.ts +193 -18
  155. package/dist/esm/import-protection-plugin/ast.js.map +0 -1
  156. package/dist/esm/import-protection-plugin/constants.d.ts +0 -6
  157. package/dist/esm/import-protection-plugin/constants.js.map +0 -1
  158. package/dist/esm/import-protection-plugin/defaults.js.map +0 -1
  159. package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js.map +0 -1
  160. package/dist/esm/import-protection-plugin/matchers.js.map +0 -1
  161. package/dist/esm/import-protection-plugin/plugin.js.map +0 -1
  162. package/dist/esm/import-protection-plugin/postCompileUsage.d.ts +0 -13
  163. package/dist/esm/import-protection-plugin/postCompileUsage.js +0 -63
  164. package/dist/esm/import-protection-plugin/postCompileUsage.js.map +0 -1
  165. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js +0 -205
  166. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js.map +0 -1
  167. package/dist/esm/import-protection-plugin/sourceLocation.js.map +0 -1
  168. package/dist/esm/import-protection-plugin/trace.js.map +0 -1
  169. package/dist/esm/import-protection-plugin/utils.js.map +0 -1
  170. package/dist/esm/import-protection-plugin/virtualModules.d.ts +0 -78
  171. package/dist/esm/import-protection-plugin/virtualModules.js.map +0 -1
  172. package/dist/esm/start-compiler/load-module.d.ts +0 -14
  173. package/dist/esm/start-compiler/load-module.js +0 -18
  174. package/dist/esm/start-compiler/load-module.js.map +0 -1
  175. package/src/import-protection-plugin/INTERNALS.md +0 -700
  176. package/src/import-protection-plugin/postCompileUsage.ts +0 -100
  177. package/src/import-protection-plugin/rewriteDeniedImports.ts +0 -379
  178. package/src/start-compiler/load-module.ts +0 -31
  179. /package/dist/esm/{import-protection-plugin → import-protection}/ast.d.ts +0 -0
  180. /package/dist/esm/{import-protection-plugin → import-protection}/defaults.d.ts +0 -0
  181. /package/dist/esm/{import-protection-plugin → import-protection}/extensionlessAbsoluteIdResolver.d.ts +0 -0
  182. /package/dist/esm/{import-protection-plugin → import-protection}/matchers.d.ts +0 -0
  183. /package/dist/esm/{import-protection-plugin → vite/import-protection-plugin}/plugin.d.ts +0 -0
  184. /package/src/{import-protection-plugin → import-protection}/ast.ts +0 -0
  185. /package/src/{import-protection-plugin → import-protection}/defaults.ts +0 -0
  186. /package/src/{import-protection-plugin → import-protection}/extensionlessAbsoluteIdResolver.ts +0 -0
  187. /package/src/{import-protection-plugin → import-protection}/matchers.ts +0 -0
@@ -32,7 +32,11 @@ function mergeServerFnsById(current, next) {
32
32
  current[id] = fn;
33
33
  }
34
34
  }
35
+ function matchesCodeFilters(code, filters) {
36
+ for (const pattern of filters) if (pattern.test(code)) return true;
37
+ return false;
38
+ }
35
39
  //#endregion
36
- export { createStartCompiler, mergeServerFnsById };
40
+ export { createStartCompiler, matchesCodeFilters, mergeServerFnsById };
37
41
 
38
42
  //# sourceMappingURL=host.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.js","names":[],"sources":["../../../src/start-compiler/host.ts"],"sourcesContent":["import { LookupKindsPerEnv, StartCompiler } from './compiler'\nimport { getLookupConfigurationsForEnv } from './config'\nimport type { CompileStartFrameworkOptions } from '../types'\nimport type {\n DevServerFnModuleSpecifierEncoder,\n GenerateFunctionIdFnOptional,\n ServerFn,\n} from './types'\n\nexport interface CreateStartCompilerOptions {\n env: 'client' | 'server'\n envName: string\n root: string\n framework: CompileStartFrameworkOptions\n providerEnvName: string\n mode: 'dev' | 'build'\n generateFunctionId?: GenerateFunctionIdFnOptional\n onServerFnsById?: (d: Record<string, ServerFn>) => void\n getKnownServerFns: () => Record<string, ServerFn>\n encodeModuleSpecifierInDev?: DevServerFnModuleSpecifierEncoder\n loadModule: (id: string) => Promise<void>\n resolveId: (id: string, importer?: string) => Promise<string | null>\n}\n\nexport function createStartCompiler(\n options: CreateStartCompilerOptions,\n): StartCompiler {\n return new StartCompiler({\n env: options.env,\n envName: options.envName,\n root: options.root,\n lookupKinds: LookupKindsPerEnv[options.env],\n lookupConfigurations: getLookupConfigurationsForEnv(\n options.env,\n options.framework,\n ),\n mode: options.mode,\n framework: options.framework,\n providerEnvName: options.providerEnvName,\n generateFunctionId: options.generateFunctionId,\n onServerFnsById: options.onServerFnsById,\n getKnownServerFns: options.getKnownServerFns,\n devServerFnModuleSpecifierEncoder: options.encodeModuleSpecifierInDev,\n loadModule: options.loadModule,\n resolveId: options.resolveId,\n })\n}\n\nexport function mergeServerFnsById(\n current: Record<string, ServerFn>,\n next: Record<string, ServerFn>,\n): void {\n for (const [id, fn] of Object.entries(next)) {\n const existing = current[id]\n\n if (existing) {\n current[id] = {\n ...fn,\n isClientReferenced:\n existing.isClientReferenced || fn.isClientReferenced,\n }\n continue\n }\n\n current[id] = fn\n }\n}\n\nexport function matchesCodeFilters(\n code: string,\n filters: ReadonlyArray<RegExp>,\n): boolean {\n for (const pattern of filters) {\n if (pattern.test(code)) {\n return true\n }\n }\n\n return false\n}\n"],"mappings":";;;AAwBA,SAAgB,oBACd,SACe;AACf,QAAO,IAAI,cAAc;EACvB,KAAK,QAAQ;EACb,SAAS,QAAQ;EACjB,MAAM,QAAQ;EACd,aAAa,kBAAkB,QAAQ;EACvC,sBAAsB,8BACpB,QAAQ,KACR,QAAQ,UACT;EACD,MAAM,QAAQ;EACd,WAAW,QAAQ;EACnB,iBAAiB,QAAQ;EACzB,oBAAoB,QAAQ;EAC5B,iBAAiB,QAAQ;EACzB,mBAAmB,QAAQ;EAC3B,mCAAmC,QAAQ;EAC3C,YAAY,QAAQ;EACpB,WAAW,QAAQ;EACpB,CAAC;;AAGJ,SAAgB,mBACd,SACA,MACM;AACN,MAAK,MAAM,CAAC,IAAI,OAAO,OAAO,QAAQ,KAAK,EAAE;EAC3C,MAAM,WAAW,QAAQ;AAEzB,MAAI,UAAU;AACZ,WAAQ,MAAM;IACZ,GAAG;IACH,oBACE,SAAS,sBAAsB,GAAG;IACrC;AACD;;AAGF,UAAQ,MAAM"}
1
+ {"version":3,"file":"host.js","names":[],"sources":["../../../src/start-compiler/host.ts"],"sourcesContent":["import { LookupKindsPerEnv, StartCompiler } from './compiler'\nimport { getLookupConfigurationsForEnv } from './config'\nimport type { CompileStartFrameworkOptions } from '../types'\nimport type {\n DevServerFnModuleSpecifierEncoder,\n GenerateFunctionIdFnOptional,\n ServerFn,\n} from './types'\n\nexport interface CreateStartCompilerOptions {\n env: 'client' | 'server'\n envName: string\n root: string\n framework: CompileStartFrameworkOptions\n providerEnvName: string\n mode: 'dev' | 'build'\n generateFunctionId?: GenerateFunctionIdFnOptional\n onServerFnsById?: (d: Record<string, ServerFn>) => void\n getKnownServerFns: () => Record<string, ServerFn>\n encodeModuleSpecifierInDev?: DevServerFnModuleSpecifierEncoder\n loadModule: (id: string) => Promise<void>\n resolveId: (id: string, importer?: string) => Promise<string | null>\n}\n\nexport function createStartCompiler(\n options: CreateStartCompilerOptions,\n): StartCompiler {\n return new StartCompiler({\n env: options.env,\n envName: options.envName,\n root: options.root,\n lookupKinds: LookupKindsPerEnv[options.env],\n lookupConfigurations: getLookupConfigurationsForEnv(\n options.env,\n options.framework,\n ),\n mode: options.mode,\n framework: options.framework,\n providerEnvName: options.providerEnvName,\n generateFunctionId: options.generateFunctionId,\n onServerFnsById: options.onServerFnsById,\n getKnownServerFns: options.getKnownServerFns,\n devServerFnModuleSpecifierEncoder: options.encodeModuleSpecifierInDev,\n loadModule: options.loadModule,\n resolveId: options.resolveId,\n })\n}\n\nexport function mergeServerFnsById(\n current: Record<string, ServerFn>,\n next: Record<string, ServerFn>,\n): void {\n for (const [id, fn] of Object.entries(next)) {\n const existing = current[id]\n\n if (existing) {\n current[id] = {\n ...fn,\n isClientReferenced:\n existing.isClientReferenced || fn.isClientReferenced,\n }\n continue\n }\n\n current[id] = fn\n }\n}\n\nexport function matchesCodeFilters(\n code: string,\n filters: ReadonlyArray<RegExp>,\n): boolean {\n for (const pattern of filters) {\n if (pattern.test(code)) {\n return true\n }\n }\n\n return false\n}\n"],"mappings":";;;AAwBA,SAAgB,oBACd,SACe;AACf,QAAO,IAAI,cAAc;EACvB,KAAK,QAAQ;EACb,SAAS,QAAQ;EACjB,MAAM,QAAQ;EACd,aAAa,kBAAkB,QAAQ;EACvC,sBAAsB,8BACpB,QAAQ,KACR,QAAQ,UACT;EACD,MAAM,QAAQ;EACd,WAAW,QAAQ;EACnB,iBAAiB,QAAQ;EACzB,oBAAoB,QAAQ;EAC5B,iBAAiB,QAAQ;EACzB,mBAAmB,QAAQ;EAC3B,mCAAmC,QAAQ;EAC3C,YAAY,QAAQ;EACpB,WAAW,QAAQ;EACpB,CAAC;;AAGJ,SAAgB,mBACd,SACA,MACM;AACN,MAAK,MAAM,CAAC,IAAI,OAAO,OAAO,QAAQ,KAAK,EAAE;EAC3C,MAAM,WAAW,QAAQ;AAEzB,MAAI,UAAU;AACZ,WAAQ,MAAM;IACZ,GAAG;IACH,oBACE,SAAS,sBAAsB,GAAG;IACrC;AACD;;AAGF,UAAQ,MAAM;;;AAIlB,SAAgB,mBACd,MACA,SACS;AACT,MAAK,MAAM,WAAW,QACpB,KAAI,QAAQ,KAAK,KAAK,CACpB,QAAO;AAIX,QAAO"}
@@ -11,6 +11,7 @@ export interface CompilationContext {
11
11
  readonly id: string;
12
12
  readonly env: 'client' | 'server';
13
13
  readonly envName: string;
14
+ readonly mode: 'dev' | 'build';
14
15
  readonly root: string;
15
16
  /** The framework being used (e.g., 'react', 'solid') */
16
17
  readonly framework: CompileStartFrameworkOptions;
@@ -8,3 +8,4 @@ export declare function createLogger(prefix: string): {
8
8
  warn: (...args: any) => void;
9
9
  error: (...args: any) => void;
10
10
  };
11
+ export declare function normalizePath(id: string): string;
package/dist/esm/utils.js CHANGED
@@ -1,4 +1,7 @@
1
+ import path from "node:path";
1
2
  //#region src/utils.ts
3
+ var isWindows = typeof process !== "undefined" && process.platform === "win32";
4
+ var windowsSlashRE = /\\/g;
2
5
  /** Read `build.rollupOptions` or `build.rolldownOptions` from a build config. */
3
6
  function getBundlerOptions(build) {
4
7
  return build?.rolldownOptions ?? build?.rollupOptions;
@@ -16,7 +19,13 @@ function createLogger(prefix) {
16
19
  error: (...args) => console.error(label, ...args)
17
20
  };
18
21
  }
22
+ function slash(path) {
23
+ return path.replace(windowsSlashRE, "/");
24
+ }
25
+ function normalizePath(id) {
26
+ return path.posix.normalize(isWindows ? slash(id) : id);
27
+ }
19
28
  //#endregion
20
- export { createLogger, getBundlerOptions, resolveViteId };
29
+ export { createLogger, getBundlerOptions, normalizePath, resolveViteId };
21
30
 
22
31
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["/** Read `build.rollupOptions` or `build.rolldownOptions` from a build config. */\nexport function getBundlerOptions(build: any): any {\n return build?.rolldownOptions ?? build?.rollupOptions\n}\n\nexport function resolveViteId(id: string) {\n return `\\0${id}`\n}\n\nexport function createLogger(prefix: string) {\n const label = `[${prefix}]`\n return {\n log: (...args: any) => console.log(label, ...args),\n debug: (...args: any) => console.debug(label, ...args),\n info: (...args: any) => console.info(label, ...args),\n warn: (...args: any) => console.warn(label, ...args),\n error: (...args: any) => console.error(label, ...args),\n }\n}\n"],"mappings":";;AACA,SAAgB,kBAAkB,OAAiB;AACjD,QAAO,OAAO,mBAAmB,OAAO;;AAG1C,SAAgB,cAAc,IAAY;AACxC,QAAO,KAAK;;AAGd,SAAgB,aAAa,QAAgB;CAC3C,MAAM,QAAQ,IAAI,OAAO;AACzB,QAAO;EACL,MAAM,GAAG,SAAc,QAAQ,IAAI,OAAO,GAAG,KAAK;EAClD,QAAQ,GAAG,SAAc,QAAQ,MAAM,OAAO,GAAG,KAAK;EACtD,OAAO,GAAG,SAAc,QAAQ,KAAK,OAAO,GAAG,KAAK;EACpD,OAAO,GAAG,SAAc,QAAQ,KAAK,OAAO,GAAG,KAAK;EACpD,QAAQ,GAAG,SAAc,QAAQ,MAAM,OAAO,GAAG,KAAK;EACvD"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import path from 'node:path'\n\nconst isWindows: boolean =\n typeof process !== 'undefined' && process.platform === 'win32'\nconst windowsSlashRE = /\\\\/g\n\n/** Read `build.rollupOptions` or `build.rolldownOptions` from a build config. */\nexport function getBundlerOptions(build: any): any {\n return build?.rolldownOptions ?? build?.rollupOptions\n}\n\nexport function resolveViteId(id: string) {\n return `\\0${id}`\n}\n\nexport function createLogger(prefix: string) {\n const label = `[${prefix}]`\n return {\n log: (...args: any) => console.log(label, ...args),\n debug: (...args: any) => console.debug(label, ...args),\n info: (...args: any) => console.info(label, ...args),\n warn: (...args: any) => console.warn(label, ...args),\n error: (...args: any) => console.error(label, ...args),\n }\n}\n\nfunction slash(path: string): string {\n return path.replace(windowsSlashRE, '/')\n}\n\nexport function normalizePath(id: string): string {\n return path.posix.normalize(isWindows ? slash(id) : id)\n}\n"],"mappings":";;AAEA,IAAM,YACJ,OAAO,YAAY,eAAe,QAAQ,aAAa;AACzD,IAAM,iBAAiB;;AAGvB,SAAgB,kBAAkB,OAAiB;AACjD,QAAO,OAAO,mBAAmB,OAAO;;AAG1C,SAAgB,cAAc,IAAY;AACxC,QAAO,KAAK;;AAGd,SAAgB,aAAa,QAAgB;CAC3C,MAAM,QAAQ,IAAI,OAAO;AACzB,QAAO;EACL,MAAM,GAAG,SAAc,QAAQ,IAAI,OAAO,GAAG,KAAK;EAClD,QAAQ,GAAG,SAAc,QAAQ,MAAM,OAAO,GAAG,KAAK;EACtD,OAAO,GAAG,SAAc,QAAQ,KAAK,OAAO,GAAG,KAAK;EACpD,OAAO,GAAG,SAAc,QAAQ,KAAK,OAAO,GAAG,KAAK;EACpD,QAAQ,GAAG,SAAc,QAAQ,MAAM,OAAO,GAAG,KAAK;EACvD;;AAGH,SAAS,MAAM,MAAsB;AACnC,QAAO,KAAK,QAAQ,gBAAgB,IAAI;;AAG1C,SAAgB,cAAc,IAAoB;AAChD,QAAO,KAAK,MAAM,UAAU,YAAY,MAAM,GAAG,GAAG,GAAG"}
@@ -1,42 +1,24 @@
1
- import { VITE_ENVIRONMENT_NAMES } from "../constants.js";
2
- import { resolveViteId } from "../utils.js";
3
- import { IMPORT_PROTECTION_DEBUG, SERVER_FN_LOOKUP_QUERY, VITE_BROWSER_VIRTUAL_PREFIX } from "./constants.js";
4
- import { buildResolutionCandidates, buildSourceCandidates, canonicalizeResolvedId, clearNormalizeFilePathCache, debugLog, dedupePatterns, escapeRegExp, extractImportSources, getOrCreate, isInsideDirectory, matchesDebugFilter, normalizeFilePath, relativizePath, shouldDeferViolation } from "./utils.js";
5
- import { ImportGraph, buildTrace, formatViolation } from "./trace.js";
6
- import { getDefaultImportProtectionRules, getMarkerSpecifiers } from "./defaults.js";
7
- import { compileMatchers, matchesAny } from "./matchers.js";
8
- import { MOCK_BUILD_PREFIX, generateDevSelfDenialModule, generateSelfContainedMockModule, getResolvedVirtualModuleMatchers, loadResolvedVirtualModule, makeMockEdgeModuleId, mockRuntimeModuleIdFromViolation, resolveInternalVirtualModuleId, resolvedMarkerVirtualModuleId } from "./virtualModules.js";
9
- import { collectMockExportNamesBySource, collectNamedExports, rewriteDeniedImports } from "./rewriteDeniedImports.js";
10
- import { ExtensionlessAbsoluteIdResolver } from "./extensionlessAbsoluteIdResolver.js";
11
- import { ImportLocCache, addTraceImportLocations, buildCodeSnippet, buildLineIndex, findImportStatementLocationFromTransformed, findPostCompileUsageLocation, pickOriginalCodeFromSourcesContent } from "./sourceLocation.js";
1
+ import { VITE_ENVIRONMENT_NAMES } from "../../constants.js";
2
+ import { resolveViteId } from "../../utils.js";
3
+ import { IMPORT_PROTECTION_DEBUG, MOCK_BUILD_PREFIX, SERVER_FN_LOOKUP_QUERY, VITE_BROWSER_VIRTUAL_PREFIX } from "../../import-protection/constants.js";
4
+ import { buildResolutionCandidates, buildSourceCandidates, canonicalizeResolvedId, checkFileDenial, clearNormalizeFilePathCache, debugLog, dedupePatterns, dedupeViolationKey, escapeRegExp, getOrCreate, isFileExcluded, isInsideDirectory, matchesDebugFilter, normalizeFilePath, relativizePath, shouldDeferViolation } from "../../import-protection/utils.js";
5
+ import { ImportGraph, buildTrace, formatViolation } from "../../import-protection/trace.js";
6
+ import { getDefaultImportProtectionRules, getMarkerSpecifiers } from "../../import-protection/defaults.js";
7
+ import { compileMatchers, matchesAny } from "../../import-protection/matchers.js";
8
+ import { getImportProtectionEnvType, getImportProtectionRelativePath, getImportProtectionRulesForEnvironment, shouldCheckImportProtectionImporter } from "../../import-protection/adapterUtils.js";
9
+ import { ImportLocCache, addTraceImportLocations, buildCodeSnippet, buildLineIndex, createImportSpecifierLocationIndex, findImportStatementLocationFromTransformed, findPostCompileUsageLocation, normalizeSourceMap, pickOriginalCodeFromSourcesContent } from "../../import-protection/sourceLocation.js";
10
+ import { getImportSources, getMockExportNamesBySource, getNamedExports } from "../../import-protection/analysis.js";
11
+ import { rewriteDeniedImports } from "../../import-protection/rewrite.js";
12
+ import { ExtensionlessAbsoluteIdResolver } from "../../import-protection/extensionlessAbsoluteIdResolver.js";
13
+ import { generateDevSelfDenialModule, generateSelfContainedMockModule, makeMockEdgeModuleId, mockRuntimeModuleIdFromViolation } from "../../import-protection/virtualModules.js";
14
+ import { getResolvedVirtualModuleMatchers, loadResolvedVirtualModule, resolveInternalVirtualModuleId, resolvedMarkerVirtualModuleId } from "./virtualModules.js";
12
15
  import { normalizePath } from "vite";
13
- //#region src/import-protection-plugin/plugin.ts
16
+ //#region src/vite/import-protection-plugin/plugin.ts
14
17
  function importProtectionPlugin(opts) {
15
18
  let devServer = null;
16
19
  const extensionlessIdResolver = new ExtensionlessAbsoluteIdResolver();
17
20
  const resolveExtensionlessAbsoluteId = (id) => extensionlessIdResolver.resolve(id);
18
- const importPatternCache = /* @__PURE__ */ new Map();
19
- function findFirstImportSpecifierIndex(code, source) {
20
- let patterns = importPatternCache.get(source);
21
- if (!patterns) {
22
- const escaped = escapeRegExp(source);
23
- patterns = [
24
- new RegExp(`\\bimport\\s+(['"])${escaped}\\1`),
25
- new RegExp(`\\bfrom\\s+(['"])${escaped}\\1`),
26
- new RegExp(`\\bimport\\s*\\(\\s*(['"])${escaped}\\1\\s*\\)`)
27
- ];
28
- importPatternCache.set(source, patterns);
29
- }
30
- let best = -1;
31
- for (const re of patterns) {
32
- const m = re.exec(code);
33
- if (!m) continue;
34
- const idx = m.index + m[0].indexOf(source);
35
- if (idx === -1) continue;
36
- if (best === -1 || idx < best) best = idx;
37
- }
38
- return best;
39
- }
21
+ const importSpecifierLocationIndex = createImportSpecifierLocationIndex();
40
22
  /**
41
23
  * Build an import trace using Vite's per-environment module graph, which
42
24
  * is authoritative even on warm starts when the plugin's own ImportGraph
@@ -156,7 +138,7 @@ function importProtectionPlugin(opts) {
156
138
  const mgTrace = buildTraceFromModuleGraph(envName, env, normalizedImporter);
157
139
  if (mgTrace && mgTrace.length > trace.length) trace = mgTrace;
158
140
  }
159
- await addTraceImportLocations(provider, trace, env.importLocCache, findFirstImportSpecifierIndex);
141
+ await addTraceImportLocations(provider, trace, env.importLocCache, importSpecifierLocationIndex.find);
160
142
  if (trace.length > 0) {
161
143
  const last = trace[trace.length - 1];
162
144
  if (!last.specifier) last.specifier = specifier;
@@ -191,7 +173,7 @@ function importProtectionPlugin(opts) {
191
173
  }
192
174
  async function resolveImporterLocation(provider, env, importer, sourceCandidates) {
193
175
  for (const candidate of sourceCandidates) {
194
- const loc = await findPostCompileUsageLocation(provider, importer, candidate) || await findImportStatementLocationFromTransformed(provider, importer, candidate, env.importLocCache, findFirstImportSpecifierIndex);
176
+ const loc = await findPostCompileUsageLocation(provider, importer, candidate) || await findImportStatementLocationFromTransformed(provider, importer, candidate, env.importLocCache, importSpecifierLocationIndex.find);
195
177
  if (loc) return loc;
196
178
  }
197
179
  }
@@ -202,41 +184,24 @@ function importProtectionPlugin(opts) {
202
184
  *
203
185
  * Returns `undefined` when the resolved import has no marker conflict.
204
186
  */
205
- async function buildMarkerViolationFromResolvedImport(provider, env, envName, envType, importer, source, resolvedId, relativePath, traceOverride) {
187
+ async function buildMarkerViolationFromResolvedImport(provider, env, envName, envType, importer, source, resolvedId, traceOverride) {
206
188
  const normalizedResolvedId = normalizeFilePath(resolvedId);
207
189
  const markerKind = shared.fileMarkerKind.get(normalizedResolvedId);
208
190
  if (!(envType === "client" && markerKind === "server" || envType === "server" && markerKind === "client")) return void 0;
209
191
  return buildViolationInfo(provider, env, envName, envType, importer, normalizeFilePath(importer), source, {
210
192
  type: "marker",
211
- resolved: normalizedResolvedId,
212
- message: buildMarkerViolationMessage(relativePath, markerKind)
193
+ resolved: normalizedResolvedId
213
194
  }, traceOverride);
214
195
  }
215
- function buildMarkerViolationMessage(relativePath, markerKind) {
216
- return markerKind === "server" ? `Module "${relativePath}" is marked server-only but is imported in the client environment` : `Module "${relativePath}" is marked client-only but is imported in the server environment`;
217
- }
218
196
  async function buildFileViolationInfo(provider, env, envName, envType, importer, normalizedImporter, source, resolvedPath, pattern, traceOverride) {
219
197
  return buildViolationInfo(provider, env, envName, envType, importer, normalizedImporter, source, {
220
198
  type: "file",
221
199
  pattern,
222
- resolved: resolvedPath,
223
- message: `Import "${source}" (resolved to "${getRelativePath(resolvedPath)}") is denied in the ${envType} environment`
200
+ resolved: resolvedPath
224
201
  }, traceOverride);
225
202
  }
226
- function getEnvType(envName) {
227
- return config.envTypeMap.get(envName) ?? "server";
228
- }
229
203
  function getRulesForEnvironment(envName) {
230
- return getEnvType(envName) === "client" ? config.compiledRules.client : config.compiledRules.server;
231
- }
232
- /**
233
- * Check if a relative path matches any denied file pattern for the given
234
- * environment, respecting `excludeFiles`. Returns the matching pattern
235
- * or `undefined` if the file is not denied.
236
- */
237
- function checkFileDenial(relativePath, matchers) {
238
- if (matchers.excludeFiles.length > 0 && matchesAny(relativePath, matchers.excludeFiles)) return;
239
- return matchers.files.length > 0 ? matchesAny(relativePath, matchers.files) : void 0;
204
+ return getImportProtectionRulesForEnvironment(config, envName);
240
205
  }
241
206
  const environmentNames = new Set([VITE_ENVIRONMENT_NAMES.client, VITE_ENVIRONMENT_NAMES.server]);
242
207
  if (opts.providerEnvName !== VITE_ENVIRONMENT_NAMES.server) environmentNames.add(opts.providerEnvName);
@@ -308,7 +273,7 @@ function importProtectionPlugin(opts) {
308
273
  const importerCode = env.transformResultProvider.getTransformResult(importerFile)?.code ?? (importerIdHint && ctx.getModuleInfo ? ctx.getModuleInfo(importerIdHint)?.code ?? void 0 : void 0);
309
274
  if (typeof importerCode !== "string" || importerCode.length === 0) return [];
310
275
  try {
311
- parsedBySource = collectMockExportNamesBySource(importerCode);
276
+ parsedBySource = getMockExportNamesBySource(importerCode);
312
277
  await recordMockExportsForImporter(env, importerFile, parsedBySource, async (src) => {
313
278
  const cacheKey = `${importerFile}:${src}`;
314
279
  if (env.resolveCache.has(cacheKey)) return env.resolveCache.get(cacheKey) ?? void 0;
@@ -351,12 +316,14 @@ function importProtectionPlugin(opts) {
351
316
  async function recordMockExportsForImporter(env, importerId, namesBySource, resolveSource) {
352
317
  const importerFile = normalizeFilePath(importerId);
353
318
  if (namesBySource.size === 0) return;
319
+ const resolvedAliases = /* @__PURE__ */ new Map();
354
320
  for (const [source, names] of namesBySource) try {
355
321
  const resolvedId = await resolveSource(source);
356
322
  if (!resolvedId) continue;
357
- namesBySource.set(normalizeFilePath(resolvedId), names);
358
- namesBySource.set(resolveExtensionlessAbsoluteId(resolvedId), names);
323
+ resolvedAliases.set(normalizeFilePath(resolvedId), names);
324
+ resolvedAliases.set(resolveExtensionlessAbsoluteId(resolvedId), names);
359
325
  } catch {}
326
+ for (const [source, names] of resolvedAliases) namesBySource.set(source, names);
360
327
  const existing = env.mockExportsByImporter.get(importerFile);
361
328
  if (!existing) {
362
329
  env.mockExportsByImporter.set(importerFile, namesBySource);
@@ -374,18 +341,10 @@ function importProtectionPlugin(opts) {
374
341
  }
375
342
  const shouldCheckImporterCache = /* @__PURE__ */ new Map();
376
343
  function shouldCheckImporter(importer) {
377
- let result = shouldCheckImporterCache.get(importer);
378
- if (result !== void 0) return result;
379
- const relativePath = relativizePath(importer, config.root);
380
- if (config.excludeMatchers.length > 0 && matchesAny(relativePath, config.excludeMatchers) || config.ignoreImporterMatchers.length > 0 && matchesAny(relativePath, config.ignoreImporterMatchers)) result = false;
381
- else if (config.includeMatchers.length > 0) result = !!matchesAny(relativePath, config.includeMatchers);
382
- else if (config.srcDirectory) result = isInsideDirectory(importer, config.srcDirectory);
383
- else result = true;
384
- shouldCheckImporterCache.set(importer, result);
385
- return result;
344
+ return shouldCheckImportProtectionImporter(config, importer, shouldCheckImporterCache);
386
345
  }
387
346
  function dedupeKey(info) {
388
- return `${info.type}:${info.importer}:${info.specifier}:${info.resolved ?? ""}`;
347
+ return dedupeViolationKey(info);
389
348
  }
390
349
  function hasSeen(env, key) {
391
350
  if (config.logMode === "always") return false;
@@ -394,7 +353,7 @@ function importProtectionPlugin(opts) {
394
353
  return false;
395
354
  }
396
355
  function getRelativePath(absolutePath) {
397
- return relativizePath(normalizePath(absolutePath), config.root);
356
+ return getImportProtectionRelativePath(config.root, absolutePath);
398
357
  }
399
358
  /** Reset all caches on an EnvState (called from buildStart). */
400
359
  function clearEnvState(envState) {
@@ -719,7 +678,6 @@ function importProtectionPlugin(opts) {
719
678
  if (!config.enabled) return;
720
679
  clearNormalizeFilePathCache();
721
680
  extensionlessIdResolver.clear();
722
- importPatternCache.clear();
723
681
  shouldCheckImporterCache.clear();
724
682
  for (const envState of envStates.values()) clearEnvState(envState);
725
683
  shared.fileMarkerKind.clear();
@@ -738,7 +696,7 @@ function importProtectionPlugin(opts) {
738
696
  async resolveId(source, importer, _options) {
739
697
  const envName = this.environment.name;
740
698
  const env = getEnv(envName);
741
- const envType = getEnvType(envName);
699
+ const envType = getImportProtectionEnvType(config, envName);
742
700
  const provider = env.transformResultProvider;
743
701
  const isScanResolve = !!_options.scan;
744
702
  if (IMPORT_PROTECTION_DEBUG) {
@@ -783,10 +741,7 @@ function importProtectionPlugin(opts) {
783
741
  shared.fileMarkerKind.set(normalizedImporter, markerKind);
784
742
  const violatesEnv = envType === "client" && markerKind === "server" || envType === "server" && markerKind === "client";
785
743
  if (violatesEnv) {
786
- const info = await buildViolationInfo(provider, env, envName, envType, importer, normalizedImporter, source, {
787
- type: "marker",
788
- message: buildMarkerViolationMessage(getRelativePath(normalizedImporter), markerKind)
789
- });
744
+ const info = await buildViolationInfo(provider, env, envName, envType, importer, normalizedImporter, source, { type: "marker" });
790
745
  const markerResult = await reportOrDeferViolation(this, env, normalizedImporter, importer, info, shouldDefer, isPreTransformResolve);
791
746
  if (isBuild && markerResult != null) return markerResult;
792
747
  }
@@ -798,7 +753,7 @@ function importProtectionPlugin(opts) {
798
753
  if (importersMap && importersMap.size > 0) for (const [importerFile, specifier] of importersMap) {
799
754
  if (!specifier) continue;
800
755
  if (!shouldCheckImporter(importerFile)) continue;
801
- const markerInfo = await buildMarkerViolationFromResolvedImport(provider, env, envName, envType, importerFile, specifier, normalizedImporter, getRelativePath(normalizedImporter));
756
+ const markerInfo = await buildMarkerViolationFromResolvedImport(provider, env, envName, envType, importerFile, specifier, normalizedImporter);
802
757
  if (markerInfo) {
803
758
  deferViolation(env, importerFile, markerInfo, isPreTransformResolve);
804
759
  retroDeferred = true;
@@ -815,8 +770,7 @@ function importProtectionPlugin(opts) {
815
770
  if (!isPreTransformResolve) env.graph.addEdge(source, normalizedImporter, source);
816
771
  const info = await buildViolationInfo(provider, env, envName, envType, importer, normalizedImporter, source, {
817
772
  type: "specifier",
818
- pattern: specifierMatch.pattern,
819
- message: `Import "${source}" is denied in the ${envType} environment`
773
+ pattern: specifierMatch.pattern
820
774
  });
821
775
  if (shouldDefer && !info.resolved) try {
822
776
  const resolvedForInfo = await resolveAgainstImporter();
@@ -838,13 +792,13 @@ function importProtectionPlugin(opts) {
838
792
  const relativePath = getRelativePath(resolved);
839
793
  if (isPreTransformResolve && !isScanResolve) env.serverFnLookupModules.add(resolved);
840
794
  if (!isPreTransformResolve) env.graph.addEdge(resolved, normalizedImporter, source);
841
- if (!(matchers.excludeFiles.length > 0 && matchesAny(relativePath, matchers.excludeFiles))) {
842
- const fileMatch = matchers.files.length > 0 ? matchesAny(relativePath, matchers.files) : void 0;
795
+ if (!isFileExcluded(relativePath, matchers)) {
796
+ const fileMatch = checkFileDenial(relativePath, matchers);
843
797
  if (fileMatch) {
844
798
  const info = await buildFileViolationInfo(provider, env, envName, envType, importer, normalizedImporter, source, resolved, fileMatch.pattern);
845
799
  return reportOrDeferViolation(this, env, normalizedImporter, importer, info, shouldDefer, isPreTransformResolve);
846
800
  }
847
- const markerInfo = await buildMarkerViolationFromResolvedImport(provider, env, envName, envType, importer, source, resolved, relativePath);
801
+ const markerInfo = await buildMarkerViolationFromResolvedImport(provider, env, envName, envType, importer, source, resolved);
848
802
  if (markerInfo) return reportOrDeferViolation(this, env, normalizedImporter, importer, markerInfo, shouldDefer, isPreTransformResolve);
849
803
  }
850
804
  }
@@ -934,7 +888,7 @@ function importProtectionPlugin(opts) {
934
888
  async handler(code, id) {
935
889
  const envName = this.environment.name;
936
890
  const file = normalizeFilePath(id);
937
- const envType = getEnvType(envName);
891
+ const envType = getImportProtectionEnvType(config, envName);
938
892
  const matchers = getRulesForEnvironment(envName);
939
893
  const isBuild = config.command === "build";
940
894
  if (IMPORT_PROTECTION_DEBUG) {
@@ -949,7 +903,7 @@ function importProtectionPlugin(opts) {
949
903
  if (selfFileMatch) {
950
904
  let exportNames = [];
951
905
  try {
952
- exportNames = collectNamedExports(code);
906
+ exportNames = getNamedExports(code);
953
907
  } catch {}
954
908
  if (isBuild) return generateSelfContainedMockModule(exportNames);
955
909
  const runtimeId = mockRuntimeModuleIdFromViolation({
@@ -961,7 +915,6 @@ function importProtectionPlugin(opts) {
961
915
  specifier: relativizePath(file, config.root),
962
916
  resolved: file,
963
917
  pattern: selfFileMatch.pattern,
964
- message: `File "${relativizePath(file, config.root)}" is denied in the ${envType} environment`,
965
918
  trace: []
966
919
  }, config.mockAccess, config.root);
967
920
  return generateDevSelfDenialModule(exportNames, runtimeId);
@@ -987,7 +940,7 @@ function importProtectionPlugin(opts) {
987
940
  });
988
941
  if (isBuild) return void 0;
989
942
  const isDevMock = config.effectiveBehavior === "mock";
990
- const importSources = extractImportSources(code);
943
+ const importSources = getImportSources(code);
991
944
  const resolvedChildren = /* @__PURE__ */ new Set();
992
945
  const deniedSourceReplacements = /* @__PURE__ */ new Map();
993
946
  for (const src of importSources) try {
@@ -1024,11 +977,7 @@ function importProtectionPlugin(opts) {
1024
977
  if (deniedSourceReplacements.size > 0) try {
1025
978
  const rewritten = rewriteDeniedImports(code, id, new Set(deniedSourceReplacements.keys()), (source) => deniedSourceReplacements.get(source) ?? source);
1026
979
  if (!rewritten) return;
1027
- const normalizedMap = rewritten.map ? {
1028
- ...rewritten.map,
1029
- version: Number(rewritten.map.version),
1030
- sourcesContent: rewritten.map.sourcesContent?.map((s) => s ?? "") ?? []
1031
- } : {
980
+ const normalizedMap = rewritten.map ? normalizeSourceMap(rewritten.map) : {
1032
981
  version: 3,
1033
982
  file: id,
1034
983
  names: [],
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","names":[],"sources":["../../../../src/vite/import-protection-plugin/plugin.ts"],"sourcesContent":["import { normalizePath } from 'vite'\n\nimport { resolveViteId } from '../../utils'\nimport { VITE_ENVIRONMENT_NAMES } from '../../constants'\nimport {\n ImportGraph,\n buildTrace,\n formatViolation,\n} from '../../import-protection/trace'\nimport {\n getDefaultImportProtectionRules,\n getMarkerSpecifiers,\n} from '../../import-protection/defaults'\nimport { compileMatchers, matchesAny } from '../../import-protection/matchers'\nimport {\n getImportProtectionEnvType,\n getImportProtectionRelativePath,\n getImportProtectionRulesForEnvironment,\n shouldCheckImportProtectionImporter,\n} from '../../import-protection/adapterUtils'\nimport {\n buildResolutionCandidates,\n buildSourceCandidates,\n canonicalizeResolvedId,\n checkFileDenial,\n clearNormalizeFilePathCache,\n debugLog,\n dedupePatterns,\n dedupeViolationKey,\n escapeRegExp,\n getOrCreate,\n isFileExcluded,\n isInsideDirectory,\n matchesDebugFilter,\n normalizeFilePath,\n relativizePath,\n shouldDeferViolation,\n} from '../../import-protection/utils'\nimport {\n getImportSources,\n getMockExportNamesBySource,\n getNamedExports,\n} from '../../import-protection/analysis'\nimport { rewriteDeniedImports } from '../../import-protection/rewrite'\nimport { ExtensionlessAbsoluteIdResolver } from '../../import-protection/extensionlessAbsoluteIdResolver'\nimport {\n IMPORT_PROTECTION_DEBUG,\n SERVER_FN_LOOKUP_QUERY,\n VITE_BROWSER_VIRTUAL_PREFIX,\n} from '../../import-protection/constants'\nimport {\n ImportLocCache,\n addTraceImportLocations,\n buildCodeSnippet,\n buildLineIndex,\n createImportSpecifierLocationIndex,\n findImportStatementLocationFromTransformed,\n findPostCompileUsageLocation,\n normalizeSourceMap,\n pickOriginalCodeFromSourcesContent,\n} from '../../import-protection/sourceLocation'\nimport {\n MOCK_BUILD_PREFIX,\n generateDevSelfDenialModule,\n generateSelfContainedMockModule,\n getResolvedVirtualModuleMatchers,\n loadResolvedVirtualModule,\n makeMockEdgeModuleId,\n mockRuntimeModuleIdFromViolation,\n resolveInternalVirtualModuleId,\n resolvedMarkerVirtualModuleId,\n} from './virtualModules'\nimport type { PluginOption, ViteDevServer } from 'vite'\nimport type {\n Loc,\n TraceStep,\n ViolationInfo,\n} from '../../import-protection/trace'\nimport type {\n SourceMapLike,\n TransformResult,\n TransformResultProvider,\n} from '../../import-protection/sourceLocation'\nimport type { ImportProtectionOptions } from '../../schema'\nimport type {\n EnvRules,\n EnvState,\n HandleViolationResult,\n ImportProtectionPluginOptions,\n ModuleGraphNode,\n PendingViolation,\n PluginConfig,\n SharedState,\n ViolationReporter,\n} from './types'\n\nexport type { ImportProtectionPluginOptions } from './types'\n\nexport function importProtectionPlugin(\n opts: ImportProtectionPluginOptions,\n): PluginOption {\n let devServer: ViteDevServer | null = null\n const extensionlessIdResolver = new ExtensionlessAbsoluteIdResolver()\n const resolveExtensionlessAbsoluteId = (id: string) =>\n extensionlessIdResolver.resolve(id)\n const importSpecifierLocationIndex = createImportSpecifierLocationIndex()\n\n /**\n * Build an import trace using Vite's per-environment module graph, which\n * is authoritative even on warm starts when the plugin's own ImportGraph\n * may be incomplete (Vite skips resolveId for cached modules).\n */\n function buildTraceFromModuleGraph(\n envName: string,\n env: EnvState,\n targetFile: string,\n ): Array<TraceStep> | null {\n if (!devServer) return null\n const environment = devServer.environments[envName]\n if (!environment) return null\n\n const file = normalizeFilePath(targetFile)\n const start = environment.moduleGraph.getModuleById(file)\n if (!start) return null\n\n // Resolve a module graph node to its normalized file path once and\n // cache the result so BFS + reconstruction don't recompute.\n const nodeIds = new Map<ModuleGraphNode, string>()\n function nodeId(n: ModuleGraphNode): string {\n let cached = nodeIds.get(n)\n if (cached === undefined) {\n cached = n.id\n ? normalizeFilePath(n.id)\n : n.url\n ? normalizeFilePath(n.url)\n : ''\n nodeIds.set(n, cached)\n }\n return cached\n }\n\n const queue: Array<ModuleGraphNode> = [start]\n const visited = new Set<ModuleGraphNode>([start])\n const parent = new Map<ModuleGraphNode, ModuleGraphNode>()\n\n let entryRoot: ModuleGraphNode | null = null\n let fallbackRoot: ModuleGraphNode | null = null\n let qi = 0\n while (qi < queue.length) {\n const node = queue[qi++]!\n const id = nodeId(node)\n\n if (id && env.graph.entries.has(id)) {\n entryRoot = node\n break\n }\n\n const importers = node.importers\n if (importers.size === 0) {\n if (!fallbackRoot) fallbackRoot = node\n continue\n }\n\n for (const imp of importers) {\n if (visited.has(imp)) continue\n visited.add(imp)\n parent.set(imp, node)\n queue.push(imp)\n }\n }\n\n const root = entryRoot ?? fallbackRoot\n\n if (!root) return null\n\n // Reconstruct: root -> ... -> start\n const chain: Array<ModuleGraphNode> = []\n let cur: ModuleGraphNode | undefined = root\n for (let i = 0; i < config.maxTraceDepth + 2 && cur; i++) {\n chain.push(cur)\n if (cur === start) break\n cur = parent.get(cur)\n }\n\n const steps: Array<TraceStep> = []\n for (let i = 0; i < chain.length; i++) {\n const id = nodeId(chain[i]!)\n if (!id) continue\n let specifier: string | undefined\n if (i + 1 < chain.length) {\n const nextId = nodeId(chain[i + 1]!)\n if (nextId) {\n specifier = env.graph.reverseEdges.get(nextId)?.get(id)\n }\n }\n steps.push(specifier ? { file: id, specifier } : { file: id })\n }\n\n return steps.length ? steps : null\n }\n\n const config: PluginConfig = {\n enabled: true,\n root: '',\n command: 'build',\n srcDirectory: '',\n framework: opts.framework,\n effectiveBehavior: 'error',\n mockAccess: 'error',\n logMode: 'once',\n maxTraceDepth: 20,\n compiledRules: {\n client: { specifiers: [], files: [], excludeFiles: [] },\n server: { specifiers: [], files: [], excludeFiles: [] },\n },\n includeMatchers: [],\n excludeMatchers: [],\n ignoreImporterMatchers: [],\n markerSpecifiers: { serverOnly: new Set(), clientOnly: new Set() },\n envTypeMap: new Map(opts.environments.map((e) => [e.name, e.type])),\n onViolation: undefined,\n }\n\n const envStates = new Map<string, EnvState>()\n const shared: SharedState = { fileMarkerKind: new Map() }\n\n /**\n * Build the best available trace for a module and enrich each step with\n * line/column locations. Tries the plugin's own ImportGraph first, then\n * Vite's moduleGraph (authoritative on warm start), keeping whichever is\n * longer. Annotates the last step with the denied specifier + location.\n *\n * Shared by {@link buildViolationInfo} and {@link processPendingViolations}.\n */\n async function rebuildAndAnnotateTrace(\n provider: TransformResultProvider,\n env: EnvState,\n envName: string,\n normalizedImporter: string,\n specifier: string,\n importerLoc: Loc | undefined,\n traceOverride?: Array<TraceStep>,\n ): Promise<Array<TraceStep>> {\n let trace =\n traceOverride ??\n buildTrace(env.graph, normalizedImporter, config.maxTraceDepth)\n\n if (config.command === 'serve') {\n const mgTrace = buildTraceFromModuleGraph(\n envName,\n env,\n normalizedImporter,\n )\n if (mgTrace && mgTrace.length > trace.length) {\n trace = mgTrace\n }\n }\n await addTraceImportLocations(\n provider,\n trace,\n env.importLocCache,\n importSpecifierLocationIndex.find,\n )\n\n if (trace.length > 0) {\n const last = trace[trace.length - 1]!\n if (!last.specifier) last.specifier = specifier\n if (importerLoc && last.line == null) {\n last.line = importerLoc.line\n last.column = importerLoc.column\n }\n }\n\n return trace\n }\n\n /**\n * Build a complete {@link ViolationInfo} with trace, location, and snippet.\n *\n * This is the single path that all violation types go through: specifier,\n * file, and marker.\n */\n async function buildViolationInfo(\n provider: TransformResultProvider,\n env: EnvState,\n envName: string,\n envType: 'client' | 'server',\n importer: string,\n normalizedImporter: string,\n source: string,\n overrides: Omit<\n ViolationInfo,\n | 'env'\n | 'envType'\n | 'behavior'\n | 'specifier'\n | 'importer'\n | 'trace'\n | 'snippet'\n | 'importerLoc'\n >,\n traceOverride?: Array<TraceStep>,\n ): Promise<ViolationInfo> {\n const sourceCandidates = buildSourceCandidates(\n source,\n 'resolved' in overrides && typeof overrides.resolved === 'string'\n ? overrides.resolved\n : undefined,\n config.root,\n )\n\n const loc = await resolveImporterLocation(\n provider,\n env,\n importer,\n sourceCandidates,\n )\n\n const trace = await rebuildAndAnnotateTrace(\n provider,\n env,\n envName,\n normalizedImporter,\n source,\n loc,\n traceOverride,\n )\n\n const snippet = loc ? buildCodeSnippet(provider, importer, loc) : undefined\n\n return {\n env: envName,\n envType,\n behavior: config.effectiveBehavior,\n specifier: source,\n importer: normalizedImporter,\n ...(loc ? { importerLoc: loc } : {}),\n trace,\n snippet,\n ...overrides,\n }\n }\n\n async function resolveImporterLocation(\n provider: TransformResultProvider,\n env: EnvState,\n importer: string,\n sourceCandidates: Iterable<string>,\n ): Promise<Loc | undefined> {\n for (const candidate of sourceCandidates) {\n const loc =\n (await findPostCompileUsageLocation(provider, importer, candidate)) ||\n (await findImportStatementLocationFromTransformed(\n provider,\n importer,\n candidate,\n env.importLocCache,\n importSpecifierLocationIndex.find,\n ))\n if (loc) return loc\n }\n return undefined\n }\n\n /**\n * Check if a resolved import violates marker restrictions (e.g. importing\n * a server-only module in the client env). If so, build and return the\n * {@link ViolationInfo} — the caller is responsible for reporting/deferring.\n *\n * Returns `undefined` when the resolved import has no marker conflict.\n */\n async function buildMarkerViolationFromResolvedImport(\n provider: TransformResultProvider,\n env: EnvState,\n envName: string,\n envType: 'client' | 'server',\n importer: string,\n source: string,\n resolvedId: string,\n traceOverride?: Array<TraceStep>,\n ): Promise<ViolationInfo | undefined> {\n const normalizedResolvedId = normalizeFilePath(resolvedId)\n const markerKind = shared.fileMarkerKind.get(normalizedResolvedId)\n const violates =\n (envType === 'client' && markerKind === 'server') ||\n (envType === 'server' && markerKind === 'client')\n if (!violates) return undefined\n\n const normalizedImporter = normalizeFilePath(importer)\n\n return buildViolationInfo(\n provider,\n env,\n envName,\n envType,\n importer,\n normalizedImporter,\n source,\n {\n type: 'marker',\n resolved: normalizedResolvedId,\n },\n traceOverride,\n )\n }\n\n async function buildFileViolationInfo(\n provider: TransformResultProvider,\n env: EnvState,\n envName: string,\n envType: 'client' | 'server',\n importer: string,\n normalizedImporter: string,\n source: string,\n resolvedPath: string,\n pattern: string | RegExp,\n traceOverride?: Array<TraceStep>,\n ): Promise<ViolationInfo> {\n return buildViolationInfo(\n provider,\n env,\n envName,\n envType,\n importer,\n normalizedImporter,\n source,\n {\n type: 'file',\n pattern,\n resolved: resolvedPath,\n },\n traceOverride,\n )\n }\n\n function getRulesForEnvironment(envName: string): EnvRules {\n return getImportProtectionRulesForEnvironment(config, envName) as EnvRules\n }\n\n const environmentNames = new Set<string>([\n VITE_ENVIRONMENT_NAMES.client,\n VITE_ENVIRONMENT_NAMES.server,\n ])\n if (opts.providerEnvName !== VITE_ENVIRONMENT_NAMES.server) {\n environmentNames.add(opts.providerEnvName)\n }\n\n /** Get (or lazily create) the per-env state for the given environment name. */\n function getEnv(envName: string): EnvState {\n let envState = envStates.get(envName)\n if (!envState) {\n const transformResultCache = new Map<string, TransformResult>()\n envState = {\n graph: new ImportGraph(),\n mockExportsByImporter: new Map(),\n resolveCache: new Map(),\n resolveCacheByFile: new Map(),\n importLocCache: new ImportLocCache(),\n seenViolations: new Set(),\n transformResultCache,\n transformResultKeysByFile: new Map(),\n transformResultProvider: {\n getTransformResult(id: string) {\n const fullKey = normalizePath(id)\n const exact = transformResultCache.get(fullKey)\n if (exact) return exact\n const strippedKey = normalizeFilePath(id)\n return strippedKey !== fullKey\n ? transformResultCache.get(strippedKey)\n : undefined\n },\n },\n postTransformImports: new Map(),\n serverFnLookupModules: new Set(),\n pendingViolations: new Map(),\n deferredBuildViolations: [],\n }\n envStates.set(envName, envState)\n }\n return envState\n }\n\n /**\n * Search a parsed export-names map for an entry matching any of the\n * specifier candidates. Returns matching names or empty array.\n */\n function findExportsInMap(\n exportMap: Map<string, Array<string>>,\n candidates: Array<string>,\n ): Array<string> {\n for (const candidate of candidates) {\n const hit = exportMap.get(candidate)\n if (hit && hit.length > 0) return hit\n }\n return []\n }\n\n /**\n * Build deduped resolution candidates for a module ID, including the\n * extensionless absolute path when the ID looks like a file path.\n */\n function buildIdCandidates(id: string, extra?: string): Array<string> {\n const set = new Set(buildResolutionCandidates(id))\n if (extra) {\n for (const c of buildResolutionCandidates(extra)) set.add(c)\n set.add(resolveExtensionlessAbsoluteId(extra))\n }\n return Array.from(set)\n }\n\n /**\n * Resolve which named exports the importer needs from a denied specifier,\n * so mock-edge modules can provide explicit ESM named exports.\n *\n * Tries multiple strategies: cached export maps, AST parsing, and\n * resolver-based comparison.\n */\n async function resolveExportsForDeniedSpecifier(\n env: EnvState,\n ctx: ViolationReporter,\n info: ViolationInfo,\n importerIdHint?: string,\n ): Promise<Array<string>> {\n const importerFile = normalizeFilePath(info.importer)\n const specifierCandidates = buildIdCandidates(info.specifier, info.resolved)\n\n // Only parse AST when a violation occurs (this function is only called\n // while handling a violation). Cache per-importer to avoid repeated parses\n // across multiple violations.\n let parsedBySource = env.mockExportsByImporter.get(importerFile)\n if (!parsedBySource) {\n // Try transform-cache result first, then moduleInfo fallback.\n const importerCode =\n env.transformResultProvider.getTransformResult(importerFile)?.code ??\n (importerIdHint && ctx.getModuleInfo\n ? (ctx.getModuleInfo(importerIdHint)?.code ?? undefined)\n : undefined)\n if (typeof importerCode !== 'string' || importerCode.length === 0)\n return []\n\n try {\n parsedBySource = getMockExportNamesBySource(importerCode)\n\n // Also index by resolved physical IDs so later lookups match.\n await recordMockExportsForImporter(\n env,\n importerFile,\n parsedBySource,\n async (src) => {\n const cacheKey = `${importerFile}:${src}`\n if (env.resolveCache.has(cacheKey)) {\n return env.resolveCache.get(cacheKey) ?? undefined\n }\n if (!ctx.resolve) return undefined\n const resolved = await ctx.resolve(src, info.importer, {\n skipSelf: true,\n })\n if (!resolved || resolved.external) return undefined\n return resolved.id\n },\n )\n\n // Keep the parsed-by-source map for direct lookups.\n parsedBySource =\n env.mockExportsByImporter.get(importerFile) ?? parsedBySource\n } catch {\n return []\n }\n }\n\n // 1. Direct candidate match\n const direct = findExportsInMap(parsedBySource, specifierCandidates)\n if (direct.length > 0) return direct\n\n // 2. Resolve each source key and compare candidates.\n const candidateSet = new Set(specifierCandidates)\n for (const [sourceKey, names] of parsedBySource) {\n if (!names.length) continue\n\n const resolvedId = await resolveSourceKey(\n env,\n ctx,\n importerFile,\n sourceKey,\n info.importer,\n )\n if (!resolvedId) continue\n\n const resolvedCandidates = buildIdCandidates(resolvedId)\n resolvedCandidates.push(resolveExtensionlessAbsoluteId(resolvedId))\n if (resolvedCandidates.some((v) => candidateSet.has(v))) {\n return names\n }\n }\n\n return []\n }\n\n /** Best-effort resolve a source key using the cache or ctx.resolve. */\n async function resolveSourceKey(\n env: EnvState,\n ctx: ViolationReporter,\n importerFile: string,\n sourceKey: string,\n importerId: string,\n ): Promise<string | undefined> {\n const cacheKey = `${importerFile}:${sourceKey}`\n if (env.resolveCache.has(cacheKey)) {\n return env.resolveCache.get(cacheKey) ?? undefined\n }\n if (!ctx.resolve) return undefined\n try {\n const resolved = await ctx.resolve(sourceKey, importerId, {\n skipSelf: true,\n })\n if (!resolved || resolved.external) return undefined\n return resolved.id\n } catch {\n return undefined\n }\n }\n\n async function recordMockExportsForImporter(\n env: EnvState,\n importerId: string,\n namesBySource: Map<string, Array<string>>,\n resolveSource: (source: string) => Promise<string | undefined>,\n ): Promise<void> {\n const importerFile = normalizeFilePath(importerId)\n\n if (namesBySource.size === 0) return\n\n const resolvedAliases = new Map<string, Array<string>>()\n for (const [source, names] of namesBySource) {\n try {\n const resolvedId = await resolveSource(source)\n if (!resolvedId) continue\n\n resolvedAliases.set(normalizeFilePath(resolvedId), names)\n resolvedAliases.set(resolveExtensionlessAbsoluteId(resolvedId), names)\n } catch {\n // Best-effort only\n }\n }\n\n for (const [source, names] of resolvedAliases) {\n namesBySource.set(source, names)\n }\n\n const existing = env.mockExportsByImporter.get(importerFile)\n if (!existing) {\n env.mockExportsByImporter.set(importerFile, namesBySource)\n return\n }\n\n for (const [source, names] of namesBySource) {\n const prev = existing.get(source)\n if (!prev) {\n existing.set(source, names)\n continue\n }\n\n const union = new Set([...prev, ...names])\n existing.set(source, Array.from(union).sort())\n }\n }\n\n const shouldCheckImporterCache = new Map<string, boolean>()\n function shouldCheckImporter(importer: string): boolean {\n return shouldCheckImportProtectionImporter(\n config,\n importer,\n shouldCheckImporterCache,\n )\n }\n\n function dedupeKey(info: ViolationInfo): string {\n return dedupeViolationKey(info)\n }\n\n function hasSeen(env: EnvState, key: string): boolean {\n if (config.logMode === 'always') return false\n if (env.seenViolations.has(key)) return true\n env.seenViolations.add(key)\n return false\n }\n\n function getRelativePath(absolutePath: string): string {\n return getImportProtectionRelativePath(config.root, absolutePath)\n }\n\n /** Reset all caches on an EnvState (called from buildStart). */\n function clearEnvState(envState: EnvState): void {\n envState.resolveCache.clear()\n envState.resolveCacheByFile.clear()\n envState.importLocCache.clear()\n envState.seenViolations.clear()\n envState.transformResultCache.clear()\n envState.transformResultKeysByFile.clear()\n envState.postTransformImports.clear()\n envState.serverFnLookupModules.clear()\n envState.pendingViolations.clear()\n envState.deferredBuildViolations.length = 0\n envState.graph.clear()\n envState.mockExportsByImporter.clear()\n }\n\n /** Invalidate all env-level caches that reference a specific file. */\n function invalidateFileFromEnv(envState: EnvState, file: string): void {\n envState.importLocCache.deleteByFile(file)\n\n // Resolve cache (keyed \"importer:source\")\n const resolveKeys = envState.resolveCacheByFile.get(file)\n if (resolveKeys) {\n for (const key of resolveKeys) envState.resolveCache.delete(key)\n envState.resolveCacheByFile.delete(file)\n }\n\n envState.graph.invalidate(file)\n envState.mockExportsByImporter.delete(file)\n envState.serverFnLookupModules.delete(file)\n envState.pendingViolations.delete(file)\n\n // Transform result cache + post-transform imports\n const transformKeys = envState.transformResultKeysByFile.get(file)\n if (transformKeys) {\n for (const key of transformKeys) {\n envState.transformResultCache.delete(key)\n envState.postTransformImports.delete(key)\n }\n envState.transformResultKeysByFile.delete(file)\n } else {\n envState.transformResultCache.delete(file)\n envState.postTransformImports.delete(file)\n }\n }\n\n /** Store a transform result under both the cacheKey and physical file path. */\n function cacheTransformResult(\n envState: EnvState,\n file: string,\n cacheKey: string,\n result: TransformResult,\n ): void {\n envState.transformResultCache.set(cacheKey, result)\n const keySet = getOrCreate(\n envState.transformResultKeysByFile,\n file,\n () => new Set<string>(),\n )\n keySet.add(cacheKey)\n if (cacheKey !== file) {\n envState.transformResultCache.set(file, result)\n keySet.add(file)\n }\n }\n\n /** Register known Start entrypoints as trace roots for all environments. */\n function registerEntries(): void {\n const { resolvedStartConfig } = opts.getConfig()\n for (const envDef of opts.environments) {\n const envState = getEnv(envDef.name)\n if (resolvedStartConfig.routerFilePath) {\n envState.graph.addEntry(\n normalizePath(resolvedStartConfig.routerFilePath),\n )\n }\n if (resolvedStartConfig.startFilePath) {\n envState.graph.addEntry(\n normalizePath(resolvedStartConfig.startFilePath),\n )\n }\n }\n }\n\n /**\n * Get the merged set of post-transform imports for a file, checking all\n * code-split variants. Returns `null` if no post-transform data exists\n * yet (transform hasn't run).\n *\n * Skips `SERVER_FN_LOOKUP` variants because they contain untransformed\n * code — the Start compiler excludes them.\n */\n function getPostTransformImports(\n env: EnvState,\n file: string,\n ): Set<string> | null {\n const keySet = env.transformResultKeysByFile.get(file)\n let merged: Set<string> | null = null\n\n if (keySet) {\n for (const k of keySet) {\n if (k.includes(SERVER_FN_LOOKUP_QUERY)) continue\n const imports = env.postTransformImports.get(k)\n if (imports) {\n if (!merged) merged = new Set(imports)\n else for (const v of imports) merged.add(v)\n }\n }\n }\n\n // Fallback: direct file-path key\n if (!merged) {\n const imports = env.postTransformImports.get(file)\n if (imports) merged = new Set(imports)\n }\n\n return merged\n }\n\n /**\n * Check whether an import edge from `parent` to `target` survived\n * post-transform compilation.\n *\n * Returns:\n * - `'live'` — target appears in a non-lookup variant's post-transform imports\n * - `'dead'` — post-transform data exists but target is absent (compiler stripped it)\n * - `'pending'` — transform ran but import data not yet posted\n * - `'no-data'` — transform never ran (warm-start cached module)\n */\n function checkEdgeLiveness(\n env: EnvState,\n parent: string,\n target: string,\n ): 'live' | 'dead' | 'pending' | 'no-data' {\n const keySet = env.transformResultKeysByFile.get(parent)\n let anyVariantCached = false\n\n if (keySet) {\n for (const k of keySet) {\n if (k.includes(SERVER_FN_LOOKUP_QUERY)) continue\n const imports = env.postTransformImports.get(k)\n if (imports) {\n anyVariantCached = true\n if (imports.has(target)) return 'live'\n }\n }\n }\n\n if (!anyVariantCached) {\n const imports = env.postTransformImports.get(parent)\n if (imports) return imports.has(target) ? 'live' : 'dead'\n const hasTransformResult =\n env.transformResultCache.has(parent) ||\n (keySet ? keySet.size > 0 : false)\n return hasTransformResult ? 'pending' : 'no-data'\n }\n\n return 'dead'\n }\n\n function checkPostTransformReachability(\n env: EnvState,\n file: string,\n ): 'reachable' | 'unreachable' | 'unknown' {\n const visited = new Set<string>()\n const queue: Array<string> = [file]\n let hasUnknownEdge = false\n let qi = 0\n\n while (qi < queue.length) {\n const current = queue[qi++]!\n if (visited.has(current)) continue\n visited.add(current)\n\n if (env.graph.entries.has(current)) {\n return 'reachable'\n }\n\n const importers = env.graph.reverseEdges.get(current)\n if (!importers) continue\n\n for (const [parent] of importers) {\n if (visited.has(parent)) continue\n const liveness = checkEdgeLiveness(env, parent, current)\n if (liveness === 'live' || liveness === 'no-data') {\n // Live edge or warm-start (no transform data) — follow it\n queue.push(parent)\n } else if (liveness === 'pending') {\n hasUnknownEdge = true\n }\n // 'dead' — edge was stripped by compiler, skip\n }\n }\n\n return hasUnknownEdge ? 'unknown' : 'unreachable'\n }\n\n /**\n * Filter pending violations using edge-survival data. Returns the subset\n * of violations whose resolved import survived the Start compiler (or all\n * violations when no post-transform data is available yet).\n *\n * Returns `undefined` when all violations were stripped or when we must wait\n * for post-transform data before proceeding.\n */\n function filterEdgeSurvival(\n env: EnvState,\n file: string,\n violations: Array<PendingViolation>,\n ):\n | { active: Array<PendingViolation>; edgeSurvivalApplied: boolean }\n | 'all-stripped'\n | 'await-transform' {\n const postTransform = getPostTransformImports(env, file)\n\n if (postTransform) {\n const surviving = violations.filter(\n (pv) => !pv.info.resolved || postTransform.has(pv.info.resolved),\n )\n if (surviving.length === 0) return 'all-stripped'\n env.pendingViolations.set(file, surviving)\n return { active: surviving, edgeSurvivalApplied: true }\n }\n\n // Pre-transform violations need edge-survival verification first.\n if (violations.some((pv) => pv.fromPreTransformResolve)) {\n return 'await-transform'\n }\n\n return { active: violations, edgeSurvivalApplied: false }\n }\n\n /**\n * Process pending violations for the given environment. Called from the\n * transform-cache hook after each module transform is cached, because new\n * transform data may allow us to confirm or discard pending violations.\n *\n * @param warnFn - `this.warn` from the transform hook context\n */\n async function processPendingViolations(\n env: EnvState,\n warnFn: (msg: string) => void,\n ): Promise<void> {\n if (env.pendingViolations.size === 0) return\n\n const toDelete: Array<string> = []\n\n for (const [file, violations] of env.pendingViolations) {\n const filtered = filterEdgeSurvival(env, file, violations)\n\n if (filtered === 'all-stripped') {\n toDelete.push(file)\n continue\n }\n if (filtered === 'await-transform') continue\n\n const { active, edgeSurvivalApplied } = filtered\n\n // Wait for entries before running reachability. registerEntries()\n // populates entries at buildStart; resolveId(!importer) may add more.\n const status =\n env.graph.entries.size > 0\n ? checkPostTransformReachability(env, file)\n : 'unknown'\n\n if (status === 'reachable') {\n for (const pv of active) {\n await emitPendingViolation(env, warnFn, pv)\n }\n toDelete.push(file)\n } else if (status === 'unreachable') {\n toDelete.push(file)\n } else if (config.command === 'serve') {\n // 'unknown' reachability — some graph edges lack transform data.\n // When edge-survival was applied, surviving violations are confirmed\n // real. Without it (warm start), emit conservatively.\n let emittedAny = false\n for (const pv of active) {\n if (pv.fromPreTransformResolve) continue\n\n const shouldEmit =\n edgeSurvivalApplied ||\n (pv.info.type === 'file' &&\n !!pv.info.resolved &&\n isInsideDirectory(pv.info.resolved, config.srcDirectory))\n\n if (shouldEmit) {\n emittedAny =\n (await emitPendingViolation(env, warnFn, pv)) || emittedAny\n }\n }\n\n if (emittedAny) {\n toDelete.push(file)\n }\n }\n // 'unknown' — keep pending for next transform-cache invocation.\n }\n\n for (const file of toDelete) {\n env.pendingViolations.delete(file)\n }\n }\n\n async function emitPendingViolation(\n env: EnvState,\n warnFn: (msg: string) => void,\n pv: PendingViolation,\n ): Promise<boolean> {\n if (!pv.info.importerLoc) {\n const sourceCandidates = buildSourceCandidates(\n pv.info.specifier,\n pv.info.resolved,\n config.root,\n )\n const loc = await resolveImporterLocation(\n env.transformResultProvider,\n env,\n pv.info.importer,\n sourceCandidates,\n )\n\n if (loc) {\n pv.info.importerLoc = loc\n pv.info.snippet = buildCodeSnippet(\n env.transformResultProvider,\n pv.info.importer,\n loc,\n )\n }\n }\n\n if (hasSeen(env, dedupeKey(pv.info))) {\n return false\n }\n\n const freshTrace = await rebuildAndAnnotateTrace(\n env.transformResultProvider,\n env,\n pv.info.env,\n pv.info.importer,\n pv.info.specifier,\n pv.info.importerLoc,\n )\n if (freshTrace.length > pv.info.trace.length) {\n pv.info.trace = freshTrace\n }\n\n if (config.onViolation) {\n const result = await config.onViolation(pv.info)\n if (result === false) return false\n }\n\n warnFn(formatViolation(pv.info, config.root))\n return true\n }\n\n /**\n * Record a violation as pending for later confirmation via graph\n * reachability. Called from `resolveId` when `shouldDefer` is true.\n */\n function deferViolation(\n env: EnvState,\n importerFile: string,\n info: ViolationInfo,\n isPreTransformResolve?: boolean,\n ): void {\n getOrCreate(env.pendingViolations, importerFile, () => []).push({\n info,\n fromPreTransformResolve: isPreTransformResolve,\n })\n }\n\n /** Counter for generating unique per-violation mock module IDs in build mode. */\n let buildViolationCounter = 0\n\n async function handleViolation(\n ctx: ViolationReporter,\n env: EnvState,\n info: ViolationInfo,\n importerIdHint?: string,\n violationOpts?: { silent?: boolean },\n ): Promise<HandleViolationResult> {\n if (!violationOpts?.silent) {\n if (config.onViolation) {\n const result = await config.onViolation(info)\n if (result === false) return undefined\n }\n\n if (config.effectiveBehavior === 'error') {\n // Dev+error: throw immediately.\n // Always throw on error — do NOT deduplicate via hasSeen().\n // Rollup may resolve the same specifier multiple times (e.g.\n // commonjs--resolver's nested this.resolve() fires before\n // getResolveStaticDependencyPromises). If we record the key\n // on the first (nested) throw, the second (real) resolve\n // silently returns undefined and the build succeeds — which\n // is the bug this fixes.\n //\n // Build mode never reaches here — all build violations are\n // deferred via shouldDefer and handled silently.\n return ctx.error(formatViolation(info, config.root))\n }\n\n if (!hasSeen(env, dedupeKey(info))) {\n ctx.warn(formatViolation(info, config.root))\n }\n } else if (\n config.effectiveBehavior === 'error' &&\n config.command !== 'build'\n ) {\n return undefined\n }\n\n // File violations: return resolved path — the self-denial transform\n // will replace the file's content with a mock module. This avoids\n // virtual module IDs that could leak across environments via\n // third-party resolver caches.\n if (info.type === 'file') return info.resolved\n\n // Non-file violations (specifier/marker): create mock-edge module.\n // Dev mode uses a runtime diagnostics ID; build mode uses a unique\n // per-violation ID so generateBundle can check tree-shaking survival.\n const exports = await resolveExportsForDeniedSpecifier(\n env,\n ctx,\n info,\n importerIdHint,\n )\n const baseMockId =\n config.command === 'serve'\n ? mockRuntimeModuleIdFromViolation(info, config.mockAccess, config.root)\n : `${MOCK_BUILD_PREFIX}${buildViolationCounter++}`\n return resolveViteId(makeMockEdgeModuleId(exports, baseMockId))\n }\n\n /**\n * Unified violation dispatch: either defers or reports immediately.\n *\n * When `shouldDefer` is true (dev mock + build modes), calls\n * `handleViolation` silently to obtain the mock module ID, then stores\n * the violation for later verification:\n * - Dev mock mode: all violations are deferred to `pendingViolations`\n * for edge-survival and graph-reachability checking via\n * `processPendingViolations`.\n * - Build mode (mock + error): defers to `deferredBuildViolations` for\n * tree-shaking verification in `generateBundle`.\n *\n * Otherwise reports immediately (dev error mode). Pre-transform\n * resolves are silenced in error mode because they fire before the\n * compiler runs and there is no deferred verification path.\n *\n * Returns the mock module ID / resolve result from `handleViolation`.\n */\n async function reportOrDeferViolation(\n ctx: ViolationReporter,\n env: EnvState,\n importerFile: string,\n importerIdHint: string | undefined,\n info: ViolationInfo,\n shouldDefer: boolean,\n isPreTransformResolve: boolean,\n ): Promise<HandleViolationResult> {\n if (shouldDefer) {\n const result = await handleViolation(ctx, env, info, importerIdHint, {\n silent: true,\n })\n\n if (config.command === 'build') {\n // Build mode: store for generateBundle tree-shaking check.\n // The mock-edge module ID is returned as a plain string.\n const mockId = result ?? ''\n env.deferredBuildViolations.push({\n info,\n mockModuleId: mockId,\n // For marker violations, check importer survival instead of mock.\n checkModuleId: info.type === 'marker' ? info.importer : undefined,\n })\n } else {\n // Dev mock: store for graph-reachability check.\n deferViolation(env, importerFile, info, isPreTransformResolve)\n await processPendingViolations(env, ctx.warn.bind(ctx))\n }\n\n return result\n }\n\n // Non-deferred path: dev error mode only.\n // Pre-transform resolves are silenced because they fire before the\n // compiler runs — imports inside `.server()` callbacks haven't been\n // stripped yet and error mode has no deferred verification.\n return handleViolation(ctx, env, info, importerIdHint, {\n silent: isPreTransformResolve,\n })\n }\n\n return [\n {\n name: 'tanstack-start-core:import-protection',\n enforce: 'pre',\n\n applyToEnvironment(env) {\n if (!config.enabled) return false\n // Start's environments are named `client` and `ssr` (not `server`), plus\n // an optional serverFn provider environment (eg `rsc`) when configured.\n return environmentNames.has(env.name)\n },\n\n configResolved(viteConfig) {\n config.root = viteConfig.root\n config.command = viteConfig.command\n\n const { startConfig, resolvedStartConfig } = opts.getConfig()\n config.srcDirectory = resolvedStartConfig.srcDirectory\n\n const userOpts: ImportProtectionOptions | undefined =\n startConfig.importProtection\n\n if (userOpts?.enabled === false) {\n config.enabled = false\n return\n }\n\n config.enabled = true\n\n const behavior = userOpts?.behavior\n if (typeof behavior === 'string') {\n config.effectiveBehavior = behavior\n } else {\n config.effectiveBehavior =\n viteConfig.command === 'serve'\n ? (behavior?.dev ?? 'mock')\n : (behavior?.build ?? 'error')\n }\n\n config.logMode = userOpts?.log ?? 'once'\n config.mockAccess = userOpts?.mockAccess ?? 'error'\n config.maxTraceDepth = userOpts?.maxTraceDepth ?? 20\n if (userOpts?.onViolation) {\n const fn = userOpts.onViolation\n config.onViolation = (info) => fn(info)\n }\n\n const defaults = getDefaultImportProtectionRules()\n // Use user-provided patterns when available, otherwise defaults.\n const pick = <T>(user: Array<T> | undefined, fallback: Array<T>) =>\n user ? [...user] : [...fallback]\n\n // Client specifier denies always include framework defaults even\n // when the user provides a custom list.\n const clientSpecifiers = dedupePatterns([\n ...defaults.client.specifiers,\n ...(userOpts?.client?.specifiers ?? []),\n ])\n\n config.compiledRules.client = {\n specifiers: compileMatchers(clientSpecifiers),\n files: compileMatchers(\n pick(userOpts?.client?.files, defaults.client.files),\n ),\n excludeFiles: compileMatchers(\n pick(userOpts?.client?.excludeFiles, defaults.client.excludeFiles),\n ),\n }\n config.compiledRules.server = {\n specifiers: compileMatchers(\n dedupePatterns(\n pick(userOpts?.server?.specifiers, defaults.server.specifiers),\n ),\n ),\n files: compileMatchers(\n pick(userOpts?.server?.files, defaults.server.files),\n ),\n excludeFiles: compileMatchers(\n pick(userOpts?.server?.excludeFiles, defaults.server.excludeFiles),\n ),\n }\n\n config.includeMatchers = compileMatchers(userOpts?.include ?? [])\n config.excludeMatchers = compileMatchers(userOpts?.exclude ?? [])\n config.ignoreImporterMatchers = compileMatchers(\n userOpts?.ignoreImporters ?? [],\n )\n\n // Marker specifiers\n const markers = getMarkerSpecifiers()\n config.markerSpecifiers = {\n serverOnly: new Set(markers.serverOnly),\n clientOnly: new Set(markers.clientOnly),\n }\n },\n\n configureServer(server) {\n devServer = server\n },\n\n buildStart() {\n if (!config.enabled) return\n // Clear memoization caches that grow unboundedly across builds\n clearNormalizeFilePathCache()\n extensionlessIdResolver.clear()\n shouldCheckImporterCache.clear()\n\n // Clear per-env caches\n for (const envState of envStates.values()) {\n clearEnvState(envState)\n }\n\n // Clear shared state\n shared.fileMarkerKind.clear()\n\n registerEntries()\n },\n\n hotUpdate(ctx) {\n if (!config.enabled) return\n // Invalidate caches for updated files\n for (const mod of ctx.modules) {\n if (mod.id) {\n const id = mod.id\n const importerFile = normalizeFilePath(id)\n\n // Invalidate extensionless-resolution cache entries affected by this file.\n extensionlessIdResolver.invalidateByFile(importerFile)\n shared.fileMarkerKind.delete(importerFile)\n\n // Invalidate per-env caches\n for (const envState of envStates.values()) {\n invalidateFileFromEnv(envState, importerFile)\n }\n }\n }\n },\n\n async resolveId(source, importer, _options) {\n const envName = this.environment.name\n const env = getEnv(envName)\n const envType = getImportProtectionEnvType(config, envName)\n const provider = env.transformResultProvider\n const isScanResolve = !!(_options as Record<string, unknown>).scan\n\n if (IMPORT_PROTECTION_DEBUG) {\n const importerPath = importer\n ? normalizeFilePath(importer)\n : '(entry)'\n const isEntryResolve = !importer\n const filtered =\n process.env.TSR_IMPORT_PROTECTION_DEBUG_FILTER === 'entry'\n ? isEntryResolve\n : matchesDebugFilter(source, importerPath)\n if (filtered) {\n debugLog('resolveId', {\n env: envName,\n envType,\n source,\n importer: importerPath,\n isEntryResolve,\n command: config.command,\n })\n }\n }\n\n // Internal virtual modules (mock:build:N, mock-edge, mock-runtime, marker)\n const internalVirtualId = resolveInternalVirtualModuleId(source)\n if (internalVirtualId) return internalVirtualId\n\n if (!importer) {\n env.graph.addEntry(source)\n // Flush pending violations now that an additional entry is known\n // and reachability analysis may have new roots.\n await processPendingViolations(env, this.warn.bind(this))\n return undefined\n }\n\n if (source.startsWith('\\0') || source.startsWith('virtual:')) {\n return undefined\n }\n\n const normalizedImporter = normalizeFilePath(importer)\n const isDirectLookup = importer.includes(SERVER_FN_LOOKUP_QUERY)\n\n if (isDirectLookup) {\n env.serverFnLookupModules.add(normalizedImporter)\n }\n\n const isPreTransformResolve =\n isDirectLookup ||\n env.serverFnLookupModules.has(normalizedImporter) ||\n isScanResolve\n\n // Dev mock mode: defer all violations (including pre-transform\n // resolves) until post-transform data is available, then\n // confirm/discard via graph reachability.\n // Build mode (both mock and error): defer violations until\n // generateBundle so tree-shaking can eliminate false positives.\n const isDevMock =\n config.command === 'serve' && config.effectiveBehavior === 'mock'\n const isBuild = config.command === 'build'\n const shouldDefer = shouldDeferViolation({ isBuild, isDevMock })\n\n const resolveAgainstImporter = async (): Promise<string | null> => {\n const primary = await this.resolve(source, importer, {\n skipSelf: true,\n })\n if (primary) {\n return canonicalizeResolvedId(\n primary.id,\n config.root,\n resolveExtensionlessAbsoluteId,\n )\n }\n\n return null\n }\n\n // Check if this is a marker import\n const markerKind = config.markerSpecifiers.serverOnly.has(source)\n ? ('server' as const)\n : config.markerSpecifiers.clientOnly.has(source)\n ? ('client' as const)\n : undefined\n\n if (markerKind) {\n const existing = shared.fileMarkerKind.get(normalizedImporter)\n if (existing && existing !== markerKind) {\n this.error(\n `[import-protection] File \"${getRelativePath(normalizedImporter)}\" has both server-only and client-only markers. This is not allowed.`,\n )\n }\n shared.fileMarkerKind.set(normalizedImporter, markerKind)\n\n const violatesEnv =\n (envType === 'client' && markerKind === 'server') ||\n (envType === 'server' && markerKind === 'client')\n\n if (violatesEnv) {\n const info = await buildViolationInfo(\n provider,\n env,\n envName,\n envType,\n importer,\n normalizedImporter,\n source,\n {\n type: 'marker',\n },\n )\n const markerResult = await reportOrDeferViolation(\n this,\n env,\n normalizedImporter,\n importer,\n info,\n shouldDefer,\n isPreTransformResolve,\n )\n\n // In build mode, if the violation was deferred, return the unique\n // build mock ID instead of the marker module. This lets\n // generateBundle check whether the importer (and thus its marker\n // import) survived tree-shaking. The mock is side-effect-free just\n // like the marker module, and the bare import has no bindings, so\n // replacing it is transparent.\n if (isBuild && markerResult != null) {\n return markerResult\n }\n }\n\n // Retroactive marker violation detection: on cold starts, module\n // A may import module B before B's marker is set (because B hasn't\n // been processed yet). When B's marker is set (here),\n // retroactively check all known importers of B in the graph and\n // create deferred marker violations for them. Without this,\n // cold-start ordering can miss marker violations that warm starts\n // detect (warm starts see markers early from cached transforms).\n //\n // Uses lightweight `deferViolation` to avoid heavy side effects\n // (mock module creation, export resolution). Immediately calls\n // `processPendingViolations` to flush the deferred violations,\n // because the marker resolveId fires during Vite's import\n // analysis (after our transform hook) — there may be no\n // subsequent transform invocation to flush them.\n //\n // Guarded by `violatesEnv` (per-environment) plus a per-env\n // seen-set. The marker is shared across environments but each\n // env's graph has its own edges; this ensures the check runs\n // at most once per (env, module) pair.\n const envRetroKey = `retro-marker:${normalizedImporter}`\n if (violatesEnv && !env.seenViolations.has(envRetroKey)) {\n env.seenViolations.add(envRetroKey)\n let retroDeferred = false\n const importersMap = env.graph.reverseEdges.get(normalizedImporter)\n if (importersMap && importersMap.size > 0) {\n for (const [importerFile, specifier] of importersMap) {\n if (!specifier) continue\n if (!shouldCheckImporter(importerFile)) continue\n const markerInfo = await buildMarkerViolationFromResolvedImport(\n provider,\n env,\n envName,\n envType,\n importerFile,\n specifier,\n normalizedImporter,\n )\n if (markerInfo) {\n deferViolation(\n env,\n importerFile,\n markerInfo,\n isPreTransformResolve,\n )\n retroDeferred = true\n }\n }\n }\n if (retroDeferred) {\n await processPendingViolations(env, this.warn.bind(this))\n }\n }\n\n return markerKind === 'server'\n ? resolvedMarkerVirtualModuleId('server')\n : resolvedMarkerVirtualModuleId('client')\n }\n\n // Check if the importer is within our scope\n if (!shouldCheckImporter(normalizedImporter)) {\n return undefined\n }\n\n const matchers = getRulesForEnvironment(envName)\n\n // 1. Specifier-based denial\n const specifierMatch = matchesAny(source, matchers.specifiers)\n if (specifierMatch) {\n if (!isPreTransformResolve) {\n env.graph.addEdge(source, normalizedImporter, source)\n }\n const info = await buildViolationInfo(\n provider,\n env,\n envName,\n envType,\n importer,\n normalizedImporter,\n source,\n {\n type: 'specifier',\n pattern: specifierMatch.pattern,\n },\n )\n\n // Resolve the specifier so edge-survival can verify whether\n // the import survives the Start compiler transform (e.g.\n // factory-safe pattern strips imports inside .server() callbacks).\n if (shouldDefer && !info.resolved) {\n try {\n const resolvedForInfo = await resolveAgainstImporter()\n if (resolvedForInfo) info.resolved = resolvedForInfo\n } catch {\n // Non-fatal: edge-survival will skip unresolved specifiers\n }\n }\n\n return reportOrDeferViolation(\n this,\n env,\n normalizedImporter,\n importer,\n info,\n shouldDefer,\n isPreTransformResolve,\n )\n }\n\n // 2. Resolve the import (cached)\n const cacheKey = `${normalizedImporter}:${source}`\n let resolved: string | null\n\n if (env.resolveCache.has(cacheKey)) {\n resolved = env.resolveCache.get(cacheKey) ?? null\n } else {\n resolved = await resolveAgainstImporter()\n\n // Only cache successful resolves. Null resolves can be\n // order-dependent across importer variants (e.g. code-split\n // `?tsr-split=...` ids) and may poison later lookups.\n if (resolved !== null) {\n env.resolveCache.set(cacheKey, resolved)\n getOrCreate(\n env.resolveCacheByFile,\n normalizedImporter,\n () => new Set(),\n ).add(cacheKey)\n }\n }\n\n if (resolved) {\n const relativePath = getRelativePath(resolved)\n\n // Propagate pre-transform status transitively\n if (isPreTransformResolve && !isScanResolve) {\n env.serverFnLookupModules.add(resolved)\n }\n\n if (!isPreTransformResolve) {\n env.graph.addEdge(resolved, normalizedImporter, source)\n }\n\n // Skip file-based and marker-based denial for resolved paths that\n // match the per-environment `excludeFiles` patterns. By default\n // this includes `**/node_modules/**` so that third-party packages\n // using `.client.` / `.server.` in their filenames (e.g. react-tweet\n // exports `index.client.js`) are not treated as user-authored\n // environment boundaries. Users can override `excludeFiles` per\n // environment to narrow or widen this exclusion.\n const isExcludedFile = isFileExcluded(relativePath, matchers)\n\n if (!isExcludedFile) {\n const fileMatch = checkFileDenial(relativePath, matchers)\n\n if (fileMatch) {\n const info = await buildFileViolationInfo(\n provider,\n env,\n envName,\n envType,\n importer,\n normalizedImporter,\n source,\n resolved,\n fileMatch.pattern,\n )\n return reportOrDeferViolation(\n this,\n env,\n normalizedImporter,\n importer,\n info,\n shouldDefer,\n isPreTransformResolve,\n )\n }\n\n const markerInfo = await buildMarkerViolationFromResolvedImport(\n provider,\n env,\n envName,\n envType,\n importer,\n source,\n resolved,\n )\n if (markerInfo) {\n return reportOrDeferViolation(\n this,\n env,\n normalizedImporter,\n importer,\n markerInfo,\n shouldDefer,\n isPreTransformResolve,\n )\n }\n }\n }\n\n return undefined\n },\n\n load: {\n filter: {\n id: new RegExp(\n getResolvedVirtualModuleMatchers().map(escapeRegExp).join('|'),\n ),\n },\n handler(id) {\n if (IMPORT_PROTECTION_DEBUG) {\n if (matchesDebugFilter(id)) {\n debugLog('load:handler', {\n env: this.environment.name,\n id: normalizePath(id),\n })\n }\n }\n\n return loadResolvedVirtualModule(id)\n },\n },\n\n async generateBundle(_options, bundle) {\n const envName = this.environment.name\n const env = envStates.get(envName)\n if (!env || env.deferredBuildViolations.length === 0) return\n\n const candidateCache = new Map<string, Array<string>>()\n const toModuleIdCandidates = (id: string): Array<string> => {\n let cached = candidateCache.get(id)\n if (cached) return cached\n\n const out = new Set<string>()\n const normalized = normalizeFilePath(id)\n out.add(id)\n out.add(normalized)\n out.add(relativizePath(normalized, config.root))\n\n if (normalized.startsWith(VITE_BROWSER_VIRTUAL_PREFIX)) {\n const internal = `\\0${normalized.slice(VITE_BROWSER_VIRTUAL_PREFIX.length)}`\n out.add(internal)\n out.add(relativizePath(normalizeFilePath(internal), config.root))\n }\n\n if (normalized.startsWith('\\0')) {\n const browser = `${VITE_BROWSER_VIRTUAL_PREFIX}${normalized.slice(1)}`\n out.add(browser)\n out.add(relativizePath(normalizeFilePath(browser), config.root))\n }\n\n cached = Array.from(out)\n candidateCache.set(id, cached)\n return cached\n }\n\n // Collect all module IDs that survived tree-shaking in this bundle.\n const survivingModules = new Set<string>()\n for (const chunk of Object.values(bundle)) {\n if (chunk.type === 'chunk') {\n for (const moduleId of Object.keys(chunk.modules)) {\n for (const candidate of toModuleIdCandidates(moduleId)) {\n survivingModules.add(candidate)\n }\n }\n }\n }\n\n const didModuleSurvive = (moduleId: string): boolean =>\n toModuleIdCandidates(moduleId).some((candidate) =>\n survivingModules.has(candidate),\n )\n\n // Check each deferred violation: if its check module survived\n // in the bundle, the import was NOT tree-shaken — real leak.\n const realViolations: Array<ViolationInfo> = []\n for (const {\n info,\n mockModuleId,\n checkModuleId,\n } of env.deferredBuildViolations) {\n let survived: boolean\n if (checkModuleId != null) {\n // Marker violation: check if the importer survived\n // (marker is about the file's directive, not a binding).\n // Include transform-result keys (e.g. code-split variants)\n // to cover all bundle representations of the importer.\n const importerVariantIds = new Set<string>([info.importer])\n const importerKeys = env.transformResultKeysByFile.get(\n normalizeFilePath(info.importer),\n )\n if (importerKeys) {\n for (const key of importerKeys) {\n importerVariantIds.add(key)\n }\n }\n survived = false\n for (const importerId of importerVariantIds) {\n if (didModuleSurvive(importerId)) {\n survived = true\n break\n }\n }\n } else {\n // File/specifier violation: check if the mock module survived.\n survived = didModuleSurvive(mockModuleId)\n }\n\n if (!survived) continue\n\n if (config.onViolation) {\n const result = await config.onViolation(info)\n if (result === false) continue\n }\n\n realViolations.push(info)\n }\n\n if (realViolations.length === 0) return\n\n if (config.effectiveBehavior === 'error') {\n // Error mode: fail the build on the first real violation.\n this.error(formatViolation(realViolations[0]!, config.root))\n } else {\n // Mock mode: warn for each surviving violation.\n const seen = new Set<string>()\n for (const info of realViolations) {\n const key = dedupeKey(info)\n if (!seen.has(key)) {\n seen.add(key)\n this.warn(formatViolation(info, config.root))\n }\n }\n }\n },\n },\n {\n // Captures transformed code + composed sourcemap for location mapping.\n // Runs after all `enforce: 'pre'` hooks (including the Start compiler).\n // Only files under `srcDirectory` are cached.\n name: 'tanstack-start-core:import-protection-transform-cache',\n\n applyToEnvironment(env) {\n if (!config.enabled) return false\n return environmentNames.has(env.name)\n },\n\n transform: {\n filter: {\n id: {\n include: [/\\.[cm]?[tj]sx?($|\\?)/],\n },\n },\n async handler(code, id) {\n const envName = this.environment.name\n const file = normalizeFilePath(id)\n const envType = getImportProtectionEnvType(config, envName)\n const matchers = getRulesForEnvironment(envName)\n const isBuild = config.command === 'build'\n\n if (IMPORT_PROTECTION_DEBUG) {\n if (matchesDebugFilter(file)) {\n debugLog('transform-cache', {\n env: envName,\n id: normalizePath(id),\n file,\n })\n }\n }\n\n if (!shouldCheckImporter(file)) {\n return undefined\n }\n\n // Self-denial: if this file is denied in the current environment\n // (e.g. a `.server` file transformed in the client environment),\n // replace its entire content with a mock module.\n //\n // This is the core mechanism for preventing cross-environment\n // cache contamination: resolveId never returns virtual module\n // IDs for file-based violations, so there is nothing for\n // third-party resolver caches (e.g. vite-tsconfig-paths) to\n // leak across environments. Each environment's transform\n // independently decides whether the file is denied.\n //\n // In dev mode, this also solves the cold-start problem where\n // the importer's AST is unavailable for export resolution:\n // the denied file's own source code is always available here,\n // so we parse its exports directly.\n const selfFileMatch = checkFileDenial(getRelativePath(file), matchers)\n if (selfFileMatch) {\n // Parse exports once — shared by build and dev paths.\n // Falls back to empty list on non-standard syntax.\n let exportNames: Array<string> = []\n try {\n exportNames = getNamedExports(code)\n } catch {\n // Parsing may fail on non-standard syntax\n }\n\n if (isBuild) {\n return generateSelfContainedMockModule(exportNames)\n }\n\n // Dev mode: generate a mock that imports mock-runtime for\n // runtime diagnostics (error/warn on property access).\n const runtimeId = mockRuntimeModuleIdFromViolation(\n {\n type: 'file',\n env: envType,\n envType,\n behavior:\n config.effectiveBehavior === 'error' ? 'error' : 'mock',\n importer: file,\n specifier: relativizePath(file, config.root),\n resolved: file,\n pattern: selfFileMatch.pattern,\n trace: [],\n },\n config.mockAccess,\n config.root,\n )\n return generateDevSelfDenialModule(exportNames, runtimeId)\n }\n\n // getCombinedSourcemap() returns the composed sourcemap\n let map: SourceMapLike | undefined\n try {\n map = this.getCombinedSourcemap()\n } catch {\n map = undefined\n }\n\n let originalCode: string | undefined\n if (map?.sourcesContent) {\n originalCode = pickOriginalCodeFromSourcesContent(\n map,\n file,\n config.root,\n )\n }\n\n const lineIndex = buildLineIndex(code)\n const cacheKey = normalizePath(id)\n\n const envState = getEnv(envName)\n const isServerFnLookup = id.includes(SERVER_FN_LOOKUP_QUERY)\n\n // Propagate SERVER_FN_LOOKUP status before import-analysis\n if (isServerFnLookup) {\n envState.serverFnLookupModules.add(file)\n }\n\n const result: TransformResult = {\n code,\n map,\n originalCode,\n lineIndex,\n }\n cacheTransformResult(envState, file, cacheKey, result)\n\n // Build mode: only self-denial (above) and transform caching are\n // needed. All violations are detected and deferred in resolveId;\n // self-denial replaces denied file content; generateBundle checks\n // tree-shaking survival. The import resolution loop below is\n // dev-mode only — it resolves imports for graph reachability,\n // catches violations missed on warm starts (where Vite caches\n // resolveId), and rewrites denied imports to mock modules.\n if (isBuild) return undefined\n\n // Dev mode: resolve imports, populate graph, detect violations,\n // and rewrite denied imports.\n const isDevMock = config.effectiveBehavior === 'mock'\n const importSources = getImportSources(code)\n const resolvedChildren = new Set<string>()\n const deniedSourceReplacements = new Map<string, string>()\n for (const src of importSources) {\n try {\n const resolved = await this.resolve(src, id, { skipSelf: true })\n if (resolved && !resolved.external) {\n const resolvedPath = canonicalizeResolvedId(\n resolved.id,\n config.root,\n resolveExtensionlessAbsoluteId,\n )\n\n resolvedChildren.add(resolvedPath)\n\n // When the resolved ID is a mock-module (from our\n // resolveId returning a mock-edge ID), postTransformImports\n // would only contain the mock ID. Edge-survival needs the\n // real physical path so pending violations can be matched.\n //\n // For relative specifiers we can compute the physical path\n // directly. For bare/alias specifiers, look up the real\n // resolved path from the pending violations that were\n // already stored by resolveId before this transform ran.\n if (resolved.id.includes('tanstack-start-import-protection:')) {\n let physicalPath: string | undefined\n // Look up real resolved path from pending violations\n const pending = envState.pendingViolations.get(file)\n if (pending) {\n const match = pending.find(\n (pv) => pv.info.specifier === src && pv.info.resolved,\n )\n if (match) physicalPath = match.info.resolved\n }\n if (physicalPath && physicalPath !== resolvedPath) {\n resolvedChildren.add(physicalPath)\n envState.graph.addEdge(physicalPath, file, src)\n }\n }\n\n // Populate import graph edges for warm-start trace accuracy\n envState.graph.addEdge(resolvedPath, file, src)\n\n if (isDevMock) {\n const relativePath = getRelativePath(resolvedPath)\n const fileMatch = checkFileDenial(relativePath, matchers)\n\n if (fileMatch) {\n const info = await buildFileViolationInfo(\n envState.transformResultProvider,\n envState,\n envName,\n envType,\n id,\n file,\n src,\n resolvedPath,\n fileMatch.pattern,\n )\n\n const replacement = await reportOrDeferViolation(\n this,\n envState,\n file,\n id,\n info,\n isDevMock,\n isServerFnLookup,\n )\n\n if (replacement) {\n deniedSourceReplacements.set(\n src,\n replacement.startsWith('\\0')\n ? VITE_BROWSER_VIRTUAL_PREFIX + replacement.slice(1)\n : replacement,\n )\n }\n }\n }\n }\n } catch {\n // Non-fatal\n }\n }\n envState.postTransformImports.set(cacheKey, resolvedChildren)\n if (cacheKey !== file && !isServerFnLookup) {\n envState.postTransformImports.set(file, resolvedChildren)\n }\n\n await processPendingViolations(envState, this.warn.bind(this))\n\n if (deniedSourceReplacements.size > 0) {\n try {\n const rewritten = rewriteDeniedImports(\n code,\n id,\n new Set(deniedSourceReplacements.keys()),\n (source: string) =>\n deniedSourceReplacements.get(source) ?? source,\n )\n\n if (!rewritten) {\n return undefined\n }\n\n const normalizedMap = rewritten.map\n ? normalizeSourceMap(rewritten.map)\n : {\n version: 3,\n file: id,\n names: [],\n sources: [id],\n sourcesContent: [code],\n mappings: '',\n }\n\n return {\n code: rewritten.code,\n map: normalizedMap,\n }\n } catch {\n // Non-fatal: keep original code when rewrite fails.\n }\n }\n\n return undefined\n },\n },\n },\n ] satisfies Array<PluginOption>\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkGA,SAAgB,uBACd,MACc;CACd,IAAI,YAAkC;CACtC,MAAM,0BAA0B,IAAI,iCAAiC;CACrE,MAAM,kCAAkC,OACtC,wBAAwB,QAAQ,GAAG;CACrC,MAAM,+BAA+B,oCAAoC;;;;;;CAOzE,SAAS,0BACP,SACA,KACA,YACyB;AACzB,MAAI,CAAC,UAAW,QAAO;EACvB,MAAM,cAAc,UAAU,aAAa;AAC3C,MAAI,CAAC,YAAa,QAAO;EAEzB,MAAM,OAAO,kBAAkB,WAAW;EAC1C,MAAM,QAAQ,YAAY,YAAY,cAAc,KAAK;AACzD,MAAI,CAAC,MAAO,QAAO;EAInB,MAAM,0BAAU,IAAI,KAA8B;EAClD,SAAS,OAAO,GAA4B;GAC1C,IAAI,SAAS,QAAQ,IAAI,EAAE;AAC3B,OAAI,WAAW,KAAA,GAAW;AACxB,aAAS,EAAE,KACP,kB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,aAAa,EACF,SAAS;AAEzD,WAAI,WAAW;QACb,MAAM,OAAO,MAAM,uBACjB,SAAS,yBACT,UACA,SACA,SACA,IACA,MACA,KACA,cACA,UAAU,QACX;QAED,MAAM,cAAc,MAAM,uBACxB,MACA,UACA,MACA,IACA,MACA,WACA,iBACD;AAED,YAAI,YACF,0BAAyB,IACvB,KACA,YAAY,WAAW,KAAK,GACxB,8BAA8B,YAAY,MAAM,EAAE,GAClD,YACL;;;;YAKH;AAIV,aAAS,qBAAqB,IAAI,UAAU,iBAAiB;AAC7D,QAAI,aAAa,QAAQ,CAAC,iBACxB,UAAS,qBAAqB,IAAI,MAAM,iBAAiB;AAG3D,UAAM,yBAAyB,UAAU,KAAK,KAAK,KAAK,KAAK,CAAC;AAE9D,QAAI,yBAAyB,OAAO,EAClC,KAAI;KACF,MAAM,YAAY,qBAChB,MACA,IACA,IAAI,IAAI,yBAAyB,MAAM,CAAC,GACvC,WACC,yBAAyB,IAAI,OAAO,IAAI,OAC3C;AAED,SAAI,CAAC,UACH;KAGF,MAAM,gBAAgB,UAAU,MAC5B,mBAAmB,UAAU,IAAI,GACjC;MACE,SAAS;MACT,MAAM;MACN,OAAO,EAAE;MACT,SAAS,CAAC,GAAG;MACb,gBAAgB,CAAC,KAAK;MACtB,UAAU;MACX;AAEL,YAAO;MACL,MAAM,UAAU;MAChB,KAAK;MACN;YACK;;GAOb;EACF,CACF"}
@@ -1,8 +1,8 @@
1
- import { CompileStartFrameworkOptions, GetConfigFn } from '../types.js';
2
- import { ImportProtectionBehavior } from '../schema.js';
3
- import { CompiledMatcher } from './matchers.js';
4
- import { ImportGraph, ViolationInfo } from './trace.js';
5
- import { ImportLocCache, TransformResult, TransformResultProvider } from './sourceLocation.js';
1
+ import { CompileStartFrameworkOptions, GetConfigFn } from '../../types.js';
2
+ import { ImportProtectionBehavior } from '../../schema.js';
3
+ import { CompiledMatcher } from '../../import-protection/matchers.js';
4
+ import { ImportGraph, ViolationInfo } from '../../import-protection/trace.js';
5
+ import { ImportLocCache, TransformResult, TransformResultProvider } from '../../import-protection/sourceLocation.js';
6
6
  /** Compiled deny/exclude patterns for one environment (client or server). */
7
7
  export interface EnvRules {
8
8
  specifiers: Array<CompiledMatcher>;