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

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.
@@ -0,0 +1,745 @@
1
+ /**
2
+ * bundler-plugin v0.1.0-beta.2
3
+ * (c) 2026 baicie
4
+ * Released under the MIT License.
5
+ **/
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ import { analyzeComponents } from "@zeus-js/component-analyzer";
9
+ import fg from "fast-glob";
10
+ import picomatch from "picomatch";
11
+ import fs$1 from "node:fs/promises";
12
+ import { transformAsync } from "@babel/core";
13
+ import presetTypeScript from "@babel/preset-typescript";
14
+ import zeusCompiler from "@zeus-js/compiler";
15
+ //#region packages/web-c/bundler-plugin/src/filter.ts
16
+ function cleanUrl(id) {
17
+ return id.replace(/[?#].*$/, "");
18
+ }
19
+ function isTypeScriptLike(id) {
20
+ return /\.[cm]?tsx?$/.test(cleanUrl(id));
21
+ }
22
+ //#endregion
23
+ //#region packages/web-c/bundler-plugin/src/componentTransformFilter.ts
24
+ function normalizePath$1(value) {
25
+ return value.replace(/\\/g, "/");
26
+ }
27
+ function createComponentTransformFilter(options) {
28
+ const isIncluded = picomatch(options.include);
29
+ const isExcluded = picomatch(options.exclude);
30
+ return function shouldTransform(id) {
31
+ const clean = normalizePath$1(cleanUrl(id));
32
+ const relative = normalizePath$1(path.relative(options.root, clean));
33
+ if (relative.startsWith("..") || path.isAbsolute(relative)) return false;
34
+ if (isExcluded(relative)) return false;
35
+ return isIncluded(relative);
36
+ };
37
+ }
38
+ //#endregion
39
+ //#region packages/web-c/bundler-plugin/src/defaults.ts
40
+ const DEFAULT_COMPONENT_INCLUDE = ["src/**/*.{ts,tsx,js,jsx}", "components/**/*.{ts,tsx,js,jsx}"];
41
+ const DEFAULT_COMPONENT_EXCLUDE = [
42
+ "**/*.test.*",
43
+ "**/*.spec.*",
44
+ "**/__tests__/**",
45
+ "**/*.d.ts",
46
+ "src/shared/**",
47
+ "node_modules/**",
48
+ "dist/**"
49
+ ];
50
+ const DEFAULT_TRANSFORM_INCLUDE = DEFAULT_COMPONENT_INCLUDE;
51
+ const DEFAULT_TRANSFORM_EXCLUDE = [
52
+ "**/*.test.*",
53
+ "**/*.spec.*",
54
+ "**/__tests__/**",
55
+ "**/*.d.ts",
56
+ "node_modules/**",
57
+ "dist/**"
58
+ ];
59
+ function resolveComponentInclude(include) {
60
+ return (include === null || include === void 0 ? void 0 : include.length) ? include : DEFAULT_COMPONENT_INCLUDE;
61
+ }
62
+ function resolveComponentExclude(exclude) {
63
+ return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_COMPONENT_EXCLUDE;
64
+ }
65
+ function resolveTransformInclude(include, componentInclude) {
66
+ if (include === null || include === void 0 ? void 0 : include.length) return include;
67
+ return Array.from(new Set([...DEFAULT_TRANSFORM_INCLUDE, ...componentInclude]));
68
+ }
69
+ function resolveTransformExclude(exclude) {
70
+ return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_TRANSFORM_EXCLUDE;
71
+ }
72
+ //#endregion
73
+ //#region packages/web-c/bundler-plugin/src/diagnostics.ts
74
+ function formatDiagnostic(diagnostic) {
75
+ return `[zeus component-analyzer] ${diagnostic.file}: ${diagnostic.message}`;
76
+ }
77
+ function hasErrorDiagnostics(diagnostics) {
78
+ return diagnostics.some((item) => item.level === "error");
79
+ }
80
+ //#endregion
81
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/asyncToGenerator.js
82
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
83
+ try {
84
+ var i = n[a](c), u = i.value;
85
+ } catch (n) {
86
+ e(n);
87
+ return;
88
+ }
89
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
90
+ }
91
+ function _asyncToGenerator(n) {
92
+ return function() {
93
+ var t = this, e = arguments;
94
+ return new Promise(function(r, o) {
95
+ var a = n.apply(t, e);
96
+ function _next(n) {
97
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
98
+ }
99
+ function _throw(n) {
100
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
101
+ }
102
+ _next(void 0);
103
+ });
104
+ };
105
+ }
106
+ //#endregion
107
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
108
+ function _typeof(o) {
109
+ "@babel/helpers - typeof";
110
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
111
+ return typeof o;
112
+ } : function(o) {
113
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
114
+ }, _typeof(o);
115
+ }
116
+ //#endregion
117
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
118
+ function toPrimitive(t, r) {
119
+ if ("object" != _typeof(t) || !t) return t;
120
+ var e = t[Symbol.toPrimitive];
121
+ if (void 0 !== e) {
122
+ var i = e.call(t, r || "default");
123
+ if ("object" != _typeof(i)) return i;
124
+ throw new TypeError("@@toPrimitive must return a primitive value.");
125
+ }
126
+ return ("string" === r ? String : Number)(t);
127
+ }
128
+ //#endregion
129
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
130
+ function toPropertyKey(t) {
131
+ var i = toPrimitive(t, "string");
132
+ return "symbol" == _typeof(i) ? i : i + "";
133
+ }
134
+ //#endregion
135
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
136
+ function _defineProperty(e, r, t) {
137
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
138
+ value: t,
139
+ enumerable: !0,
140
+ configurable: !0,
141
+ writable: !0
142
+ }) : e[r] = t, e;
143
+ }
144
+ //#endregion
145
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectSpread2.js
146
+ function ownKeys(e, r) {
147
+ var t = Object.keys(e);
148
+ if (Object.getOwnPropertySymbols) {
149
+ var o = Object.getOwnPropertySymbols(e);
150
+ r && (o = o.filter(function(r) {
151
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
152
+ })), t.push.apply(t, o);
153
+ }
154
+ return t;
155
+ }
156
+ function _objectSpread2(e) {
157
+ for (var r = 1; r < arguments.length; r++) {
158
+ var t = null != arguments[r] ? arguments[r] : {};
159
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
160
+ _defineProperty(e, r, t[r]);
161
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
162
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
163
+ });
164
+ }
165
+ return e;
166
+ }
167
+ //#endregion
168
+ //#region packages/web-c/bundler-plugin/src/dts.ts
169
+ function resolveDts(_x) {
170
+ return _resolveDts.apply(this, arguments);
171
+ }
172
+ function _resolveDts() {
173
+ _resolveDts = _asyncToGenerator(function* (options) {
174
+ var _options$mode;
175
+ const mode = (_options$mode = options.mode) !== null && _options$mode !== void 0 ? _options$mode : "auto";
176
+ if (mode === true) return {
177
+ enabled: true,
178
+ mode,
179
+ reason: ["explicit-enabled"]
180
+ };
181
+ if (mode === false) return {
182
+ enabled: false,
183
+ mode,
184
+ reason: ["explicit-disabled"]
185
+ };
186
+ const reason = [];
187
+ if (yield packageDeclaresTypes(options.root)) reason.push("package-types-field");
188
+ if (yield hasTypeScriptDependency(options.root)) reason.push("typescript-dependency");
189
+ if (yield fileExists(path.join(options.root, "tsconfig.json"))) reason.push("tsconfig");
190
+ if (yield hasTypeScriptSource({
191
+ root: options.root,
192
+ include: options.include,
193
+ exclude: options.exclude
194
+ })) reason.push("typescript-source");
195
+ return {
196
+ enabled: reason.length > 0,
197
+ mode,
198
+ reason
199
+ };
200
+ });
201
+ return _resolveDts.apply(this, arguments);
202
+ }
203
+ function hasTypeScriptDependency(_x2) {
204
+ return _hasTypeScriptDependency.apply(this, arguments);
205
+ }
206
+ function _hasTypeScriptDependency() {
207
+ _hasTypeScriptDependency = _asyncToGenerator(function* (root) {
208
+ const pkg = yield readPackageJson(root);
209
+ if (!pkg) return false;
210
+ const deps = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, pkg.dependencies), pkg.devDependencies), pkg.peerDependencies), pkg.optionalDependencies);
211
+ return Boolean(deps.typescript);
212
+ });
213
+ return _hasTypeScriptDependency.apply(this, arguments);
214
+ }
215
+ function packageDeclaresTypes(_x3) {
216
+ return _packageDeclaresTypes.apply(this, arguments);
217
+ }
218
+ function _packageDeclaresTypes() {
219
+ _packageDeclaresTypes = _asyncToGenerator(function* (root) {
220
+ const pkg = yield readPackageJson(root);
221
+ if (!pkg) return false;
222
+ if (pkg.types || pkg.typings) return true;
223
+ return hasTypesInExports(pkg.exports);
224
+ });
225
+ return _packageDeclaresTypes.apply(this, arguments);
226
+ }
227
+ function hasTypesInExports(value) {
228
+ if (!value) return false;
229
+ if (typeof value !== "object") return false;
230
+ if ("types" in value) return true;
231
+ return Object.values(value).some(hasTypesInExports);
232
+ }
233
+ function hasTypeScriptSource(_x4) {
234
+ return _hasTypeScriptSource.apply(this, arguments);
235
+ }
236
+ function _hasTypeScriptSource() {
237
+ _hasTypeScriptSource = _asyncToGenerator(function* (options) {
238
+ return (yield fg(options.include, {
239
+ cwd: options.root,
240
+ onlyFiles: true,
241
+ absolute: false,
242
+ ignore: options.exclude
243
+ })).some((file) => file.endsWith(".ts") || file.endsWith(".tsx"));
244
+ });
245
+ return _hasTypeScriptSource.apply(this, arguments);
246
+ }
247
+ function readPackageJson(_x5) {
248
+ return _readPackageJson.apply(this, arguments);
249
+ }
250
+ function _readPackageJson() {
251
+ _readPackageJson = _asyncToGenerator(function* (root) {
252
+ try {
253
+ return JSON.parse(yield fs$1.readFile(path.join(root, "package.json"), "utf-8"));
254
+ } catch (_unused) {
255
+ return null;
256
+ }
257
+ });
258
+ return _readPackageJson.apply(this, arguments);
259
+ }
260
+ function fileExists(_x6) {
261
+ return _fileExists.apply(this, arguments);
262
+ }
263
+ function _fileExists() {
264
+ _fileExists = _asyncToGenerator(function* (file) {
265
+ try {
266
+ yield fs$1.access(file);
267
+ return true;
268
+ } catch (_unused2) {
269
+ return false;
270
+ }
271
+ });
272
+ return _fileExists.apply(this, arguments);
273
+ }
274
+ //#endregion
275
+ //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
276
+ function createOutputRegistry() {
277
+ const map = /* @__PURE__ */ new Map();
278
+ return {
279
+ register(kind, options) {
280
+ map.set(kind, normalizeRegistration(kind, options));
281
+ },
282
+ has(kind) {
283
+ return map.has(kind);
284
+ },
285
+ get(kind) {
286
+ const current = map.get(kind);
287
+ if (!current) throw new Error(`[zeus] output kind "${kind}" is not registered.`);
288
+ return current;
289
+ },
290
+ getDir(kind) {
291
+ return this.get(kind).outDir;
292
+ },
293
+ getFileName(kind, tag) {
294
+ const current = this.get(kind);
295
+ if (current.fileName) return current.fileName(tag, kind);
296
+ return `${normalizeTagName(tag, current.stripPrefix)}.js`;
297
+ },
298
+ join(kind, fileName) {
299
+ return path.posix.join(this.getDir(kind), fileName);
300
+ }
301
+ };
302
+ }
303
+ function normalizeRegistration(kind, options) {
304
+ var _options$outDir, _options$stripPrefix;
305
+ return {
306
+ outDir: (_options$outDir = options.outDir) !== null && _options$outDir !== void 0 ? _options$outDir : defaultDir(kind),
307
+ stripPrefix: (_options$stripPrefix = options.stripPrefix) !== null && _options$stripPrefix !== void 0 ? _options$stripPrefix : false,
308
+ fileName: options.fileName
309
+ };
310
+ }
311
+ function defaultDir(kind) {
312
+ switch (kind) {
313
+ case "wc": return "wc";
314
+ case "react": return "react";
315
+ case "vue": return "vue";
316
+ case "icons-react": return "icons/react";
317
+ case "icons-vue": return "icons/vue";
318
+ case "icons-wc": return "icons/wc";
319
+ case "asset": return "";
320
+ }
321
+ }
322
+ function normalizeTagName(tag, stripPrefix) {
323
+ if (stripPrefix && tag.startsWith(stripPrefix)) return tag.slice(stripPrefix.length);
324
+ return tag;
325
+ }
326
+ //#endregion
327
+ //#region packages/web-c/bundler-plugin/src/transform.ts
328
+ function transformZeus(_x) {
329
+ return _transformZeus.apply(this, arguments);
330
+ }
331
+ function _transformZeus() {
332
+ _transformZeus = _asyncToGenerator(function* (options) {
333
+ var _compilerOptions$modu;
334
+ const { id, code, compiler, sourcemap = true, transpile = false } = options;
335
+ const isTs = isTypeScriptLike(id);
336
+ const isTsx = /\.[cm]?tsx$/.test(id.replace(/[?#].*$/, ""));
337
+ const shouldRunCompiler = compiler !== false;
338
+ const shouldStripTs = transpile && isTs;
339
+ if (!shouldRunCompiler && !shouldStripTs) return null;
340
+ const compilerOptions = compiler === false ? {} : compiler === void 0 ? {} : compiler;
341
+ const result = yield transformAsync(code, {
342
+ filename: id,
343
+ sourceMaps: sourcemap,
344
+ plugins: shouldRunCompiler ? [[zeusCompiler, _objectSpread2({
345
+ moduleName: (_compilerOptions$modu = compilerOptions.moduleName) !== null && _compilerOptions$modu !== void 0 ? _compilerOptions$modu : "@zeus-js/runtime-dom",
346
+ generate: "dom",
347
+ hydratable: false,
348
+ delegateEvents: true
349
+ }, compilerOptions)]] : [],
350
+ presets: shouldStripTs ? [[presetTypeScript, {
351
+ allExtensions: true,
352
+ isTSX: isTsx,
353
+ allowDeclareFields: true
354
+ }]] : [],
355
+ parserOpts: {
356
+ sourceType: "module",
357
+ plugins: ["typescript", "jsx"]
358
+ },
359
+ generatorOpts: {
360
+ retainLines: false,
361
+ compact: false,
362
+ jsescOption: { minimal: true }
363
+ }
364
+ });
365
+ if (!(result === null || result === void 0 ? void 0 : result.code)) return null;
366
+ return {
367
+ code: result.code,
368
+ map: result.map
369
+ };
370
+ });
371
+ return _transformZeus.apply(this, arguments);
372
+ }
373
+ //#endregion
374
+ //#region packages/web-c/bundler-plugin/src/virtual.ts
375
+ const RESOLVED_VIRTUAL_PREFIX = "\0";
376
+ var VirtualModuleRegistry = class {
377
+ constructor() {
378
+ this.modules = /* @__PURE__ */ new Map();
379
+ this.virtualDirs = /* @__PURE__ */ new Map();
380
+ this.virtualFileNames = /* @__PURE__ */ new Map();
381
+ this.idsByFileName = /* @__PURE__ */ new Map();
382
+ }
383
+ set(id, code, fileName) {
384
+ const normalized = normalizeVirtualId(id);
385
+ this.modules.set(normalized, code);
386
+ if (fileName) {
387
+ const dir = path.posix.dirname(fileName);
388
+ this.virtualDirs.set(normalized, dir);
389
+ const normalizedFileName = normalizePath(fileName);
390
+ this.virtualFileNames.set(normalized, normalizedFileName);
391
+ this.idsByFileName.set(normalizedFileName, normalized);
392
+ }
393
+ }
394
+ has(id) {
395
+ return this.modules.has(normalizeVirtualId(id));
396
+ }
397
+ get(id) {
398
+ return this.modules.get(normalizeVirtualId(id));
399
+ }
400
+ clear() {
401
+ this.modules.clear();
402
+ this.virtualDirs.clear();
403
+ this.virtualFileNames.clear();
404
+ this.idsByFileName.clear();
405
+ }
406
+ resolve(id, importer) {
407
+ const normalized = normalizeVirtualId(id);
408
+ if (this.modules.has(normalized)) return RESOLVED_VIRTUAL_PREFIX + normalized;
409
+ if (importer && (id.startsWith(".") || id.startsWith(".."))) {
410
+ const importerNormalized = normalizeVirtualId(importer);
411
+ const importerDir = this.virtualDirs.get(importerNormalized);
412
+ if (importerDir) {
413
+ const resolved = normalizePath(path.posix.join(importerDir, id));
414
+ const resolvedVirtualId = this.idsByFileName.get(resolved);
415
+ if (resolvedVirtualId) return RESOLVED_VIRTUAL_PREFIX + resolvedVirtualId;
416
+ const importingPrefix = this.getIdPrefix(importerNormalized);
417
+ if (importingPrefix !== null) {
418
+ const baseName = path.posix.basename(resolved, ".js");
419
+ for (const [key] of this.modules.entries()) if (key === importingPrefix + baseName) return RESOLVED_VIRTUAL_PREFIX + key;
420
+ for (const stripPrefix of [
421
+ "z-",
422
+ "wc-",
423
+ "wc/",
424
+ ""
425
+ ]) {
426
+ const candidate = stripPrefix ? importingPrefix + stripPrefix + baseName : importingPrefix + baseName;
427
+ if (this.modules.has(candidate)) return RESOLVED_VIRTUAL_PREFIX + candidate;
428
+ }
429
+ const fullName = baseName;
430
+ for (const [key] of this.modules.entries()) if (key.endsWith(":" + fullName)) return RESOLVED_VIRTUAL_PREFIX + key;
431
+ }
432
+ }
433
+ }
434
+ return null;
435
+ }
436
+ getIdPrefix(virtualId) {
437
+ const lastColon = virtualId.lastIndexOf(":");
438
+ if (lastColon <= 0) return null;
439
+ return virtualId.slice(0, lastColon + 1);
440
+ }
441
+ load(id) {
442
+ var _this$modules$get;
443
+ if (!id.startsWith(RESOLVED_VIRTUAL_PREFIX)) return null;
444
+ const normalized = id.slice(1);
445
+ return (_this$modules$get = this.modules.get(normalized)) !== null && _this$modules$get !== void 0 ? _this$modules$get : null;
446
+ }
447
+ };
448
+ function normalizeVirtualId(id) {
449
+ return id.startsWith("\0") ? id.slice(1) : id;
450
+ }
451
+ function normalizePath(value) {
452
+ return value.replace(/\\/g, "/").replace(/^\.\//, "");
453
+ }
454
+ //#endregion
455
+ //#region packages/web-c/bundler-plugin/src/core.ts
456
+ function createZeusBundlerPlugin(options = {}, createOptions) {
457
+ const target = createOptions.target;
458
+ let shouldCompileZeus = (_id) => false;
459
+ let ctx;
460
+ let root = process.cwd();
461
+ const virtualModules = new VirtualModuleRegistry();
462
+ return {
463
+ name: resolvePluginName(target),
464
+ buildStart() {
465
+ var _this = this;
466
+ return _asyncToGenerator(function* () {
467
+ var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
468
+ virtualModules.clear();
469
+ root = resolveRoot(options.root);
470
+ const componentInclude = resolveComponentInclude((_options$components = options.components) === null || _options$components === void 0 ? void 0 : _options$components.include);
471
+ const componentExclude = resolveComponentExclude((_options$components2 = options.components) === null || _options$components2 === void 0 ? void 0 : _options$components2.exclude);
472
+ const transformInclude = resolveTransformInclude((_options$transform = options.transform) === null || _options$transform === void 0 ? void 0 : _options$transform.include, componentInclude);
473
+ const transformExclude = resolveTransformExclude((_options$transform2 = options.transform) === null || _options$transform2 === void 0 ? void 0 : _options$transform2.exclude);
474
+ shouldCompileZeus = createComponentTransformFilter({
475
+ root,
476
+ include: transformInclude,
477
+ exclude: transformExclude
478
+ });
479
+ const dts = yield resolveDts({
480
+ root,
481
+ mode: options.dts,
482
+ include: componentInclude,
483
+ exclude: componentExclude
484
+ });
485
+ const manifestResult = yield createManifest(root, componentInclude, componentExclude);
486
+ for (const file of yield collectWatchFiles(root, componentInclude, componentExclude)) _this.addWatchFile(file);
487
+ const diagnostics = manifestResult.diagnostics;
488
+ for (const diagnostic of diagnostics) {
489
+ const message = formatDiagnostic(diagnostic);
490
+ if (diagnostic.level === "error") _this.error(message);
491
+ else if (options.diagnostics !== false) _this.warn(message);
492
+ }
493
+ if (hasErrorDiagnostics(diagnostics)) _this.error("[zeus] component analyzer failed.");
494
+ if (options.diagnostics === "verbose") _this.warn(`[zeus] dts ${dts.enabled ? "enabled" : "disabled"}: ${dts.reason.join(", ") || "no signal"}`);
495
+ ctx = {
496
+ root,
497
+ manifest: manifestResult.manifest,
498
+ diagnostics,
499
+ dts,
500
+ outputs: createOutputRegistry(),
501
+ emitFile: _this.emitFile.bind(_this),
502
+ warn: _this.warn.bind(_this),
503
+ error: _this.error.bind(_this),
504
+ addWatchFile: _this.addWatchFile.bind(_this),
505
+ meta: { watchMode: _this.meta.watchMode }
506
+ };
507
+ const plugins = (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : [];
508
+ for (const plugin of plugins) {
509
+ var _plugin$setup;
510
+ yield (_plugin$setup = plugin.setup) === null || _plugin$setup === void 0 ? void 0 : _plugin$setup.call(plugin, ctx);
511
+ }
512
+ for (const plugin of plugins) {
513
+ var _plugin$buildStart;
514
+ yield (_plugin$buildStart = plugin.buildStart) === null || _plugin$buildStart === void 0 ? void 0 : _plugin$buildStart.call(plugin, ctx);
515
+ }
516
+ for (const plugin of plugins) {
517
+ var _plugin$virtualModule;
518
+ const modules = yield (_plugin$virtualModule = plugin.virtualModules) === null || _plugin$virtualModule === void 0 ? void 0 : _plugin$virtualModule.call(plugin, ctx);
519
+ if (!modules) continue;
520
+ for (const mod of modules) virtualModules.set(mod.id, mod.code, mod.fileName);
521
+ emitVirtualEntries(modules, _this);
522
+ }
523
+ })();
524
+ },
525
+ resolveId(id, importer) {
526
+ const resolvedVirtual = virtualModules.resolve(id, importer);
527
+ if (resolvedVirtual) return {
528
+ id: resolvedVirtual,
529
+ moduleSideEffects: "no-treeshake"
530
+ };
531
+ if (target === "rollup") {
532
+ const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
533
+ if (resolvedTs) return resolvedTs;
534
+ }
535
+ return null;
536
+ },
537
+ load(id) {
538
+ return virtualModules.load(id);
539
+ },
540
+ transform(code, id) {
541
+ return _asyncToGenerator(function* () {
542
+ const shouldRunZeus = shouldCompileZeus(id);
543
+ const shouldStripTs = resolveTranspile(options.transpile, target) && isTypeScriptLike(id);
544
+ if (!shouldRunZeus && !shouldStripTs) return null;
545
+ return yield transformZeus({
546
+ id,
547
+ code,
548
+ compiler: shouldRunZeus ? options.compiler : false,
549
+ sourcemap: true,
550
+ transpile: shouldStripTs
551
+ });
552
+ })();
553
+ },
554
+ generateBundle(_, bundle) {
555
+ var _this2 = this;
556
+ return _asyncToGenerator(function* () {
557
+ var _options$plugins2;
558
+ if (!ctx) return;
559
+ const plugins = (_options$plugins2 = options.plugins) !== null && _options$plugins2 !== void 0 ? _options$plugins2 : [];
560
+ for (const plugin of plugins) {
561
+ var _plugin$generateBundl;
562
+ const files = yield (_plugin$generateBundl = plugin.generateBundle) === null || _plugin$generateBundl === void 0 ? void 0 : _plugin$generateBundl.call(plugin, ctx, bundle);
563
+ if (!files) continue;
564
+ for (const file of files) emitOutputFile(_this2, file);
565
+ }
566
+ })();
567
+ }
568
+ };
569
+ }
570
+ function resolvePluginName(target) {
571
+ if (target === "vite") return "vite-plugin-zeus";
572
+ if (target === "rolldown") return "rolldown-plugin-zeus";
573
+ return "rollup-plugin-zeus";
574
+ }
575
+ function resolveTranspile(value, target) {
576
+ if (typeof value === "boolean") return value;
577
+ return target === "rollup";
578
+ }
579
+ function resolveRoot(root) {
580
+ if (typeof root === "function") return path.resolve(root());
581
+ return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
582
+ }
583
+ function createManifest(_x, _x2, _x3) {
584
+ return _createManifest.apply(this, arguments);
585
+ }
586
+ function _createManifest() {
587
+ _createManifest = _asyncToGenerator(function* (root, include, exclude) {
588
+ if (!include.length) return {
589
+ manifest: {
590
+ version: 1,
591
+ components: []
592
+ },
593
+ diagnostics: []
594
+ };
595
+ return yield analyzeComponents({
596
+ root,
597
+ include,
598
+ exclude
599
+ });
600
+ });
601
+ return _createManifest.apply(this, arguments);
602
+ }
603
+ function collectWatchFiles(_x4, _x5, _x6) {
604
+ return _collectWatchFiles.apply(this, arguments);
605
+ }
606
+ function _collectWatchFiles() {
607
+ _collectWatchFiles = _asyncToGenerator(function* (root, include, exclude) {
608
+ if (!include.length) return [];
609
+ return yield fg(include, {
610
+ cwd: root,
611
+ absolute: true,
612
+ ignore: exclude
613
+ });
614
+ });
615
+ return _collectWatchFiles.apply(this, arguments);
616
+ }
617
+ function resolveTsLikeImport(id, importer, options) {
618
+ var _options$extensions;
619
+ if (!importer) return null;
620
+ if (cleanUrl(id) !== id) return null;
621
+ const source = cleanUrl(id);
622
+ const from = cleanUrl(importer);
623
+ if (source.startsWith("\0") || from.startsWith("\0")) return null;
624
+ if (!source.startsWith(".") && !isAbsoluteImportPath(source)) return null;
625
+ if (path.extname(source)) return null;
626
+ if (options.extensions === false) return null;
627
+ const extensions = (_options$extensions = options.extensions) !== null && _options$extensions !== void 0 ? _options$extensions : [
628
+ ".ts",
629
+ ".tsx",
630
+ ".mts",
631
+ ".cts",
632
+ ".js",
633
+ ".jsx",
634
+ ".mjs",
635
+ ".cjs"
636
+ ];
637
+ const base = isAbsoluteImportPath(source) ? source : path.resolve(path.dirname(from), source);
638
+ const candidates = [
639
+ base,
640
+ ...extensions.map((ext) => `${base}${ext}`),
641
+ ...extensions.map((ext) => path.join(base, `index${ext}`))
642
+ ];
643
+ for (const file of candidates) if (fs.existsSync(file) && fs.statSync(file).isFile()) return file;
644
+ return null;
645
+ }
646
+ function isAbsoluteImportPath(id) {
647
+ return path.isAbsolute(id) || /^[a-zA-Z]:[\\/]/.test(id);
648
+ }
649
+ function emitOutputFile(pluginContext, file) {
650
+ if (file.type === "asset") {
651
+ pluginContext.emitFile({
652
+ type: "asset",
653
+ fileName: file.fileName,
654
+ source: file.source
655
+ });
656
+ return;
657
+ }
658
+ pluginContext.emitFile({
659
+ type: "chunk",
660
+ id: file.id,
661
+ fileName: file.fileName
662
+ });
663
+ }
664
+ function emitVirtualEntries(modules, pluginContext) {
665
+ for (const mod of modules) {
666
+ if (!mod.fileName) continue;
667
+ pluginContext.emitFile({
668
+ type: "chunk",
669
+ id: mod.id,
670
+ fileName: mod.fileName,
671
+ preserveSignature: "strict"
672
+ });
673
+ }
674
+ }
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];
692
+ }
693
+ //#endregion
694
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectWithoutPropertiesLoose.js
695
+ function _objectWithoutPropertiesLoose(r, e) {
696
+ if (null == r) return {};
697
+ var t = {};
698
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
699
+ if (e.includes(n)) continue;
700
+ t[n] = r[n];
701
+ }
702
+ return t;
703
+ }
704
+ //#endregion
705
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectWithoutProperties.js
706
+ function _objectWithoutProperties(e, t) {
707
+ if (null == e) return {};
708
+ var o, r, i = _objectWithoutPropertiesLoose(e, t);
709
+ if (Object.getOwnPropertySymbols) {
710
+ var s = Object.getOwnPropertySymbols(e);
711
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
712
+ }
713
+ return i;
714
+ }
715
+ //#endregion
716
+ //#region packages/web-c/bundler-plugin/src/rolldown.ts
717
+ const _excluded = [
718
+ "zeus",
719
+ "plugins",
720
+ "input",
721
+ "output",
722
+ "external"
723
+ ];
724
+ function zeus(options = {}) {
725
+ return createZeusBundlerPlugin(options, { target: "rolldown" });
726
+ }
727
+ function defineZeusRolldownConfig(config = {}) {
728
+ const { zeus: zeusOptions = {}, plugins, input, output, external } = config, rest = _objectWithoutProperties(config, _excluded);
729
+ const pluginExternals = collectPluginExternals(zeusOptions);
730
+ return _objectSpread2(_objectSpread2({ input: input !== null && input !== void 0 ? input : "src/index.ts" }, rest), {}, {
731
+ external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
732
+ plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
733
+ output: output !== null && output !== void 0 ? output : {
734
+ dir: "dist",
735
+ format: "esm",
736
+ sourcemap: true
737
+ }
738
+ });
739
+ }
740
+ function normalizePlugins(plugins) {
741
+ if (!plugins) return [];
742
+ return Array.isArray(plugins) ? plugins.filter(Boolean) : [plugins].filter(Boolean);
743
+ }
744
+ //#endregion
745
+ export { zeus as default, zeus, defineZeusRolldownConfig };