vite-plugin-cross-origin-storage 1.3.5 → 1.3.7
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 +30 -55
- package/dist/loader.js +15 -8
- package/loader.js +15 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1669,77 +1669,52 @@ function cosPlugin(options = {}) {
|
|
|
1669
1669
|
}
|
|
1670
1670
|
const allChunks = Object.values(bundle).filter((c) => c.type === "chunk");
|
|
1671
1671
|
for (const targetChunk of allChunks) {
|
|
1672
|
-
for (const fileName in
|
|
1673
|
-
|
|
1674
|
-
|
|
1672
|
+
for (const fileName in bundle) {
|
|
1673
|
+
const chunk = bundle[fileName];
|
|
1674
|
+
if (chunk.type !== "chunk") continue;
|
|
1675
1675
|
const chunkBasename = fileName.split("/").pop();
|
|
1676
1676
|
const escapedName = chunkBasename.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1677
1677
|
const pattern = `import\\s*(?:(?:\\{\\s*([^}]+)\\s*\\}|\\*\\s+as\\s+([^\\s]+)|([^\\s\\{\\}]+))\\s*from\\s*)?['"]\\.\\/${escapedName}['"];?`;
|
|
1678
1678
|
const importRegex = new RegExp(pattern, "g");
|
|
1679
1679
|
if (importRegex.test(targetChunk.code)) {
|
|
1680
|
-
const
|
|
1681
|
-
const absoluteUrl = `new URL("${base}${fileName}", document.baseURI).href`;
|
|
1680
|
+
const bareSpecifier = fileName;
|
|
1682
1681
|
targetChunk.code = targetChunk.code.replace(importRegex, (_match, named, namespace, defaultImport) => {
|
|
1683
|
-
const fallback = `await import(${absoluteUrl})`;
|
|
1684
1682
|
if (named) {
|
|
1685
|
-
|
|
1686
|
-
const parts = b.trim().split(/\s+as\s+/);
|
|
1687
|
-
return parts.length === 2 ? `${parts[0]}:${parts[1]}` : parts[0];
|
|
1688
|
-
}).join(",");
|
|
1689
|
-
return `const {${destructuringPattern}}=await import(window.${globalVar}||${absoluteUrl});`;
|
|
1683
|
+
return `import {${named}} from "${bareSpecifier}";`;
|
|
1690
1684
|
} else if (namespace) {
|
|
1691
|
-
return `
|
|
1685
|
+
return `import * as ${namespace} from "${bareSpecifier}";`;
|
|
1692
1686
|
} else if (defaultImport) {
|
|
1693
|
-
return `
|
|
1687
|
+
return `import ${defaultImport} from "${bareSpecifier}";`;
|
|
1694
1688
|
} else {
|
|
1695
|
-
return `
|
|
1689
|
+
return `import "${bareSpecifier}";`;
|
|
1696
1690
|
}
|
|
1697
1691
|
});
|
|
1698
1692
|
}
|
|
1699
1693
|
}
|
|
1700
1694
|
}
|
|
1701
|
-
for (const fileName in managedChunks) {
|
|
1702
|
-
const chunk = managedChunks[fileName];
|
|
1703
|
-
chunk.imports.forEach((importedFile) => {
|
|
1704
|
-
if (!chunkInfo[importedFile]) {
|
|
1705
|
-
const importedBasename = importedFile.split("/").pop();
|
|
1706
|
-
const escapedName = importedBasename.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1707
|
-
const pattern = `import\\s*(?:(?:\\{\\s*([^}]+)\\s*\\}|\\*\\s+as\\s+([^\\s]+)|([^\\s\\{\\}]+))\\s*from\\s*)?['"]\\.\\/${escapedName}['"];?`;
|
|
1708
|
-
const importRegex = new RegExp(pattern, "g");
|
|
1709
|
-
if (importRegex.test(chunk.code)) {
|
|
1710
|
-
const base = config.base.endsWith("/") ? config.base : config.base + "/";
|
|
1711
|
-
const absoluteUrl = `new URL("${base}${importedFile}", document.baseURI).href`;
|
|
1712
|
-
chunk.code = chunk.code.replace(importRegex, (_match, named, namespace, defaultImport) => {
|
|
1713
|
-
if (named) {
|
|
1714
|
-
const destructuringPattern = named.split(",").map((b) => {
|
|
1715
|
-
const parts = b.trim().split(/\s+as\s+/);
|
|
1716
|
-
return parts.length === 2 ? `${parts[0]}:${parts[1]}` : parts[0];
|
|
1717
|
-
}).join(",");
|
|
1718
|
-
return `const {${destructuringPattern}}=await import(${absoluteUrl});`;
|
|
1719
|
-
} else if (namespace) {
|
|
1720
|
-
return `const ${namespace}=await import(${absoluteUrl});`;
|
|
1721
|
-
} else if (defaultImport) {
|
|
1722
|
-
return `const ${defaultImport}=(await import(${absoluteUrl})).default;`;
|
|
1723
|
-
} else {
|
|
1724
|
-
return `await import(${absoluteUrl});`;
|
|
1725
|
-
}
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
});
|
|
1730
|
-
}
|
|
1731
1695
|
const manifest = {};
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
const
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1696
|
+
const base = config.base.endsWith("/") ? config.base : config.base + "/";
|
|
1697
|
+
for (const fileName in bundle) {
|
|
1698
|
+
const chunk = bundle[fileName];
|
|
1699
|
+
if (chunk.type !== "chunk") continue;
|
|
1700
|
+
if (chunkInfo[fileName]) {
|
|
1701
|
+
const { globalVar } = chunkInfo[fileName];
|
|
1702
|
+
const finalHash = crypto.createHash("sha256").update(chunk.code).digest("hex");
|
|
1703
|
+
const hasDefault = /export\s+\{\s*([^}]+\s+as\s+)?default\s*\}/.test(chunk.code) || /export\s+default\s+/.test(chunk.code);
|
|
1704
|
+
manifest[fileName] = {
|
|
1705
|
+
fileName,
|
|
1706
|
+
file: `${base}${fileName}`,
|
|
1707
|
+
hash: finalHash,
|
|
1708
|
+
globalVar,
|
|
1709
|
+
hasDefault
|
|
1710
|
+
};
|
|
1711
|
+
} else {
|
|
1712
|
+
manifest[fileName] = {
|
|
1713
|
+
fileName,
|
|
1714
|
+
file: `${base}${fileName}`,
|
|
1715
|
+
unmanaged: true
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1743
1718
|
}
|
|
1744
1719
|
manifest["index"] = {
|
|
1745
1720
|
file: `${config.base.endsWith("/") ? config.base : config.base + "/"}${mainChunk.fileName}`
|
package/dist/loader.js
CHANGED
|
@@ -51,9 +51,17 @@
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Load all managed chunks in parallel
|
|
54
|
-
if (
|
|
54
|
+
if (Object.keys(manifest).length > 0) {
|
|
55
55
|
const importMap = { imports: {} };
|
|
56
56
|
|
|
57
|
+
// Fill unmanaged chunks first
|
|
58
|
+
for (const fileName in manifest) {
|
|
59
|
+
const entry = manifest[fileName];
|
|
60
|
+
if (fileName !== 'index' && !entry.hash) {
|
|
61
|
+
importMap.imports[fileName] = entry.file;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
await Promise.all(chunksToLoad.map(async (chunk) => {
|
|
58
66
|
let url = null;
|
|
59
67
|
|
|
@@ -80,15 +88,14 @@
|
|
|
80
88
|
|
|
81
89
|
if (url) {
|
|
82
90
|
// Create a Data URL shim that re-exports everything from the Blob URL.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
shimSource += `export { default } from "${url}";`;
|
|
87
|
-
}
|
|
91
|
+
const shimSource = chunk.hasDefault
|
|
92
|
+
? `export * from "${url}"; export { default } from "${url}";`
|
|
93
|
+
: `export * from "${url}";`;
|
|
88
94
|
const shimUrl = `data:text/javascript;base64,${btoa(shimSource)}`;
|
|
89
95
|
|
|
90
|
-
// Map the
|
|
91
|
-
importMap.imports[chunk.
|
|
96
|
+
// Map the bare specifier (fileName) and full paths to this shim
|
|
97
|
+
importMap.imports[chunk.fileName] = shimUrl; // bare specifier
|
|
98
|
+
importMap.imports[chunk.file] = shimUrl; // absolute path (legacy/fallback)
|
|
92
99
|
|
|
93
100
|
// Also set global if anyone still needs it (legacy)
|
|
94
101
|
if (chunk.globalVar) {
|
package/loader.js
CHANGED
|
@@ -51,9 +51,17 @@
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Load all managed chunks in parallel
|
|
54
|
-
if (
|
|
54
|
+
if (Object.keys(manifest).length > 0) {
|
|
55
55
|
const importMap = { imports: {} };
|
|
56
56
|
|
|
57
|
+
// Fill unmanaged chunks first
|
|
58
|
+
for (const fileName in manifest) {
|
|
59
|
+
const entry = manifest[fileName];
|
|
60
|
+
if (fileName !== 'index' && !entry.hash) {
|
|
61
|
+
importMap.imports[fileName] = entry.file;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
await Promise.all(chunksToLoad.map(async (chunk) => {
|
|
58
66
|
let url = null;
|
|
59
67
|
|
|
@@ -80,15 +88,14 @@
|
|
|
80
88
|
|
|
81
89
|
if (url) {
|
|
82
90
|
// Create a Data URL shim that re-exports everything from the Blob URL.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
shimSource += `export { default } from "${url}";`;
|
|
87
|
-
}
|
|
91
|
+
const shimSource = chunk.hasDefault
|
|
92
|
+
? `export * from "${url}"; export { default } from "${url}";`
|
|
93
|
+
: `export * from "${url}";`;
|
|
88
94
|
const shimUrl = `data:text/javascript;base64,${btoa(shimSource)}`;
|
|
89
95
|
|
|
90
|
-
// Map the
|
|
91
|
-
importMap.imports[chunk.
|
|
96
|
+
// Map the bare specifier (fileName) and full paths to this shim
|
|
97
|
+
importMap.imports[chunk.fileName] = shimUrl; // bare specifier
|
|
98
|
+
importMap.imports[chunk.file] = shimUrl; // absolute path (legacy/fallback)
|
|
92
99
|
|
|
93
100
|
// Also set global if anyone still needs it (legacy)
|
|
94
101
|
if (chunk.globalVar) {
|