@zeus-js/bundler-plugin 0.1.0-beta.2 → 0.1.0-beta.4

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/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * bundler-plugin v0.1.0-beta.2
2
+ * bundler-plugin v0.1.0-beta.4
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -78,7 +78,7 @@ function hasErrorDiagnostics(diagnostics) {
78
78
  return diagnostics.some((item) => item.level === "error");
79
79
  }
80
80
  //#endregion
81
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/asyncToGenerator.js
81
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/asyncToGenerator.js
82
82
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
83
83
  try {
84
84
  var i = n[a](c), u = i.value;
@@ -104,7 +104,7 @@ function _asyncToGenerator(n) {
104
104
  };
105
105
  }
106
106
  //#endregion
107
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
107
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
108
108
  function _typeof(o) {
109
109
  "@babel/helpers - typeof";
110
110
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -114,7 +114,7 @@ function _typeof(o) {
114
114
  }, _typeof(o);
115
115
  }
116
116
  //#endregion
117
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
117
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
118
118
  function toPrimitive(t, r) {
119
119
  if ("object" != _typeof(t) || !t) return t;
120
120
  var e = t[Symbol.toPrimitive];
@@ -126,13 +126,13 @@ function toPrimitive(t, r) {
126
126
  return ("string" === r ? String : Number)(t);
127
127
  }
128
128
  //#endregion
129
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
129
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
130
130
  function toPropertyKey(t) {
131
131
  var i = toPrimitive(t, "string");
132
132
  return "symbol" == _typeof(i) ? i : i + "";
133
133
  }
134
134
  //#endregion
135
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
135
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
136
136
  function _defineProperty(e, r, t) {
137
137
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
138
138
  value: t,
@@ -142,7 +142,7 @@ function _defineProperty(e, r, t) {
142
142
  }) : e[r] = t, e;
143
143
  }
144
144
  //#endregion
