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 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 chunkInfo) {
1673
- if (targetChunk.fileName === fileName) continue;
1674
- const { globalVar } = chunkInfo[fileName];
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 base = config.base.endsWith("/") ? config.base : config.base + "/";
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
- const destructuringPattern = named.split(",").map((b) => {
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 `const ${namespace}=await import(window.${globalVar}||${absoluteUrl});`;
1685
+ return `import * as ${namespace} from "${bareSpecifier}";`;
1692
1686
  } else if (defaultImport) {
1693
- return `const ${defaultImport}=(await import(window.${globalVar}||${absoluteUrl})).default;`;
1687
+ return `import ${defaultImport} from "${bareSpecifier}";`;
1694
1688
  } else {
1695
- return `await import(window.${globalVar}||${absoluteUrl});`;
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
- for (const fileName in chunkInfo) {
1733
- const { chunk, globalVar } = chunkInfo[fileName];
1734
- const finalHash = crypto.createHash("sha256").update(chunk.code).digest("hex");
1735
- const hasDefault = /export\s+\{\s*([^}]+\s+as\s+)?default\s*\}/.test(chunk.code) || /export\s+default\s+/.test(chunk.code);
1736
- const base = config.base.endsWith("/") ? config.base : config.base + "/";
1737
- manifest[fileName] = {
1738
- file: `${base}${fileName}`,
1739
- hash: finalHash,
1740
- globalVar,
1741
- hasDefault
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 (chunksToLoad.length > 0) {
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
- // This provides a "stable" alias that works with Import Maps and handles cycles.
84
- let shimSource = `export * from "${url}";`;
85
- if (chunk.hasDefault) {
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 absolute path to this shim
91
- importMap.imports[chunk.file] = shimUrl;
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 (chunksToLoad.length > 0) {
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
- // This provides a "stable" alias that works with Import Maps and handles cycles.
84
- let shimSource = `export * from "${url}";`;
85
- if (chunk.hasDefault) {
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 absolute path to this shim
91
- importMap.imports[chunk.file] = shimUrl;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-cross-origin-storage",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "Vite plugin to load chunks from Cross-Origin Storage",
5
5
  "keywords": [
6
6
  "vite",