@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
  **/
@@ -45,6 +45,8 @@ let _babel_preset_typescript = require("@babel/preset-typescript");
45
45
  _babel_preset_typescript = __toESM(_babel_preset_typescript, 1);
46
46
  let _zeus_js_compiler = require("@zeus-js/compiler");
47
47
  _zeus_js_compiler = __toESM(_zeus_js_compiler, 1);
48
+ let node_module = require("node:module");
49
+ let vite = require("vite");
48
50
  //#region packages/web-c/bundler-plugin/src/filter.ts
49
51
  function cleanUrl(id) {
50
52
  return id.replace(/[?#].*$/, "");
@@ -187,6 +189,42 @@ async function fileExists(file) {
187
189
  }
188
190
  }
189
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
190
228
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
191
229
  function createOutputRegistry() {
192
230
  const map = /* @__PURE__ */ new Map();
@@ -368,9 +406,39 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
368
406
  let shouldCompileZeus = (_id) => false;
369
407
  let ctx;
370
408
  let root = process.cwd();
409
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
371
410
  const virtualModules = new VirtualModuleRegistry();
372
411
  return {
373
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
+ },
374
442
  async buildStart() {
375
443
  var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
376
444
  virtualModules.clear();
@@ -435,6 +503,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
435
503
  id: resolvedVirtual,
436
504
  moduleSideEffects: "no-treeshake"
437
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
+ }
438
514
  if (target === "rollup") {
439
515
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
440
516
  if (resolvedTs) return resolvedTs;
@@ -482,6 +558,31 @@ function resolveRoot(root) {
482
558
  if (typeof root === "function") return node_path.default.resolve(root());
483
559
  return node_path.default.resolve(root !== null && root !== void 0 ? root : process.cwd());
484
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
+ }
485
586
  async function createManifest(root, include, exclude) {
486
587
  if (!include.length) return {
487
588
  manifest: {
@@ -562,19 +663,125 @@ function emitVirtualEntries(modules, pluginContext) {
562
663
  });
563
664
  }
564
665
  }
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}`;
671
+ }
565
672
  //#endregion
566
- //#region packages/web-c/bundler-plugin/src/external.ts
567
- function mergeExternal(userExternal, pluginExternal) {
568
- if (!userExternal) return pluginExternal;
569
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
570
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
673
+ //#region packages/web-c/bundler-plugin/src/rollup.ts
674
+ function zeus$1(options = {}) {
675
+ return createZeusBundlerPlugin(options, { target: "rollup" });
676
+ }
677
+ function defineZeusRollupConfig(config = {}) {
678
+ const { zeus: zeusOptions = {}, plugins, input, output, external, ...rest } = config;
679
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
680
+ return {
681
+ input: input !== null && input !== void 0 ? input : "src/index.ts",
682
+ ...rest,
683
+ external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
684
+ plugins: [zeus$1(zeusOptions), ...normalizePlugins$1(plugins)],
685
+ output: output !== null && output !== void 0 ? output : {
686
+ dir: "dist",
687
+ format: "es",
688
+ chunkFileNames: "chunks/[name]-[hash].js",
689
+ sourcemap: true
690
+ }
571
691
  };
572
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
692
+ }
693
+ function normalizePlugins$1(plugins) {
694
+ if (!plugins) return [];
695
+ return Array.isArray(plugins) ? plugins.filter(Boolean) : [plugins].filter(Boolean);
573
696
  }
574
697
  //#endregion
575
- //#region packages/web-c/bundler-plugin/src/rollup.ts
698
+ //#region packages/web-c/bundler-plugin/src/vite.ts
699
+ function createZeusVitePlugin(options = {}) {
700
+ var _options$root, _options$transpile;
701
+ let resolvedConfig;
702
+ return {
703
+ ...createZeusBundlerPlugin({
704
+ ...options,
705
+ root: (_options$root = options.root) !== null && _options$root !== void 0 ? _options$root : (() => {
706
+ var _resolvedConfig$root;
707
+ return (_resolvedConfig$root = resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.root) !== null && _resolvedConfig$root !== void 0 ? _resolvedConfig$root : process.cwd();
708
+ }),
709
+ transpile: (_options$transpile = options.transpile) !== null && _options$transpile !== void 0 ? _options$transpile : false
710
+ }, { target: "vite" }),
711
+ name: "vite-plugin-zeus",
712
+ enforce: "pre",
713
+ async config(userConfig) {
714
+ var _userConfig$build;
715
+ const runtimeDomEntry = resolveRuntimeDOMEntry(userConfig.root);
716
+ const pluginExternals = collectPluginExternals(options);
717
+ const pluginConfig = {
718
+ ...await isRolldownVite() ? { oxc: { jsx: "preserve" } } : { esbuild: { jsx: "preserve" } },
719
+ resolve: {
720
+ alias: runtimeDomEntry ? { "@zeus-js/runtime-dom": runtimeDomEntry } : void 0,
721
+ dedupe: [
722
+ "@zeus-js/signal",
723
+ "@zeus-js/runtime-dom",
724
+ "@zeus-js/zeus",
725
+ "@zeus-js/component-dts"
726
+ ]
727
+ }
728
+ };
729
+ if (!pluginExternals.length) return pluginConfig;
730
+ return (0, vite.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) } } });
731
+ },
732
+ configResolved(config) {
733
+ resolvedConfig = config;
734
+ }
735
+ };
736
+ }
737
+ async function isRolldownVite() {
738
+ try {
739
+ const vite$1 = await import("vite");
740
+ return typeof vite$1.rolldownVersion === "string" || typeof vite$1.transformWithOxc === "function";
741
+ } catch {
742
+ return false;
743
+ }
744
+ }
745
+ function resolveRuntimeDOMEntry(root) {
746
+ const projectRoot = node_path.default.resolve(process.cwd(), root !== null && root !== void 0 ? root : ".");
747
+ const requireFromProject = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
748
+ try {
749
+ return requireFromProject.resolve("@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js");
750
+ } catch {}
751
+ try {
752
+ return (0, node_module.createRequire)(requireFromProject.resolve("@zeus-js/zeus")).resolve("@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js");
753
+ } catch {
754
+ return;
755
+ }
756
+ }
757
+ //#endregion
758
+ //#region packages/web-c/bundler-plugin/src/rolldown.ts
576
759
  function zeus(options = {}) {
577
- return createZeusBundlerPlugin(options, { target: "rollup" });
760
+ return createZeusBundlerPlugin(options, { target: "rolldown" });
761
+ }
762
+ function defineZeusRolldownConfig(config = {}) {
763
+ const { zeus: zeusOptions = {}, plugins, input, output, external, transform, ...rest } = config;
764
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
765
+ return {
766
+ input: input !== null && input !== void 0 ? input : "src/index.ts",
767
+ ...rest,
768
+ external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
769
+ plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
770
+ transform: {
771
+ target: "es2016",
772
+ ...transform
773
+ },
774
+ output: output !== null && output !== void 0 ? output : {
775
+ dir: "dist",
776
+ format: "esm",
777
+ chunkFileNames: "chunks/[name]-[hash].js",
778
+ sourcemap: true
779
+ }
780
+ };
781
+ }
782
+ function normalizePlugins(plugins) {
783
+ if (!plugins) return [];
784
+ return Array.isArray(plugins) ? plugins.filter(Boolean) : [plugins].filter(Boolean);
578
785
  }
579
786
  //#endregion
580
787
  //#region packages/web-c/bundler-plugin/src/pluginOptions.ts
@@ -585,9 +792,14 @@ function resolvePluginDts(value, ctx) {
585
792
  }
586
793
  //#endregion
587
794
  exports.createOutputRegistry = createOutputRegistry;
588
- exports.default = zeus;
795
+ exports.createZeusRolldownPlugin = zeus;
796
+ exports.createZeusRollupPlugin = zeus$1;
797
+ exports.createZeusVitePlugin = createZeusVitePlugin;
798
+ exports.default = zeus$1;
799
+ exports.defineZeusRolldownConfig = defineZeusRolldownConfig;
800
+ exports.defineZeusRollupConfig = defineZeusRollupConfig;
589
801
  exports.mergeExternal = mergeExternal;
590
802
  exports.resolveComponentExclude = resolveComponentExclude;
591
803
  exports.resolveComponentInclude = resolveComponentInclude;
592
804
  exports.resolvePluginDts = resolvePluginDts;
593
- exports.zeus = zeus;
805
+ exports.zeus = zeus$1;
@@ -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
  **/
@@ -45,6 +45,8 @@ let _babel_preset_typescript = require("@babel/preset-typescript");
45
45
  _babel_preset_typescript = __toESM(_babel_preset_typescript, 1);
46
46
  let _zeus_js_compiler = require("@zeus-js/compiler");
47
47
  _zeus_js_compiler = __toESM(_zeus_js_compiler, 1);
48
+ let node_module = require("node:module");
49
+ let vite = require("vite");
48
50
  //#region packages/web-c/bundler-plugin/src/filter.ts
49
51
  function cleanUrl(id) {
50
52
  return id.replace(/[?#].*$/, "");
@@ -187,6 +189,42 @@ async function fileExists(file) {
187
189
  }
188
190
  }
189
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
190
228
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
191
229
  function createOutputRegistry() {
192
230
  const map = /* @__PURE__ */ new Map();
@@ -368,9 +406,39 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
368
406
  let shouldCompileZeus = (_id) => false;
369
407
  let ctx;
370
408
  let root = process.cwd();
409
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
371
410
  const virtualModules = new VirtualModuleRegistry();
372
411
  return {
373
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
+ },
374
442
  async buildStart() {
375
443
  var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
376
444
  virtualModules.clear();
@@ -435,6 +503,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
435
503
  id: resolvedVirtual,
436
504
  moduleSideEffects: "no-treeshake"
437
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
+ }
438
514
  if (target === "rollup") {
439
515
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
440
516
  if (resolvedTs) return resolvedTs;
@@ -482,6 +558,31 @@ function resolveRoot(root) {
482
558
  if (typeof root === "function") return node_path.default.resolve(root());
483
559
  return node_path.default.resolve(root !== null && root !== void 0 ? root : process.cwd());
484
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
+ }
485
586
  async function createManifest(root, include, exclude) {
486
587
  if (!include.length) return {
487
588
  manifest: {
@@ -562,19 +663,125 @@ function emitVirtualEntries(modules, pluginContext) {
562
663
  });
563
664
  }
564
665
  }
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}`;
671
+ }
565
672
  //#endregion
566
- //#region packages/web-c/bundler-plugin/src/external.ts
567
- function mergeExternal(userExternal, pluginExternal) {
568
- if (!userExternal) return pluginExternal;
569
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
570
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
673
+ //#region packages/web-c/bundler-plugin/src/rollup.ts
674
+ function zeus$1(options = {}) {
675
+ return createZeusBundlerPlugin(options, { target: "rollup" });
676
+ }
677
+ function defineZeusRollupConfig(config = {}) {
678
+ const { zeus: zeusOptions = {}, plugins, input, output, external, ...rest } = config;
679
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
680
+ return {
681
+ input: input !== null && input !== void 0 ? input : "src/index.ts",
682
+ ...rest,
683
+ external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
684
+ plugins: [zeus$1(zeusOptions), ...normalizePlugins$1(plugins)],
685
+ output: output !== null && output !== void 0 ? output : {
686
+ dir: "dist",
687
+ format: "es",
688
+ chunkFileNames: "chunks/[name]-[hash].js",
689
+ sourcemap: true
690
+ }
571
691
  };
572
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
692
+ }
693
+ function normalizePlugins$1(plugins) {
694
+ if (!plugins) return [];
695
+ return Array.isArray(plugins) ? plugins.filter(Boolean) : [plugins].filter(Boolean);
573
696
  }
574
697
  //#endregion
575
- //#region packages/web-c/bundler-plugin/src/rollup.ts
698
+ //#region packages/web-c/bundler-plugin/src/vite.ts
699
+ function createZeusVitePlugin(options = {}) {
700
+ var _options$root, _options$transpile;
701
+ let resolvedConfig;
702
+ return {
703
+ ...createZeusBundlerPlugin({
704
+ ...options,
705
+ root: (_options$root = options.root) !== null && _options$root !== void 0 ? _options$root : (() => {
706
+ var _resolvedConfig$root;
707
+ return (_resolvedConfig$root = resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.root) !== null && _resolvedConfig$root !== void 0 ? _resolvedConfig$root : process.cwd();
708
+ }),
709
+ transpile: (_options$transpile = options.transpile) !== null && _options$transpile !== void 0 ? _options$transpile : false
710
+ }, { target: "vite" }),
711
+ name: "vite-plugin-zeus",
712
+ enforce: "pre",
713
+ async config(userConfig) {
714
+ var _userConfig$build;
715
+ const runtimeDomEntry = resolveRuntimeDOMEntry(userConfig.root);
716
+ const pluginExternals = collectPluginExternals(options);
717
+ const pluginConfig = {
718
+ ...await isRolldownVite() ? { oxc: { jsx: "preserve" } } : { esbuild: { jsx: "preserve" } },
719
+ resolve: {
720
+ alias: runtimeDomEntry ? { "@zeus-js/runtime-dom": runtimeDomEntry } : void 0,
721
+ dedupe: [
722
+ "@zeus-js/signal",
723
+ "@zeus-js/runtime-dom",
724
+ "@zeus-js/zeus",
725
+ "@zeus-js/component-dts"
726
+ ]
727
+ }
728
+ };
729
+ if (!pluginExternals.length) return pluginConfig;
730
+ return (0, vite.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) } } });
731
+ },
732
+ configResolved(config) {
733
+ resolvedConfig = config;
734
+ }
735
+ };
736
+ }
737
+ async function isRolldownVite() {
738
+ try {
739
+ const vite$1 = await import("vite");
740
+ return typeof vite$1.rolldownVersion === "string" || typeof vite$1.transformWithOxc === "function";
741
+ } catch {
742
+ return false;
743
+ }
744
+ }
745
+ function resolveRuntimeDOMEntry(root) {
746
+ const projectRoot = node_path.default.resolve(process.cwd(), root !== null && root !== void 0 ? root : ".");
747
+ const requireFromProject = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
748
+ try {
749
+ return requireFromProject.resolve("@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js");
750
+ } catch {}
751
+ try {
752
+ return (0, node_module.createRequire)(requireFromProject.resolve("@zeus-js/zeus")).resolve("@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js");
753
+ } catch {
754
+ return;
755
+ }
756
+ }
757
+ //#endregion
758
+ //#region packages/web-c/bundler-plugin/src/rolldown.ts
576
759
  function zeus(options = {}) {
577
- return createZeusBundlerPlugin(options, { target: "rollup" });
760
+ return createZeusBundlerPlugin(options, { target: "rolldown" });
761
+ }
762
+ function defineZeusRolldownConfig(config = {}) {
763
+ const { zeus: zeusOptions = {}, plugins, input, output, external, transform, ...rest } = config;
764
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
765
+ return {
766
+ input: input !== null && input !== void 0 ? input : "src/index.ts",
767
+ ...rest,
768
+ external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
769
+ plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
770
+ transform: {
771
+ target: "es2016",
772
+ ...transform
773
+ },
774
+ output: output !== null && output !== void 0 ? output : {
775
+ dir: "dist",
776
+ format: "esm",
777
+ chunkFileNames: "chunks/[name]-[hash].js",
778
+ sourcemap: true
779
+ }
780
+ };
781
+ }
782
+ function normalizePlugins(plugins) {
783
+ if (!plugins) return [];
784
+ return Array.isArray(plugins) ? plugins.filter(Boolean) : [plugins].filter(Boolean);
578
785
  }
