@tanstack/start-plugin-core 1.160.1 → 1.161.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 (58) hide show
  1. package/dist/esm/dev-server-plugin/plugin.js +1 -1
  2. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  3. package/dist/esm/import-protection-plugin/defaults.d.ts +17 -0
  4. package/dist/esm/import-protection-plugin/defaults.js +36 -0
  5. package/dist/esm/import-protection-plugin/defaults.js.map +1 -0
  6. package/dist/esm/import-protection-plugin/matchers.d.ts +13 -0
  7. package/dist/esm/import-protection-plugin/matchers.js +31 -0
  8. package/dist/esm/import-protection-plugin/matchers.js.map +1 -0
  9. package/dist/esm/import-protection-plugin/plugin.d.ts +16 -0
  10. package/dist/esm/import-protection-plugin/plugin.js +699 -0
  11. package/dist/esm/import-protection-plugin/plugin.js.map +1 -0
  12. package/dist/esm/import-protection-plugin/postCompileUsage.d.ts +11 -0
  13. package/dist/esm/import-protection-plugin/postCompileUsage.js +177 -0
  14. package/dist/esm/import-protection-plugin/postCompileUsage.js.map +1 -0
  15. package/dist/esm/import-protection-plugin/rewriteDeniedImports.d.ts +27 -0
  16. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js +51 -0
  17. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js.map +1 -0
  18. package/dist/esm/import-protection-plugin/sourceLocation.d.ts +132 -0
  19. package/dist/esm/import-protection-plugin/sourceLocation.js +255 -0
  20. package/dist/esm/import-protection-plugin/sourceLocation.js.map +1 -0
  21. package/dist/esm/import-protection-plugin/trace.d.ts +67 -0
  22. package/dist/esm/import-protection-plugin/trace.js +204 -0
  23. package/dist/esm/import-protection-plugin/trace.js.map +1 -0
  24. package/dist/esm/import-protection-plugin/utils.d.ts +8 -0
  25. package/dist/esm/import-protection-plugin/utils.js +29 -0
  26. package/dist/esm/import-protection-plugin/utils.js.map +1 -0
  27. package/dist/esm/import-protection-plugin/virtualModules.d.ts +25 -0
  28. package/dist/esm/import-protection-plugin/virtualModules.js +235 -0
  29. package/dist/esm/import-protection-plugin/virtualModules.js.map +1 -0
  30. package/dist/esm/plugin.js +7 -0
  31. package/dist/esm/plugin.js.map +1 -1
  32. package/dist/esm/prerender.js +3 -3
  33. package/dist/esm/prerender.js.map +1 -1
  34. package/dist/esm/schema.d.ts +260 -0
  35. package/dist/esm/schema.js +35 -1
  36. package/dist/esm/schema.js.map +1 -1
  37. package/dist/esm/start-compiler-plugin/compiler.js +5 -1
  38. package/dist/esm/start-compiler-plugin/compiler.js.map +1 -1
  39. package/dist/esm/start-compiler-plugin/handleCreateServerFn.js +2 -2
  40. package/dist/esm/start-compiler-plugin/handleCreateServerFn.js.map +1 -1
  41. package/dist/esm/start-compiler-plugin/plugin.js.map +1 -1
  42. package/dist/esm/start-router-plugin/plugin.js +5 -5
  43. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  44. package/package.json +6 -3
  45. package/src/dev-server-plugin/plugin.ts +1 -1
  46. package/src/import-protection-plugin/defaults.ts +56 -0
  47. package/src/import-protection-plugin/matchers.ts +48 -0
  48. package/src/import-protection-plugin/plugin.ts +1173 -0
  49. package/src/import-protection-plugin/postCompileUsage.ts +266 -0
  50. package/src/import-protection-plugin/rewriteDeniedImports.ts +255 -0
  51. package/src/import-protection-plugin/sourceLocation.ts +524 -0
  52. package/src/import-protection-plugin/trace.ts +296 -0
  53. package/src/import-protection-plugin/utils.ts +32 -0
  54. package/src/import-protection-plugin/virtualModules.ts +300 -0
  55. package/src/plugin.ts +7 -0
  56. package/src/schema.ts +58 -0
  57. package/src/start-compiler-plugin/compiler.ts +12 -1
  58. package/src/start-compiler-plugin/plugin.ts +3 -3
package/src/schema.ts CHANGED
@@ -7,6 +7,53 @@ const tsrConfig = configSchema
7
7
  .omit({ autoCodeSplitting: true, target: true, verboseFileRoutes: true })
8
8
  .partial()
9
9
 
