Skip to content

Commit a874252

Browse files
committed
fix: preserve package-less Nx mapping
Match the existing bounded project.json discovery scope when deciding whether Node-family mappers are needed.
1 parent a73fd32 commit a874252

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/mapper.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17263,6 +17263,22 @@ EndProject
1726317263
expect(result.features.map((feature) => feature.title)).toContain("Node source apps/web/src");
1726417264
});
1726517265

17266+
it("preserves package-less Nx projects outside conventional roots", async () => {
17267+
const root = await fixtureRoot("clawpatch-map-package-less-nx-");
17268+
await writeFixture(
17269+
root,
17270+
"tools/cli/project.json",
17271+
JSON.stringify({ name: "cli", sourceRoot: "tools/cli/src" }),
17272+
);
17273+
await writeFixture(root, "tools/cli/src/index.ts", "export function main() {}\n");
17274+
17275+
const project = await detectProject(root);
17276+
const result = await mapFeatures(root, project, []);
17277+
17278+
expect(project.detected.languages).not.toContain("typescript");
17279+
expect(result.features.map((feature) => feature.title)).toContain("Node source tools/cli/src");
17280+
});
17281+
1726617282
it("propagates Turbo failures and retries with a fresh mapping context", async () => {
1726717283
const root = await fixtureRoot("clawpatch-map-turbo-failure-");
1726817284
await writeFixture(root, "package.json", JSON.stringify({ name: "node-app" }));

src/mappers/projects.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export async function discoverNodeProjects(root: string): Promise<NodeProjectInf
127127
}
128128

129129
export async function hasFallbackNodeProjectSignal(root: string): Promise<boolean> {
130-
if (await pathExists(join(root, "nx.json"))) {
130+
if ((await pathExists(join(root, "nx.json"))) || (await hasNestedNxProject(root, "", 5))) {
131131
return true;
132132
}
133133
for (const prefix of ["apps", "packages", "frontend", "client", "web"]) {
@@ -153,6 +153,26 @@ export async function hasFallbackNodeProjectSignal(root: string): Promise<boolea
153153
return false;
154154
}
155155

156+
async function hasNestedNxProject(
157+
root: string,
158+
prefix: string,
159+
remainingDepth: number,
160+
): Promise<boolean> {
161+
if (remainingDepth < 0 || shouldSkipProjectDir(prefix)) {
162+
return false;
163+
}
164+
if (prefix.length > 0 && (await pathExists(join(root, prefix, "project.json")))) {
165+
return true;
166+
}
167+
for (const entry of await safeDirectoryEntries(root, prefix)) {
168+
const child = prefix.length === 0 ? entry : `${prefix}/${entry}`;
169+
if (await hasNestedNxProject(root, child, remainingDepth - 1)) {
170+
return true;
171+
}
172+
}
173+
return false;
174+
}
175+
156176
async function hasNestedPackageJson(
157177
root: string,
158178
prefix: string,

0 commit comments

Comments
 (0)