@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
package/dist/vite.prod.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
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
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { mergeConfig } from "vite";
|
|
9
|
+
import fs from "node:fs";
|
|
9
10
|
import { analyzeComponents } from "@zeus-js/component-analyzer";
|
|
10
11
|
import fg from "fast-glob";
|
|
11
12
|
import picomatch from "picomatch";
|
|
12
|
-
import fs from "node:fs/promises";
|
|
13
|
+
import fs$1 from "node:fs/promises";
|
|
13
14
|
import { transformAsync } from "@babel/core";
|
|
15
|
+
import presetTypeScript from "@babel/preset-typescript";
|
|
14
16
|
import zeusCompiler from "@zeus-js/compiler";
|
|
15
17
|
//#region packages/web-c/bundler-plugin/src/filter.ts
|
|
16
18
|
function cleanUrl(id) {
|
|
17
19
|
return id.replace(/[?#].*$/, "");
|
|
18
20
|
}
|
|
21
|
+
function isTypeScriptLike(id) {
|
|
22
|
+
return /\.[cm]?tsx?$/.test(cleanUrl(id));
|
|
23
|
+
}
|
|
19
24
|
//#endregion
|
|
20
25
|
//#region packages/web-c/bundler-plugin/src/componentTransformFilter.ts
|
|
21
26
|
function normalizePath$1(value) {
|
|
@@ -44,12 +49,28 @@ const DEFAULT_COMPONENT_EXCLUDE = [
|
|
|
44
49
|
"node_modules/**",
|
|
45
50
|
"dist/**"
|
|
46
51
|
];
|
|
52
|
+
const DEFAULT_TRANSFORM_INCLUDE = DEFAULT_COMPONENT_INCLUDE;
|
|
53
|
+
const DEFAULT_TRANSFORM_EXCLUDE = [
|
|
54
|
+
"**/*.test.*",
|
|
55
|
+
"**/*.spec.*",
|
|
56
|
+
"**/__tests__/**",
|
|
57
|
+
"**/*.d.ts",
|
|
58
|
+
"node_modules/**",
|
|
59
|
+
"dist/**"
|
|
60
|
+
];
|
|
47
61
|
function resolveComponentInclude(include) {
|
|
48
62
|
return (include === null || include === void 0 ? void 0 : include.length) ? include : DEFAULT_COMPONENT_INCLUDE;
|
|
49
63
|
}
|
|
50
64
|
function resolveComponentExclude(exclude) {
|
|
51
65
|
return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_COMPONENT_EXCLUDE;
|
|
52
66
|
}
|
|
67
|
+
function resolveTransformInclude(include, componentInclude) {
|
|
68
|
+
if (include === null || include === void 0 ? void 0 : include.length) return include;
|
|
69
|
+
return Array.from(new Set([...DEFAULT_TRANSFORM_INCLUDE, ...componentInclude]));
|
|
70
|
+
}
|
|
71
|
+
function resolveTransformExclude(exclude) {
|
|
72
|
+
return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_TRANSFORM_EXCLUDE;
|
|
73
|
+
}
|
|
53
74
|
//#endregion
|
|
54
75
|
//#region packages/web-c/bundler-plugin/src/diagnostics.ts
|
|
55
76
|
function formatDiagnostic(diagnostic) {
|
|
@@ -59,7 +80,7 @@ function hasErrorDiagnostics(diagnostics) {
|
|
|
59
80
|
return diagnostics.some((item) => item.level === "error");
|
|
60
81
|
}
|
|
61
82
|
//#endregion
|
|
62
|
-
//#region \0@oxc-project+runtime@0.
|
|
83
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/asyncToGenerator.js
|
|
63
84
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
64
85
|
try {
|
|
65
86
|
var i = n[a](c), u = i.value;
|
|
@@ -85,7 +106,7 @@ function _asyncToGenerator(n) {
|
|
|
85
106
|
};
|
|
86
107
|
}
|
|
87
108
|
//#endregion
|
|
88
|
-
//#region \0@oxc-project+runtime@0.
|
|
109
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
|
|
89
110
|
function _typeof(o) {
|
|
90
111
|
"@babel/helpers - typeof";
|
|
91
112
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -95,7 +116,7 @@ function _typeof(o) {
|
|
|
95
116
|
}, _typeof(o);
|
|
96
117
|
}
|
|
97
118
|
//#endregion
|
|
98
|
-
//#region \0@oxc-project+runtime@0.
|
|
119
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
|
|
99
120
|
function toPrimitive(t, r) {
|
|
100
121
|
if ("object" != _typeof(t) || !t) return t;
|
|
101
122
|
var e = t[Symbol.toPrimitive];
|
|
@@ -107,13 +128,13 @@ function toPrimitive(t, r) {
|
|
|
107
128
|
return ("string" === r ? String : Number)(t);
|
|
108
129
|
}
|
|
109
130
|
//#endregion
|
|
110
|
-
//#region \0@oxc-project+runtime@0.
|
|
131
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
|
|
111
132
|
function toPropertyKey(t) {
|
|
112
133
|
var i = toPrimitive(t, "string");
|
|
113
134
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
114
135
|
}
|
|
115
136
|
//#endregion
|
|
116
|
-
//#region \0@oxc-project+runtime@0.
|
|
137
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
|
|
117
138
|
function _defineProperty(e, r, t) {
|
|
118
139
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
119
140
|
value: t,
|
|
@@ -123,7 +144,7 @@ function _defineProperty(e, r, t) {
|
|
|
123
144
|
}) : e[r] = t, e;
|
|
124
145
|
}
|
|
125
146
|
//#endregion
|
|
126
|
-
//#region \0@oxc-project+runtime@0.
|
|
147
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectSpread2.js
|
|
127
148
|
function ownKeys(e, r) {
|
|
128
149
|
var t = Object.keys(e);
|
|
129
150
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -231,7 +252,7 @@ function readPackageJson(_x5) {
|
|
|
231
252
|
function _readPackageJson() {
|
|
232
253
|
_readPackageJson = _asyncToGenerator(function* (root) {
|
|
233
254
|
try {
|
|
234
|
-
return JSON.parse(yield fs.readFile(path.join(root, "package.json"), "utf-8"));
|
|
255
|
+
return JSON.parse(yield fs$1.readFile(path.join(root, "package.json"), "utf-8"));
|
|
235
256
|
} catch (_unused) {
|
|
236
257
|
return null;
|
|
237
258
|
}
|
|
@@ -244,7 +265,7 @@ function fileExists(_x6) {
|
|
|
244
265
|
function _fileExists() {
|
|
245
266
|
_fileExists = _asyncToGenerator(function* (file) {
|
|
246
267
|
try {
|
|
247
|
-
yield fs.access(file);
|
|
268
|
+
yield fs$1.access(file);
|
|
248
269
|
return true;
|
|
249
270
|
} catch (_unused2) {
|
|
250
271
|
return false;
|
|
@@ -253,6 +274,42 @@ function _fileExists() {
|
|
|
253
274
|
return _fileExists.apply(this, arguments);
|
|
254
275
|
}
|
|
255
276
|
//#endregion
|
|
277
|
+
//#region packages/web-c/bundler-plugin/src/external.ts
|
|
278
|
+
const ZEUS_LIBRARY_EXTERNALS = [/^@zeus-js\//];
|
|
279
|
+
function collectPluginExternals(options, collectOptions = {}) {
|
|
280
|
+
var _options$plugins;
|
|
281
|
+
const entries = [];
|
|
282
|
+
if (collectOptions.includeZeusLibraryExternals) entries.push(...ZEUS_LIBRARY_EXTERNALS);
|
|
283
|
+
for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
|
|
284
|
+
var _plugin$external;
|
|
285
|
+
for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) entries.push(dep);
|
|
286
|
+
}
|
|
287
|
+
return uniqueExternalEntries(entries);
|
|
288
|
+
}
|
|
289
|
+
function mergeExternal(userExternal, pluginExternal) {
|
|
290
|
+
if (!userExternal) return pluginExternal;
|
|
291
|
+
if (typeof userExternal === "function") return (source, importer, isResolved) => {
|
|
292
|
+
return matchesExternal(source, pluginExternal) || userExternal(source, importer, isResolved);
|
|
293
|
+
};
|
|
294
|
+
return uniqueExternalEntries([...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal]);
|
|
295
|
+
}
|
|
296
|
+
function matchesExternal(source, entries) {
|
|
297
|
+
return entries.some((entry) => {
|
|
298
|
+
return typeof entry === "string" ? entry === source : entry.test(source);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function uniqueExternalEntries(entries) {
|
|
302
|
+
const seen = /* @__PURE__ */ new Set();
|
|
303
|
+
const result = [];
|
|
304
|
+
for (const entry of entries) {
|
|
305
|
+
const key = typeof entry === "string" ? `s:${entry}` : `r:${entry.source}/${entry.flags}`;
|
|
306
|
+
if (seen.has(key)) continue;
|
|
307
|
+
seen.add(key);
|
|
308
|
+
result.push(entry);
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
256
313
|
//#region packages/web-c/bundler-plugin/src/outputRegistry.ts
|
|
257
314
|
function createOutputRegistry() {
|
|
258
315
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -311,17 +368,28 @@ function transformZeus(_x) {
|
|
|
311
368
|
}
|
|
312
369
|
function _transformZeus() {
|
|
313
370
|
_transformZeus = _asyncToGenerator(function* (options) {
|
|
314
|
-
var
|
|
315
|
-
const { id, code, compiler, sourcemap = true } = options;
|
|
371
|
+
var _compilerOptions$modu;
|
|
372
|
+
const { id, code, compiler, sourcemap = true, transpile = false } = options;
|
|
373
|
+
const isTs = isTypeScriptLike(id);
|
|
374
|
+
const isTsx = /\.[cm]?tsx$/.test(id.replace(/[?#].*$/, ""));
|
|
375
|
+
const shouldRunCompiler = compiler !== false;
|
|
376
|
+
const shouldStripTs = transpile && isTs;
|
|
377
|
+
if (!shouldRunCompiler && !shouldStripTs) return null;
|
|
378
|
+
const compilerOptions = compiler === false ? {} : compiler === void 0 ? {} : compiler;
|
|
316
379
|
const result = yield transformAsync(code, {
|
|
317
380
|
filename: id,
|
|
318
381
|
sourceMaps: sourcemap,
|
|
319
|
-
plugins: [[zeusCompiler, _objectSpread2({
|
|
320
|
-
moduleName: (
|
|
382
|
+
plugins: shouldRunCompiler ? [[zeusCompiler, _objectSpread2({
|
|
383
|
+
moduleName: (_compilerOptions$modu = compilerOptions.moduleName) !== null && _compilerOptions$modu !== void 0 ? _compilerOptions$modu : "@zeus-js/runtime-dom",
|
|
321
384
|
generate: "dom",
|
|
322
385
|
hydratable: false,
|
|
323
386
|
delegateEvents: true
|
|
324
|
-
},
|
|
387
|
+
}, compilerOptions)]] : [],
|
|
388
|
+
presets: shouldStripTs ? [[presetTypeScript, {
|
|
389
|
+
allExtensions: true,
|
|
390
|
+
isTSX: isTsx,
|
|
391
|
+
allowDeclareFields: true
|
|
392
|
+
}]] : [],
|
|
325
393
|
parserOpts: {
|
|
326
394
|
sourceType: "module",
|
|
327
395
|
plugins: ["typescript", "jsx"]
|
|
@@ -422,34 +490,55 @@ function normalizePath(value) {
|
|
|
422
490
|
return value.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
423
491
|
}
|
|
424
492
|
//#endregion
|
|
425
|
-
//#region packages/web-c/bundler-plugin/src/
|
|
426
|
-
function
|
|
427
|
-
|
|
428
|
-
|
|
493
|
+
//#region packages/web-c/bundler-plugin/src/core.ts
|
|
494
|
+
function createZeusBundlerPlugin(options = {}, createOptions) {
|
|
495
|
+
const target = createOptions.target;
|
|
496
|
+
let shouldCompileZeus = (_id) => false;
|
|
429
497
|
let ctx;
|
|
498
|
+
let root = process.cwd();
|
|
499
|
+
const cleanedOutputDirs = /* @__PURE__ */ new Set();
|
|
500
|
+
const virtualModules = new VirtualModuleRegistry();
|
|
430
501
|
return {
|
|
431
|
-
name:
|
|
502
|
+
name: resolvePluginName(target),
|
|
503
|
+
options(inputOptions) {
|
|
504
|
+
if (target === "vite") return null;
|
|
505
|
+
const pluginExternals = collectPluginExternals(options, { includeZeusLibraryExternals: true });
|
|
506
|
+
if (!pluginExternals.length) return null;
|
|
507
|
+
return _objectSpread2(_objectSpread2({}, inputOptions), {}, { external: mergeExternal(inputOptions.external, pluginExternals) });
|
|
508
|
+
},
|
|
509
|
+
outputOptions(outputOptions) {
|
|
510
|
+
if (target === "vite") return null;
|
|
511
|
+
cleanOutputDir(outputOptions, {
|
|
512
|
+
root: resolveRoot(options.root),
|
|
513
|
+
enabled: options.clean !== false,
|
|
514
|
+
cleanedOutputDirs
|
|
515
|
+
});
|
|
516
|
+
if (outputOptions.chunkFileNames) return null;
|
|
517
|
+
return _objectSpread2(_objectSpread2({}, outputOptions), {}, { chunkFileNames: "chunks/[name]-[hash].js" });
|
|
518
|
+
},
|
|
432
519
|
buildStart() {
|
|
433
520
|
var _this = this;
|
|
434
521
|
return _asyncToGenerator(function* () {
|
|
435
|
-
var _options$components, _options$components2, _options$plugins;
|
|
522
|
+
var _options$components, _options$components2, _options$transform, _options$transform2, _options$plugins;
|
|
436
523
|
virtualModules.clear();
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
const
|
|
440
|
-
|
|
524
|
+
root = resolveRoot(options.root);
|
|
525
|
+
const componentInclude = resolveComponentInclude((_options$components = options.components) === null || _options$components === void 0 ? void 0 : _options$components.include);
|
|
526
|
+
const componentExclude = resolveComponentExclude((_options$components2 = options.components) === null || _options$components2 === void 0 ? void 0 : _options$components2.exclude);
|
|
527
|
+
const transformInclude = resolveTransformInclude((_options$transform = options.transform) === null || _options$transform === void 0 ? void 0 : _options$transform.include, componentInclude);
|
|
528
|
+
const transformExclude = resolveTransformExclude((_options$transform2 = options.transform) === null || _options$transform2 === void 0 ? void 0 : _options$transform2.exclude);
|
|
529
|
+
shouldCompileZeus = createComponentTransformFilter({
|
|
441
530
|
root,
|
|
442
|
-
include,
|
|
443
|
-
exclude
|
|
531
|
+
include: transformInclude,
|
|
532
|
+
exclude: transformExclude
|
|
444
533
|
});
|
|
445
534
|
const dts = yield resolveDts({
|
|
446
535
|
root,
|
|
447
536
|
mode: options.dts,
|
|
448
|
-
include,
|
|
449
|
-
exclude
|
|
537
|
+
include: componentInclude,
|
|
538
|
+
exclude: componentExclude
|
|
450
539
|
});
|
|
451
|
-
const manifestResult = yield createManifest(root,
|
|
452
|
-
for (const file of yield collectWatchFiles(root,
|
|
540
|
+
const manifestResult = yield createManifest(root, componentInclude, componentExclude);
|
|
541
|
+
for (const file of yield collectWatchFiles(root, componentInclude, componentExclude)) _this.addWatchFile(file);
|
|
453
542
|
const diagnostics = manifestResult.diagnostics;
|
|
454
543
|
for (const diagnostic of diagnostics) {
|
|
455
544
|
const message = formatDiagnostic(diagnostic);
|
|
@@ -458,13 +547,12 @@ function createZeusPlugin(options = {}) {
|
|
|
458
547
|
}
|
|
459
548
|
if (hasErrorDiagnostics(diagnostics)) _this.error("[zeus] component analyzer failed.");
|
|
460
549
|
if (options.diagnostics === "verbose") _this.warn(`[zeus] dts ${dts.enabled ? "enabled" : "disabled"}: ${dts.reason.join(", ") || "no signal"}`);
|
|
461
|
-
const outputs = createOutputRegistry();
|
|
462
550
|
ctx = {
|
|
463
551
|
root,
|
|
464
552
|
manifest: manifestResult.manifest,
|
|
465
553
|
diagnostics,
|
|
466
554
|
dts,
|
|
467
|
-
outputs,
|
|
555
|
+
outputs: createOutputRegistry(),
|
|
468
556
|
emitFile: _this.emitFile.bind(_this),
|
|
469
557
|
warn: _this.warn.bind(_this),
|
|
470
558
|
error: _this.error.bind(_this),
|
|
@@ -490,11 +578,23 @@ function createZeusPlugin(options = {}) {
|
|
|
490
578
|
})();
|
|
491
579
|
},
|
|
492
580
|
resolveId(id, importer) {
|
|
493
|
-
const
|
|
494
|
-
if (
|
|
495
|
-
id:
|
|
581
|
+
const resolvedVirtual = virtualModules.resolve(id, importer);
|
|
582
|
+
if (resolvedVirtual) return {
|
|
583
|
+
id: resolvedVirtual,
|
|
496
584
|
moduleSideEffects: "no-treeshake"
|
|
497
585
|
};
|
|
586
|
+
const cleanImporter = importer === null || importer === void 0 ? void 0 : importer.replace(/^\x00/, "");
|
|
587
|
+
if ((cleanImporter === null || cleanImporter === void 0 ? void 0 : cleanImporter.startsWith("zeus:")) && (id.startsWith("./") || id.startsWith("../"))) {
|
|
588
|
+
const virtualEntryId = resolveVirtualEntryImport(id, cleanImporter);
|
|
589
|
+
if (virtualEntryId && virtualModules.has(virtualEntryId)) return {
|
|
590
|
+
id: "\0" + virtualEntryId,
|
|
591
|
+
moduleSideEffects: "no-treeshake"
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
if (target === "rollup") {
|
|
595
|
+
const resolvedTs = resolveTsLikeImport(id, importer, { extensions: options.resolveExtensions });
|
|
596
|
+
if (resolvedTs) return resolvedTs;
|
|
597
|
+
}
|
|
498
598
|
return null;
|
|
499
599
|
},
|
|
500
600
|
load(id) {
|
|
@@ -502,15 +602,16 @@ function createZeusPlugin(options = {}) {
|
|
|
502
602
|
},
|
|
503
603
|
transform(code, id) {
|
|
504
604
|
return _asyncToGenerator(function* () {
|
|
505
|
-
|
|
506
|
-
const
|
|
605
|
+
const shouldRunZeus = shouldCompileZeus(id);
|
|
606
|
+
const shouldStripTs = resolveTranspile(options.transpile, target) && isTypeScriptLike(id);
|
|
607
|
+
if (!shouldRunZeus && !shouldStripTs) return null;
|
|
608
|
+
return yield transformZeus({
|
|
507
609
|
id,
|
|
508
610
|
code,
|
|
509
|
-
compiler: options.compiler,
|
|
510
|
-
sourcemap: true
|
|
611
|
+
compiler: shouldRunZeus ? options.compiler : false,
|
|
612
|
+
sourcemap: true,
|
|
613
|
+
transpile: shouldStripTs
|
|
511
614
|
});
|
|
512
|
-
if (!result) return null;
|
|
513
|
-
return result;
|
|
514
615
|
})();
|
|
515
616
|
},
|
|
516
617
|
generateBundle(_, bundle) {
|
|
@@ -529,6 +630,44 @@ function createZeusPlugin(options = {}) {
|
|
|
529
630
|
}
|
|
530
631
|
};
|
|
531
632
|
}
|
|
633
|
+
function resolvePluginName(target) {
|
|
634
|
+
if (target === "vite") return "vite-plugin-zeus";
|
|
635
|
+
if (target === "rolldown") return "rolldown-plugin-zeus";
|
|
636
|
+
return "rollup-plugin-zeus";
|
|
637
|
+
}
|
|
638
|
+
function resolveTranspile(value, target) {
|
|
639
|
+
if (typeof value === "boolean") return value;
|
|
640
|
+
return target === "rollup";
|
|
641
|
+
}
|
|
642
|
+
function resolveRoot(root) {
|
|
643
|
+
if (typeof root === "function") return path.resolve(root());
|
|
644
|
+
return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
|
|
645
|
+
}
|
|
646
|
+
function cleanOutputDir(outputOptions, options) {
|
|
647
|
+
if (!options.enabled) return;
|
|
648
|
+
const outputDir = resolveOutputDir(outputOptions, options.root);
|
|
649
|
+
if (!outputDir || !isSafeCleanTarget(outputDir, options.root)) return;
|
|
650
|
+
if (options.cleanedOutputDirs.has(outputDir)) return;
|
|
651
|
+
options.cleanedOutputDirs.add(outputDir);
|
|
652
|
+
fs.rmSync(outputDir, {
|
|
653
|
+
recursive: true,
|
|
654
|
+
force: true
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
function resolveOutputDir(outputOptions, root) {
|
|
658
|
+
const dir = outputOptions.dir;
|
|
659
|
+
if (typeof dir === "string" && dir.length > 0) return path.resolve(root, dir);
|
|
660
|
+
const file = outputOptions.file;
|
|
661
|
+
if (typeof file === "string" && file.length > 0) return path.dirname(path.resolve(root, file));
|
|
662
|
+
return path.resolve(root, "dist");
|
|
663
|
+
}
|
|
664
|
+
function isSafeCleanTarget(outputDir, root) {
|
|
665
|
+
const resolvedRoot = path.resolve(root);
|
|
666
|
+
const resolvedOutputDir = path.resolve(outputDir);
|
|
667
|
+
if (resolvedOutputDir === resolvedRoot) return false;
|
|
668
|
+
const relative = path.relative(resolvedRoot, resolvedOutputDir);
|
|
669
|
+
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
670
|
+
}
|
|
532
671
|
function createManifest(_x, _x2, _x3) {
|
|
533
672
|
return _createManifest.apply(this, arguments);
|
|
534
673
|
}
|
|
@@ -563,9 +702,37 @@ function _collectWatchFiles() {
|
|
|
563
702
|
});
|
|
564
703
|
return _collectWatchFiles.apply(this, arguments);
|
|
565
704
|
}
|
|
566
|
-
function
|
|
567
|
-
|
|
568
|
-
|
|
705
|
+
function resolveTsLikeImport(id, importer, options) {
|
|
706
|
+
var _options$extensions;
|
|
707
|
+
if (!importer) return null;
|
|
708
|
+
if (cleanUrl(id) !== id) return null;
|
|
709
|
+
const source = cleanUrl(id);
|
|
710
|
+
const from = cleanUrl(importer);
|
|
711
|
+
if (source.startsWith("\0") || from.startsWith("\0")) return null;
|
|
712
|
+
if (!source.startsWith(".") && !isAbsoluteImportPath(source)) return null;
|
|
713
|
+
if (path.extname(source)) return null;
|
|
714
|
+
if (options.extensions === false) return null;
|
|
715
|
+
const extensions = (_options$extensions = options.extensions) !== null && _options$extensions !== void 0 ? _options$extensions : [
|
|
716
|
+
".ts",
|
|
717
|
+
".tsx",
|
|
718
|
+
".mts",
|
|
719
|
+
".cts",
|
|
720
|
+
".js",
|
|
721
|
+
".jsx",
|
|
722
|
+
".mjs",
|
|
723
|
+
".cjs"
|
|
724
|
+
];
|
|
725
|
+
const base = isAbsoluteImportPath(source) ? source : path.resolve(path.dirname(from), source);
|
|
726
|
+
const candidates = [
|
|
727
|
+
base,
|
|
728
|
+
...extensions.map((ext) => `${base}${ext}`),
|
|
729
|
+
...extensions.map((ext) => path.join(base, `index${ext}`))
|
|
730
|
+
];
|
|
731
|
+
for (const file of candidates) if (fs.existsSync(file) && fs.statSync(file).isFile()) return file;
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
function isAbsoluteImportPath(id) {
|
|
735
|
+
return path.isAbsolute(id) || /^[a-zA-Z]:[\\/]/.test(id);
|
|
569
736
|
}
|
|
570
737
|
function emitOutputFile(pluginContext, file) {
|
|
571
738
|
if (file.type === "asset") {
|
|
@@ -593,19 +760,29 @@ function emitVirtualEntries(modules, pluginContext) {
|
|
|
593
760
|
});
|
|
594
761
|
}
|
|
595
762
|
}
|
|
763
|
+
function resolveVirtualEntryImport(id, importer) {
|
|
764
|
+
const tagName = id.replace(/\.js$/, "").replace(/^\.\//, "").replace(/\.entry$/, "");
|
|
765
|
+
const lastColon = importer.lastIndexOf(":");
|
|
766
|
+
if (lastColon <= 0) return null;
|
|
767
|
+
return `${importer.slice(0, lastColon + 1)}entry:${tagName}`;
|
|
768
|
+
}
|
|
596
769
|
//#endregion
|
|
597
770
|
//#region packages/web-c/bundler-plugin/src/vite.ts
|
|
598
771
|
function createZeusVitePlugin(options = {}) {
|
|
599
|
-
var _options$root;
|
|
772
|
+
var _options$root, _options$transpile;
|
|
600
773
|
let resolvedConfig;
|
|
601
|
-
return _objectSpread2(_objectSpread2({},
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
774
|
+
return _objectSpread2(_objectSpread2({}, createZeusBundlerPlugin(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
775
|
+
root: (_options$root = options.root) !== null && _options$root !== void 0 ? _options$root : (() => {
|
|
776
|
+
var _resolvedConfig$root;
|
|
777
|
+
return (_resolvedConfig$root = resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.root) !== null && _resolvedConfig$root !== void 0 ? _resolvedConfig$root : process.cwd();
|
|
778
|
+
}),
|
|
779
|
+
transpile: (_options$transpile = options.transpile) !== null && _options$transpile !== void 0 ? _options$transpile : false
|
|
780
|
+
}), { target: "vite" })), {}, {
|
|
605
781
|
name: "vite-plugin-zeus",
|
|
606
782
|
enforce: "pre",
|
|
607
783
|
config(userConfig) {
|
|
608
784
|
return _asyncToGenerator(function* () {
|
|
785
|
+
var _userConfig$build;
|
|
609
786
|
const runtimeDomEntry = resolveRuntimeDOMEntry(userConfig.root);
|
|
610
787
|
const pluginExternals = collectPluginExternals(options);
|
|
611
788
|
const pluginConfig = _objectSpread2(_objectSpread2({}, (yield isRolldownVite()) ? { oxc: { jsx: "preserve" } } : { esbuild: { jsx: "preserve" } }), {}, { resolve: {
|
|
@@ -617,11 +794,8 @@ function createZeusVitePlugin(options = {}) {
|
|
|
617
794
|
"@zeus-js/component-dts"
|
|
618
795
|
]
|
|
619
796
|
} });
|
|
620
|
-
if (pluginExternals.length)
|
|
621
|
-
|
|
622
|
-
return 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) } } });
|
|
623
|
-
}
|
|
624
|
-
return pluginConfig;
|
|
797
|
+
if (!pluginExternals.length) return pluginConfig;
|
|
798
|
+
return 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) } } });
|
|
625
799
|
})();
|
|
626
800
|
},
|
|
627
801
|
configResolved(config) {
|
|
@@ -629,22 +803,6 @@ function createZeusVitePlugin(options = {}) {
|
|
|
629
803
|
}
|
|
630
804
|
});
|
|
631
805
|
}
|
|
632
|
-
function collectPluginExternals(options) {
|
|
633
|
-
var _options$plugins;
|
|
634
|
-
const set = /* @__PURE__ */ new Set();
|
|
635
|
-
for (const plugin of (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : []) {
|
|
636
|
-
var _plugin$external;
|
|
637
|
-
for (const dep of (_plugin$external = plugin.external) !== null && _plugin$external !== void 0 ? _plugin$external : []) set.add(dep);
|
|
638
|
-
}
|
|
639
|
-
return Array.from(set);
|
|
640
|
-
}
|
|
641
|
-
function mergeExternal(userExternal, pluginExternal) {
|
|
642
|
-
if (!userExternal) return pluginExternal;
|
|
643
|
-
if (typeof userExternal === "function") return (source, importer, isResolved) => {
|
|
644
|
-
return pluginExternal.includes(source) || userExternal(source, importer, isResolved);
|
|
645
|
-
};
|
|
646
|
-
return [...Array.isArray(userExternal) ? userExternal : [userExternal], ...pluginExternal];
|
|
647
|
-
}
|
|
648
806
|
function isRolldownVite() {
|
|
649
807
|
return _isRolldownVite.apply(this, arguments);
|
|
650
808
|
}
|
|
@@ -672,4 +830,4 @@ function resolveRuntimeDOMEntry(root) {
|
|
|
672
830
|
}
|
|
673
831
|
}
|
|
674
832
|
//#endregion
|
|
675
|
-
export { createZeusVitePlugin, createZeusVitePlugin as default, createZeusVitePlugin as zeus
|
|
833
|
+
export { createZeusVitePlugin, createZeusVitePlugin as default, createZeusVitePlugin as zeus };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeus-js/bundler-plugin",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.3",
|
|
4
4
|
"description": "Zeus bundler plugin host",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -13,24 +13,31 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/bundler-plugin.d.ts",
|
|
16
|
+
"module": "./dist/bundler-plugin.esm-bundler.js",
|
|
17
|
+
"import": "./dist/bundler-plugin.esm-bundler.js",
|
|
18
|
+
"require": "./index.js",
|
|
16
19
|
"node": {
|
|
17
20
|
"production": "./dist/bundler-plugin.cjs.prod.js",
|
|
18
21
|
"development": "./dist/bundler-plugin.cjs.js",
|
|
19
22
|
"default": "./index.js"
|
|
20
|
-
}
|
|
21
|
-
"module": "./dist/bundler-plugin.esm-bundler.js",
|
|
22
|
-
"import": "./dist/bundler-plugin.esm-bundler.js",
|
|
23
|
-
"require": "./index.js"
|
|
23
|
+
}
|
|
24
24
|
},
|
|
25
25
|
"./vite": {
|
|
26
26
|
"types": "./dist/vite.d.ts",
|
|
27
27
|
"import": "./dist/vite.js"
|
|
28
28
|
},
|
|
29
|
+
"./rollup": {
|
|
30
|
+
"types": "./dist/rollup.d.ts",
|
|
31
|
+
"import": "./dist/rollup.js"
|
|
32
|
+
},
|
|
33
|
+
"./rolldown": {
|
|
34
|
+
"types": "./dist/rolldown.d.ts",
|
|
35
|
+
"import": "./dist/rolldown.js"
|
|
36
|
+
},
|
|
29
37
|
"./manifest": {
|
|
30
38
|
"types": "./dist/outputPlugins/manifest.d.ts",
|
|
31
39
|
"import": "./dist/outputPlugins/manifest.js"
|
|
32
|
-
}
|
|
33
|
-
"./*": "./*"
|
|
40
|
+
}
|
|
34
41
|
},
|
|
35
42
|
"sideEffects": false,
|
|
36
43
|
"repository": {
|
|
@@ -48,6 +55,14 @@
|
|
|
48
55
|
"entry": "vite.ts",
|
|
49
56
|
"output": "dist/vite.js"
|
|
50
57
|
},
|
|
58
|
+
{
|
|
59
|
+
"entry": "rollup.ts",
|
|
60
|
+
"output": "dist/rollup.js"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"entry": "rolldown.ts",
|
|
64
|
+
"output": "dist/rolldown.js"
|
|
65
|
+
},
|
|
51
66
|
{
|
|
52
67
|
"entry": "outputPlugins/manifest.ts",
|
|
53
68
|
"output": "dist/outputPlugins/manifest.js"
|
|
@@ -56,19 +71,24 @@
|
|
|
56
71
|
},
|
|
57
72
|
"dependencies": {
|
|
58
73
|
"@babel/core": "^7.29.0",
|
|
74
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
59
75
|
"fast-glob": "^3.3.3",
|
|
60
76
|
"picomatch": "^4.0.4",
|
|
61
|
-
"@zeus-js/compiler": "0.1.0-beta.
|
|
62
|
-
"@zeus-js/component-analyzer": "0.1.0-beta.
|
|
77
|
+
"@zeus-js/compiler": "0.1.0-beta.3",
|
|
78
|
+
"@zeus-js/component-analyzer": "0.1.0-beta.3"
|
|
63
79
|
},
|
|
64
80
|
"peerDependencies": {
|
|
65
81
|
"rollup": "^4.0.0",
|
|
82
|
+
"rolldown": "^1.0.0",
|
|
66
83
|
"vite": "^8.0.5"
|
|
67
84
|
},
|
|
68
85
|
"peerDependenciesMeta": {
|
|
69
86
|
"rollup": {
|
|
70
87
|
"optional": true
|
|
71
88
|
},
|
|
89
|
+
"rolldown": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
72
92
|
"vite": {
|
|
73
93
|
"optional": true
|
|
74
94
|
}
|