@tanstack/start-plugin-core 1.166.12 → 1.166.14

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 (87) hide show
  1. package/dist/esm/build-sitemap.js +94 -123
  2. package/dist/esm/build-sitemap.js.map +1 -1
  3. package/dist/esm/constants.js +15 -20
  4. package/dist/esm/constants.js.map +1 -1
  5. package/dist/esm/dev-server-plugin/dev-styles.js +137 -150
  6. package/dist/esm/dev-server-plugin/dev-styles.js.map +1 -1
  7. package/dist/esm/dev-server-plugin/extract-html-scripts.js +16 -15
  8. package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
  9. package/dist/esm/dev-server-plugin/plugin.js +125 -195
  10. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  11. package/dist/esm/import-protection-plugin/ast.js +6 -5
  12. package/dist/esm/import-protection-plugin/ast.js.map +1 -1
  13. package/dist/esm/import-protection-plugin/constants.js +20 -22
  14. package/dist/esm/import-protection-plugin/constants.js.map +1 -1
  15. package/dist/esm/import-protection-plugin/defaults.js +35 -25
  16. package/dist/esm/import-protection-plugin/defaults.js.map +1 -1
  17. package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js +93 -92
  18. package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js.map +1 -1
  19. package/dist/esm/import-protection-plugin/matchers.js +23 -24
  20. package/dist/esm/import-protection-plugin/matchers.js.map +1 -1
  21. package/dist/esm/import-protection-plugin/plugin.js +1045 -1361
  22. package/dist/esm/import-protection-plugin/plugin.js.map +1 -1
  23. package/dist/esm/import-protection-plugin/postCompileUsage.js +58 -55
  24. package/dist/esm/import-protection-plugin/postCompileUsage.js.map +1 -1
  25. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js +187 -259
  26. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js.map +1 -1
  27. package/dist/esm/import-protection-plugin/sourceLocation.js +238 -248
  28. package/dist/esm/import-protection-plugin/sourceLocation.js.map +1 -1
  29. package/dist/esm/import-protection-plugin/trace.js +173 -184
  30. package/dist/esm/import-protection-plugin/trace.js.map +1 -1
  31. package/dist/esm/import-protection-plugin/utils.js +132 -111
  32. package/dist/esm/import-protection-plugin/utils.js.map +1 -1
  33. package/dist/esm/import-protection-plugin/virtualModules.js +216 -196
  34. package/dist/esm/import-protection-plugin/virtualModules.js.map +1 -1
  35. package/dist/esm/index.js +2 -7
  36. package/dist/esm/load-env-plugin/plugin.js +12 -11
  37. package/dist/esm/load-env-plugin/plugin.js.map +1 -1
  38. package/dist/esm/output-directory.js +10 -10
  39. package/dist/esm/output-directory.js.map +1 -1
  40. package/dist/esm/plugin.js +275 -355
  41. package/dist/esm/plugin.js.map +1 -1
  42. package/dist/esm/post-server-build.js +39 -53
  43. package/dist/esm/post-server-build.js.map +1 -1
  44. package/dist/esm/prerender.js +177 -239
  45. package/dist/esm/prerender.js.map +1 -1
  46. package/dist/esm/preview-server-plugin/plugin.js +41 -44
  47. package/dist/esm/preview-server-plugin/plugin.js.map +1 -1
  48. package/dist/esm/queue.js +115 -126
  49. package/dist/esm/queue.js.map +1 -1
  50. package/dist/esm/resolve-entries.js +31 -32
  51. package/dist/esm/resolve-entries.js.map +1 -1
  52. package/dist/esm/schema.js +156 -179
  53. package/dist/esm/schema.js.map +1 -1
  54. package/dist/esm/start-compiler-plugin/compiler.js +655 -812
  55. package/dist/esm/start-compiler-plugin/compiler.js.map +1 -1
  56. package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js +25 -8
  57. package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js.map +1 -1
  58. package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js +22 -19
  59. package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js.map +1 -1
  60. package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js +20 -22
  61. package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js.map +1 -1
  62. package/dist/esm/start-compiler-plugin/handleCreateServerFn.js +187 -255
  63. package/dist/esm/start-compiler-plugin/handleCreateServerFn.js.map +1 -1
  64. package/dist/esm/start-compiler-plugin/handleEnvOnly.js +23 -33
  65. package/dist/esm/start-compiler-plugin/handleEnvOnly.js.map +1 -1
  66. package/dist/esm/start-compiler-plugin/plugin.js +247 -291
  67. package/dist/esm/start-compiler-plugin/plugin.js.map +1 -1
  68. package/dist/esm/start-compiler-plugin/utils.js +27 -27
  69. package/dist/esm/start-compiler-plugin/utils.js.map +1 -1
  70. package/dist/esm/start-manifest-plugin/manifestBuilder.js +272 -378
  71. package/dist/esm/start-manifest-plugin/manifestBuilder.js.map +1 -1
  72. package/dist/esm/start-manifest-plugin/plugin.js +35 -44
  73. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
  74. package/dist/esm/start-router-plugin/constants.js +6 -5
  75. package/dist/esm/start-router-plugin/constants.js.map +1 -1
  76. package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js +24 -19
  77. package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js.map +1 -1
  78. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +28 -29
  79. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  80. package/dist/esm/start-router-plugin/plugin.js +146 -199
  81. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  82. package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +32 -31
  83. package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -1
  84. package/dist/esm/utils.js +14 -14
  85. package/dist/esm/utils.js.map +1 -1
  86. package/package.json +7 -7
  87. package/dist/esm/index.js.map +0 -1
