vite-plugin-cross-origin-storage 1.4.4 → 1.5.0

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 +51 -15
  2. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -1638,17 +1638,30 @@ function cosPlugin(options = {}) {
1638
1638
  const include = options.include || ["**/*"];
1639
1639
  const includeArray = Array.isArray(include) ? include : [include];
1640
1640
  const require2 = createRequire(path.join(process.cwd(), "index.js"));
1641
- for (const item of includeArray) {
1641
+ function getPackageName(item) {
1642
1642
  if (typeof item === "string") {
1643
- let pkgName = item;
1644
- if (item.startsWith("vendor-")) {
1645
- pkgName = item.replace("vendor-", "");
1646
- }
1643
+ return item.startsWith("vendor-") ? item.replace("vendor-", "") : item;
1644
+ }
1645
+ if (item instanceof RegExp) {
1646
+ const source = item.source;
1647
+ const match = source.match(/vendor-([a-zA-Z0-9-@/]+?)(?:[-._]|\/|$)/);
1648
+ return match ? match[1] : null;
1649
+ }
1650
+ return null;
1651
+ }
1652
+ for (const item of includeArray) {
1653
+ const pkgName = getPackageName(item);
1654
+ if (pkgName) {
1647
1655
  try {
1648
1656
  require2.resolve(pkgName);
1649
- if (!externalArray.includes(pkgName)) {
1650
- console.log(`COS Plugin: [MAGIC] Externalizing package "${pkgName}"`);
1651
- externalArray.push(pkgName);
1657
+ const externalPatterns = [pkgName, `${pkgName}/*`];
1658
+ for (const pattern of externalPatterns) {
1659
+ if (!externalArray.includes(pattern)) {
1660
+ console.log(
1661
+ `COS Plugin: [MAGIC] Externalizing pattern "${pattern}" (matched from ${item})`
1662
+ );
1663
+ externalArray.push(pattern);
1664
+ }
1652
1665
  }
1653
1666
  } catch (e) {
1654
1667
  }
@@ -1695,12 +1708,20 @@ function cosPlugin(options = {}) {
1695
1708
  const require2 = createRequire(path.join(process.cwd(), "index.js"));
1696
1709
  const include = options.include || ["**/*"];
1697
1710
  const includeArray = Array.isArray(include) ? include : [include];
1698
- for (const item of includeArray) {
1699
- if (typeof item !== "string") continue;
1700
- let pkgName = item;
1701
- if (item.startsWith("vendor-")) {
1702
- pkgName = item.replace("vendor-", "");
1711
+ function getPackageName(item) {
1712
+ if (typeof item === "string") {
1713
+ return item.startsWith("vendor-") ? item.replace("vendor-", "") : item;
1703
1714
  }
1715
+ if (item instanceof RegExp) {
1716
+ const source = item.source;
1717
+ const match = source.match(/vendor-([a-zA-Z0-9-@/]+?)(?:[-._]|\/|$)/);
1718
+ return match ? match[1] : null;
1719
+ }
1720
+ return null;
1721
+ }
1722
+ for (const item of includeArray) {
1723
+ const pkgName = getPackageName(item);
1724
+ if (!pkgName) continue;
1704
1725
  try {
1705
1726
  let pkgPath = "";
1706
1727
  try {
@@ -1732,8 +1753,23 @@ function cosPlugin(options = {}) {
1732
1753
  } catch (e) {
1733
1754
  pkgPath = require2.resolve(pkgName);
1734
1755
  }
1735
- console.log(`COS Plugin: [MAGIC] Resolved ${pkgName} to ${pkgPath}`);
1736
- const content = fs.readFileSync(pkgPath);
1756
+ const esbuildRequire = createRequire(import.meta.url);
1757
+ const esbuild = esbuildRequire("esbuild");
1758
+ const buildResult = await esbuild.build({
1759
+ entryPoints: [pkgPath],
1760
+ bundle: true,
1761
+ format: "esm",
1762
+ minify: true,
1763
+ platform: "browser",
1764
+ write: false,
1765
+ // Don't write to disk
1766
+ target: "esnext",
1767
+ // Neutralize environment
1768
+ define: {
1769
+ "process.env.NODE_ENV": '"production"'
1770
+ }
1771
+ });
1772
+ const content = buildResult.outputFiles[0].contents;
1737
1773
  const hash = crypto.createHash("sha256").update(content).digest("hex");
1738
1774
  const ext = path.extname(pkgPath);
1739
1775
  const fileName = path.join(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-cross-origin-storage",
3
- "version": "1.4.4",
3
+ "version": "1.5.0",
4
4
  "description": "Vite plugin to load chunks from Cross-Origin Storage",
5
5
  "keywords": [
6
6
  "vite",
@@ -48,9 +48,12 @@
48
48
  "@rollup/pluginutils": "^5.3.0",
49
49
  "@types/node": "^25.2.3",
50
50
  "rollup": "^4.57.1",
51
+ "three": "^0.183.0",
51
52
  "tsup": "^8.5.1",
52
53
  "typescript": "^5.9.3",
53
- "vite": "^7.3.1",
54
- "three": "^0.183.0"
54
+ "vite": "^7.3.1"
55
+ },
56
+ "dependencies": {
57
+ "esbuild": "^0.27.3"
55
58
  }
56
59
  }