Pre Release New Changes
This commit is contained in:
@@ -54,7 +54,7 @@ function words(name) {
|
||||
return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase();
|
||||
}
|
||||
|
||||
const components = readdirSync(componentsDir)
|
||||
const sourceEntries = readdirSync(componentsDir)
|
||||
.filter((file) => file.endsWith(".wrn"))
|
||||
.map((file) => {
|
||||
const source = readFileSync(join(componentsDir, file), "utf8");
|
||||
@@ -62,22 +62,35 @@ const components = readdirSync(componentsDir)
|
||||
if (!declaration) {
|
||||
throw new Error(`UI component source does not declare a component: ${file}`);
|
||||
}
|
||||
const name = declaration[1];
|
||||
return { file, source, name: declaration[1] };
|
||||
});
|
||||
|
||||
// Windows checkouts can temporarily contain legacy lowercase files beside the
|
||||
// canonical component source. Generate one public contract per declaration and
|
||||
// prefer the exact <ComponentName>.wrn filename when both exist.
|
||||
const sourceByName = new Map();
|
||||
for (const candidate of sourceEntries) {
|
||||
const current = sourceByName.get(candidate.name);
|
||||
const candidateCanonical = candidate.file === `${candidate.name}.wrn`;
|
||||
const currentCanonical = current?.file === `${candidate.name}.wrn`;
|
||||
if (!current || (candidateCanonical && !currentCanonical)) {
|
||||
sourceByName.set(candidate.name, candidate);
|
||||
}
|
||||
}
|
||||
|
||||
const components = [...sourceByName.values()]
|
||||
.map(({ file, source, name }) => {
|
||||
const entry = metadata.get(name);
|
||||
const slots = [...source.matchAll(/<slot(?:\s+name="([^"]+)")?/g)].map(
|
||||
(match) => match[1] ?? "default",
|
||||
);
|
||||
const declaredEvents = [
|
||||
const events = [
|
||||
...new Set(
|
||||
[...source.matchAll(/@event\s+([A-Za-z][A-Za-z0-9_]*)\s*=\s*function/g)].map(
|
||||
(match) => match[1],
|
||||
),
|
||||
),
|
||||
];
|
||||
// Only `@event` declarations form the public component contract. Native
|
||||
// handlers in a component's implementation are private wiring and must not
|
||||
// leak into the generated consumer-facing reference.
|
||||
const events = declaredEvents;
|
||||
return {
|
||||
name,
|
||||
mount: name,
|
||||
|
||||
Reference in New Issue
Block a user