@@ -1,171 +1,158 @@
1
1
  import path from "node:path";
2
- const CSS_FILE_REGEX = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
3
- const CSS_MODULES_REGEX = /\.module\.(css|less|sass|scss|styl|stylus)(?:$|[?#])/i;
2
+ //#region src/dev-server-plugin/dev-styles.ts
3
+ /**
4
+ * CSS collection for dev mode.
5
+ * Crawls the Vite module graph to collect CSS from the router entry and all its dependencies.
6
+ */
7
+ var CSS_FILE_REGEX = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
8
+ var CSS_MODULES_REGEX = /\.module\.(css|less|sass|scss|styl|stylus)(?:$|[?#])/i;
4
9
  function normalizeCssModuleCacheKey(idOrFile) {
5
- const baseId = idOrFile.split("?")[0].split("#")[0];
6
- return baseId.replace(/\\/g, "/");
10
+ return idOrFile.split("?")[0].split("#")[0].replace(/\\/g, "/");
7
11
  }
8
- const CSS_SIDE_EFFECT_FREE_PARAMS = ["url", "inline", "raw", "inline-css"];
9
- const VITE_CSS_MARKER = "const __vite__css = ";
10
- const ESCAPE_CSS_COMMENT_START_REGEX = /\/\*/g;
11
- const ESCAPE_CSS_COMMENT_END_REGEX = /\*\//g;
12
+ var CSS_SIDE_EFFECT_FREE_PARAMS = [
13
+ "url",
14
+ "inline",
15
+ "raw",
16
+ "inline-css"
17
+ ];
18
+ var VITE_CSS_MARKER = "const __vite__css = ";
19
+ var ESCAPE_CSS_COMMENT_START_REGEX = /\/\*/g;
20
+ var ESCAPE_CSS_COMMENT_END_REGEX = /\*\//g;
12
21
  function isCssFile(file) {
13
- return CSS_FILE_REGEX.test(file);
22
+ return CSS_FILE_REGEX.test(file);
14
23
  }
15
24
  function isCssModulesFile(file) {
16
- return CSS_MODULES_REGEX.test(file);
25
+ return CSS_MODULES_REGEX.test(file);
17
26
  }
18
27
  function hasCssSideEffectFreeParam(url) {
19
- const queryString = url.split("?")[1];
20
- if (!queryString) return false;
21
- const params = new URLSearchParams(queryString);
22
- return CSS_SIDE_EFFECT_FREE_PARAMS.some(
23
- (param) => params.get(param) === "" && !url.includes(`?${param}=`) && !url.includes(`&${param}=`)
24
- );
28
+ const queryString = url.split("?")[1];
29
+ if (!queryString) return false;
30
+ const params = new URLSearchParams(queryString);
31
+ return CSS_SIDE_EFFECT_FREE_PARAMS.some((param) => params.get(param) === "" && !url.includes(`?${param}=`) && !url.includes(`&${param}=`));
25
32
  }
33
+ /**
34
+ * Resolve a file path to a Vite dev server URL.
35
+ * Files within the root directory use relative paths, files outside use /@fs prefix.
36
+ */
26
37
  function resolveDevUrl(rootDirectory, filePath) {
27
- const normalizedPath = filePath.replace(/\\/g, "/");
28
- const relativePath = path.posix.relative(
29
- rootDirectory.replace(/\\/g, "/"),
30
- normalizedPath
31
- );
32
- const isWithinRoot = !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
33
- if (isWithinRoot) {
34
- return path.posix.join("/", relativePath);
35
- }
36
- return path.posix.join("/@fs", normalizedPath);
38
+ const normalizedPath = filePath.replace(/\\/g, "/");
39
+ const relativePath = path.posix.relative(rootDirectory.replace(/\\/g, "/"), normalizedPath);
40
+ if (!relativePath.startsWith("..") && !path.isAbsolute(relativePath)) return path.posix.join("/", relativePath);
41
+ return path.posix.join("/@fs", normalizedPath);
37
42
  }
43
+ /**
44
+ * Collect CSS content from the module graph starting from the given entry points.
45
+ */
38
46
  async function collectDevStyles(opts) {
39
- const { viteDevServer, entries, cssModulesCache = {} } = opts;
40
- const styles = /* @__PURE__ */ new Map();
41
- const visited = /* @__PURE__ */ new Set();
42
- const rootDirectory = viteDevServer.config.root;
43
- await Promise.all(
44
- entries.map(
45
- (entry) => processEntry(viteDevServer, resolveDevUrl(rootDirectory, entry), visited)
46
- )
47
- );
48
- const cssPromises = [];
49
- for (const dep of visited) {
50
- if (hasCssSideEffectFreeParam(dep.url)) {
51
- continue;
52
- }
53
- if (dep.file && isCssModulesFile(dep.file)) {
54
- const css = cssModulesCache[normalizeCssModuleCacheKey(dep.file)];
55
- if (!css) {
56
- continue;
57
- }
58
- styles.set(dep.url, css);
59
- continue;
60
- }
61
- const fileOrUrl = dep.file ?? dep.url;
62
- if (!isCssFile(fileOrUrl)) {
63
- continue;
64
- }
65
- cssPromises.push(
66
- fetchCssFromModule(viteDevServer, dep).then(
67
- (css) => css ? [dep.url, css] : null
68
- )
69
- );
70
- }
71
- const cssResults = await Promise.all(cssPromises);
72
- for (const result of cssResults) {
73
- if (result) {
74
- styles.set(result[0], result[1]);
75
- }
76
- }
77
- if (styles.size === 0) return void 0;
78
- const parts = [];
79
- for (const [fileName, css] of styles.entries()) {
80
- const escapedFileName = fileName.replace(ESCAPE_CSS_COMMENT_START_REGEX, "/\\*").replace(ESCAPE_CSS_COMMENT_END_REGEX, "*\\/");
81
- parts.push(`
82
- /* ${escapedFileName} */
83
- ${css}`);
84
- }
85
- return parts.join("\n");
47
+ const { viteDevServer, entries, cssModulesCache = {} } = opts;
48
+ const styles = /* @__PURE__ */ new Map();
49
+ const visited = /* @__PURE__ */ new Set();
50
+ const rootDirectory = viteDevServer.config.root;
51
+ await Promise.all(entries.map((entry) => processEntry(viteDevServer, resolveDevUrl(rootDirectory, entry), visited)));
52
+ const cssPromises = [];
53
+ for (const dep of visited) {
54
+ if (hasCssSideEffectFreeParam(dep.url)) continue;
55
+ if (dep.file && isCssModulesFile(dep.file)) {
56
+ const css = cssModulesCache[normalizeCssModuleCacheKey(dep.file)];
57
+ if (!css) continue;
58
+ styles.set(dep.url, css);
59
+ continue;
60
+ }
61
+ if (!isCssFile(dep.file ?? dep.url)) continue;
62
+ cssPromises.push(fetchCssFromModule(viteDevServer, dep).then((css) => css ? [dep.url, css] : null));
63
+ }
64
+ const cssResults = await Promise.all(cssPromises);
65
+ for (const result of cssResults) if (result) styles.set(result[0], result[1]);
66
+ if (styles.size === 0) return void 0;
67
+ const parts = [];
68
+ for (const [fileName, css] of styles.entries()) {
69
+ const escapedFileName = fileName.replace(ESCAPE_CSS_COMMENT_START_REGEX, "/\\*").replace(ESCAPE_CSS_COMMENT_END_REGEX, "*\\/");
70
+ parts.push(`\n/* ${escapedFileName} */\n${css}`);
71
+ }
72
+ return parts.join("\n");
86
73
  }
74
+ /**
75
+ * Process an entry URL: transform it if needed, get the module node, and crawl its dependencies.
76
+ */
87
77
  async function processEntry(viteDevServer, entryUrl, visited) {
88
- let node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl);
89
- if (!node?.ssrTransformResult) {
90
- try {
91
- await viteDevServer.transformRequest(entryUrl);
92
- } catch {
93
- }
94
- node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl);
95
- }
96
- if (!node || visited.has(node)) return;
97
- visited.add(node);
98
- await findModuleDeps(viteDevServer, node, visited);
78
+ let node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl);
79
+ if (!node?.ssrTransformResult) {
80
+ try {
81
+ await viteDevServer.transformRequest(entryUrl);
82
+ } catch {}
83
+ node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl);
84
+ }
85
+ if (!node || visited.has(node)) return;
86
+ visited.add(node);
87
+ await findModuleDeps(viteDevServer, node, visited);
99
88
  }
