@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
package/dist/vite.cjs.js
CHANGED
|
@@ -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
|
**/
|
|
@@ -33,6 +33,8 @@ let node_module = require("node:module");
|
|
|
33
33
|
let node_path = require("node:path");
|
|
34
34
|
node_path = __toESM(node_path, 1);
|
|
35
35
|
let vite = require("vite");
|
|
36
|
+
let node_fs = require("node:fs");
|
|
37
|
+
node_fs = __toESM(node_fs, 1);
|
|
36
38
|
let _zeus_js_component_analyzer = require("@zeus-js/component-analyzer");
|
|
37
39
|
let fast_glob = require("fast-glob");
|
|
38
40
|
fast_glob = __toESM(fast_glob, 1);
|
|
@@ -41,12 +43,17 @@ picomatch = __toESM(picomatch, 1);
|
|
|
41
43
|
let node_fs_promises = require("node:fs/promises");
|
|
42
44
|
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
43
45
|
let _babel_core = require("@babel/core");
|
|
46
|
+
let _babel_preset_typescript = require("@babel/preset-typescript");
|
|
47
|
+
_babel_preset_typescript = __toESM(_babel_preset_typescript, 1);
|
|
44
48
|
let _zeus_js_compiler = require("@zeus-js/compiler");
|
|
45
49
|
_zeus_js_compiler = __toESM(_zeus_js_compiler, 1);
|
|
46
50
|
//#region packages/web-c/bundler-plugin/src/filter.ts
|
|
47
51
|
function cleanUrl(id) {
|
|
48
52
|
return id.replace(/[?#].*$/, "");
|
|
49
53
|
}
|
|
54
|
+
function isTypeScriptLike(id) {
|
|
55
|
+
return /\.[cm]?tsx?$/.test(cleanUrl(id));
|
|
56
|
+
}
|
|
50
57
|
//#endregion
|
|
51
58
|
//#region packages/web-c/bundler-plugin/src/componentTransformFilter.ts
|
|
52
59
|
function normalizePath$1(value) {
|
|
@@ -75,12 +82,28 @@ const DEFAULT_COMPONENT_EXCLUDE = [
|
|
|
75
82
|
"node_modules/**",
|
|
76
83
|
"dist/**"
|
|
77
84
|
];
|
|
85
|
+
const DEFAULT_TRANSFORM_INCLUDE = DEFAULT_COMPONENT_INCLUDE;
|
|
86
|
+
const DEFAULT_TRANSFORM_EXCLUDE = [
|
|
87
|
+
"**/*.test.*",
|
|
88
|
+
"**/*.spec.*",
|
|
89
|
+
"**/__tests__/**",
|
|
90
|
+
"**/*.d.ts",
|
|
91
|
+
"node_modules/**",
|
|
92
|
+
"dist/**"
|
|
93
|
+
];
|
|
78
94
|
function resolveComponentInclude(include) {
|
|
79
95
|
return (include === null || include === void 0 ? void 0 : include.length) ? include : DEFAULT_COMPONENT_INCLUDE;
|
|
80
96
|
}
|
|
81
97
|
function resolveComponentExclude(exclude) {
|
|
82
98
|
return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_COMPONENT_EXCLUDE;
|
|
83
99
|
}
|
|
100
|
+
function resolveTransformInclude(include, componentInclude) {
|
|
101
|
+
if (include === null || include === void 0 ? void 0 : include.length) return include;
|
|
102
|
+
return Array.from(new Set([...DEFAULT_TRANSFORM_INCLUDE, ...componentInclude]));
|
|
103
|
+
}
|
|
104
|
+
function resolveTransformExclude(exclude) {
|
|
105
|
+
return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_TRANSFORM_EXCLUDE;
|
|
106
|
+
}
|
|
84
107
|
//#endregion
|
|
85
108
|
//#region packages/web-c/bundler-plugin/src/diagnostics.ts
|
|
86
109
|
function formatDiagnostic(diagnostic) {
|
|
@@ -220,18 +243,29 @@ function normalizeTagName(tag, stripPrefix) {
|
|
|
220
243
|
//#endregion
|
|
221
244
|
//#region packages/web-c/bundler-plugin/src/transform.ts
|
|
222
245
|
async function transformZeus(options) {
|
|
223
|
-
var
|
|
224
|
-
const { id, code, compiler, sourcemap = true } = options;
|
|
246
|
+
var _compilerOptions$modu;
|
|
247
|
+
const { id, code, compiler, sourcemap = true, transpile = false } = options;
|
|
248
|
+
const isTs = isTypeScriptLike(id);
|
|
249
|
+
const isTsx = /\.[cm]?tsx$/.test(id.replace(/[?#].*$/, ""));
|
|
250
|
+
const shouldRunCompiler = compiler !== false;
|
|
251
|
+
const shouldStripTs = transpile && isTs;
|
|
252
|
+
if (!shouldRunCompiler && !shouldStripTs) return null;
|
|
253
|
+
const compilerOptions = compiler === false ? {} : compiler === void 0 ? {} : compiler;
|
|
225
254
|
const result = await (0, _babel_core.transformAsync)(code, {
|
|
226
255
|
filename: id,
|
|
227
256
|
sourceMaps: sourcemap,
|
|
228
|
-
plugins: [[_zeus_js_compiler.default, {
|
|
229
|
-
moduleName: (
|
|
257
|
+
plugins: shouldRunCompiler ? [[_zeus_js_compiler.default, {
|
|
258
|
+
moduleName: (_compilerOptions$modu = compilerOptions.moduleName) !== null && _compilerOptions$modu !== void 0 ? _compilerOptions$modu : "@zeus-js/runtime-dom",
|
|
230
259
|
generate: "dom",
|
|
231
260
|
hydratable: false,
|
|
232
261
|
delegateEvents: true,
|
|
233
|
-
...
|
|
234
|
-
}]],
|
|
262
|
+
...compilerOptions
|
|
263
|
+
}]] : [],
|
|
264
|
+
presets: shouldStripTs ? [[_babel_preset_typescript.default, {
|
|
265
|
+
allExtensions: true,
|
|
266
|
+
isTSX: isTsx,
|
|
267
|
+
allowDeclareFields: true
|
|
268
|
+
}]] : [],
|
|
235
269
|
parserOpts: {
|
|
236
270
|
sourceType: "module",
|
|
237
271
|
plugins: ["typescript", "jsx"]
|
|
@@ -330,32 +364,36 @@ function normalizePath(value) {
|
|
|
330
364
|
return value.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
331
365
|
}
|
|
332
366
|
//#endregion
|
|
333
|
-
//#region packages/web-c/bundler-plugin/src/
|
|
334
|
-
function
|
|
335
|
-
|
|
336
|
-
|
|
367
|
+
//#region packages/web-c/bundler-plugin/src/core.ts
|
|
368
|
+
function createZeusBundlerPlugin(options = {}, createOptions) {
|
|
369
|
+
const target = createOptions.target;
|
|
370
|
+
let shouldCompileZeus = (_id) => false;
|
|
337
371
|
let ctx;
|
|
372
|
+
let root = process.cwd();
|
|
373
|
+
const virtualModules = new VirtualModuleRegistry();
|
|
338
374
|
return {
|
|
339
|
-
name:
|
|
375
|
+
name: resolvePluginName(target),
|
|
340
376
|
async buildStart() {
|
|
341
|
-
var _options$components, _options$components2, _options$plugins;
|
|
377
|
+
var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
|
|
342
378
|
virtualModules.clear();
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
const
|
|
346
|
-
|
|
379
|
+
root = resolveRoot(options.root);
|
|
380
|
+
const componentInclude = resolveComponentInclude((_options$components = options.components) === null || _options$components === void 0 ? void 0 : _options$components.include);
|
|
381
|
+
const componentExclude = resolveComponentExclude((_options$components2 = options.components) === null || _options$components2 === void 0 ? void 0 : _options$components2.exclude);
|
|
382
|
+
const transformInclude = resolveTransformInclude((_options$transform = options.transform) === null || _options$transform === void 0 ? void 0 : _options$transform.include, componentInclude);
|
|
383
|
+
const transformExclude = resolveTransformExclude((_options$transform2 = options.transform) === null || _options$transform2 === void 0 ? void 0 : _options$transform2.exclude);
|
|
384
|
+
shouldCompileZeus = createComponentTransformFilter({
|
|
347
385
|
root,
|
|
348
|
-
include,
|
|
349
|
-
exclude
|
|
386
|
+
include: transformInclude,
|
|
387
|
+
exclude: transformExclude
|
|
350
388
|
});
|
|
351
389
|
const dts = await resolveDts({
|
|
352
390
|
root,
|
|
353
391
|
mode: options.dts,
|
|
354
|
-
include,
|
|
355
|
-
exclude
|
|
392
|
+
include: componentInclude,
|
|
393
|
+
exclude: componentExclude
|
|
356
394
|
});
|
|
357
|
-
const manifestResult = await createManifest(root,
|
|
358
|
-
for (const file of await collectWatchFiles(root,
|
|
395
|
+
const manifestResult = await createManifest(root, componentInclude, componentExclude);
|
|
396
|
+
for (const file of await collectWatchFiles(root, componentInclude, componentExclude)) this.addWatchFile(file);
|
|
359
397
|
const diagnostics = manifestResult.diagnostics;
|
|
360
398
|
for (const diagnostic of diagnostics) {
|
|
361
399
|
const message = formatDiagnostic(diagnostic);
|
|
@@ -364,13 +402,12 @@ function createZeusPlugin(options = {}) {
|
|
|
364
402
|
}
|
|
365
403
|
if (hasErrorDiagnostics(diagnostics)) this.error("[zeus] component analyzer failed.");
|
|
366
404
|
if (options.diagnostics === "verbose") this.warn(`[zeus] dts ${dts.enabled ? "enabled" : "disabled"}: ${dts.reason.join(", ") || "no signal"}`);
|
|
367
|
-
const outputs = createOutputRegistry();
|
|
368
405
|
ctx = {
|
|
369
406
|
root,
|
|
370
407
|
manifest: manifestResult.manifest,
|
|
371
408
|
diagnostics,
|
|
372
409
|
dts,
|
|
373
|
-
outputs,
|
|
410
|
+
outputs: createOutputRegistry(),
|
|
374
411
|
emitFile: this.emitFile.bind(this),
|
|
375
412
|
warn: this.warn.bind(this),
|
|
376
413
|
error: this.error.bind(this),
|
|
@@ -395,26 +432,31 @@ function createZeusPlugin(options = {}) {
|
|
|
395
432
|
}
|
|
396
433
|
},
|
|
397
434
|
resolveId(id, importer) {
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
400
|
-
id:
|
|
435
|
+
const resolvedVirtual = virtualModules.resolve(id, importer);
|
|
436
|
+
if (resolvedVirtual) return {
|
|
437
|
+
id: resolvedVirtual,
|
|
401
438
|
moduleSideEffects: "no-treeshake"
|
|
402
439
|
};
|
|
440
|
+
if (target === "rollup") {
|
|
441
|
+
const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
|
|
442
|
+
if (resolvedTs) return resolvedTs;
|
|
443
|
+
}
|
|
403
444
|
return null;
|
|
404
445
|
},
|
|
405
446
|
load(id) {
|
|
406
447
|
return virtualModules.load(id);
|
|
407
448
|
},
|
|
408
449
|
async transform(code, id) {
|
|
409
|
-
|
|
410
|
-
const
|
|
450
|
+
const shouldRunZeus = shouldCompileZeus(id);
|
|
451
|
+
const shouldStripTs = resolveTranspile(options.transpile, target) && isTypeScriptLike(id);
|
|
452
|
+
if (!shouldRunZeus && !shouldStripTs) return null;
|
|
453
|
+
return await transformZeus({
|
|
411
454
|
id,
|
|
412
455
|
code,
|
|
413
|
-
compiler: options.compiler,
|
|
414
|
-
sourcemap: true
|
|
456
|
+
compiler: shouldRunZeus ? options.compiler : false,
|
|
457
|
+
sourcemap: true,
|
|
458
|
+
transpile: shouldStripTs
|
|
415
459
|
});
|
|
416
|
-
if (!result) return null;
|
|
417
|
-
return result;
|
|
418
460
|
},
|
|
419
461
|
async generateBundle(_, bundle) {
|
|
420
462
|
var _options$plugins2;
|
|
@@ -429,6 +471,19 @@ function createZeusPlugin(options = {}) {
|
|
|
429
471
|
}
|
|
430
472
|
};
|
|
431
473
|
}
|
|
474
|
+
function resolvePluginName(target) {
|
|
475
|
+
if (target === "vite") return "vite-plugin-zeus";
|
|
476
|
+
if (target === "rolldown") return "rolldown-plugin-zeus";
|
|
477
|
+
return "rollup-plugin-zeus";
|
|
478
|
+
}
|
|
479
|
+
function resolveTranspile(value, target) {
|
|
480
|
+
if (typeof value === "boolean") return value;
|
|
481
|
+
return target === "rollup";
|
|
482
|
+
}
|
|
483
|
+
function resolveRoot(root) {
|
|
484
|
+
if (typeof root === "function") return node_path.default.resolve(root());
|
|
485
|
+
return node_path.default.resolve(root !== null && root !== void 0 ? root : process.cwd());
|
|
486
|
+
}
|
|
432
487
|
async function createManifest(root, include, exclude) {
|
|
433
488
|
if (!include.length) return {
|
|
434
489
|
manifest: {
|
|
@@ -451,9 +506,37 @@ async function collectWatchFiles(root, include, exclude) {
|
|
|
451
506
|
ignore: exclude
|
|
452
507
|
});
|
|
453
508
|
}
|
|
454
|
-
function
|
|
455
|
-
|
|
456
|
-
|
|
509
|
+
function resolveTsLikeImport(id, importer, options) {
|
|
510
|
+
var _options$extensions;
|
|
511
|
+
if (!importer) return null;
|
|
512
|
+
if (cleanUrl(id) !== id) return null;
|
|
513
|
+
const source = cleanUrl(id);
|
|
514
|
+
const from = cleanUrl(importer);
|
|
515
|
+
if (source.startsWith("\0") || from.startsWith("\0")) return null;
|
|
516
|
+
if (!source.startsWith(".") && !isAbsoluteImportPath(source)) return null;
|
|
517
|
+
if (node_path.default.extname(source)) return null;
|
|
518
|
+
if (options.extensions === false) return null;
|
|
519
|
+
const extensions = (_options$extensions = options.extensions) !== null && _options$extensions !== void 0 ? _options$extensions : [
|
|
520
|
+
".ts",
|
|
521
|
+
".tsx",
|
|
522
|
+
".mts",
|
|
523
|
+
".cts",
|
|
524
|
+
".js",
|
|
525
|
+
".jsx",
|
|
526
|
+
".mjs",
|
|
527
|
+
".cjs"
|
|
528
|
+
];
|
|
529
|
+
const base = isAbsoluteImportPath(source) ? source : node_path.default.resolve(node_path.default.dirname(from), source);
|
|
530
|
+
const candidates = [
|
|
531
|
+
base,
|
|
532
|
+
...extensions.map((ext) => `${base}${ext}`),
|
|
533
|
+
...extensions.map((ext) => node_path.default.join(base, `index${ext}`))
|
|
534
|
+
];
|
|
535
|
+
for (const file of candidates) if (node_fs.default.existsSync(file) && node_fs.default.statSync(file).isFile()) return file;
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
function isAbsoluteImportPath(id) {
|
|
539
|
+
return node_path.default.isAbsolute(id) || /^[a-zA-Z]:[\\/]/.test(id);
|
|
457
540
|
}
|
|
458
541
|
function emitOutputFile(pluginContext, file) {
|
|
459
542
|
if (file.type === "asset") {
|
|
@@ -482,21 +565,41 @@ function emitVirtualEntries(modules, pluginContext) {
|
|
|
482
565
|
}
|
|
483
566
|
}
|
|
484
567
|
//#endregion
|
|
568
|
+
//#region packages/web-c/bundler-plugin/src/external.ts
|
|
569
|
+
function collectPluginExternals(options) {
|
|
570
|
+
var _options$plugins;
|
|
571
|
+
const set = /* @__PURE__ */ new Set();
|
|
572
|
+
for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
|
|
573
|
+
var _plugin$external;
|
|
574
|
+
for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
|
|
575
|
+
}
|
|
576
|
+
return Array.from(set);
|
|
577
|
+
}
|
|
578
|
+
function mergeExternal(userExternal, pluginExternal) {
|
|
579
|
+
if (!userExternal) return pluginExternal;
|
|
580
|
+
if (typeof userExternal === "function") return (source, importer, isResolved) => {
|
|
581
|
+
return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
|
|
582
|
+
};
|
|
583
|
+
return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
|
|
584
|
+
}
|
|
585
|
+
//#endregion
|
|
485
586
|
//#region packages/web-c/bundler-plugin/src/vite.ts
|
|
486
587
|
function createZeusVitePlugin(options = {}) {
|
|
487
|
-
var _options$root;
|
|
588
|
+
var _options$root, _options$transpile;
|
|
488
589
|
let resolvedConfig;
|
|
489
590
|
return {
|
|
490
|
-
...
|
|
591
|
+
...createZeusBundlerPlugin({
|
|
491
592
|
...options,
|
|
492
593
|
root: (_options$root = options.root) !== null && _options$root !== void 0 ? _options$root : (() => {
|
|
493
594
|
var _resolvedConfig$root;
|
|
494
595
|
return (_resolvedConfig$root = resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.root) !== null && _resolvedConfig$root !== void 0 ? _resolvedConfig$root : process.cwd();
|
|
495
|
-
})
|
|
496
|
-
|
|
596
|
+
}),
|
|
597
|
+
transpile: (_options$transpile = options.transpile) !== null && _options$transpile !== void 0 ? _options$transpile : false
|
|
598
|
+
}, { target: "vite" }),
|
|
497
599
|
name: "vite-plugin-zeus",
|
|
498
600
|
enforce: "pre",
|
|
499
601
|
async config(userConfig) {
|
|
602
|
+
var _userConfig$build;
|
|
500
603
|
const runtimeDomEntry = resolveRuntimeDOMEntry(userConfig.root);
|
|
501
604
|
const pluginExternals = collectPluginExternals(options);
|
|
502
605
|
const pluginConfig = {
|
|
@@ -511,33 +614,14 @@ function createZeusVitePlugin(options = {}) {
|
|
|
511
614
|
]
|
|
512
615
|
}
|
|
513
616
|
};
|
|
514
|
-
if (pluginExternals.length)
|
|
515
|
-
|
|
516
|
-
return (0, vite.mergeConfig)(pluginConfig, { build: { rollupOptions: { external: mergeExternal((_userConfig$build = userConfig.build) === null || _userConfig$build === void 0 || (_userConfig$build = _userConfig$build.rollupOptions) === null || _userConfig$build === void 0 ? void 0 : _userConfig$build.external, pluginExternals) } } });
|
|
517
|
-
}
|
|
518
|
-
return pluginConfig;
|
|
617
|
+
if (!pluginExternals.length) return pluginConfig;
|
|
618
|
+
return (0, vite.mergeConfig)(pluginConfig, { build: { rollupOptions: { external: mergeExternal((_userConfig$build = userConfig.build) === null || _userConfig$build === void 0 || (_userConfig$build = _userConfig$build.rollupOptions) === null || _userConfig$build === void 0 ? void 0 : _userConfig$build.external, pluginExternals) } } });
|
|
519
619
|
},
|
|
520
620
|
configResolved(config) {
|
|
521
621
|
resolvedConfig = config;
|
|
522
622
|
}
|
|
523
623
|
};
|
|
524
624
|
}
|
|
525
|
-
function collectPluginExternals(options) {
|
|
526
|
-
var _options$plugins;
|
|
527
|
-
const set = /* @__PURE__ */ new Set();
|
|
528
|
-
for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
|
|
529
|
-
var _plugin$external;
|
|
530
|
-
for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
|
|
531
|
-
}
|
|
532
|
-
return Array.from(set);
|
|
533
|
-
}
|
|
534
|
-
function mergeExternal(userExternal, pluginExternal) {
|
|
535
|
-
if (!userExternal) return pluginExternal;
|
|
536
|
-
if (typeof userExternal === "function") return (source, importer, isResolved) => {
|
|
537
|
-
return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
|
|
538
|
-
};
|
|
539
|
-
return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
|
|
540
|
-
}
|
|
541
625
|
async function isRolldownVite() {
|
|
542
626
|
try {
|
|
543
627
|
const vite$1 = await import("vite");
|
|
@@ -562,4 +646,3 @@ function resolveRuntimeDOMEntry(root) {
|
|
|
562
646
|
exports.createZeusVitePlugin = createZeusVitePlugin;
|
|
563
647
|
exports.default = createZeusVitePlugin;
|
|
564
648
|
exports.zeus = createZeusVitePlugin;
|
|
565
|
-
exports.mergeExternal = mergeExternal;
|