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

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.3
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,32 @@ 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
+ if (!pluginExternals.length) return null;
417
+ return {
418
+ ...inputOptions,
419
+ external: mergeExternal(inputOptions.external, pluginExternals)
420
+ };
421
+ },
422
+ outputOptions(outputOptions) {
423
+ if (target === "vite") return null;
424
+ cleanOutputDir(outputOptions, {
425
+ root: resolveRoot(options.root),
426
+ enabled: options.clean !== false,
427
+ cleanedOutputDirs
428
+ });
429
+ if (outputOptions.chunkFileNames) return null;
430
+ return {
431
+ ...outputOptions,
432
+ chunkFileNames: "chunks/[name]-[hash].js"
433
+ };
434
+ },
376
435
  async buildStart() {
377
436
  var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
378
437
  virtualModules.clear();
@@ -437,6 +496,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
437
496
  id: resolvedVirtual,
438
497
  moduleSideEffects: "no-treeshake"
439
498
  };
499
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
500
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
501
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
502
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
503
+ id: "\0" + virtualEntryId,
504
+ moduleSideEffects: "no-treeshake"
505
+ };
506
+ }
440
507
  if (target === "rollup") {
441
508
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
442
509
  if (resolvedTs) return resolvedTs;
@@ -484,6 +551,31 @@ function resolveRoot(root) {
484
551
  if (typeof root === "function") return node_path.default.resolve(root());
485
552
  return node_path.default.resolve(root !== null && root !== void 0 ? root : process.cwd());
486
553
  }
554
+ function cleanOutputDir(outputOptions, options) {
555
+ if (!options.enabled) return;
556
+ const outputDir = resolveOutputDir(outputOptions, options.root);
557
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
558
+ if (options.cleanedOutputDirs.has(outputDir)) return;
559
+ options.cleanedOutputDirs.add(outputDir);
560
+ node_fs.default.rmSync(outputDir, {
561
+ recursive: true,
562
+ force: true
563
+ });
564
+ }
565
+ function resolveOutputDir(outputOptions, root) {
566
+ const dir = outputOptions.dir;
567
+ if (typeof dir === "string" && dir.length > 0) return node_path.default.resolve(root, dir);
568
+ const file = outputOptions.file;
569
+ if (typeof file === "string" && file.length > 0) return node_path.default.dirname(node_path.default.resolve(root, file));
570
+ return node_path.default.resolve(root, "dist");
571
+ }
572
+ function isSafeCleanTarget(outputDir, root) {
573
+ const resolvedRoot = node_path.default.resolve(root);
574
+ const resolvedOutputDir = node_path.default.resolve(outputDir);
575
+ if (resolvedOutputDir === resolvedRoot) return false;
576
+ const relative = node_path.default.relative(resolvedRoot, resolvedOutputDir);
577
+ return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
578
+ }
487
579
  async function createManifest(root, include, exclude) {
488
580
  if (!include.length) return {
489
581
  manifest: {
@@ -564,23 +656,11 @@ function emitVirtualEntries(modules, pluginContext) {
564
656
  });
565
657
  }
566
658
  }
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];
659
+ function resolveVirtualEntryImport(id, importer) {
660
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
661
+ const lastColon = importer.lastIndexOf(":");
662
+ if (lastColon <= 0) return null;
663
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
584
664
  }
585
665
  //#endregion
586
666
  //#region packages/web-c/bundler-plugin/src/vite.ts
package/dist/vite.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.
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * bundler-plugin v0.1.0-beta.2
2
+ * bundler-plugin v0.1.0-beta.3
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -80,7 +80,7 @@ function hasErrorDiagnostics(diagnostics) {
80
80
  return diagnostics.some((item) => item.level === "error");
81
81
  }
82
82
  //#endregion
83
- //#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
84
84
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
85
85
  try {
86
86
  var i = n[a](c), u = i.value;
@@ -106,7 +106,7 @@ function _asyncToGenerator(n) {
106
106
  };
107
107
  }
108
108
  //#endregion
109
- //#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
110
110
  function _typeof(o) {
111
111
  "@babel/helpers - typeof";
112
112
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -116,7 +116,7 @@ function _typeof(o) {
116
116
  }, _typeof(o);
117
117
  }
118
118
  //#endregion
