vite-plugin-cross-origin-storage 1.3.5 → 1.3.6

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.
Files changed (2) hide show
  1. package/dist/index.js +12 -48
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1668,64 +1668,28 @@ function cosPlugin(options = {}) {
1668
1668
  };
1669
1669
  }
1670
1670
  const allChunks = Object.values(bundle).filter((c) => c.type === "chunk");
1671
- for (const targetChunk of allChunks) {
1672
- for (const fileName in chunkInfo) {
1673
- if (targetChunk.fileName === fileName) continue;
1674
- const { globalVar } = chunkInfo[fileName];
1675
- const chunkBasename = fileName.split("/").pop();
1676
- const escapedName = chunkBasename.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1671
+ for (const fileName in managedChunks) {
1672
+ const chunk = managedChunks[fileName];
1673
+ chunk.imports.forEach((importedFile) => {
1674
+ const importedBasename = importedFile.split("/").pop();
1675
+ const escapedName = importedBasename.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1677
1676
  const pattern = `import\\s*(?:(?:\\{\\s*([^}]+)\\s*\\}|\\*\\s+as\\s+([^\\s]+)|([^\\s\\{\\}]+))\\s*from\\s*)?['"]\\.\\/${escapedName}['"];?`;
1678
1677
  const importRegex = new RegExp(pattern, "g");
1679
- if (importRegex.test(targetChunk.code)) {
1678
+ if (importRegex.test(chunk.code)) {
1680
1679
  const base = config.base.endsWith("/") ? config.base : config.base + "/";
1681
- const absoluteUrl = `new URL("${base}${fileName}", document.baseURI).href`;
1682
- targetChunk.code = targetChunk.code.replace(importRegex, (_match, named, namespace, defaultImport) => {
1683
- const fallback = `await import(${absoluteUrl})`;
1680
+ const absoluteUrl = `${base}${importedFile}`;
1681
+ chunk.code = chunk.code.replace(importRegex, (_match, named, namespace, defaultImport) => {
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 "${absoluteUrl}";`;
1690
1684
  } else if (namespace) {
1691
- return `const ${namespace}=await import(window.${globalVar}||${absoluteUrl});`;
1685
+ return `import * as ${namespace} from "${absoluteUrl}";`;
1692
1686
  } else if (defaultImport) {
1693
- return `const ${defaultImport}=(await import(window.${globalVar}||${absoluteUrl})).default;`;
1687
+ return `import ${defaultImport} from "${absoluteUrl}";`;
1694
1688
  } else {
1695
- return `await import(window.${globalVar}||${absoluteUrl});`;
1689
+ return `import "${absoluteUrl}";`;
1696
1690
  }
1697
1691
  });
1698
1692
  }
1699
- }
1700
- }
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
1693
  });
1730
1694
  }
1731
1695
  const manifest = {};
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.6",
4
4
  "description": "Vite plugin to load chunks from Cross-Origin Storage",
5
5
  "keywords": [
6
6
  "vite",