vite-plugin-react-server 0.3.11 → 0.3.12
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/package.json +15 -11
- package/dist/plugin/checkFilesExist.d.ts +2 -2
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +39 -57
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/collect-css-manifest.d.ts.map +1 -1
- package/dist/plugin/collect-css-manifest.js +5 -0
- package/dist/plugin/collect-css-manifest.js.map +1 -1
- package/dist/plugin/components.js +10 -15
- package/dist/plugin/config/createModuleIdGenerator.js +1 -1
- package/dist/plugin/config/createModuleIdGenerator.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +5 -14
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +12 -12
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.js +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +73 -52
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +53 -65
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +6 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +48 -19
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts +1 -2
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +52 -46
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +29 -26
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.d.ts +16 -0
- package/dist/plugin/loader/css-loader.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.js +70 -0
- package/dist/plugin/loader/css-loader.js.map +1 -0
- package/dist/plugin/loader/react-loader.d.ts +17 -0
- package/dist/plugin/loader/react-loader.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.js +647 -0
- package/dist/plugin/loader/react-loader.js.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts +2 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.js +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +2 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.js +1 -0
- package/dist/plugin/react-client/index.js +2 -2
- package/dist/plugin/react-client/index.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +202 -25
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +10 -4
- package/dist/plugin/react-server/createHandler.js.map +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts +15 -3
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
- package/dist/plugin/react-server/createRscStream.js +52 -49
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +24 -20
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +65 -52
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/types.d.ts +5 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/logger.d.ts +9 -0
- package/dist/plugin/utils/logger.d.ts.map +1 -0
- package/dist/plugin/utils/logger.js +68 -0
- package/dist/plugin/utils/logger.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +1 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +23 -36
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +5 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +10 -19
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/renderPages.d.ts +2 -2
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +130 -131
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/rsc/index.d.ts +1 -3
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/index.js +1 -9
- package/dist/plugin/worker/rsc/index.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +3 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.js +107 -0
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -0
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/plugin.js +74 -80
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +32 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js +43 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.js +4 -106
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts +2 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js +14 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -0
- package/dist/plugin/worker/rsc/state.d.ts +11 -0
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/state.js +12 -0
- package/dist/plugin/worker/rsc/state.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +60 -46
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -11
- package/plugin/checkFilesExist.ts +42 -62
- package/plugin/collect-css-manifest.ts +5 -1
- package/plugin/config/createModuleIdGenerator.ts +1 -1
- package/plugin/config/defaults.ts +13 -15
- package/plugin/config/resolveOptions.ts +134 -76
- package/plugin/config/resolveUserConfig.ts +75 -76
- package/plugin/helpers/getBundleManifest.ts +69 -31
- package/plugin/helpers/inputNormalizer.ts +82 -70
- package/plugin/helpers/tryManifest.ts +1 -1
- package/plugin/loader/createBuildLoader.ts +38 -41
- package/plugin/loader/css-loader.ts +96 -0
- package/plugin/loader/react-loader.ts +945 -0
- package/plugin/loader/rsc/messageHandler.tsx +1 -0
- package/plugin/loader/rsc/rsc-worker.development.ts +1 -0
- package/plugin/react-client/index.ts +1 -1
- package/plugin/react-client/plugin.ts +266 -41
- package/plugin/react-server/createHandler.ts +9 -5
- package/plugin/react-server/createRscStream.ts +75 -54
- package/plugin/react-server/plugin.ts +26 -21
- package/plugin/transformer/plugin.ts +67 -76
- package/plugin/types/global.d.ts +8 -0
- package/plugin/types.ts +2 -0
- package/plugin/utils/logger.ts +52 -0
- package/plugin/worker/createWorker.ts +43 -44
- package/plugin/worker/html/html-worker.production.tsx +7 -2
- package/plugin/worker/html/messageHandler.ts +13 -21
- package/plugin/worker/html/renderPages.ts +146 -179
- package/plugin/worker/rsc/index.ts +4 -13
- package/plugin/worker/rsc/messageHandler.tsx +143 -0
- package/plugin/worker/rsc/plugin.ts +38 -37
- package/plugin/worker/rsc/rsc-worker.development.ts +107 -0
- package/plugin/worker/rsc/rsc-worker.production.ts +13 -0
- package/plugin/worker/rsc/rsc-worker.tsx +5 -128
- package/plugin/worker/rsc/state.ts +37 -0
- package/plugin/worker/types.ts +79 -55
- package/scripts/check-react-version.mjs +17 -7
- package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +143 -4170
- package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +14271 -90079
- package/dist/plugin/components.js.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts +0 -8
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.js +0 -35
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts +0 -9
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createServerInputNormalizer.js +0 -37
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +0 -7
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createStaticInputNormalizer.js +0 -18
- package/dist/plugin/helpers/getModuleManifest.d.ts +0 -17
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js +0 -23
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -12
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +0 -33
- package/dist/plugin/helpers/normalizedRelativePath.d.ts +0 -11
- package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +0 -1
- package/dist/plugin/helpers/normalizedRelativePath.js +0 -36
- package/dist/plugin/helpers/resolveFilePath.d.ts +0 -13
- package/dist/plugin/helpers/resolveFilePath.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveFilePath.js +0 -74
- package/dist/plugin/helpers/resolveWorkerModule.d.ts +0 -6
- package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveWorkerModule.js +0 -24
- package/dist/plugin/helpers/validateModuleBase.d.ts +0 -3
- package/dist/plugin/helpers/validateModuleBase.d.ts.map +0 -1
- package/dist/plugin/helpers/validateModuleBase.js +0 -16
- package/dist/plugin/helpers/validateResolvedConfig.d.ts +0 -3
- package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +0 -1
- package/dist/plugin/helpers/validateResolvedConfig.js +0 -17
- package/dist/plugin/transformer/transformer-client-components.d.ts +0 -30
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-client-components.js +0 -122
- package/dist/plugin/transformer/transformer-client-components.js.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.d.ts +0 -29
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.js +0 -90
- package/dist/plugin/worker/rsc/createRscStream.d.ts +0 -5
- package/dist/plugin/worker/rsc/createRscStream.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/createRscStream.js +0 -39
- package/dist/plugin/worker/rsc/createRscStream.js.map +0 -1
- package/dist/plugin/worker/rsc/development.d.ts +0 -5
- package/dist/plugin/worker/rsc/development.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/development.js +0 -13
- package/dist/plugin/worker/rsc/development.js.map +0 -1
- package/dist/plugin/worker/rsc/plugin.js.map +0 -1
- package/dist/plugin/worker/rsc/production.d.ts +0 -5
- package/dist/plugin/worker/rsc/production.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/production.js +0 -13
- package/dist/plugin/worker/rsc/production.js.map +0 -1
- package/plugin/helpers/createClientInputNormalizer.ts +0 -48
- package/plugin/helpers/createServerInputNormalizer.ts +0 -52
- package/plugin/helpers/createStaticInputNormalizer.ts +0 -26
- package/plugin/helpers/getModuleManifest.ts +0 -36
- package/plugin/helpers/inputNormalizerWorker.ts +0 -52
- package/plugin/helpers/normalizedRelativePath.ts +0 -59
- package/plugin/helpers/resolveFilePath.ts +0 -108
- package/plugin/helpers/resolveWorkerModule.ts +0 -41
- package/plugin/helpers/validateModuleBase.ts +0 -30
- package/plugin/helpers/validateResolvedConfig.ts +0 -21
- package/plugin/transformer/transformer-client-components.ts +0 -168
- package/plugin/transformer/transformer-server-actions.ts +0 -125
- package/plugin/worker/rsc/createRscStream.ts +0 -42
- package/plugin/worker/rsc/development.ts +0 -6
- package/plugin/worker/rsc/production.ts +0 -6
- package/scripts/react-server-dom-esm+0.0.1.patch +0 -24775
|
@@ -4,39 +4,68 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*/
|
|
6
6
|
import { createInputNormalizer } from './inputNormalizer.js';
|
|
7
|
-
import
|
|
7
|
+
import 'path';
|
|
8
|
+
import { DEFAULT_CONFIG } from '../config/defaults.js';
|
|
8
9
|
|
|
9
|
-
function getBundleManifest(
|
|
10
|
+
function getBundleManifest({
|
|
11
|
+
pluginContext,
|
|
12
|
+
bundle,
|
|
13
|
+
moduleBase,
|
|
14
|
+
preserveModulesRoot
|
|
15
|
+
}) {
|
|
10
16
|
const normalizer = createInputNormalizer({
|
|
11
17
|
root: pluginContext.environment.config.root,
|
|
12
|
-
removeExtension:
|
|
13
|
-
preserveModulesRoot: undefined
|
|
18
|
+
removeExtension: DEFAULT_CONFIG.FILE_REGEX,
|
|
19
|
+
preserveModulesRoot: preserveModulesRoot === true ? moduleBase : undefined
|
|
14
20
|
});
|
|
15
|
-
if (!bundle) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return Object.fromEntries(
|
|
21
|
+
if (!bundle) return {};
|
|
22
|
+
const virtualModules = /* @__PURE__ */ new Map();
|
|
23
|
+
const bundleManifest = Object.fromEntries(
|
|
19
24
|
Object.entries(bundle).map(([fileName, chunk]) => {
|
|
20
25
|
if (chunk.type !== "chunk") return null;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
const chunkWithFacade = chunk;
|
|
27
|
+
const moduleId = chunkWithFacade.facadeModuleId || chunkWithFacade.moduleIds[0] || fileName;
|
|
28
|
+
if (moduleId.includes("commonjsHelpers")) {
|
|
29
|
+
return [
|
|
30
|
+
moduleId,
|
|
31
|
+
{
|
|
32
|
+
file: "commonjs-runtime.js",
|
|
33
|
+
name: "commonjsHelpers",
|
|
34
|
+
src: moduleId,
|
|
35
|
+
isEntry: false
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
const [normalizedId, sourcePath] = normalizer(moduleId);
|
|
40
|
+
let finalFileName = fileName;
|
|
41
|
+
if (moduleId.includes("?")) {
|
|
42
|
+
const [basePath, query] = moduleId.split("?");
|
|
43
|
+
const virtualPath = basePath.includes("node_modules") ? basePath.split("node_modules/")[1] : basePath;
|
|
44
|
+
const virtualKey = `${virtualPath}?${query}`;
|
|
45
|
+
if (!virtualModules.has(virtualKey)) {
|
|
46
|
+
const virtualFileName = `${virtualPath.replace(/\.js$/, "")}.${query}.js`;
|
|
47
|
+
virtualModules.set(virtualKey, virtualFileName);
|
|
48
|
+
}
|
|
49
|
+
finalFileName = virtualModules.get(virtualKey);
|
|
50
|
+
}
|
|
51
|
+
const bundleManifestEntry = [
|
|
52
|
+
sourcePath,
|
|
26
53
|
{
|
|
27
|
-
file:
|
|
28
|
-
name:
|
|
29
|
-
src: sourcePath.startsWith(
|
|
54
|
+
file: finalFileName,
|
|
55
|
+
name: normalizedId.startsWith("\0") ? normalizedId.replace("\0", "") : normalizedId,
|
|
56
|
+
src: sourcePath.startsWith("/") ? sourcePath.slice(1) : sourcePath,
|
|
30
57
|
isEntry: chunk.isEntry,
|
|
31
|
-
...
|
|
32
|
-
...
|
|
33
|
-
...chunk.viteMetadata?.importedCss ? {
|
|
58
|
+
...chunk.imports?.length > 0 ? { imports: chunk.imports } : {},
|
|
59
|
+
...chunk.dynamicImports?.length > 0 ? { dynamicImports: chunk.dynamicImports } : {},
|
|
60
|
+
...chunk.viteMetadata?.importedCss?.size ? {
|
|
34
61
|
css: Array.from(chunk.viteMetadata.importedCss)
|
|
35
62
|
} : {}
|
|
36
63
|
}
|
|
37
64
|
];
|
|
65
|
+
return bundleManifestEntry;
|
|
38
66
|
}).filter(Boolean)
|
|
39
67
|
);
|
|
68
|
+
return bundleManifest;
|
|
40
69
|
}
|
|
41
70
|
|
|
42
71
|
export { getBundleManifest };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBundleManifest.js","sources":["../../../plugin/helpers/getBundleManifest.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"file":"getBundleManifest.js","sources":["../../../plugin/helpers/getBundleManifest.ts"],"sourcesContent":["import type {\n OutputBundle,\n PluginContext,\n OutputChunk,\n} from \"rollup\";\nimport { createInputNormalizer } from \"./inputNormalizer.js\";\nimport { join } from \"path\";\nimport { DEFAULT_CONFIG, resolveOptions } from \"../config/index.js\";\n\ninterface BundleManifestEntry {\n file: string;\n name: string;\n src?: string;\n isEntry?: boolean;\n imports?: string[];\n dynamicImports?: string[];\n css?: string[];\n}\n\n/**\n * Get the bundle manifest from the plugin context. Will only work during production build\n * @param pluginContext - The plugin context\n * @param bundle - The bundle\n * @param preserveModulesRoot - The preserve modules root\n * @returns The bundle manifest\n */\nexport function getBundleManifest({\n pluginContext,\n bundle,\n moduleBase,\n preserveModulesRoot,\n}: {\n pluginContext: PluginContext,\n bundle: OutputBundle,\n moduleBase?: string,\n preserveModulesRoot?: boolean,\n}): Record<string, BundleManifestEntry> {\n\n const normalizer = createInputNormalizer({\n root: pluginContext.environment.config.root,\n removeExtension: DEFAULT_CONFIG.FILE_REGEX,\n preserveModulesRoot: preserveModulesRoot === true ? moduleBase : undefined,\n });\n\n if (!bundle) return {};\n\n // Track virtual modules to prevent duplicates\n const virtualModules = new Map<string, string>();\n\n const bundleManifest = Object.fromEntries(\n Object.entries(bundle)\n .map(([fileName, chunk]) => {\n if (chunk.type !== \"chunk\") return null as never;\n const chunkWithFacade = chunk as OutputChunk;\n \n // Get the module ID, preferring facadeModuleId\n const moduleId = chunkWithFacade.facadeModuleId || chunkWithFacade.moduleIds[0] || fileName;\n \n // Handle commonjs helpers specially - must be done before normalization\n if (moduleId.includes('commonjsHelpers')) {\n return [\n moduleId,\n {\n file: 'commonjs-runtime.js',\n name: 'commonjsHelpers',\n src: moduleId,\n isEntry: false\n }\n ];\n }\n \n // Normalize both paths, removing the root prefix\n const [normalizedId, sourcePath] = normalizer(moduleId);\n\n // For virtual modules, use a consistent naming scheme\n let finalFileName = fileName;\n if (moduleId.includes('?')) {\n const [basePath, query] = moduleId.split('?');\n const virtualPath = basePath.includes('node_modules') \n ? basePath.split('node_modules/')[1] \n : basePath;\n \n // Create a unique key for this virtual module\n const virtualKey = `${virtualPath}?${query}`;\n \n if (!virtualModules.has(virtualKey)) {\n // First time seeing this virtual module\n const virtualFileName = `${virtualPath.replace(/\\.js$/, '')}.${query}.js`;\n virtualModules.set(virtualKey, virtualFileName);\n }\n \n finalFileName = virtualModules.get(virtualKey)!;\n }\n const bundleManifestEntry = [\n sourcePath,\n {\n file: finalFileName,\n name: normalizedId.startsWith('\\x00') ? normalizedId.replace('\\x00', '') : normalizedId,\n src: sourcePath.startsWith('/') ? sourcePath.slice(1) : sourcePath,\n isEntry: chunk.isEntry,\n ...(chunk.imports?.length > 0 ? { imports: chunk.imports } : {}),\n ...(chunk.dynamicImports?.length > 0 ? { dynamicImports: chunk.dynamicImports } : {}),\n ...(chunk.viteMetadata?.importedCss?.size ? {\n css: Array.from(chunk.viteMetadata.importedCss),\n } : {}),\n },\n ];\n return bundleManifestEntry;\n })\n .filter(Boolean)\n );\n return bundleManifest;\n}\n"],"names":[],"mappings":";;;;;;;;;AA0BO,SAAS,iBAAkB,CAAA;AAAA,EAChC,aAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA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AC5C;AAAC;AACP,OACF;AACA,MAAO,OAAA,mBAAA;AAAA,KACR,CACA,CAAA,MAAA,CAAO,OAAO;AAAA,GACnB;AACA,EAAO,OAAA,cAAA;AACT;;;;"}
|
|
@@ -3,7 +3,6 @@ type CreateInputNormalizerProps = {
|
|
|
3
3
|
root: string;
|
|
4
4
|
preserveModulesRoot?: string | undefined;
|
|
5
5
|
removeExtension?: boolean | RegExp | string | ((path: string) => boolean);
|
|
6
|
-
moduleBasePath?: string;
|
|
7
6
|
};
|
|
8
7
|
/**
|
|
9
8
|
* @description Create a function that normalizes the input
|
|
@@ -12,6 +11,6 @@ type CreateInputNormalizerProps = {
|
|
|
12
11
|
* @param removeExtension - Whether to remove the extension of the file
|
|
13
12
|
* @returns A function that normalizes the input
|
|
14
13
|
*/
|
|
15
|
-
export declare function createInputNormalizer({ root, preserveModulesRoot, removeExtension,
|
|
14
|
+
export declare function createInputNormalizer({ root, preserveModulesRoot, removeExtension, }: CreateInputNormalizerProps): InputNormalizer;
|
|
16
15
|
export {};
|
|
17
16
|
//# 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;AAIpE,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;AAIpE,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;CAC3E,CAAC;AAmHF;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,IAAI,EACJ,mBAA+B,EAC/B,eAA2C,GAC5C,EAAE,0BAA0B,GAAG,eAAe,CA8D9C"}
|
|
@@ -38,77 +38,76 @@ const resolveExtensionOptions = (removeExtension) => {
|
|
|
38
38
|
return (path) => path;
|
|
39
39
|
};
|
|
40
40
|
const resolveRootOption = (root, preserveModulesRoot) => {
|
|
41
|
-
if (typeof root !== "string" && typeof preserveModulesRoot !== "string") {
|
|
42
|
-
return "";
|
|
43
|
-
}
|
|
44
41
|
if (typeof preserveModulesRoot === "string" && typeof root === "string") {
|
|
45
|
-
const normalizedRoot = normalizePath(root);
|
|
46
42
|
const normalizedPreserveModulesRoot = normalizePath(preserveModulesRoot);
|
|
47
|
-
if (normalizedPreserveModulesRoot.startsWith(
|
|
48
|
-
return
|
|
43
|
+
if (normalizedPreserveModulesRoot.startsWith(root)) {
|
|
44
|
+
return normalizedPreserveModulesRoot.slice(root.length + 1);
|
|
49
45
|
}
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const normalizedRoot = normalizePath(root);
|
|
54
|
-
const normalizedPreserveModulesRoot = normalizePath(preserveModulesRoot);
|
|
55
|
-
if (normalizedRoot.startsWith(normalizedPreserveModulesRoot)) {
|
|
56
|
-
return join(normalizedPreserveModulesRoot, "/");
|
|
57
|
-
}
|
|
58
|
-
return join(normalizedRoot, normalizedPreserveModulesRoot, "/");
|
|
59
|
-
}
|
|
60
|
-
if (typeof preserveModulesRoot !== "string" && typeof root === "string") {
|
|
61
|
-
const normalizedRoot = normalizePath(root);
|
|
62
|
-
return join(normalizedRoot, "/");
|
|
46
|
+
return "";
|
|
47
|
+
} else if (typeof preserveModulesRoot === "string" && typeof root !== "string") {
|
|
48
|
+
return normalizePath(preserveModulesRoot);
|
|
63
49
|
}
|
|
64
|
-
return "
|
|
50
|
+
return "";
|
|
65
51
|
};
|
|
66
52
|
const createKeyNormalizer = ({
|
|
67
|
-
normalizedRoot,
|
|
53
|
+
root: normalizedRoot,
|
|
68
54
|
preserveModulesRoot,
|
|
69
55
|
handleExtension
|
|
70
56
|
}) => (key) => {
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
noRelativeNorAbsolute = noRelativeNorAbsolute.slice(1);
|
|
57
|
+
const virtualPrefix = key.match(/^\0+/)?.[0] || "";
|
|
58
|
+
const actualKey = key.slice(virtualPrefix.length);
|
|
59
|
+
let moduleId = normalizePath(actualKey);
|
|
60
|
+
if (moduleId.startsWith(normalizedRoot)) {
|
|
61
|
+
moduleId = moduleId.slice(normalizedRoot.length);
|
|
77
62
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
) ? noRelativeNorAbsolute.slice(preserveModulesRoot.length) : noRelativeNorAbsolute;
|
|
82
|
-
return removedModulesRoot.startsWith(normalizedRoot) ? removedModulesRoot.slice(normalizedRoot.length) : removedModulesRoot;
|
|
63
|
+
moduleId = handleExtension(moduleId);
|
|
64
|
+
while (moduleId.startsWith("/") || moduleId.startsWith(".")) {
|
|
65
|
+
moduleId = moduleId.slice(1);
|
|
83
66
|
}
|
|
84
|
-
|
|
67
|
+
while (moduleId.endsWith("/")) {
|
|
68
|
+
moduleId = moduleId.slice(0, -1);
|
|
69
|
+
}
|
|
70
|
+
if (typeof preserveModulesRoot === "string" && preserveModulesRoot !== "") {
|
|
71
|
+
moduleId = moduleId.startsWith(preserveModulesRoot) ? moduleId.slice(preserveModulesRoot.length) : moduleId;
|
|
72
|
+
}
|
|
73
|
+
return virtualPrefix + moduleId;
|
|
85
74
|
};
|
|
86
|
-
const createPathNormalizer = ({
|
|
75
|
+
const createPathNormalizer = ({
|
|
76
|
+
root,
|
|
77
|
+
preserveModulesRoot
|
|
78
|
+
}) => (path) => {
|
|
87
79
|
if (typeof path !== "string") {
|
|
88
80
|
throw new Error(`Invalid path: ${JSON.stringify(path)}`);
|
|
89
81
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
let normalPath = normalizePath(path);
|
|
83
|
+
if (normalPath.startsWith(root)) {
|
|
84
|
+
normalPath = normalPath.slice(root.length);
|
|
85
|
+
}
|
|
86
|
+
if (typeof preserveModulesRoot === "string" && preserveModulesRoot !== "") {
|
|
87
|
+
normalPath = normalPath.startsWith(preserveModulesRoot) ? normalPath.slice(preserveModulesRoot.length) : normalPath;
|
|
94
88
|
}
|
|
95
|
-
|
|
89
|
+
while (normalPath.endsWith("/")) {
|
|
90
|
+
normalPath = normalPath.slice(0, -1);
|
|
91
|
+
}
|
|
92
|
+
return normalPath;
|
|
96
93
|
};
|
|
97
94
|
function createInputNormalizer({
|
|
98
95
|
root,
|
|
99
96
|
preserveModulesRoot = undefined,
|
|
100
|
-
removeExtension = DEFAULT_CONFIG.FILE_REGEX
|
|
101
|
-
moduleBasePath = "/"
|
|
97
|
+
removeExtension = DEFAULT_CONFIG.FILE_REGEX
|
|
102
98
|
}) {
|
|
103
|
-
const
|
|
99
|
+
const relativeRoot = resolveRootOption(root, preserveModulesRoot);
|
|
104
100
|
const handleExtension = resolveExtensionOptions(removeExtension);
|
|
105
101
|
const normalizeEntryKey = createKeyNormalizer({
|
|
106
|
-
|
|
107
|
-
preserveModulesRoot,
|
|
102
|
+
root,
|
|
103
|
+
preserveModulesRoot: relativeRoot,
|
|
108
104
|
handleExtension
|
|
109
105
|
});
|
|
110
|
-
const normalizeEntryPath = createPathNormalizer({
|
|
111
|
-
|
|
106
|
+
const normalizeEntryPath = createPathNormalizer({
|
|
107
|
+
root,
|
|
108
|
+
preserveModulesRoot: relativeRoot
|
|
109
|
+
});
|
|
110
|
+
function normalizeInput(id) {
|
|
112
111
|
if (Array.isArray(id)) {
|
|
113
112
|
const [key, path] = id;
|
|
114
113
|
if (typeof key === "string" && Array.isArray(path) && path.length === 2) {
|
|
@@ -132,6 +131,13 @@ function createInputNormalizer({
|
|
|
132
131
|
return normalized;
|
|
133
132
|
}
|
|
134
133
|
throw new Error(`Invalid input type: ${typeof id}`);
|
|
134
|
+
}
|
|
135
|
+
return (input) => {
|
|
136
|
+
const [key, path] = normalizeInput(input);
|
|
137
|
+
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
138
|
+
const virtualPrefix = key.match(/^\0+/)?.[0] || "";
|
|
139
|
+
const finalPath = virtualPrefix ? normalizedPath.startsWith(virtualPrefix) ? normalizedPath : virtualPrefix + normalizedPath : normalizedPath;
|
|
140
|
+
return [key, finalPath];
|
|
135
141
|
};
|
|
136
142
|
}
|
|
137
143
|
|
|
@@ -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 { join } from \"path\";\nimport { DEFAULT_CONFIG } from \"../config/defaults.js\";\n\ntype CreateInputNormalizerProps = {\n root: string;\n preserveModulesRoot?: string | undefined;\n removeExtension?: boolean | RegExp | string | ((path: string) => boolean);\n moduleBasePath?: string;\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 root !== \"string\" && typeof preserveModulesRoot !== \"string\") {\n return \"\";\n }\n if (typeof preserveModulesRoot === \"string\" && typeof root === \"string\") {\n const normalizedRoot = normalizePath(root);\n const normalizedPreserveModulesRoot = normalizePath(preserveModulesRoot);\n if (normalizedPreserveModulesRoot.startsWith(normalizedRoot)) {\n return join(normalizedPreserveModulesRoot, \"/\");\n }\n return join(normalizedRoot, normalizedPreserveModulesRoot, \"/\");\n }\n if (typeof preserveModulesRoot === \"string\" && typeof root !== \"string\") {\n const normalizedRoot = normalizePath(root);\n const normalizedPreserveModulesRoot = normalizePath(preserveModulesRoot);\n if (normalizedRoot.startsWith(normalizedPreserveModulesRoot)) {\n return join(normalizedPreserveModulesRoot, \"/\");\n }\n return join(normalizedRoot, normalizedPreserveModulesRoot, \"/\");\n }\n if (typeof preserveModulesRoot !== \"string\" && typeof root === \"string\") {\n const normalizedRoot = normalizePath(root);\n return join(normalizedRoot, \"/\");\n }\n return \"/\";\n};\nconst createKeyNormalizer =\n ({\n normalizedRoot,\n preserveModulesRoot,\n handleExtension,\n }: {\n normalizedRoot: string;\n preserveModulesRoot: string | undefined;\n handleExtension: (path: string) => string;\n }) =>\n (key: string) => {\n const normalPath = normalizePath(key);\n const noRoot = normalPath.startsWith(normalizedRoot)\n ? normalPath.slice(normalizedRoot.length)\n : normalPath;\n const noExtension = handleExtension(noRoot);\n\n let noRelativeNorAbsolute = noExtension;\n while (\n noRelativeNorAbsolute.startsWith(\"/\") ||\n noRelativeNorAbsolute.startsWith(\".\")\n ) {\n noRelativeNorAbsolute = noRelativeNorAbsolute.slice(1);\n }\n if (preserveModulesRoot) {\n const removedModulesRoot = noRelativeNorAbsolute.startsWith(\n preserveModulesRoot\n )\n ? noRelativeNorAbsolute.slice(preserveModulesRoot.length)\n : noRelativeNorAbsolute;\n return removedModulesRoot.startsWith(normalizedRoot)\n ? removedModulesRoot.slice(normalizedRoot.length)\n : removedModulesRoot;\n }\n return noRelativeNorAbsolute;\n };\n\nconst createPathNormalizer =\n ({ normalizedRoot, moduleBasePath }: { normalizedRoot: string, moduleBasePath: string }) =>\n (path: string) => {\n if(typeof path !== 'string') {\n throw new Error(`Invalid path: ${JSON.stringify(path)}`);\n }\n const normalPath = normalizePath(path);\n const noRoot = normalPath.startsWith(normalizedRoot)\n ? normalPath.slice(normalizedRoot.length)\n : normalPath;\n // no leading slash when starting with module base\n if(noRoot.startsWith(moduleBasePath)) {\n return noRoot.slice(1);\n }\n return noRoot;\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.FILE_REGEX,\n moduleBasePath = \"/\",\n}: CreateInputNormalizerProps): InputNormalizer {\n const normalizedRoot = resolveRootOption(root, preserveModulesRoot);\n const handleExtension = resolveExtensionOptions(removeExtension);\n\n const normalizeEntryKey = createKeyNormalizer({\n normalizedRoot,\n preserveModulesRoot,\n handleExtension,\n });\n\n const normalizeEntryPath = createPathNormalizer({ normalizedRoot, moduleBasePath });\n return 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"],"names":[],"mappings":";;;;;;;;;AAYA,MAAM,uBAAA,GAA0B,CAC9B,eACG,KAAA;AACH,EAAI,IAAA,OAAO,oBAAoB,SAAW,EAAA;AACxC,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAA,OAAO,CAAC,IAAiB,KAAA;AACvB,QAAM,MAAA,cAAA,GAAiB,IAAK,CAAA,WAAA,CAAY,GAAG,CAAA;AAC3C,QAAA,OAAO,mBAAmB,EAAK,GAAA,IAAA,CAAK,KAAM,CAAA,CAAA,EAAG,cAAc,CAAI,GAAA,IAAA;AAAA,OACjE;AAAA;AAEF,IAAA,OAAO,CAAC,IAAiB,KAAA,IAAA;AAAA;AAE3B,EAAI,IAAA,OAAO,oBAAoB,QAAU,EAAA;AACvC,IAAA,OAAO,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,iBAAiB,EAAE,CAAA;AAAA;AAE3D,EAAA,IAAI,2BAA2B,MAAQ,EAAA;AACrC,IAAO,OAAA,CAAC,IACN,KAAA,eAAA,CAAgB,IAAK,CAAA,IAAI,IAAI,IAAK,CAAA,OAAA,CAAQ,eAAiB,EAAA,EAAE,CAAI,GAAA,IAAA;AAAA;AAErE,EAAI,IAAA,OAAO,oBAAoB,UAAY,EAAA;AACzC,IAAA,O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putNormalizer.js","sources":["../../../plugin/helpers/inputNormalizer.ts"],"sourcesContent":["import { normalizePath } from \"vite\";\nimport type { InputNormalizer, NormalizerInput } from \"../types.js\";\nimport { join } from \"path\";\nimport { DEFAULT_CONFIG } from \"../config/defaults.js\";\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 (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 if (moduleId.startsWith(normalizedRoot)) {\n moduleId = moduleId.slice(normalizedRoot.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)\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.FILE_REGEX,\n}: CreateInputNormalizerProps): InputNormalizer {\n const relativeRoot = resolveRootOption(root, preserveModulesRoot);\n const handleExtension = resolveExtensionOptions(removeExtension);\n\n const normalizeEntryKey = createKeyNormalizer({\n root: root,\n preserveModulesRoot: relativeRoot,\n handleExtension,\n });\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 return (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}\n"],"names":[],"mappings":";;;;;;;;;AAWA,MAAM,uBAAA,GAA0B,CAC9B,eACG,KAAA;AACH,EAAI,IAAA,OAAO,oBAAoB,SAAW,EAAA;AACxC,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAA,OAAO,CAAC,IAAiB,KAAA;AACvB,QAAM,MAAA,cAAA,GAAiB,IAAK,CAAA,WAAA,CAAY,GA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ACd,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,OAAO,CAAC,KAA6C,KAAA;AACnD,IAAA,MAAM,CAAC,GAAA,EAAK,IAAI,CAAA,GAAI,eAAe,KAAK,CAAA;AAExC,IAAM,MAAA,cAAA,GAAiB,KAAK,UAAW,CAAA,GAAG,IAAI,IAAK,CAAA,KAAA,CAAM,CAAC,CAAI,GAAA,IAAA;AAC9D,IAAA,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;AACF;;;;"}
|
|
@@ -2,7 +2,7 @@ import type { Manifest } from "vite";
|
|
|
2
2
|
type TryManifestOptions<SSR extends boolean> = {
|
|
3
3
|
root: string;
|
|
4
4
|
outDir: string;
|
|
5
|
-
ssrManifest
|
|
5
|
+
ssrManifest?: SSR;
|
|
6
6
|
};
|
|
7
7
|
export declare function tryManifest<SSR extends boolean>(options: TryManifestOptions<SSR>): {
|
|
8
8
|
type: "success";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tryManifest.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/tryManifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAErC,KAAK,kBAAkB,CAAC,GAAG,SAAS,OAAO,IAAI;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"tryManifest.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/tryManifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAErC,KAAK,kBAAkB,CAAC,GAAG,SAAS,OAAO,IAAI;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,GAAG,CAAC;CACnB,CAAC;AAEF,wBAAgB,WAAW,CAAC,GAAG,SAAS,OAAO,EAAE,OAAO,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG;IAClF,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,GAAG,SAAS,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC;IACjE,KAAK,CAAC,EAAC,KAAK,CAAA;CACb,GAAG;IACF,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAC,KAAK,CAAA;CAChB,CAoBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tryManifest.js","sources":["../../../plugin/helpers/tryManifest.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { Manifest } from \"vite\";\n\ntype TryManifestOptions<SSR extends boolean> = {\n root: string;\n outDir: string;\n ssrManifest
|
|
1
|
+
{"version":3,"file":"tryManifest.js","sources":["../../../plugin/helpers/tryManifest.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { Manifest } from \"vite\";\n\ntype TryManifestOptions<SSR extends boolean> = {\n root: string;\n outDir: string;\n ssrManifest?: SSR;\n};\n\nexport function tryManifest<SSR extends boolean>(options: TryManifestOptions<SSR>): {\n type: \"success\";\n manifest: SSR extends true ? Record<string, string[]> : Manifest;\n error?:never\n} | {\n type: \"error\";\n error: Error;\n manifest?:never\n} {\n const manifestPath = resolve(\n options.root,\n options.outDir,\n \".vite\",\n options.ssrManifest ? \"ssr-manifest.json\" : \"manifest.json\"\n );\n try {\n const result= JSON.parse(readFileSync(manifestPath, \"utf-8\"));\n return {\n type: \"success\",\n manifest: result,\n }\n } catch (e) {\n console.log(\"No manifest found\", manifestPath);\n return {\n type: \"error\",\n error: e as Error,\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAUO,SAAS,YAAiC,OAQ/C,EAAA;AACA,EAAA,MAAM,YAAe,GAAA,OAAA;AAAA,IACnB,OAAQ,CAAA,IAAA;AAAA,IACR,OAAQ,CAAA,MAAA;AAAA,IACR,OAAA;AAAA,IACA,OAAA,CAAQ,cAAc,mBAAsB,GAAA;AAAA,GAC9C;AACA,EAAI,IAAA;AACF,IAAA,MAAM,SAAS,IAAK,CAAA,KAAA,CAAM,YAAa,CAAA,YAAA,EAAc,OAAO,CAAC,CAAA;AAC7D,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,SAAA;AAAA,MACN,QAAU,EAAA;AAAA,KACZ;AAAA,WACO,CAAG,EAAA;AACV,IAAQ,OAAA,CAAA,GAAA,CAAI,qBAAqB,YAAY,CAAA;AAC7C,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,OAAA;AAAA,MACN,KAAO,EAAA;AAAA,KACT;AAAA;AAEJ;;;;"}
|
|
@@ -9,5 +9,5 @@ export interface BuildLoaderOptions {
|
|
|
9
9
|
serverManifest: Manifest;
|
|
10
10
|
clientManifest: Manifest;
|
|
11
11
|
}
|
|
12
|
-
export declare function createBuildLoader({ userConfig, userOptions, pluginContext,
|
|
12
|
+
export declare function createBuildLoader({ root, userConfig, userOptions, pluginContext, serverManifest, clientManifest, }: BuildLoaderOptions): (id: string) => Promise<any>;
|
|
13
13
|
//# sourceMappingURL=createBuildLoader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildLoader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/createBuildLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAGrC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,EAAE,kBAAkB,CAAC;IAC/B,WAAW,EAAE,mBAAmB,CAAC;IACjC,cAAc,EAAE,QAAQ,CAAC;IACzB,cAAc,EAAE,QAAQ,CAAC;CAC1B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,UAAU,EACV,WAAW,EACX,aAAa,EACb,cAAc,EACd,cAAc,GACf,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"createBuildLoader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/createBuildLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAGrC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,EAAE,kBAAkB,CAAC;IAC/B,WAAW,EAAE,mBAAmB,CAAC;IACjC,cAAc,EAAE,QAAQ,CAAC;IACzB,cAAc,EAAE,QAAQ,CAAC;CAC1B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,UAAU,EACV,WAAW,EACX,aAAa,EACb,cAAc,EACd,cAAc,GACf,EAAE,kBAAkB,QAMmB,MAAM,kBAmC7C"}
|
|
@@ -7,40 +7,43 @@ import { join } from 'node:path';
|
|
|
7
7
|
import { createInputNormalizer } from '../helpers/inputNormalizer.js';
|
|
8
8
|
|
|
9
9
|
function createBuildLoader({
|
|
10
|
+
root,
|
|
10
11
|
userConfig,
|
|
11
12
|
userOptions,
|
|
12
13
|
pluginContext,
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
serverManifest,
|
|
15
|
+
clientManifest
|
|
15
16
|
}) {
|
|
16
|
-
const root = pluginContext.environment.config.root ?? userConfig.root ?? userOptions.projectRoot ?? process.cwd();
|
|
17
17
|
const normalizer = createInputNormalizer({
|
|
18
|
-
root
|
|
19
|
-
preserveModulesRoot:
|
|
18
|
+
root,
|
|
19
|
+
preserveModulesRoot: undefined,
|
|
20
|
+
removeExtension: false
|
|
20
21
|
});
|
|
21
22
|
return async function buildLoader(id) {
|
|
22
|
-
const [
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const [key, value] = normalizer(id);
|
|
24
|
+
const distDir = userOptions.build.outDir;
|
|
25
|
+
const manifests = [clientManifest, serverManifest];
|
|
26
|
+
for (const n of [0, 1]) {
|
|
27
|
+
const manifest = manifests[n];
|
|
28
|
+
const manifestEntry = manifest[key];
|
|
29
|
+
if (!manifestEntry) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const isClient = userOptions.autoDiscover.clientComponents(id);
|
|
33
|
+
const isServer = userOptions.autoDiscover.serverFunctions(id);
|
|
34
|
+
const outDir = isClient ? userOptions.build.client : isServer ? userOptions.build.server : n === 0 ? userOptions.build.client : userOptions.build.server;
|
|
35
|
+
if (manifestEntry.file.startsWith(`${root}/${distDir}/${outDir}/`)) {
|
|
36
|
+
return import(manifestEntry.file);
|
|
37
|
+
}
|
|
38
|
+
if (manifestEntry.file.startsWith(`${distDir}/`)) {
|
|
39
|
+
return import(join(root, manifestEntry.file));
|
|
40
|
+
}
|
|
41
|
+
if (manifestEntry.file.startsWith(`${outDir}/`)) {
|
|
42
|
+
return import(join(root, distDir, outDir, manifestEntry.file));
|
|
43
|
+
}
|
|
44
|
+
return import(join(root, distDir, outDir, manifestEntry.file));
|
|
31
45
|
}
|
|
32
|
-
|
|
33
|
-
const [keyNormalized] = normalizer(key);
|
|
34
|
-
return keyNormalized === normalizedId;
|
|
35
|
-
});
|
|
36
|
-
if (serverEntry) {
|
|
37
|
-
const module = await import(join(root, serverEntry[1].file));
|
|
38
|
-
return module;
|
|
39
|
-
}
|
|
40
|
-
const availableModules = [...Object.keys(clientManifest), ...Object.keys(serverManifest)];
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Module not found: ${id}, available modules: ${availableModules.join(", ")}`
|
|
43
|
-
);
|
|
46
|
+
throw new Error(`Module not found: ${id}`);
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
49
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildLoader.js","sources":["../../../plugin/loader/createBuildLoader.ts"],"sourcesContent":["import { join, resolve } from \"node:path\";\nimport type { PluginContext } from \"rollup\";\nimport type { ResolvedUserConfig, ResolvedUserOptions } from \"../../server.js\";\nimport type { Manifest } from \"vite\";\nimport { createInputNormalizer } from \"../helpers/inputNormalizer.js\";\n\nexport interface BuildLoaderOptions {\n root: string;\n pluginContext: PluginContext;\n userConfig: ResolvedUserConfig;\n userOptions: ResolvedUserOptions;\n serverManifest: Manifest;\n clientManifest: Manifest;\n}\n\nexport function createBuildLoader({\n userConfig,\n userOptions,\n pluginContext,\n
|
|
1
|
+
{"version":3,"file":"createBuildLoader.js","sources":["../../../plugin/loader/createBuildLoader.ts"],"sourcesContent":["import { join, relative, resolve } from \"node:path\";\nimport type { PluginContext } from \"rollup\";\nimport type { ResolvedUserConfig, ResolvedUserOptions } from \"../../server.js\";\nimport type { Manifest } from \"vite\";\nimport { createInputNormalizer } from \"../helpers/inputNormalizer.js\";\n\nexport interface BuildLoaderOptions {\n root: string;\n pluginContext: PluginContext;\n userConfig: ResolvedUserConfig;\n userOptions: ResolvedUserOptions;\n serverManifest: Manifest;\n clientManifest: Manifest;\n}\n\nexport function createBuildLoader({\n root,\n userConfig,\n userOptions,\n pluginContext,\n serverManifest,\n clientManifest,\n}: BuildLoaderOptions) {\n const normalizer = createInputNormalizer({\n root,\n preserveModulesRoot: undefined,\n removeExtension: false,\n });\n return async function buildLoader(id: string) {\n const [key, value] = normalizer(id);\n // Remove leading slash if present\n const distDir = userOptions.build.outDir;\n const manifests = [clientManifest, serverManifest];\n // Try to find the module in the manifest\n for (const n of [0, 1]) {\n const manifest = manifests[n];\n const manifestEntry = manifest[key]\n if (!manifestEntry) {\n continue;\n }\n const isClient = userOptions.autoDiscover.clientComponents(id);\n const isServer = userOptions.autoDiscover.serverFunctions(id);\n const outDir = isClient\n ? userOptions.build.client\n : isServer\n ? userOptions.build.server\n : n === 0\n ? userOptions.build.client\n : userOptions.build.server;\n if (manifestEntry.file.startsWith(`${root}/${distDir}/${outDir}/`)) {\n return import(manifestEntry.file);\n }\n if (manifestEntry.file.startsWith(`${distDir}/`)) {\n return import(join(root, manifestEntry.file));\n }\n if (manifestEntry.file.startsWith(`${outDir}/`)) {\n return import(join(root, distDir, outDir, manifestEntry.file));\n }\n // Load the module\n return import(join(root, distDir, outDir, manifestEntry.file));\n }\n throw new Error(`Module not found: ${id}`);\n };\n}\n"],"names":[],"mappings":";;;;;;;;AAeO,SAAS,iBAAkB,CAAA;AAAA,EAChC,IAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF,CAAuB,EAAA;AACrB,EAAA,MAAM,aA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CAAK,IAAM,EAAA,aAAA,CAAc,IAAI,CAAA,CAAA;AAAA;AAE7C,MAAA,IAAI,cAAc,IAAK,CAAA,UAAA,CAAW,CAAG,EAAA,MAAM,GAAG,CAAG,EAAA;AAC/C,QAAA,OAAO,OAAO,IAAK,CAAA,IAAA,EAAM,OAAS,EAAA,MAAA,EAAQ,cAAc,IAAI,CAAA,CAAA;AAAA;AAG9D,MAAA,OAAO,OAAO,IAAK,CAAA,IAAA,EAAM,OAAS,EAAA,MAAA,EAAQ,cAAc,IAAI,CAAA,CAAA;AAAA;AAE9D,IAAA,MAAM,IAAI,KAAA,CAAM,CAAqB,kBAAA,EAAA,EAAE,CAAE,CAAA,CAAA;AAAA,GAC3C;AACF;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MessagePort } from 'node:worker_threads';
|
|
2
|
+
import type { LoadHookContext } from 'node:module';
|
|
3
|
+
type LoaderContext = {
|
|
4
|
+
data?: {
|
|
5
|
+
port: MessagePort;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare function initialize(data: {
|
|
9
|
+
port: MessagePort;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
export declare function setCurrentPage(page: string | null): void;
|
|
12
|
+
export declare function getCssFilesForPage(page: string): string[];
|
|
13
|
+
export declare function load(url: string, context: LoadHookContext & LoaderContext, defaultLoad: any): Promise<any>;
|
|
14
|
+
export declare function resolve(specifier: string, context: any, defaultResolve: any): any;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=css-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-loader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/css-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC;CAC9B,CAAC;AAKF,wBAAsB,UAAU,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,iBAI3D;AAMD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,QAKjD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzD;AAGD,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,aAAa,EAAE,WAAW,EAAE,GAAG,gBAqDjG;AAED,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,OAE3E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { readFile } from 'fs/promises';
|
|
7
|
+
import { basename } from 'path';
|
|
8
|
+
import postcss from 'postcss';
|
|
9
|
+
|
|
10
|
+
let cssLoaderPort;
|
|
11
|
+
async function initialize(data) {
|
|
12
|
+
cssLoaderPort = data.port;
|
|
13
|
+
data.port.postMessage({ type: "INITIALIZED" });
|
|
14
|
+
data.port.unref();
|
|
15
|
+
}
|
|
16
|
+
const cssFilesByPage = /* @__PURE__ */ new Map();
|
|
17
|
+
function setCurrentPage(page) {
|
|
18
|
+
if (page && !cssFilesByPage.has(page)) {
|
|
19
|
+
cssFilesByPage.set(page, /* @__PURE__ */ new Set());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function getCssFilesForPage(page) {
|
|
23
|
+
return Array.from(cssFilesByPage.get(page) || []);
|
|
24
|
+
}
|
|
25
|
+
async function load(url, context, defaultLoad) {
|
|
26
|
+
if (url.endsWith(".css")) {
|
|
27
|
+
const source = await readFile(new URL(url), "utf-8");
|
|
28
|
+
const result = await postcss().process(source, {
|
|
29
|
+
from: url,
|
|
30
|
+
to: url,
|
|
31
|
+
map: {
|
|
32
|
+
inline: false,
|
|
33
|
+
annotation: false
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const moduleName = basename(url, ".css").replace(".", "_");
|
|
37
|
+
const classes = {};
|
|
38
|
+
result.root.walkRules((rule) => {
|
|
39
|
+
const selector = rule.selector.replace(".", "");
|
|
40
|
+
const className = `${moduleName}_${selector}`;
|
|
41
|
+
classes[selector] = className;
|
|
42
|
+
rule.selector = `.${className}`;
|
|
43
|
+
});
|
|
44
|
+
const transformedCss = result.root.toString();
|
|
45
|
+
if (cssLoaderPort) {
|
|
46
|
+
cssLoaderPort.postMessage({
|
|
47
|
+
type: "CSS_FILE",
|
|
48
|
+
id: url,
|
|
49
|
+
cssFile: transformedCss
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const moduleSource = `
|
|
53
|
+
const styles = ${JSON.stringify(classes)};
|
|
54
|
+
export default styles;
|
|
55
|
+
export const css = ${JSON.stringify(transformedCss)};
|
|
56
|
+
`;
|
|
57
|
+
return {
|
|
58
|
+
format: "module",
|
|
59
|
+
source: moduleSource,
|
|
60
|
+
shortCircuit: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return defaultLoad(url, context, defaultLoad);
|
|
64
|
+
}
|
|
65
|
+
function resolve(specifier, context, defaultResolve) {
|
|
66
|
+
return defaultResolve(specifier, context, defaultResolve);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { getCssFilesForPage, initialize, load, resolve, setCurrentPage };
|
|
70
|
+
//# sourceMappingURL=css-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-loader.js","sources":["../../../plugin/loader/css-loader.ts"],"sourcesContent":["import { readFile } from 'fs/promises';\nimport { basename } from 'path';\nimport postcss from 'postcss';\nimport type { MessagePort } from 'node:worker_threads';\nimport type { CssFileMessage } from '../worker/types.js';\nimport type { LoadHookContext } from 'node:module';\n\ntype LoaderContext = {\n data?: { port: MessagePort };\n};\n// Store port globally for CSS loader\nlet cssLoaderPort: MessagePort | undefined;\n\n// Initialize hook\nexport async function initialize(data: { port: MessagePort }) {\n cssLoaderPort = data.port; // Store port\n data.port.postMessage({ type: 'INITIALIZED' });\n data.port.unref();\n}\n\n// CSS file tracking per page\nconst cssFilesByPage = new Map<string, Set<string>>();\nlet currentPage: string | null = null;\n\nexport function setCurrentPage(page: string | null) {\n currentPage = page;\n if (page && !cssFilesByPage.has(page)) {\n cssFilesByPage.set(page, new Set());\n }\n}\n\nexport function getCssFilesForPage(page: string): string[] {\n return Array.from(cssFilesByPage.get(page) || []);\n}\n\n// Modify the CSS handling in the load function\nexport async function load(url: string, context: LoadHookContext & LoaderContext, defaultLoad: any) {\n // Handle CSS files\n if(url.endsWith(\".css\")) {\n const source = await readFile(new URL(url), 'utf-8');\n \n // Process CSS with PostCSS\n const result = await postcss().process(source, {\n from: url,\n to: url,\n map: {\n inline: false,\n annotation: false\n }\n });\n\n // Generate both transformed CSS and class mappings\n const moduleName = basename(url, '.css').replace('.', '_');\n const classes: Record<string, string> = {};\n\n // Transform selectors\n result.root.walkRules(rule => {\n const selector = rule.selector.replace('.', '');\n const className = `${moduleName}_${selector}`;\n classes[selector] = className;\n rule.selector = `.${className}`;\n });\n\n // Get transformed CSS using root.toString()\n const transformedCss = result.root.toString();\n\n // Send processed CSS to worker\n if (cssLoaderPort) {\n cssLoaderPort.postMessage({\n type: 'CSS_FILE',\n id: url,\n cssFile: transformedCss\n } satisfies CssFileMessage);\n }\n \n // Return CSS module\n const moduleSource = `\n const styles = ${JSON.stringify(classes)};\n export default styles;\n export const css = ${JSON.stringify(transformedCss)};\n `;\n\n return {\n format: 'module',\n source: moduleSource,\n shortCircuit: true\n };\n }\n return defaultLoad(url, context, defaultLoad);\n}\n\nexport function resolve(specifier: string, context: any, defaultResolve: any) {\n return defa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face LoaderContext {
|
|
4
|
+
data?: {
|
|
5
|
+
port: MessagePort;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare function getSource(url: string, context: any, defaultGetSource: any): Promise<any>;
|
|
9
|
+
export declare function transformModuleIfNeeded(source: string, url: string, loader: any, port?: MessagePort): Promise<string>;
|
|
10
|
+
export declare function initialize(data: {
|
|
11
|
+
port: MessagePort;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export declare function resolve(specifier: string, context: ResolveHookContext, nextResolve: any): Promise<any>;
|
|
14
|
+
export declare function load(url: string, context: LoadHookContext & LoaderContext, nextLoad: any): Promise<any>;
|
|
15
|
+
export declare function transformSource(source: string, context: any, defaultTransformSource: any): Promise<any>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=react-loader.d.ts.map
|
|
@@ -0,0 +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;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAYvD,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC;CAC9B;AAKD,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,GAAG,EACZ,gBAAgB,EAAE,GAAG,gBAKtB;AAomBD,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,CAAC,EAAE,WAAW,mBAwDnB;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,gBAad;AAGD,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,GAAG,EACZ,sBAAsB,EAAE,GAAG,gBAyB5B"}
|