@tanstack/start-plugin-core 1.167.35 → 1.168.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 (181) 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 +1 -1
  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 +12 -19
  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 +4 -0
  34. package/dist/esm/index.js +3 -1
  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/normalized-client-build.d.ts +18 -0
  48. package/dist/esm/rsbuild/normalized-client-build.js +207 -0
  49. package/dist/esm/rsbuild/normalized-client-build.js.map +1 -0
  50. package/dist/esm/rsbuild/planning.d.ts +52 -0
  51. package/dist/esm/rsbuild/planning.js +108 -0
  52. package/dist/esm/rsbuild/planning.js.map +1 -0
  53. package/dist/esm/rsbuild/plugin.d.ts +4 -0
  54. package/dist/esm/rsbuild/plugin.js +344 -0
  55. package/dist/esm/rsbuild/plugin.js.map +1 -0
  56. package/dist/esm/rsbuild/post-build.d.ts +6 -0
  57. package/dist/esm/rsbuild/post-build.js +57 -0
  58. package/dist/esm/rsbuild/post-build.js.map +1 -0
  59. package/dist/esm/rsbuild/schema.d.ts +3372 -0
  60. package/dist/esm/rsbuild/schema.js +12 -0
  61. package/dist/esm/rsbuild/schema.js.map +1 -0
  62. package/dist/esm/rsbuild/start-compiler-host.d.ts +20 -0
  63. package/dist/esm/rsbuild/start-compiler-host.js +150 -0
  64. package/dist/esm/rsbuild/start-compiler-host.js.map +1 -0
  65. package/dist/esm/rsbuild/start-router-plugin.d.ts +18 -0
  66. package/dist/esm/rsbuild/start-router-plugin.js +63 -0
  67. package/dist/esm/rsbuild/start-router-plugin.js.map +1 -0
  68. package/dist/esm/rsbuild/swc-rsc.d.ts +14 -0
  69. package/dist/esm/rsbuild/swc-rsc.js +93 -0
  70. package/dist/esm/rsbuild/swc-rsc.js.map +1 -0
  71. package/dist/esm/rsbuild/types.d.ts +17 -0
  72. package/dist/esm/rsbuild/types.js +0 -0
  73. package/dist/esm/rsbuild/virtual-modules.d.ts +53 -0
  74. package/dist/esm/rsbuild/virtual-modules.js +287 -0
  75. package/dist/esm/rsbuild/virtual-modules.js.map +1 -0
  76. package/dist/esm/schema.d.ts +43 -43
  77. package/dist/esm/start-compiler/compiler.d.ts +1 -1
  78. package/dist/esm/start-compiler/compiler.js +80 -9
  79. package/dist/esm/start-compiler/compiler.js.map +1 -1
  80. package/dist/esm/start-compiler/handleCreateServerFn.js +9 -0
  81. package/dist/esm/start-compiler/handleCreateServerFn.js.map +1 -1
  82. package/dist/esm/start-compiler/host.js +5 -1
  83. package/dist/esm/start-compiler/host.js.map +1 -1
  84. package/dist/esm/start-compiler/types.d.ts +1 -0
  85. package/dist/esm/utils.d.ts +1 -0
  86. package/dist/esm/utils.js +4 -1
  87. package/dist/esm/utils.js.map +1 -1
  88. package/dist/esm/{import-protection-plugin → vite/import-protection-plugin}/plugin.js +41 -92
  89. package/dist/esm/vite/import-protection-plugin/plugin.js.map +1 -0
  90. package/dist/esm/{import-protection-plugin → vite/import-protection-plugin}/types.d.ts +5 -5
  91. package/dist/esm/vite/import-protection-plugin/virtualModules.d.ts +8 -0
  92. package/dist/esm/vite/import-protection-plugin/virtualModules.js +49 -0
  93. package/dist/esm/vite/import-protection-plugin/virtualModules.js.map +1 -0
  94. package/dist/esm/vite/plugin.js +1 -1
  95. package/dist/esm/vite/plugin.js.map +1 -1
  96. package/dist/esm/vite/post-server-build.js +14 -32
  97. package/dist/esm/vite/post-server-build.js.map +1 -1
  98. package/dist/esm/vite/prerender.d.ts +2 -2
  99. package/dist/esm/vite/prerender.js +17 -147
  100. package/dist/esm/vite/prerender.js.map +1 -1
  101. package/dist/esm/vite/schema.d.ts +23 -23
  102. package/dist/esm/vite/start-compiler-plugin/hot-update.d.ts +2 -0
  103. package/dist/esm/vite/start-compiler-plugin/hot-update.js +16 -0
  104. package/dist/esm/vite/start-compiler-plugin/hot-update.js.map +1 -0
  105. package/dist/esm/vite/start-compiler-plugin/module-specifier.js +9 -4
  106. package/dist/esm/vite/start-compiler-plugin/module-specifier.js.map +1 -1
  107. package/dist/esm/vite/start-compiler-plugin/plugin.js +86 -13
  108. package/dist/esm/vite/start-compiler-plugin/plugin.js.map +1 -1
  109. package/package.json +17 -4
  110. package/src/import-protection/INTERNALS.md +266 -0
  111. package/src/import-protection/adapterUtils.ts +94 -0
  112. package/src/import-protection/analysis.ts +853 -0
  113. package/src/{import-protection-plugin → import-protection}/constants.ts +7 -0
  114. package/src/import-protection/rewrite.ts +229 -0
  115. package/src/{import-protection-plugin → import-protection}/sourceLocation.ts +125 -9
  116. package/src/{import-protection-plugin → import-protection}/trace.ts +0 -1
  117. package/src/{import-protection-plugin → import-protection}/utils.ts +35 -20
  118. package/src/{import-protection-plugin → import-protection}/virtualModules.ts +30 -177
  119. package/src/index.ts +5 -0
  120. package/src/post-build.ts +64 -0
  121. package/src/prerender.ts +292 -0
  122. package/src/rsbuild/INTERNALS-import-protection.md +169 -0
  123. package/src/rsbuild/dev-server.ts +129 -0
  124. package/src/rsbuild/import-protection.ts +1600 -0
  125. package/src/rsbuild/normalized-client-build.ts +346 -0
  126. package/src/rsbuild/planning.ts +234 -0
  127. package/src/rsbuild/plugin.ts +754 -0
  128. package/src/rsbuild/post-build.ts +96 -0
  129. package/src/rsbuild/schema.ts +31 -0
  130. package/src/rsbuild/start-compiler-host.ts +250 -0
  131. package/src/rsbuild/start-router-plugin.ts +86 -0
  132. package/src/rsbuild/swc-rsc.ts +166 -0
  133. package/src/rsbuild/types.ts +20 -0
  134. package/src/rsbuild/virtual-modules.ts +565 -0
  135. package/src/start-compiler/compiler.ts +153 -19
  136. package/src/start-compiler/handleCreateServerFn.ts +18 -0
  137. package/src/start-compiler/types.ts +1 -0
  138. package/src/utils.ts +4 -0
  139. package/src/vite/import-protection-plugin/INTERNALS.md +187 -0
  140. package/src/{import-protection-plugin → vite/import-protection-plugin}/plugin.ts +73 -158
  141. package/src/{import-protection-plugin → vite/import-protection-plugin}/types.ts +5 -5
  142. package/src/vite/import-protection-plugin/virtualModules.ts +122 -0
  143. package/src/vite/plugin.ts +1 -1
  144. package/src/vite/post-server-build.ts +14 -57
  145. package/src/vite/prerender.ts +19 -260
  146. package/src/vite/start-compiler-plugin/hot-update.ts +24 -0
  147. package/src/vite/start-compiler-plugin/module-specifier.ts +15 -5
  148. package/src/vite/start-compiler-plugin/plugin.ts +193 -18
  149. package/dist/esm/import-protection-plugin/ast.js.map +0 -1
  150. package/dist/esm/import-protection-plugin/constants.d.ts +0 -6
  151. package/dist/esm/import-protection-plugin/constants.js.map +0 -1
  152. package/dist/esm/import-protection-plugin/defaults.js.map +0 -1
  153. package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js.map +0 -1
  154. package/dist/esm/import-protection-plugin/matchers.js.map +0 -1
  155. package/dist/esm/import-protection-plugin/plugin.js.map +0 -1
  156. package/dist/esm/import-protection-plugin/postCompileUsage.d.ts +0 -13
  157. package/dist/esm/import-protection-plugin/postCompileUsage.js +0 -63
  158. package/dist/esm/import-protection-plugin/postCompileUsage.js.map +0 -1
  159. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js +0 -205
  160. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js.map +0 -1
  161. package/dist/esm/import-protection-plugin/sourceLocation.js.map +0 -1
  162. package/dist/esm/import-protection-plugin/trace.js.map +0 -1
  163. package/dist/esm/import-protection-plugin/utils.js.map +0 -1
  164. package/dist/esm/import-protection-plugin/virtualModules.d.ts +0 -78
  165. package/dist/esm/import-protection-plugin/virtualModules.js.map +0 -1
  166. package/dist/esm/start-compiler/load-module.d.ts +0 -14
  167. package/dist/esm/start-compiler/load-module.js +0 -18
  168. package/dist/esm/start-compiler/load-module.js.map +0 -1
  169. package/src/import-protection-plugin/INTERNALS.md +0 -700
  170. package/src/import-protection-plugin/postCompileUsage.ts +0 -100
  171. package/src/import-protection-plugin/rewriteDeniedImports.ts +0 -379
  172. package/src/start-compiler/load-module.ts +0 -31
  173. /package/dist/esm/{import-protection-plugin → import-protection}/ast.d.ts +0 -0
  174. /package/dist/esm/{import-protection-plugin → import-protection}/defaults.d.ts +0 -0
  175. /package/dist/esm/{import-protection-plugin → import-protection}/extensionlessAbsoluteIdResolver.d.ts +0 -0
  176. /package/dist/esm/{import-protection-plugin → import-protection}/matchers.d.ts +0 -0
  177. /package/dist/esm/{import-protection-plugin → vite/import-protection-plugin}/plugin.d.ts +0 -0
  178. /package/src/{import-protection-plugin → import-protection}/ast.ts +0 -0
  179. /package/src/{import-protection-plugin → import-protection}/defaults.ts +0 -0
  180. /package/src/{import-protection-plugin → import-protection}/extensionlessAbsoluteIdResolver.ts +0 -0
  181. /package/src/{import-protection-plugin → import-protection}/matchers.ts +0 -0