579
786
  //#endregion
580
787
  //#region packages/web-c/bundler-plugin/src/pluginOptions.ts
@@ -585,9 +792,14 @@ function resolvePluginDts(value, ctx) {
585
792
  }
586
793
  //#endregion
587
794
  exports.createOutputRegistry = createOutputRegistry;
588
- exports.default = zeus;
795
+ exports.createZeusRolldownPlugin = zeus;
796
+ exports.createZeusRollupPlugin = zeus$1;
797
+ exports.createZeusVitePlugin = createZeusVitePlugin;
798
+ exports.default = zeus$1;
799
+ exports.defineZeusRolldownConfig = defineZeusRolldownConfig;
800
+ exports.defineZeusRollupConfig = defineZeusRollupConfig;
589
801
  exports.mergeExternal = mergeExternal;
590
802
  exports.resolveComponentExclude = resolveComponentExclude;
591
803
  exports.resolveComponentInclude = resolveComponentInclude;
592
804
  exports.resolvePluginDts = resolvePluginDts;
593
- exports.zeus = zeus;
805
+ exports.zeus = zeus$1;
@@ -1,6 +1,8 @@
1
1
  import { CompilerOptions } from '@zeus-js/compiler';
2
2
  import { ComponentManifest, AnalyzerDiagnostic } from '@zeus-js/component-analyzer';