89
+ /**
90
+ * Find all module dependencies by crawling the module graph.
91
+ * Uses transformResult.deps for URL-based lookups (parallel) and
92
+ * importedModules for already-resolved nodes (parallel).
93
+ */
100
94
  async function findModuleDeps(viteDevServer, node, visited) {
101
- const deps = node.ssrTransformResult?.deps ?? node.transformResult?.deps ?? null;
102
- const importedModules = node.importedModules;
103
- if ((!deps || deps.length === 0) && importedModules.size === 0) {
104
- return;
105
- }
106
- const branches = [];
107
- if (deps) {
108
- for (const depUrl of deps) {
109
- const dep = await viteDevServer.moduleGraph.getModuleByUrl(depUrl);
110
- if (!dep) continue;
111
- if (visited.has(dep)) continue;
112
- visited.add(dep);
113
- branches.push(findModuleDeps(viteDevServer, dep, visited));
114
- }
115
- }
116
- for (const depNode of importedModules) {
117
- if (visited.has(depNode)) continue;
118
- visited.add(depNode);
119
- branches.push(findModuleDeps(viteDevServer, depNode, visited));
120
- }
121
- if (branches.length === 1) {
122
- await branches[0];
123
- return;
124
- }
125
- await Promise.all(branches);
95
+ const deps = node.ssrTransformResult?.deps ?? node.transformResult?.deps ?? null;
96
+ const importedModules = node.importedModules;
97
+ if ((!deps || deps.length === 0) && importedModules.size === 0) return;
98
+ const branches = [];
99
+ if (deps) for (const depUrl of deps) {
100
+ const dep = await viteDevServer.moduleGraph.getModuleByUrl(depUrl);
101
+ if (!dep) continue;
102
+ if (visited.has(dep)) continue;
103
+ visited.add(dep);
104
+ branches.push(findModuleDeps(viteDevServer, dep, visited));
105
+ }
106
+ for (const depNode of importedModules) {
107
+ if (visited.has(depNode)) continue;
108
+ visited.add(depNode);
109
+ branches.push(findModuleDeps(viteDevServer, depNode, visited));
110
+ }
111
+ if (branches.length === 1) {
112
+ await branches[0];
113
+ return;
114
+ }
115
+ await Promise.all(branches);
126
116
  }
