@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
  **/
@@ -12,6 +12,8 @@ import fs$1 from "node:fs/promises";
12
12
  import { transformAsync } from "@babel/core";
13
13
  import presetTypeScript from "@babel/preset-typescript";
14
14
  import zeusCompiler from "@zeus-js/compiler";
15
+ import { createRequire } from "node:module";
16
+ import { mergeConfig } from "vite";
15
17
  //#region packages/web-c/bundler-plugin/src/filter.ts
16
18
  function cleanUrl(id) {
17
19
  return id.replace(/[?#].*$/, "");
@@ -78,7 +80,7 @@ function hasErrorDiagnostics(diagnostics) {
78
80
  return diagnostics.some((item) => item.level === "error");
79
81
  }
80
82
  //#endregion
81
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/asyncToGenerator.js
83
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/asyncToGenerator.js
82
84
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
83
85
  try {
84
86
  var i = n[a](c), u = i.value;
@@ -104,7 +106,7 @@ function _asyncToGenerator(n) {
104
106
  };
105
107
  }
106
108
  //#endregion
107
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
109
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
108
110
  function _typeof(o) {
109
111
  "@babel/helpers - typeof";
110
112
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -114,7 +116,7 @@ function _typeof(o) {
114
116
  }, _typeof(o);
115
117
  }
116
118
  //#endregion
117
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
119
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
118
120
  function toPrimitive(t, r) {
119
121
  if ("object" != _typeof(t) || !t) return t;
120
122
  var e = t[Symbol.toPrimitive];
@@ -126,13 +128,13 @@ function toPrimitive(t, r) {
126
128
  return ("string" === r ? String : Number)(t);
127
129
  }
128
130
  //#endregion
129
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
131
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
130
132
  function toPropertyKey(t) {
131
133
  var i = toPrimitive(t, "string");
132
134
  return "symbol" == _typeof(i) ? i : i + "";
133
135
  }
134
136
  //#endregion
135
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
137
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
136
138
  function _defineProperty(e, r, t) {
137
139
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
138
140
  value: t,
@@ -142,7 +144,7 @@ function _defineProperty(e, r, t) {
142
144
  }) : e[r] = t, e;
143
145
  }
144
146
  //#endregion
145
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectSpread2.js
147
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectSpread2.js
146
148
  function ownKeys(e, r) {
147
149
  var t = Object.keys(e);
148
150
  if (Object.getOwnPropertySymbols) {
@@ -272,6 +274,42 @@ function _fileExists() {
272
274
  return _fileExists.apply(this, arguments);
273
275
  }
274
276
  //#endregion
277
+ //#region packages/web-c/bundler-plugin/src/external.ts
278
+ const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
279
+ function collectPluginExternals(options, collectOptions = {}) {
280
+ var _options$plugins;
281
+ const entries = [];
282
+ if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
283
+ for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
284
+ var _plugin$external;
285
+ for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
286
+ }
287
+ return uniqueExternalEntries(entries);
288
+ }
289
+ function mergeExternal(userExternal, pluginExternal) {
290
+ if (!userExternal) return pluginExternal;
291
+ if (typeof userExternal === "function") return (source, importer, isResolved) => {
292
+ return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
293
+ };
294
+ return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
295
+ }
296
+ function matchesExternal(source, entries) {
297
+ return entries.some((entry) => {
298
+ return typeof entry === "string" ? entry === source : entry.test(source);
299
+ });
300
+ }
301
+ function uniqueExternalEntries(entries) {
302
+ const seen = /* @__PURE__ */ new Set();
303
+ const result = [];
304
+ for (const entry of entries) {
305
+ const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
306
+ if (seen.has(key)) continue;
307
+ seen.add(key);
308
+ result.push(entry);
309
+ }
310
+ return result;
311
+ }
312
+ //#endregion
275
313
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
276
314
  function createOutputRegistry() {
277
315
  const map = /* @__PURE__ */ new Map();
@@ -458,9 +496,33 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
458
496
  let shouldCompileZeus = (_id) => false;
459
497
  let ctx;
460
498
  let root = process.cwd();
499
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
461
500
  const virtualModules = new VirtualModuleRegistry();
462
501
  return {
463
502
  name: resolvePluginName(target),
503
+ options(inputOptions) {
504
+ if (target === "vite") return null;
505
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
506
+ const shouldSetRolldownTarget = target === "rolldown";
507
+ if (!pluginExternals.length && !shouldSetRolldownTarget) return null;
508
+ const nextOptions = _objectSpread2({}, inputOptions);
509
+ if (pluginExternals.length) nextOptions.external = mergeExternal(inputOptions.external, pluginExternals);
510
+ if (shouldSetRolldownTarget) {
511
+ var _transform;
512
+ nextOptions.transform = _objectSpread2({ target: "es2016" }, (_transform = inputOptions.transform) !== null && _transform !== void 0 ? _transform : {});
513
+ }
514
+ return nextOptions;
515
+ },
516
+ outputOptions(outputOptions) {
517
+ if (target === "vite") return null;
518
+ cleanOutputDir(outputOptions, {
519
+ root: resolveRoot(options.root),
520
+ enabled: options.clean !== false,
521
+ cleanedOutputDirs
522
+ });
523
+ if (outputOptions.chunkFileNames) return null;
524
+ return _objectSpread2(_objectSpread2({}, outputOptions), {}, { chunkFileNames: "chunks/[name]-[hash].js" });
525
+ },
464
526
  buildStart() {
465
527
  var _this = this;
466
528
  return _asyncToGenerator(function* () {
@@ -528,6 +590,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
528
590
  id: resolvedVirtual,
529
591
  moduleSideEffects: "no-treeshake"
530
592
  };
593
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
594
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
595
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
596
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
597
+ id: "\0" + virtualEntryId,
598
+ moduleSideEffects: "no-treeshake"
599
+ };
600
+ }
531
601
  if (target === "rollup") {
532
602
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
533
603
  if (resolvedTs) return resolvedTs;
@@ -580,6 +650,31 @@ function resolveRoot(root) {
580
650
  if (typeof root === "function") return path.resolve(root());
581
651
  return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
582
652
  }
653
+ function cleanOutputDir(outputOptions, options) {
654
+ if (!options.enabled) return;
655
+ const outputDir = resolveOutputDir(outputOptions, options.root);
656
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
657
+ if (options.cleanedOutputDirs.has(outputDir)) return;
658
+ options.cleanedOutputDirs.add(outputDir);
659
+ fs.rmSync(outputDir, {
660
+ recursive: true,
661
+ force: true
662
+ });
663
+ }
664
+ function resolveOutputDir(outputOptions, root) {
665
+ const dir = outputOptions.dir;
666
+ if (typeof dir === "string" && dir.length > 0) return path.resolve(root, dir);
667
+ const file = outputOptions.file;
668
+ if (typeof file === "string" && file.length > 0) return path.dirname(path.resolve(root, file));
669
+ return path.resolve(root, "dist");
670
+ }
671
+ function isSafeCleanTarget(outputDir, root) {
672
+ const resolvedRoot = path.resolve(root);
673
+ const resolvedOutputDir = path.resolve(outputDir);
674
+ if (resolvedOutputDir === resolvedRoot) return false;
675
+ const relative = path.relative(resolvedRoot, resolvedOutputDir);
676
+ return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
677
+ }
583
678
  function createManifest(_x, _x2, _x3) {
584
679
  return _createManifest.apply(this, arguments);
585
680
  }
@@ -672,20 +767,159 @@ function emitVirtualEntries(modules, pluginContext) {
672
767
  });
673
768
  }
674
769
  }
770
+ function resolveVirtualEntryImport(id, importer) {
771
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
772
+ const lastColon = importer.lastIndexOf(":");
773
+ if (lastColon <= 0) return null;
774
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
775
+ }
675
776
  //#endregion
676
- //#region packages/web-c/bundler-plugin/src/external.ts
677
- function mergeExternal(userExternal, pluginExternal) {
678
- if (!userExternal) return pluginExternal;
679
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
680
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
681
- };
682
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
777
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectWithoutPropertiesLoose.js
778
+ function _objectWithoutPropertiesLoose(r, e) {
779
+ if (null == r) return {};
780
+ var t = {};
781
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
782
+ if (e.includes(n)) continue;
783
+ t[n] = r[n];
784
+ }
785
+ return t;
786
+ }
787
+ //#endregion
788
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectWithoutProperties.js
789
+ function _objectWithoutProperties(e, t) {
790
+ if (null == e) return {};
791
+ var o, r, i = _objectWithoutPropertiesLoose(e, t);
792
+ if (Object.getOwnPropertySymbols) {
793
+ var s = Object.getOwnPropertySymbols(e);
794
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
795
+ }
796
+ return i;
683
797
  }
684
798
  //#endregion
685
799
  //#region packages/web-c/bundler-plugin/src/rollup.ts
686
- function zeus(options = {}) {
800
+ const _excluded$1 = [
801
+ "zeus",
802
+ "plugins",
803
+ "input",
804
+ "output",
805
+ "external"
806
+ ];
807
+ function zeus$1(options = {}) {
687
808
  return createZeusBundlerPlugin(options, { target: "rollup" });
688
809
  }
810
+ function defineZeusRollupConfig(config = {}) {
811
+ const { zeus: zeusOptions = {}, plugins, input, output, external } = config, rest = _objectWithoutProperties(config, _excluded$1);
812
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
813
+ return _objectSpread2(_objectSpread2({ input: input !== null && input !== void 0 ? input : "src/index.ts" }, rest), {}, {
814
+ external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
815
+ plugins: [zeus$1(zeusOptions), ...normalizePlugins$1(plugins)],
816
+ output: output !== null && output !== void 0 ? output : {
817
+ dir: "dist",
818
+ format: "es",
819
+ chunkFileNames: "chunks/[name]-[hash].js",
820
+ sourcemap: true
821
+ }
822
+ });
823
+ }
824
+ function normalizePlugins$1(plugins) {
825
+ if (!plugins) return [];
826
+ return Array.isArray(plugins) ? plugins.filter(Boolean) : [plugins].filter(Boolean);
827
+ }
828
+ //#endregion
829
+ //#region packages/web-c/bundler-plugin/src/vite.ts
830
+ function createZeusVitePlugin(options = {}) {
831
+ var _options$root, _options$transpile;
832
+ let resolvedConfig;
833
+ return _objectSpread2(_objectSpread2({}, createZeusBundlerPlugin(_objectSpread2(_objectSpread2({}, options), {}, {
834
+ root: (_options$root = options.root) !== null && _options$root !== void 0 ? _options$root : (() => {
835
+ var _resolvedConfig$root;
836
+ return (_resolvedConfig$root = resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.root) !== null && _resolvedConfig$root !== void 0 ? _resolvedConfig$root : process.cwd();
837
+ }),
838
+ transpile: (_options$transpile = options.transpile) !== null && _options$transpile !== void 0 ? _options$transpile : false
839
+ }), { target: "vite" })), {}, {
840
+ name: "vite-plugin-zeus",
841
+ enforce: "pre",
842
+ config(userConfig) {
843
+ return _asyncToGenerator(function* () {
844
+ var _userConfig$build;
845
+ const runtimeDomEntry = resolveRuntimeDOMEntry(userConfig.root);
846
+ const pluginExternals = collectPluginExternals(options);
847
+ const pluginConfig = _objectSpread2(_objectSpread2({}, (yield isRolldownVite()) ? { oxc: { jsx: "preserve" } } : { esbuild: { jsx: "preserve" } }), {}, { resolve: {
848
+ alias: runtimeDomEntry ? { "@zeus-js/runtime-dom": runtimeDomEntry } : void 0,
849
+ dedupe: [
850
+ "@zeus-js/signal",
851
+ "@zeus-js/runtime-dom",
852
+ "@zeus-js/zeus",
853
+ "@zeus-js/component-dts"
854
+ ]
855
+ } });
856
+ if (!pluginExternals.length) return pluginConfig;
857
+ return mergeConfig(pluginConfig, { build: { rollupOptions: { external: mergeExternal((_userConfig$build = userConfig.build) === null || _userConfig$build === void 0 || (_userConfig$build = _userConfig$build.rollupOptions) === null || _userConfig$build === void 0 ? void 0 : _userConfig$build.external, pluginExternals) } } });
858
+ })();
859
+ },
860
+ configResolved(config) {
861
+ resolvedConfig = config;
862
+ }
863
+ });
864
+ }
865
+ function isRolldownVite() {
866
+ return _isRolldownVite.apply(this, arguments);
867
+ }
868
+ function _isRolldownVite() {
869
+ _isRolldownVite = _asyncToGenerator(function* () {
870
+ try {
871
+ const vite = yield import("vite");
872
+ return typeof vite.rolldownVersion === "string" || typeof vite.transformWithOxc === "function";
873
+ } catch (_unused) {
874
+ return false;
875
+ }
876
+ });
877
+ return _isRolldownVite.apply(this, arguments);
878
+ }
879
+ function resolveRuntimeDOMEntry(root) {
880
+ const projectRoot = path.resolve(process.cwd(), root !== null && root !== void 0 ? root : ".");
881
+ const requireFromProject = createRequire(path.join(projectRoot, "package.json"));
882
+ try {
883
+ return requireFromProject.resolve("@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js");
884
+ } catch (_unused2) {}
885
+ try {
886
+ return createRequire(requireFromProject.resolve("@zeus-js/zeus")).resolve("@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js");
887
+ } catch (_unused3) {
888
+ return;
889
+ }
890
+ }
891
+ //#endregion
892
+ //#region packages/web-c/bundler-plugin/src/rolldown.ts
893
+ const _excluded = [
894
+ "zeus",
895
+ "plugins",
896
+ "input",
897
+ "output",
898
+ "external",
899
+ "transform"
900
+ ];
901
+ function zeus(options = {}) {
902
+ return createZeusBundlerPlugin(options, { target: "rolldown" });
903
+ }
904
+ function defineZeusRolldownConfig(config = {}) {
905
+ const { zeus: zeusOptions = {}, plugins, input, output, external, transform } = config, rest = _objectWithoutProperties(config, _excluded);
906
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
907
+ return _objectSpread2(_objectSpread2({ input: input !== null && input !== void 0 ? input : "src/index.ts" }, rest), {}, {
908
+ external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
909
+ plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
910
+ transform: _objectSpread2({ target: "es2016" }, transform),
911
+ output: output !== null && output !== void 0 ? output : {
912
+ dir: "dist",
913
+ format: "esm",
914
+ chunkFileNames: "chunks/[name]-[hash].js",
915
+ sourcemap: true
916
+ }
917
+ });
918
+ }
919
+ function normalizePlugins(plugins) {
920
+ if (!plugins) return [];
921
+ return Array.isArray(plugins) ? plugins.filter(Boolean) : [plugins].filter(Boolean);
922
+ }
689
923
  //#endregion
690
924
  //#region packages/web-c/bundler-plugin/src/pluginOptions.ts
691
925
  function resolvePluginDts(value, ctx) {
@@ -694,4 +928,4 @@ function resolvePluginDts(value, ctx) {
694
928
  return ctx.dts.enabled;
695
929
  }
696
930
  //#endregion
697
- export { createOutputRegistry, zeus as default, zeus, mergeExternal, resolveComponentExclude, resolveComponentInclude, resolvePluginDts };
931
+ export { createOutputRegistry, zeus as createZeusRolldownPlugin, zeus$1 as createZeusRollupPlugin, zeus$1 as default, zeus$1 as zeus, createZeusVitePlugin, defineZeusRolldownConfig, defineZeusRollupConfig, mergeExternal, resolveComponentExclude, resolveComponentInclude, resolvePluginDts };
@@ -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
  **/
@@ -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
  **/
@@ -75,7 +75,7 @@ interface ZeusComponentPlugin {
75
75
  * Used by the Vite adapter, defineZeusRollupConfig(), and
76
76
  * defineZeusRolldownConfig().
77
77
  */
78
- external?: string[];
78
+ external?: Array<string | RegExp>;
79
79
  }
80
80
 
81
81
  export interface ManifestOutputOptions {
@@ -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
  **/
@@ -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
  **/
@@ -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/rolldown.ts
@@ -586,16 +673,21 @@ function zeus(options = {}) {
586
673
  return createZeusBundlerPlugin(options, { target: "rolldown" });
587
674
  }
588
675
  function defineZeusRolldownConfig(config = {}) {
589
- const { zeus: zeusOptions = {}, plugins, input, output, external, ...rest } = config;
590
- const pluginExternals = collectPluginExternals(zeusOptions);
676
+ const { zeus: zeusOptions = {}, plugins, input, output, external, transform, ...rest } = config;
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,
594
681
  external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
595
682
  plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
683
+ transform: {
684
+ target: "es2016",
685
+ ...transform
686
+ },
596
687
  output: output !== null && output !== void 0 ? output : {
597
688
  dir: "dist",
598
689
  format: "esm",
690
+ chunkFileNames: "chunks/[name]-[hash].js",
599
691
  sourcemap: true
600
692
  }
601
693
  };