@zeus-js/bundler-plugin 0.1.0-beta.1 → 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.
@@ -0,0 +1,691 @@
1
+ /**
2
+ * bundler-plugin v0.1.0-beta.3
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/external.ts
191
+ const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
192
+ function collectPluginExternals(options, collectOptions = {}) {
193
+ var _options$plugins;
194
+ const entries = [];
195
+ if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
196
+ for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
197
+ var _plugin$external;
198
+ for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
199
+ }
200
+ return uniqueExternalEntries(entries);
201
+ }
202
+ function mergeExternal(userExternal, pluginExternal) {
203
+ if (!userExternal) return pluginExternal;
204
+ if (typeof userExternal === "function") return (source, importer, isResolved) => {
205
+ return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
206
+ };
207
+ return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
208
+ }
209
+ function matchesExternal(source, entries) {
210
+ return entries.some((entry) => {
211
+ return typeof entry === "string" ? entry === source : entry.test(source);
212
+ });
213
+ }
214
+ function uniqueExternalEntries(entries) {
215
+ const seen = /* @__PURE__ */ new Set();
216
+ const result = [];
217
+ for (const entry of entries) {
218
+ const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
219
+ if (seen.has(key)) continue;
220
+ seen.add(key);
221
+ result.push(entry);
222
+ }
223
+ return result;
224
+ }
225
+ //#endregion
226
+ //#region packages/web-c/bundler-plugin/src/outputRegistry.ts
227
+ function createOutputRegistry() {
228
+ const map = /* @__PURE__ */ new Map();
229
+ return {
230
+ register(kind, options) {
231
+ map.set(kind, normalizeRegistration(kind, options));
232
+ },
233
+ has(kind) {
234
+ return map.has(kind);
235
+ },
236
+ get(kind) {
237
+ const current = map.get(kind);
238
+ if (!current) throw new Error(`[zeus] output kind "${kind}" is not registered.`);
239
+ return current;
240
+ },
241
+ getDir(kind) {
242
+ return this.get(kind).outDir;
243
+ },
244
+ getFileName(kind, tag) {
245
+ const current = this.get(kind);
246
+ if (current.fileName) return current.fileName(tag, kind);
247
+ return `${normalizeTagName(tag, current.stripPrefix)}.js`;
248
+ },
249
+ join(kind, fileName) {
250
+ return node_path.default.posix.join(this.getDir(kind), fileName);
251
+ }
252
+ };
253
+ }
254
+ function normalizeRegistration(kind, options) {
255
+ var _options$outDir, _options$stripPrefix;
256
+ return {
257
+ outDir: (_options$outDir = options.outDir) !== null && _options$outDir !== void 0 ? _options$outDir : defaultDir(kind),
258
+ stripPrefix: (_options$stripPrefix = options.stripPrefix) !== null && _options$stripPrefix !== void 0 ? _options$stripPrefix : false,
259
+ fileName: options.fileName
260
+ };
261
+ }
262
+ function defaultDir(kind) {
263
+ switch (kind) {
264
+ case "wc": return "wc";
265
+ case "react": return "react";
266
+ case "vue": return "vue";
267
+ case "icons-react": return "icons/react";
268
+ case "icons-vue": return "icons/vue";
269
+ case "icons-wc": return "icons/wc";
270
+ case "asset": return "";
271
+ }
272
+ }
273
+ function normalizeTagName(tag, stripPrefix) {
274
+ if (stripPrefix && tag.startsWith(stripPrefix)) return tag.slice(stripPrefix.length);
275
+ return tag;
276
+ }
277
+ //#endregion
278
+ //#region packages/web-c/bundler-plugin/src/transform.ts
279
+ async function transformZeus(options) {
280
+ var _compilerOptions$modu;
281
+ const { id, code, compiler, sourcemap = true, transpile = false } = options;
282
+ const isTs = isTypeScriptLike(id);
283
+ const isTsx = /\.[cm]?tsx$/.test(id.replace(/[?#].*$/, ""));
284
+ const shouldRunCompiler = compiler !== false;
285
+ const shouldStripTs = transpile && isTs;
286
+ if (!shouldRunCompiler && !shouldStripTs) return null;
287
+ const compilerOptions = compiler === false ? {} : compiler === void 0 ? {} : compiler;
288
+ const result = await (0, _babel_core.transformAsync)(code, {
289
+ filename: id,
290
+ sourceMaps: sourcemap,
291
+ plugins: shouldRunCompiler ? [[_zeus_js_compiler.default, {
292
+ moduleName: (_compilerOptions$modu = compilerOptions.moduleName) !== null && _compilerOptions$modu !== void 0 ? _compilerOptions$modu : "@zeus-js/runtime-dom",
293
+ generate: "dom",
294
+ hydratable: false,
295
+ delegateEvents: true,
296
+ ...compilerOptions
297
+ }]] : [],
298
+ presets: shouldStripTs ? [[_babel_preset_typescript.default, {
299
+ allExtensions: true,
300
+ isTSX: isTsx,
301
+ allowDeclareFields: true
302
+ }]] : [],
303
+ parserOpts: {
304
+ sourceType: "module",
305
+ plugins: ["typescript", "jsx"]
306
+ },
307
+ generatorOpts: {
308
+ retainLines: false,
309
+ compact: false,
310
+ jsescOption: { minimal: true }
311
+ }
312
+ });
313
+ if (!(result === null || result === void 0 ? void 0 : result.code)) return null;
314
+ return {
315
+ code: result.code,
316
+ map: result.map
317
+ };
318
+ }
319
+ //#endregion
320
+ //#region packages/web-c/bundler-plugin/src/virtual.ts
321
+ const RESOLVED_VIRTUAL_PREFIX = "\0";
322
+ var VirtualModuleRegistry = class {
323
+ constructor() {
324
+ this.modules = /* @__PURE__ */ new Map();
325
+ this.virtualDirs = /* @__PURE__ */ new Map();
326
+ this.virtualFileNames = /* @__PURE__ */ new Map();
327
+ this.idsByFileName = /* @__PURE__ */ new Map();
328
+ }
329
+ set(id, code, fileName) {
330
+ const normalized = normalizeVirtualId(id);
331
+ this.modules.set(normalized, code);
332
+ if (fileName) {
333
+ const dir = node_path.default.posix.dirname(fileName);
334
+ this.virtualDirs.set(normalized, dir);
335
+ const normalizedFileName = normalizePath(fileName);
336
+ this.virtualFileNames.set(normalized, normalizedFileName);
337
+ this.idsByFileName.set(normalizedFileName, normalized);
338
+ }
339
+ }
340
+ has(id) {
341
+ return this.modules.has(normalizeVirtualId(id));
342
+ }
343
+ get(id) {
344
+ return this.modules.get(normalizeVirtualId(id));
345
+ }
346
+ clear() {
347
+ this.modules.clear();
348
+ this.virtualDirs.clear();
349
+ this.virtualFileNames.clear();
350
+ this.idsByFileName.clear();
351
+ }
352
+ resolve(id, importer) {
353
+ const normalized = normalizeVirtualId(id);
354
+ if (this.modules.has(normalized)) return RESOLVED_VIRTUAL_PREFIX + normalized;
355
+ if (importer && (id.startsWith(".") || id.startsWith(".."))) {
356
+ const importerNormalized = normalizeVirtualId(importer);
357
+ const importerDir = this.virtualDirs.get(importerNormalized);
358
+ if (importerDir) {
359
+ const resolved = normalizePath(node_path.default.posix.join(importerDir, id));
360
+ const resolvedVirtualId = this.idsByFileName.get(resolved);
361
+ if (resolvedVirtualId) return RESOLVED_VIRTUAL_PREFIX + resolvedVirtualId;
362
+ const importingPrefix = this.getIdPrefix(importerNormalized);
363
+ if (importingPrefix !== null) {
364
+ const baseName = node_path.default.posix.basename(resolved, ".js");
365
+ for (const [key] of this.modules.entries()) if (key === importingPrefix + baseName) return RESOLVED_VIRTUAL_PREFIX + key;
366
+ for (const stripPrefix of [
367
+ "z-",
368
+ "wc-",
369
+ "wc/",
370
+ ""
371
+ ]) {
372
+ const candidate = stripPrefix ? importingPrefix + stripPrefix + baseName : importingPrefix + baseName;
373
+ if (this.modules.has(candidate)) return RESOLVED_VIRTUAL_PREFIX + candidate;
374
+ }
375
+ const fullName = baseName;
376
+ for (const [key] of this.modules.entries()) if (key.endsWith(":" + fullName)) return RESOLVED_VIRTUAL_PREFIX + key;
377
+ }
378
+ }
379
+ }
380
+ return null;
381
+ }
382
+ getIdPrefix(virtualId) {
383
+ const lastColon = virtualId.lastIndexOf(":");
384
+ if (lastColon <= 0) return null;
385
+ return virtualId.slice(0, lastColon + 1);
386
+ }
387
+ load(id) {
388
+ var _this$modules$get;
389
+ if (!id.startsWith(RESOLVED_VIRTUAL_PREFIX)) return null;
390
+ const normalized = id.slice(1);
391
+ return (_this$modules$get = this.modules.get(normalized)) !== null && _this$modules$get !== void 0 ? _this$modules$get : null;
392
+ }
393
+ };
394
+ function normalizeVirtualId(id) {
395
+ return id.startsWith("\0") ? id.slice(1) : id;
396
+ }
397
+ function normalizePath(value) {
398
+ return value.replace(/\\/g, "/").replace(/^\.\//, "");
399
+ }
400
+ //#endregion
401
+ //#region packages/web-c/bundler-plugin/src/core.ts
402
+ function createZeusBundlerPlugin(options = {}, createOptions) {
403
+ const target = createOptions.target;
404
+ let shouldCompileZeus = (_id) => false;
405
+ let ctx;
406
+ let root = process.cwd();
407
+ const cleanedOutputDirs = /* @__PURE__ */ new Set();
408
+ const virtualModules = new VirtualModuleRegistry();
409
+ return {
410
+ name: resolvePluginName(target),
411
+ options(inputOptions) {
412
+ if (target === "vite") return null;
413
+ const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
414
+ if (!pluginExternals.length) return null;
415
+ return {
416
+ ...inputOptions,
417
+ external: mergeExternal(inputOptions.external, pluginExternals)
418
+ };
419
+ },
420
+ outputOptions(outputOptions) {
421
+ if (target === "vite") return null;
422
+ cleanOutputDir(outputOptions, {
423
+ root: resolveRoot(options.root),
424
+ enabled: options.clean !== false,
425
+ cleanedOutputDirs
426
+ });
427
+ if (outputOptions.chunkFileNames) return null;
428
+ return {
429
+ ...outputOptions,
430
+ chunkFileNames: "chunks/[name]-[hash].js"
431
+ };
432
+ },
433
+ async buildStart() {
434
+ var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
435
+ virtualModules.clear();
436
+ root = resolveRoot(options.root);
437
+ const componentInclude = resolveComponentInclude((_options$components = options.components) === null || _options$components === void 0 ? void 0 : _options$components.include);
438
+ const componentExclude = resolveComponentExclude((_options$components2 = options.components) === null || _options$components2 === void 0 ? void 0 : _options$components2.exclude);
439
+ const transformInclude = resolveTransformInclude((_options$transform = options.transform) === null || _options$transform === void 0 ? void 0 : _options$transform.include, componentInclude);
440
+ const transformExclude = resolveTransformExclude((_options$transform2 = options.transform) === null || _options$transform2 === void 0 ? void 0 : _options$transform2.exclude);
441
+ shouldCompileZeus = createComponentTransformFilter({
442
+ root,
443
+ include: transformInclude,
444
+ exclude: transformExclude
445
+ });
446
+ const dts = await resolveDts({
447
+ root,
448
+ mode: options.dts,
449
+ include: componentInclude,
450
+ exclude: componentExclude
451
+ });
452
+ const manifestResult = await createManifest(root, componentInclude, componentExclude);
453
+ for (const file of await collectWatchFiles(root, componentInclude, componentExclude)) this.addWatchFile(file);
454
+ const diagnostics = manifestResult.diagnostics;
455
+ for (const diagnostic of diagnostics) {
456
+ const message = formatDiagnostic(diagnostic);
457
+ if (diagnostic.level === "error") this.error(message);
458
+ else if (options.diagnostics !== false) this.warn(message);
459
+ }
460
+ if (hasErrorDiagnostics(diagnostics)) this.error("[zeus] component analyzer failed.");
461
+ if (options.diagnostics === "verbose") this.warn(`[zeus] dts ${dts.enabled ? "enabled" : "disabled"}: ${dts.reason.join(", ") || "no signal"}`);
462
+ ctx = {
463
+ root,
464
+ manifest: manifestResult.manifest,
465
+ diagnostics,
466
+ dts,
467
+ outputs: createOutputRegistry(),
468
+ emitFile: this.emitFile.bind(this),
469
+ warn: this.warn.bind(this),
470
+ error: this.error.bind(this),
471
+ addWatchFile: this.addWatchFile.bind(this),
472
+ meta: { watchMode: this.meta.watchMode }
473
+ };
474
+ const plugins = (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : [];
475
+ for (const plugin of plugins) {
476
+ var _plugin$setup;
477
+ await ((_plugin$setup = plugin.setup) === null || _plugin$setup === void 0 ? void 0 : _plugin$setup.call(plugin, ctx));
478
+ }
479
+ for (const plugin of plugins) {
480
+ var _plugin$buildStart;
481
+ await ((_plugin$buildStart = plugin.buildStart) === null || _plugin$buildStart === void 0 ? void 0 : _plugin$buildStart.call(plugin, ctx));
482
+ }
483
+ for (const plugin of plugins) {
484
+ var _plugin$virtualModule;
485
+ const modules = await ((_plugin$virtualModule = plugin.virtualModules) === null || _plugin$virtualModule === void 0 ? void 0 : _plugin$virtualModule.call(plugin, ctx));
486
+ if (!modules) continue;
487
+ for (const mod of modules) virtualModules.set(mod.id, mod.code, mod.fileName);
488
+ emitVirtualEntries(modules, this);
489
+ }
490
+ },
491
+ resolveId(id, importer) {
492
+ const resolvedVirtual = virtualModules.resolve(id, importer);
493
+ if (resolvedVirtual) return {
494
+ id: resolvedVirtual,
495
+ moduleSideEffects: "no-treeshake"
496
+ };
497
+ const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
498
+ if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
499
+ const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
500
+ if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
501
+ id: "\0" + virtualEntryId,
502
+ moduleSideEffects: "no-treeshake"
503
+ };
504
+ }
505
+ if (target === "rollup") {
506
+ const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
507
+ if (resolvedTs) return resolvedTs;
508
+ }
509
+ return null;
510
+ },
511
+ load(id) {
512
+ return virtualModules.load(id);
513
+ },
514
+ async transform(code, id) {
515
+ const shouldRunZeus = shouldCompileZeus(id);
516
+ const shouldStripTs = resolveTranspile(options.transpile, target) && isTypeScriptLike(id);
517
+ if (!shouldRunZeus && !shouldStripTs) return null;
518
+ return await transformZeus({
519
+ id,
520
+ code,
521
+ compiler: shouldRunZeus ? options.compiler : false,
522
+ sourcemap: true,
523
+ transpile: shouldStripTs
524
+ });
525
+ },
526
+ async generateBundle(_, bundle) {
527
+ var _options$plugins2;
528
+ if (!ctx) return;
529
+ const plugins = (_options$plugins2 = options.plugins) !== null && _options$plugins2 !== void 0 ? _options$plugins2 : [];
530
+ for (const plugin of plugins) {
531
+ var _plugin$generateBundl;
532
+ const files = await ((_plugin$generateBundl = plugin.generateBundle) === null || _plugin$generateBundl === void 0 ? void 0 : _plugin$generateBundl.call(plugin, ctx, bundle));
533
+ if (!files) continue;
534
+ for (const file of files) emitOutputFile(this, file);
535
+ }
536
+ }
537
+ };
538
+ }
539
+ function resolvePluginName(target) {
540
+ if (target === "vite") return "vite-plugin-zeus";
541
+ if (target === "rolldown") return "rolldown-plugin-zeus";
542
+ return "rollup-plugin-zeus";
543
+ }
544
+ function resolveTranspile(value, target) {
545
+ if (typeof value === "boolean") return value;
546
+ return target === "rollup";
547
+ }
548
+ function resolveRoot(root) {
549
+ if (typeof root === "function") return node_path.default.resolve(root());
550
+ return node_path.default.resolve(root !== null && root !== void 0 ? root : process.cwd());
551
+ }
552
+ function cleanOutputDir(outputOptions, options) {
553
+ if (!options.enabled) return;
554
+ const outputDir = resolveOutputDir(outputOptions, options.root);
555
+ if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
556
+ if (options.cleanedOutputDirs.has(outputDir)) return;
557
+ options.cleanedOutputDirs.add(outputDir);
558
+ node_fs.default.rmSync(outputDir, {
559
+ recursive: true,
560
+ force: true
561
+ });
562
+ }
563
+ function resolveOutputDir(outputOptions, root) {
564
+ const dir = outputOptions.dir;
565
+ if (typeof dir === "string" && dir.length > 0) return node_path.default.resolve(root, dir);
566
+ const file = outputOptions.file;
567
+ if (typeof file === "string" && file.length > 0) return node_path.default.dirname(node_path.default.resolve(root, file));
568
+ return node_path.default.resolve(root, "dist");
569
+ }
570
+ function isSafeCleanTarget(outputDir, root) {
571
+ const resolvedRoot = node_path.default.resolve(root);
572
+ const resolvedOutputDir = node_path.default.resolve(outputDir);
573
+ if (resolvedOutputDir === resolvedRoot) return false;
574
+ const relative = node_path.default.relative(resolvedRoot, resolvedOutputDir);
575
+ return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
576
+ }
577
+ async function createManifest(root, include, exclude) {
578
+ if (!include.length) return {
579
+ manifest: {
580
+ version: 1,
581
+ components: []
582
+ },
583
+ diagnostics: []
584
+ };
585
+ return await (0, _zeus_js_component_analyzer.analyzeComponents)({
586
+ root,
587
+ include,
588
+ exclude
589
+ });
590
+ }
591
+ async function collectWatchFiles(root, include, exclude) {
592
+ if (!include.length) return [];
593
+ return await (0, fast_glob.default)(include, {
594
+ cwd: root,
595
+ absolute: true,
596
+ ignore: exclude
597
+ });
598
+ }
599
+ function resolveTsLikeImport(id, importer, options) {
600
+ var _options$extensions;
601
+ if (!importer) return null;
602
+ if (cleanUrl(id) !== id) return null;
603
+ const source = cleanUrl(id);
604
+ const from = cleanUrl(importer);
605
+ if (source.startsWith("\0") || from.startsWith("\0")) return null;
606
+ if (!source.startsWith(".") && !isAbsoluteImportPath(source)) return null;
607
+ if (node_path.default.extname(source)) return null;
608
+ if (options.extensions === false) return null;
609
+ const extensions = (_options$extensions = options.extensions) !== null && _options$extensions !== void 0 ? _options$extensions : [
610
+ ".ts",
611
+ ".tsx",
612
+ ".mts",
613
+ ".cts",
614
+ ".js",
615
+ ".jsx",
616
+ ".mjs",
617
+ ".cjs"
618
+ ];
619
+ const base = isAbsoluteImportPath(source) ? source : node_path.default.resolve(node_path.default.dirname(from), source);
620
+ const candidates = [
621
+ base,
622
+ ...extensions.map((ext) => `${base}${ext}`),
623
+ ...extensions.map((ext) => node_path.default.join(base, `index${ext}`))
624
+ ];
625
+ for (const file of candidates) if (node_fs.default.existsSync(file) && node_fs.default.statSync(file).isFile()) return file;
626
+ return null;
627
+ }
628
+ function isAbsoluteImportPath(id) {
629
+ return node_path.default.isAbsolute(id) || /^[a-zA-Z]:[\\/]/.test(id);
630
+ }
631
+ function emitOutputFile(pluginContext, file) {
632
+ if (file.type === "asset") {
633
+ pluginContext.emitFile({
634
+ type: "asset",
635
+ fileName: file.fileName,
636
+ source: file.source
637
+ });
638
+ return;
639
+ }
640
+ pluginContext.emitFile({
641
+ type: "chunk",
642
+ id: file.id,
643
+ fileName: file.fileName
644
+ });
645
+ }
646
+ function emitVirtualEntries(modules, pluginContext) {
647
+ for (const mod of modules) {
648
+ if (!mod.fileName) continue;
649
+ pluginContext.emitFile({
650
+ type: "chunk",
651
+ id: mod.id,
652
+ fileName: mod.fileName,
653
+ preserveSignature: "strict"
654
+ });
655
+ }
656
+ }
657
+ function resolveVirtualEntryImport(id, importer) {
658
+ const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
659
+ const lastColon = importer.lastIndexOf(":");
660
+ if (lastColon <= 0) return null;
661
+ return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
662
+ }
663
+ //#endregion
664
+ //#region packages/web-c/bundler-plugin/src/rolldown.ts
665
+ function zeus(options = {}) {
666
+ return createZeusBundlerPlugin(options, { target: "rolldown" });
667
+ }
668
+ function defineZeusRolldownConfig(config = {}) {
669
+ const { zeus: zeusOptions = {}, plugins, input, output, external, ...rest } = config;
670
+ const pluginExternals = collectPluginExternals(zeusOptions, { includeZeusLibraryExternals: true });
671
+ return {
672
+ input: input !== null && input !== void 0 ? input : "src/index.ts",
673
+ ...rest,
674
+ external: pluginExternals.length ? mergeExternal(external, pluginExternals) : external,
675
+ plugins: [zeus(zeusOptions), ...normalizePlugins(plugins)],
676
+ output: output !== null && output !== void 0 ? output : {
677
+ dir: "dist",
678
+ format: "esm",
679
+ chunkFileNames: "chunks/[name]-[hash].js",
680
+ sourcemap: true
681
+ }
682
+ };
683
+ }
684
+ function normalizePlugins(plugins) {
685
+ if (!plugins) return [];
686
+ return Array.isArray(plugins) ? plugins.filter(Boolean) : [plugins].filter(Boolean);
687
+ }
688
+ //#endregion
689
+ exports.default = zeus;
690
+ exports.zeus = zeus;
691
+ exports.defineZeusRolldownConfig = defineZeusRolldownConfig;