145
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectSpread2.js
145
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectSpread2.js
146
146
  function ownKeys(e, r) {
147
147
  var t = Object.keys(e);
148
148
  if (Object.getOwnPropertySymbols) {
@@ -272,6 +272,42 @@ function _fileExists() {
272
272
  return _fileExists.apply(this, arguments);
273
273
  }
274
274
  //#endregion
275
+ //#region packages/web-c/bundler-plugin/src/external.ts
276
+ const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
277
+ function collectPluginExternals(options, collectOptions = {}) {
278
+ var _options$plugins;
279
+ const entries = [];
280
+ if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
281
+ for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
282
+ var _plugin$external;
283
+ for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
284
+ }
285
+ return uniqueExternalEntries(entries);
286
+ }
287
+ function mergeExternal(userExternal, pluginExternal) {
288
+ if (!userExternal) return pluginExternal;
289
+ if (typeof userExternal === "function") return (source, importer, isResolved) => {
290
+ return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
291
+ };
292
+ return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
293
+ }
294
+ function matchesExternal(source, entries) {
295
+ return entries.some((entry) => {
296
+ return typeof entry === "string" ? entry === source : entry.test(source);
297
+ });
298
+ }
299
+ function uniqueExternalEntries(entries) {
300
+ const seen = /* @__PURE__ */ new Set();
301
+ const result = [];
302
+ for (const entry of entries) {
303
+ const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
304
+ if (seen.has(key)) continue;
305
+ seen.add(key);
306
+ result.push(entry);
307
+ }
308
+ return result;
309
+ }
310
+ //#endregion
275
311
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
276
312
  function createOutputRegistry() {
277
313
  const map = /* @__PURE__ */ new Map();
@@ -458,9 +494,33 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
458
494
  let shouldCompileZeus = (_id) => false;
459
495
  let ctx;
460
496
  let root = process.cwd();
497
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
461
498
  const virtualModules = new VirtualModuleRegistry();
462
499
  return {
463
500
  name: resolvePluginName(target),
501
+ options(inputOptions) {
502
+ if (target === "vite") return null;
503
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
504
+ const shouldSetRolldownTarget = target === "rolldown";
505
+ if (!pluginExternals.length && !shouldSetRolldownTarget) return null;
506
+ const nextOptions = _objectSpread2({}, inputOptions);
507
+ if (pluginExternals.length) nextOptions.external = mergeExternal(inputOptions.external, pluginExternals);
508
+ if (shouldSetRolldownTarget) {
509
+ var _transform;
510
+ nextOptions.transform = _objectSpread2({ target: "es2016" }, (_transform = inputOptions.transform) !== null && _transform !== void 0 ? _transform : {});
511
+ }
512
+ return nextOptions;
513
+ },
514
+ outputOptions(outputOptions) {
515
+ if (target === "vite") return null;
516
+ cleanOutputDir(outputOptions, {
517
+ root: resolveRoot(options.root),
518
+ enabled: options.clean !== false,
519
+ cleanedOutputDirs
520
+ });
521
+ if (outputOptions.chunkFileNames) return null;
522
+ return _objectSpread2(_objectSpread2({}, outputOptions), {}, { chunkFileNames: "chunks/[name]-[hash].js" });
523
+ },
464
524
  buildStart() {
465
525
  var _this = this;
466
526
  return _asyncToGenerator(function* () {
@@ -528,6 +588,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
528
588
  id: resolvedVirtual,
529
589
  moduleSideEffects: "no-treeshake"
530
590
  };
591
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
592
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
593
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
594
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
595
+ id: "\0" + virtualEntryId,
596
+ moduleSideEffects: "no-treeshake"
597
+ };
598
+ }
531
599
  if (target === "rollup") {
532
600
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
533
601
  if (resolvedTs) return resolvedTs;
@@ -580,6 +648,31 @@ function resolveRoot(root) {
580
648
  if (typeof root === "function") return path.resolve(root());
581
649
  return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
582
650
  }
651
+ function cleanOutputDir(outputOptions, options) {
652
+ if (!options.enabled) return;
653
+ const outputDir = resolveOutputDir(outputOptions, options.root);
654
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
655
+ if (options.cleanedOutputDirs.has(outputDir)) return;
656
+ options.cleanedOutputDirs.add(outputDir);
657
+ fs.rmSync(outputDir, {
658
+ recursive: true,
659
+ force: true
660
+ });
661
+ }
662
+ function resolveOutputDir(outputOptions, root) {
663
+ const dir = outputOptions.dir;
664
+ if (typeof dir === "string" && dir.length > 0) return path.resolve(root, dir);
665
+ const file = outputOptions.file;
666
+ if (typeof file === "string" && file.length > 0) return path.dirname(path.resolve(root, file));
667
+ return path.resolve(root, "dist");
668
+ }
669
+ function isSafeCleanTarget(outputDir, root) {
670
+ const resolvedRoot = path.resolve(root);
671
+ const resolvedOutputDir = path.resolve(outputDir);
672
+ if (resolvedOutputDir === resolvedRoot) return false;
673
+ const relative = path.relative(resolvedRoot, resolvedOutputDir);
674
+ return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
675
+ }
583
676
  function createManifest(_x, _x2, _x3) {
584
677
  return _createManifest.apply(this, arguments);
585
678
  }
@@ -672,26 +765,14 @@ function emitVirtualEntries(modules, pluginContext) {
672
765
  });
673
766
  }
674
767
  }
675
- //#endregion
676
- //#region packages/web-c/bundler-plugin/src/external.ts
677
- function collectPluginExternals(options) {
678
- var _options$plugins;
679
- const set = /* @__PURE__ */ new Set();
680
- for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
681
- var _plugin$external;
682
- for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
683
- }
684
- return Array.from(set);
685
- }
686
- function mergeExternal(userExternal, pluginExternal) {
687
- if (!userExternal) return pluginExternal;
688
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
689
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
690
- };
691
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
768
+ function resolveVirtualEntryImport(id, importer) {
769
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
770
+ const lastColon = importer.lastIndexOf(":");
771
+ if (lastColon <= 0) return null;
772
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
692
773
  }
693
774
  //#endregion