10
+ // --- Import Protection Schema ---
11
+
12
+ const patternSchema = z.union([z.string(), z.instanceof(RegExp)])
13
+
14
+ const importProtectionBehaviorSchema = z.enum(['error', 'mock'])
15
+
16
+ const importProtectionEnvRulesSchema = z.object({
17
+ specifiers: z.array(patternSchema).optional(),
18
+ files: z.array(patternSchema).optional(),
19
+ })
20
+
21
+ const importProtectionOptionsSchema = z
22
+ .object({
23
+ enabled: z.boolean().optional(),
24
+ behavior: z
25
+ .union([
26
+ importProtectionBehaviorSchema,
27
+ z.object({
28
+ dev: importProtectionBehaviorSchema.optional(),
29
+ build: importProtectionBehaviorSchema.optional(),
30
+ }),
31
+ ])
32
+ .optional(),
33
+ /**
34
+ * In `behavior: 'mock'`, control whether mocked imports emit a runtime
35
+ * console diagnostic when accessed.
36
+ *
37
+ * - 'error': console.error(new Error(...)) (default)
38
+ * - 'warn': console.warn(new Error(...))
39
+ * - 'off': disable runtime diagnostics
40
+ */
41
+ mockAccess: z.enum(['error', 'warn', 'off']).optional(),
42
+ onViolation: z
43
+ .function()
44
+ .args(z.any())
45
+ .returns(z.union([z.boolean(), z.void()]))
46
+ .optional(),
47
+ include: z.array(patternSchema).optional(),
48
+ exclude: z.array(patternSchema).optional(),
49
+ client: importProtectionEnvRulesSchema.optional(),
50
+ server: importProtectionEnvRulesSchema.optional(),
51
+ ignoreImporters: z.array(patternSchema).optional(),
52
+ maxTraceDepth: z.number().optional(),
53
+ log: z.enum(['once', 'always']).optional(),
54
+ })
55
+ .optional()
56
+
10
57
  export function parseStartConfig(
11
58
  opts: z.input<typeof tanstackStartOptionsSchema>,
12
59
  corePluginOpts: TanStackStartVitePluginCoreOptions,
@@ -201,6 +248,7 @@ const tanstackStartOptionsSchema = z
201
248
  vite: z
202
249
  .object({ installDevServerMiddleware: z.boolean().optional() })
203
250
  .optional(),
251
+ importProtection: importProtectionOptionsSchema,
204
252
  })
205
253
  .optional()
206
254
  .default({})
@@ -211,3 +259,13 @@ export type TanStackStartInputConfig = z.input<
211
259
  typeof tanstackStartOptionsSchema
212
260
  >
213
261
  export type TanStackStartOutputConfig = ReturnType<typeof parseStartConfig>
262
+
263
+ export type ImportProtectionBehavior = z.infer<
264
+ typeof importProtectionBehaviorSchema
265
+ >
266
+ export type ImportProtectionEnvRules = z.infer<
267
+ typeof importProtectionEnvRulesSchema
268
+ >
269
+ export type ImportProtectionOptions = z.input<
270
+ typeof importProtectionOptionsSchema
271
+ >
@@ -948,11 +948,22 @@ export class StartCompiler {
948
948
 
949
949
  deadCodeElimination(ast, refIdents)
950
950
 
951
- return generateFromAst(ast, {
951
+ const result = generateFromAst(ast, {
952
952
  sourceMaps: true,
953
953
  sourceFileName: id,
954
954
  filename: id,
955
955
  })
956
+
957
+ // @babel/generator does not populate sourcesContent because it only has
958
+ // the AST, not the original text. Without this, Vite's composed
959
+ // sourcemap omits the original source, causing downstream consumers
960
+ // (e.g. import-protection snippet display) to fall back to the shorter
961
+ // compiled output and fail to resolve original line numbers.
962
+ if (result.map) {
963
+ result.map.sourcesContent = [code]
964
+ }
965
+
966
+ return result
956
967
  }
957
968
 
958
969
  private async resolveIdentifierKind(
@@ -195,7 +195,7 @@ export function startCompilerPlugin(
195
195
  }
196
196
 
197
197
  let root = process.cwd()
198
- let command: 'build' | 'serve' = 'build'
198
+ let _command: 'build' | 'serve' = 'build'
199
199
 
200
200
  const resolvedResolverVirtualImportId = resolveViteId(
201
201
  VIRTUAL_MODULES.serverFnResolver,
@@ -229,7 +229,7 @@ export function startCompilerPlugin(
229
229
  },
230
230
  configResolved(config) {
231
231
  root = config.root
232
- command = config.command
232
+ _command = config.command
233
233
  },
234
234
  transform: {
235
235
  filter: {
@@ -423,7 +423,7 @@ export function startCompilerPlugin(
423
423
  },
424
424
  configResolved(config) {
425
425
  root = config.root
426
- command = config.command
426
+ _command = config.command
427
427
  },
428
428
  resolveId: {
429
429
  filter: { id: new RegExp(VIRTUAL_MODULES.serverFnResolver) },