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