@module-federation/vite 1.20.1 → 1.20.3
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/lib/buildPaths-BkaQHrd2.js +47 -0
- package/lib/index.js +372 -307
- package/lib/pathNormalization-CLDIcf9-.js +119 -0
- package/lib/{ssrEntryLoader-Bw423jj_.js → ssrEntryLoader-7v0Do_g5.js} +47 -16
- package/lib/{ssrVmStrategy-7HAPa-Vc.js → ssrVmStrategy-BkEp3YIv.js} +23 -4
- package/lib/utils/ssrEntryLoader.d.ts +4 -5
- package/lib/utils/ssrEntryLoader.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/utils/buildPaths.ts
|
|
2
|
+
/**
|
|
3
|
+
* Rebase an import path for a bootstrap file that moved from root into `dir`.
|
|
4
|
+
*
|
|
5
|
+
* When entryFileNames places entries in a subdirectory (e.g. `static/js/`),
|
|
6
|
+
* the bootstrap file moves there too. Paths that resolved from the HTML root
|
|
7
|
+
* must resolve from the new directory instead.
|
|
8
|
+
*
|
|
9
|
+
* Cases: `/static/js/hostInit.js` → `./hostInit.js` (strip dir prefix)
|
|
10
|
+
* `./src/main.tsx` → `../../src/main.tsx` (climb back up for each dir level)
|
|
11
|
+
* `https://cdn.example.com` → unchanged (absolute URL)
|
|
12
|
+
*/
|
|
13
|
+
function rebaseImport(importSrc, dir) {
|
|
14
|
+
if (!dir) return importSrc;
|
|
15
|
+
if (isAbsoluteUrl(importSrc)) return importSrc;
|
|
16
|
+
const normalizedDir = dir.replace(/^\/+|\/+$/g, "");
|
|
17
|
+
if (!normalizedDir) return importSrc;
|
|
18
|
+
const stripDirPrefix = (src, prefix) => {
|
|
19
|
+
if (src === prefix) return "";
|
|
20
|
+
if (src.startsWith(prefix + "/")) return src.slice(prefix.length);
|
|
21
|
+
};
|
|
22
|
+
const absoluteRemainder = stripDirPrefix(importSrc, "/" + normalizedDir);
|
|
23
|
+
if (absoluteRemainder !== void 0) {
|
|
24
|
+
const remainder = absoluteRemainder.replace(/^\/+/, "");
|
|
25
|
+
return remainder ? "./" + remainder : "./";
|
|
26
|
+
}
|
|
27
|
+
const relativeRemainder = stripDirPrefix(importSrc, normalizedDir);
|
|
28
|
+
if (relativeRemainder !== void 0) {
|
|
29
|
+
const remainder = relativeRemainder.replace(/^\/+/, "");
|
|
30
|
+
return remainder ? "./" + remainder : "./";
|
|
31
|
+
}
|
|
32
|
+
const upLevels = normalizedDir.split("/").filter(Boolean).length;
|
|
33
|
+
const prefix = upLevels > 0 ? "../".repeat(upLevels) : "./";
|
|
34
|
+
if (importSrc.startsWith("./")) return prefix + importSrc.slice(2);
|
|
35
|
+
if (importSrc.startsWith("/")) return prefix + importSrc.slice(1);
|
|
36
|
+
return prefix + importSrc;
|
|
37
|
+
}
|
|
38
|
+
function normalizePathForImport(path) {
|
|
39
|
+
return path.replace(/\\/g, "/");
|
|
40
|
+
}
|
|
41
|
+
const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i;
|
|
42
|
+
function isAbsoluteUrl(src) {
|
|
43
|
+
if (/^[a-z]:[\\/]/i.test(src)) return false;
|
|
44
|
+
return EXTERNAL_URL_RE.test(src);
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { normalizePathForImport as n, rebaseImport as r, EXTERNAL_URL_RE as t };
|