@@ -1,50 +1,16 @@
1
- import { promises as fsp } from 'node:fs'
2
- import os from 'node:os'
3
- import path from 'pathe'
4
- import { joinURL, withBase, withTrailingSlash, withoutBase } from 'ufo'
5
1
  import { VITE_ENVIRONMENT_NAMES } from '../constants'
6
- import { createLogger } from '../utils'
7
- import { Queue } from '../queue'
2
+ import { prerender } from '../prerender'
3
+ import type { PrerenderHandler } from '../prerender'
4
+ import type { TanStackStartOutputConfig } from '../schema'
8
5
  import type { PreviewServer, ResolvedConfig, ViteBuilder } from 'vite'
9
- import type { Page, TanStackStartOutputConfig } from '../schema'
10
6
 
11
- export async function prerender({
7
+ export async function prerenderWithVite({
12
8
  startConfig,
13
9
  builder,
14
10
  }: {
15
11
  startConfig: TanStackStartOutputConfig
16
12
  builder: ViteBuilder
17
13
  }) {
18
- const logger = createLogger('prerender')
19
- logger.info('Prerendering pages...')
20
-
21
- if (startConfig.prerender?.enabled) {
22
- let pages = startConfig.pages.length ? startConfig.pages : [{ path: '/' }]
23
-
24
- if (startConfig.prerender.autoStaticPathsDiscovery ?? true) {
25
- const pagesMap = new Map(pages.map((item) => [item.path, item]))
26
- const discoveredPages = globalThis.TSS_PRERENDABLE_PATHS || []
27
-
28
- for (const page of discoveredPages) {
29
- if (!pagesMap.has(page.path)) {
30
- pagesMap.set(page.path, page)
31
- }
32
- }
33
-
34
- pages = Array.from(pagesMap.values())
35
- }
36
-
37
- startConfig.pages = pages
38
- }
39
-
40
- const routerBasePath = joinURL('/', startConfig.router.basepath ?? '')
41
- const routerBaseUrl = new URL(routerBasePath, 'http://localhost')
42
-
43
- startConfig.pages = validateAndNormalizePrerenderPages(
44
- startConfig.pages,
45
- routerBaseUrl,
46
- )
47
-
48
14
  const serverEnv = builder.environments[VITE_ENVIRONMENT_NAMES.server]
49
15
 
50
16
  if (!serverEnv) {
@@ -68,203 +34,23 @@ export async function prerender({
68
34
  const previewServer = await startPreviewServer(serverEnv.config)
69
35
  const baseUrl = getResolvedUrl(previewServer)
70
36
 
71
- const isRedirectResponse = (res: Response) => {
72
- return res.status >= 300 && res.status < 400 && res.headers.get('location')
73
- }
74
-
75
- async function localFetch(
76
- path: string,
77
- options?: RequestInit,
78
- maxRedirects: number = 5,
79
- ): Promise<Response> {
80
- const url = new URL(path, baseUrl)
81
- const request = new Request(url, options)
82
- const response = await fetch(request)
83
-
84
- if (isRedirectResponse(response) && maxRedirects > 0) {
85
- const location = response.headers.get('location')!
86
- if (location.startsWith('http://localhost') || location.startsWith('/')) {
87
- const newUrl = location.replace('http://localhost', '')
88
- return localFetch(newUrl, options, maxRedirects - 1)
89
- }
90
-
91
- logger.warn(`Skipping redirect to external location: ${location}`)
92
- }
93
-
94
- return response
95
- }
96
-
97
- try {
98
- const pages = await prerenderPages({ outputDir })
99
-
100
- logger.info(`Prerendered ${pages.length} pages:`)
101
- pages.forEach((page) => {
102
- logger.info(`- ${page}`)
103
- })
104
- } catch (error) {
105
- logger.error(error)
106
- } finally {
107
- await previewServer.close()
37
+ const handler: PrerenderHandler = {
38
+ getClientOutputDirectory() {
39
+ return outputDir
40
+ },
41
+ request(path, options) {
42
+ const url = new URL(path, baseUrl)
43
+ return fetch(new Request(url, options))
44
+ },
45
+ close() {
46
+ return previewServer.close()
47
+ },
108
48
  }
109
49
 
110
- function extractLinks(html: string): Array<string> {
111
- const linkRegex = /<a[^>]+href=["']([^"']+)["'][^>]*>/g
112
- const links: Array<string> = []
113
- let match: RegExpExecArray | null
114
-
115
- while ((match = linkRegex.exec(html)) !== null) {
116
- const href = match[1]
117
- if (href && (href.startsWith('/') || href.startsWith('./'))) {
118
- links.push(href)
119
- }
120
- }
121
-
122
- return links
123
- }
124
-
125
- async function prerenderPages({ outputDir }: { outputDir: string }) {
126
- const seen = new Set<string>()
127
- const prerendered = new Set<string>()
128
- const retriesByPath = new Map<string, number>()
129
- const concurrency = startConfig.prerender?.concurrency ?? os.cpus().length
130
- logger.info(`Concurrency: ${concurrency}`)
131
- const queue = new Queue({ concurrency })
132
- const routerBasePath = joinURL('/', startConfig.router.basepath ?? '')
133
-
134
- const routerBaseUrl = new URL(routerBasePath, 'http://localhost')
135
- startConfig.pages = validateAndNormalizePrerenderPages(
136
- startConfig.pages,
137
- routerBaseUrl,
138
- )
139
-
140
- startConfig.pages.forEach((page) => addCrawlPageTask(page))
141
-
142
- if (queue.isSettled()) {
143
- logger.info('No pages matched prerender filter; skipping.')
144
- return Array.from(prerendered)
145
- }
146
-
147
- await queue.start()
148
-
149
- return Array.from(prerendered)
150
-
151
- function addCrawlPageTask(page: Page) {
152
- if (seen.has(page.path)) return
153
-
154
- seen.add(page.path)
155
-
156
- if (page.fromCrawl) {
157
- startConfig.pages.push(page)
158
- }
159
-
160
- if (!(page.prerender?.enabled ?? true)) return
161
-
162
- if (
163
- startConfig.prerender?.filter &&
164
- !startConfig.prerender.filter(page)
165
- ) {
166
- return
167
- }
168
-
169
- const prerenderOptions = {
170
- ...startConfig.prerender,
171
- ...page.prerender,
172
- }
173
-
174
- queue.add(async () => {
175
- logger.info(`Crawling: ${page.path}`)
176
- const retries = retriesByPath.get(page.path) || 0
177
- try {
178
- const res = await localFetch(
179
- withTrailingSlash(withBase(page.path, routerBasePath)),
180
- {
181
- headers: {
182
- ...(prerenderOptions.headers ?? {}),
183
- },
184
- },
185
- prerenderOptions.maxRedirects,
186
- )
187
-
188
- if (!res.ok) {
189
- if (isRedirectResponse(res)) {
190
- logger.warn(`Max redirects reached for ${page.path}`)
191
- }
192
- throw new Error(`Failed to fetch ${page.path}: ${res.statusText}`, {
193
- cause: res,
194
- })
195
- }
196
-
197
- const cleanPagePath = (
198
- prerenderOptions.outputPath || page.path
199
- ).split(/[?#]/)[0]!
200
-
201
- const contentType = res.headers.get('content-type') || ''
202
- const isImplicitHTML =
203
- !cleanPagePath.endsWith('.html') && contentType.includes('html')
204
-
205
- const routeWithIndex = cleanPagePath.endsWith('/')
206
- ? cleanPagePath + 'index'
207
- : cleanPagePath
208
-
209
- const isSpaShell =
210
- startConfig.spa?.prerender.outputPath === cleanPagePath
211
-
212
- let htmlPath: string
213
- if (isSpaShell) {
214
- htmlPath = cleanPagePath + '.html'
215
- } else if (
216
- cleanPagePath.endsWith('/') ||
217
- (prerenderOptions.autoSubfolderIndex ?? true)
218
- ) {
219
- htmlPath = joinURL(cleanPagePath, 'index.html')
220
- } else {
221
- htmlPath = cleanPagePath + '.html'
222
- }
223
-
224
- const filename = withoutBase(
225
- isImplicitHTML ? htmlPath : routeWithIndex,
226
- routerBasePath,
227
- )
228
-
229
- const html = await res.text()
230
-
231
- const filepath = path.join(outputDir, filename)
232
-
233
- await fsp.mkdir(path.dirname(filepath), {
234
- recursive: true,
235
- })
236
-
237
- await fsp.writeFile(filepath, html)
238
-
239
- prerendered.add(page.path)
240
-
241
- const newPage = await prerenderOptions.onSuccess?.({ page, html })
242
-
243
- if (newPage) {
244
- Object.assign(page, newPage)
245
- }
246
-
247
- if (prerenderOptions.crawlLinks ?? true) {
248
- const links = extractLinks(html)
249
- for (const link of links) {
250
- addCrawlPageTask({ path: link, fromCrawl: true })
251
- }
252
- }
253
- } catch (error) {
254
- if (retries < (prerenderOptions.retryCount ?? 0)) {
255
- logger.warn(`Encountered error, retrying: ${page.path} in 500ms`)
256
- await new Promise((resolve) =>
257
- setTimeout(resolve, prerenderOptions.retryDelay),
258
- )
259
- retriesByPath.set(page.path, retries + 1)
260
- addCrawlPageTask(page)
261
- } else if (prerenderOptions.failOnError ?? true) {
262
- throw error
263
- }
264
- }
265
- })
266
- }
267
- }
50
+ return prerender({
51
+ startConfig,
52
+ handler,
53
+ })
268
54
  }
269
55
 
270
56
  async function startPreviewServer(
@@ -299,30 +85,3 @@ function getResolvedUrl(previewServer: PreviewServer): URL {
299
85
 
300
86
  return new URL(baseUrl)
301
87
  }
302
-
303
- function validateAndNormalizePrerenderPages(
304
- pages: Array<Page>,
305
- routerBaseUrl: URL,
306
- ): Array<Page> {
307
- return pages.map((page) => {
308
- let url: URL
309
- try {
310
- url = new URL(page.path, routerBaseUrl)
311
- } catch (err) {
312
- throw new Error(`prerender page path must be relative: ${page.path}`, {
313
- cause: err,
314
- })
315
- }
316
-
317
- if (url.origin !== 'http://localhost') {
318
- throw new Error(`prerender page path must be relative: ${page.path}`)
319
- }
320
-
321
- const decodedPathname = decodeURIComponent(url.pathname)
322
-
323
- return {
324
- ...page,
325
- path: decodedPathname + url.search + url.hash,
326
- }
327
- })
328
- }
@@ -0,0 +1,24 @@
1
+ import type { EnvironmentModuleNode } from 'vite'
2
+
3
+ export function mergeHotUpdateModules(
4
+ currentModules: Array<EnvironmentModuleNode>,
5
+ additionalModules: Array<EnvironmentModuleNode>,
6
+ ): Array<EnvironmentModuleNode> | undefined {
7
+ if (additionalModules.length === 0) {
8
+ return undefined
9
+ }
10
+
11
+ const mergedModules = currentModules.slice()
12
+ const seenModules = new Set(currentModules)
13
+
14
+ for (const mod of additionalModules) {
15
+ if (seenModules.has(mod)) {
16
+ continue
17
+ }
18
+
19
+ seenModules.add(mod)
20
+ mergedModules.push(mod)
21
+ }
22
+
23
+ return mergedModules
24
+ }
@@ -3,16 +3,21 @@ import type { DevServerFnModuleSpecifierEncoder } from '../../start-compiler/typ
3
3
  export function createViteDevServerFnModuleSpecifierEncoder(
4
4
  root: string,
5
5
  ): DevServerFnModuleSpecifierEncoder {
6
- const rootWithTrailingSlash = root.endsWith('/') ? root : `${root}/`
6
+ const normalizedRoot = root.replace(/\\/g, '/')
7
+ const rootWithTrailingSlash = normalizedRoot.endsWith('/')
8
+ ? normalizedRoot
9
+ : `${normalizedRoot}/`
7
10
 
8
11
  return ({ extractedFilename }) => {
9
- let file = extractedFilename
12
+ const normalizedFile = extractedFilename.replace(/\\/g, '/')
10
13
 
11
- if (file.startsWith(rootWithTrailingSlash)) {
12
- file = file.slice(rootWithTrailingSlash.length)
14
+ if (normalizedFile.startsWith(rootWithTrailingSlash)) {
15
+ return `/${normalizedFile.slice(rootWithTrailingSlash.length)}`
13
16
  }
14
17
 
15
- return `/@id/${file}`
18
+ return normalizedFile.startsWith('/')
19
+ ? `/@fs${normalizedFile}`
20
+ : `/@fs/${normalizedFile}`
16
21
  }
17
22
  }
18
23
 
@@ -23,6 +28,11 @@ export function decodeViteDevServerModuleSpecifier(
23
28
 
24
29
  if (sourceFile.startsWith('/@id/')) {
25
30
  sourceFile = sourceFile.slice('/@id/'.length)
31
+ } else if (sourceFile.startsWith('/@fs/')) {
32
+ sourceFile = sourceFile.slice('/@fs'.length)
33
+ sourceFile = sourceFile.replace(/^\/([A-Za-z]:\/)/, '$1')
34
+ } else if (sourceFile.startsWith('/')) {
35
+ sourceFile = sourceFile.slice(1)
26
36
  }
27
37
 
28
38
  const queryIndex = sourceFile.indexOf('?')
@@ -1,4 +1,3 @@
1
- import assert from 'node:assert'
2
1
  import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
3
2
  import { resolve as resolvePath } from 'pathe'
4
3
  import {
@@ -12,7 +11,6 @@ import {
12
11
  createStartCompiler,
13
12
  mergeServerFnsById,
14
13
  } from '../../start-compiler/host'
15
- import { loadModuleForViteCompiler } from '../../start-compiler/load-module'
16
14
  import { generateServerFnResolverModule } from '../../start-compiler/server-fn-resolver-module'
17
15
  import { cleanId } from '../../start-compiler/utils'
18
16
  import { createVirtualModule } from '../createVirtualModule'
@@ -21,17 +19,116 @@ import {
21
19
  createViteDevServerFnModuleSpecifierEncoder,
22
20
  decodeViteDevServerModuleSpecifier,
23
21
  } from './module-specifier'
22
+ import { mergeHotUpdateModules } from './hot-update'
24
23
  import type { CompileStartFrameworkOptions } from '../../types'
25
24
  import type {
26
25
  GenerateFunctionIdFnOptional,
27
26
  ServerFn,
28
27
  } from '../../start-compiler/types'
29
- import type { PluginOption } from 'vite'
28
+ import type { EnvironmentModuleNode, PluginOption } from 'vite'
30
29
 
31
30
  // Re-export from shared constants for backwards compatibility
32
31
  export { SERVER_FN_LOOKUP }
33
32
 
34
33
  const validateServerFnIdVirtualModule = `virtual:tanstack-start-validate-server-fn-id`
34
+ const TSS_SERVERFN_SPLIT_PARAM = 'tss-serverfn-split'
35
+
36
+ type ModuleInvalidationEnvironment = {
37
+ moduleGraph: {
38
+ getModulesByFile: (file: string) => Set<EnvironmentModuleNode> | undefined
39
+ invalidateModule: (
40
+ mod: EnvironmentModuleNode,
41
+ seen?: Set<EnvironmentModuleNode>,
42
+ ) => void
43
+ }
44
+ }
45
+
46
+ function invalidateMatchingFileModules(
47
+ environment: ModuleInvalidationEnvironment,
48
+ ids: Iterable<string>,
49
+ shouldInvalidate: (mod: EnvironmentModuleNode) => boolean,
50
+ ) {
51
+ const seen = new Set<EnvironmentModuleNode>()
52
+ const invalidatedModules: Array<EnvironmentModuleNode> = []
53
+
54
+ for (const id of ids) {
55
+ const fileModules = environment.moduleGraph.getModulesByFile(cleanId(id))
56
+
57
+ if (!fileModules) {
58
+ continue
59
+ }
60
+
61
+ for (const fileModule of fileModules) {
62
+ if (!shouldInvalidate(fileModule)) {
63
+ continue
64
+ }
65
+
66
+ environment.moduleGraph.invalidateModule(fileModule, seen)
67
+ invalidatedModules.push(fileModule)
68
+ }
69
+ }
70
+
71
+ return invalidatedModules
72
+ }
73
+
74
+ function invalidateServerFnProviderModules(
75
+ environment: {
76
+ moduleGraph: {
77
+ getModulesByFile: (file: string) => Set<EnvironmentModuleNode> | undefined
78
+ invalidateModule: (
79
+ mod: EnvironmentModuleNode,
80
+ seen?: Set<EnvironmentModuleNode>,
81
+ ) => void
82
+ }
83
+ },
84
+ ids: Iterable<string>,
85
+ ) {
86
+ return invalidateMatchingFileModules(
87
+ environment,
88
+ ids,
89
+ (fileModule) => fileModule.id?.includes(TSS_SERVERFN_SPLIT_PARAM) ?? false,
90
+ )
91
+ }
92
+
93
+ function invalidateServerFnLookupModules(
94
+ environment: ModuleInvalidationEnvironment,
95
+ ids: Iterable<string>,
96
+ ) {
97
+ invalidateMatchingFileModules(
98
+ environment,
99
+ ids,
100
+ (fileModule) => fileModule.id?.includes(SERVER_FN_LOOKUP) ?? false,
101
+ )
102
+ }
103
+
104
+ function getServerFnProviderIds(ids: Iterable<string>) {
105
+ const providerIds = new Set<string>()
106
+
107
+ for (const id of ids) {
108
+ const cleanedId = cleanId(id)
109
+ providerIds.add(`${cleanedId}?${TSS_SERVERFN_SPLIT_PARAM}`)
110
+ }
111
+
112
+ return providerIds
113
+ }
114
+
115
+ function invalidateModuleNodes(
116
+ environment: {
117
+ moduleGraph: {
118
+ invalidateModule: (
119
+ mod: EnvironmentModuleNode,
120
+ seen?: Set<EnvironmentModuleNode>,
121
+ ) => void
122
+ }
123
+ },
124
+ modules: Iterable<EnvironmentModuleNode>,
125
+ ) {
126
+ const seen = new Set<EnvironmentModuleNode>()
127
+
128
+ for (const mod of modules) {
129
+ environment.moduleGraph.invalidateModule(mod, seen)
130
+ }
131
+ }
35
132
 
36
133
  function getDevServerFnValidatorModule(): string {
37
134
  return `
@@ -148,16 +245,23 @@ export function startCompilerPlugin(
148
245
  ? createViteDevServerFnModuleSpecifierEncoder(root)
149
246
  : undefined,
150
247
  loadModule: async (id: string) => {
151
- await loadModuleForViteCompiler({
152
- compiler: compiler!,
153
- mode: this.environment.mode,
154
- fetchModule:
155
- this.environment.mode === 'dev'
156
- ? this.environment.fetchModule.bind(this.environment)
157
- : undefined,
158
- loadModule: this.load.bind(this),
159
- id,
160
- })
248
+ if (mode === 'build') {
249
+ const loaded = await this.load({ id })
250
+ const code = loaded.code ?? ''
251
+
252
+ compiler!.ingestModule({ code, id })
253
+ return
254
+ }
255
+
256
+ if (this.environment.mode !== 'dev') {
257
+ this.error(
258
+ `could not load module ${id}: unknown environment mode ${this.environment.mode}`,
259
+ )
260
+ }
261
+
262
+ await this.environment.transformRequest(
263
+ `${id}?${SERVER_FN_LOOKUP}`,
264
+ )
161
265
  },
162
266
 
163
267
  resolveId: async (source: string, importer?: string) => {
@@ -190,19 +294,85 @@ export function startCompilerPlugin(
190
294
 
191
295
  hotUpdate(ctx) {
192
296
  const compiler = compilers.get(this.environment.name)
297
+ const idsToInvalidate = new Set<string>()
298
+ const transitiveCompilerImportersToInvalidate = new Set<string>()
299
+ const importerModulesToInvalidate = new Set<EnvironmentModuleNode>()
193
300
 
194
301
  ctx.modules.forEach((m) => {
195
302
  if (m.id) {
303
+ idsToInvalidate.add(m.id)
196
304
  const deleted = compiler?.invalidateModule(m.id)
305
+
306
+ if (deleted) {
307
+ transitiveCompilerImportersToInvalidate.add(cleanId(m.id))
308
+ }
309
+
197
310
  if (deleted) {
198
311
  m.importers.forEach((importer) => {
199
312
  if (importer.id) {
200
- compiler?.invalidateModule(importer.id)
313
+ idsToInvalidate.add(importer.id)
314
+ importerModulesToInvalidate.add(importer)
315
+ transitiveCompilerImportersToInvalidate.add(
316
+ cleanId(importer.id),
317
+ )
201
318
  }
202
319
  })
203
320
  }
204
321
  }
205
322
  })
323
+
324
+ const finishHotUpdate = async () => {
325
+ if (environment.type === 'server' && compiler) {
326
+ const pendingImporters = [
327
+ ...transitiveCompilerImportersToInvalidate,
328
+ ]
329
+ const seenImporters = new Set(pendingImporters)
330
+
331
+ while (pendingImporters.length > 0) {
332
+ const importerId = pendingImporters.pop()!
333
+ const nestedImporters =
334
+ await compiler.getTransitiveImporters(importerId)
335
+
336
+ for (const nestedImporterId of nestedImporters) {
337
+ if (seenImporters.has(nestedImporterId)) {
338
+ continue
339
+ }
340
+
341
+ seenImporters.add(nestedImporterId)
342
+ pendingImporters.push(nestedImporterId)
343
+ }
344
+ }
345
+
346
+ for (const importerId of seenImporters) {
347
+ idsToInvalidate.add(importerId)
348
+ compiler.invalidateModule(importerId)
349
+ }
350
+ }
351
+
352
+ invalidateModuleNodes(this.environment, importerModulesToInvalidate)
353
+ invalidateServerFnLookupModules(this.environment, idsToInvalidate)
354
+
355
+ if (environment.type !== 'server') {
356
+ return
357
+ }
358
+
359
+ invalidateModuleNodes(this.environment, ctx.modules)
360
+
361
+ const providerIdsToInvalidate =
362
+ getServerFnProviderIds(idsToInvalidate)
363
+ for (const providerId of providerIdsToInvalidate) {
364
+ compiler?.invalidateModule(providerId)
365
+ }
366
+
367
+ const providerModules = invalidateServerFnProviderModules(
368
+ this.environment,
369
+ [...idsToInvalidate, ...providerIdsToInvalidate],
370
+ )
371
+
372
+ return mergeHotUpdateModules(ctx.modules, providerModules)
373
+ }
374
+
375
+ return finishHotUpdate()
206
376
  },
207
377
  }
208
378
  }
@@ -267,10 +437,15 @@ export function startCompilerPlugin(
267
437
  // Trigger transform of the source file in this environment,
268
438
  // which will compile createServerFn calls and populate
269
439
  // serverFnsById as a side effect.
270
- // This plugin only runs in dev (apply: 'serve'), so mode
271
- // must be 'dev' — assert to narrow to DevEnvironment.
272
- assert(this.environment.mode === 'dev')
273
- await this.environment.fetchModule(absPath)
440
+ if (this.environment.mode !== 'dev') {
441
+ this.error(
442
+ `could not validate server function ID ${fnId}: unknown environment mode ${this.environment.mode}`,
443
+ )
444
+ }
445
+
446
+ await this.environment.transformRequest(
447
+ `${absPath}?${SERVER_FN_LOOKUP}`,
448
+ )
274
449
 
275
450
  // Re-check after lazy compilation
276
451
  if (serverFnsById[fnId]) {
@@ -1 +0,0 @@
1
- {"version":3,"file":"ast.js","names":[],"sources":["../../../src/import-protection-plugin/ast.ts"],"sourcesContent":["import { parseAst } from '@tanstack/router-utils'\n\nexport type ParsedAst = ReturnType<typeof parseAst>\n\nexport function parseImportProtectionAst(code: string): ParsedAst {\n return parseAst({ code })\n}\n"],"mappings":";;AAIA,SAAgB,yBAAyB,MAAyB;AAChE,QAAO,SAAS,EAAE,MAAM,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const SERVER_FN_LOOKUP_QUERY = "?server-fn-module-lookup";
2
- export declare const IMPORT_PROTECTION_DEBUG: boolean;
3
- export declare const IMPORT_PROTECTION_DEBUG_FILTER: string | undefined;
4
- export declare const KNOWN_SOURCE_EXTENSIONS: Set<string>;
5
- /** Vite's browser-visible prefix for virtual modules (replaces `\0`). */
6
- export declare const VITE_BROWSER_VIRTUAL_PREFIX = "/@id/__x00__";
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../../../src/import-protection-plugin/constants.ts"],"sourcesContent":["import { SERVER_FN_LOOKUP } from '../constants'\n\nexport const SERVER_FN_LOOKUP_QUERY = `?${SERVER_FN_LOOKUP}`\n\nexport const IMPORT_PROTECTION_DEBUG =\n process.env.TSR_IMPORT_PROTECTION_DEBUG === '1' ||\n process.env.TSR_IMPORT_PROTECTION_DEBUG === 'true'\n\nexport const IMPORT_PROTECTION_DEBUG_FILTER =\n process.env.TSR_IMPORT_PROTECTION_DEBUG_FILTER\n\nexport const KNOWN_SOURCE_EXTENSIONS = new Set([\n '.ts',\n '.tsx',\n '.mts',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n '.json',\n])\n\n/** Vite's browser-visible prefix for virtual modules (replaces `\\0`). */\nexport const VITE_BROWSER_VIRTUAL_PREFIX = '/@id/__x00__'\n"],"mappings":";;AAEA,IAAa,yBAAyB,IAAI;AAE1C,IAAa,0BACX,QAAQ,IAAI,gCAAgC,OAC5C,QAAQ,IAAI,gCAAgC;AAE9C,IAAa,iCACX,QAAQ,IAAI;AAEd,IAAa,0BAA0B,IAAI,IAAI;CAC7C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;AAGF,IAAa,8BAA8B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaults.js","names":[],"sources":["../../../src/import-protection-plugin/defaults.ts"],"sourcesContent":["import type { ImportProtectionEnvRules } from '../schema'\nimport type { Pattern } from './utils'\n\nexport interface DefaultImportProtectionRules {\n client: Required<ImportProtectionEnvRules>\n server: Required<ImportProtectionEnvRules>\n}\n\nconst frameworks = ['react', 'solid', 'vue'] as const\n\n/**\n * Returns the default import protection rules.\n *\n * All three framework variants are always included so that, e.g., a React\n * project also denies `@tanstack/solid-start/server` imports.\n */\nexport function getDefaultImportProtectionRules(): DefaultImportProtectionRules {\n const clientSpecifiers: Array<Pattern> = frameworks.map(\n (fw) => `@tanstack/${fw}-start/server`,\n )\n\n return {\n client: {\n specifiers: clientSpecifiers,\n files: ['**/*.server.*'],\n excludeFiles: ['**/node_modules/**'],\n },\n server: {\n specifiers: [],\n files: ['**/*.client.*'],\n excludeFiles: ['**/node_modules/**'],\n },\n }\n}\n\n/**\n * Marker module specifiers that restrict a file to a specific environment.\n */\nexport function getMarkerSpecifiers(): {\n serverOnly: Array<string>\n clientOnly: Array<string>\n} {\n return {\n serverOnly: frameworks.map((fw) => `@tanstack/${fw}-start/server-only`),\n clientOnly: frameworks.map((fw) => `@tanstack/${fw}-start/client-only`),\n }\n}\n"],"mappings":";AAQA,IAAM,aAAa;CAAC;CAAS;CAAS;CAAM;;;;;;;AAQ5C,SAAgB,kCAAgE;AAK9E,QAAO;EACL,QAAQ;GACN,YANqC,WAAW,KACjD,OAAO,aAAa,GAAG,eACzB;GAKG,OAAO,CAAC,gBAAgB;GACxB,cAAc,CAAC,qBAAqB;GACrC;EACD,QAAQ;GACN,YAAY,EAAE;GACd,OAAO,CAAC,gBAAgB;GACxB,cAAc,CAAC,qBAAqB;GACrC;EACF;;;;;AAMH,SAAgB,sBAGd;AACA,QAAO;EACL,YAAY,WAAW,KAAK,OAAO,aAAa,GAAG,oBAAoB;EACvE,YAAY,WAAW,KAAK,OAAO,aAAa,GAAG,oBAAoB;EACxE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"extensionlessAbsoluteIdResolver.js","names":[],"sources":["../../../src/import-protection-plugin/extensionlessAbsoluteIdResolver.ts"],"sourcesContent":["import { basename, dirname, extname, isAbsolute } from 'node:path'\nimport { resolveModulePath } from 'exsolve'\n\nimport { KNOWN_SOURCE_EXTENSIONS } from './constants'\nimport { normalizeFilePath } from './utils'\n\nconst FILE_RESOLUTION_EXTENSIONS = [...KNOWN_SOURCE_EXTENSIONS]\n\ntype DepKey = `file:${string}` | `dir:${string}`\n\n/**\n * Canonicalize extensionless absolute IDs like `/src/foo.server` to the\n * physical file when possible.\n *\n * Keeps a small cache plus a reverse index so we can invalidate on HMR\n * updates without clearing the whole map.\n */\nexport class ExtensionlessAbsoluteIdResolver {\n private entries = new Map<string, { value: string; deps: Set<DepKey> }>()\n private keysByDep = new Map<DepKey, Set<string>>()\n\n clear(): void {\n this.entries.clear()\n this.keysByDep.clear()\n }\n\n /**\n * Invalidate any cached entries that might be affected by changes to `id`.\n * We invalidate both the file and its containing directory.\n */\n invalidateByFile(id: string): void {\n const file = normalizeFilePath(id)\n this.invalidateDep(`file:${file}`)\n if (isAbsolute(file)) {\n this.invalidateDep(`dir:${dirname(file)}`)\n }\n }\n\n resolve(id: string): string {\n const key = normalizeFilePath(id)\n const cached = this.entries.get(key)\n if (cached) return cached.value\n\n let result = key\n let resolvedPhysical: string | undefined\n\n if (isAbsolute(key)) {\n const ext = extname(key)\n if (!FILE_RESOLUTION_EXTENSIONS.includes(ext)) {\n const resolved = resolveModulePath(`./${basename(key)}`, {\n from: dirname(key),\n extensions: FILE_RESOLUTION_EXTENSIONS,\n try: true,\n })\n if (resolved) {\n resolvedPhysical = resolved\n result = normalizeFilePath(resolved)\n }\n }\n }\n\n const resolvedFile = resolvedPhysical\n ? normalizeFilePath(resolvedPhysical)\n : undefined\n\n const deps = this.buildDepsForKey(key, resolvedFile)\n this.entries.set(key, { value: result, deps })\n this.indexDeps(key, deps)\n return result\n }\n\n private invalidateDep(dep: DepKey): void {\n const keys = this.keysByDep.get(dep)\n if (!keys) return\n\n // Copy because deleting keys mutates indexes.\n for (const key of Array.from(keys)) {\n this.deleteKey(key)\n }\n }\n\n private buildDepsForKey(key: string, resolvedFile: string | undefined) {\n const deps = new Set<DepKey>()\n deps.add(`file:${key}`)\n\n if (isAbsolute(key)) {\n deps.add(`dir:${dirname(key)}`)\n }\n if (resolvedFile) {\n deps.add(`file:${resolvedFile}`)\n }\n\n return deps\n }\n\n private indexDeps(key: string, deps: Set<DepKey>): void {\n for (const dep of deps) {\n let keys = this.keysByDep.get(dep)\n if (!keys) {\n keys = new Set<string>()\n this.keysByDep.set(dep, keys)\n }\n keys.add(key)\n }\n }\n\n private deleteKey(key: string): void {\n const entry = this.entries.get(key)\n this.entries.delete(key)\n if (!entry) return\n\n for (const dep of entry.deps) {\n const keys = this.keysByDep.get(dep)\n if (!keys) continue\n keys.delete(key)\n if (keys.size === 0) {\n this.keysByDep.delete(dep)\n }\n }\n }\n}\n"],"mappings":";;;;;AAMA,IAAM,6BAA6B,CAAC,GAAG,wBAAwB;;;;;;;;AAW/D,IAAa,kCAAb,MAA6C;CAC3C,0BAAkB,IAAI,KAAmD;CACzE,4BAAoB,IAAI,KAA0B;CAElD,QAAc;AACZ,OAAK,QAAQ,OAAO;AACpB,OAAK,UAAU,OAAO;;;;;;CAOxB,iBAAiB,IAAkB;EACjC,MAAM,OAAO,kBAAkB,GAAG;AAClC,OAAK,cAAc,QAAQ,OAAO;AAClC,MAAI,WAAW,KAAK,CAClB,MAAK,cAAc,OAAO,QAAQ,KAAK,GAAG;;CAI9C,QAAQ,IAAoB;EAC1B,MAAM,MAAM,kBAAkB,GAAG;EACjC,MAAM,SAAS,KAAK,QAAQ,IAAI,IAAI;AACpC,MAAI,OAAQ,QAAO,OAAO;EAE1B,IAAI,SAAS;EACb,IAAI;AAEJ,MAAI,WAAW,IAAI,EAAE;GACnB,MAAM,MAAM,QAAQ,IAAI;AACxB,OAAI,CAAC,2BAA2B,SAAS,IAAI,EAAE;IAC7C,MAAM,WAAW,kBAAkB,KAAK,SAAS,IAAI,IAAI;KACvD,MAAM,QAAQ,IAAI;KAClB,YAAY;KACZ,KAAK;KACN,CAAC;AACF,QAAI,UAAU;AACZ,wBAAmB;AACnB,cAAS,kBAAkB,SAAS;;;;EAK1C,MAAM,eAAe,mBACjB,kBAAkB,iBAAiB,GACnC,KAAA;EAEJ,MAAM,OAAO,KAAK,gBAAgB,KAAK,aAAa;AACpD,OAAK,QAAQ,IAAI,KAAK;GAAE,OAAO;GAAQ;GAAM,CAAC;AAC9C,OAAK,UAAU,KAAK,KAAK;AACzB,SAAO;;CAGT,cAAsB,KAAmB;EACvC,MAAM,OAAO,KAAK,UAAU,IAAI,IAAI;AACpC,MAAI,CAAC,KAAM;AAGX,OAAK,MAAM,OAAO,MAAM,KAAK,KAAK,CAChC,MAAK,UAAU,IAAI;;CAIvB,gBAAwB,KAAa,cAAkC;EACrE,MAAM,uBAAO,IAAI,KAAa;AAC9B,OAAK,IAAI,QAAQ,MAAM;AAEvB,MAAI,WAAW,IAAI,CACjB,MAAK,IAAI,OAAO,QAAQ,IAAI,GAAG;AAEjC,MAAI,aACF,MAAK,IAAI,QAAQ,eAAe;AAGlC,SAAO;;CAGT,UAAkB,KAAa,MAAyB;AACtD,OAAK,MAAM,OAAO,MAAM;GACtB,IAAI,OAAO,KAAK,UAAU,IAAI,IAAI;AAClC,OAAI,CAAC,MAAM;AACT,2BAAO,IAAI,KAAa;AACxB,SAAK,UAAU,IAAI,KAAK,KAAK;;AAE/B,QAAK,IAAI,IAAI;;;CAIjB,UAAkB,KAAmB;EACnC,MAAM,QAAQ,KAAK,QAAQ,IAAI,IAAI;AACnC,OAAK,QAAQ,OAAO,IAAI;AACxB,MAAI,CAAC,MAAO;AAEZ,OAAK,MAAM,OAAO,MAAM,MAAM;GAC5B,MAAM,OAAO,KAAK,UAAU,IAAI,IAAI;AACpC,OAAI,CAAC,KAAM;AACX,QAAK,OAAO,IAAI;AAChB,OAAI,KAAK,SAAS,EAChB,MAAK,UAAU,OAAO,IAAI"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"matchers.js","names":[],"sources":["../../../src/import-protection-plugin/matchers.ts"],"sourcesContent":["import picomatch from 'picomatch'\n\nimport type { Pattern } from './utils'\n\nexport interface CompiledMatcher {\n pattern: Pattern\n test: (value: string) => boolean\n}\n\n/**\n * Compile a Pattern (string glob or RegExp) into a fast test function.\n * String patterns use picomatch for full glob support (**, *, ?, braces, etc.).\n * RegExp patterns are used as-is.\n */\nexport function compileMatcher(pattern: Pattern): CompiledMatcher {\n if (pattern instanceof RegExp) {\n // RegExp with `g` or `y` flags are stateful because `.test()` mutates\n // `lastIndex`. Reset it to keep matcher evaluation deterministic.\n return {\n pattern,\n test: (value: string) => {\n pattern.lastIndex = 0\n return pattern.test(value)\n },\n }\n }\n\n const isMatch = picomatch(pattern, { dot: true })\n return { pattern, test: isMatch }\n}\n\nexport function compileMatchers(\n patterns: Array<Pattern>,\n): Array<CompiledMatcher> {\n return patterns.map(compileMatcher)\n}\n\nexport function matchesAny(\n value: string,\n matchers: Array<CompiledMatcher>,\n): CompiledMatcher | undefined {\n for (const matcher of matchers) {\n if (matcher.test(value)) {\n return matcher\n }\n }\n return undefined\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,eAAe,SAAmC;AAChE,KAAI,mBAAmB,OAGrB,QAAO;EACL;EACA,OAAO,UAAkB;AACvB,WAAQ,YAAY;AACpB,UAAO,QAAQ,KAAK,MAAM;;EAE7B;AAIH,QAAO;EAAE;EAAS,MADF,UAAU,SAAS,EAAE,KAAK,MAAM,CAAC;EAChB;;AAGnC,SAAgB,gBACd,UACwB;AACxB,QAAO,SAAS,IAAI,eAAe;;AAGrC,SAAgB,WACd,OACA,UAC6B;AAC7B,MAAK,MAAM,WAAW,SACpB,KAAI,QAAQ,KAAK,MAAM,CACrB,QAAO"}