@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.
@@ -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);
@@ -719,20 +800,23 @@ const _excluded = [
719
800
  "plugins",
720
801
  "input",
721
802
  "output",
722
- "external"
803
+ "external",
804
+ "transform"
723
805
  ];
724
806
  function zeus(options = {}) {
725
807
  return createZeusBundlerPlugin(options, { target: "rolldown" });
726
808
  }
727
809
  function defineZeusRolldownConfig(config = {}) {
728
- const { zeus: zeusOptions = {}, plugins, input, output, external } = config, rest = _objectWithoutProperties(config, _excluded);
729
- const pluginExternals = collectPluginExternals(zeusOptions);
810
+ const { zeus: zeusOptions = {}, plugins, input, output, external, transform } = config, rest = _objectWithoutProperties(config, _excluded);
811
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
730
812
  return _objectSpread2(_objectSpread2({ input: input !== null && input !== void 0 ? input : "src/index.ts" }, rest), {}, {
731
813
  external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
732
814
  plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
815
+ transform: _objectSpread2({ target: "es2016" }, transform),
733
816
  output: output !== null && output !== void 0 ? output : {
734
817
  dir: "dist",
735
818
  format: "esm",
819
+ chunkFileNames: "chunks/[name]-[hash].js",
736
820
  sourcemap: true
737
821
  }
738
822
  });
@@ -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
  **/
@@ -187,6 +187,42 @@ async function fileExists(file) {
187
187
  }
188
188
  }
189
189
  //#endregion
