Implement checked workspace integration contracts (WI-01)
This commit is contained in:
@@ -1333,9 +1333,25 @@ const lowerPackage = (
|
||||
}),
|
||||
);
|
||||
const genericExports: GenericPackageExport[] = [];
|
||||
const components: NonNullable<PackageRevision["components"]> = [];
|
||||
const queries: QueryDeclaration[] = [];
|
||||
const queryTemplates: QueryTemplate[] = [];
|
||||
const exports = context.packageExport().flatMap((exportContext): PackageExport[] => {
|
||||
const component = exportContext.componentDecl();
|
||||
if (component) {
|
||||
const runtime = identifier(component.identifier(1));
|
||||
if (runtime !== "react")
|
||||
loweringIssue(state, component, "unsupported-component-runtime", `Unsupported component runtime ${runtime}`);
|
||||
components.push({
|
||||
id: stringValue(component.stringLiteral()),
|
||||
displayName: identifier(component.identifier(0)),
|
||||
subject: new TypeSubstitution(state.types.environment()).application(
|
||||
state.types.interface(component.interfaceType()),
|
||||
),
|
||||
runtime: "react",
|
||||
});
|
||||
return [];
|
||||
}
|
||||
if (exportContext.packageQuerySpecialization()) return [];
|
||||
const query = exportContext.packageQuery();
|
||||
if (query) {
|
||||
@@ -1595,6 +1611,7 @@ const lowerPackage = (
|
||||
displayName: alias,
|
||||
source,
|
||||
exports,
|
||||
...(components.length ? { components } : {}),
|
||||
...(queries.length ? { queries } : {}),
|
||||
...(queryTemplates.length ? { queryTemplates } : {}),
|
||||
...(queries.some((query) => query.argumentRequirements?.length)
|
||||
@@ -2397,6 +2414,30 @@ const lowerWorkspace = (
|
||||
: [];
|
||||
});
|
||||
|
||||
const presentations: NonNullable<WorkspaceRevision["presentations"]> = items.flatMap((item) => {
|
||||
const presentation = item.presentationDecl();
|
||||
if (!presentation) return [];
|
||||
const packageName = identifier(presentation.identifier(1));
|
||||
const componentName = identifier(presentation.identifier(2));
|
||||
const pkg = requireSymbol(state, state.packages, packageName, presentation, "package");
|
||||
const component = pkg?.definition?.components?.find((entry) => entry.displayName === componentName);
|
||||
if (!component) {
|
||||
loweringIssue(state, presentation, "unknown-component", `Unknown component ${packageName}.${componentName}`);
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: stringValue(presentation.stringLiteral()),
|
||||
displayName: identifier(presentation.identifier(0)),
|
||||
subject: new TypeSubstitution(state.types.environment()).application(
|
||||
state.types.interface(presentation.interfaceType()),
|
||||
),
|
||||
packageRevisionId: pkg!.revisionId,
|
||||
componentId: component.id,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
return {
|
||||
imports,
|
||||
workspace: {
|
||||
@@ -2417,6 +2458,7 @@ const lowerWorkspace = (
|
||||
),
|
||||
conformances,
|
||||
constructors,
|
||||
...(presentations.length ? { presentations } : {}),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user