@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.
- package/dist/bundler-plugin.cjs.js +225 -49
- package/dist/bundler-plugin.cjs.prod.js +225 -49
- package/dist/bundler-plugin.d.ts +51 -12
- package/dist/bundler-plugin.esm-bundler.js +224 -55
- package/dist/outputPlugins/manifest.cjs.js +1 -1
- package/dist/outputPlugins/manifest.cjs.prod.js +1 -1
- package/dist/outputPlugins/manifest.d.ts +86 -2
- package/dist/outputPlugins/manifest.js +1 -1
- package/dist/outputPlugins/manifest.prod.js +1 -1
- package/dist/rolldown.cjs.js +691 -0
- package/dist/rolldown.cjs.prod.js +691 -0
- package/dist/rolldown.d.ts +164 -0
- package/dist/rolldown.js +820 -0
- package/dist/rolldown.prod.js +820 -0
- package/dist/rollup.cjs.js +691 -0
- package/dist/rollup.cjs.prod.js +691 -0
- package/dist/rollup.d.ts +164 -0
- package/dist/rollup.js +820 -0
- package/dist/rollup.prod.js +820 -0
- package/dist/vite.cjs.js +226 -63
- package/dist/vite.cjs.prod.js +226 -63
- package/dist/vite.d.ts +156 -4
- package/dist/vite.js +230 -72
- package/dist/vite.prod.js +230 -72
- package/package.json +29 -9
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* bundler-plugin v0.1.0-beta.
|
|
2
|
+
* bundler-plugin v0.1.0-beta.3
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
6
|
+
import fs from "node:fs";
|
|
6
7
|
import path from "node:path";
|
|
7
8
|
import { analyzeComponents } from "@zeus-js/component-analyzer";
|
|
8
9
|
import fg from "fast-glob";
|
|
9
10
|
import picomatch from "picomatch";
|
|
10
|
-
import fs from "node:fs/promises";
|
|
11
|
+
import fs$1 from "node:fs/promises";
|
|
11
12
|
import { transformAsync } from "@babel/core";
|
|
13
|
+
import presetTypeScript from "@babel/preset-typescript";
|
|
12
14
|
import zeusCompiler from "@zeus-js/compiler";
|
|
13
15
|
//#region packages/web-c/bundler-plugin/src/filter.ts
|
|
14
16
|
function cleanUrl(id) {
|
|
15
17
|
return id.replace(/[?#].*$/, "");
|
|
16
18
|
}
|
|
19
|
+
function isTypeScriptLike(id) {
|
|
20
|
+
return /\.[cm]?tsx?$/.test(cleanUrl(id));
|
|
21
|
+
}
|
|
17
22
|
//#endregion
|
|
18
23
|
//#region packages/web-c/bundler-plugin/src/componentTransformFilter.ts
|
|
19
24
|
function normalizePath$1(value) {
|
|
@@ -42,12 +47,28 @@ const DEFAULT_COMPONENT_EXCLUDE = [
|
|
|
42
47
|
"node_modules/**",
|
|
43
48
|
"dist/**"
|
|
44
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
|
+
];
|
|
45
59
|
function resolveComponentInclude(include) {
|
|
46
60
|
return (include === null || include === void 0 ? void 0 : include.length) ? include : DEFAULT_COMPONENT_INCLUDE;
|
|
47
61
|
}
|
|
48
62
|
function resolveComponentExclude(exclude) {
|
|
49
63
|
return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_COMPONENT_EXCLUDE;
|
|
50
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
|
+
}
|
|
51
72
|
//#endregion
|
|
52
73
|
//#region packages/web-c/bundler-plugin/src/diagnostics.ts
|
|
53
74
|
function formatDiagnostic(diagnostic) {
|
|
@@ -57,7 +78,7 @@ function hasErrorDiagnostics(diagnostics) {
|
|
|
57
78
|
return diagnostics.some((item) => item.level === "error");
|
|
58
79
|
}
|
|
59
80
|
//#endregion
|
|
60
|
-
//#region \0@oxc-project+runtime@0.
|
|
81
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/asyncToGenerator.js
|
|
61
82
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
62
83
|
try {
|
|
63
84
|
var i = n[a](c), u = i.value;
|
|
@@ -83,7 +104,7 @@ function _asyncToGenerator(n) {
|
|
|
83
104
|
};
|
|
84
105
|
}
|
|
85
106
|
//#endregion
|
|
86
|
-
//#region \0@oxc-project+runtime@0.
|
|
107
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
|
|
87
108
|
function _typeof(o) {
|
|
88
109
|
"@babel/helpers - typeof";
|
|
89
110
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -93,7 +114,7 @@ function _typeof(o) {
|
|
|
93
114
|
}, _typeof(o);
|
|
94
115
|
}
|
|
95
116
|
//#endregion
|
|
96
|
-
//#region \0@oxc-project+runtime@0.
|
|
117
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
|
|
97
118
|
function toPrimitive(t, r) {
|
|
98
119
|
if ("object" != _typeof(t) || !t) return t;
|
|
99
120
|
var e = t[Symbol.toPrimitive];
|
|
@@ -105,13 +126,13 @@ function toPrimitive(t, r) {
|
|
|
105
126
|
return ("string" === r ? String : Number)(t);
|
|
106
127
|
}
|
|
107
128
|
//#endregion
|
|
108
|
-
//#region \0@oxc-project+runtime@0.
|
|
129
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
|
|
109
130
|
function toPropertyKey(t) {
|
|
110
131
|
var i = toPrimitive(t, "string");
|
|
111
132
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
112
133
|
}
|
|
113
134
|
//#endregion
|
|
114
|
-
//#region \0@oxc-project+runtime@0.
|
|
135
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
|
|
115
136
|
function _defineProperty(e, r, t) {
|
|
116
137
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
117
138
|
value: t,
|
|
@@ -121,7 +142,7 @@ function _defineProperty(e, r, t) {
|
|
|
121
142
|
}) : e[r] = t, e;
|
|
122
143
|
}
|
|
123
144
|
//#endregion
|
|
124
|
-
//#region \0@oxc-project+runtime@0.
|
|
145
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectSpread2.js
|
|
125
146
|
function ownKeys(e, r) {
|
|
126
147
|
var t = Object.keys(e);
|
|
127
148
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -229,7 +250,7 @@ function readPackageJson(_x5) {
|
|
|
229
250
|
function _readPackageJson() {
|
|
230
251
|
_readPackageJson = _asyncToGenerator(function* (root) {
|
|
231
252
|
try {
|
|
232
|
-
return JSON.parse(yield fs.readFile(path.join(root, "package.json"), "utf-8"));
|
|
253
|
+
return JSON.parse(yield fs$1.readFile(path.join(root, "package.json"), "utf-8"));
|
|
233
254
|
} catch (_unused) {
|
|
234
255
|
return null;
|
|
235
256
|
}
|
|
@@ -242,7 +263,7 @@ function fileExists(_x6) {
|
|
|
242
263
|
function _fileExists() {
|
|
243
264
|
_fileExists = _asyncToGenerator(function* (file) {
|
|
244
265
|
try {
|
|
245
|
-
yield fs.access(file);
|
|
266
|
+
yield fs$1.access(file);
|
|
246
267
|
return true;
|
|
247
268
|
} catch (_unused2) {
|
|
248
269
|
return false;
|
|
@@ -251,6 +272,42 @@ function _fileExists() {
|
|
|
251
272
|
return _fileExists.apply(this, arguments);
|
|
252
273
|
}
|
|
253
274
|
//#endregion
|
|
275
|
+
//#region packages/web-c/bundler-plugin/src/external.ts
|
|
276
|
+
const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
|
|
277
|
+
function collectPluginExternals(options, collectOptions = {}) {
|
|
278
|
+
var _options$plugins;
|
|
279
|
+
const entries = [];
|
|
280
|
+
if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
|
|
281
|
+
for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
|
|
282
|
+
var _plugin$external;
|
|
283
|
+
for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
|
|
284
|
+
}
|
|
285
|
+
return uniqueExternalEntries(entries);
|
|
286
|
+
}
|
|
287
|
+
function mergeExternal(userExternal, pluginExternal) {
|
|
288
|
+
if (!userExternal) return pluginExternal;
|
|
289
|
+
if (typeof userExternal === "function") return (source, importer, isResolved) => {
|
|
290
|
+
return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
|
|
291
|
+
};
|
|
292
|
+
return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
|
|
293
|
+
}
|
|
294
|
+
function matchesExternal(source, entries) {
|
|
295
|
+
return entries.some((entry) => {
|
|
296
|
+
return typeof entry === "string" ? entry === source : entry.test(source);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
function uniqueExternalEntries(entries) {
|
|
300
|
+
const seen = /* @__PURE__ */ new Set();
|
|
301
|
+
const result = [];
|
|
302
|
+
for (const entry of entries) {
|
|
303
|
+
const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
|
|
304
|
+
if (seen.has(key)) continue;
|
|
305
|
+
seen.add(key);
|
|
306
|
+
result.push(entry);
|
|
307
|
+
}
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
254
311
|
//#region packages/web-c/bundler-plugin/src/outputRegistry.ts
|
|
255
312
|
function createOutputRegistry() {
|
|
256
313
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -309,17 +366,28 @@ function transformZeus(_x) {
|
|
|
309
366
|
}
|
|
310
367
|
function _transformZeus() {
|
|
311
368
|
_transformZeus = _asyncToGenerator(function* (options) {
|
|
312
|
-
var
|
|
313
|
-
const { id, code, compiler, sourcemap = true } = options;
|
|
369
|
+
var _compilerOptions$modu;
|
|
370
|
+
const { id, code, compiler, sourcemap = true, transpile = false } = options;
|
|
371
|
+
const isTs = isTypeScriptLike(id);
|
|
372
|
+
const isTsx = /\.[cm]?tsx$/.test(id.replace(/[?#].*$/, ""));
|
|
373
|
+
const shouldRunCompiler = compiler !== false;
|
|
374
|
+
const shouldStripTs = transpile && isTs;
|
|
375
|
+
if (!shouldRunCompiler && !shouldStripTs) return null;
|
|
376
|
+
const compilerOptions = compiler === false ? {} : compiler === void 0 ? {} : compiler;
|
|
314
377
|
const result = yield transformAsync(code, {
|
|
315
378
|
filename: id,
|
|
316
379
|
sourceMaps: sourcemap,
|
|
317
|
-
plugins: [[zeusCompiler, _objectSpread2({
|
|
318
|
-
moduleName: (
|
|
380
|
+
plugins: shouldRunCompiler ? [[zeusCompiler, _objectSpread2({
|
|
381
|
+
moduleName: (_compilerOptions$modu = compilerOptions.moduleName) !== null && _compilerOptions$modu !== void 0 ? _compilerOptions$modu : "@zeus-js/runtime-dom",
|
|
319
382
|
generate: "dom",
|
|
320
383
|
hydratable: false,
|
|
321
384
|
delegateEvents: true
|
|
322
|
-
},
|
|
385
|
+
}, compilerOptions)]] : [],
|
|
386
|
+
presets: shouldStripTs ? [[presetTypeScript, {
|
|
387
|
+
allExtensions: true,
|
|
388
|
+
isTSX: isTsx,
|
|
389
|
+
allowDeclareFields: true
|
|
390
|
+
}]] : [],
|
|
323
391
|
parserOpts: {
|
|
324
392
|
sourceType: "module",
|
|
325
393
|
plugins: ["typescript", "jsx"]
|
|
@@ -420,34 +488,55 @@ function normalizePath(value) {
|
|
|
420
488
|
return value.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
421
489
|
}
|
|
422
490
|
//#endregion
|
|
423
|
-
//#region packages/web-c/bundler-plugin/src/
|
|
424
|
-
function
|
|
425
|
-
|
|
426
|
-
|
|
491
|
+
//#region packages/web-c/bundler-plugin/src/core.ts
|
|
492
|
+
function createZeusBundlerPlugin(options = {}, createOptions) {
|
|
493
|
+
const target = createOptions.target;
|
|
494
|
+
let shouldCompileZeus = (_id) => false;
|
|
427
495
|
let ctx;
|
|
496
|
+
let root = process.cwd();
|
|
497
|
+
const cleanedOutputDirs = /* @__PURE__ */ new Set();
|
|
498
|
+
const virtualModules = new VirtualModuleRegistry();
|
|
428
499
|
return {
|
|
429
|
-
name:
|
|
500
|
+
name: resolvePluginName(target),
|
|
501
|
+
options(inputOptions) {
|
|
502
|
+
if (target === "vite") return null;
|
|
503
|
+
const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
|
|
504
|
+
if (!pluginExternals.length) return null;
|
|
505
|
+
return _objectSpread2(_objectSpread2({}, inputOptions), {}, { external: mergeExternal(inputOptions.external, pluginExternals) });
|
|
506
|
+
},
|
|
507
|
+
outputOptions(outputOptions) {
|
|
508
|
+
if (target === "vite") return null;
|
|
509
|
+
cleanOutputDir(outputOptions, {
|
|
510
|
+
root: resolveRoot(options.root),
|
|
511
|
+
enabled: options.clean !== false,
|
|
512
|
+
cleanedOutputDirs
|
|
513
|
+
});
|
|
514
|
+
if (outputOptions.chunkFileNames) return null;
|
|
515
|
+
return _objectSpread2(_objectSpread2({}, outputOptions), {}, { chunkFileNames: "chunks/[name]-[hash].js" });
|
|
516
|
+
},
|
|
430
517
|
buildStart() {
|
|
431
518
|
var _this = this;
|
|
432
519
|
return _asyncToGenerator(function* () {
|
|
433
|
-
var _options$components, _options$components2, _options$plugins;
|
|
520
|
+
var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
|
|
434
521
|
virtualModules.clear();
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
const
|
|
438
|
-
|
|
522
|
+
root = resolveRoot(options.root);
|
|
523
|
+
const componentInclude = resolveComponentInclude((_options$components = options.components) === null || _options$components === void 0 ? void 0 : _options$components.include);
|
|
524
|
+
const componentExclude = resolveComponentExclude((_options$components2 = options.components) === null || _options$components2 === void 0 ? void 0 : _options$components2.exclude);
|
|
525
|
+
const transformInclude = resolveTransformInclude((_options$transform = options.transform) === null || _options$transform === void 0 ? void 0 : _options$transform.include, componentInclude);
|
|
526
|
+
const transformExclude = resolveTransformExclude((_options$transform2 = options.transform) === null || _options$transform2 === void 0 ? void 0 : _options$transform2.exclude);
|
|
527
|
+
shouldCompileZeus = createComponentTransformFilter({
|
|
439
528
|
root,
|
|
440
|
-
include,
|
|
441
|
-
exclude
|
|
529
|
+
include: transformInclude,
|
|
530
|
+
exclude: transformExclude
|
|
442
531
|
});
|
|
443
532
|
const dts = yield resolveDts({
|
|
444
533
|
root,
|
|
445
534
|
mode: options.dts,
|
|
446
|
-
include,
|
|
447
|
-
exclude
|
|
535
|
+
include: componentInclude,
|
|
536
|
+
exclude: componentExclude
|
|
448
537
|
});
|
|
449
|
-
const manifestResult = yield createManifest(root,
|
|
450
|
-
for (const file of yield collectWatchFiles(root,
|
|
538
|
+
const manifestResult = yield createManifest(root, componentInclude, componentExclude);
|
|
539
|
+
for (const file of yield collectWatchFiles(root, componentInclude, componentExclude)) _this.addWatchFile(file);
|
|
451
540
|
const diagnostics = manifestResult.diagnostics;
|
|
452
541
|
for (const diagnostic of diagnostics) {
|
|
453
542
|
const message = formatDiagnostic(diagnostic);
|
|
@@ -456,13 +545,12 @@ function createZeusPlugin(options = {}) {
|
|
|
456
545
|
}
|
|
457
546
|
if (hasErrorDiagnostics(diagnostics)) _this.error("[zeus] component analyzer failed.");
|
|
458
547
|
if (options.diagnostics === "verbose") _this.warn(`[zeus] dts ${dts.enabled ? "enabled" : "disabled"}: ${dts.reason.join(", ") || "no signal"}`);
|
|
459
|
-
const outputs = createOutputRegistry();
|
|
460
548
|
ctx = {
|
|
461
549
|
root,
|
|
462
550
|
manifest: manifestResult.manifest,
|
|
463
551
|
diagnostics,
|
|
464
552
|
dts,
|
|
465
|
-
outputs,
|
|
553
|
+
outputs: createOutputRegistry(),
|
|
466
554
|
emitFile: _this.emitFile.bind(_this),
|
|
467
555
|
warn: _this.warn.bind(_this),
|
|
468
556
|
error: _this.error.bind(_this),
|
|
@@ -488,11 +576,23 @@ function createZeusPlugin(options = {}) {
|
|
|
488
576
|
})();
|
|
489
577
|
},
|
|
490
578
|
resolveId(id, importer) {
|
|
491
|
-
const
|
|
492
|
-
if (
|
|
493
|
-
id:
|
|
579
|
+
const resolvedVirtual = virtualModules.resolve(id, importer);
|
|
580
|
+
if (resolvedVirtual) return {
|
|
581
|
+
id: resolvedVirtual,
|
|
494
582
|
moduleSideEffects: "no-treeshake"
|
|
495
583
|
};
|
|
584
|
+
const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
|
|
585
|
+
if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
|
|
586
|
+
const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
|
|
587
|
+
if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
|
|
588
|
+
id: "\0" + virtualEntryId,
|
|
589
|
+
moduleSideEffects: "no-treeshake"
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
if (target === "rollup") {
|
|
593
|
+
const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
|
|
594
|
+
if (resolvedTs) return resolvedTs;
|
|
595
|
+
}
|
|
496
596
|
return null;
|
|
497
597
|
},
|
|
498
598
|
load(id) {
|
|
@@ -500,15 +600,16 @@ function createZeusPlugin(options = {}) {
|
|
|
500
600
|
},
|
|
501
601
|
transform(code, id) {
|
|
502
602
|
return _asyncToGenerator(function* () {
|
|
503
|
-
|
|
504
|
-
const
|
|
603
|
+
const shouldRunZeus = shouldCompileZeus(id);
|
|
604
|
+
const shouldStripTs = resolveTranspile(options.transpile, target) && isTypeScriptLike(id);
|
|
605
|
+
if (!shouldRunZeus && !shouldStripTs) return null;
|
|
606
|
+
return yield transformZeus({
|
|
505
607
|
id,
|
|
506
608
|
code,
|
|
507
|
-
compiler: options.compiler,
|
|
508
|
-
sourcemap: true
|
|
609
|
+
compiler: shouldRunZeus ? options.compiler : false,
|
|
610
|
+
sourcemap: true,
|
|
611
|
+
transpile: shouldStripTs
|
|
509
612
|
});
|
|
510
|
-
if (!result) return null;
|
|
511
|
-
return result;
|
|
512
613
|
})();
|
|
513
614
|
},
|
|
514
615
|
generateBundle(_, bundle) {
|
|
@@ -527,6 +628,44 @@ function createZeusPlugin(options = {}) {
|
|
|
527
628
|
}
|
|
528
629
|
};
|
|
529
630
|
}
|
|
631
|
+
function resolvePluginName(target) {
|
|
632
|
+
if (target === "vite") return "vite-plugin-zeus";
|
|
633
|
+
if (target === "rolldown") return "rolldown-plugin-zeus";
|
|
634
|
+
return "rollup-plugin-zeus";
|
|
635
|
+
}
|
|
636
|
+
function resolveTranspile(value, target) {
|
|
637
|
+
if (typeof value === "boolean") return value;
|
|
638
|
+
return target === "rollup";
|
|
639
|
+
}
|
|
640
|
+
function resolveRoot(root) {
|
|
641
|
+
if (typeof root === "function") return path.resolve(root());
|
|
642
|
+
return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
|
|
643
|
+
}
|
|
644
|
+
function cleanOutputDir(outputOptions, options) {
|
|
645
|
+
if (!options.enabled) return;
|
|
646
|
+
const outputDir = resolveOutputDir(outputOptions, options.root);
|
|
647
|
+
if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
|
|
648
|
+
if (options.cleanedOutputDirs.has(outputDir)) return;
|
|
649
|
+
options.cleanedOutputDirs.add(outputDir);
|
|
650
|
+
fs.rmSync(outputDir, {
|
|
651
|
+
recursive: true,
|
|
652
|
+
force: true
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
function resolveOutputDir(outputOptions, root) {
|
|
656
|
+
const dir = outputOptions.dir;
|
|
657
|
+
if (typeof dir === "string" && dir.length > 0) return path.resolve(root, dir);
|
|
658
|
+
const file = outputOptions.file;
|
|
659
|
+
if (typeof file === "string" && file.length > 0) return path.dirname(path.resolve(root, file));
|
|
660
|
+
return path.resolve(root, "dist");
|
|
661
|
+
}
|
|
662
|
+
function isSafeCleanTarget(outputDir, root) {
|
|
663
|
+
const resolvedRoot = path.resolve(root);
|
|
664
|
+
const resolvedOutputDir = path.resolve(outputDir);
|
|
665
|
+
if (resolvedOutputDir === resolvedRoot) return false;
|
|
666
|
+
const relative = path.relative(resolvedRoot, resolvedOutputDir);
|
|
667
|
+
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
668
|
+
}
|
|
530
669
|
function createManifest(_x, _x2, _x3) {
|
|
531
670
|
return _createManifest.apply(this, arguments);
|
|
532
671
|
}
|
|
@@ -561,9 +700,37 @@ function _collectWatchFiles() {
|
|
|
561
700
|
});
|
|
562
701
|
return _collectWatchFiles.apply(this, arguments);
|
|
563
702
|
}
|
|
564
|
-
function
|
|
565
|
-
|
|
566
|
-
|
|
703
|
+
function resolveTsLikeImport(id, importer, options) {
|
|
704
|
+
var _options$extensions;
|
|
705
|
+
if (!importer) return null;
|
|
706
|
+
if (cleanUrl(id) !== id) return null;
|
|
707
|
+
const source = cleanUrl(id);
|
|
708
|
+
const from = cleanUrl(importer);
|
|
709
|
+
if (source.startsWith("\0") || from.startsWith("\0")) return null;
|
|
710
|
+
if (!source.startsWith(".") && !isAbsoluteImportPath(source)) return null;
|
|
711
|
+
if (path.extname(source)) return null;
|
|
712
|
+
if (options.extensions === false) return null;
|
|
713
|
+
const extensions = (_options$extensions = options.extensions) !== null && _options$extensions !== void 0 ? _options$extensions : [
|
|
714
|
+
".ts",
|
|
715
|
+
".tsx",
|
|
716
|
+
".mts",
|
|
717
|
+
".cts",
|
|
718
|
+
".js",
|
|
719
|
+
".jsx",
|
|
720
|
+
".mjs",
|
|
721
|
+
".cjs"
|
|
722
|
+
];
|
|
723
|
+
const base = isAbsoluteImportPath(source) ? source : path.resolve(path.dirname(from), source);
|
|
724
|
+
const candidates = [
|
|
725
|
+
base,
|
|
726
|
+
...extensions.map((ext) => `${base}${ext}`),
|
|
727
|
+
...extensions.map((ext) => path.join(base, `index${ext}`))
|
|
728
|
+
];
|
|
729
|
+
for (const file of candidates) if (fs.existsSync(file) && fs.statSync(file).isFile()) return file;
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
function isAbsoluteImportPath(id) {
|
|
733
|
+
return path.isAbsolute(id) || /^[a-zA-Z]:[\\/]/.test(id);
|
|
567
734
|
}
|
|
568
735
|
function emitOutputFile(pluginContext, file) {
|
|
569
736
|
if (file.type === "asset") {
|
|
@@ -591,6 +758,17 @@ function emitVirtualEntries(modules, pluginContext) {
|
|
|
591
758
|
});
|
|
592
759
|
}
|
|
593
760
|
}
|
|
761
|
+
function resolveVirtualEntryImport(id, importer) {
|
|
762
|
+
const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
|
|
763
|
+
const lastColon = importer.lastIndexOf(":");
|
|
764
|
+
if (lastColon <= 0) return null;
|
|
765
|
+
return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
|
|
766
|
+
}
|
|
767
|
+
//#endregion
|
|
768
|
+
//#region packages/web-c/bundler-plugin/src/rollup.ts
|
|
769
|
+
function zeus(options = {}) {
|
|
770
|
+
return createZeusBundlerPlugin(options, { target: "rollup" });
|
|
771
|
+
}
|
|
594
772
|
//#endregion
|
|
595
773
|
//#region packages/web-c/bundler-plugin/src/pluginOptions.ts
|
|
596
774
|
function resolvePluginDts(value, ctx) {
|
|
@@ -599,13 +777,4 @@ function resolvePluginDts(value, ctx) {
|
|
|
599
777
|
return ctx.dts.enabled;
|
|
600
778
|
}
|
|
601
779
|
//#endregion
|
|
602
|
-
|
|
603
|
-
function mergeExternal(userExternal, pluginExternal) {
|
|
604
|
-
if (!userExternal) return pluginExternal;
|
|
605
|
-
if (typeof userExternal === "function") return (source, importer, isResolved) => {
|
|
606
|
-
return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
|
|
607
|
-
};
|
|
608
|
-
return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
|
|
609
|
-
}
|
|
610
|
-
//#endregion
|
|
611
|
-
export { createOutputRegistry, createZeusPlugin, createZeusPlugin as default, createZeusPlugin as zeus, mergeExternal, resolveComponentExclude, resolveComponentInclude, resolvePluginDts };
|
|
780
|
+
export { createOutputRegistry, zeus as default, zeus, mergeExternal, resolveComponentExclude, resolveComponentInclude, resolvePluginDts };
|
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ComponentManifest, AnalyzerDiagnostic } from '@zeus-js/component-analyzer';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
type ZeusOutputKind = 'wc' | 'react' | 'vue' | 'icons-react' | 'icons-vue' | 'icons-wc' | 'asset';
|
|
5
|
+
type DtsMode = boolean | 'auto';
|
|
6
|
+
interface ResolvedDts {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
mode: DtsMode;
|
|
9
|
+
reason: DtsAutoReason[];
|
|
10
|
+
}
|
|
11
|
+
type DtsAutoReason = 'explicit-enabled' | 'explicit-disabled' | 'package-types-field' | 'typescript-dependency' | 'tsconfig' | 'typescript-source';
|
|
12
|
+
interface ZeusBuildContext {
|
|
13
|
+
root: string;
|
|
14
|
+
manifest: ComponentManifest;
|
|
15
|
+
diagnostics: AnalyzerDiagnostic[];
|
|
16
|
+
dts: ResolvedDts;
|
|
17
|
+
outputs: ZeusOutputRegistry;
|
|
18
|
+
emitFile: (file: unknown) => string | void;
|
|
19
|
+
warn: (message: string | Error) => void;
|
|
20
|
+
error: (message: string | Error) => never;
|
|
21
|
+
addWatchFile: (id: string) => void;
|
|
22
|
+
meta: {
|
|
23
|
+
watchMode: boolean;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
type ZeusOutputBundle = Record<string, unknown>;
|
|
27
|
+
interface ZeusOutputRegistry {
|
|
28
|
+
register(kind: ZeusOutputKind, options: ZeusOutputRegistration): void;
|
|
29
|
+
has(kind: ZeusOutputKind): boolean;
|
|
30
|
+
get(kind: ZeusOutputKind): RequiredZeusOutputRegistration;
|
|
31
|
+
getDir(kind: ZeusOutputKind): string;
|
|
32
|
+
getFileName(kind: ZeusOutputKind, tag: string): string;
|
|
33
|
+
join(kind: ZeusOutputKind, fileName: string): string;
|
|
34
|
+
}
|
|
35
|
+
interface ZeusOutputRegistration {
|
|
36
|
+
outDir?: string;
|
|
37
|
+
stripPrefix?: string | false;
|
|
38
|
+
fileName?: (tag: string, kind: ZeusOutputKind) => string;
|
|
39
|
+
}
|
|
40
|
+
interface RequiredZeusOutputRegistration {
|
|
41
|
+
outDir: string;
|
|
42
|
+
stripPrefix: string | false;
|
|
43
|
+
fileName?: (tag: string, kind: ZeusOutputKind) => string;
|
|
44
|
+
}
|
|
45
|
+
interface ZeusVirtualModule {
|
|
46
|
+
id: string;
|
|
47
|
+
code: string;
|
|
48
|
+
fileName?: string;
|
|
49
|
+
}
|
|
50
|
+
interface ZeusOutputAsset {
|
|
51
|
+
type: 'asset';
|
|
52
|
+
fileName: string;
|
|
53
|
+
source: string | Uint8Array;
|
|
54
|
+
}
|
|
55
|
+
interface ZeusOutputChunk {
|
|
56
|
+
type: 'chunk';
|
|
57
|
+
id: string;
|
|
58
|
+
fileName?: string;
|
|
59
|
+
}
|
|
60
|
+
type ZeusOutputFile = ZeusOutputAsset | ZeusOutputChunk;
|
|
61
|
+
interface ZeusComponentPlugin {
|
|
62
|
+
name: string;
|
|
63
|
+
/**
|
|
64
|
+
* Register output dirs / externals / plugin metadata.
|
|
65
|
+
*
|
|
66
|
+
* This hook runs before virtualModules().
|
|
67
|
+
*/
|
|
68
|
+
setup?(ctx: ZeusBuildContext): void | Promise<void>;
|
|
69
|
+
buildStart?(ctx: ZeusBuildContext): MaybePromise<void>;
|
|
70
|
+
virtualModules?(ctx: ZeusBuildContext): MaybePromise<ZeusVirtualModule[] | void>;
|
|
71
|
+
generateBundle?(ctx: ZeusBuildContext, bundle: ZeusOutputBundle): MaybePromise<ZeusOutputFile[] | void>;
|
|
72
|
+
/**
|
|
73
|
+
* Framework dependencies that bundler config helpers should externalize.
|
|
74
|
+
*
|
|
75
|
+
* Used by the Vite adapter, defineZeusRollupConfig(), and
|
|
76
|
+
* defineZeusRolldownConfig().
|
|
77
|
+
*/
|
|
78
|
+
external?: Array<string | RegExp>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface ManifestOutputOptions {
|
|
82
|
+
fileName?: string;
|
|
83
|
+
pretty?: boolean;
|
|
84
|
+
}
|
|
85
|
+
export declare function manifestOutput(options?: ManifestOutputOptions): ZeusComponentPlugin;
|
|
86
|
+
|
|
87
|
+
export { manifestOutput as default };
|