190
+ //#region packages/web-c/bundler-plugin/src/external.ts
191
+ const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
192
+ function collectPluginExternals(options, collectOptions = {}) {
193
+ var _options$plugins;
194
+ const entries = [];
195
+ if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
196
+ for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
197
+ var _plugin$external;
198
+ for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
199
+ }
200
+ return uniqueExternalEntries(entries);
201
+ }
202
+ function mergeExternal(userExternal, pluginExternal) {
203
+ if (!userExternal) return pluginExternal;
204
+ if (typeof userExternal === "function") return (source, importer, isResolved) => {
205
+ return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
206
+ };
207
+ return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
208
+ }
209
+ function matchesExternal(source, entries) {
210
+ return entries.some((entry) => {
211
+ return typeof entry === "string" ? entry === source : entry.test(source);
212
+ });
213
+ }
214
+ function uniqueExternalEntries(entries) {
215
+ const seen = /* @__PURE__ */ new Set();
216
+ const result = [];
217
+ for (const entry of entries) {
218
+ const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
219
+ if (seen.has(key)) continue;
220
+ seen.add(key);
221
+ result.push(entry);
222
+ }
223
+ return result;
224
+ }
225
+ //#endregion
190
226
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
191
227
  function createOutputRegistry() {
192
228
  const map = /* @__PURE__ */ new Map();
@@ -368,9 +404,39 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
368
404
  let shouldCompileZeus = (_id) => false;
369
405
  let ctx;
370
406
  let root = process.cwd();
407
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
371
408
  const virtualModules = new VirtualModuleRegistry();
372
409
  return {
373
410
  name: resolvePluginName(target),
411
+ options(inputOptions) {
412
+ if (target === "vite") return null;
413
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
414
+ const shouldSetRolldownTarget = target === "rolldown";
415
+ if (!pluginExternals.length && !shouldSetRolldownTarget) return null;
416
+ const nextOptions = { ...inputOptions };
417
+ if (pluginExternals.length) nextOptions.external = mergeExternal(inputOptions.external, pluginExternals);
418
+ if (shouldSetRolldownTarget) {
419
+ var _transform;
420
+ nextOptions.transform = {
421
+ target: "es2016",
422
+ ...(_transform = inputOptions.transform) !== null && _transform !== void 0 ? _transform : {}
423
+ };
424
+ }
425
+ return nextOptions;
426
+ },
427
+ outputOptions(outputOptions) {
428
+ if (target === "vite") return null;
429
+ cleanOutputDir(outputOptions, {
430
+ root: resolveRoot(options.root),
431
+ enabled: options.clean !== false,
432
+ cleanedOutputDirs
433
+ });
434
+ if (outputOptions.chunkFileNames) return null;
435
+ return {
436
+ ...outputOptions,
437
+ chunkFileNames: "chunks/[name]-[hash].js"
438
+ };
439
+ },
374
440
  async buildStart() {
375
441
  var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
376
442
  virtualModules.clear();
@@ -435,6 +501,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
435
501
  id: resolvedVirtual,
436
502
  moduleSideEffects: "no-treeshake"
437
503
  };
504
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
505
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
506
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
507
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
508
+ id: "\0" + virtualEntryId,
509
+ moduleSideEffects: "no-treeshake"
510
+ };
511
+ }
438
512
  if (target === "rollup") {
439
513
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
440
514
  if (resolvedTs) return resolvedTs;
@@ -482,6 +556,31 @@ function resolveRoot(root) {
482
556
  if (typeof root === "function") return node_path.default.resolve(root());
483
557
  return node_path.default.resolve(root !== null && root !== void 0 ? root : process.cwd());
484
558
  }
559
+ function cleanOutputDir(outputOptions, options) {
560
+ if (!options.enabled) return;
561
+ const outputDir = resolveOutputDir(outputOptions, options.root);
562
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
563
+ if (options.cleanedOutputDirs.has(outputDir)) return;
564
+ options.cleanedOutputDirs.add(outputDir);
565
+ node_fs.default.rmSync(outputDir, {
566
+ recursive: true,
567
+ force: true
568
+ });
569
+ }
570
+ function resolveOutputDir(outputOptions, root) {
571
+ const dir = outputOptions.dir;
572
+ if (typeof dir === "string" && dir.length > 0) return node_path.default.resolve(root, dir);
573
+ const file = outputOptions.file;
574
+ if (typeof file === "string" && file.length > 0) return node_path.default.dirname(node_path.default.resolve(root, file));
575
+ return node_path.default.resolve(root, "dist");
576
+ }
577
+ function isSafeCleanTarget(outputDir, root) {
578
+ const resolvedRoot = node_path.default.resolve(root);
579
+ const resolvedOutputDir = node_path.default.resolve(outputDir);
580
+ if (resolvedOutputDir === resolvedRoot) return false;
581
+ const relative = node_path.default.relative(resolvedRoot, resolvedOutputDir);
582
+ return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
583
+ }
485
584
  async function createManifest(root, include, exclude) {
486
585
  if (!include.length) return {
487
586
  manifest: {
@@ -562,23 +661,11 @@ function emitVirtualEntries(modules, pluginContext) {
562
661
  });
563
662
  }
564
663
  }
565
- //#endregion
566
- //#region packages/web-c/bundler-plugin/src/external.ts
567
- function collectPluginExternals(options) {
568
- var _options$plugins;
569
- const set = /* @__PURE__ */ new Set();
570
- for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
571
- var _plugin$external;
572
- for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
573
- }
574
- return Array.from(set);
575
- }
576
- function mergeExternal(userExternal, pluginExternal) {
577
- if (!userExternal) return pluginExternal;
578
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
579
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
580
- };
581
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
664
+ function resolveVirtualEntryImport(id, importer) {
665
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
666
+ const lastColon = importer.lastIndexOf(":");
667
+ if (lastColon <= 0) return null;
668
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
582
669
  }
583
670
  //#endregion
584
671
  //#region packages/web-c/bundler-plugin/src/rollup.ts
@@ -587,7 +674,7 @@ function zeus(options = {}) {
587
674
  }
