vite-plugin-react-server 1.1.8 → 1.1.10
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.
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/plugin/config/defaults.d.ts +2 -1
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +3 -1
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/resolveDevServerConfig.d.ts +2 -0
- package/dist/plugin/config/resolveDevServerConfig.d.ts.map +1 -0
- package/dist/plugin/config/resolveDevServerConfig.js +1 -0
- package/dist/plugin/config/resolveEnv.d.ts +3 -0
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -0
- package/dist/plugin/config/resolveEnv.js +21 -0
- package/dist/plugin/config/resolveEnv.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +25 -9
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +45 -52
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +10 -2
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.js +18 -35
- package/dist/plugin/helpers/inputNormalizer.d.ts +2 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +34 -9
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/requestInfo.d.ts +16 -0
- package/dist/plugin/helpers/requestInfo.d.ts.map +1 -0
- package/dist/plugin/helpers/requestInfo.js +66 -0
- package/dist/plugin/helpers/requestInfo.js.map +1 -0
- package/dist/plugin/helpers/requestToRoute.js +14 -22
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.development.js +1 -7
- package/dist/plugin/loader/css-loader.development.js.map +1 -1
- package/dist/plugin/loader/css-loader.production.js.map +1 -1
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +1 -8
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/metrics/formatMetrics.d.ts +6 -1
- package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/metrics/formatMetrics.js +21 -3
- package/dist/plugin/metrics/formatMetrics.js.map +1 -1
- package/dist/plugin/metrics.js +1 -1
- package/dist/plugin/plugin.client.js.map +1 -1
- package/dist/plugin/plugin.server.js.map +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/createMessageHandlers.d.ts +10 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -0
- package/dist/plugin/react-client/createMessageHandlers.js +36 -0
- package/dist/plugin/react-client/createMessageHandlers.js.map +1 -0
- package/dist/plugin/react-client/createWorkerStream.d.ts +3 -3
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +60 -69
- package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +1 -3
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +2 -2
- package/dist/plugin/react-client/restartWorker.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts.map +1 -1
- package/dist/plugin/react-client/server.js +29 -40
- package/dist/plugin/react-client/server.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts.map +1 -1
- package/dist/plugin/react-server/server.js +17 -19
- package/dist/plugin/react-server/server.js.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
- package/dist/plugin/react-static/collectRscContent.js.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +58 -54
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
- package/dist/plugin/react-static/fileWriter.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +12 -6
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPages.js.map +1 -1
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.client.js +3 -12
- package/dist/plugin/transformer/plugin.client.js.map +1 -1
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +17 -24
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/types.d.ts +4 -1
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/callServer.d.ts.map +1 -1
- package/dist/plugin/utils/callServer.js +2 -2
- package/dist/plugin/utils/callServer.js.map +1 -1
- package/dist/plugin/utils/createReactFetcher.d.ts +1 -1
- package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
- package/dist/plugin/utils/createReactFetcher.js +6 -8
- package/dist/plugin/utils/createReactFetcher.js.map +1 -1
- package/dist/plugin/utils/env.d.ts +2 -0
- package/dist/plugin/utils/env.d.ts.map +1 -0
- package/dist/plugin/utils/env.js +9 -0
- package/dist/plugin/utils/env.js.map +1 -0
- package/dist/plugin/utils/index.d.ts +1 -0
- package/dist/plugin/utils/index.d.ts.map +1 -1
- package/dist/plugin/utils/index.js +1 -0
- package/dist/plugin/utils/pageURL.d.ts +4 -1
- package/dist/plugin/utils/pageURL.d.ts.map +1 -1
- package/dist/plugin/utils/pageURL.js +23 -11
- package/dist/plugin/utils/pageURL.js.map +1 -1
- package/dist/plugin/utils.js +1 -0
- package/dist/plugin/utils.js.map +1 -1
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +4 -3
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +3 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts +2 -7
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/types.d.ts +6 -0
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/plugin/config/defaults.tsx +2 -1
- package/plugin/config/resolveDevServerConfig.tsx +0 -0
- package/plugin/config/resolveEnv.ts +37 -0
- package/plugin/config/resolveOptions.ts +49 -24
- package/plugin/config/resolveUserConfig.ts +73 -70
- package/plugin/helpers/createCssProps.tsx +14 -6
- package/plugin/helpers/inputNormalizer.ts +66 -17
- package/plugin/helpers/requestInfo.ts +81 -0
- package/plugin/loader/css-loader.development.ts +2 -8
- package/plugin/loader/react-loader.ts +1 -10
- package/plugin/metrics/formatMetrics.ts +29 -4
- package/plugin/preserver/plugin.ts +1 -0
- package/plugin/react-client/createMessageHandlers.ts +37 -0
- package/plugin/react-client/createWorkerStream.ts +76 -83
- package/plugin/react-client/plugin.ts +1 -4
- package/plugin/react-client/restartWorker.ts +2 -2
- package/plugin/react-client/server.ts +36 -62
- package/plugin/react-server/server.ts +17 -30
- package/plugin/react-static/configurePreviewServer.ts +75 -62
- package/plugin/react-static/plugin.ts +17 -11
- package/plugin/transformer/plugin.client.ts +4 -12
- package/plugin/transformer/plugin.server.ts +18 -25
- package/plugin/types.ts +12 -9
- package/plugin/utils/callServer.ts +20 -19
- package/plugin/utils/createReactFetcher.ts +6 -8
- package/plugin/utils/env.ts +1 -0
- package/plugin/utils/index.ts +2 -1
- package/plugin/utils/pageURL.ts +29 -24
- package/plugin/worker/createWorker.ts +4 -9
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +3 -0
- package/plugin/worker/rsc/handleRender.ts +2 -7
- package/plugin/worker/rsc/messageHandler.tsx +4 -7
- package/plugin/worker/rsc/rsc-worker.development.ts +1 -1
- package/plugin/worker/types.ts +7 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +0 -1
- package/dist/plugin/helpers/requestToRoute.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collectManifestCss.js","sources":["../../../plugin/helpers/collectManifestCss.ts"],"sourcesContent":["import type { Manifest } from \"vite\";\nimport type { ResolvedUserOptions } from \"../types.js\";\n\n/**\n * Collects CSS file paths from a manifest by walking through imports starting from a given file\n */\nexport function collectManifestCss(\n manifest: Manifest,\n startFile: string | string[],\n userOptions: Pick<ResolvedUserOptions, \"normalizer\">\n): Record<string, string> {\n const cssInputs: Record<string, string> = {};\n const visited = new Set<string>();\n \n // Convert startFile to array and ensure we have valid file paths\n const toVisit = Array.isArray(startFile) ? startFile : [startFile];\n\n \n while (toVisit.length > 0) {\n const currentFile = toVisit.pop()!;\n if (visited.has(currentFile)) continue;\n visited.add(currentFile);\n \n const fileInfo = manifest[currentFile];\n if (!fileInfo) {\n continue;\n }\n\n // Add CSS files from the css property\n if (fileInfo.css) {\n for (const cssFile of fileInfo.css) {\n const [keyNormalized, valueNormalized] = userOptions.normalizer(cssFile);\n cssInputs[keyNormalized] = valueNormalized;\n }\n }\n\n // Add imports to visit\n if (fileInfo.imports) {\n for (const importPath of fileInfo.imports) {\n // Skip if we've already visited this import\n if (visited.has(importPath)) {\n continue;\n }\n \n // Add the import to visit\n toVisit.push(importPath);\n \n // Check if the imported file has CSS\n const importedFile = manifest[importPath];\n if (importedFile?.css) {\n for (const cssFile of importedFile.css) {\n const [keyNormalized, valueNormalized] = userOptions.normalizer(cssFile);\n cssInputs[keyNormalized] = valueNormalized;\n }\n }\n }\n }\n }\n\n return cssInputs;\n} "],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"collectManifestCss.js","sources":["../../../plugin/helpers/collectManifestCss.ts"],"sourcesContent":["import type { Manifest } from \"vite\";\nimport type { ResolvedUserOptions } from \"../types.js\";\n\n/**\n * Collects CSS file paths from a manifest by walking through imports starting from a given file\n */\nexport function collectManifestCss(\n manifest: Manifest,\n startFile: string | string[],\n userOptions: Pick<ResolvedUserOptions, \"normalizer\">\n): Record<string, string> {\n const cssInputs: Record<string, string> = {};\n const visited = new Set<string>();\n \n // Convert startFile to array and ensure we have valid file paths\n const toVisit = Array.isArray(startFile) ? startFile : [startFile];\n\n \n while (toVisit.length > 0) {\n const currentFile = toVisit.pop()!;\n if (visited.has(currentFile)) continue;\n visited.add(currentFile);\n \n const fileInfo = manifest[currentFile];\n if (!fileInfo) {\n continue;\n }\n\n // Add CSS files from the css property\n if (fileInfo.css) {\n for (const cssFile of fileInfo.css) {\n const [keyNormalized, valueNormalized] = userOptions.normalizer(cssFile);\n cssInputs[keyNormalized] = valueNormalized;\n }\n }\n\n // Add imports to visit\n if (fileInfo.imports) {\n for (const importPath of fileInfo.imports) {\n // Skip if we've already visited this import\n if (visited.has(importPath)) {\n continue;\n }\n \n // Add the import to visit\n toVisit.push(importPath);\n \n // Check if the imported file has CSS\n const importedFile = manifest[importPath];\n if (importedFile?.css) {\n for (const cssFile of importedFile.css) {\n const [keyNormalized, valueNormalized] = userOpt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C,YAAA,MAAM,CAAC,aAAe,EAAA,eAAe,CAAI,GAAA,WAAA,CAAY,WAAW,OAAO,CAAA;AACvE,YAAA,SAAA,CAAU,aAAa,CAAI,GAAA,eAAA;AAAA;AAC7B;AACF;AACF;AACF;AAGF,EAAO,OAAA,SAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCssProps.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/createCssProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAInE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,+BAIxB;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,IAAI,CACf,mBAAmB,EACjB,KAAK,GACL,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,aAAa,CAChB,CAAC;CACH,KAAG,
|
|
1
|
+
{"version":3,"file":"createCssProps.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/createCssProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAInE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,+BAIxB;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,IAAI,CACf,mBAAmB,EACjB,KAAK,GACL,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,aAAa,CAChB,CAAC;CACH,KAAG,UAiEH,CAAC"}
|
|
@@ -41,12 +41,20 @@ const createCssProps = ({
|
|
|
41
41
|
} : {}
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
+
const joined = normalizedId.startsWith(moduleBasePath) ? normalizedId : join(moduleBasePath, normalizedId);
|
|
45
|
+
const moduleBaseHasTrailingSlash = moduleBaseURL.endsWith("/");
|
|
46
|
+
const joinedHasLeadingSlash = joined.startsWith("/");
|
|
44
47
|
const safeParseURL = (() => {
|
|
48
|
+
if (joined.startsWith(moduleBaseHasTrailingSlash ? moduleBaseURL.slice(0, -1) : moduleBaseURL)) {
|
|
49
|
+
return joined;
|
|
50
|
+
}
|
|
45
51
|
try {
|
|
46
|
-
|
|
52
|
+
if (moduleBaseURL.includes("//")) {
|
|
53
|
+
return new URL(joinedHasLeadingSlash ? joined.slice(1) : joined, moduleBaseURL).href;
|
|
54
|
+
}
|
|
47
55
|
} catch (error) {
|
|
48
|
-
return moduleBaseURL + join(moduleBasePath, normalizedId);
|
|
49
56
|
}
|
|
57
|
+
return moduleBaseURL + (!moduleBaseHasTrailingSlash && !joinedHasLeadingSlash ? "/" : "") + (moduleBaseHasTrailingSlash ? joined.slice(1) : joined);
|
|
50
58
|
})();
|
|
51
59
|
return {
|
|
52
60
|
id: normalizedId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCssProps.js","sources":["../../../plugin/helpers/createCssProps.tsx"],"sourcesContent":["import type { ResolvedUserOptions, CssContent } from \"../types.js\";\nimport { join, relative } from \"node:path\";\nimport { deserializeRegExp } from \"./serializeUserOptions.js\";\n\n/**\n * Creates a CssContent object for a given path and css options\n *\n * Requirements:\n * - path is a string\n * - css is an object with the following properties:\n * - inlineCss: boolean\n * - purgeCss: boolean\n * - inlineThreshold: number\n * - inlinePatterns: RegExp[]\n * - linkPatterns: RegExp[]\n * based on the bundle, we retrieve the css content and check if it should be inlined or linked\n * inlined tags get the as:style and the children are the css content\n * linked tags get the as:link and the href is the path\n *\n * @param path - The path to the css file\n * @param css - The css options\n * @returns A CssContent object\n */\nexport const createCssProps = ({\n id,\n code,\n userOptions,\n}: {\n id: string;\n code: string;\n userOptions: Pick<\n ResolvedUserOptions,\n | \"css\"\n | \"moduleBaseURL\"\n | \"moduleBasePath\"\n | \"moduleRootPath\"\n | \"projectRoot\"\n >;\n}): CssContent => {\n const { css, moduleBaseURL, moduleBasePath, moduleRootPath, projectRoot } =\n userOptions;\n // If we don't have a bundle entry, create a linked CSS file\n let inline = typeof code === \"string\" && code.length > css.inlineThreshold;\n // Normalize the ID to be relative to src/\n const normalizedId = id.startsWith(projectRoot)\n ? relative(projectRoot, id)\n : id;\n\n if (css.inlinePatterns?.length) {\n // Deserialize RegExp patterns if they exist\n const inlinePatterns = css.inlinePatterns?.map((pattern) =>\n typeof pattern === \"string\" ? deserializeRegExp(pattern) : pattern\n );\n if (inlinePatterns.some((pattern) => pattern.test?.(normalizedId))) {\n inline = true;\n }\n }\n if (css.linkPatterns?.length) {\n const linkPatterns = css.linkPatterns?.map((pattern) =>\n typeof pattern === \"string\" ? deserializeRegExp(pattern) : pattern\n );\n if (linkPatterns.some((pattern) => pattern.test?.(normalizedId))) {\n inline = false;\n }\n }\n if (inline) {\n return {\n type: \"text/css\",\n id: normalizedId,\n as: \"style\",\n children: code.trim(),\n ...(process.env[\"NODE_ENV\"] !== \"production\"\n ? {\n \"data-vite-dev-id\": join(projectRoot, moduleRootPath, normalizedId),\n }\n : {}),\n } as CssContent<true>;\n }\n const safeParseURL = (() => {\n try {\n return new URL(
|
|
1
|
+
{"version":3,"file":"createCssProps.js","sources":["../../../plugin/helpers/createCssProps.tsx"],"sourcesContent":["import type { ResolvedUserOptions, CssContent } from \"../types.js\";\nimport { join, relative } from \"node:path\";\nimport { deserializeRegExp } from \"./serializeUserOptions.js\";\n\n/**\n * Creates a CssContent object for a given path and css options\n *\n * Requirements:\n * - path is a string\n * - css is an object with the following properties:\n * - inlineCss: boolean\n * - purgeCss: boolean\n * - inlineThreshold: number\n * - inlinePatterns: RegExp[]\n * - linkPatterns: RegExp[]\n * based on the bundle, we retrieve the css content and check if it should be inlined or linked\n * inlined tags get the as:style and the children are the css content\n * linked tags get the as:link and the href is the path\n *\n * @param path - The path to the css file\n * @param css - The css options\n * @returns A CssContent object\n */\nexport const createCssProps = ({\n id,\n code,\n userOptions,\n}: {\n id: string;\n code: string;\n userOptions: Pick<\n ResolvedUserOptions,\n | \"css\"\n | \"moduleBaseURL\"\n | \"moduleBasePath\"\n | \"moduleRootPath\"\n | \"projectRoot\"\n >;\n}): CssContent => {\n const { css, moduleBaseURL, moduleBasePath, moduleRootPath, projectRoot } =\n userOptions;\n // If we don't have a bundle entry, create a linked CSS file\n let inline = typeof code === \"string\" && code.length > css.inlineThreshold;\n // Normalize the ID to be relative to src/\n const normalizedId = id.startsWith(projectRoot)\n ? relative(projectRoot, id)\n : id;\n\n if (css.inlinePatterns?.length) {\n // Deserialize RegExp patterns if they exist\n const inlinePatterns = css.inlinePatterns?.map((pattern) =>\n typeof pattern === \"string\" ? deserializeRegExp(pattern) : pattern\n );\n if (inlinePatterns.some((pattern) => pattern.test?.(normalizedId))) {\n inline = true;\n }\n }\n if (css.linkPatterns?.length) {\n const linkPatterns = css.linkPatterns?.map((pattern) =>\n typeof pattern === \"string\" ? deserializeRegExp(pattern) : pattern\n );\n if (linkPatterns.some((pattern) => pattern.test?.(normalizedId))) {\n inline = false;\n }\n }\n if (inline) {\n return {\n type: \"text/css\",\n id: normalizedId,\n as: \"style\",\n children: code.trim(),\n ...(process.env[\"NODE_ENV\"] !== \"production\"\n ? {\n \"data-vite-dev-id\": join(projectRoot, moduleRootPath, normalizedId),\n }\n : {}),\n } as CssContent<true>;\n }\n const joined = normalizedId.startsWith(moduleBasePath) ? normalizedId : join(moduleBasePath, normalizedId);\n const moduleBaseHasTrailingSlash = moduleBaseURL.endsWith(\"/\");\n const joinedHasLeadingSlash = joined.startsWith(\"/\");\n const safeParseURL = (() => {\n if(joined.startsWith(moduleBaseHasTrailingSlash ? moduleBaseURL.slice(0, -1) : moduleBaseURL)) {\n return joined;\n }\n try {\n if (moduleBaseURL.includes(\"//\")) {\n // relative to moduleBaseURL\n return new URL(joinedHasLeadingSlash ? joined.slice(1) : joined, moduleBaseURL).href;\n }\n } catch (error) {}\n // if the url is not valid, we return the moduleBaseURL + the normalizedId\n // dont make it a argument of join or it will mangle something like http:// into http:/\n return moduleBaseURL + (!moduleBaseHasTrailingSlash && !joinedHasLeadingSlash ? \"/\" : \"\") + (moduleBaseHasTrailingSlash ? joined.slice(1) : joined);\n })();\n // Default case\n return {\n id: normalizedId,\n as: \"link\",\n rel: \"stylesheet\",\n href: safeParseURL,\n precedence: \"high\",\n } as CssContent<false>;\n};\n"],"names":[],"mappings":";;;;;;;;AAuBO,MAAM,iBAAiB,CAAC;AAAA,EAC7B,EAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAWkB,KAAA;AAChB,EAAA,MAAM,EAAE,GAAK,EAAA,aAAA,EAAe,cAAgB,EAAA,cAAA,EAAgB,aAC1D,GAAA,WAAA;AAEF,EAAA,IAAI,SAAS,OAAO,IAAA,KAAS,QAAY,IAAA,IAAA,CAAK,SAAS,GAAI,CAAA,eAAA;AAE3D,EAAM,MAAA,YAAA,GAAe,GAAG,UAAW,CAAA,WAAW,IAC1C,QAAS,CAAA,WAAA,EAAa,EAAE,CACxB,GAAA,EAAA;AAEJ,EAAI,IAAA,GAAA,CAAI,gBAAgB,MAAQ,EAAA;AAE9B,IAAM,MAAA,cAAA,GAAiB,IAAI,cAAgB,EAAA,GAAA;AAAA,MAAI,CAAC,OAC9C,KAAA,OAAO,YAAY,QAAW,GAAA,iBAAA,CAAkB,OAAO,CAAI,GAAA;AAAA,KAC7D;AACA,IAAI,IAAA,cAAA,CAAe,KAAK,CAAC,OAAA,KAAY,QAAQ,IAAO,GAAA,YAAY,CAAC,CAAG,EAAA;AAClE,MAAS,MAAA,GAAA,IAAA;AAAA;AACX;AAEF,EAAI,IAAA,GAAA,CAAI,cAAc,MAAQ,EAAA;AAC5B,IAAM,MAAA,YAAA,GAAe,IAAI,YAAc,EAAA,GAAA;AAAA,MAAI,CAAC,OAC1C,KAAA,OAAO,YAAY,QAAW,GAAA,iBAAA,CAAkB,OAAO,CAAI,GAAA;AAAA,KAC7D;AACA,IAAI,IAAA,YAA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A,MAAA,CAAO,KAAM,CAAA,CAAC,CAAI,GAAA,MAAA,CAAA;AAAA,GAC3I,GAAA;AAEH,EAAO,OAAA;AAAA,IACL,EAAI,EAAA,YAAA;AAAA,IACJ,EAAI,EAAA,MAAA;AAAA,IACJ,GAAK,EAAA,YAAA;AAAA,IACL,IAAM,EAAA,YAAA;AAAA,IACN,UAAY,EAAA;AAAA,GACd;AACF;;;;"}
|
|
@@ -1,36 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
userOptions,
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return { type: "error", error };
|
|
20
|
-
}
|
|
21
|
-
if (!userOptions.props) {
|
|
22
|
-
return { type: "success", page: Page, props: undefined };
|
|
23
|
-
}
|
|
24
|
-
const {
|
|
25
|
-
type: propsType,
|
|
26
|
-
error: propsError,
|
|
27
|
-
props
|
|
28
|
-
} = await resolveUrlOption(userOptions, "props", route);
|
|
29
|
-
if (propsType === "error") {
|
|
30
|
-
return { type: "error", error: propsError };
|
|
31
|
-
}
|
|
32
|
-
return { type: "success", page: Page, props };
|
|
1
|
+
import { resolveUrlOption } from "../config/resolveUrlOption.js";
|
|
2
|
+
export const getRouteFiles = async (route, autoDiscoveredFiles, userOptions) => {
|
|
3
|
+
if (autoDiscoveredFiles.urlMap.has(route)) {
|
|
4
|
+
const { page, props } = autoDiscoveredFiles.urlMap.get(route);
|
|
5
|
+
return { type: "success", page, props };
|
|
6
|
+
}
|
|
7
|
+
const { type, error, Page } = await resolveUrlOption(userOptions, "Page", route);
|
|
8
|
+
if (type === "error") {
|
|
9
|
+
return { type: "error", error };
|
|
10
|
+
}
|
|
11
|
+
if (!userOptions.props) {
|
|
12
|
+
return { type: "success", page: Page, props: undefined };
|
|
13
|
+
}
|
|
14
|
+
const { type: propsType, error: propsError, props, } = await resolveUrlOption(userOptions, "props", route);
|
|
15
|
+
if (propsType === "error") {
|
|
16
|
+
return { type: "error", error: propsError };
|
|
17
|
+
}
|
|
18
|
+
return { type: "success", page: Page, props };
|
|
33
19
|
};
|
|
34
|
-
|
|
35
|
-
export { getRouteFiles };
|
|
36
|
-
//# sourceMappingURL=getRouteFiles.js.map
|
|
@@ -3,6 +3,7 @@ type CreateInputNormalizerProps = {
|
|
|
3
3
|
root: string;
|
|
4
4
|
preserveModulesRoot?: string | undefined;
|
|
5
5
|
removeExtension?: boolean | RegExp | string | ((path: string) => boolean);
|
|
6
|
+
moduleBasePath?: string | undefined;
|
|
6
7
|
};
|
|
7
8
|
/**
|
|
8
9
|
* @description Create a function that normalizes the input
|
|
@@ -11,6 +12,6 @@ type CreateInputNormalizerProps = {
|
|
|
11
12
|
* @param removeExtension - Whether to remove the extension of the file
|
|
12
13
|
* @returns A function that normalizes the input
|
|
13
14
|
*/
|
|
14
|
-
export declare function createInputNormalizer({ root, preserveModulesRoot, removeExtension, }: CreateInputNormalizerProps): InputNormalizer;
|
|
15
|
+
export declare function createInputNormalizer({ root, moduleBasePath, preserveModulesRoot, removeExtension, }: CreateInputNormalizerProps): InputNormalizer;
|
|
15
16
|
export {};
|
|
16
17
|
//# sourceMappingURL=inputNormalizer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputNormalizer.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/inputNormalizer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,aAAa,CAAC;AAMpE,KAAK,0BAA0B,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"inputNormalizer.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/inputNormalizer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,aAAa,CAAC;AAMpE,KAAK,0BAA0B,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;IAC1E,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,CAAC;AA+JF;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,IAAI,EACJ,cAAc,EACd,mBAA+B,EAC/B,eAAiD,GAClD,EAAE,0BAA0B,GAAG,eAAe,CAqE9C"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*/
|
|
6
6
|
import { normalizePath } from 'vite';
|
|
7
|
-
import path, { join } from 'path';
|
|
7
|
+
import path, { join, sep } from 'path';
|
|
8
8
|
import { DEFAULT_CONFIG } from '../config/defaults.js';
|
|
9
9
|
|
|
10
10
|
let stashedNormalizer = null;
|
|
@@ -53,15 +53,26 @@ const resolveRootOption = (root, preserveModulesRoot) => {
|
|
|
53
53
|
const createKeyNormalizer = ({
|
|
54
54
|
root: normalizedRoot,
|
|
55
55
|
preserveModulesRoot,
|
|
56
|
-
handleExtension
|
|
56
|
+
handleExtension,
|
|
57
|
+
moduleBasePath
|
|
57
58
|
}) => (key) => {
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
if (key.includes("?")) {
|
|
60
|
+
key = key.split("?")[0];
|
|
61
|
+
}
|
|
62
|
+
const virtualPrefix = key.match(/^\0+/) ?? "";
|
|
63
|
+
const actualKey = virtualPrefix ? key.slice(virtualPrefix[0].length) : key;
|
|
60
64
|
let moduleId = normalizePath(actualKey);
|
|
61
65
|
const normalizedRootPath = normalizePath(normalizedRoot);
|
|
62
66
|
if (moduleId.startsWith(normalizedRootPath)) {
|
|
63
67
|
moduleId = moduleId.slice(normalizedRootPath.length);
|
|
64
68
|
}
|
|
69
|
+
if (typeof moduleBasePath === "string" && moduleBasePath !== "" && moduleBasePath !== "/") {
|
|
70
|
+
moduleId = moduleId.startsWith(
|
|
71
|
+
moduleBasePath.endsWith(sep) ? moduleBasePath : moduleBasePath + sep
|
|
72
|
+
) ? moduleId.slice(
|
|
73
|
+
moduleBasePath.length + (moduleBasePath.endsWith(sep) ? 0 : sep.length)
|
|
74
|
+
) : moduleId;
|
|
75
|
+
}
|
|
65
76
|
moduleId = handleExtension(moduleId);
|
|
66
77
|
while (moduleId.startsWith("/") || moduleId.startsWith(".")) {
|
|
67
78
|
moduleId = moduleId.slice(1);
|
|
@@ -76,15 +87,26 @@ const createKeyNormalizer = ({
|
|
|
76
87
|
};
|
|
77
88
|
const createPathNormalizer = ({
|
|
78
89
|
root,
|
|
79
|
-
preserveModulesRoot
|
|
90
|
+
preserveModulesRoot,
|
|
91
|
+
moduleBasePath
|
|
80
92
|
}) => (path2) => {
|
|
81
93
|
if (typeof path2 !== "string") {
|
|
82
94
|
throw new Error(`Invalid path: ${JSON.stringify(path2)}`);
|
|
83
95
|
}
|
|
96
|
+
if (path2.includes("?")) {
|
|
97
|
+
path2 = path2.split("?")[0];
|
|
98
|
+
}
|
|
84
99
|
let normalPath = normalizePath(path2);
|
|
85
100
|
if (normalPath.startsWith(root)) {
|
|
86
101
|
normalPath = normalPath.slice(root.length);
|
|
87
102
|
}
|
|
103
|
+
if (typeof moduleBasePath === "string" && moduleBasePath !== "" && moduleBasePath !== "/") {
|
|
104
|
+
normalPath = normalPath.startsWith(
|
|
105
|
+
moduleBasePath.endsWith(sep) ? moduleBasePath : moduleBasePath + sep
|
|
106
|
+
) ? normalPath.slice(
|
|
107
|
+
moduleBasePath.length + (moduleBasePath.endsWith(sep) ? 0 : sep.length)
|
|
108
|
+
) : normalPath;
|
|
109
|
+
}
|
|
88
110
|
if (typeof preserveModulesRoot === "string" && preserveModulesRoot !== "") {
|
|
89
111
|
normalPath = normalPath.startsWith(preserveModulesRoot) ? normalPath.slice(preserveModulesRoot.length) : normalPath;
|
|
90
112
|
}
|
|
@@ -95,6 +117,7 @@ const createPathNormalizer = ({
|
|
|
95
117
|
};
|
|
96
118
|
function createInputNormalizer({
|
|
97
119
|
root,
|
|
120
|
+
moduleBasePath,
|
|
98
121
|
preserveModulesRoot = undefined,
|
|
99
122
|
removeExtension = DEFAULT_CONFIG.MODULE_EXTENSION
|
|
100
123
|
}) {
|
|
@@ -106,11 +129,13 @@ function createInputNormalizer({
|
|
|
106
129
|
const normalizeEntryKey = createKeyNormalizer({
|
|
107
130
|
root,
|
|
108
131
|
preserveModulesRoot,
|
|
109
|
-
handleExtension
|
|
132
|
+
handleExtension,
|
|
133
|
+
moduleBasePath
|
|
110
134
|
});
|
|
111
135
|
const normalizeEntryPath = createPathNormalizer({
|
|
112
136
|
root,
|
|
113
|
-
preserveModulesRoot: relativeRoot
|
|
137
|
+
preserveModulesRoot: relativeRoot,
|
|
138
|
+
moduleBasePath
|
|
114
139
|
});
|
|
115
140
|
function normalizeInput(id) {
|
|
116
141
|
if (Array.isArray(id)) {
|
|
@@ -140,8 +165,8 @@ function createInputNormalizer({
|
|
|
140
165
|
stashedNormalizer = (input) => {
|
|
141
166
|
const [key, path2] = normalizeInput(input);
|
|
142
167
|
const normalizedPath = path2.startsWith("/") ? path2.slice(1) : path2;
|
|
143
|
-
const virtualPrefix = key.match(/^\0+/)
|
|
144
|
-
const finalPath = virtualPrefix ? normalizedPath.startsWith(virtualPrefix) ? normalizedPath : virtualPrefix + normalizedPath : normalizedPath;
|
|
168
|
+
const virtualPrefix = key.match(/^\0+/) ?? "";
|
|
169
|
+
const finalPath = virtualPrefix ? virtualPrefix.length && normalizedPath.startsWith(virtualPrefix[0]) ? normalizedPath : virtualPrefix.length ? virtualPrefix[0] + normalizedPath : normalizedPath : normalizedPath;
|
|
145
170
|
return [key, finalPath];
|
|
146
171
|
};
|
|
147
172
|
return stashedNormalizer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputNormalizer.js","sources":["../../../plugin/helpers/inputNormalizer.ts"],"sourcesContent":["import { normalizePath } from \"vite\";\nimport type { InputNormalizer, NormalizerInput } from \"../types.js\";\nimport path, { join } from \"path\";\nimport { DEFAULT_CONFIG } from \"../config/defaults.js\";\n\nlet stashedNormalizer: InputNormalizer | null = null;\n\ntype CreateInputNormalizerProps = {\n root: string;\n preserveModulesRoot?: string | undefined;\n removeExtension?: boolean | RegExp | string | ((path: string) => boolean);\n};\n\nconst resolveExtensionOptions = (\n removeExtension: CreateInputNormalizerProps[\"removeExtension\"]\n) => {\n if (typeof removeExtension === \"boolean\") {\n if (removeExtension) {\n return (path: string) => {\n const extensionIndex = path.lastIndexOf(\".\");\n return extensionIndex !== -1 ? path.slice(0, extensionIndex) : path;\n };\n }\n return (path: string) => path;\n }\n if (typeof removeExtension === \"string\") {\n return (path: string) => path.replace(removeExtension, \"\");\n }\n if (removeExtension instanceof RegExp) {\n return (path: string) =>\n removeExtension.test(path) ? path.replace(removeExtension, \"\") : path;\n }\n if (typeof removeExtension === \"function\") {\n return (path: string) => {\n const extIndex = path.lastIndexOf(\".\");\n if (extIndex !== -1) {\n const extension = path.slice(extIndex);\n if (removeExtension(extension)) {\n return path.slice(0, extIndex);\n }\n }\n return path;\n };\n }\n return (path: string) => path;\n};\n\nconst resolveRootOption = (\n root: CreateInputNormalizerProps[\"root\"],\n preserveModulesRoot: CreateInputNormalizerProps[\"preserveModulesRoot\"]\n) => {\n if (typeof preserveModulesRoot === \"string\" && typeof root === \"string\") {\n const normalizedPreserveModulesRoot = normalizePath(preserveModulesRoot);\n if (root !== \"\" && normalizedPreserveModulesRoot.startsWith(root)) {\n return normalizedPreserveModulesRoot.slice(root.length + 1);\n }\n return \"\";\n } else if (typeof preserveModulesRoot === \"string\" && typeof root !== \"string\") {\n return normalizePath(preserveModulesRoot);\n }\n return \"\";\n};\nconst createKeyNormalizer =\n ({\n root: normalizedRoot,\n preserveModulesRoot,\n handleExtension,\n }: {\n root: string;\n preserveModulesRoot: string | undefined;\n handleExtension: (path: string) => string;\n }) =>\n (key: string) => {\n // Handle virtual modules first\n const virtualPrefix = key.match(/^\\0+/)?.[0] || '';\n const actualKey = key.slice(virtualPrefix.length);\n \n let moduleId = normalizePath(actualKey);\n \n // Normalize root path to handle both absolute and relative paths\n const normalizedRootPath = normalizePath(normalizedRoot);\n if (moduleId.startsWith(normalizedRootPath)) {\n moduleId = moduleId.slice(normalizedRootPath.length);\n }\n\n moduleId = handleExtension(moduleId);\n while (moduleId.startsWith(\"/\") || moduleId.startsWith(\".\")) {\n moduleId = moduleId.slice(1);\n }\n while (moduleId.endsWith(\"/\")) {\n moduleId = moduleId.slice(0, -1);\n }\n if (typeof preserveModulesRoot === \"string\" && preserveModulesRoot !== \"\") {\n moduleId = moduleId.startsWith(preserveModulesRoot)\n ? moduleId.slice(preserveModulesRoot.length + path.sep.length)\n : moduleId;\n }\n \n // Add virtual prefix back\n return virtualPrefix + moduleId;\n };\n\nconst createPathNormalizer =\n ({\n root,\n preserveModulesRoot,\n }: {\n root: string;\n preserveModulesRoot: string | undefined;\n }) =>\n (path: string) => {\n if (typeof path !== \"string\") {\n throw new Error(`Invalid path: ${JSON.stringify(path)}`);\n }\n let normalPath = normalizePath(path);\n if(normalPath.startsWith(root)) {\n normalPath = normalPath.slice(root.length);\n }\n if (typeof preserveModulesRoot === \"string\" && preserveModulesRoot !== \"\") {\n normalPath = normalPath.startsWith(preserveModulesRoot)\n ? normalPath.slice(preserveModulesRoot.length)\n : normalPath;\n }\n while (normalPath.endsWith(\"/\")) {\n normalPath = normalPath.slice(0, -1);\n }\n return normalPath;\n };\n/**\n * @description Create a function that normalizes the input\n * @param root - The root of the project\n * @param preserveModulesRoot - The root of the preserve modules\n * @param removeExtension - Whether to remove the extension of the file\n * @returns A function that normalizes the input\n */\nexport function createInputNormalizer({\n root,\n preserveModulesRoot = undefined,\n removeExtension = DEFAULT_CONFIG.MODULE_EXTENSION,\n}: CreateInputNormalizerProps): InputNormalizer {\n if(stashedNormalizer) {\n return stashedNormalizer;\n }\n const relativeRoot = resolveRootOption(root, preserveModulesRoot);\n const handleExtension = resolveExtensionOptions(removeExtension);\n const normalizeEntryKey = createKeyNormalizer({\n root: root,\n preserveModulesRoot: preserveModulesRoot,\n handleExtension,\n });\n const normalizeEntryPath = createPathNormalizer({\n root: root,\n preserveModulesRoot: relativeRoot,\n });\n function normalizeInput(id: NormalizerInput): [string, string] {\n // Normalize both paths to use POSIX separators\n if (Array.isArray(id)) {\n const [key, path] = id;\n if (typeof key === \"string\" && Array.isArray(path) && path.length === 2) {\n const isNumber = !isNaN(Number(key));\n if (isNumber) {\n // ignore it\n return normalizeInput([path[0], path[1]]);\n }\n return normalizeInput([join(key, path[0]), path[1]]);\n }\n if (typeof key !== \"string\" || typeof path !== \"string\") {\n throw new Error(`Invalid input: ${JSON.stringify(id)}`);\n }\n return [normalizeEntryKey(key), normalizeEntryPath(path)];\n } else if (typeof id === \"string\") {\n // Return both the normalized ID and original normalized path\n return [normalizeEntryKey(id), normalizeEntryPath(id)];\n } else if (\n typeof id === \"object\" &&\n id !== null &&\n \"$$typeof\" in id &&\n \"$$id\" in id &&\n typeof id.$$id === \"string\"\n ) {\n const normalized: [string, string] = [\n normalizeEntryKey(id.$$id),\n normalizeEntryPath(id.$$id),\n ];\n return normalized;\n }\n throw new Error(`Invalid input type: ${typeof id}`);\n };\n\n stashedNormalizer = (input: NormalizerInput): [string, string] => {\n const [key, path] = normalizeInput(input);\n // Apply the same normalization to both key and path\n const normalizedPath = path.startsWith('/') ? path.slice(1) : path;\n const virtualPrefix = key.match(/^\\0+/)?.[0] || '';\n \n // If key has virtual prefix, ensure path has it too\n const finalPath = virtualPrefix ? \n (normalizedPath.startsWith(virtualPrefix) ? normalizedPath : virtualPrefix + normalizedPath) : \n normalizedPath;\n \n return [key, finalPath];\n };\n return stashedNormalizer;\n}\n"],"names":["path"],"mappings":";;;;;;;;;AAKA,IAAI,iBAA4C,GAAA,IAAA;AAQhD,MAAM,uBAAA,GAA0B,CAC9B,eACG,KAAA;AACH,EAAI,IAAA,OAAO,oBAAoB,SAAW,EAAA;AACxC,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAA,OAAO,CAACA,KAAiB,KAAA;AACvB,QAAM,MAAA,cAAA,GAAiBA,KAAK,CAAA,WAAA,CAAY,GAAG,CAAA;AAC3C,QAAA,OAAO,mBAAmB,EAAKA,GAAAA,KAAAA,CAAK,KAAM,CAAA,CAAA,EAAG,cAAc,CAAIA,GAAAA,KAAAA;AAAA,OACjE;AAAA;AAEF,IAAA,OAAO,CAACA,KAAiBA,KAAAA,KAAAA;AAAA;AAE3B,EAAI,IAAA,OAAO,oBAAoB,QAAU,EAAA;AACvC,IAAA,OAAO,CAACA,KAAAA,KAAiBA,KAAK,CAAA,OAAA,CAAQ,iBAAiB,EAAE,CAAA;AAAA;AAE3D,EAAA,IAAI,2BAA2B,MAAQ,EAAA;AACrC,IAAO,OAAA,CAACA,KACN,KAAA,eAAA,CAAgB,IAAKA,CAAAA,KAAI,IAAIA,KAAK,CAAA,OAAA,CAAQ,eAAiB,EAAA,EAAE,CAAIA,GAAAA,KAAAA;AAAA;AAErE,EAAI,IAAA,OAAO,oBAAoB,UAAY,EAAA;AACzC,IAAA,OAAO,CAACA,KAAiB,KAAA;AACvB,MAAM,MAAA,QAAA,GAAWA,KAAK,CAAA,WAAA,CAAY,GAAG,CAAA;AACrC,MAAA,IAAI,aAAa,EAAI,EAAA;AACnB,QAAM,MAAA,SAAA,GAAYA,KAAK,CAAA,KAAA,CAAM,QAAQ,CAAA;AACrC,QAAI,IAAA,eAAA,CAAgB,SAAS,CAAG,EAAA;AAC9B,UAAOA,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AA,MAAM,gBAAgB,GAAI,CAAA,KAAA,CAAM,MAAM,CAAA,GAAI,CAAC,CAAK,IAAA,EAAA;AAGhD,IAAM,MAAA,SAAA,GAAY,gBACf,cAAe,CAAA,UAAA,CAAW,aAAa,CAAI,GAAA,cAAA,GAAiB,gBAAgB,cAC7E,GAAA,cAAA;AAEF,IAAO,OAAA,CAAC,KAAK,SAAS,CAAA;AAAA,GACxB;AACA,EAAO,OAAA,iBAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"inputNormalizer.js","sources":["../../../plugin/helpers/inputNormalizer.ts"],"sourcesContent":["import { normalizePath } from \"vite\";\nimport type { InputNormalizer, NormalizerInput } from \"../types.js\";\nimport path, { join, sep } from \"path\";\nimport { DEFAULT_CONFIG } from \"../config/defaults.js\";\n\nlet stashedNormalizer: InputNormalizer | null = null;\n\ntype CreateInputNormalizerProps = {\n root: string;\n preserveModulesRoot?: string | undefined;\n removeExtension?: boolean | RegExp | string | ((path: string) => boolean);\n moduleBasePath?: string | undefined;\n};\n\nconst resolveExtensionOptions = (\n removeExtension: CreateInputNormalizerProps[\"removeExtension\"]\n) => {\n if (typeof removeExtension === \"boolean\") {\n if (removeExtension) {\n return (path: string) => {\n const extensionIndex = path.lastIndexOf(\".\");\n return extensionIndex !== -1 ? path.slice(0, extensionIndex) : path;\n };\n }\n return (path: string) => path;\n }\n if (typeof removeExtension === \"string\") {\n return (path: string) => path.replace(removeExtension, \"\");\n }\n if (removeExtension instanceof RegExp) {\n return (path: string) =>\n removeExtension.test(path) ? path.replace(removeExtension, \"\") : path;\n }\n if (typeof removeExtension === \"function\") {\n return (path: string) => {\n const extIndex = path.lastIndexOf(\".\");\n if (extIndex !== -1) {\n const extension = path.slice(extIndex);\n if (removeExtension(extension)) {\n return path.slice(0, extIndex);\n }\n }\n return path;\n };\n }\n return (path: string) => path;\n};\n\nconst resolveRootOption = (\n root: CreateInputNormalizerProps[\"root\"],\n preserveModulesRoot: CreateInputNormalizerProps[\"preserveModulesRoot\"]\n) => {\n if (typeof preserveModulesRoot === \"string\" && typeof root === \"string\") {\n const normalizedPreserveModulesRoot = normalizePath(preserveModulesRoot);\n if (root !== \"\" && normalizedPreserveModulesRoot.startsWith(root)) {\n return normalizedPreserveModulesRoot.slice(root.length + 1);\n }\n return \"\";\n } else if (\n typeof preserveModulesRoot === \"string\" &&\n typeof root !== \"string\"\n ) {\n return normalizePath(preserveModulesRoot);\n }\n return \"\";\n};\nconst createKeyNormalizer =\n ({\n root: normalizedRoot,\n preserveModulesRoot,\n handleExtension,\n moduleBasePath,\n }: {\n root: string;\n preserveModulesRoot: string | undefined;\n handleExtension: (path: string) => string;\n moduleBasePath: string | undefined;\n }) =>\n (key: string) => {\n if (key.includes(\"?\")) {\n key = key.split(\"?\")[0];\n }\n\n // Handle virtual modules first\n const virtualPrefix = key.match(/^\\0+/) ?? \"\";\n const actualKey = virtualPrefix ? key.slice(virtualPrefix[0].length) : key;\n\n let moduleId = normalizePath(actualKey);\n\n // Normalize root path to handle both absolute and relative paths\n const normalizedRootPath = normalizePath(normalizedRoot);\n if (moduleId.startsWith(normalizedRootPath)) {\n moduleId = moduleId.slice(normalizedRootPath.length);\n }\n if (\n typeof moduleBasePath === \"string\" &&\n moduleBasePath !== \"\" &&\n moduleBasePath !== \"/\"\n ) {\n moduleId = moduleId.startsWith(\n moduleBasePath.endsWith(sep) ? moduleBasePath : moduleBasePath + sep\n )\n ? moduleId.slice(\n moduleBasePath.length +\n (moduleBasePath.endsWith(sep) ? 0 : sep.length)\n )\n : moduleId;\n }\n\n moduleId = handleExtension(moduleId);\n while (moduleId.startsWith(\"/\") || moduleId.startsWith(\".\")) {\n moduleId = moduleId.slice(1);\n }\n while (moduleId.endsWith(\"/\")) {\n moduleId = moduleId.slice(0, -1);\n }\n if (typeof preserveModulesRoot === \"string\" && preserveModulesRoot !== \"\") {\n moduleId = moduleId.startsWith(preserveModulesRoot)\n ? moduleId.slice(preserveModulesRoot.length + path.sep.length)\n : moduleId;\n }\n\n // Add virtual prefix back\n return virtualPrefix + moduleId;\n };\n\nconst createPathNormalizer =\n ({\n root,\n preserveModulesRoot,\n moduleBasePath,\n }: {\n root: string;\n preserveModulesRoot: string | undefined;\n moduleBasePath: string | undefined;\n }) =>\n (path: string) => {\n if (typeof path !== \"string\") {\n throw new Error(`Invalid path: ${JSON.stringify(path)}`);\n }\n if (path.includes(\"?\")) {\n path = path.split(\"?\")[0];\n }\n let normalPath = normalizePath(path);\n if (normalPath.startsWith(root)) {\n normalPath = normalPath.slice(root.length);\n }\n if (\n typeof moduleBasePath === \"string\" &&\n moduleBasePath !== \"\" &&\n moduleBasePath !== \"/\"\n ) {\n normalPath = normalPath.startsWith(\n moduleBasePath.endsWith(sep) ? moduleBasePath : moduleBasePath + sep\n )\n ? normalPath.slice(\n moduleBasePath.length +\n (moduleBasePath.endsWith(sep) ? 0 : sep.length)\n )\n : normalPath;\n }\n if (typeof preserveModulesRoot === \"string\" && preserveModulesRoot !== \"\") {\n normalPath = normalPath.startsWith(preserveModulesRoot)\n ? normalPath.slice(preserveModulesRoot.length)\n : normalPath;\n }\n while (normalPath.endsWith(\"/\")) {\n normalPath = normalPath.slice(0, -1);\n }\n return normalPath;\n };\n/**\n * @description Create a function that normalizes the input\n * @param root - The root of the project\n * @param preserveModulesRoot - The root of the preserve modules\n * @param removeExtension - Whether to remove the extension of the file\n * @returns A function that normalizes the input\n */\nexport function createInputNormalizer({\n root,\n moduleBasePath,\n preserveModulesRoot = undefined,\n removeExtension = DEFAULT_CONFIG.MODULE_EXTENSION,\n}: CreateInputNormalizerProps): InputNormalizer {\n if (stashedNormalizer) {\n return stashedNormalizer;\n }\n const relativeRoot = resolveRootOption(root, preserveModulesRoot);\n const handleExtension = resolveExtensionOptions(removeExtension);\n const normalizeEntryKey = createKeyNormalizer({\n root: root,\n preserveModulesRoot: preserveModulesRoot,\n handleExtension,\n moduleBasePath,\n });\n const normalizeEntryPath = createPathNormalizer({\n root: root,\n preserveModulesRoot: relativeRoot,\n moduleBasePath,\n });\n function normalizeInput(id: NormalizerInput): [string, string] {\n // Normalize both paths to use POSIX separators\n if (Array.isArray(id)) {\n const [key, path] = id;\n if (typeof key === \"string\" && Array.isArray(path) && path.length === 2) {\n const isNumber = !isNaN(Number(key));\n if (isNumber) {\n // ignore it\n return normalizeInput([path[0], path[1]]);\n }\n return normalizeInput([join(key, path[0]), path[1]]);\n }\n if (typeof key !== \"string\" || typeof path !== \"string\") {\n throw new Error(`Invalid input: ${JSON.stringify(id)}`);\n }\n return [normalizeEntryKey(key), normalizeEntryPath(path)];\n } else if (typeof id === \"string\") {\n // Return both the normalized ID and original normalized path\n return [normalizeEntryKey(id), normalizeEntryPath(id)];\n } else if (\n typeof id === \"object\" &&\n id !== null &&\n \"$$typeof\" in id &&\n \"$$id\" in id &&\n typeof id.$$id === \"string\"\n ) {\n const normalized: [string, string] = [\n normalizeEntryKey(id.$$id),\n normalizeEntryPath(id.$$id),\n ];\n return normalized;\n }\n throw new Error(`Invalid input type: ${typeof id}`);\n }\n\n stashedNormalizer = (input: NormalizerInput): [string, string] => {\n const [key, path] = normalizeInput(input);\n // Apply the same normalization to both key and path\n const normalizedPath = path.startsWith(\"/\") ? path.slice(1) : path;\n const virtualPrefix = key.match(/^\\0+/) ?? \"\";\n // If key has virtual prefix, ensure path has it too\n const finalPath = virtualPrefix\n ? virtualPrefix.length && normalizedPath.startsWith(virtualPrefix[0])\n ? normalizedPath\n : virtualPrefix.length\n ? virtualPrefix[0] + normalizedPath\n : normalizedPath\n : normalizedPath;\n\n return [key, finalPath];\n };\n return stashedNormalizer;\n}\n"],"names":["path"],"mappings":";;;;;;;;;AAKA,IAAI,iBAA4C,GAAA,IAAA;AAShD,MAAM,uBAAA,GAA0B,CAC9B,eACG,KAAA;AACH,EAAI,IAAA,OAAO,oBAAoB,SAAW,EAAA;AACxC,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAA,OAAO,CAACA,KAAiB,KAAA;AACvB,QAAM,MAAA,cAAA,GA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AO,QAAU,EAAA;AAEjC,MAAA,OAAO,CAAC,iBAAkB,CAAA,EAAE,CAAG,EAAA,kBAAA,CAAmB,EAAE,CAAC,CAAA;AAAA,KAErD,MAAA,IAAA,OAAO,EAAO,KAAA,QAAA,IACd,EAAO,KAAA,IAAA,IACP,UAAc,IAAA,EAAA,IACd,MAAU,IAAA,EAAA,IACV,OAAO,EAAA,CAAG,SAAS,QACnB,EAAA;AACA,MAAA,MAAM,UAA+B,GAAA;AAAA,QACnC,iBAAA,CAAkB,GAAG,IAAI,CAAA;AAAA,QACzB,kBAAA,CAAmB,GAAG,IAAI;AAAA,OAC5B;AACA,MAAO,OAAA,UAAA;AAAA;AAET,IAAA,MAAM,IAAI,KAAA,CAAM,CAAuB,oBAAA,EAAA,OAAO,EAAE,CAAE,CAAA,CAAA;AAAA;AAGpD,EAAA,iBAAA,GAAoB,CAAC,KAA6C,KAAA;AAChE,IAAA,MAAM,CAAC,GAAA,EAAKA,KAAI,CAAA,GAAI,eAAe,KAAK,CAAA;AAExC,IAAM,MAAA,cAAA,GAAiBA,MAAK,UAAW,CAAA,GAAG,IAAIA,KAAK,CAAA,KAAA,CAAM,CAAC,CAAIA,GAAAA,KAAAA;AAC9D,IAAA,MAAM,aAAgB,GAAA,GAAA,CAAI,KAAM,CAAA,MAAM,CAAK,IAAA,EAAA;AAE3C,IAAA,MAAM,YAAY,aACd,GAAA,aAAA,CAAc,MAAU,IAAA,cAAA,CAAe,WAAW,aAAc,CAAA,CAAC,CAAC,CAAA,GAChE,iBACA,aAAc,CAAA,MAAA,GACd,cAAc,CAAC,CAAA,GAAI,iBACnB,cACF,GAAA,cAAA;AAEJ,IAAO,OAAA,CAAC,KAAK,SAAS,CAAA;AAAA,GACxB;AACA,EAAO,OAAA,iBAAA;AACT;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ResolvedUserOptions } from "../types.js";
|
|
2
|
+
import type { Connect } from "vite";
|
|
3
|
+
export declare function requestInfo(req: Connect.IncomingMessage, userOptions: Pick<ResolvedUserOptions, "normalizer" | "build" | "autoDiscover">, hostDir: string): {
|
|
4
|
+
route: string;
|
|
5
|
+
ext: string;
|
|
6
|
+
isHtmlRequest: boolean;
|
|
7
|
+
isRscRequest: boolean | undefined;
|
|
8
|
+
isCssRequest: boolean | undefined;
|
|
9
|
+
isCss: boolean;
|
|
10
|
+
isHtml: boolean;
|
|
11
|
+
isRsc: boolean;
|
|
12
|
+
isFolder: boolean;
|
|
13
|
+
contentType: string;
|
|
14
|
+
filePath: string;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=requestInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestInfo.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/requestInfo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGpC,wBAAgB,WAAW,CACzB,GAAG,EAAE,OAAO,CAAC,eAAe,EAC5B,WAAW,EAAE,IAAI,CAAC,mBAAmB,EAAE,YAAY,GAAG,OAAO,GAAG,cAAc,CAAC,EAC/E,OAAO,EAAE,MAAM;;;;;;;;;;;;EAwEhB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { MIME_TYPES } from '../config/mimeTypes.js';
|
|
8
|
+
|
|
9
|
+
function requestInfo(req, userOptions, hostDir) {
|
|
10
|
+
const [, value] = userOptions.normalizer(req.url);
|
|
11
|
+
const dotIndex = value.lastIndexOf(".");
|
|
12
|
+
const ext = dotIndex === -1 ? "" : value.slice(dotIndex);
|
|
13
|
+
const isHtml = userOptions.autoDiscover.htmlPattern(value);
|
|
14
|
+
const hasHtmlHeader = req.headers.accept?.includes("text/html");
|
|
15
|
+
const isRsc = userOptions.autoDiscover.rscPattern(value);
|
|
16
|
+
const hasRscHeader = req.headers.accept?.includes("text/x-component");
|
|
17
|
+
const isFolder = !ext;
|
|
18
|
+
const isHtmlRequest = isHtml || hasHtmlHeader || isFolder && !hasRscHeader && !isRsc;
|
|
19
|
+
const isRscRequest = !isHtmlRequest && (isRsc || hasRscHeader);
|
|
20
|
+
const isCss = userOptions.autoDiscover.cssPattern(value);
|
|
21
|
+
const isCssRequest = !isHtmlRequest && !isRscRequest && (isCss || req.headers.accept?.includes("text/css"));
|
|
22
|
+
let filePath = join(hostDir, value);
|
|
23
|
+
let contentType;
|
|
24
|
+
if (isHtmlRequest) {
|
|
25
|
+
if (!isHtml) {
|
|
26
|
+
filePath = join(hostDir, value, userOptions.build.htmlOutputPath);
|
|
27
|
+
}
|
|
28
|
+
contentType = "text/html; charset=utf-8";
|
|
29
|
+
} else if (isRscRequest) {
|
|
30
|
+
if (!isRsc) {
|
|
31
|
+
filePath = join(hostDir, value, userOptions.build.rscOutputPath);
|
|
32
|
+
}
|
|
33
|
+
contentType = "text/x-component; charset=utf-8";
|
|
34
|
+
} else if (isCssRequest) {
|
|
35
|
+
if (!isCss) {
|
|
36
|
+
filePath = join(hostDir, value);
|
|
37
|
+
}
|
|
38
|
+
contentType = "text/css; charset=utf-8";
|
|
39
|
+
} else {
|
|
40
|
+
const mimeType = MIME_TYPES[ext];
|
|
41
|
+
if (mimeType) {
|
|
42
|
+
contentType = mimeType;
|
|
43
|
+
} else {
|
|
44
|
+
contentType = "application/octet-stream";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const route = value.replace(userOptions.build.rscOutputPath, "").replace(userOptions.build.htmlOutputPath, "");
|
|
48
|
+
const routeWithoutTrailingSlash = route === "" || route === "/" ? "/" : route.endsWith("/") ? route.slice(0, -1) : route;
|
|
49
|
+
const routeWithLeadingSlash = routeWithoutTrailingSlash.startsWith("/") ? routeWithoutTrailingSlash : `/${routeWithoutTrailingSlash}`;
|
|
50
|
+
return {
|
|
51
|
+
route: routeWithLeadingSlash,
|
|
52
|
+
ext,
|
|
53
|
+
isHtmlRequest,
|
|
54
|
+
isRscRequest,
|
|
55
|
+
isCssRequest,
|
|
56
|
+
isCss,
|
|
57
|
+
isHtml,
|
|
58
|
+
isRsc,
|
|
59
|
+
isFolder,
|
|
60
|
+
contentType,
|
|
61
|
+
filePath
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { requestInfo };
|
|
66
|
+
//# sourceMappingURL=requestInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestInfo.js","sources":["../../../plugin/helpers/requestInfo.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport type { ResolvedUserOptions } from \"../types.js\";\nimport type { Connect } from \"vite\";\nimport { MIME_TYPES } from \"../config/mimeTypes.js\";\n\nexport function requestInfo(\n req: Connect.IncomingMessage,\n userOptions: Pick<ResolvedUserOptions, \"normalizer\" | \"build\" | \"autoDiscover\">,\n hostDir: string\n) {\n const [, value] = userOptions.normalizer(req.url);\n const dotIndex = value.lastIndexOf(\".\");\n const ext = dotIndex === -1 ? \"\" : value.slice(dotIndex);\n // handle index.html\n const isHtml = userOptions.autoDiscover.htmlPattern(value);\n const hasHtmlHeader = req.headers.accept?.includes(\"text/html\");\n const isRsc = userOptions.autoDiscover.rscPattern(value);\n const hasRscHeader = req.headers.accept?.includes(\"text/x-component\");\n const isFolder = !ext;\n const isHtmlRequest =\n isHtml || hasHtmlHeader || (isFolder && !hasRscHeader && !isRsc);\n const isRscRequest = !isHtmlRequest && (isRsc || hasRscHeader);\n const isCss = userOptions.autoDiscover.cssPattern(value);\n const isCssRequest =\n !isHtmlRequest &&\n !isRscRequest &&\n (isCss || req.headers.accept?.includes(\"text/css\"));\n let filePath = join(hostDir, value);\n let contentType;\n if (isHtmlRequest) {\n if (!isHtml) {\n filePath = join(hostDir, value, userOptions.build.htmlOutputPath);\n }\n contentType = \"text/html; charset=utf-8\";\n } else if (isRscRequest) {\n if (!isRsc) {\n filePath = join(hostDir, value, userOptions.build.rscOutputPath);\n }\n contentType = \"text/x-component; charset=utf-8\";\n } else if (isCssRequest) {\n if (!isCss) {\n filePath = join(hostDir, value);\n }\n contentType = \"text/css; charset=utf-8\";\n } else {\n const mimeType = MIME_TYPES[ext];\n if (mimeType) {\n contentType = mimeType;\n } else {\n contentType = \"application/octet-stream\";\n }\n }\n const route = value\n .replace(userOptions.build.rscOutputPath, \"\")\n .replace(userOptions.build.htmlOutputPath, \"\");\n \n const routeWithoutTrailingSlash =\n route === \"\" || route === \"/\"\n ? \"/\"\n : route.endsWith(\"/\")\n ? route.slice(0, -1)\n : route;\n const routeWithLeadingSlash =\n routeWithoutTrailingSlash.startsWith(\"/\")\n ? routeWithoutTrailingSlash\n : `/${routeWithoutTrailingSlash}`;\n\n return {\n route: routeWithLeadingSlash,\n ext,\n isHtmlRequest,\n isRscRequest,\n isCssRequest,\n isCss,\n isHtml,\n isRsc,\n isFolder,\n contentType,\n filePath,\n };\n}\n"],"names":[],"mappings":";;;;;;;;AAKO,SAAS,WAAA,CACd,GACA,EAAA,WAAA,EACA,OACA,EAAA;AACA,EAAA,MAAM,GAAG,KAAK,IAAI,WAAY,CAAA,UAAA,CAAW,IAAI,GAAG,CAAA;AAChD,EAAM,MAAA,QAAA,GAAW,KAAM,CAAA,WAAA,CAAY,GAAG,CAAA;AACtC,EAAA,MAAM,MAAM,QAAa,KAAA,EAAA,GAAK,EAAK,GAAA,KAAA,CAAM,MAAM,QAAQ,CAAA;AAEvD,EAAA,MAAM,MAAS,GAAA,WAAA,CAAY,YAAa,CAAA,WAAA,CAAY,KAAK,CAAA;AACzD,EAAA,MAAM,aAAgB,GAAA,GAAA,CAAI,OAAQ,CAAA,MAAA,EAAQ,SAAS,WAAW,CAAA;AAC9D,EAAA,MAAM,KAAQ,GAAA,WAAA,CAAY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/B,IAAA,IAAI,QAAU,EAAA;AACZ,MAAc,WAAA,GAAA,QAAA;AAAA,KACT,MAAA;AACL,MAAc,WAAA,GAAA,0BAAA;AAAA;AAChB;AAEF,EAAA,MAAM,KAAQ,GAAA,KAAA,CACX,OAAQ,CAAA,WAAA,CAAY,KAAM,CAAA,aAAA,EAAe,EAAE,CAAA,CAC3C,OAAQ,CAAA,WAAA,CAAY,KAAM,CAAA,cAAA,EAAgB,EAAE,CAAA;AAE/C,EAAA,MAAM,yBACJ,GAAA,KAAA,KAAU,EAAM,IAAA,KAAA,KAAU,MACtB,GACA,GAAA,KAAA,CAAM,QAAS,CAAA,GAAG,CAClB,GAAA,KAAA,CAAM,KAAM,CAAA,CAAA,EAAG,EAAE,CACjB,GAAA,KAAA;AACN,EAAA,MAAM,wBACJ,yBAA0B,CAAA,UAAA,CAAW,GAAG,CACpC,GAAA,yBAAA,GACA,IAAI,yBAAyB,CAAA,CAAA;AAEnC,EAAO,OAAA;AAAA,IACL,KAAO,EAAA,qBAAA;AAAA,IACP,GAAA;AAAA,IACA,aAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export function requestToRoute(req, handlerOptions) {
|
|
2
|
+
let route = req.url?.replace("/" + handlerOptions.build.rscOutputPath, "");
|
|
3
|
+
if (typeof route !== "string") {
|
|
4
|
+
return route;
|
|
5
|
+
}
|
|
6
|
+
if (route.startsWith(handlerOptions.moduleBasePath)) {
|
|
7
|
+
route = route.slice(handlerOptions.moduleBasePath.length);
|
|
8
|
+
}
|
|
9
|
+
if (!route || route === "") {
|
|
10
|
+
route = "/";
|
|
11
|
+
}
|
|
12
|
+
if (!route.startsWith("/")) {
|
|
13
|
+
route = "/" + route;
|
|
14
|
+
}
|
|
9
15
|
return route;
|
|
10
|
-
}
|
|
11
|
-
if (route.startsWith(handlerOptions.moduleBasePath)) {
|
|
12
|
-
route = route.slice(handlerOptions.moduleBasePath.length);
|
|
13
|
-
}
|
|
14
|
-
if (!route || route === "") {
|
|
15
|
-
route = "/";
|
|
16
|
-
}
|
|
17
|
-
if (!route.startsWith("/")) {
|
|
18
|
-
route = "/" + route;
|
|
19
|
-
}
|
|
20
|
-
return route;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
|
-
export { requestToRoute };
|
|
24
|
-
//# sourceMappingURL=requestToRoute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializeUserOptions.js","sources":["../../../plugin/helpers/serializeUserOptions.ts"],"sourcesContent":["import type { ResolvedConfig, ViteDevServer } from \"vite\";\nimport type {\n AutoDiscoveredFiles,\n ResolvedUserOptions,\n} from \"../types.js\";\nimport { cleanObject } from \"./cleanObject.js\";\n\n// Common non-serializable functions in Vite's resolved config\nconst VITE_NON_SERIALIZABLE_FUNCTIONS = new Set([\n \"renderChunk\",\n \"buildStart\",\n \"buildEnd\",\n \"watchChange\",\n \"resolveId\",\n \"config\",\n \"output[].entryFileNames\",\n \"output[].chunkFileNames\",\n \"output[].assetFileNames\",\n \"transform\",\n \"handler\",\n \"configureServer\",\n \"shouldTransformCachedModule\",\n \"generateBundle\",\n \"renderStart\",\n \"writeBundle\",\n \"hotUpdate\",\n \"configResolved\",\n \"configurePreviewServer\",\n \"handleHotUpdate\",\n \"load\",\n \"augmentChunkHash\",\n \"closeBundle\",\n \"entryFileNames\",\n \"assetFileNames\",\n \"chunkFileNames\",\n \"createEnvironment\",\n \"sourcemapIgnoreList\",\n \"assetsInclude\",\n \"info\",\n \"warn\",\n \"warnOnce\",\n \"error\",\n \"clearScreen\",\n \"hasErrorLogged\",\n \"set\",\n \"plugins\",\n \"getSortedPlugins\",\n \"getSortedPluginHooks\",\n \"createResolver\",\n \"fsDenyGlob\",\n // Nested plugin functions\n \"plugins[].renderChunk\",\n \"plugins[].buildStart\",\n \"plugins[].buildEnd\",\n \"plugins[].watchChange\",\n \"plugins[].resolveId\",\n \"plugins[].config\",\n \"plugins[].transform\",\n \"plugins[].handler\",\n \"plugins[].configureServer\",\n \"plugins[].shouldTransformCachedModule\",\n \"plugins[].generateBundle\",\n \"plugins[].renderStart\",\n \"plugins[].writeBundle\",\n \"plugins[].hotUpdate\",\n \"plugins[].configResolved\",\n \"plugins[].configurePreviewServer\",\n \"plugins[].handleHotUpdate\",\n \"plugins[].load\",\n \"plugins[].augmentChunkHash\",\n \"plugins[].closeBundle\",\n \"plugins[].entryFileNames\",\n \"plugins[].assetFileNames\",\n \"plugins[].chunkFileNames\",\n \"plugins[].createEnvironment\",\n \"plugins[].sourcemapIgnoreList\",\n \"plugins[].assetsInclude\",\n]);\n\n// Common non-serializable functions in our plugin's options\nconst PLUGIN_NON_SERIALIZABLE_FUNCTIONS = new Set([\n \"Page\",\n \"props\",\n \"normalizer\",\n \"CssCollector\",\n \"Html\",\n \"onEvent\",\n \"onMetrics\",\n \"build.entryFile\",\n \"build.chunkFile\",\n \"build.assetFile\",\n \"build.pages\",\n \"autoDiscover\",\n]);\n\n// Helper function to serialize RegExp objects\nfunction serializeRegExp(regex: RegExp) {\n return {\n source: regex.source,\n flags: regex.flags,\n __isRegExp: true\n };\n}\n\n// Helper function to deserialize RegExp objects\nexport function deserializeRegExp(obj: any): any {\n if (obj && obj.__isRegExp) {\n return new RegExp(obj.source, obj.flags);\n }\n if (Array.isArray(obj)) {\n return obj.map(deserializeRegExp);\n }\n if (obj && typeof obj === 'object') {\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = deserializeRegExp(value);\n }\n return result;\n }\n return obj;\n}\n\n// Helper function to recursively process objects for serialization\nexport function processForSerialization(obj: any): any {\n if (obj instanceof RegExp) {\n return serializeRegExp(obj);\n }\n if (Array.isArray(obj)) {\n return obj.map(processForSerialization);\n }\n if (obj && typeof obj === 'object') {\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = processForSerialization(value);\n }\n return result;\n }\n return obj;\n}\n\nexport function serializeResolvedConfig<T extends ResolvedConfig>(\n config: T,\n knownNonSerializableFunctions: Set<string> = VITE_NON_SERIALIZABLE_FUNCTIONS\n) {\n const {\n getSortedPluginHooks,\n getSortedPlugins,\n assetsInclude,\n // extract known vite function properties\n ...handlerOptions\n } = config;\n\n // Clean the object to remove non-serializable properties and process RegExp objects\n return processForSerialization(cleanObject(handlerOptions, knownNonSerializableFunctions));\n}\n\n// For Vite's config\nexport const serializedDevServerConfig = <T extends ViteDevServer[\"config\"]>(\n config: T,\n customNonSerializableFunctions: Set<string> = PLUGIN_NON_SERIALIZABLE_FUNCTIONS\n) => {\n const {\n getSortedPluginHooks,\n getSortedPlugins,\n assetsInclude,\n build,\n ...handlerOptions\n } = config;\n return processForSerialization(cleanObject(\n handlerOptions,\n customNonSerializableFunctions\n ));\n};\n\n// For your own options (if you need custom non-serializable functions)\nexport const serializedOptions = <T extends ResolvedUserOptions>(\n userOptions: T,\n autoDiscoveredFiles: AutoDiscoveredFiles,\n customNonSerializableFunctions: Set<string> = PLUGIN_NON_SERIALIZABLE_FUNCTIONS\n) => {\n const {\n Page,\n props,\n normalizer,\n CssCollector,\n Html,\n onEvent,\n onMetrics,\n build,\n autoDiscover,\n ...handlerOptions\n } = userOptions;\n const { entryFile, chunkFile, assetFile, pages, ...buildOptions } = build;\n const result = {\n ...handlerOptions,\n build: {\n ...buildOptions,\n pages: autoDiscoveredFiles\n ? Array.from(autoDiscoveredFiles.urlMap.keys())\n : [],\n },\n };\n\n // Clean the object to remove non-serializable properties and process RegExp objects\n return processForSerialization(cleanObject(\n result,\n customNonSerializableFunctions\n ));\n};\n"],"names":[],"mappings":";;;;;;;AAQA,MAAM,+BAAA,uBAAsC,GAAI,CAA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;AAExC,EAAI,IAAA,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAU,EAAA;AAClC,IAAA,MAAM,SAAc,EAAC;AACrB,IAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,GAAG,CAAG,EAAA;AAC9C,MAAO,MAAA,CAAA,GAAG,CAAI,GAAA,uBAAA,CAAwB,KAAK,CAAA;AAAA;AAE7C,IAAO,OAAA,MAAA;AAAA;AAET,EAAO,OAAA,GAAA;AACT;
|
|
1
|
+
{"version":3,"file":"serializeUserOptions.js","sources":["../../../plugin/helpers/serializeUserOptions.ts"],"sourcesContent":["import type { ResolvedConfig, ViteDevServer } from \"vite\";\nimport type {\n AutoDiscoveredFiles,\n ResolvedUserOptions,\n} from \"../types.js\";\nimport { cleanObject } from \"./cleanObject.js\";\n\n// Common non-serializable functions in Vite's resolved config\nconst VITE_NON_SERIALIZABLE_FUNCTIONS = new Set([\n \"renderChunk\",\n \"buildStart\",\n \"buildEnd\",\n \"watchChange\",\n \"resolveId\",\n \"config\",\n \"output[].entryFileNames\",\n \"output[].chunkFileNames\",\n \"output[].assetFileNames\",\n \"transform\",\n \"handler\",\n \"configureServer\",\n \"shouldTransformCachedModule\",\n \"generateBundle\",\n \"renderStart\",\n \"writeBundle\",\n \"hotUpdate\",\n \"configResolved\",\n \"configurePreviewServer\",\n \"handleHotUpdate\",\n \"load\",\n \"augmentChunkHash\",\n \"closeBundle\",\n \"entryFileNames\",\n \"assetFileNames\",\n \"chunkFileNames\",\n \"createEnvironment\",\n \"sourcemapIgnoreList\",\n \"assetsInclude\",\n \"info\",\n \"warn\",\n \"warnOnce\",\n \"error\",\n \"clearScreen\",\n \"hasErrorLogged\",\n \"set\",\n \"plugins\",\n \"getSortedPlugins\",\n \"getSortedPluginHooks\",\n \"createResolver\",\n \"fsDenyGlob\",\n // Nested plugin functions\n \"plugins[].renderChunk\",\n \"plugins[].buildStart\",\n \"plugins[].buildEnd\",\n \"plugins[].watchChange\",\n \"plugins[].resolveId\",\n \"plugins[].config\",\n \"plugins[].transform\",\n \"plugins[].handler\",\n \"plugins[].configureServer\",\n \"plugins[].shouldTransformCachedModule\",\n \"plugins[].generateBundle\",\n \"plugins[].renderStart\",\n \"plugins[].writeBundle\",\n \"plugins[].hotUpdate\",\n \"plugins[].configResolved\",\n \"plugins[].configurePreviewServer\",\n \"plugins[].handleHotUpdate\",\n \"plugins[].load\",\n \"plugins[].augmentChunkHash\",\n \"plugins[].closeBundle\",\n \"plugins[].entryFileNames\",\n \"plugins[].assetFileNames\",\n \"plugins[].chunkFileNames\",\n \"plugins[].createEnvironment\",\n \"plugins[].sourcemapIgnoreList\",\n \"plugins[].assetsInclude\",\n]);\n\n// Common non-serializable functions in our plugin's options\nconst PLUGIN_NON_SERIALIZABLE_FUNCTIONS = new Set([\n \"Page\",\n \"props\",\n \"normalizer\",\n \"CssCollector\",\n \"Html\",\n \"onEvent\",\n \"onMetrics\",\n \"build.entryFile\",\n \"build.chunkFile\",\n \"build.assetFile\",\n \"build.pages\",\n \"autoDiscover\",\n]);\n\n// Helper function to serialize RegExp objects\nfunction serializeRegExp(regex: RegExp) {\n return {\n source: regex.source,\n flags: regex.flags,\n __isRegExp: true\n };\n}\n\n// Helper function to deserialize RegExp objects\nexport function deserializeRegExp(obj: any): any {\n if (obj && obj.__isRegExp) {\n return new RegExp(obj.source, obj.flags);\n }\n if (Array.isArray(obj)) {\n return obj.map(deserializeRegExp);\n }\n if (obj && typeof obj === 'object') {\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = deserializeRegExp(value);\n }\n return result;\n }\n return obj;\n}\n\n// Helper function to recursively process objects for serialization\nexport function processForSerialization(obj: any): any {\n if (obj instanceof RegExp) {\n return serializeRegExp(obj);\n }\n if (Array.isArray(obj)) {\n return obj.map(processForSerialization);\n }\n if (obj && typeof obj === 'object') {\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = processForSerialization(value);\n }\n return result;\n }\n return obj;\n}\n\nexport function serializeResolvedConfig<T extends ResolvedConfig>(\n config: T,\n knownNonSerializableFunctions: Set<string> = VITE_NON_SERIALIZABLE_FUNCTIONS\n) {\n const {\n getSortedPluginHooks,\n getSortedPlugins,\n assetsInclude,\n // extract known vite function properties\n ...handlerOptions\n } = config;\n\n // Clean the object to remove non-serializable properties and process RegExp objects\n return processForSerialization(cleanObject(handlerOptions, knownNonSerializableFunctions));\n}\n\n// For Vite's config\nexport const serializedDevServerConfig = <T extends ViteDevServer[\"config\"]>(\n config: T,\n customNonSerializableFunctions: Set<string> = PLUGIN_NON_SERIALIZABLE_FUNCTIONS\n) => {\n const {\n getSortedPluginHooks,\n getSortedPlugins,\n assetsInclude,\n build,\n ...handlerOptions\n } = config;\n return processForSerialization(cleanObject(\n handlerOptions,\n customNonSerializableFunctions\n ));\n};\n\n// For your own options (if you need custom non-serializable functions)\nexport const serializedOptions = <T extends ResolvedUserOptions>(\n userOptions: T,\n autoDiscoveredFiles: AutoDiscoveredFiles,\n customNonSerializableFunctions: Set<string> = PLUGIN_NON_SERIALIZABLE_FUNCTIONS\n) => {\n const {\n Page,\n props,\n normalizer,\n CssCollector,\n Html,\n onEvent,\n onMetrics,\n build,\n autoDiscover,\n ...handlerOptions\n } = userOptions;\n const { entryFile, chunkFile, assetFile, pages, ...buildOptions } = build;\n const result = {\n ...handlerOptions,\n build: {\n ...buildOptions,\n pages: autoDiscoveredFiles\n ? Array.from(autoDiscoveredFiles.urlMap.keys())\n : [],\n },\n };\n\n // Clean the object to remove non-serializable properties and process RegExp objects\n return processForSerialization(cleanObject(\n result,\n customNonSerializableFunctions\n ));\n};\n"],"names":[],"mappings":";;;;;;;AAQA,MAAM,+BAAA,uBAAsC,GAAI,CAAA;AAAA,EAC9C,aAAA;AAAA,EACA,YAAA;AAAA,EACA,UAAA;AAAA,EACA,aAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA,yBAAA;AAAA,EACA,yBAAA;AAA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,EAAO,sBACH,KAAM,CAAA,IAAA,CAAK,oBAAoB,MAAO,CAAA,IAAA,EAAM,CAAA,GAC5C;AAAC;AACP,GACF;AAGA,EAAA,OAAO,uBAAwB,CAAA,WAAA;AAAA,IAC7B,MAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css-loader.development.d.ts","sourceRoot":"","sources":["../../../plugin/loader/css-loader.development.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"css-loader.development.d.ts","sourceRoot":"","sources":["../../../plugin/loader/css-loader.development.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAQvE;;;GAGG;AACH,eAAO,IAAI,UAAU,EAAE,WAAW,GAAG,SAAS,CAAC;AAY/C;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,cAAc,EAAE,oBAAoB,CAAA;CAAE,iBAIjG;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,QAEjD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzD;AA2DD;;;;;;;;;GASG;AACH,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,eAAe,GAAG,aAAa,GAAG;IAAE,cAAc,EAAE,oBAAoB,CAAA;CAAE,EACnF,WAAW,EAAE,GAAG,gBAQjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,OAE3E"}
|
|
@@ -8,18 +8,12 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
import { preprocessCSS } from 'vite';
|
|
9
9
|
import { readFile } from 'node:fs/promises';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
|
+
import { env } from '../utils/env.js';
|
|
11
12
|
|
|
12
13
|
let loaderPort;
|
|
13
14
|
const cssFilesByPage = /* @__PURE__ */ new Map();
|
|
14
15
|
let currentPage = null;
|
|
15
16
|
let resolvedConfig;
|
|
16
|
-
const env = import.meta?.env || {
|
|
17
|
-
BASE_URL: "/",
|
|
18
|
-
DEV: true,
|
|
19
|
-
MODE: "development",
|
|
20
|
-
PROD: false,
|
|
21
|
-
SSR: true
|
|
22
|
-
};
|
|
23
17
|
async function initialize(data) {
|
|
24
18
|
loaderPort = data.port;
|
|
25
19
|
resolvedConfig = data.resolvedConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css-loader.development.js","sources":["../../../plugin/loader/css-loader.development.ts"],"sourcesContent":["import { type MessagePort } from \"node:worker_threads\";\nimport type { LoadHookContext } from \"node:module\";\nimport type { LoaderContext, SerializedUserConfig } from \"../types.js\";\nimport { fileURLToPath } from \"node:url\";\nimport { preprocessCSS } from \"vite\";\nimport type { ResolvedConfig } from \"vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\n/**\n * Global port for communication between the main thread and the CSS loader.\n * This port is used to send CSS file requests and receive responses.\n */\nexport let loaderPort: MessagePort | undefined;\n\n/**\n * Tracks CSS files used by each page.\n * Maps page URLs to sets of CSS file paths that are used by that page.\n */\nconst cssFilesByPage = new Map<string, Set<string>>();\n\nlet currentPage: string | null = null;\nlet resolvedConfig: ResolvedConfig | undefined;\n
|
|
1
|
+
{"version":3,"file":"css-loader.development.js","sources":["../../../plugin/loader/css-loader.development.ts"],"sourcesContent":["import { type MessagePort } from \"node:worker_threads\";\nimport type { LoadHookContext } from \"node:module\";\nimport type { LoaderContext, SerializedUserConfig } from \"../types.js\";\nimport { fileURLToPath } from \"node:url\";\nimport { preprocessCSS } from \"vite\";\nimport type { ResolvedConfig } from \"vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { env } from \"../utils/env.js\";\n\n/**\n * Global port for communication between the main thread and the CSS loader.\n * This port is used to send CSS file requests and receive responses.\n */\nexport let loaderPort: MessagePort | undefined;\n\n/**\n * Tracks CSS files used by each page.\n * Maps page URLs to sets of CSS file paths that are used by that page.\n */\nconst cssFilesByPage = new Map<string, Set<string>>();\n\nlet currentPage: string | null = null;\nlet resolvedConfig: ResolvedConfig | undefined;\n\n\n/**\n * Initializes the CSS loader with the necessary communication channels.\n * Sets up message handlers for CSS file requests and responses.\n *\n * @param data - Configuration data for the CSS loader\n * @param data.port - The message port for communication\n */\nexport async function initialize(data: { port: MessagePort, resolvedConfig: SerializedUserConfig }) {\n loaderPort = data.port;\n resolvedConfig = data.resolvedConfig;\n data.port.postMessage({ type: \"INITIALIZED_CSS_LOADER\" });\n}\n\n/**\n * Sets the current page being processed.\n * Used to track which CSS files are associated with which pages.\n *\n * @param page - The URL of the current page, or null if no page is active\n */\nexport function setCurrentPage(page: string | null) {\n currentPage = page;\n}\n\n/**\n * Retrieves all CSS files associated with a specific page.\n *\n * @param page - The URL of the page\n * @returns An array of CSS file paths used by the page\n */\nexport function getCssFilesForPage(page: string): string[] {\n return Array.from(cssFilesByPage.get(page) || []);\n}\n\n/**\n * Processes a CSS file request.\n * Sends a request to the main thread and waits for the processed CSS.\n *\n * @param filePath - The file system path of the CSS file\n * @param config - The Vite config\n * @returns A promise that resolves to the processed CSS content\n */\nasync function processCssFile(\n filePath: string,\n config: ResolvedConfig,\n inline: boolean\n): Promise<{ format: string; source: string; shortCircuit: boolean }> {\n try {\n // Convert file URL to path if needed\n const path = filePath.startsWith(\"file://\")\n ? fileURLToPath(filePath)\n : filePath;\n\n // Process CSS using Vite's preprocessCSS\n const source = await readFile(path, \"utf-8\");\n const processed = await preprocessCSS(source, path, {\n ...config,\n env: env\n });\n\n // If we're processing CSS for a specific page, notify the message handler\n if (loaderPort) {\n loaderPort.postMessage({\n type: \"CSS_FILE\",\n id: currentPage ? join(path, \"?page=\" + currentPage) : path,\n path: path,\n content: processed.code,\n modules: processed.modules || {},\n inline,\n });\n }\n\n // Return a module that can be used by React components\n if (inline) {\n return {\n format: \"module\",\n source: processed.code,\n shortCircuit: true,\n };\n }\n return {\n format: \"module\",\n source: `export default ${JSON.stringify(processed.modules || {})};`,\n shortCircuit: true,\n };\n } catch (error) {\n console.error(`[css-loader] Error processing CSS file: ${error}`);\n throw error;\n }\n}\n\n/**\n * Vite's load hook implementation for CSS files.\n * Handles CSS file loading requests and returns a placeholder module.\n * The actual CSS content is processed in the main thread.\n *\n * @param url - The URL of the module to load\n * @param context - The load hook context\n * @param defaultLoad - The default load function\n * @returns A promise that resolves to the module content\n */\nexport async function load(\n url: string,\n context: LoadHookContext & LoaderContext & { resolvedConfig: SerializedUserConfig },\n defaultLoad: any\n) {\n const [name, query] = url.split(\"?\");\n if (name.endsWith(\".css\")) {\n return processCssFile(url, resolvedConfig as ResolvedConfig, query === \"inline\");\n }\n\n return defaultLoad(url, context, defaultLoad);\n}\n\n/**\n * Vite's resolve hook implementation.\n * Handles module resolution during development.\n *\n * @param specifier - The module specifier to resolve\n * @param context - The resolve hook context\n * @param defaultResolve - The default resolve function\n * @returns A promise that resolves to the resolved module\n */\nexport function resolve(specifier: string, context: any, defaultResolve: any) {\n return defaultResolve(specifier, context, defaultResolve);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAcW,IAAA;AAMX,MAAM,cAAA,uBAAqB,GAAyB,EAAA;AAEpD,IAAI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AAQ,SAAU,CAAA,IAAA;AAAA,QAClB,YAAc,EAAA;AAAA,OAChB;AAAA;AAEF,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA,QAAA;AAAA,MACR,MAAA,EAAQ,kBAAkB,IAAK,CAAA,SAAA,CAAU,UAAU,OAAW,IAAA,EAAE,CAAC,CAAA,CAAA,CAAA;AAAA,MACjE,YAAc,EAAA;AAAA,KAChB;AAAA,WACO,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,CAA2C,wCAAA,EAAA,KAAK,CAAE,CAAA,CAAA;AAChE,IAAM,MAAA,KAAA;AAAA;AAEV;AAYA,eAAsB,IAAA,CACpB,GACA,EAAA,OAAA,EACA,WACA,EAAA;AACA,EAAA,MAAM,CAAC,IAAM,EAAA,KAAK,CAAI,GAAA,GAAA,CAAI,MAAM,GAAG,CAAA;AACnC,EAAI,IAAA,IAAA,CAAK,QAAS,CAAA,MAAM,CAAG,EAAA;AACzB,IAAA,OAAO,cAAe,CAAA,GAAA,EAAK,cAAkC,EAAA,KAAA,KAAU,QAAQ,CAAA;AAAA;AAGjF,EAAO,OAAA,WAAA,CAAY,GAAK,EAAA,OAAA,EAAS,WAAW,CAAA;AAC9C;AAWO,SAAS,OAAA,CAAQ,SAAmB,EAAA,OAAA,EAAc,cAAqB,EAAA;AAC5E,EAAO,OAAA,cAAA,CAAe,SAAW,EAAA,OAAA,EAAS,cAAc,CAAA;AAC1D;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css-loader.production.js","sources":["../../../plugin/loader/css-loader.production.ts"],"sourcesContent":["import type { MessagePort } from \"node:worker_threads\";\nimport type { LoadHookContext } from \"node:module\";\nimport type { LoaderContext } from \"../types.js\";\nimport { fileURLToPath } from \"node:url\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * Global port for communication between the main thread and the CSS loader.\n * This port is used to send CSS file requests and receive responses.\n */\nexport let loaderPort: MessagePort | undefined;\n\nlet stashedCssFiles = new Map();\n\n/**\n * Initializes the CSS loader with the necessary communication channels.\n * Sets up message handlers for CSS file requests and responses.\n *\n * @param data - Configuration data for the CSS loader\n * @param data.port - The message port for communication\n * @param data.server - The Vite dev server instance\n */\nexport async function initialize(data: { port: MessagePort }) {\n loaderPort = data.port;\n data.port.postMessage({ type: \"INITIALIZED_CSS_LOADER\" });\n}\n\n/**\n * Processes a CSS file request.\n * Sends a request to the main thread and waits for the processed CSS.\n *\n * @param filePath - The file system path of the CSS file\n * @param config - The Vite config\n * @returns A promise that resolves to the processed CSS content\n */\nasync function processCssFile(\n filePath: string\n): Promise<{ format: string; source: string; shortCircuit: boolean }> {\n try {\n // Convert file URL to path if needed\n const path = filePath.startsWith(\"file://\")\n ? fileURLToPath(filePath)\n : filePath;\n if (stashedCssFiles.has(filePath)) {\n return {\n format: \"module\",\n source: stashedCssFiles.get(filePath),\n shortCircuit: true,\n };\n }\n // Process CSS using Vite's preprocessCSS\n const source = await readFile(path, \"utf-8\");\n stashedCssFiles.set(path, source);\n return {\n format: \"module\",\n source: source,\n shortCircuit: true,\n };\n } catch (error) {\n throw error;\n }\n}\n\n/**\n * Vite's load hook implementation for CSS files.\n * Handles CSS file loading requests and returns a placeholder module.\n * The actual CSS content is processed in the main thread.\n *\n * @param url - The URL of the module to load\n * @param context - The load hook context\n * @param defaultLoad - The default load function\n * @returns A promise that resolves to the module content\n */\nexport async function load(\n url: string,\n context: LoadHookContext & LoaderContext,\n defaultLoad: any\n) {\n // Handle CSS files\n const [name] = url.split(\"?\");\n if (name.endsWith(\".css\")) {\n return processCssFile(url);\n }\n\n return defaultLoad(url, context, defaultLoad);\n}\n"],"names":[],"mappings":";;;;;;;;AAUW,IAAA;AAEX,IAAI,eAAA,uBAAsB,GAAI,EAAA;AAU9B,eAAsB,WAAW,IAA6B,EAAA;AAC5D,EAAA,UAAA,GAAa,IAAK,CAAA,IAAA;AAClB,EAAA,IAAA,CAAK,IAAK,CAAA,WAAA,CAAY,EAAE,IAAA,EAAM,0BAA0B,CAAA;AAC1D;AAUA,eAAe,eACb,QACoE,EAAA;AACpE,EAAI,IAAA;AAEF,IAAA,MAAM,OAAO,QAAS,CAAA,UAAA,CAAW,SAAS,CACtC,GAAA,aAAA,CAAc,QAAQ,CACtB,GAAA,QAAA;AACJ,IAAI,IAAA,eAAA,CAAgB,GAAI,CAAA,QAAQ,CAAG,EAAA;AACjC,MAAO,OAAA;AAAA,QACL,MAAQ,EAAA,QAAA;AAAA,QACR,MAAA,EAAQ,eAAgB,CAAA,GAAA,CAAI,QAAQ,CAAA;AAAA,QACpC,YAAc,EAAA;AAAA,OAChB;AAAA;AAGF,IAAA,MAAM,MAAS,GAAA,MAAM,QAAS,CAAA,IAAA,EAAM,OAAO,CAAA;AAC3C,IAAgB,eAAA,CAAA,GAAA,CAAI,MAAM,MAAM,CAAA;AAChC,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA,QAAA;AAAA,MACR,MAAA;AAAA,MACA,YAAc,EAAA;AAAA,KAChB;AAAA,WACO,KAAO,EAAA;AACd,IAAM,MAAA,KAAA;AAAA;AAEV;
|
|
1
|
+
{"version":3,"file":"css-loader.production.js","sources":["../../../plugin/loader/css-loader.production.ts"],"sourcesContent":["import type { MessagePort } from \"node:worker_threads\";\nimport type { LoadHookContext } from \"node:module\";\nimport type { LoaderContext } from \"../types.js\";\nimport { fileURLToPath } from \"node:url\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * Global port for communication between the main thread and the CSS loader.\n * This port is used to send CSS file requests and receive responses.\n */\nexport let loaderPort: MessagePort | undefined;\n\nlet stashedCssFiles = new Map();\n\n/**\n * Initializes the CSS loader with the necessary communication channels.\n * Sets up message handlers for CSS file requests and responses.\n *\n * @param data - Configuration data for the CSS loader\n * @param data.port - The message port for communication\n * @param data.server - The Vite dev server instance\n */\nexport async function initialize(data: { port: MessagePort }) {\n loaderPort = data.port;\n data.port.postMessage({ type: \"INITIALIZED_CSS_LOADER\" });\n}\n\n/**\n * Processes a CSS file request.\n * Sends a request to the main thread and waits for the processed CSS.\n *\n * @param filePath - The file system path of the CSS file\n * @param config - The Vite config\n * @returns A promise that resolves to the processed CSS content\n */\nasync function processCssFile(\n filePath: string\n): Promise<{ format: string; source: string; shortCircuit: boolean }> {\n try {\n // Convert file URL to path if needed\n const path = filePath.startsWith(\"file://\")\n ? fileURLToPath(filePath)\n : filePath;\n if (stashedCssFiles.has(filePath)) {\n return {\n format: \"module\",\n source: stashedCssFiles.get(filePath),\n shortCircuit: true,\n };\n }\n // Process CSS using Vite's preprocessCSS\n const source = await readFile(path, \"utf-8\");\n stashedCssFiles.set(path, source);\n return {\n format: \"module\",\n source: source,\n shortCircuit: true,\n };\n } catch (error) {\n throw error;\n }\n}\n\n/**\n * Vite's load hook implementation for CSS files.\n * Handles CSS file loading requests and returns a placeholder module.\n * The actual CSS content is processed in the main thread.\n *\n * @param url - The URL of the module to load\n * @param context - The load hook context\n * @param defaultLoad - The default load function\n * @returns A promise that resolves to the module content\n */\nexport async function load(\n url: string,\n context: LoadHookContext & LoaderContext,\n defaultLoad: any\n) {\n // Handle CSS files\n const [name] = url.split(\"?\");\n if (name.endsWith(\".css\")) {\n return processCssFile(url);\n }\n\n return defaultLoad(url, context, defaultLoad);\n}\n"],"names":[],"mappings":";;;;;;;;AAUW,IAAA;AAEX,IAAI,eAAA,uBAAsB,GAAI,EAAA;AAU9B,eAAsB,WAAW,IAA6B,EAAA;AAC5D,EAAA,UAAA,GAAa,IAAK,CAAA,IAAA;AAClB,EAAA,IAAA,CAAK,IAAK,CAAA,WAAA,CAAY,EAAE,IAAA,EAAM,0BAA0B,CAAA;AAC1D;AAUA,eAAe,eACb,QACoE,EAAA;AACpE,EAAI,IAAA;AAEF,IAAA,MAAM,OAAO,QAAS,CAAA,UAAA,CAAW,SAAS,CACtC,GAAA,aAAA,CAAc,QAAQ,CACtB,GAAA,QAAA;AACJ,IAAI,IAAA,eAAA,CAAgB,GAAI,CAAA,QAAQ,CAAG,EAAA;AACjC,MAAO,OAAA;AAAA,QACL,MAAQ,EAAA,QAAA;AAAA,QACR,MAAA,EAAQ,eAAgB,CAAA,GAAA,CAAI,QAAQ,CAAA;AAAA,QACpC,YAAc,EAAA;AAAA,OAChB;AAAA;AAGF,IAAA,MAAM,MAAS,GAAA,MAAM,QAAS,CAAA,IAAA,EAAM,OAAO,CAAA;AAC3C,IAAgB,eAAA,CAAA,GAAA,CAAI,MAAM,MAAM,CAAA;AAChC,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA,QAAA;AAAA,MACR,MAAA;AAAA,MACA,YAAc,EAAA;AAAA,KAChB;AAAA,WACO,KAAO,EAAA;AACd,IAAM,MAAA,KAAA;AAAA;AAEV;AAYA,eAAsB,IAAA,CACpB,GACA,EAAA,OAAA,EACA,WACA,EAAA;AAEA,EAAA,MAAM,CAAC,IAAI,CAAI,GAAA,GAAA,CAAI,MAAM,GAAG,CAAA;AAC5B,EAAI,IAAA,IAAA,CAAK,QAAS,CAAA,MAAM,CAAG,EAAA;AACzB,IAAA,OAAO,eAAe,GAAG,CAAA;AAAA;AAG3B,EAAO,OAAA,WAAA,CAAY,GAAK,EAAA,OAAA,EAAS,WAAW,CAAA;AAC9C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-loader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/react-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"react-loader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/react-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAcjD,eAAO,IAAI,UAAU,EAAE,WAAW,GAAG,SAAS,CAAC;AAI/C,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,GAAG,EACZ,gBAAgB,EAAE,GAAG,gBAKtB;AA0mBD,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,CAAC,EAAE,WAAW,0BAuDnB;AA4KD,wBAAsB,UAAU,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,iBAI3D;AAGD,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,EAC3B,WAAW,EAAE,GAAG,gBAGjB;AAGD,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,eAAe,GAAG,aAAa,EACxC,QAAQ,EAAE,GAAG,gBA0Dd;AAGD,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,GAAG,EACZ,sBAAsB,EAAE,GAAG,gBAkC5B"}
|