@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.
- package/dist/bundler-plugin.cjs.js +135 -48
- package/dist/bundler-plugin.cjs.prod.js +135 -48
- package/dist/bundler-plugin.d.ts +40 -10
- package/dist/bundler-plugin.esm-bundler.js +134 -48
- 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 +610 -0
- package/dist/rolldown.cjs.prod.js +610 -0
- package/dist/rolldown.d.ts +156 -0
- package/dist/rolldown.js +745 -0
- package/dist/rolldown.prod.js +745 -0
- package/dist/rollup.cjs.js +610 -0
- package/dist/rollup.cjs.prod.js +610 -0
- package/dist/rollup.d.ts +156 -0
- package/dist/rollup.js +745 -0
- package/dist/rollup.prod.js +745 -0
- package/dist/vite.cjs.js +146 -63
- package/dist/vite.cjs.prod.js +146 -63
- package/dist/vite.d.ts +148 -4
- package/dist/vite.js +150 -66
- package/dist/vite.prod.js +150 -66
- package/package.json +25 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* bundler-plugin v0.1.0-beta.
|
|
2
|
+
* bundler-plugin v0.1.0-beta.2
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -29,6 +29,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
enumerable: true
|
|
30
30
|
}) : target, mod));
|
|
31
31
|
//#endregion
|
|
32
|
+
let node_fs = require("node:fs");
|
|
33
|
+
node_fs = __toESM(node_fs, 1);
|
|
32
34
|
let node_path = require("node:path");
|
|
33
35
|
node_path = __toESM(node_path, 1);
|
|
34
36
|
let _zeus_js_component_analyzer = require("@zeus-js/component-analyzer");
|
|
@@ -39,12 +41,17 @@ picomatch = __toESM(picomatch, 1);
|
|
|
39
41
|
let node_fs_promises = require("node:fs/promises");
|
|
40
42
|
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
41
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);
|
|
42
46
|
let _zeus_js_compiler = require("@zeus-js/compiler");
|
|
43
47
|
_zeus_js_compiler = __toESM(_zeus_js_compiler, 1);
|
|
44
48
|
//#region packages/web-c/bundler-plugin/src/filter.ts
|
|
45
49
|
function cleanUrl(id) {
|
|
46
50
|
return id.replace(/[?#].*$/, "");
|
|
47
51
|
}
|
|
52
|
+
function isTypeScriptLike(id) {
|
|
53
|
+
return /\.[cm]?tsx?$/.test(cleanUrl(id));
|
|
54
|
+
}
|
|
48
55
|
//#endregion
|
|
49
56
|
//#region packages/web-c/bundler-plugin/src/componentTransformFilter.ts
|
|
50
57
|
function normalizePath$1(value) {
|
|
@@ -73,12 +80,28 @@ const DEFAULT_COMPONENT_EXCLUDE = [
|
|
|
73
80
|
"node_modules/**",
|
|
74
81
|
"dist/**"
|
|
75
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
|
+
];
|
|
76
92
|
function resolveComponentInclude(include) {
|
|
77
93
|
return (include === null || include === void 0 ? void 0 : include.length) ? include : DEFAULT_COMPONENT_INCLUDE;
|
|
78
94
|
}
|
|
79
95
|
function resolveComponentExclude(exclude) {
|
|
80
96
|
return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_COMPONENT_EXCLUDE;
|
|
81
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
|
+
}
|
|
82
105
|
//#endregion
|
|
83
106
|
//#region packages/web-c/bundler-plugin/src/diagnostics.ts
|
|
84
107
|
function formatDiagnostic(diagnostic) {
|
|
@@ -218,18 +241,29 @@ function normalizeTagName(tag, stripPrefix) {
|
|
|
218
241
|
//#endregion
|
|
219
242
|
//#region packages/web-c/bundler-plugin/src/transform.ts
|
|
220
243
|
async function transformZeus(options) {
|
|
221
|
-
var
|
|
222
|
-
const { id, code, compiler, sourcemap = true } = 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;
|
|
223
252
|
const result = await (0, _babel_core.transformAsync)(code, {
|
|
224
253
|
filename: id,
|
|
225
254
|
sourceMaps: sourcemap,
|
|
226
|
-
plugins: [[_zeus_js_compiler.default, {
|
|
227
|
-
moduleName: (
|
|
255
|
+
plugins: shouldRunCompiler ? [[_zeus_js_compiler.default, {
|
|
256
|
+
moduleName: (_compilerOptions$modu = compilerOptions.moduleName) !== null && _compilerOptions$modu !== void 0 ? _compilerOptions$modu : "@zeus-js/runtime-dom",
|
|
228
257
|
generate: "dom",
|
|
229
258
|
hydratable: false,
|
|
230
259
|
delegateEvents: true,
|
|
231
|
-
...
|
|
232
|
-
}]],
|
|
260
|
+
...compilerOptions
|
|
261
|
+
}]] : [],
|
|
262
|
+
presets: shouldStripTs ? [[_babel_preset_typescript.default, {
|
|
263
|
+
allExtensions: true,
|
|
264
|
+
isTSX: isTsx,
|
|
265
|
+
allowDeclareFields: true
|
|
266
|
+
}]] : [],
|
|
233
267
|
parserOpts: {
|
|
234
268
|
sourceType: "module",
|
|
235
269
|
plugins: ["typescript", "jsx"]
|
|
@@ -328,32 +362,36 @@ function normalizePath(value) {
|
|
|
328
362
|
return value.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
329
363
|
}
|
|
330
364
|
//#endregion
|
|
331
|
-
//#region packages/web-c/bundler-plugin/src/
|
|
332
|
-
function
|
|
333
|
-
|
|
334
|
-
|
|
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;
|
|
335
369
|
let ctx;
|
|
370
|
+
let root = process.cwd();
|
|
371
|
+
const virtualModules = new VirtualModuleRegistry();
|
|
336
372
|
return {
|
|
337
|
-
name:
|
|
373
|
+
name: resolvePluginName(target),
|
|
338
374
|
async buildStart() {
|
|
339
|
-
var _options$components, _options$components2, _options$plugins;
|
|
375
|
+
var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
|
|
340
376
|
virtualModules.clear();
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
const
|
|
344
|
-
|
|
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({
|
|
345
383
|
root,
|
|
346
|
-
include,
|
|
347
|
-
exclude
|
|
384
|
+
include: transformInclude,
|
|
385
|
+
exclude: transformExclude
|
|
348
386
|
});
|
|
349
387
|
const dts = await resolveDts({
|
|
350
388
|
root,
|
|
351
389
|
mode: options.dts,
|
|
352
|
-
include,
|
|
353
|
-
exclude
|
|
390
|
+
include: componentInclude,
|
|
391
|
+
exclude: componentExclude
|
|
354
392
|
});
|
|
355
|
-
const manifestResult = await createManifest(root,
|
|
356
|
-
for (const file of await collectWatchFiles(root,
|
|
393
|
+
const manifestResult = await createManifest(root, componentInclude, componentExclude);
|
|
394
|
+
for (const file of await collectWatchFiles(root, componentInclude, componentExclude)) this.addWatchFile(file);
|
|
357
395
|
const diagnostics = manifestResult.diagnostics;
|
|
358
396
|
for (const diagnostic of diagnostics) {
|
|
359
397
|
const message = formatDiagnostic(diagnostic);
|
|
@@ -362,13 +400,12 @@ function createZeusPlugin(options = {}) {
|
|
|
362
400
|
}
|
|
363
401
|
if (hasErrorDiagnostics(diagnostics)) this.error("[zeus] component analyzer failed.");
|
|
364
402
|
if (options.diagnostics === "verbose") this.warn(`[zeus] dts ${dts.enabled ? "enabled" : "disabled"}: ${dts.reason.join(", ") || "no signal"}`);
|
|
365
|
-
const outputs = createOutputRegistry();
|
|
366
403
|
ctx = {
|
|
367
404
|
root,
|
|
368
405
|
manifest: manifestResult.manifest,
|
|
369
406
|
diagnostics,
|
|
370
407
|
dts,
|
|
371
|
-
outputs,
|
|
408
|
+
outputs: createOutputRegistry(),
|
|
372
409
|
emitFile: this.emitFile.bind(this),
|
|
373
410
|
warn: this.warn.bind(this),
|
|
374
411
|
error: this.error.bind(this),
|
|
@@ -393,26 +430,31 @@ function createZeusPlugin(options = {}) {
|
|
|
393
430
|
}
|
|
394
431
|
},
|
|
395
432
|
resolveId(id, importer) {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
id:
|
|
433
|
+
const resolvedVirtual = virtualModules.resolve(id, importer);
|
|
434
|
+
if (resolvedVirtual) return {
|
|
435
|
+
id: resolvedVirtual,
|
|
399
436
|
moduleSideEffects: "no-treeshake"
|
|
400
437
|
};
|
|
438
|
+
if (target === "rollup") {
|
|
439
|
+
const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
|
|
440
|
+
if (resolvedTs) return resolvedTs;
|
|
441
|
+
}
|
|
401
442
|
return null;
|
|
402
443
|
},
|
|
403
444
|
load(id) {
|
|
404
445
|
return virtualModules.load(id);
|
|
405
446
|
},
|
|
406
447
|
async transform(code, id) {
|
|
407
|
-
|
|
408
|
-
const
|
|
448
|
+
const shouldRunZeus = shouldCompileZeus(id);
|
|
449
|
+
const shouldStripTs = resolveTranspile(options.transpile, target) && isTypeScriptLike(id);
|
|
450
|
+
if (!shouldRunZeus && !shouldStripTs) return null;
|
|
451
|
+
return await transformZeus({
|
|
409
452
|
id,
|
|
410
453
|
code,
|
|
411
|
-
compiler: options.compiler,
|
|
412
|
-
sourcemap: true
|
|
454
|
+
compiler: shouldRunZeus ? options.compiler : false,
|
|
455
|
+
sourcemap: true,
|
|
456
|
+
transpile: shouldStripTs
|
|
413
457
|
});
|
|
414
|
-
if (!result) return null;
|
|
415
|
-
return result;
|
|
416
458
|
},
|
|
417
459
|
async generateBundle(_, bundle) {
|
|
418
460
|
var _options$plugins2;
|
|
@@ -427,6 +469,19 @@ function createZeusPlugin(options = {}) {
|
|
|
427
469
|
}
|
|
428
470
|
};
|
|
429
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
|
+
}
|
|
430
485
|
async function createManifest(root, include, exclude) {
|
|
431
486
|
if (!include.length) return {
|
|
432
487
|
manifest: {
|
|
@@ -449,9 +504,37 @@ async function collectWatchFiles(root, include, exclude) {
|
|
|
449
504
|
ignore: exclude
|
|
450
505
|
});
|
|
451
506
|
}
|
|
452
|
-
function
|
|
453
|
-
|
|
454
|
-
|
|
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);
|
|
455
538
|
}
|
|
456
539
|
function emitOutputFile(pluginContext, file) {
|
|
457
540
|
if (file.type === "asset") {
|
|
@@ -480,14 +563,7 @@ function emitVirtualEntries(modules, pluginContext) {
|
|
|
480
563
|
}
|
|
481
564
|
}
|
|
482
565
|
//#endregion
|
|
483
|
-
//#region packages/web-c/bundler-plugin/src/
|
|
484
|
-
function resolvePluginDts(value, ctx) {
|
|
485
|
-
if (value === true) return true;
|
|
486
|
-
if (value === false) return false;
|
|
487
|
-
return ctx.dts.enabled;
|
|
488
|
-
}
|
|
489
|
-
//#endregion
|
|
490
|
-
//#region packages/web-c/bundler-plugin/src/vite.ts
|
|
566
|
+
//#region packages/web-c/bundler-plugin/src/external.ts
|
|
491
567
|
function mergeExternal(userExternal, pluginExternal) {
|
|
492
568
|
if (!userExternal) return pluginExternal;
|
|
493
569
|
if (typeof userExternal === "function") return (source, importer, isResolved) => {
|
|
@@ -496,11 +572,22 @@ function mergeExternal(userExternal, pluginExternal) {
|
|
|
496
572
|
return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
|
|
497
573
|
}
|
|
498
574
|
//#endregion
|
|
575
|
+
//#region packages/web-c/bundler-plugin/src/rollup.ts
|
|
576
|
+
function zeus(options = {}) {
|
|
577
|
+
return createZeusBundlerPlugin(options, { target: "rollup" });
|
|
578
|
+
}
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region packages/web-c/bundler-plugin/src/pluginOptions.ts
|
|
581
|
+
function resolvePluginDts(value, ctx) {
|
|
582
|
+
if (value === true) return true;
|
|
583
|
+
if (value === false) return false;
|
|
584
|
+
return ctx.dts.enabled;
|
|
585
|
+
}
|
|
586
|
+
//#endregion
|
|
499
587
|
exports.createOutputRegistry = createOutputRegistry;
|
|
500
|
-
exports.
|
|
501
|
-
exports.default = createZeusPlugin;
|
|
588
|
+
exports.default = zeus;
|
|
502
589
|
exports.mergeExternal = mergeExternal;
|
|
503
590
|
exports.resolveComponentExclude = resolveComponentExclude;
|
|
504
591
|
exports.resolveComponentInclude = resolveComponentInclude;
|
|
505
592
|
exports.resolvePluginDts = resolvePluginDts;
|
|
506
|
-
exports.zeus =
|
|
593
|
+
exports.zeus = zeus;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* bundler-plugin v0.1.0-beta.
|
|
2
|
+
* bundler-plugin v0.1.0-beta.2
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -29,6 +29,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
enumerable: true
|
|
30
30
|
}) : target, mod));
|
|
31
31
|
//#endregion
|
|
32
|
+
let node_fs = require("node:fs");
|
|
33
|
+
node_fs = __toESM(node_fs, 1);
|
|
32
34
|
let node_path = require("node:path");
|
|
33
35
|
node_path = __toESM(node_path, 1);
|
|
34
36
|
let _zeus_js_component_analyzer = require("@zeus-js/component-analyzer");
|
|
@@ -39,12 +41,17 @@ picomatch = __toESM(picomatch, 1);
|
|
|
39
41
|
let node_fs_promises = require("node:fs/promises");
|
|
40
42
|
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
41
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);
|
|
42
46
|
let _zeus_js_compiler = require("@zeus-js/compiler");
|
|
43
47
|
_zeus_js_compiler = __toESM(_zeus_js_compiler, 1);
|
|
44
48
|
//#region packages/web-c/bundler-plugin/src/filter.ts
|
|
45
49
|
function cleanUrl(id) {
|
|
46
50
|
return id.replace(/[?#].*$/, "");
|
|
47
51
|
}
|
|
52
|
+
function isTypeScriptLike(id) {
|
|
53
|
+
return /\.[cm]?tsx?$/.test(cleanUrl(id));
|
|
54
|
+
}
|
|
48
55
|
//#endregion
|
|
49
56
|
//#region packages/web-c/bundler-plugin/src/componentTransformFilter.ts
|
|
50
57
|
function normalizePath$1(value) {
|
|
@@ -73,12 +80,28 @@ const DEFAULT_COMPONENT_EXCLUDE = [
|
|
|
73
80
|
"node_modules/**",
|
|
74
81
|
"dist/**"
|
|
75
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
|
+
];
|
|
76
92
|
function resolveComponentInclude(include) {
|
|
77
93
|
return (include === null || include === void 0 ? void 0 : include.length) ? include : DEFAULT_COMPONENT_INCLUDE;
|
|
78
94
|
}
|
|
79
95
|
function resolveComponentExclude(exclude) {
|
|
80
96
|
return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_COMPONENT_EXCLUDE;
|
|
81
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
|
+
}
|
|
82
105
|
//#endregion
|
|
83
106
|
//#region packages/web-c/bundler-plugin/src/diagnostics.ts
|
|
84
107
|
function formatDiagnostic(diagnostic) {
|
|
@@ -218,18 +241,29 @@ function normalizeTagName(tag, stripPrefix) {
|
|
|
218
241
|
//#endregion
|
|
219
242
|
//#region packages/web-c/bundler-plugin/src/transform.ts
|
|
220
243
|
async function transformZeus(options) {
|
|
221
|
-
var
|
|
222
|
-
const { id, code, compiler, sourcemap = true } = 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;
|
|
223
252
|
const result = await (0, _babel_core.transformAsync)(code, {
|
|
224
253
|
filename: id,
|
|
225
254
|
sourceMaps: sourcemap,
|
|
226
|
-
plugins: [[_zeus_js_compiler.default, {
|
|
227
|
-
moduleName: (
|
|
255
|
+
plugins: shouldRunCompiler ? [[_zeus_js_compiler.default, {
|
|
256
|
+
moduleName: (_compilerOptions$modu = compilerOptions.moduleName) !== null && _compilerOptions$modu !== void 0 ? _compilerOptions$modu : "@zeus-js/runtime-dom",
|
|
228
257
|
generate: "dom",
|
|
229
258
|
hydratable: false,
|
|
230
259
|
delegateEvents: true,
|
|
231
|
-
...
|
|
232
|
-
}]],
|
|
260
|
+
...compilerOptions
|
|
261
|
+
}]] : [],
|
|
262
|
+
presets: shouldStripTs ? [[_babel_preset_typescript.default, {
|
|
263
|
+
allExtensions: true,
|
|
264
|
+
isTSX: isTsx,
|
|
265
|
+
allowDeclareFields: true
|
|
266
|
+
}]] : [],
|
|
233
267
|
parserOpts: {
|
|
234
268
|
sourceType: "module",
|
|
235
269
|
plugins: ["typescript", "jsx"]
|
|
@@ -328,32 +362,36 @@ function normalizePath(value) {
|
|
|
328
362
|
return value.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
329
363
|
}
|
|
330
364
|
//#endregion
|
|
331
|
-
//#region packages/web-c/bundler-plugin/src/
|
|
332
|
-
function
|
|
333
|
-
|
|
334
|
-
|
|
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;
|
|
335
369
|
let ctx;
|
|
370
|
+
let root = process.cwd();
|
|
371
|
+
const virtualModules = new VirtualModuleRegistry();
|
|
336
372
|
return {
|
|
337
|
-
name:
|
|
373
|
+
name: resolvePluginName(target),
|
|
338
374
|
async buildStart() {
|
|
339
|
-
var _options$components, _options$components2, _options$plugins;
|
|
375
|
+
var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
|
|
340
376
|
virtualModules.clear();
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
const
|
|
344
|
-
|
|
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({
|
|
345
383
|
root,
|
|
346
|
-
include,
|
|
347
|
-
exclude
|
|
384
|
+
include: transformInclude,
|
|
385
|
+
exclude: transformExclude
|
|
348
386
|
});
|
|
349
387
|
const dts = await resolveDts({
|
|
350
388
|
root,
|
|
351
389
|
mode: options.dts,
|
|
352
|
-
include,
|
|
353
|
-
exclude
|
|
390
|
+
include: componentInclude,
|
|
391
|
+
exclude: componentExclude
|
|
354
392
|
});
|
|
355
|
-
const manifestResult = await createManifest(root,
|
|
356
|
-
for (const file of await collectWatchFiles(root,
|
|
393
|
+
const manifestResult = await createManifest(root, componentInclude, componentExclude);
|
|
394
|
+
for (const file of await collectWatchFiles(root, componentInclude, componentExclude)) this.addWatchFile(file);
|
|
357
395
|
const diagnostics = manifestResult.diagnostics;
|
|
358
396
|
for (const diagnostic of diagnostics) {
|
|
359
397
|
const message = formatDiagnostic(diagnostic);
|
|
@@ -362,13 +400,12 @@ function createZeusPlugin(options = {}) {
|
|
|
362
400
|
}
|
|
363
401
|
if (hasErrorDiagnostics(diagnostics)) this.error("[zeus] component analyzer failed.");
|
|
364
402
|
if (options.diagnostics === "verbose") this.warn(`[zeus] dts ${dts.enabled ? "enabled" : "disabled"}: ${dts.reason.join(", ") || "no signal"}`);
|
|
365
|
-
const outputs = createOutputRegistry();
|
|
366
403
|
ctx = {
|
|
367
404
|
root,
|
|
368
405
|
manifest: manifestResult.manifest,
|
|
369
406
|
diagnostics,
|
|
370
407
|
dts,
|
|
371
|
-
outputs,
|
|
408
|
+
outputs: createOutputRegistry(),
|
|
372
409
|
emitFile: this.emitFile.bind(this),
|
|
373
410
|
warn: this.warn.bind(this),
|
|
374
411
|
error: this.error.bind(this),
|
|
@@ -393,26 +430,31 @@ function createZeusPlugin(options = {}) {
|
|
|
393
430
|
}
|
|
394
431
|
},
|
|
395
432
|
resolveId(id, importer) {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
id:
|
|
433
|
+
const resolvedVirtual = virtualModules.resolve(id, importer);
|
|
434
|
+
if (resolvedVirtual) return {
|
|
435
|
+
id: resolvedVirtual,
|
|
399
436
|
moduleSideEffects: "no-treeshake"
|
|
400
437
|
};
|
|
438
|
+
if (target === "rollup") {
|
|
439
|
+
const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
|
|
440
|
+
if (resolvedTs) return resolvedTs;
|
|
441
|
+
}
|
|
401
442
|
return null;
|
|
402
443
|
},
|
|
403
444
|
load(id) {
|
|
404
445
|
return virtualModules.load(id);
|
|
405
446
|
},
|
|
406
447
|
async transform(code, id) {
|
|
407
|
-
|
|
408
|
-
const
|
|
448
|
+
const shouldRunZeus = shouldCompileZeus(id);
|
|
449
|
+
const shouldStripTs = resolveTranspile(options.transpile, target) && isTypeScriptLike(id);
|
|
450
|
+
if (!shouldRunZeus && !shouldStripTs) return null;
|
|
451
|
+
return await transformZeus({
|
|
409
452
|
id,
|
|
410
453
|
code,
|
|
411
|
-
compiler: options.compiler,
|
|
412
|
-
sourcemap: true
|
|
454
|
+
compiler: shouldRunZeus ? options.compiler : false,
|
|
455
|
+
sourcemap: true,
|
|
456
|
+
transpile: shouldStripTs
|
|
413
457
|
});
|
|
414
|
-
if (!result) return null;
|
|
415
|
-
return result;
|
|
416
458
|
},
|
|
417
459
|
async generateBundle(_, bundle) {
|
|
418
460
|
var _options$plugins2;
|
|
@@ -427,6 +469,19 @@ function createZeusPlugin(options = {}) {
|
|
|
427
469
|
}
|
|
428
470
|
};
|
|
429
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
|
+
}
|
|
430
485
|
async function createManifest(root, include, exclude) {
|
|
431
486
|
if (!include.length) return {
|
|
432
487
|
manifest: {
|
|
@@ -449,9 +504,37 @@ async function collectWatchFiles(root, include, exclude) {
|
|
|
449
504
|
ignore: exclude
|
|
450
505
|
});
|
|
451
506
|
}
|
|
452
|
-
function
|
|
453
|
-
|
|
454
|
-
|
|
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);
|
|
455
538
|
}
|
|
456
539
|
function emitOutputFile(pluginContext, file) {
|
|
457
540
|
if (file.type === "asset") {
|
|
@@ -480,14 +563,7 @@ function emitVirtualEntries(modules, pluginContext) {
|
|
|
480
563
|
}
|
|
481
564
|
}
|
|
482
565
|
//#endregion
|
|
483
|
-
//#region packages/web-c/bundler-plugin/src/
|
|
484
|
-
function resolvePluginDts(value, ctx) {
|
|
485
|
-
if (value === true) return true;
|
|
486
|
-
if (value === false) return false;
|
|
487
|
-
return ctx.dts.enabled;
|
|
488
|
-
}
|
|
489
|
-
//#endregion
|
|
490
|
-
//#region packages/web-c/bundler-plugin/src/vite.ts
|
|
566
|
+
//#region packages/web-c/bundler-plugin/src/external.ts
|
|
491
567
|
function mergeExternal(userExternal, pluginExternal) {
|
|
492
568
|
if (!userExternal) return pluginExternal;
|
|
493
569
|
if (typeof userExternal === "function") return (source, importer, isResolved) => {
|
|
@@ -496,11 +572,22 @@ function mergeExternal(userExternal, pluginExternal) {
|
|
|
496
572
|
return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
|
|
497
573
|
}
|
|
498
574
|
//#endregion
|
|
575
|
+
//#region packages/web-c/bundler-plugin/src/rollup.ts
|
|
576
|
+
function zeus(options = {}) {
|
|
577
|
+
return createZeusBundlerPlugin(options, { target: "rollup" });
|
|
578
|
+
}
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region packages/web-c/bundler-plugin/src/pluginOptions.ts
|
|
581
|
+
function resolvePluginDts(value, ctx) {
|
|
582
|
+
if (value === true) return true;
|
|
583
|
+
if (value === false) return false;
|
|
584
|
+
return ctx.dts.enabled;
|
|
585
|
+
}
|
|
586
|
+
//#endregion
|
|
499
587
|
exports.createOutputRegistry = createOutputRegistry;
|
|
500
|
-
exports.
|
|
501
|
-
exports.default = createZeusPlugin;
|
|
588
|
+
exports.default = zeus;
|
|
502
589
|
exports.mergeExternal = mergeExternal;
|
|
503
590
|
exports.resolveComponentExclude = resolveComponentExclude;
|
|
504
591
|
exports.resolveComponentInclude = resolveComponentInclude;
|
|
505
592
|
exports.resolvePluginDts = resolvePluginDts;
|
|
506
|
-
exports.zeus =
|
|
593
|
+
exports.zeus = zeus;
|