588
675
  function defineZeusRollupConfig(config = {}) {
589
676
  const { zeus: zeusOptions = {}, plugins, input, output, external, ...rest } = config;
590
- const pluginExternals = collectPluginExternals(zeusOptions);
677
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
591
678
  return {
592
679
  input: input !== null && input !== void 0 ? input : "src/index.ts",
593
680
  ...rest,
@@ -596,6 +683,7 @@ function defineZeusRollupConfig(config = {}) {
596
683
  output: output !== null && output !== void 0 ? output : {
597
684
  dir: "dist",
598
685
  format: "es",
686
+ chunkFileNames: "chunks/[name]-[hash].js",
599
687
  sourcemap: true
600
688
  }
601
689
  };
@@ -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
  **/
@@ -187,6 +187,42 @@ async function fileExists(file) {
187
187
  }
188
188
  }
189
189
  //#endregion
190
+ //#region packages/web-c/bundler-plugin/src/external.ts
191
+ const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
192
+ function collectPluginExternals(options, collectOptions = {}) {
193
+ var _options$plugins;
194
+ const entries = [];
195
+ if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
196
+ for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
197
+ var _plugin$external;
198
+ for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
199
+ }
200
+ return uniqueExternalEntries(entries);
201
+ }
202
+ function mergeExternal(userExternal, pluginExternal) {
203
+ if (!userExternal) return pluginExternal;
204
+ if (typeof userExternal === "function") return (source, importer, isResolved) => {
205
+ return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
206
+ };
207
+ return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
208
+ }
209
+ function matchesExternal(source, entries) {
210
+ return entries.some((entry) => {
211
+ return typeof entry === "string" ? entry === source : entry.test(source);
212
+ });
213
+ }
214
+ function uniqueExternalEntries(entries) {
215
+ const seen = /* @__PURE__ */ new Set();
216
+ const result = [];
217
+ for (const entry of entries) {
218
+ const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
219
+ if (seen.has(key)) continue;
220
+ seen.add(key);
221
+ result.push(entry);
222
+ }
223
+ return result;
224
+ }
225
+ //#endregion
190
226
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
191
227
  function createOutputRegistry() {
192
228
  const map = /* @__PURE__ */ new Map();
@@ -368,9 +404,39 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
368
404
  let shouldCompileZeus = (_id) => false;
369
405
  let ctx;
370
406
  let root = process.cwd();
407
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
371
408
  const virtualModules = new VirtualModuleRegistry();
372
409
  return {
373
410
  name: resolvePluginName(target),
411
+ options(inputOptions) {
412
+ if (target === "vite") return null;
413
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
414
+ const shouldSetRolldownTarget = target === "rolldown";
415
+ if (!pluginExternals.length && !shouldSetRolldownTarget) return null;
416
+ const nextOptions = { ...inputOptions };
417
+ if (pluginExternals.length) nextOptions.external = mergeExternal(inputOptions.external, pluginExternals);
418
+ if (shouldSetRolldownTarget) {
419
+ var _transform;
420
+ nextOptions.transform = {
421
+ target: "es2016",
422
+ ...(_transform = inputOptions.transform) !== null && _transform !== void 0 ? _transform : {}
423
+ };
424
+ }
425
+ return nextOptions;
426
+ },
427
+ outputOptions(outputOptions) {
428
+ if (target === "vite") return null;
429
+ cleanOutputDir(outputOptions, {
430
+ root: resolveRoot(options.root),
431
+ enabled: options.clean !== false,
432
+ cleanedOutputDirs
433
+ });
434
+ if (outputOptions.chunkFileNames) return null;
435
+ return {
436
+ ...outputOptions,
437
+ chunkFileNames: "chunks/[name]-[hash].js"
438
+ };
439
+ },
374
440
  async buildStart() {
375
441
  var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
376
442
  virtualModules.clear();
@@ -435,6 +501,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
435
501
  id: resolvedVirtual,
436
502
  moduleSideEffects: "no-treeshake"
437
503
  };
504
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
505
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
506
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
507
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
508
+ id: "\0" + virtualEntryId,
509
+ moduleSideEffects: "no-treeshake"
510
+ };
511
+ }
438
512
  if (target === "rollup") {
439
513
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
440
514
  if (resolvedTs) return resolvedTs;
@@ -482,6 +556,31 @@ function resolveRoot(root) {
482
556
  if (typeof root === "function") return node_path.default.resolve(root());
483
557
  return node_path.default.resolve(root !== null && root !== void 0 ? root : process.cwd());
484
558
  }
559
+ function cleanOutputDir(outputOptions, options) {
560
+ if (!options.enabled) return;
561
+ const outputDir = resolveOutputDir(outputOptions, options.root);
562
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
563
+ if (options.cleanedOutputDirs.has(outputDir)) return;
564
+ options.cleanedOutputDirs.add(outputDir);
565
+ node_fs.default.rmSync(outputDir, {
566
+ recursive: true,
567
+ force: true
568
+ });
569
+ }
570
+ function resolveOutputDir(outputOptions, root) {
571
+ const dir = outputOptions.dir;
572
+ if (typeof dir === "string" && dir.length > 0) return node_path.default.resolve(root, dir);
573
+ const file = outputOptions.file;
574
+ if (typeof file === "string" && file.length > 0) return node_path.default.dirname(node_path.default.resolve(root, file));
575
+ return node_path.default.resolve(root, "dist");
576
+ }
577
+ function isSafeCleanTarget(outputDir, root) {
578
+ const resolvedRoot = node_path.default.resolve(root);
579
+ const resolvedOutputDir = node_path.default.resolve(outputDir);
580
+ if (resolvedOutputDir === resolvedRoot) return false;
581
+ const relative = node_path.default.relative(resolvedRoot, resolvedOutputDir);
582
+ return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
583
+ }
485
584
  async function createManifest(root, include, exclude) {
486
585
  if (!include.length) return {
487
586
  manifest: {
@@ -562,23 +661,11 @@ function emitVirtualEntries(modules, pluginContext) {
562
661
  });
563
662
  }
564
663
  }
565
- //#endregion
566
- //#region packages/web-c/bundler-plugin/src/external.ts
567
- function collectPluginExternals(options) {
568
- var _options$plugins;
569
- const set = /* @__PURE__ */ new Set();
570
- for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
571
- var _plugin$external;
572
- for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
573
- }
574
- return Array.from(set);
575
- }
576
- function mergeExternal(userExternal, pluginExternal) {
577
- if (!userExternal) return pluginExternal;
578
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
579
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
580
- };
581
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
664
+ function resolveVirtualEntryImport(id, importer) {
665
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
666
+ const lastColon = importer.lastIndexOf(":");
667
+ if (lastColon <= 0) return null;
668
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
582
669
  }