127
117
  async function fetchCssFromModule(viteDevServer, node) {
128
- const cachedCode = node.transformResult?.code ?? node.ssrTransformResult?.code;
129
- if (cachedCode) {
130
- return extractCssFromCode(cachedCode);
131
- }
132
- try {
133
- const transformResult = await viteDevServer.transformRequest(node.url);
134
- if (!transformResult?.code) return void 0;
135
- return extractCssFromCode(transformResult.code);
136
- } catch {
137
- return void 0;
138
- }
118
+ const cachedCode = node.transformResult?.code ?? node.ssrTransformResult?.code;
119
+ if (cachedCode) return extractCssFromCode(cachedCode);
120
+ try {
121
+ const transformResult = await viteDevServer.transformRequest(node.url);
122
+ if (!transformResult?.code) return void 0;
123
+ return extractCssFromCode(transformResult.code);
124
+ } catch {
125
+ return;
126
+ }
139
127
  }
128
+ /**
129
+ * Extract CSS content from Vite's transformed CSS module code.
130
+ *
131
+ * Vite embeds CSS into the module as a JS string via `JSON.stringify(cssContent)`,
132
+ * e.g. `const __vite__css = ${JSON.stringify('...css...')}`.
133
+ *
134
+ * We locate that JSON string literal and run `JSON.parse` on it to reverse the
135
+ * escaping (\\n, \\t, \\", \\\\, \\uXXXX, etc.).
136
+ */
140
137
  function extractCssFromCode(code) {
141
- const startIdx = code.indexOf(VITE_CSS_MARKER);
142
- if (startIdx === -1) return void 0;
143
- const valueStart = startIdx + VITE_CSS_MARKER.length;
144
- if (code.charCodeAt(valueStart) !== 34) return void 0;
145
- const codeLength = code.length;
146
- let i = valueStart + 1;
147
- while (i < codeLength) {
148
- const charCode = code.charCodeAt(i);
149
- if (charCode === 34) {
150
- try {
151
- return JSON.parse(code.slice(valueStart, i + 1));
152
- } catch {
153
- return void 0;
154
- }
155
- }
156
- if (charCode === 92) {
157
- i += 2;
158
- } else {
159
- i++;
160
- }
161
- }
162
- return void 0;
138
+ const startIdx = code.indexOf(VITE_CSS_MARKER);
139
+ if (startIdx === -1) return void 0;
140
+ const valueStart = startIdx + 20;
141
+ if (code.charCodeAt(valueStart) !== 34) return void 0;
142
+ const codeLength = code.length;
143
+ let i = valueStart + 1;
144
+ while (i < codeLength) {
145
+ const charCode = code.charCodeAt(i);
146
+ if (charCode === 34) try {
147
+ return JSON.parse(code.slice(valueStart, i + 1));
148
+ } catch {
149
+ return;
150
+ }
151
+ if (charCode === 92) i += 2;
152
+ else i++;
153
+ }
163
154
  }