694
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectWithoutPropertiesLoose.js
775
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectWithoutPropertiesLoose.js
695
776
  function _objectWithoutPropertiesLoose(r, e) {
696
777
  if (null == r) return {};
697
778
  var t = {};
@@ -702,7 +783,7 @@ function _objectWithoutPropertiesLoose(r, e) {
702
783
  return t;
703
784
  }
704
785
  //#endregion
705
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectWithoutProperties.js
786
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectWithoutProperties.js
706
787
  function _objectWithoutProperties(e, t) {
707
788
  if (null == e) return {};
708
789
  var o, r, i = _objectWithoutPropertiesLoose(e, t);
@@ -726,13 +807,14 @@ function zeus(options = {}) {
726
807
  }
727
808
  function defineZeusRollupConfig(config = {}) {
728
809
  const { zeus: zeusOptions = {}, plugins, input, output, external } = config, rest = _objectWithoutProperties(config, _excluded);
729
- const pluginExternals = collectPluginExternals(zeusOptions);
810
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
730
811
  return _objectSpread2(_objectSpread2({ input: input !== null && input !== void 0 ? input : "src/index.ts" }, rest), {}, {
731
812
  external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
732
813
  plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
733
814
  output: output !== null && output !== void 0 ? output : {
734
815
  dir: "dist",
735
816
  format: "es",
817
+ chunkFileNames: "chunks/[name]-[hash].js",
736
818
  sourcemap: true
737
819
  }
738
820
  });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * bundler-plugin v0.1.0-beta.2
2
+ * bundler-plugin v0.1.0-beta.4
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -78,7 +78,7 @@ function hasErrorDiagnostics(diagnostics) {
78
78
  return diagnostics.some((item) => item.level === "error");
79
79
  }
80
80
  //#endregion
81
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/asyncToGenerator.js
81
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/asyncToGenerator.js
82
82
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
83
83
  try {
84
84
  var i = n[a](c), u = i.value;
@@ -104,7 +104,7 @@ function _asyncToGenerator(n) {
104
104
  };
105
105
  }
106
106
  //#endregion
107
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
107
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
108
108
  function _typeof(o) {
109
109
  "@babel/helpers - typeof";
110
110
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -114,7 +114,7 @@ function _typeof(o) {
114
114
  }, _typeof(o);
115
115
  }
116
116
  //#endregion
117
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
117
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
118
118
  function toPrimitive(t, r) {
119
119
  if ("object" != _typeof(t) || !t) return t;
120
120
  var e = t[Symbol.toPrimitive];
@@ -126,13 +126,13 @@ function toPrimitive(t, r) {
126
126
  return ("string" === r ? String : Number)(t);
127
127
  }
128
128
  //#endregion
129
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
129
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
130
130
  function toPropertyKey(t) {
131
131
  var i = toPrimitive(t, "string");
132
132
  return "symbol" == _typeof(i) ? i : i + "";
133
133
  }
134
134
  //#endregion
135
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
135
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
136
136
  function _defineProperty(e, r, t) {
137
137
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
138
138
  value: t,
@@ -142,7 +142,7 @@ function _defineProperty(e, r, t) {
142
142
  }) : e[r] = t, e;
143
143
  }
144
144
  //#endregion
145
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectSpread2.js
145
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectSpread2.js
146
146
  function ownKeys(e, r) {
147
147
  var t = Object.keys(e);
148
148
  if (Object.getOwnPropertySymbols) {
@@ -272,6 +272,42 @@ function _fileExists() {
272
272
  return _fileExists.apply(this, arguments);
273
273
  }
274
274
  //#endregion
275
+ //#region packages/web-c/bundler-plugin/src/external.ts
276
+ const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
277
+ function collectPluginExternals(options, collectOptions = {}) {
278
+ var _options$plugins;
279
+ const entries = [];
280
+ if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
281
+ for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
282
+ var _plugin$external;
283
+ for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
284
+ }
285
+ return uniqueExternalEntries(entries);
286
+ }
287
+ function mergeExternal(userExternal, pluginExternal) {
288
+ if (!userExternal) return pluginExternal;
289
+ if (typeof userExternal === "function") return (source, importer, isResolved) => {
290
+ return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
291
+ };
292
+ return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
293
+ }
294
+ function matchesExternal(source, entries) {
295
+ return entries.some((entry) => {
296
+ return typeof entry === "string" ? entry === source : entry.test(source);
297
+ });
298
+ }
299
+ function uniqueExternalEntries(entries) {
300
+ const seen = /* @__PURE__ */ new Set();
301
+ const result = [];
302
+ for (const entry of entries) {
303
+ const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
304
+ if (seen.has(key)) continue;
305
+ seen.add(key);
306
+ result.push(entry);
307
+ }
308
+ return result;
309
+ }
310
+ //#endregion
275
311
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
276
312
  function createOutputRegistry() {
277
313
  const map = /* @__PURE__ */ new Map();
@@ -458,9 +494,33 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
458
494
  let shouldCompileZeus = (_id) => false;
459
495
  let ctx;
460
496
  let root = process.cwd();
497
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
461
498
  const virtualModules = new VirtualModuleRegistry();
462
499
  return {
463
500
  name: resolvePluginName(target),
501
+ options(inputOptions) {
502
+ if (target === "vite") return null;
503
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
504
+ const shouldSetRolldownTarget = target === "rolldown";
505
+ if (!pluginExternals.length && !shouldSetRolldownTarget) return null;
506
+ const nextOptions = _objectSpread2({}, inputOptions);
507
+ if (pluginExternals.length) nextOptions.external = mergeExternal(inputOptions.external, pluginExternals);
508
+ if (shouldSetRolldownTarget) {
509
+ var _transform;
510
+ nextOptions.transform = _objectSpread2({ target: "es2016" }, (_transform = inputOptions.transform) !== null && _transform !== void 0 ? _transform : {});
511
+ }
512
+ return nextOptions;
513
+ },
514
+ outputOptions(outputOptions) {
515
+ if (target === "vite") return null;
516
+ cleanOutputDir(outputOptions, {
517
+ root: resolveRoot(options.root),
518
+ enabled: options.clean !== false,
519
+ cleanedOutputDirs
520
+ });
521
+ if (outputOptions.chunkFileNames) return null;
522
+ return _objectSpread2(_objectSpread2({}, outputOptions), {}, { chunkFileNames: "chunks/[name]-[hash].js" });
523
+ },
464
524
  buildStart() {
465
525
  var _this = this;
466
526
  return _asyncToGenerator(function* () {
@@ -528,6 +588,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
528
588
  id: resolvedVirtual,
529
589
  moduleSideEffects: "no-treeshake"
530
590
  };
591
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
592
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
593
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
594
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
595
+ id: "\0" + virtualEntryId,
596
+ moduleSideEffects: "no-treeshake"
597
+ };
598
+ }
531
599
  if (target === "rollup") {
532
600
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
533
601
  if (resolvedTs) return resolvedTs;
@@ -580,6 +648,31 @@ function resolveRoot(root) {
580
648
  if (typeof root === "function") return path.resolve(root());
581
649
  return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
582
650
  }
651
+ function cleanOutputDir(outputOptions, options) {
652
+ if (!options.enabled) return;
653
+ const outputDir = resolveOutputDir(outputOptions, options.root);
654
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
655
+ if (options.cleanedOutputDirs.has(outputDir)) return;
656
+ options.cleanedOutputDirs.add(outputDir);
657
+ fs.rmSync(outputDir, {
658
+ recursive: true,
659
+ force: true
660
+ });
661
+ }
662
+ function resolveOutputDir(outputOptions, root) {
663
+ const dir = outputOptions.dir;
664
+ if (typeof dir === "string" && dir.length > 0) return path.resolve(root, dir);
665
+ const file = outputOptions.file;
666
+ if (typeof file === "string" && file.length > 0) return path.dirname(path.resolve(root, file));
667
+ return path.resolve(root, "dist");
668
+ }
669
+ function isSafeCleanTarget(outputDir, root) {
670
+ const resolvedRoot = path.resolve(root);
671
+ const resolvedOutputDir = path.resolve(outputDir);
672
+ if (resolvedOutputDir === resolvedRoot) return false;
673
+ const relative = path.relative(resolvedRoot, resolvedOutputDir);
674
+ return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
675
+ }
583
676
  function createManifest(_x, _x2, _x3) {
584
677
  return _createManifest.apply(this, arguments);
585
678
  }
@@ -672,26 +765,14 @@ function emitVirtualEntries(modules, pluginContext) {
672
765
  });
673
766
  }
674
767
  }
675
- //#endregion
676
- //#region packages/web-c/bundler-plugin/src/external.ts
677
- function collectPluginExternals(options) {
678
- var _options$plugins;
679
- const set = /* @__PURE__ */ new Set();
680
- for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
681
- var _plugin$external;
682
- for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
683
- }
684
- return Array.from(set);
685
- }
686
- function mergeExternal(userExternal, pluginExternal) {
687
- if (!userExternal) return pluginExternal;
688
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
689
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
690
- };
691
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
768
+ function resolveVirtualEntryImport(id, importer) {
769
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
770
+ const lastColon = importer.lastIndexOf(":");
771
+ if (lastColon <= 0) return null;
772
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
692
773
  }
693
774
  //#endregion
694
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectWithoutPropertiesLoose.js
775
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectWithoutPropertiesLoose.js
695
776
  function _objectWithoutPropertiesLoose(r, e) {
696
777
  if (null == r) return {};
697
778
  var t = {};
@@ -702,7 +783,7 @@ function _objectWithoutPropertiesLoose(r, e) {
702
783
  return t;
703
784
  }
704
785
  //#endregion
705
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectWithoutProperties.js
786
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectWithoutProperties.js
706
787
  function _objectWithoutProperties(e, t) {
707
788
  if (null == e) return {};
708
789
  var o, r, i = _objectWithoutPropertiesLoose(e, t);
@@ -726,13 +807,14 @@ function zeus(options = {}) {
726
807
  }
727
808
  function defineZeusRollupConfig(config = {}) {
728
809
  const { zeus: zeusOptions = {}, plugins, input, output, external } = config, rest = _objectWithoutProperties(config, _excluded);
729
- const pluginExternals = collectPluginExternals(zeusOptions);
810
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
730
811
  return _objectSpread2(_objectSpread2({ input: input !== null && input !== void 0 ? input : "src/index.ts" }, rest), {}, {
731
812
  external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
732
813
  plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
733
814
  output: output !== null && output !== void 0 ? output : {
734
815
  dir: "dist",
735
816
  format: "es",
817
+ chunkFileNames: "chunks/[name]-[hash].js",
736
818
  sourcemap: true
737
819
  }
738
820
  });
package/dist/vite.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * bundler-plugin v0.1.0-beta.2
2
+ * bundler-plugin v0.1.0-beta.4
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -189,6 +189,42 @@ async function fileExists(file) {
189
189
  }
190
190
  }
191
191
  //#endregion
192
+ //#region packages/web-c/bundler-plugin/src/external.ts
193
+ const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
194
+ function collectPluginExternals(options, collectOptions = {}) {
195
+ var _options$plugins;
196
+ const entries = [];
197
+ if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
198
+ for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
199
+ var _plugin$external;
200
+ for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
201
+ }
202
+ return uniqueExternalEntries(entries);
203
+ }
204
+ function mergeExternal(userExternal, pluginExternal) {
205
+ if (!userExternal) return pluginExternal;
206
+ if (typeof userExternal === "function") return (source, importer, isResolved) => {
207
+ return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
208
+ };
209
+ return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
210
+ }
211
+ function matchesExternal(source, entries) {
212
+ return entries.some((entry) => {
213
+ return typeof entry === "string" ? entry === source : entry.test(source);
214
+ });
215
+ }
216
+ function uniqueExternalEntries(entries) {
217
+ const seen = /* @__PURE__ */ new Set();
218
+ const result = [];
219
+ for (const entry of entries) {
220
+ const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
221
+ if (seen.has(key)) continue;
222
+ seen.add(key);
223
+ result.push(entry);
224
+ }
225
+ return result;
226
+ }
227
+ //#endregion
192
228
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
193
229
  function createOutputRegistry() {
194
230
  const map = /* @__PURE__ */ new Map();
@@ -370,9 +406,39 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
370
406
  let shouldCompileZeus = (_id) => false;
371
407
  let ctx;
372
408
  let root = process.cwd();
409
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
373
410
  const virtualModules = new VirtualModuleRegistry();
374
411
  return {
375
412
  name: resolvePluginName(target),
413
+ options(inputOptions) {
414
+ if (target === "vite") return null;
415
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
416
+ const shouldSetRolldownTarget = target === "rolldown";
417
+ if (!pluginExternals.length && !shouldSetRolldownTarget) return null;
418
+ const nextOptions = { ...inputOptions };
419
+ if (pluginExternals.length) nextOptions.external = mergeExternal(inputOptions.external, pluginExternals);
420
+ if (shouldSetRolldownTarget) {
421
+ var _transform;
422
+ nextOptions.transform = {
423
+ target: "es2016",
424
+ ...(_transform = inputOptions.transform) !== null && _transform !== void 0 ? _transform : {}
425
+ };
426
+ }
427
+ return nextOptions;
428
+ },
429
+ outputOptions(outputOptions) {
430
+ if (target === "vite") return null;
431
+ cleanOutputDir(outputOptions, {
432
+ root: resolveRoot(options.root),
433
+ enabled: options.clean !== false,
434
+ cleanedOutputDirs
435
+ });
436
+ if (outputOptions.chunkFileNames) return null;
437
+ return {
438
+ ...outputOptions,
439
+ chunkFileNames: "chunks/[name]-[hash].js"
440
+ };
441
+ },
376
442
  async buildStart() {
377
443
  var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
378
444
  virtualModules.clear();
@@ -437,6 +503,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
437
503
  id: resolvedVirtual,
438
504
  moduleSideEffects: "no-treeshake"
439
505
  };
506
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
507
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
508
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
509
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
510
+ id: "\0" + virtualEntryId,
511
+ moduleSideEffects: "no-treeshake"
512
+ };
513
+ }
440
514
  if (target === "rollup") {
441
515
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
442
516
  if (resolvedTs) return resolvedTs;
@@ -484,6 +558,31 @@ function resolveRoot(root) {
484
558
  if (typeof root === "function") return node_path.default.resolve(root());
485
559
  return node_path.default.resolve(root !== null && root !== void 0 ? root : process.cwd());
486
560
  }
561
+ function cleanOutputDir(outputOptions, options) {
562
+ if (!options.enabled) return;
563
+ const outputDir = resolveOutputDir(outputOptions, options.root);
564
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
565
+ if (options.cleanedOutputDirs.has(outputDir)) return;
566
+ options.cleanedOutputDirs.add(outputDir);
567
+ node_fs.default.rmSync(outputDir, {
568
+ recursive: true,
569
+ force: true
570
+ });
571
+ }
572
+ function resolveOutputDir(outputOptions, root) {
573
+ const dir = outputOptions.dir;
574
+ if (typeof dir === "string" && dir.length > 0) return node_path.default.resolve(root, dir);
575
+ const file = outputOptions.file;
576
+ if (typeof file === "string" && file.length > 0) return node_path.default.dirname(node_path.default.resolve(root, file));
577
+ return node_path.default.resolve(root, "dist");
578
+ }
579
+ function isSafeCleanTarget(outputDir, root) {
580
+ const resolvedRoot = node_path.default.resolve(root);
581
+ const resolvedOutputDir = node_path.default.resolve(outputDir);
582
+ if (resolvedOutputDir === resolvedRoot) return false;
583
+ const relative = node_path.default.relative(resolvedRoot, resolvedOutputDir);
584
+ return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
585
+ }
487
586
  async function createManifest(root, include, exclude) {
488
587
  if (!include.length) return {
489
588
  manifest: {
@@ -564,23 +663,11 @@ function emitVirtualEntries(modules, pluginContext) {
564
663
  });
565
664
  }
566
665
  }
567
- //#endregion
568
- //#region packages/web-c/bundler-plugin/src/external.ts
569
- function collectPluginExternals(options) {
570
- var _options$plugins;
571
- const set = /* @__PURE__ */ new Set();
572
- for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
573
- var _plugin$external;
574
- for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
575
- }
576
- return Array.from(set);
577
- }
578
- function mergeExternal(userExternal, pluginExternal) {
579
- if (!userExternal) return pluginExternal;
580
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
581
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
582
- };
583
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
666
+ function resolveVirtualEntryImport(id, importer) {
667
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
668
+ const lastColon = importer.lastIndexOf(":");
669
+ if (lastColon <= 0) return null;
670
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
584
671
  }
585
672
  //#endregion
586
673
  //#region packages/web-c/bundler-plugin/src/vite.ts