583
670
  //#endregion
584
671
  //#region packages/web-c/bundler-plugin/src/rollup.ts
@@ -587,7 +674,7 @@ function zeus(options = {}) {
587
674
  }
588
675
  function defineZeusRollupConfig(config = {}) {
589
676
  const { zeus: zeusOptions = {}, plugins, input, output, external, ...rest } = config;
590
- const pluginExternals = collectPluginExternals(zeusOptions);
677
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
591
678
  return {
592
679
  input: input !== null && input !== void 0 ? input : "src/index.ts",
593
680
  ...rest,
@@ -596,6 +683,7 @@ function defineZeusRollupConfig(config = {}) {
596
683
  output: output !== null && output !== void 0 ? output : {
597
684
  dir: "dist",
598
685
  format: "es",
686
+ chunkFileNames: "chunks/[name]-[hash].js",
599
687
  sourcemap: true
600
688
  }
601
689
  };
package/dist/rollup.d.ts CHANGED
@@ -78,7 +78,7 @@ interface ZeusComponentPlugin {
78
78
  * Used by the Vite adapter, defineZeusRollupConfig(), and
79
79
  * defineZeusRolldownConfig().
80
80
  */
81
- external?: string[];
81
+ external?: Array<string | RegExp>;
82
82
  }
83
83
  interface ZeusBundlerPluginOptions {
84
84
  /**
@@ -136,6 +136,14 @@ interface ZeusBundlerPluginOptions {
136
136
  * - vite: false
137
137
  */
138
138
  transpile?: boolean;
139
+ /**
140
+ * Clean the resolved Rollup/Rolldown output directory before writing.
141
+ *
142
+ * Vite keeps using its own emptyOutDir behavior.
143
+ *
144
+ * @default true
145
+ */
146
+ clean?: boolean;
139
147
  /**
140
148
  * Rollup adapter only. Additional extensions to try when resolving imports.
141
149
  * Set to `false` to disable extension resolution.