164
- export {
165
- CSS_MODULES_REGEX,
166
- collectDevStyles,
167
- extractCssFromCode,
168
- isCssModulesFile,
169
- normalizeCssModuleCacheKey
170
- };
171
- //# sourceMappingURL=dev-styles.js.map
155
+ //#endregion
156
+ export { CSS_MODULES_REGEX, collectDevStyles, normalizeCssModuleCacheKey };
157
+
158
+ //# sourceMappingURL=dev-styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dev-styles.js","sources":["../../../src/dev-server-plugin/dev-styles.ts"],"sourcesContent":["/**\n * CSS collection for dev mode.\n * Crawls the Vite module graph to collect CSS from the router entry and all its dependencies.\n */\nimport path from 'node:path'\nimport type { ModuleNode, ViteDevServer } from 'vite'\n\n// CSS file extensions supported by Vite\nconst CSS_FILE_REGEX =\n /\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\\?)/\n// CSS modules file pattern - exported for use in plugin hook filters\n// Note: allow query/hash suffix since Vite ids often include them.\nexport const CSS_MODULES_REGEX =\n /\\.module\\.(css|less|sass|scss|styl|stylus)(?:$|[?#])/i\n\nexport function normalizeCssModuleCacheKey(idOrFile: string): string {\n const baseId = idOrFile.split('?')[0]!.split('#')[0]!\n return baseId.replace(/\\\\/g, '/')\n}\n// URL params that indicate CSS should not be injected (e.g., ?url, ?inline)\nconst CSS_SIDE_EFFECT_FREE_PARAMS = ['url', 'inline', 'raw', 'inline-css']\n\n// Marker to find the CSS string in Vite's transformed output\nconst VITE_CSS_MARKER = 'const __vite__css = '\n\nconst ESCAPE_CSS_COMMENT_START_REGEX = /\\/\\*/g\nconst ESCAPE_CSS_COMMENT_END_REGEX = /\\*\\//g\n\nfunction isCssFile(file: string): boolean {\n return CSS_FILE_REGEX.test(file)\n}\n\nexport function isCssModulesFile(file: string): boolean {\n return CSS_MODULES_REGEX.test(file)\n}\n\nfunction hasCssSideEffectFreeParam(url: string): boolean {\n const queryString = url.split('?')[1]\n if (!queryString) return false\n\n const params = new URLSearchParams(queryString)\n return CSS_SIDE_EFFECT_FREE_PARAMS.some(\n (param) =>\n params.get(param) === '' &&\n !url.includes(`?${param}=`) &&\n !url.includes(`&${param}=`),\n )\n}\n\n/**\n * Resolve a file path to a Vite dev server URL.\n * Files within the root directory use relative paths, files outside use /@fs prefix.\n */\nfunction resolveDevUrl(rootDirectory: string, filePath: string): string {\n const normalizedPath = filePath.replace(/\\\\/g, '/')\n const relativePath = path.posix.relative(\n rootDirectory.replace(/\\\\/g, '/'),\n normalizedPath,\n )\n const isWithinRoot =\n !relativePath.startsWith('..') && !path.isAbsolute(relativePath)\n\n if (isWithinRoot) {\n return path.posix.join('/', relativePath)\n }\n // Files outside root need /@fs prefix\n return path.posix.join('/@fs', normalizedPath)\n}\n\nexport interface CollectDevStylesOptions {\n viteDevServer: ViteDevServer\n entries: Array<string>\n /** Cache of CSS modules content captured during transform hook */\n cssModulesCache?: Record<string, string>\n}\n\n/**\n * Collect CSS content from the module graph starting from the given entry points.\n */\nexport async function collectDevStyles(\n opts: CollectDevStylesOptions,\n): Promise<string | undefined> {\n const { viteDevServer, entries, cssModulesCache = {} } = opts\n const styles: Map<string, string> = new Map()\n const visited = new Set<ModuleNode>()\n\n const rootDirectory = viteDevServer.config.root\n\n // Process entries in parallel - each entry is independent\n await Promise.all(\n entries.map((entry) =>\n processEntry(viteDevServer, resolveDevUrl(rootDirectory, entry), visited),\n ),\n )\n\n // Collect CSS from visited modules in parallel\n const cssPromises: Array<Promise<readonly [string, string] | null>> = []\n\n for (const dep of visited) {\n if (hasCssSideEffectFreeParam(dep.url)) {\n continue\n }\n\n if (dep.file && isCssModulesFile(dep.file)) {\n const css = cssModulesCache[normalizeCssModuleCacheKey(dep.file)]\n if (!css) {\n // skip this module - it may not be a real CSS module or it may not have been transformed yet\n continue\n }\n styles.set(dep.url, css)\n continue\n }\n\n const fileOrUrl = dep.file ?? dep.url\n if (!isCssFile(fileOrUrl)) {\n continue\n }\n\n // Load regular CSS files in parallel\n cssPromises.push(\n fetchCssFromModule(viteDevServer, dep).then((css) =>\n css ? ([dep.url, css] as const) : null,\n ),\n )\n }\n\n // Wait for all CSS loads to complete\n const cssResults = await Promise.all(cssPromises)\n for (const result of cssResults) {\n if (result) {\n styles.set(result[0], result[1])\n }\n }\n\n if (styles.size === 0) return undefined\n\n const parts: Array<string> = []\n for (const [fileName, css] of styles.entries()) {\n const escapedFileName = fileName\n .replace(ESCAPE_CSS_COMMENT_START_REGEX, '/\\\\*')\n .replace(ESCAPE_CSS_COMMENT_END_REGEX, '*\\\\/')\n parts.push(`\\n/* ${escapedFileName} */\\n${css}`)\n }\n return parts.join('\\n')\n}\n\n/**\n * Process an entry URL: transform it if needed, get the module node, and crawl its dependencies.\n */\nasync function processEntry(\n viteDevServer: ViteDevServer,\n entryUrl: string,\n visited: Set<ModuleNode>,\n): Promise<void> {\n let node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl)\n\n // Only transform if not yet SSR-transformed (need ssrTransformResult.deps for crawling)\n if (!node?.ssrTransformResult) {\n try {\n await viteDevServer.transformRequest(entryUrl)\n } catch {\n // ignore - module might not exist yet\n }\n node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl)\n }\n\n if (!node || visited.has(node)) return\n\n visited.add(node)\n await findModuleDeps(viteDevServer, node, visited)\n}\n\n/**\n * Find all module dependencies by crawling the module graph.\n * Uses transformResult.deps for URL-based lookups (parallel) and\n * importedModules for already-resolved nodes (parallel).\n */\nasync function findModuleDeps(\n viteDevServer: ViteDevServer,\n node: ModuleNode,\n visited: Set<ModuleNode>,\n): Promise<void> {\n // Note: caller must add node to visited BEFORE calling this function\n // to prevent race conditions with parallel traversal\n\n // Process deps from transformResult if available (URLs including bare imports)\n const deps =\n node.ssrTransformResult?.deps ?? node.transformResult?.deps ?? null\n\n const importedModules = node.importedModules\n\n // Fast path: no deps and no imports\n if ((!deps || deps.length === 0) && importedModules.size === 0) {\n return\n }\n\n // Build branches only when needed (avoid array allocation on leaf nodes)\n const branches: Array<Promise<void>> = []\n\n if (deps) {\n for (const depUrl of deps) {\n const dep = await viteDevServer.moduleGraph.getModuleByUrl(depUrl)\n if (!dep) continue\n\n if (visited.has(dep)) continue\n visited.add(dep)\n branches.push(findModuleDeps(viteDevServer, dep, visited))\n }\n }\n\n // ALWAYS also traverse importedModules - this catches:\n // - Code-split chunks (e.g. ?tsr-split=component) not in deps\n // - Already-resolved nodes\n for (const depNode of importedModules) {\n if (visited.has(depNode)) continue\n visited.add(depNode)\n branches.push(findModuleDeps(viteDevServer, depNode, visited))\n }\n\n if (branches.length === 1) {\n await branches[0]\n return\n }\n\n await Promise.all(branches)\n}\n\nasync function fetchCssFromModule(\n viteDevServer: ViteDevServer,\n node: ModuleNode,\n): Promise<string | undefined> {\n // Use cached transform result if available\n const cachedCode = node.transformResult?.code ?? node.ssrTransformResult?.code\n if (cachedCode) {\n return extractCssFromCode(cachedCode)\n }\n\n // Otherwise request a fresh transform\n try {\n const transformResult = await viteDevServer.transformRequest(node.url)\n if (!transformResult?.code) return undefined\n\n return extractCssFromCode(transformResult.code)\n } catch {\n // Preprocessor partials (e.g., Sass files with mixins) can't compile in isolation.\n // The root stylesheet that @imports them will contain the compiled CSS.\n return undefined\n }\n}\n\n/**\n * Extract CSS content from Vite's transformed CSS module code.\n *\n * Vite embeds CSS into the module as a JS string via `JSON.stringify(cssContent)`,\n * e.g. `const __vite__css = ${JSON.stringify('...css...')}`.\n *\n * We locate that JSON string literal and run `JSON.parse` on it to reverse the\n * escaping (\\\\n, \\\\t, \\\\\", \\\\\\\\, \\\\uXXXX, etc.).\n */\nexport function extractCssFromCode(code: string): string | undefined {\n const startIdx = code.indexOf(VITE_CSS_MARKER)\n if (startIdx === -1) return undefined\n\n const valueStart = startIdx + VITE_CSS_MARKER.length\n // Vite emits `const __vite__css = ${JSON.stringify(cssContent)}` which always\n // produces double-quoted JSON string literals.\n if (code.charCodeAt(valueStart) !== 34) return undefined\n\n const codeLength = code.length\n let i = valueStart + 1\n while (i < codeLength) {\n const charCode = code.charCodeAt(i)\n // 34 = '\"'\n if (charCode === 34) {\n try {\n return JSON.parse(code.slice(valueStart, i + 1))\n } catch {\n return undefined\n }\n }\n // 92 = '\\\\'\n if (charCode === 92) {\n i += 2\n } else {\n i++\n }\n }\n\n return undefined\n}\n"],"names":[],"mappings":";AAQA,MAAM,iBACJ;AAGK,MAAM,oBACX;AAEK,SAAS,2BAA2B,UAA0B;AACnE,QAAM,SAAS,SAAS,MAAM,GAAG,EAAE,CAAC,EAAG,MAAM,GAAG,EAAE,CAAC;AACnD,SAAO,OAAO,QAAQ,OAAO,GAAG;AAClC;AAEA,MAAM,8BAA8B,CAAC,OAAO,UAAU,OAAO,YAAY;AAGzE,MAAM,kBAAkB;AAExB,MAAM,iCAAiC;AACvC,MAAM,+BAA+B;AAErC,SAAS,UAAU,MAAuB;AACxC,SAAO,eAAe,KAAK,IAAI;AACjC;AAEO,SAAS,iBAAiB,MAAuB;AACtD,SAAO,kBAAkB,KAAK,IAAI;AACpC;AAEA,SAAS,0BAA0B,KAAsB;AACvD,QAAM,cAAc,IAAI,MAAM,GAAG,EAAE,CAAC;AACpC,MAAI,CAAC,YAAa,QAAO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;AAAA,MACjD,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAEA,QAAI,aAAa,IAAI;AACnB,WAAK;AAAA,IACP,OAAO;AACL;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;"}
1
+ {"version":3,"file":"dev-styles.js","names":[],"sources":["../../../src/dev-server-plugin/dev-styles.ts"],"sourcesContent":["/**\n * CSS collection for dev mode.\n * Crawls the Vite module graph to collect CSS from the router entry and all its dependencies.\n */\nimport path from 'node:path'\nimport type { ModuleNode, ViteDevServer } from 'vite'\n\n// CSS file extensions supported by Vite\nconst CSS_FILE_REGEX =\n /\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\\?)/\n// CSS modules file pattern - exported for use in plugin hook filters\n// Note: allow query/hash suffix since Vite ids often include them.\nexport const CSS_MODULES_REGEX =\n /\\.module\\.(css|less|sass|scss|styl|stylus)(?:$|[?#])/i\n\nexport function normalizeCssModuleCacheKey(idOrFile: string): string {\n const baseId = idOrFile.split('?')[0]!.split('#')[0]!\n return baseId.replace(/\\\\/g, '/')\n}\n// URL params that indicate CSS should not be injected (e.g., ?url, ?inline)\nconst CSS_SIDE_EFFECT_FREE_PARAMS = ['url', 'inline', 'raw', 'inline-css']\n\n// Marker to find the CSS string in Vite's transformed output\nconst VITE_CSS_MARKER = 'const __vite__css = '\n\nconst ESCAPE_CSS_COMMENT_START_REGEX = /\\/\\*/g\nconst ESCAPE_CSS_COMMENT_END_REGEX = /\\*\\//g\n\nfunction isCssFile(file: string): boolean {\n return CSS_FILE_REGEX.test(file)\n}\n\nexport function isCssModulesFile(file: string): boolean {\n return CSS_MODULES_REGEX.test(file)\n}\n\nfunction hasCssSideEffectFreeParam(url: string): boolean {\n const queryString = url.split('?')[1]\n if (!queryString) return false\n\n const params = new URLSearchParams(queryString)\n return CSS_SIDE_EFFECT_FREE_PARAMS.some(\n (param) =>\n params.get(param) === '' &&\n !url.includes(`?${param}=`) &&\n !url.includes(`&${param}=`),\n )\n}\n\n/**\n * Resolve a file path to a Vite dev server URL.\n * Files within the root directory use relative paths, files outside use /@fs prefix.\n */\nfunction resolveDevUrl(rootDirectory: string, filePath: string): string {\n const normalizedPath = filePath.replace(/\\\\/g, '/')\n const relativePath = path.posix.relative(\n rootDirectory.replace(/\\\\/g, '/'),\n normalizedPath,\n )\n const isWithinRoot =\n !relativePath.startsWith('..') && !path.isAbsolute(relativePath)\n\n if (isWithinRoot) {\n return path.posix.join('/', relativePath)\n }\n // Files outside root need /@fs prefix\n return path.posix.join('/@fs', normalizedPath)\n}\n\nexport interface CollectDevStylesOptions {\n viteDevServer: ViteDevServer\n entries: Array<string>\n /** Cache of CSS modules content captured during transform hook */\n cssModulesCache?: Record<string, string>\n}\n\n/**\n * Collect CSS content from the module graph starting from the given entry points.\n */\nexport async function collectDevStyles(\n opts: CollectDevStylesOptions,\n): Promise<string | undefined> {\n const { viteDevServer, entries, cssModulesCache = {} } = opts\n const styles: Map<string, string> = new Map()\n const visited = new Set<ModuleNode>()\n\n const rootDirectory = viteDevServer.config.root\n\n // Process entries in parallel - each entry is independent\n await Promise.all(\n entries.map((entry) =>\n processEntry(viteDevServer, resolveDevUrl(rootDirectory, entry), visited),\n ),\n )\n\n // Collect CSS from visited modules in parallel\n const cssPromises: Array<Promise<readonly [string, string] | null>> = []\n\n for (const dep of visited) {\n if (hasCssSideEffectFreeParam(dep.url)) {\n continue\n }\n\n if (dep.file && isCssModulesFile(dep.file)) {\n const css = cssModulesCache[normalizeCssModuleCacheKey(dep.file)]\n if (!css) {\n // skip this module - it may not be a real CSS module or it may not have been transformed yet\n continue\n }\n styles.set(dep.url, css)\n continue\n }\n\n const fileOrUrl = dep.file ?? dep.url\n if (!isCssFile(fileOrUrl)) {\n continue\n }\n\n // Load regular CSS files in parallel\n cssPromises.push(\n fetchCssFromModule(viteDevServer, dep).then((css) =>\n css ? ([dep.url, css] as const) : null,\n ),\n )\n }\n\n // Wait for all CSS loads to complete\n const cssResults = await Promise.all(cssPromises)\n for (const result of cssResults) {\n if (result) {\n styles.set(result[0], result[1])\n }\n }\n\n if (styles.size === 0) return undefined\n\n const parts: Array<string> = []\n for (const [fileName, css] of styles.entries()) {\n const escapedFileName = fileName\n .replace(ESCAPE_CSS_COMMENT_START_REGEX, '/\\\\*')\n .replace(ESCAPE_CSS_COMMENT_END_REGEX, '*\\\\/')\n parts.push(`\\n/* ${escapedFileName} */\\n${css}`)\n }\n return parts.join('\\n')\n}\n\n/**\n * Process an entry URL: transform it if needed, get the module node, and crawl its dependencies.\n */\nasync function processEntry(\n viteDevServer: ViteDevServer,\n entryUrl: string,\n visited: Set<ModuleNode>,\n): Promise<void> {\n let node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl)\n\n // Only transform if not yet SSR-transformed (need ssrTransformResult.deps for crawling)\n if (!node?.ssrTransformResult) {\n try {\n await viteDevServer.transformRequest(entryUrl)\n } catch {\n // ignore - module might not exist yet\n }\n node = await viteDevServer.moduleGraph.getModuleByUrl(entryUrl)\n }\n\n if (!node || visited.has(node)) return\n\n visited.add(node)\n await findModuleDeps(viteDevServer, node, visited)\n}\n\n/**\n * Find all module dependencies by crawling the module graph.\n * Uses transformResult.deps for URL-based lookups (parallel) and\n * importedModules for already-resolved nodes (parallel).\n */\nasync function findModuleDeps(\n viteDevServer: ViteDevServer,\n node: ModuleNode,\n visited: Set<ModuleNode>,\n): Promise<void> {\n // Note: caller must add node to visited BEFORE calling this function\n // to prevent race conditions with parallel traversal\n\n // Process deps from transformResult if available (URLs including bare imports)\n const deps =\n node.ssrTransformResult?.deps ?? node.transformResult?.deps ?? null\n\n const importedModules = node.importedModules\n\n // Fast path: no deps and no imports\n if ((!deps || deps.length === 0) && importedModules.size === 0) {\n return\n }\n\n // Build branches only when needed (avoid array allocation on leaf nodes)\n const branches: Array<Promise<void>> = []\n\n if (deps) {\n for (const depUrl of deps) {\n const dep = await viteDevServer.moduleGraph.getModuleByUrl(depUrl)\n if (!dep) continue\n\n if (visited.has(dep)) continue\n visited.add(dep)\n branches.push(findModuleDeps(viteDevServer, dep, visited))\n }\n }\n\n // ALWAYS also traverse importedModules - this catches:\n // - Code-split chunks (e.g. ?tsr-split=component) not in deps\n // - Already-resolved nodes\n for (const depNode of importedModules) {\n if (visited.has(depNode)) continue\n visited.add(depNode)\n branches.push(findModuleDeps(viteDevServer, depNode, visited))\n }\n\n if (branches.length === 1) {\n await branches[0]\n return\n }\n\n await Promise.all(branches)\n}\n\nasync function fetchCssFromModule(\n viteDevServer: ViteDevServer,\n node: ModuleNode,\n): Promise<string | undefined> {\n // Use cached transform result if available\n const cachedCode = node.transformResult?.code ?? node.ssrTransformResult?.code\n if (cachedCode) {\n return extractCssFromCode(cachedCode)\n }\n\n // Otherwise request a fresh transform\n try {\n const transformResult = await viteDevServer.transformRequest(node.url)\n if (!transformResult?.code) return undefined\n\n return extractCssFromCode(transformResult.code)\n } catch {\n // Preprocessor partials (e.g., Sass files with mixins) can't compile in isolation.\n // The root stylesheet that @imports them will contain the compiled CSS.\n return undefined\n }\n}\n\n/**\n * Extract CSS content from Vite's transformed CSS module code.\n *\n * Vite embeds CSS into the module as a JS string via `JSON.stringify(cssContent)`,\n * e.g. `const __vite__css = ${JSON.stringify('...css...')}`.\n *\n * We locate that JSON string literal and run `JSON.parse` on it to reverse the\n * escaping (\\\\n, \\\\t, \\\\\", \\\\\\\\, \\\\uXXXX, etc.).\n */\nexport function extractCssFromCode(code: string): string | undefined {\n const startIdx = code.indexOf(VITE_CSS_MARKER)\n if (startIdx === -1) return undefined\n\n const valueStart = startIdx + VITE_CSS_MARKER.length\n // Vite emits `const __vite__css = ${JSON.stringify(cssContent)}` which always\n // produces double-quoted JSON string literals.\n if (code.charCodeAt(valueStart) !== 34) return undefined\n\n const codeLength = code.length\n let i = valueStart + 1\n while (i < codeLength) {\n const charCode = code.charCodeAt(i)\n // 34 = '\"'\n if (charCode === 34) {\n try {\n return JSON.parse(code.slice(valueStart, i + 1))\n } catch {\n return undefined\n }\n }\n // 92 = '\\\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I,IAAI,aAAa;AACrB,QAAO,IAAI,YAAY;EACrB,MAAM,WAAW,KAAK,WAAW,EAAE;AAEnC,MAAI,aAAa,GACf,KAAI;AACF,UAAO,KAAK,MAAM,KAAK,MAAM,YAAY,IAAI,EAAE,CAAC;UAC1C;AACN;;AAIJ,MAAI,aAAa,GACf,MAAK;MAEL"}
@@ -1,18 +1,19 @@
1
1
  import * as cheerio from "cheerio";
2
+ //#region src/dev-server-plugin/extract-html-scripts.ts
2
3
  function extractHtmlScripts(html) {
3
- const $ = cheerio.load(html);
4
- const scripts = [];
5
- $("script").each((_, element) => {
6
- const src = $(element).attr("src");
7
- const content = $(element).html() ?? void 0;
8
- scripts.push({
9
- src,
10
- content
11
- });
12
- });
13
- return scripts;
4
+ const $ = cheerio.load(html);
5
+ const scripts = [];
6
+ $("script").each((_, element) => {
7
+ const src = $(element).attr("src");
8
+ const content = $(element).html() ?? void 0;
9
+ scripts.push({
10
+ src,
11
+ content
12
+ });
13
+ });
14
+ return scripts;
14
15
  }
15
- export {
16
- extractHtmlScripts
17
- };
18
- //# sourceMappingURL=extract-html-scripts.js.map
16
+ //#endregion
17
+ export { extractHtmlScripts };
18
+
19
+ //# sourceMappingURL=extract-html-scripts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-html-scripts.js","sources":["../../../src/dev-server-plugin/extract-html-scripts.ts"],"sourcesContent":["import * as cheerio from 'cheerio'\n\nexport function extractHtmlScripts(\n html: string,\n): Array<{ content?: string; src?: string }> {\n const $ = cheerio.load(html)\n const scripts: Array<{ content?: string; src?: string }> = []\n\n $('script').each((_, element) => {\n const src = $(element).attr('src')\n const content = $(element).html() ?? undefined\n scripts.push({\n src,\n content,\n })\n })\n\n return scripts\n}\n"],"names":[],"mappings":";AAEO,SAAS,mBACd,MAC2C;AAC3C,QAAM,IAAI,QAAQ,KAAK,IAAI;AAC3B,QAAM,UAAqD,CAAA;AAE3D,IAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,YAAY;AAC/B,UAAM,MAAM,EAAE,OAAO,EAAE,KAAK,KAAK;AACjC,UAAM,UAAU,EAAE,OAAO,EAAE,UAAU;AACrC,YAAQ,KAAK;AAAA,MACX;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EACH,CAAC;AAED,SAAO;AACT;"}
1
+ {"version":3,"file":"extract-html-scripts.js","names":[],"sources":["../../../src/dev-server-plugin/extract-html-scripts.ts"],"sourcesContent":["import * as cheerio from 'cheerio'\n\nexport function extractHtmlScripts(\n html: string,\n): Array<{ content?: string; src?: string }> {\n const $ = cheerio.load(html)\n const scripts: Array<{ content?: string; src?: string }> = []\n\n $('script').each((_, element) => {\n const src = $(element).attr('src')\n const content = $(element).html() ?? undefined\n scripts.push({\n src,\n content,\n })\n })\n\n return scripts\n}\n"],"mappings":";;AAEA,SAAgB,mBACd,MAC2C;CAC3C,MAAM,IAAI,QAAQ,KAAK,KAAK;CAC5B,MAAM,UAAqD,EAAE;AAE7D,GAAE,SAAS,CAAC,MAAM,GAAG,YAAY;EAC/B,MAAM,MAAM,EAAE,QAAQ,CAAC,KAAK,MAAM;EAClC,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,IAAI,KAAA;AACrC,UAAQ,KAAK;GACX;GACA;GACD,CAAC;GACF;AAEF,QAAO"}