@zeus-js/bundler-plugin 0.1.0-beta.0
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 +506 -0
- package/dist/bundler-plugin.cjs.prod.js +506 -0
- package/dist/bundler-plugin.d.ts +130 -0
- package/dist/bundler-plugin.esm-bundler.js +611 -0
- package/dist/outputPlugins/manifest.cjs.js +27 -0
- package/dist/outputPlugins/manifest.cjs.prod.js +27 -0
- package/dist/outputPlugins/manifest.d.ts +3 -0
- package/dist/outputPlugins/manifest.js +23 -0
- package/dist/outputPlugins/manifest.prod.js +23 -0
- package/dist/vite.cjs.js +565 -0
- package/dist/vite.cjs.prod.js +565 -0
- package/dist/vite.d.ts +6 -0
- package/dist/vite.js +675 -0
- package/dist/vite.prod.js +675 -0
- package/index.js +4 -0
- package/package.json +85 -0
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bundler-plugin v0.1.0-beta.0
|
|
3
|
+
* (c) 2026 baicie
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
**/
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { mergeConfig } from "vite";
|
|
9
|
+
import { analyzeComponents } from "@zeus-js/component-analyzer";
|
|
10
|
+
import fg from "fast-glob";
|
|
11
|
+
import picomatch from "picomatch";
|
|
12
|
+
import fs from "node:fs/promises";
|
|
13
|
+
import { transformAsync } from "@babel/core";
|
|
14
|
+
import zeusCompiler from "@zeus-js/compiler";
|
|
15
|
+
//#region packages/web-c/bundler-plugin/src/filter.ts
|
|
16
|
+
function cleanUrl(id) {
|
|
17
|
+
return id.replace(/[?#].*$/, "");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region packages/web-c/bundler-plugin/src/componentTransformFilter.ts
|
|
21
|
+
function normalizePath$1(value) {
|
|
22
|
+
return value.replace(/\\/g, "/");
|
|
23
|
+
}
|
|
24
|
+
function createComponentTransformFilter(options) {
|
|
25
|
+
const isIncluded = picomatch(options.include);
|
|
26
|
+
const isExcluded = picomatch(options.exclude);
|
|
27
|
+
return function shouldTransform(id) {
|
|
28
|
+
const clean = normalizePath$1(cleanUrl(id));
|
|
29
|
+
const relative = normalizePath$1(path.relative(options.root, clean));
|
|
30
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) return false;
|
|
31
|
+
if (isExcluded(relative)) return false;
|
|
32
|
+
return isIncluded(relative);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region packages/web-c/bundler-plugin/src/defaults.ts
|
|
37
|
+
const DEFAULT_COMPONENT_INCLUDE = ["src/**/*.{ts,tsx,js,jsx}", "components/**/*.{ts,tsx,js,jsx}"];
|
|
38
|
+
const DEFAULT_COMPONENT_EXCLUDE = [
|
|
39
|
+
"**/*.test.*",
|
|
40
|
+
"**/*.spec.*",
|
|
41
|
+
"**/__tests__/**",
|
|
42
|
+
"**/*.d.ts",
|
|
43
|
+
"src/shared/**",
|
|
44
|
+
"node_modules/**",
|
|
45
|
+
"dist/**"
|
|
46
|
+
];
|
|
47
|
+
function resolveComponentInclude(include) {
|
|
48
|
+
return (include === null || include === void 0 ? void 0 : include.length) ? include : DEFAULT_COMPONENT_INCLUDE;
|
|
49
|
+
}
|
|
50
|
+
function resolveComponentExclude(exclude) {
|
|
51
|
+
return (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? exclude : DEFAULT_COMPONENT_EXCLUDE;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region packages/web-c/bundler-plugin/src/diagnostics.ts
|
|
55
|
+
function formatDiagnostic(diagnostic) {
|
|
56
|
+
return `[zeus component-analyzer] ${diagnostic.file}: ${diagnostic.message}`;
|
|
57
|
+
}
|
|
58
|
+
function hasErrorDiagnostics(diagnostics) {
|
|
59
|
+
return diagnostics.some((item) => item.level === "error");
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/asyncToGenerator.js
|
|
63
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
64
|
+
try {
|
|
65
|
+
var i = n[a](c), u = i.value;
|
|
66
|
+
} catch (n) {
|
|
67
|
+
e(n);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
71
|
+
}
|
|
72
|
+
function _asyncToGenerator(n) {
|
|
73
|
+
return function() {
|
|
74
|
+
var t = this, e = arguments;
|
|
75
|
+
return new Promise(function(r, o) {
|
|
76
|
+
var a = n.apply(t, e);
|
|
77
|
+
function _next(n) {
|
|
78
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
79
|
+
}
|
|
80
|
+
function _throw(n) {
|
|
81
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
82
|
+
}
|
|
83
|
+
_next(void 0);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
89
|
+
function _typeof(o) {
|
|
90
|
+
"@babel/helpers - typeof";
|
|
91
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
92
|
+
return typeof o;
|
|
93
|
+
} : function(o) {
|
|
94
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
95
|
+
}, _typeof(o);
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
99
|
+
function toPrimitive(t, r) {
|
|
100
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
101
|
+
var e = t[Symbol.toPrimitive];
|
|
102
|
+
if (void 0 !== e) {
|
|
103
|
+
var i = e.call(t, r || "default");
|
|
104
|
+
if ("object" != _typeof(i)) return i;
|
|
105
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
106
|
+
}
|
|
107
|
+
return ("string" === r ? String : Number)(t);
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
111
|
+
function toPropertyKey(t) {
|
|
112
|
+
var i = toPrimitive(t, "string");
|
|
113
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
117
|
+
function _defineProperty(e, r, t) {
|
|
118
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
119
|
+
value: t,
|
|
120
|
+
enumerable: !0,
|
|
121
|
+
configurable: !0,
|
|
122
|
+
writable: !0
|
|
123
|
+
}) : e[r] = t, e;
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectSpread2.js
|
|
127
|
+
function ownKeys(e, r) {
|
|
128
|
+
var t = Object.keys(e);
|
|
129
|
+
if (Object.getOwnPropertySymbols) {
|
|
130
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
131
|
+
r && (o = o.filter(function(r) {
|
|
132
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
133
|
+
})), t.push.apply(t, o);
|
|
134
|
+
}
|
|
135
|
+
return t;
|
|
136
|
+
}
|
|
137
|
+
function _objectSpread2(e) {
|
|
138
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
139
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
140
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
141
|
+
_defineProperty(e, r, t[r]);
|
|
142
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
143
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return e;
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region packages/web-c/bundler-plugin/src/dts.ts
|
|
150
|
+
function resolveDts(_x) {
|
|
151
|
+
return _resolveDts.apply(this, arguments);
|
|
152
|
+
}
|
|
153
|
+
function _resolveDts() {
|
|
154
|
+
_resolveDts = _asyncToGenerator(function* (options) {
|
|
155
|
+
var _options$mode;
|
|
156
|
+
const mode = (_options$mode = options.mode) !== null && _options$mode !== void 0 ? _options$mode : "auto";
|
|
157
|
+
if (mode === true) return {
|
|
158
|
+
enabled: true,
|
|
159
|
+
mode,
|
|
160
|
+
reason: ["explicit-enabled"]
|
|
161
|
+
};
|
|
162
|
+
if (mode === false) return {
|
|
163
|
+
enabled: false,
|
|
164
|
+
mode,
|
|
165
|
+
reason: ["explicit-disabled"]
|
|
166
|
+
};
|
|
167
|
+
const reason = [];
|
|
168
|
+
if (yield packageDeclaresTypes(options.root)) reason.push("package-types-field");
|
|
169
|
+
if (yield hasTypeScriptDependency(options.root)) reason.push("typescript-dependency");
|
|
170
|
+
if (yield fileExists(path.join(options.root, "tsconfig.json"))) reason.push("tsconfig");
|
|
171
|
+
if (yield hasTypeScriptSource({
|
|
172
|
+
root: options.root,
|
|
173
|
+
include: options.include,
|
|
174
|
+
exclude: options.exclude
|
|
175
|
+
})) reason.push("typescript-source");
|
|
176
|
+
return {
|
|
177
|
+
enabled: reason.length > 0,
|
|
178
|
+
mode,
|
|
179
|
+
reason
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
return _resolveDts.apply(this, arguments);
|
|
183
|
+
}
|
|
184
|
+
function hasTypeScriptDependency(_x2) {
|
|
185
|
+
return _hasTypeScriptDependency.apply(this, arguments);
|
|
186
|
+
}
|
|
187
|
+
function _hasTypeScriptDependency() {
|
|
188
|
+
_hasTypeScriptDependency = _asyncToGenerator(function* (root) {
|
|
189
|
+
const pkg = yield readPackageJson(root);
|
|
190
|
+
if (!pkg) return false;
|
|
191
|
+
const deps = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, pkg.dependencies), pkg.devDependencies), pkg.peerDependencies), pkg.optionalDependencies);
|
|
192
|
+
return Boolean(deps.typescript);
|
|
193
|
+
});
|
|
194
|
+
return _hasTypeScriptDependency.apply(this, arguments);
|
|
195
|
+
}
|
|
196
|
+
function packageDeclaresTypes(_x3) {
|
|
197
|
+
return _packageDeclaresTypes.apply(this, arguments);
|
|
198
|
+
}
|
|
199
|
+
function _packageDeclaresTypes() {
|
|
200
|
+
_packageDeclaresTypes = _asyncToGenerator(function* (root) {
|
|
201
|
+
const pkg = yield readPackageJson(root);
|
|
202
|
+
if (!pkg) return false;
|
|
203
|
+
if (pkg.types || pkg.typings) return true;
|
|
204
|
+
return hasTypesInExports(pkg.exports);
|
|
205
|
+
});
|
|
206
|
+
return _packageDeclaresTypes.apply(this, arguments);
|
|
207
|
+
}
|
|
208
|
+
function hasTypesInExports(value) {
|
|
209
|
+
if (!value) return false;
|
|
210
|
+
if (typeof value !== "object") return false;
|
|
211
|
+
if ("types" in value) return true;
|
|
212
|
+
return Object.values(value).some(hasTypesInExports);
|
|
213
|
+
}
|
|
214
|
+
function hasTypeScriptSource(_x4) {
|
|
215
|
+
return _hasTypeScriptSource.apply(this, arguments);
|
|
216
|
+
}
|
|
217
|
+
function _hasTypeScriptSource() {
|
|
218
|
+
_hasTypeScriptSource = _asyncToGenerator(function* (options) {
|
|
219
|
+
return (yield fg(options.include, {
|
|
220
|
+
cwd: options.root,
|
|
221
|
+
onlyFiles: true,
|
|
222
|
+
absolute: false,
|
|
223
|
+
ignore: options.exclude
|
|
224
|
+
})).some((file) => file.endsWith(".ts") || file.endsWith(".tsx"));
|
|
225
|
+
});
|
|
226
|
+
return _hasTypeScriptSource.apply(this, arguments);
|
|
227
|
+
}
|
|
228
|
+
function readPackageJson(_x5) {
|
|
229
|
+
return _readPackageJson.apply(this, arguments);
|
|
230
|
+
}
|
|
231
|
+
function _readPackageJson() {
|
|
232
|
+
_readPackageJson = _asyncToGenerator(function* (root) {
|
|
233
|
+
try {
|
|
234
|
+
return JSON.parse(yield fs.readFile(path.join(root, "package.json"), "utf-8"));
|
|
235
|
+
} catch (_unused) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
return _readPackageJson.apply(this, arguments);
|
|
240
|
+
}
|
|
241
|
+
function fileExists(_x6) {
|
|
242
|
+
return _fileExists.apply(this, arguments);
|
|
243
|
+
}
|
|
244
|
+
function _fileExists() {
|
|
245
|
+
_fileExists = _asyncToGenerator(function* (file) {
|
|
246
|
+
try {
|
|
247
|
+
yield fs.access(file);
|
|
248
|
+
return true;
|
|
249
|
+
} catch (_unused2) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return _fileExists.apply(this, arguments);
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region packages/web-c/bundler-plugin/src/outputRegistry.ts
|
|
257
|
+
function createOutputRegistry() {
|
|
258
|
+
const map = /* @__PURE__ */ new Map();
|
|
259
|
+
return {
|
|
260
|
+
register(kind, options) {
|
|
261
|
+
map.set(kind, normalizeRegistration(kind, options));
|
|
262
|
+
},
|
|
263
|
+
has(kind) {
|
|
264
|
+
return map.has(kind);
|
|
265
|
+
},
|
|
266
|
+
get(kind) {
|
|
267
|
+
const current = map.get(kind);
|
|
268
|
+
if (!current) throw new Error(`[zeus] output kind "${kind}" is not registered.`);
|
|
269
|
+
return current;
|
|
270
|
+
},
|
|
271
|
+
getDir(kind) {
|
|
272
|
+
return this.get(kind).outDir;
|
|
273
|
+
},
|
|
274
|
+
getFileName(kind, tag) {
|
|
275
|
+
const current = this.get(kind);
|
|
276
|
+
if (current.fileName) return current.fileName(tag, kind);
|
|
277
|
+
return `${normalizeTagName(tag, current.stripPrefix)}.js`;
|
|
278
|
+
},
|
|
279
|
+
join(kind, fileName) {
|
|
280
|
+
return path.posix.join(this.getDir(kind), fileName);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function normalizeRegistration(kind, options) {
|
|
285
|
+
var _options$outDir, _options$stripPrefix;
|
|
286
|
+
return {
|
|
287
|
+
outDir: (_options$outDir = options.outDir) !== null && _options$outDir !== void 0 ? _options$outDir : defaultDir(kind),
|
|
288
|
+
stripPrefix: (_options$stripPrefix = options.stripPrefix) !== null && _options$stripPrefix !== void 0 ? _options$stripPrefix : false,
|
|
289
|
+
fileName: options.fileName
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function defaultDir(kind) {
|
|
293
|
+
switch (kind) {
|
|
294
|
+
case "wc": return "wc";
|
|
295
|
+
case "react": return "react";
|
|
296
|
+
case "vue": return "vue";
|
|
297
|
+
case "icons-react": return "icons/react";
|
|
298
|
+
case "icons-vue": return "icons/vue";
|
|
299
|
+
case "icons-wc": return "icons/wc";
|
|
300
|
+
case "asset": return "";
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function normalizeTagName(tag, stripPrefix) {
|
|
304
|
+
if (stripPrefix && tag.startsWith(stripPrefix)) return tag.slice(stripPrefix.length);
|
|
305
|
+
return tag;
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region packages/web-c/bundler-plugin/src/transform.ts
|
|
309
|
+
function transformZeus(_x) {
|
|
310
|
+
return _transformZeus.apply(this, arguments);
|
|
311
|
+
}
|
|
312
|
+
function _transformZeus() {
|
|
313
|
+
_transformZeus = _asyncToGenerator(function* (options) {
|
|
314
|
+
var _compiler$moduleName;
|
|
315
|
+
const { id, code, compiler, sourcemap = true } = options;
|
|
316
|
+
const result = yield transformAsync(code, {
|
|
317
|
+
filename: id,
|
|
318
|
+
sourceMaps: sourcemap,
|
|
319
|
+
plugins: [[zeusCompiler, _objectSpread2({
|
|
320
|
+
moduleName: (_compiler$moduleName = compiler === null || compiler === void 0 ? void 0 : compiler.moduleName) !== null && _compiler$moduleName !== void 0 ? _compiler$moduleName : "@zeus-js/runtime-dom",
|
|
321
|
+
generate: "dom",
|
|
322
|
+
hydratable: false,
|
|
323
|
+
delegateEvents: true
|
|
324
|
+
}, compiler)]],
|
|
325
|
+
parserOpts: {
|
|
326
|
+
sourceType: "module",
|
|
327
|
+
plugins: ["typescript", "jsx"]
|
|
328
|
+
},
|
|
329
|
+
generatorOpts: {
|
|
330
|
+
retainLines: false,
|
|
331
|
+
compact: false,
|
|
332
|
+
jsescOption: { minimal: true }
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
if (!(result === null || result === void 0 ? void 0 : result.code)) return null;
|
|
336
|
+
return {
|
|
337
|
+
code: result.code,
|
|
338
|
+
map: result.map
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
return _transformZeus.apply(this, arguments);
|
|
342
|
+
}
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region packages/web-c/bundler-plugin/src/virtual.ts
|
|
345
|
+
const RESOLVED_VIRTUAL_PREFIX = "\0";
|
|
346
|
+
var VirtualModuleRegistry = class {
|
|
347
|
+
constructor() {
|
|
348
|
+
this.modules = /* @__PURE__ */ new Map();
|
|
349
|
+
this.virtualDirs = /* @__PURE__ */ new Map();
|
|
350
|
+
this.virtualFileNames = /* @__PURE__ */ new Map();
|
|
351
|
+
this.idsByFileName = /* @__PURE__ */ new Map();
|
|
352
|
+
}
|
|
353
|
+
set(id, code, fileName) {
|
|
354
|
+
const normalized = normalizeVirtualId(id);
|
|
355
|
+
this.modules.set(normalized, code);
|
|
356
|
+
if (fileName) {
|
|
357
|
+
const dir = path.posix.dirname(fileName);
|
|
358
|
+
this.virtualDirs.set(normalized, dir);
|
|
359
|
+
const normalizedFileName = normalizePath(fileName);
|
|
360
|
+
this.virtualFileNames.set(normalized, normalizedFileName);
|
|
361
|
+
this.idsByFileName.set(normalizedFileName, normalized);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
has(id) {
|
|
365
|
+
return this.modules.has(normalizeVirtualId(id));
|
|
366
|
+
}
|
|
367
|
+
get(id) {
|
|
368
|
+
return this.modules.get(normalizeVirtualId(id));
|
|
369
|
+
}
|
|
370
|
+
clear() {
|
|
371
|
+
this.modules.clear();
|
|
372
|
+
this.virtualDirs.clear();
|
|
373
|
+
this.virtualFileNames.clear();
|
|
374
|
+
this.idsByFileName.clear();
|
|
375
|
+
}
|
|
376
|
+
resolve(id, importer) {
|
|
377
|
+
const normalized = normalizeVirtualId(id);
|
|
378
|
+
if (this.modules.has(normalized)) return RESOLVED_VIRTUAL_PREFIX + normalized;
|
|
379
|
+
if (importer && (id.startsWith(".") || id.startsWith(".."))) {
|
|
380
|
+
const importerNormalized = normalizeVirtualId(importer);
|
|
381
|
+
const importerDir = this.virtualDirs.get(importerNormalized);
|
|
382
|
+
if (importerDir) {
|
|
383
|
+
const resolved = normalizePath(path.posix.join(importerDir, id));
|
|
384
|
+
const resolvedVirtualId = this.idsByFileName.get(resolved);
|
|
385
|
+
if (resolvedVirtualId) return RESOLVED_VIRTUAL_PREFIX + resolvedVirtualId;
|
|
386
|
+
const importingPrefix = this.getIdPrefix(importerNormalized);
|
|
387
|
+
if (importingPrefix !== null) {
|
|
388
|
+
const baseName = path.posix.basename(resolved, ".js");
|
|
389
|
+
for (const [key] of this.modules.entries()) if (key === importingPrefix + baseName) return RESOLVED_VIRTUAL_PREFIX + key;
|
|
390
|
+
for (const stripPrefix of [
|
|
391
|
+
"z-",
|
|
392
|
+
"wc-",
|
|
393
|
+
"wc/",
|
|
394
|
+
""
|
|
395
|
+
]) {
|
|
396
|
+
const candidate = stripPrefix ? importingPrefix + stripPrefix + baseName : importingPrefix + baseName;
|
|
397
|
+
if (this.modules.has(candidate)) return RESOLVED_VIRTUAL_PREFIX + candidate;
|
|
398
|
+
}
|
|
399
|
+
const fullName = baseName;
|
|
400
|
+
for (const [key] of this.modules.entries()) if (key.endsWith(":" + fullName)) return RESOLVED_VIRTUAL_PREFIX + key;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
getIdPrefix(virtualId) {
|
|
407
|
+
const lastColon = virtualId.lastIndexOf(":");
|
|
408
|
+
if (lastColon <= 0) return null;
|
|
409
|
+
return virtualId.slice(0, lastColon + 1);
|
|
410
|
+
}
|
|
411
|
+
load(id) {
|
|
412
|
+
var _this$modules$get;
|
|
413
|
+
if (!id.startsWith(RESOLVED_VIRTUAL_PREFIX)) return null;
|
|
414
|
+
const normalized = id.slice(1);
|
|
415
|
+
return (_this$modules$get = this.modules.get(normalized)) !== null && _this$modules$get !== void 0 ? _this$modules$get : null;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
function normalizeVirtualId(id) {
|
|
419
|
+
return id.startsWith("\0") ? id.slice(1) : id;
|
|
420
|
+
}
|
|
421
|
+
function normalizePath(value) {
|
|
422
|
+
return value.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region packages/web-c/bundler-plugin/src/rollup.ts
|
|
426
|
+
function createZeusPlugin(options = {}) {
|
|
427
|
+
let shouldTransform = (_id) => false;
|
|
428
|
+
const virtualModules = new VirtualModuleRegistry();
|
|
429
|
+
let ctx;
|
|
430
|
+
return {
|
|
431
|
+
name: "zeus-bundler-plugin",
|
|
432
|
+
buildStart() {
|
|
433
|
+
var _this = this;
|
|
434
|
+
return _asyncToGenerator(function* () {
|
|
435
|
+
var _options$components, _options$components2, _options$plugins;
|
|
436
|
+
virtualModules.clear();
|
|
437
|
+
const root = resolveRoot(options.root);
|
|
438
|
+
const include = resolveComponentInclude((_options$components = options.components) === null || _options$components === void 0 ? void 0 : _options$components.include);
|
|
439
|
+
const exclude = resolveComponentExclude((_options$components2 = options.components) === null || _options$components2 === void 0 ? void 0 : _options$components2.exclude);
|
|
440
|
+
shouldTransform = createComponentTransformFilter({
|
|
441
|
+
root,
|
|
442
|
+
include,
|
|
443
|
+
exclude
|
|
444
|
+
});
|
|
445
|
+
const dts = yield resolveDts({
|
|
446
|
+
root,
|
|
447
|
+
mode: options.dts,
|
|
448
|
+
include,
|
|
449
|
+
exclude
|
|
450
|
+
});
|
|
451
|
+
const manifestResult = yield createManifest(root, include, exclude);
|
|
452
|
+
for (const file of yield collectWatchFiles(root, include, exclude)) _this.addWatchFile(file);
|
|
453
|
+
const diagnostics = manifestResult.diagnostics;
|
|
454
|
+
for (const diagnostic of diagnostics) {
|
|
455
|
+
const message = formatDiagnostic(diagnostic);
|
|
456
|
+
if (diagnostic.level === "error") _this.error(message);
|
|
457
|
+
else if (options.diagnostics !== false) _this.warn(message);
|
|
458
|
+
}
|
|
459
|
+
if (hasErrorDiagnostics(diagnostics)) _this.error("[zeus] component analyzer failed.");
|
|
460
|
+
if (options.diagnostics === "verbose") _this.warn(`[zeus] dts ${dts.enabled ? "enabled" : "disabled"}: ${dts.reason.join(", ") || "no signal"}`);
|
|
461
|
+
const outputs = createOutputRegistry();
|
|
462
|
+
ctx = {
|
|
463
|
+
root,
|
|
464
|
+
manifest: manifestResult.manifest,
|
|
465
|
+
diagnostics,
|
|
466
|
+
dts,
|
|
467
|
+
outputs,
|
|
468
|
+
emitFile: _this.emitFile.bind(_this),
|
|
469
|
+
warn: _this.warn.bind(_this),
|
|
470
|
+
error: _this.error.bind(_this),
|
|
471
|
+
addWatchFile: _this.addWatchFile.bind(_this),
|
|
472
|
+
meta: { watchMode: _this.meta.watchMode }
|
|
473
|
+
};
|
|
474
|
+
const plugins = (_options$plugins = options.plugins) !== null && _options$plugins !== void 0 ? _options$plugins : [];
|
|
475
|
+
for (const plugin of plugins) {
|
|
476
|
+
var _plugin$setup;
|
|
477
|
+
yield (_plugin$setup = plugin.setup) === null || _plugin$setup === void 0 ? void 0 : _plugin$setup.call(plugin, ctx);
|
|
478
|
+
}
|
|
479
|
+
for (const plugin of plugins) {
|
|
480
|
+
var _plugin$buildStart;
|
|
481
|
+
yield (_plugin$buildStart = plugin.buildStart) === null || _plugin$buildStart === void 0 ? void 0 : _plugin$buildStart.call(plugin, ctx);
|
|
482
|
+
}
|
|
483
|
+
for (const plugin of plugins) {
|
|
484
|
+
var _plugin$virtualModule;
|
|
485
|
+
const modules = yield (_plugin$virtualModule = plugin.virtualModules) === null || _plugin$virtualModule === void 0 ? void 0 : _plugin$virtualModule.call(plugin, ctx);
|
|
486
|
+
if (!modules) continue;
|
|
487
|
+
for (const mod of modules) virtualModules.set(mod.id, mod.code, mod.fileName);
|
|
488
|
+
emitVirtualEntries(modules, _this);
|
|
489
|
+
}
|
|
490
|
+
})();
|
|
491
|
+
},
|
|
492
|
+
resolveId(id, importer) {
|
|
493
|
+
const resolved = virtualModules.resolve(id, importer);
|
|
494
|
+
if (resolved) return {
|
|
495
|
+
id: resolved,
|
|
496
|
+
moduleSideEffects: "no-treeshake"
|
|
497
|
+
};
|
|
498
|
+
return null;
|
|
499
|
+
},
|
|
500
|
+
load(id) {
|
|
501
|
+
return virtualModules.load(id);
|
|
502
|
+
},
|
|
503
|
+
transform(code, id) {
|
|
504
|
+
return _asyncToGenerator(function* () {
|
|
505
|
+
if (!shouldTransform(id)) return null;
|
|
506
|
+
const result = yield transformZeus({
|
|
507
|
+
id,
|
|
508
|
+
code,
|
|
509
|
+
compiler: options.compiler,
|
|
510
|
+
sourcemap: true
|
|
511
|
+
});
|
|
512
|
+
if (!result) return null;
|
|
513
|
+
return result;
|
|
514
|
+
})();
|
|
515
|
+
},
|
|
516
|
+
generateBundle(_, bundle) {
|
|
517
|
+
var _this2 = this;
|
|
518
|
+
return _asyncToGenerator(function* () {
|
|
519
|
+
var _options$plugins2;
|
|
520
|
+
if (!ctx) return;
|
|
521
|
+
const plugins = (_options$plugins2 = options.plugins) !== null && _options$plugins2 !== void 0 ? _options$plugins2 : [];
|
|
522
|
+
for (const plugin of plugins) {
|
|
523
|
+
var _plugin$generateBundl;
|
|
524
|
+
const files = yield (_plugin$generateBundl = plugin.generateBundle) === null || _plugin$generateBundl === void 0 ? void 0 : _plugin$generateBundl.call(plugin, ctx, bundle);
|
|
525
|
+
if (!files) continue;
|
|
526
|
+
for (const file of files) emitOutputFile(_this2, file);
|
|
527
|
+
}
|
|
528
|
+
})();
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
function createManifest(_x, _x2, _x3) {
|
|
533
|
+
return _createManifest.apply(this, arguments);
|
|
534
|
+
}
|
|
535
|
+
function _createManifest() {
|
|
536
|
+
_createManifest = _asyncToGenerator(function* (root, include, exclude) {
|
|
537
|
+
if (!include.length) return {
|
|
538
|
+
manifest: {
|
|
539
|
+
version: 1,
|
|
540
|
+
components: []
|
|
541
|
+
},
|
|
542
|
+
diagnostics: []
|
|
543
|
+
};
|
|
544
|
+
return yield analyzeComponents({
|
|
545
|
+
root,
|
|
546
|
+
include,
|
|
547
|
+
exclude
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
return _createManifest.apply(this, arguments);
|
|
551
|
+
}
|
|
552
|
+
function collectWatchFiles(_x4, _x5, _x6) {
|
|
553
|
+
return _collectWatchFiles.apply(this, arguments);
|
|
554
|
+
}
|
|
555
|
+
function _collectWatchFiles() {
|
|
556
|
+
_collectWatchFiles = _asyncToGenerator(function* (root, include, exclude) {
|
|
557
|
+
if (!include.length) return [];
|
|
558
|
+
return yield fg(include, {
|
|
559
|
+
cwd: root,
|
|
560
|
+
absolute: true,
|
|
561
|
+
ignore: exclude
|
|
562
|
+
});
|
|
563
|
+
});
|
|
564
|
+
return _collectWatchFiles.apply(this, arguments);
|
|
565
|
+
}
|
|
566
|
+
function resolveRoot(root) {
|
|
567
|
+
if (typeof root === "function") return path.resolve(root());
|
|
568
|
+
return path.resolve(root !== null && root !== void 0 ? root : process.cwd());
|
|
569
|
+
}
|
|
570
|
+
function emitOutputFile(pluginContext, file) {
|
|
571
|
+
if (file.type === "asset") {
|
|
572
|
+
pluginContext.emitFile({
|
|
573
|
+
type: "asset",
|
|
574
|
+
fileName: file.fileName,
|
|
575
|
+
source: file.source
|
|
576
|
+
});
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
pluginContext.emitFile({
|
|
580
|
+
type: "chunk",
|
|
581
|
+
id: file.id,
|
|
582
|
+
fileName: file.fileName
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
function emitVirtualEntries(modules, pluginContext) {
|
|
586
|
+
for (const mod of modules) {
|
|
587
|
+
if (!mod.fileName) continue;
|
|
588
|
+
pluginContext.emitFile({
|
|
589
|
+
type: "chunk",
|
|
590
|
+
id: mod.id,
|
|
591
|
+
fileName: mod.fileName,
|
|
592
|
+
preserveSignature: "strict"
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region packages/web-c/bundler-plugin/src/vite.ts
|
|
598
|
+
function createZeusVitePlugin(options = {}) {
|
|
599
|
+
var _options$root;
|
|
600
|
+
let resolvedConfig;
|
|
601
|
+
return _objectSpread2(_objectSpread2({}, createZeusPlugin(_objectSpread2(_objectSpread2({}, options), {}, { root: (_options$root = options.root) !== null && _options$root !== void 0 ? _options$root : (() => {
|
|
602
|
+
var _resolvedConfig$root;
|
|
603
|
+
return (_resolvedConfig$root = resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.root) !== null && _resolvedConfig$root !== void 0 ? _resolvedConfig$root : process.cwd();
|
|
604
|
+
}) }))), {}, {
|
|
605
|
+
name: "vite-plugin-zeus",
|
|
606
|
+
enforce: "pre",
|
|
607
|
+
config(userConfig) {
|
|
608
|
+
return _asyncToGenerator(function* () {
|
|
609
|
+
const runtimeDomEntry = resolveRuntimeDOMEntry(userConfig.root);
|
|
610
|
+
const pluginExternals = collectPluginExternals(options);
|
|
611
|
+
const pluginConfig = _objectSpread2(_objectSpread2({}, (yield isRolldownVite()) ? { oxc: { jsx: "preserve" } } : { esbuild: { jsx: "preserve" } }), {}, { resolve: {
|
|
612
|
+
alias: runtimeDomEntry ? { "@zeus-js/runtime-dom": runtimeDomEntry } : void 0,
|
|
613
|
+
dedupe: [
|
|
614
|
+
"@zeus-js/signal",
|
|
615
|
+
"@zeus-js/runtime-dom",
|
|
616
|
+
"@zeus-js/zeus",
|
|
617
|
+
"@zeus-js/component-dts"
|
|
618
|
+
]
|
|
619
|
+
} });
|
|
620
|
+
if (pluginExternals.length) {
|
|
621
|
+
var _userConfig$build;
|
|
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;
|
|
625
|
+
})();
|
|
626
|
+
},
|
|
627
|
+
configResolved(config) {
|
|
628
|
+
resolvedConfig = config;
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
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
|
+
function isRolldownVite() {
|
|
649
|
+
return _isRolldownVite.apply(this, arguments);
|
|
650
|
+
}
|
|
651
|
+
function _isRolldownVite() {
|
|
652
|
+
_isRolldownVite = _asyncToGenerator(function* () {
|
|
653
|
+
try {
|
|
654
|
+
const vite = yield import("vite");
|
|
655
|
+
return typeof vite.rolldownVersion === "string" || typeof vite.transformWithOxc === "function";
|
|
656
|
+
} catch (_unused) {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
return _isRolldownVite.apply(this, arguments);
|
|
661
|
+
}
|
|
662
|
+
function resolveRuntimeDOMEntry(root) {
|
|
663
|
+
const projectRoot = path.resolve(process.cwd(), root !== null && root !== void 0 ? root : ".");
|
|
664
|
+
const requireFromProject = createRequire(path.join(projectRoot, "package.json"));
|
|
665
|
+
try {
|
|
666
|
+
return requireFromProject.resolve("@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js");
|
|
667
|
+
} catch (_unused2) {}
|
|
668
|
+
try {
|
|
669
|
+
return createRequire(requireFromProject.resolve("@zeus-js/zeus")).resolve("@zeus-js/runtime-dom/dist/runtime-dom.esm-bundler.js");
|
|
670
|
+
} catch (_unused3) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
//#endregion
|
|
675
|
+
export { createZeusVitePlugin, createZeusVitePlugin as default, createZeusVitePlugin as zeus, mergeExternal };
|
package/index.js
ADDED