Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/solid-layouts-oxc/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function resolvePublicPackageEntry(root, module, subpath = ".") {
);
}

function validateComponent(module, packageRoot, name, component) {
function validateComponent(module, packageRoot, name, component, solid) {
if (component?.kind === "embedded") return;
if (component?.kind !== "generated") {
throw new Error(`${module}: component ${name} has unsupported manifest kind ${JSON.stringify(component?.kind)}`);
Expand Down Expand Up @@ -214,7 +214,19 @@ function validateComponent(module, packageRoot, name, component) {
}
}

if (!entrySource.includes(APPLICATION_BOUNDARY)) {
/*
* The boundary this major actually emits, not the 1.9 one.
*
* `boundaryFor()` already encodes the mapping and the library generator uses
* it, so a `solid: 2` build writes `solid-layouts/solid-2/application-boundary`
* into the entry. Checking for the hardcoded 1.9 spelling made the pairing we
* generate the pairing we reject: the entry is correct and validation fails on
* output this package just produced.
*
* `includes` on the Solid 2 specifier is not satisfied by the 1.9 one either
* way round, because neither string contains the other as written.
*/
if (!entrySource.includes(boundaryFor(solid).specifier)) {
throw new Error(`${module}: ${name} entry has no application compiler boundary`);
}
if (!new RegExp(`\\bexport\\s+const\\s+${component.recipeExport}\\b`).test(recipeSource)) {
Expand All @@ -229,7 +241,7 @@ function validateComponent(module, packageRoot, name, component) {
}
}

function resolveLayoutSource(root, configured) {
function resolveLayoutSource(root, configured, solid) {
const module = typeof configured === "string" ? configured : configured.module;
if (!module) throw new Error("configured Layout source is missing its module name");
const packageRoot = typeof configured === "string"
Expand Down Expand Up @@ -271,7 +283,7 @@ function resolveLayoutSource(root, configured) {
}
const exports = Object.keys(components).sort();
if (exports.length === 0) throw new Error(`${module} Layout manifest has no components`);
for (const name of exports) validateComponent(module, packageRoot, name, components[name]);
for (const name of exports) validateComponent(module, packageRoot, name, components[name], solid);

return {
module,
Expand All @@ -291,7 +303,7 @@ function compileApplication(options = {}) {
if (!Array.isArray(layouts) || layouts.length === 0) {
throw new Error("application compiler requires at least one Layout package");
}
const sources = layouts.map((configured) => resolveLayoutSource(root, configured));
const sources = layouts.map((configured) => resolveLayoutSource(root, configured, options.solid));
const rootSources = sources.map(({ module, exports, publicEntry }) => ({
module,
exports,
Expand Down
31 changes: 31 additions & 0 deletions packages/solid-layouts-oxc/application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,34 @@ test("rejects a generated entry that disagrees with its component record", () =>
"entry call site disagrees",
);
});

/*
* The boundary check has to follow the major being compiled.
*
* `boundaryFor()` already maps 1 and 2 to different specifiers, and the library
* generator uses it, so a `solid: 2` library writes the solid-2 spelling into
* its entry. Validation greping for the hardcoded 1.9 spelling made the pairing
* this package generates the pairing it rejects: a correct Solid 2 bundle failed
* with "entry has no application compiler boundary", naming a file that was
* exactly right.
*/
test("accepts a solid-2 entry when compiling for Solid 2", () => {
const { root, packageRoot } = fixture();
const copy = makePackageEditable(root, packageRoot);
const entryPath = join(copy, "index.ts");
const entry = readFileSync(entryPath, "utf8").replaceAll(
"solid-layouts/application-boundary",
"solid-layouts/solid-2/application-boundary",
);
writeFileSync(entryPath, entry);
expect(() =>
compileApplication({ root, layouts: ["@pathscale/test-ui"], solid: 2 }),
).not.toThrow();
});

test("rejects a 1.9 entry when compiling for Solid 2", () => {
const { root, packageRoot } = fixture();
expect(() => compileApplication({ root, layouts: ["@pathscale/test-ui"], solid: 2 })).toThrow(
"entry has no application compiler boundary",
);
});
Loading