3
- import { Plugin } from 'rollup';
3
+ import { RollupOptions, Plugin } from 'rollup';
4
+ import { Plugin as Plugin$1 } from 'vite';
5
+ import { RolldownOptions, Plugin as Plugin$2 } from 'rolldown';
4
6
 
5
7
  type MaybePromise<T> = T | Promise<T>;
6
8
  export type RollupExternalOption = string | RegExp | Array<string | RegExp> | ((source: string, importer: string | undefined, isResolved: boolean) => boolean);
@@ -79,7 +81,7 @@ export interface ZeusComponentPlugin {
79
81
  * Used by the Vite adapter, defineZeusRollupConfig(), and
80
82
  * defineZeusRolldownConfig().
81
83
  */
82
- external?: string[];
84
+ external?: Array<string | RegExp>;
83
85
  }
84
86
  export interface ZeusBundlerPluginOptions {
85
87
  /**
@@ -137,6 +139,14 @@ export interface ZeusBundlerPluginOptions {
137
139
  * - vite: false
138
140
  */
139
141
  transpile?: boolean;
142
+ /**
143
+ * Clean the resolved Rollup/Rolldown output directory before writing.
144
+ *
145
+ * Vite keeps using its own emptyOutDir behavior.
146
+ *
147
+ * @default true
148
+ */
149
+ clean?: boolean;
140
150
  /**
141
151
  * Rollup adapter only. Additional extensions to try when resolving imports.
142
152
  * Set to `false` to disable extension resolution.
@@ -146,7 +156,23 @@ export interface ZeusBundlerPluginOptions {
146
156
  resolveExtensions?: string[] | false;
147
157
  }
148
158
 
149
- export declare function zeus(options?: ZeusBundlerPluginOptions): Plugin;
159
+ export declare function zeus$1(options?: ZeusBundlerPluginOptions): Plugin;
160
+
161
+ export interface ZeusRollupConfigOptions extends Omit<RollupOptions, 'plugins'> {
162
+ zeus?: ZeusBundlerPluginOptions;
163
+ plugins?: RollupOptions['plugins'];
164
+ }
165
+ export declare function defineZeusRollupConfig(config?: ZeusRollupConfigOptions): RollupOptions;
166
+
167
+ export declare function createZeusVitePlugin(options?: ZeusBundlerPluginOptions): Plugin$1;
168
+
169
+ export declare function zeus(options?: ZeusBundlerPluginOptions): Plugin$2;
170
+
171
+ export interface ZeusRolldownConfigOptions extends Omit<RolldownOptions, 'plugins'> {
172
+ zeus?: ZeusBundlerPluginOptions;
173
+ plugins?: RolldownOptions['plugins'];
174
+ }
175
+ export declare function defineZeusRolldownConfig(config?: ZeusRolldownConfigOptions): RolldownOptions;
150
176
 
151
177
  export declare function createOutputRegistry(): ZeusOutputRegistry;
152
178
 
@@ -155,6 +181,7 @@ export declare function resolveComponentExclude(exclude?: string[]): string[];
155
181
 
156
182
  export declare function resolvePluginDts(value: DtsMode | undefined, ctx: ZeusBuildContext): boolean;
157
183
 
158
- export declare function mergeExternal(userExternal: RollupExternalOption | undefined, pluginExternal: string[]): RollupExternalOption;
184
+ type ZeusExternalEntry = string | RegExp;
185
+ export declare function mergeExternal(userExternal: RollupExternalOption | undefined, pluginExternal: ZeusExternalEntry[]): RollupExternalOption;
159
186
 
160
- export { zeus as default, };
187
+ export { zeus as createZeusRolldownPlugin, zeus$1 as createZeusRollupPlugin, zeus$1 as default, zeus$1 as zeus };