11import { describe , expect , test , vi } from 'vitest'
22import { importProtectionPlugin } from '../../src/vite/import-protection-plugin/plugin'
33
4- describe ( 'importProtectionPlugin resolveId ' , ( ) => {
4+ describe ( 'importProtectionPlugin' , ( ) => {
55 test ( 'returns the nested resolver result when a resolved import is allowed' , async ( ) => {
66 const root = '/repo'
77 const plugin = createPlugin ( root )
@@ -38,9 +38,53 @@ describe('importProtectionPlugin resolveId', () => {
3838 skipSelf : true ,
3939 } )
4040 } )
41+
42+ test ( 'keeps bundled-dev client violations pending until route importers are known' , async ( ) => {
43+ const root = '/repo'
44+ const { plugin, transformCachePlugin } = createPlugins ( root , {
45+ command : 'serve' ,
46+ bundledDev : true ,
47+ } )
48+ plugin . buildStart ( )
49+
50+ const routeFile = `${ root } /src/routes/leak.tsx`
51+ const deniedFile = `${ root } /src/lib/secret.server.ts`
52+ const warn = vi . fn ( )
53+ const resolve = vi . fn ( async ( source : string ) =>
54+ source === '../lib/secret.server' ? { id : deniedFile } : null ,
55+ )
56+
57+ await transformCachePlugin . transform . handler . call (
58+ {
59+ environment : { name : 'client' } ,
60+ resolve,
61+ warn,
62+ error ( message : string ) {
63+ throw new Error ( message )
64+ } ,
65+ getCombinedSourcemap : ( ) => null ,
66+ } ,
67+ `import { secret } from '../lib/secret.server'
68+ export const value = secret
69+ ` ,
70+ routeFile ,
71+ )
72+
73+ expect ( warn ) . not . toHaveBeenCalled ( )
74+ } )
4175} )
4276
4377function createPlugin ( root : string ) : any {
78+ return createPlugins ( root ) . plugin
79+ }
80+
81+ function createPlugins (
82+ root : string ,
83+ opts : {
84+ command ?: 'build' | 'serve'
85+ bundledDev ?: boolean
86+ } = { } ,
87+ ) : { plugin : any ; transformCachePlugin : any } {
4488 const plugins = importProtectionPlugin ( {
4589 framework : 'react' ,
4690 providerEnvName : 'ssr' ,
@@ -62,12 +106,16 @@ function createPlugin(root: string): any {
62106 const plugin = plugins . find (
63107 ( item ) => item . name === 'tanstack-start-core:import-protection' ,
64108 ) !
109+ const transformCachePlugin = plugins . find (
110+ ( item ) =>
111+ item . name === 'tanstack-start-core:import-protection-transform-cache' ,
112+ ) !
65113
66114 plugin . configResolved ( {
67115 root,
68- command : 'build' ,
69- experimental : { bundledDev : false } ,
116+ command : opts . command ?? 'build' ,
117+ experimental : { bundledDev : opts . bundledDev ?? false } ,
70118 } )
71119
72- return plugin
120+ return { plugin, transformCachePlugin }
73121}
0 commit comments