@zeus-js/output-wc 0.1.0-beta.2 → 0.1.0-beta.4
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/capabilities.cjs.js +2 -2
- package/dist/capabilities.cjs.prod.js +2 -2
- package/dist/capabilities.js +1 -1
- package/dist/capabilities.prod.js +1 -1
- package/dist/output-wc.cjs.js +317 -23
- package/dist/output-wc.cjs.prod.js +317 -23
- package/dist/output-wc.d.ts +26 -2
- package/dist/output-wc.esm-bundler.js +318 -24
- package/package.json +13 -11
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* output-wc v0.1.0-beta.
|
|
2
|
+
* output-wc v0.1.0-beta.4
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { resolvePluginDts } from "@zeus-js/bundler-plugin";
|
|
8
|
-
import { generateWCDtsFiles } from "@zeus-js/component-dts";
|
|
8
|
+
import { generateLoaderDts, generateWCDtsFiles, generateWCJsxDts } from "@zeus-js/component-dts";
|
|
9
9
|
//#region packages/web-c/output-wc/src/generateCustomElementsJson.ts
|
|
10
10
|
function generateCustomElementsJson(options) {
|
|
11
11
|
const { manifest, getModulePath } = options;
|
|
@@ -27,7 +27,10 @@ function generateCustomElementsJson(options) {
|
|
|
27
27
|
events: generateEvents(component),
|
|
28
28
|
slots: generateSlots(component),
|
|
29
29
|
cssParts: component.cssParts.map((name) => ({ name })),
|
|
30
|
-
cssProperties: component.
|
|
30
|
+
cssProperties: getCssVars(component).map((variable) => ({
|
|
31
|
+
name: variable.name,
|
|
32
|
+
description: variable.description
|
|
33
|
+
}))
|
|
31
34
|
}],
|
|
32
35
|
exports: [{
|
|
33
36
|
kind: "js",
|
|
@@ -57,7 +60,8 @@ function generateAttributes(component) {
|
|
|
57
60
|
return result;
|
|
58
61
|
}
|
|
59
62
|
function generateMembers(component) {
|
|
60
|
-
|
|
63
|
+
var _component$methods;
|
|
64
|
+
const fields = Object.entries(component.props).map(([name, prop]) => {
|
|
61
65
|
return {
|
|
62
66
|
kind: "field",
|
|
63
67
|
name,
|
|
@@ -66,18 +70,28 @@ function generateMembers(component) {
|
|
|
66
70
|
default: prop.default === void 0 ? void 0 : JSON.stringify(prop.default)
|
|
67
71
|
};
|
|
68
72
|
});
|
|
73
|
+
const methods = Object.keys((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {}).map((name) => {
|
|
74
|
+
return {
|
|
75
|
+
kind: "method",
|
|
76
|
+
name
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
return [...fields, ...methods];
|
|
69
80
|
}
|
|
70
81
|
function generateEvents(component) {
|
|
71
|
-
return Object.entries(component.events).map(([
|
|
82
|
+
return Object.entries(component.events).map(([key, event]) => {
|
|
83
|
+
var _event$name, _event$key;
|
|
72
84
|
return {
|
|
73
|
-
name,
|
|
85
|
+
name: (_event$name = event.name) !== null && _event$name !== void 0 ? _event$name : toKebabCase$1((_event$key = event.key) !== null && _event$key !== void 0 ? _event$key : key),
|
|
74
86
|
description: event.description,
|
|
75
87
|
type: { text: event.detail ? `CustomEvent<${formatDetailType(event.detail)}>` : "CustomEvent" }
|
|
76
88
|
};
|
|
77
89
|
});
|
|
78
90
|
}
|
|
79
91
|
function generateSlots(component) {
|
|
80
|
-
return Object.entries(component.slots).map(([
|
|
92
|
+
return Object.entries(component.slots).map(([key, slot]) => {
|
|
93
|
+
var _slot$name;
|
|
94
|
+
const name = (_slot$name = slot.name) !== null && _slot$name !== void 0 ? _slot$name : key;
|
|
81
95
|
return {
|
|
82
96
|
name: name === "default" ? "" : name,
|
|
83
97
|
description: slot.description
|
|
@@ -87,6 +101,7 @@ function generateSlots(component) {
|
|
|
87
101
|
function getAttributeName(propName, prop) {
|
|
88
102
|
if (prop.attr === false) return false;
|
|
89
103
|
if (typeof prop.attr === "string") return prop.attr;
|
|
104
|
+
if (!isAttributeBackedType$1(prop.type)) return false;
|
|
90
105
|
return propName.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
91
106
|
}
|
|
92
107
|
function formatPropType(prop) {
|
|
@@ -98,15 +113,25 @@ function formatPropType(prop) {
|
|
|
98
113
|
case "boolean": return "boolean";
|
|
99
114
|
case "array": return "unknown[]";
|
|
100
115
|
case "object": return "Record<string, unknown>";
|
|
116
|
+
case "function": return "Function";
|
|
101
117
|
default: return "unknown";
|
|
102
118
|
}
|
|
103
119
|
}
|
|
120
|
+
function isAttributeBackedType$1(type) {
|
|
121
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
122
|
+
}
|
|
104
123
|
function formatDetailType(detail) {
|
|
105
124
|
return `{ ${Object.entries(detail).map(([name, type]) => `${name}: ${type}`).join("; ")} }`;
|
|
106
125
|
}
|
|
107
126
|
function normalizeModulePath(value) {
|
|
108
127
|
return value.replace(/\\/g, "/");
|
|
109
128
|
}
|
|
129
|
+
function getCssVars(component) {
|
|
130
|
+
return Object.values(component.cssVars);
|
|
131
|
+
}
|
|
132
|
+
function toKebabCase$1(value) {
|
|
133
|
+
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
134
|
+
}
|
|
110
135
|
//#endregion
|
|
111
136
|
//#region packages/web-c/output-wc/src/imports.ts
|
|
112
137
|
function toAbsoluteImportPath(root, source) {
|
|
@@ -149,6 +174,162 @@ function getVirtualIndexId() {
|
|
|
149
174
|
return "zeus:wc:index";
|
|
150
175
|
}
|
|
151
176
|
//#endregion
|
|
177
|
+
//#region packages/web-c/output-wc/src/generateLazyEntry.ts
|
|
178
|
+
function generateLazyEntry(options) {
|
|
179
|
+
const { component, outPath, sourceImport } = options;
|
|
180
|
+
const source = sourceImport !== null && sourceImport !== void 0 ? sourceImport : toRelativeImport(component.source, outPath);
|
|
181
|
+
return [
|
|
182
|
+
`import { mountElementDefinition } from "@zeus-js/runtime-dom";`,
|
|
183
|
+
`import { ${component.exportName} } from ${JSON.stringify(source)};`,
|
|
184
|
+
"",
|
|
185
|
+
`export function createComponent(hostRef) {`,
|
|
186
|
+
` let mounted;`,
|
|
187
|
+
` const mountState = {`,
|
|
188
|
+
` attributeProps: hostRef.attributeProps,`,
|
|
189
|
+
` internals: hostRef.internals,`,
|
|
190
|
+
` reflectingAttrs: hostRef.reflectingAttrs,`,
|
|
191
|
+
` };`,
|
|
192
|
+
"",
|
|
193
|
+
` return {`,
|
|
194
|
+
` connected() {`,
|
|
195
|
+
` if (mounted) return;`,
|
|
196
|
+
"",
|
|
197
|
+
` mounted = mountElementDefinition(`,
|
|
198
|
+
` ${component.exportName},`,
|
|
199
|
+
` hostRef.host,`,
|
|
200
|
+
` hostRef.values,`,
|
|
201
|
+
` mountState,`,
|
|
202
|
+
` );`,
|
|
203
|
+
` },`,
|
|
204
|
+
"",
|
|
205
|
+
` disconnected() {`,
|
|
206
|
+
` mounted?.dispose();`,
|
|
207
|
+
` mounted = undefined;`,
|
|
208
|
+
` },`,
|
|
209
|
+
"",
|
|
210
|
+
` propertyChanged(name, oldValue, newValue) {`,
|
|
211
|
+
` mounted?.propertyChanged(name, oldValue, newValue);`,
|
|
212
|
+
` },`,
|
|
213
|
+
"",
|
|
214
|
+
` formAssociated(form) {`,
|
|
215
|
+
` mounted?.formAssociated(form);`,
|
|
216
|
+
` },`,
|
|
217
|
+
"",
|
|
218
|
+
` formDisabled(disabled) {`,
|
|
219
|
+
` mounted?.formDisabled(disabled);`,
|
|
220
|
+
` },`,
|
|
221
|
+
"",
|
|
222
|
+
` formReset() {`,
|
|
223
|
+
` mounted?.formReset();`,
|
|
224
|
+
` },`,
|
|
225
|
+
"",
|
|
226
|
+
` formStateRestore(state, mode) {`,
|
|
227
|
+
` mounted?.formStateRestore(state, mode);`,
|
|
228
|
+
` },`,
|
|
229
|
+
` };`,
|
|
230
|
+
`}`,
|
|
231
|
+
"",
|
|
232
|
+
`export default { createComponent };`,
|
|
233
|
+
""
|
|
234
|
+
].join("\n");
|
|
235
|
+
}
|
|
236
|
+
function toRelativeImport(source, outPath) {
|
|
237
|
+
const sourceParts = normalizePath(source).split("/");
|
|
238
|
+
const outParts = normalizePath(outPath).split("/");
|
|
239
|
+
let common = 0;
|
|
240
|
+
for (let i = 0; i < Math.min(sourceParts.length, outParts.length); i++) if (sourceParts[i] === outParts[i]) common++;
|
|
241
|
+
else break;
|
|
242
|
+
return [...outParts.slice(common).map(() => ".."), ...sourceParts.slice(common)].join("/");
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region packages/web-c/output-wc/src/generateLazyManifest.ts
|
|
246
|
+
function generateLazyManifest(options) {
|
|
247
|
+
const { components, getEntryFileName } = options;
|
|
248
|
+
return `export const components = [
|
|
249
|
+
${components.map((component) => {
|
|
250
|
+
var _component$runtimePro, _component$methods, _component$meta$shado, _component$meta, _component$meta$formA, _component$meta2;
|
|
251
|
+
const entryFile = getEntryFileName(component.tag).replace(/\\/g, "/");
|
|
252
|
+
const props = generatePropsArray((_component$runtimePro = component.runtimeProps) !== null && _component$runtimePro !== void 0 ? _component$runtimePro : component.props);
|
|
253
|
+
const methods = Object.keys((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {});
|
|
254
|
+
const importPath = entryFile.startsWith(".") ? JSON.stringify(entryFile) : JSON.stringify(`./${entryFile}`);
|
|
255
|
+
const methodLine = methods.length ? ` methods: ${JSON.stringify(methods)},\n` : "";
|
|
256
|
+
return ` {
|
|
257
|
+
tagName: ${JSON.stringify(component.tag)},
|
|
258
|
+
shadow: ${(_component$meta$shado = (_component$meta = component.meta) === null || _component$meta === void 0 ? void 0 : _component$meta.shadow) !== null && _component$meta$shado !== void 0 ? _component$meta$shado : false},
|
|
259
|
+
formAssociated: ${(_component$meta$formA = (_component$meta2 = component.meta) === null || _component$meta2 === void 0 ? void 0 : _component$meta2.formAssociated) !== null && _component$meta$formA !== void 0 ? _component$meta$formA : false},
|
|
260
|
+
load: () => import(${importPath}),
|
|
261
|
+
props: ${props},
|
|
262
|
+
${methodLine}
|
|
263
|
+
}`;
|
|
264
|
+
}).join(",\n")}
|
|
265
|
+
];
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
268
|
+
function generatePropsArray(props) {
|
|
269
|
+
const entries = Object.entries(props);
|
|
270
|
+
if (entries.length === 0) return "[]";
|
|
271
|
+
return `[\n${entries.map(([name, prop]) => {
|
|
272
|
+
const parts = [`name: ${JSON.stringify(name)}`];
|
|
273
|
+
if (!isAttributeBackedType(prop.type) && !prop.deserialize || prop.attr === false) parts.push("attrName: false");
|
|
274
|
+
else {
|
|
275
|
+
var _prop$attr;
|
|
276
|
+
const attrName = (_prop$attr = prop.attr) !== null && _prop$attr !== void 0 ? _prop$attr : toKebabCase(name);
|
|
277
|
+
if (attrName !== toKebabCase(name)) parts.push(`attrName: ${JSON.stringify(attrName)}`);
|
|
278
|
+
}
|
|
279
|
+
parts.push(`type: ${JSON.stringify(prop.type)}`);
|
|
280
|
+
if (prop.reflect && (isAttributeBackedType(prop.type) || Boolean(prop.serialize))) parts.push("reflect: true");
|
|
281
|
+
if (prop.serialize) parts.push("serialize: true");
|
|
282
|
+
if (prop.deserialize) parts.push("deserialize: true");
|
|
283
|
+
return ` { ${parts.join(", ")} }`;
|
|
284
|
+
}).join(",\n")}\n ]`;
|
|
285
|
+
}
|
|
286
|
+
function isAttributeBackedType(type) {
|
|
287
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
288
|
+
}
|
|
289
|
+
function toKebabCase(value) {
|
|
290
|
+
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region packages/web-c/output-wc/src/generateLoader.ts
|
|
294
|
+
function generateLoader() {
|
|
295
|
+
return `import { bootstrapLazy } from "@zeus-js/web-c-runtime";
|
|
296
|
+
import { components } from "./components.manifest.js";
|
|
297
|
+
|
|
298
|
+
let defined = false;
|
|
299
|
+
|
|
300
|
+
export function defineCustomElements() {
|
|
301
|
+
if (defined) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (typeof customElements === "undefined") {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
bootstrapLazy(components);
|
|
310
|
+
|
|
311
|
+
defined = true;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export const defineLazyElements = defineCustomElements;
|
|
315
|
+
`;
|
|
316
|
+
}
|
|
317
|
+
function generateAutoEntry() {
|
|
318
|
+
return `import { defineCustomElements } from "./loader.js";
|
|
319
|
+
|
|
320
|
+
defineCustomElements();
|
|
321
|
+
|
|
322
|
+
export {};
|
|
323
|
+
`;
|
|
324
|
+
}
|
|
325
|
+
function generateLazyIndex() {
|
|
326
|
+
return `export {
|
|
327
|
+
defineCustomElements,
|
|
328
|
+
defineLazyElements,
|
|
329
|
+
} from "./loader.js";
|
|
330
|
+
`;
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
152
333
|
//#region packages/web-c/output-wc/src/generateManifest.ts
|
|
153
334
|
function generateZeusComponentsManifest(manifest) {
|
|
154
335
|
return `${JSON.stringify(manifest, null, 2)}\n`;
|
|
@@ -156,17 +337,21 @@ function generateZeusComponentsManifest(manifest) {
|
|
|
156
337
|
//#endregion
|
|
157
338
|
//#region packages/web-c/output-wc/src/index.ts
|
|
158
339
|
function wc(options = {}) {
|
|
159
|
-
var _options$outDir, _options$stripPrefix, _options$manifestFile, _options$customElemen, _options$dts, _options$jsxDts, _options$index, _options$warnOnFileNa;
|
|
340
|
+
var _options$register, _options$outDir, _options$stripPrefix, _options$manifestFile, _options$customElemen, _options$dts, _options$jsxDts, _options$index, _options$warnOnFileNa, _options$auto, _options$entryFileNam;
|
|
341
|
+
const registerMode = (_options$register = options.register) !== null && _options$register !== void 0 ? _options$register : "lazy";
|
|
160
342
|
const normalized = {
|
|
161
343
|
outDir: (_options$outDir = options.outDir) !== null && _options$outDir !== void 0 ? _options$outDir : "wc",
|
|
162
344
|
stripPrefix: (_options$stripPrefix = options.stripPrefix) !== null && _options$stripPrefix !== void 0 ? _options$stripPrefix : false,
|
|
163
345
|
fileName: options.fileName,
|
|
164
346
|
manifestFile: (_options$manifestFile = options.manifestFile) !== null && _options$manifestFile !== void 0 ? _options$manifestFile : "zeus.components.json",
|
|
165
347
|
customElementsFile: (_options$customElemen = options.customElementsFile) !== null && _options$customElemen !== void 0 ? _options$customElemen : "custom-elements.json",
|
|
166
|
-
dts: (_options$dts = options.dts) !== null && _options$dts !== void 0 ? _options$dts :
|
|
167
|
-
jsxDts: (_options$jsxDts = options.jsxDts) !== null && _options$jsxDts !== void 0 ? _options$jsxDts :
|
|
348
|
+
dts: (_options$dts = options.dts) !== null && _options$dts !== void 0 ? _options$dts : true,
|
|
349
|
+
jsxDts: (_options$jsxDts = options.jsxDts) !== null && _options$jsxDts !== void 0 ? _options$jsxDts : true,
|
|
168
350
|
index: (_options$index = options.index) !== null && _options$index !== void 0 ? _options$index : true,
|
|
169
|
-
warnOnFileNameCollision: (_options$warnOnFileNa = options.warnOnFileNameCollision) !== null && _options$warnOnFileNa !== void 0 ? _options$warnOnFileNa : true
|
|
351
|
+
warnOnFileNameCollision: (_options$warnOnFileNa = options.warnOnFileNameCollision) !== null && _options$warnOnFileNa !== void 0 ? _options$warnOnFileNa : true,
|
|
352
|
+
register: registerMode,
|
|
353
|
+
auto: (_options$auto = options.auto) !== null && _options$auto !== void 0 ? _options$auto : true,
|
|
354
|
+
entryFileName: (_options$entryFileNam = options.entryFileName) !== null && _options$entryFileNam !== void 0 ? _options$entryFileNam : ((tag) => `${tag}.entry`)
|
|
170
355
|
};
|
|
171
356
|
let _outDir = normalized.outDir;
|
|
172
357
|
return {
|
|
@@ -181,7 +366,32 @@ function wc(options = {}) {
|
|
|
181
366
|
},
|
|
182
367
|
buildStart(ctx) {
|
|
183
368
|
if (!ctx.manifest) return;
|
|
184
|
-
|
|
369
|
+
if (normalized.register === "lazy") for (const component of ctx.manifest.components) {
|
|
370
|
+
var _component$runtimePro, _component$runtimePro2;
|
|
371
|
+
const diagnostics = (_component$runtimePro = component.runtimePropsDiagnostics) !== null && _component$runtimePro !== void 0 ? _component$runtimePro : [];
|
|
372
|
+
if (diagnostics.length > 0) ctx.error([`[zeus-output-wc] <${component.tag}> cannot be emitted with register:"lazy" because its runtime props are not statically analyzable.`, ...diagnostics.map((message) => `- ${message}`)].join("\n"));
|
|
373
|
+
const runtimeProps = (_component$runtimePro2 = component.runtimeProps) !== null && _component$runtimePro2 !== void 0 ? _component$runtimePro2 : {};
|
|
374
|
+
for (const [name, prop] of Object.entries(runtimeProps)) {
|
|
375
|
+
if (isAttributeBackedRuntimeProp(prop.type)) continue;
|
|
376
|
+
if (prop.attr !== void 0 && prop.attr !== false && !prop.deserialize) ctx.error([
|
|
377
|
+
`[zeus-output-wc] <${component.tag}> prop "${name}" cannot use attr:${JSON.stringify(prop.attr)} with register:"lazy".`,
|
|
378
|
+
"Non-primitive lazy attributes require a custom deserialize function.",
|
|
379
|
+
"Add deserialize or use attr:false and pass the value as a property."
|
|
380
|
+
].join("\n"));
|
|
381
|
+
if (prop.reflect && !prop.serialize) ctx.error([
|
|
382
|
+
`[zeus-output-wc] <${component.tag}> prop "${name}" cannot use reflect:true with register:"lazy".`,
|
|
383
|
+
"Non-primitive lazy reflection requires a custom serialize function.",
|
|
384
|
+
"Add serialize or remove reflect:true."
|
|
385
|
+
].join("\n"));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
checkFileNameCollisions(ctx.manifest.components, {
|
|
389
|
+
getFileName: (tag) => {
|
|
390
|
+
if (normalized.register === "lazy") return getLazyEntryFileName(normalized.entryFileName, tag);
|
|
391
|
+
return normalizeFileName(tag, normalized.stripPrefix, normalized.fileName);
|
|
392
|
+
},
|
|
393
|
+
warnOnFileNameCollision: normalized.warnOnFileNameCollision
|
|
394
|
+
}, { warn: ctx.warn });
|
|
185
395
|
},
|
|
186
396
|
virtualModules(ctx) {
|
|
187
397
|
if (!ctx.manifest) return [];
|
|
@@ -195,7 +405,55 @@ function wc(options = {}) {
|
|
|
195
405
|
if (hasOutputs) return ctx.outputs.join("wc", fileName);
|
|
196
406
|
return path.posix.join(_outDir, fileName);
|
|
197
407
|
};
|
|
198
|
-
|
|
408
|
+
const isLazy = normalized.register === "lazy";
|
|
409
|
+
if (isLazy) {
|
|
410
|
+
modules.push({
|
|
411
|
+
id: "zeus:wc:components.manifest",
|
|
412
|
+
fileName: joinPath("components.manifest.js"),
|
|
413
|
+
code: generateLazyManifest({
|
|
414
|
+
components: ctx.manifest.components,
|
|
415
|
+
getEntryFileName: (tag) => getLazyEntryFileName(normalized.entryFileName, tag)
|
|
416
|
+
})
|
|
417
|
+
});
|
|
418
|
+
modules.push({
|
|
419
|
+
id: "zeus:wc:loader",
|
|
420
|
+
fileName: joinPath("loader.js"),
|
|
421
|
+
code: generateLoader()
|
|
422
|
+
});
|
|
423
|
+
if (normalized.auto) modules.push({
|
|
424
|
+
id: "zeus:wc:auto",
|
|
425
|
+
fileName: joinPath("auto.js"),
|
|
426
|
+
code: generateAutoEntry()
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
for (const component of ctx.manifest.components) if (isLazy) {
|
|
430
|
+
/**
|
|
431
|
+
* Registration bridge module consumed by Vue / React wrappers.
|
|
432
|
+
*
|
|
433
|
+
* It only registers lazy Proxy Elements.
|
|
434
|
+
* It does not import the real component implementation.
|
|
435
|
+
*/
|
|
436
|
+
modules.push({
|
|
437
|
+
id: getVirtualComponentId(component),
|
|
438
|
+
code: `
|
|
439
|
+
import { defineCustomElements } from "zeus:wc:loader";
|
|
440
|
+
|
|
441
|
+
defineCustomElements();
|
|
442
|
+
|
|
443
|
+
export {};
|
|
444
|
+
`.trimStart()
|
|
445
|
+
});
|
|
446
|
+
const fileName = joinPath(getLazyEntryFileName(normalized.entryFileName, component.tag));
|
|
447
|
+
modules.push({
|
|
448
|
+
id: `zeus:wc:entry:${component.tag}`,
|
|
449
|
+
fileName,
|
|
450
|
+
code: generateLazyEntry({
|
|
451
|
+
component,
|
|
452
|
+
outPath: fileName,
|
|
453
|
+
sourceImport: toAbsoluteImportPath(ctx.root, component.source)
|
|
454
|
+
})
|
|
455
|
+
});
|
|
456
|
+
} else {
|
|
199
457
|
const fileName = joinPath(getFileName(component.tag));
|
|
200
458
|
modules.push({
|
|
201
459
|
id: getVirtualComponentId(component),
|
|
@@ -206,7 +464,7 @@ function wc(options = {}) {
|
|
|
206
464
|
})
|
|
207
465
|
});
|
|
208
466
|
}
|
|
209
|
-
if (normalized.index) modules.push({
|
|
467
|
+
if (normalized.index && !isLazy) modules.push({
|
|
210
468
|
id: getVirtualIndexId(),
|
|
211
469
|
fileName: joinPath("index.js"),
|
|
212
470
|
code: generateWCIndex({
|
|
@@ -214,16 +472,18 @@ function wc(options = {}) {
|
|
|
214
472
|
getFileName
|
|
215
473
|
})
|
|
216
474
|
});
|
|
475
|
+
if (isLazy && normalized.index) modules.push({
|
|
476
|
+
id: getVirtualIndexId(),
|
|
477
|
+
fileName: joinPath("index.js"),
|
|
478
|
+
code: generateLazyIndex()
|
|
479
|
+
});
|
|
217
480
|
return modules;
|
|
218
481
|
},
|
|
219
482
|
generateBundle(ctx) {
|
|
220
483
|
if (!ctx.manifest) return [];
|
|
221
484
|
const files = [];
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
fileName: normalized.manifestFile,
|
|
225
|
-
source: generateZeusComponentsManifest(ctx.manifest)
|
|
226
|
-
});
|
|
485
|
+
const dts = resolvePluginDts(normalized.dts, ctx);
|
|
486
|
+
const jsxDts = resolvePluginDts(normalized.jsxDts, ctx);
|
|
227
487
|
const hasOutputs = ctx.outputs.has("wc");
|
|
228
488
|
const getFileName = (tag) => {
|
|
229
489
|
if (hasOutputs) return ctx.outputs.getFileName("wc", tag);
|
|
@@ -233,17 +493,41 @@ function wc(options = {}) {
|
|
|
233
493
|
if (hasOutputs) return ctx.outputs.join("wc", fileName);
|
|
234
494
|
return path.posix.join(_outDir, fileName);
|
|
235
495
|
};
|
|
496
|
+
const isLazy = normalized.register === "lazy";
|
|
497
|
+
if (isLazy) {
|
|
498
|
+
if (dts) {
|
|
499
|
+
const loaderDts = generateLoaderDts(ctx.manifest);
|
|
500
|
+
files.push({
|
|
501
|
+
type: "asset",
|
|
502
|
+
fileName: joinPath("loader.d.ts"),
|
|
503
|
+
source: loaderDts
|
|
504
|
+
});
|
|
505
|
+
if (normalized.index) files.push({
|
|
506
|
+
type: "asset",
|
|
507
|
+
fileName: joinPath("index.d.ts"),
|
|
508
|
+
source: loaderDts
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
if (jsxDts) files.push({
|
|
512
|
+
type: "asset",
|
|
513
|
+
fileName: joinPath("types/jsx.d.ts"),
|
|
514
|
+
source: generateWCJsxDts(ctx.manifest)
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
if (normalized.manifestFile) files.push({
|
|
518
|
+
type: "asset",
|
|
519
|
+
fileName: normalized.manifestFile,
|
|
520
|
+
source: generateZeusComponentsManifest(ctx.manifest)
|
|
521
|
+
});
|
|
236
522
|
if (normalized.customElementsFile) files.push({
|
|
237
523
|
type: "asset",
|
|
238
524
|
fileName: normalized.customElementsFile,
|
|
239
525
|
source: generateCustomElementsJson({
|
|
240
526
|
manifest: ctx.manifest,
|
|
241
|
-
getModulePath: (component) => joinPath(getFileName(component.tag))
|
|
527
|
+
getModulePath: (component) => isLazy ? joinPath(getLazyEntryFileName(normalized.entryFileName, component.tag)) : joinPath(getFileName(component.tag))
|
|
242
528
|
})
|
|
243
529
|
});
|
|
244
|
-
|
|
245
|
-
const jsxDts = resolvePluginDts(normalized.jsxDts, ctx);
|
|
246
|
-
if (dts || jsxDts) {
|
|
530
|
+
if (!isLazy && (dts || jsxDts)) {
|
|
247
531
|
const dtsFiles = generateWCDtsFiles(ctx.manifest, {
|
|
248
532
|
outDir: _outDir,
|
|
249
533
|
stripPrefix: normalized.stripPrefix,
|
|
@@ -272,12 +556,22 @@ function normalizeFileName(tag, stripPrefix, fileName) {
|
|
|
272
556
|
if (!name.endsWith(".js")) name = `${name}.js`;
|
|
273
557
|
return name;
|
|
274
558
|
}
|
|
559
|
+
function normalizeLazyEntryFileName(fileName) {
|
|
560
|
+
const normalized = fileName.replace(/\\/g, "/");
|
|
561
|
+
return normalized.endsWith(".js") ? normalized : `${normalized}.js`;
|
|
562
|
+
}
|
|
563
|
+
function getLazyEntryFileName(entryFileName, tag) {
|
|
564
|
+
return normalizeLazyEntryFileName(entryFileName(tag));
|
|
565
|
+
}
|
|
566
|
+
function isAttributeBackedRuntimeProp(type) {
|
|
567
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
568
|
+
}
|
|
275
569
|
function checkFileNameCollisions(components, options, reporter) {
|
|
276
570
|
if (options.warnOnFileNameCollision === false) return;
|
|
277
571
|
const map = /* @__PURE__ */ new Map();
|
|
278
572
|
for (const component of components) {
|
|
279
573
|
var _map$get;
|
|
280
|
-
const fileName =
|
|
574
|
+
const fileName = options.getFileName(component.tag);
|
|
281
575
|
const list = (_map$get = map.get(fileName)) !== null && _map$get !== void 0 ? _map$get : [];
|
|
282
576
|
list.push(component);
|
|
283
577
|
map.set(fileName, list);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeus-js/output-wc",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
4
4
|
"description": "Zeus Web Component output plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -13,24 +13,24 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/output-wc.d.ts",
|
|
16
|
+
"module": "./dist/output-wc.esm-bundler.js",
|
|
17
|
+
"import": "./dist/output-wc.esm-bundler.js",
|
|
18
|
+
"require": "./index.js",
|
|
16
19
|
"node": {
|
|
17
20
|
"production": "./dist/output-wc.cjs.prod.js",
|
|
18
21
|
"development": "./dist/output-wc.cjs.js",
|
|
19
22
|
"default": "./index.js"
|
|
20
|
-
}
|
|
21
|
-
"module": "./dist/output-wc.esm-bundler.js",
|
|
22
|
-
"import": "./dist/output-wc.esm-bundler.js",
|
|
23
|
-
"require": "./index.js"
|
|
23
|
+
}
|
|
24
24
|
},
|
|
25
25
|
"./capabilities": {
|
|
26
26
|
"types": "./dist/capabilities.d.ts",
|
|
27
|
+
"import": "./dist/capabilities.js",
|
|
28
|
+
"require": "./dist/capabilities.cjs.js",
|
|
27
29
|
"node": {
|
|
28
30
|
"production": "./dist/capabilities.cjs.prod.js",
|
|
29
31
|
"development": "./dist/capabilities.cjs.js",
|
|
30
32
|
"default": "./dist/capabilities.cjs.js"
|
|
31
|
-
}
|
|
32
|
-
"import": "./dist/capabilities.js",
|
|
33
|
-
"require": "./dist/capabilities.cjs.js"
|
|
33
|
+
}
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
@@ -52,9 +52,11 @@
|
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@zeus-js/bundler-plugin": "0.1.0-beta.
|
|
56
|
-
"@zeus-js/component-analyzer": "0.1.0-beta.
|
|
57
|
-
"@zeus-js/
|
|
55
|
+
"@zeus-js/bundler-plugin": "0.1.0-beta.4",
|
|
56
|
+
"@zeus-js/component-analyzer": "0.1.0-beta.4",
|
|
57
|
+
"@zeus-js/runtime-dom": "0.1.0-beta.4",
|
|
58
|
+
"@zeus-js/component-dts": "0.1.0-beta.4",
|
|
59
|
+
"@zeus-js/web-c-runtime": "0.2.0"
|
|
58
60
|
},
|
|
59
61
|
"peerDependencies": {
|
|
60
62
|
"rollup": "^4.0.0"
|