119
- //#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
120
120
  function toPrimitive(t, r) {
121
121
  if ("object" != _typeof(t) || !t) return t;
122
122
  var e = t[Symbol.toPrimitive];
@@ -128,13 +128,13 @@ function toPrimitive(t, r) {
128
128
  return ("string" === r ? String : Number)(t);
129
129
  }
130
130
  //#endregion
131
- //#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
132
132
  function toPropertyKey(t) {
133
133
  var i = toPrimitive(t, "string");
134
134
  return "symbol" == _typeof(i) ? i : i + "";
135
135
  }
136
136
  //#endregion
137
- //#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
138
138
  function _defineProperty(e, r, t) {
139
139
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
140
140
  value: t,
@@ -144,7 +144,7 @@ function _defineProperty(e, r, t) {
144
144
  }) : e[r] = t, e;
145
145
  }
146
146
  //#endregion
147
- //#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
148
148
  function ownKeys(e, r) {
149
149
  var t = Object.keys(e);
150
150
  if (Object.getOwnPropertySymbols) {
@@ -274,6 +274,42 @@ function _fileExists() {
274
274
  return _fileExists.apply(this, arguments);
275
275
  }
276
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
277
313
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
278
314
  function createOutputRegistry() {
279
315
  const map = /* @__PURE__ */ new Map();
@@ -460,9 +496,26 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
460
496
  let shouldCompileZeus = (_id) => false;
461
497
  let ctx;
462
498
  let root = process.cwd();
499
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
463
500
  const virtualModules = new VirtualModuleRegistry();
464
501
  return {
465
502
  name: resolvePluginName(target),
503
+ options(inputOptions) {
504
+ if (target === "vite") return null;
505
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
506
+ if (!pluginExternals.length) return null;
507
+ return _objectSpread2(_objectSpread2({}, inputOptions), {}, { external: mergeExternal(inputOptions.external, pluginExternals) });
508
+ },
509
+ outputOptions(outputOptions) {
510
+ if (target === "vite") return null;
511
+ cleanOutputDir(outputOptions, {
512
+ root: resolveRoot(options.root),
513
+ enabled: options.clean !== false,
514
+ cleanedOutputDirs
515
+ });
516
+ if (outputOptions.chunkFileNames) return null;
517
+ return _objectSpread2(_objectSpread2({}, outputOptions), {}, { chunkFileNames: "chunks/[name]-[hash].js" });
518
+ },
466
519
  buildStart() {
467
520
  var _this = this;
468
521
  return _asyncToGenerator(function* () {
@@ -530,6 +583,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
530
583
  id: resolvedVirtual,
531
584
  moduleSideEffects: "no-treeshake"
532
585
  };
586
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
587
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
588
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
589
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
590
+ id: "\0" + virtualEntryId,
591
+ moduleSideEffects: "no-treeshake"
592
+ };
593
+ }
533
594
  if (target === "rollup") {
534
595
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
535
596
  if (resolvedTs) return resolvedTs;
@@ -582,6 +643,31 @@ function resolveRoot(root) {
582
643
  if (typeof root === "function") return path.resolve(root());
583
644
  return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
584
645
  }
646
+ function cleanOutputDir(outputOptions, options) {
647
+ if (!options.enabled) return;
648
+ const outputDir = resolveOutputDir(outputOptions, options.root);
649
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
650
+ if (options.cleanedOutputDirs.has(outputDir)) return;
651
+ options.cleanedOutputDirs.add(outputDir);
652
+ fs.rmSync(outputDir, {
653
+ recursive: true,
654
+ force: true
655
+ });
656
+ }
657
+ function resolveOutputDir(outputOptions, root) {
658
+ const dir = outputOptions.dir;
659
+ if (typeof dir === "string" && dir.length > 0) return path.resolve(root, dir);
660
+ const file = outputOptions.file;
661
+ if (typeof file === "string" && file.length > 0) return path.dirname(path.resolve(root, file));
662
+ return path.resolve(root, "dist");
663
+ }
664
+ function isSafeCleanTarget(outputDir, root) {
665
+ const resolvedRoot = path.resolve(root);
666
+ const resolvedOutputDir = path.resolve(outputDir);
667
+ if (resolvedOutputDir === resolvedRoot) return false;
668
+ const relative = path.relative(resolvedRoot, resolvedOutputDir);
669
+ return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
670
+ }
585
671
  function createManifest(_x, _x2, _x3) {
586
672
  return _createManifest.apply(this, arguments);
587
673
  }
@@ -674,23 +760,11 @@ function emitVirtualEntries(modules, pluginContext) {
674
760
  });
675
761
  }
676
762
  }
677
- //#endregion
678
- //#region packages/web-c/bundler-plugin/src/external.ts
679
- function collectPluginExternals(options) {
680
- var _options$plugins;
681
- const set = /* @__PURE__ */ new Set();
682
- for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
683
- var _plugin$external;
684
- for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
685
- }
686
- return Array.from(set);
687
- }
688
- function mergeExternal(userExternal, pluginExternal) {
689
- if (!userExternal) return pluginExternal;
690
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
691
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
692
- };
693
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
763
+ function resolveVirtualEntryImport(id, importer) {
764
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
765
+ const lastColon = importer.lastIndexOf(":");
766
+ if (lastColon <= 0) return null;
767
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
694
768
  }
695
769
  //#endregion
696
770
  //#region packages/web-c/bundler-plugin/src/vite.ts
package/dist/vite.prod.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * bundler-plugin v0.1.0-beta.2
2
+ * bundler-plugin v0.1.0-beta.3
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -80,7 +80,7 @@ function hasErrorDiagnostics(diagnostics) {
80
80
  return diagnostics.some((item) => item.level === "error");
81
81
  }
82
82
  //#endregion
83
- //#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
84
84
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
85
85
  try {
86
86
  var i = n[a](c), u = i.value;
@@ -106,7 +106,7 @@ function _asyncToGenerator(n) {
106
106
  };
107
107
  }
108
108
  //#endregion
109
- //#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
110
110
  function _typeof(o) {
111
111
  "@babel/helpers - typeof";
112
112
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -116,7 +116,7 @@ function _typeof(o) {
116
116
  }, _typeof(o);
117
117
  }
118
118
  //#endregion
119
- //#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
120
120
  function toPrimitive(t, r) {
121
121
  if ("object" != _typeof(t) || !t) return t;
122
122
  var e = t[Symbol.toPrimitive];
@@ -128,13 +128,13 @@ function toPrimitive(t, r) {
128
128
  return ("string" === r ? String : Number)(t);
129
129
  }
130
130
  //#endregion
131
- //#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
132
132
  function toPropertyKey(t) {
133
133
  var i = toPrimitive(t, "string");
134
134
  return "symbol" == _typeof(i) ? i : i + "";
135
135
  }
136
136
  //#endregion
137
- //#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
138
138
  function _defineProperty(e, r, t) {
139
139
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
140
140
  value: t,
@@ -144,7 +144,7 @@ function _defineProperty(e, r, t) {
144
144
  }) : e[r] = t, e;
145
145
  }
146
146
  //#endregion
147
- //#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
148
148
  function ownKeys(e, r) {
149
149
  var t = Object.keys(e);
150
150
  if (Object.getOwnPropertySymbols) {
@@ -274,6 +274,42 @@ function _fileExists() {
274
274
  return _fileExists.apply(this, arguments);
275
275
  }
276
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
277
313
  //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
278
314
  function createOutputRegistry() {
279
315
  const map = /* @__PURE__ */ new Map();
@@ -460,9 +496,26 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
460
496
  let shouldCompileZeus = (_id) => false;
461
497
  let ctx;
462
498
  let root = process.cwd();
499
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
463
500
  const virtualModules = new VirtualModuleRegistry();
464
501
  return {
465
502
  name: resolvePluginName(target),
503
+ options(inputOptions) {
504
+ if (target === "vite") return null;
505
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
506
+ if (!pluginExternals.length) return null;
507
+ return _objectSpread2(_objectSpread2({}, inputOptions), {}, { external: mergeExternal(inputOptions.external, pluginExternals) });
508
+ },
509
+ outputOptions(outputOptions) {
510
+ if (target === "vite") return null;
511
+ cleanOutputDir(outputOptions, {
512
+ root: resolveRoot(options.root),
513
+ enabled: options.clean !== false,
514
+ cleanedOutputDirs
515
+ });
516
+ if (outputOptions.chunkFileNames) return null;
517
+ return _objectSpread2(_objectSpread2({}, outputOptions), {}, { chunkFileNames: "chunks/[name]-[hash].js" });
518
+ },
466
519
  buildStart() {
467
520
  var _this = this;
468
521
  return _asyncToGenerator(function* () {
@@ -530,6 +583,14 @@ function createZeusBundlerPlugin(options = {}, createOptions) {
530
583
  id: resolvedVirtual,
531
584
  moduleSideEffects: "no-treeshake"
532
585
  };
586
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
587
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
588
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
589
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
590
+ id: "\0" + virtualEntryId,
591
+ moduleSideEffects: "no-treeshake"
592
+ };
593
+ }
533
594
  if (target === "rollup") {
534
595
  const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
535
596
  if (resolvedTs) return resolvedTs;
@@ -582,6 +643,31 @@ function resolveRoot(root) {
582
643
  if (typeof root === "function") return path.resolve(root());
583
644
  return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
584
645
  }
646
+ function cleanOutputDir(outputOptions, options) {
647
+ if (!options.enabled) return;
648
+ const outputDir = resolveOutputDir(outputOptions, options.root);
649
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
650
+ if (options.cleanedOutputDirs.has(outputDir)) return;
651
+ options.cleanedOutputDirs.add(outputDir);
652
+ fs.rmSync(outputDir, {
653
+ recursive: true,
654
+ force: true
655
+ });
656
+ }
657
+ function resolveOutputDir(outputOptions, root) {
658
+ const dir = outputOptions.dir;
659
+ if (typeof dir === "string" && dir.length > 0) return path.resolve(root, dir);
660
+ const file = outputOptions.file;
661
+ if (typeof file === "string" && file.length > 0) return path.dirname(path.resolve(root, file));
662
+ return path.resolve(root, "dist");
663
+ }
664
+ function isSafeCleanTarget(outputDir, root) {
665
+ const resolvedRoot = path.resolve(root);
666
+ const resolvedOutputDir = path.resolve(outputDir);
667
+ if (resolvedOutputDir === resolvedRoot) return false;
668
+ const relative = path.relative(resolvedRoot, resolvedOutputDir);
669
+ return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
670
+ }
585
671
  function createManifest(_x, _x2, _x3) {
586
672
  return _createManifest.apply(this, arguments);
587
673
  }
@@ -674,23 +760,11 @@ function emitVirtualEntries(modules, pluginContext) {
674
760
  });
675
761
  }
676
762
  }
677
- //#endregion
678
- //#region packages/web-c/bundler-plugin/src/external.ts
679
- function collectPluginExternals(options) {
680
- var _options$plugins;
681
- const set = /* @__PURE__ */ new Set();
682
- for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
683
- var _plugin$external;
684
- for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
685
- }
686
- return Array.from(set);
687
- }
688
- function mergeExternal(userExternal, pluginExternal) {
689
- if (!userExternal) return pluginExternal;
690
- if (typeof userExternal === "function") return (source, importer, isResolved) => {
691
- return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
692
- };
693
- return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
763
+ function resolveVirtualEntryImport(id, importer) {
764
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
765
+ const lastColon = importer.lastIndexOf(":");
766
+ if (lastColon <= 0) return null;
767
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
694
768
  }
695
769
  //#endregion
696
770
  //#region packages/web-c/bundler-plugin/src/vite.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeus-js/bundler-plugin",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.3",
4
4
  "description": "Zeus bundler plugin host",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -13,14 +13,14 @@
13
13
  "exports": {
14
14
  ".": {
15
15
  "types": "./dist/bundler-plugin.d.ts",
16
+ "module": "./dist/bundler-plugin.esm-bundler.js",
17
+ "import": "./dist/bundler-plugin.esm-bundler.js",
18
+ "require": "./index.js",
16
19
  "node": {
17
20
  "production": "./dist/bundler-plugin.cjs.prod.js",
18
21
  "development": "./dist/bundler-plugin.cjs.js",
19
22
  "default": "./index.js"
20
- },
21
- "module": "./dist/bundler-plugin.esm-bundler.js",
22
- "import": "./dist/bundler-plugin.esm-bundler.js",
23
- "require": "./index.js"
23
+ }
24
24
  },
25
25
  "./vite": {
26
26
  "types": "./dist/vite.d.ts",
@@ -74,8 +74,8 @@
74
74
  "@babel/preset-typescript": "^7.29.7",
75
75
  "fast-glob": "^3.3.3",
76
76
  "picomatch": "^4.0.4",
77
- "@zeus-js/compiler": "0.1.0-beta.2",
78
- "@zeus-js/component-analyzer": "0.1.0-beta.2"
77
+ "@zeus-js/compiler": "0.1.0-beta.3",
78
+ "@zeus-js/component-analyzer": "0.1.0-beta.3"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "rollup": "^4.0.0",