diff --git a/build-components.mjs b/build-components.mjs index ae30074..193e5ac 100644 --- a/build-components.mjs +++ b/build-components.mjs @@ -3,6 +3,7 @@ import fs from "node:fs/promises"; import path from "node:path"; import { createHash } from "node:crypto"; import { execFileSync } from "node:child_process"; +import { pathToFileURL } from "node:url"; const digest = (bytes) => createHash("sha256").update(bytes).digest("hex"); export async function buildComponents({ config, compiler, plan, pkg, output, recordFile, generated }) { const settings = config.components; @@ -158,6 +159,9 @@ export async function buildComponents({ config, compiler, plan, pkg, output, rec `\nexport {};\ndeclare module ${JSON.stringify("./" + bindingPath.replace(/\.ts$/, ".js"))} { interface ModuleProps {${propsMembers.join("\n")}} }\n`, ); const components = []; + const { checkControls } = await import(pathToFileURL(path.join(settings.sdk, "lint-controls.mjs"))); + const { default: ts } = await import(pathToFileURL(path.resolve(path.dirname(config.tsc), "../lib/typescript.js"))); + const checkedControls = new Set(); for (const [id, entry] of entries) { const declaration = declarations.find((component) => component.id === id), source = compiler.artifactPath(entry.entry); @@ -225,6 +229,12 @@ export async function buildComponents({ config, compiler, plan, pkg, output, rec ); const meta = JSON.parse(await fs.readFile(metadata, "utf8")), outputs = Object.entries(meta.outputs); + for (const file of Object.keys(meta.inputs)) { + if (!/\.[cm]?[jt]sx?$/.test(file) || file.includes("node_modules/") || checkedControls.has(file)) continue; + checkedControls.add(file); + const errors = checkControls(ts, await fs.readFile(path.resolve(work, file), "utf8"), file); + if (errors.length) throw Error(errors.join("\n")); + } const main = outputs.find(([file]) => file.endsWith("/module.mjs"))?.[1]; if (!main?.exports.includes(entry.export)) throw Error("Component bundle lacks declared export"); if (