Skip to content

Commit c240ff7

Browse files
committed
fix layer analyzer not finding CLI script when installed as package
1 parent 790b204 commit c240ff7

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"type": "module",
2323
"files": [
2424
"dist",
25-
"bin"
25+
"bin",
26+
"src/layerResolverCli.ts",
27+
"src/layerResolverCore.ts"
2628
],
2729
"bin": {
2830
"effect-devtools": "./bin/effect-devtools"

src/layerAnalysis.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ export const runLayerAnalysis = (projectPath: string = process.cwd()) =>
7373
console.log(`Running layer analysis on ${tsconfigPath}`);
7474

7575
// Get the path to layerResolverCli.ts
76-
const cliPath = path.resolve(__dirname, "./layerResolverCli.ts");
76+
// When running from source: __dirname is src/
77+
// When running from npm package: files are at package-root/src/
78+
// We try multiple locations to handle both cases
79+
const cliPath = yield* findCliPath();
7780

7881
// Use Bun.spawn to run the analyzer with the same bun executable
7982
// Use process.execPath to get the path to the current bun executable
@@ -341,3 +344,36 @@ const findTsConfig = (startPath: string) =>
341344

342345
return null;
343346
});
347+
348+
/**
349+
* Find the layerResolverCli.ts script
350+
* Searches multiple locations to handle both development and installed package scenarios
351+
*/
352+
const findCliPath = () =>
353+
Effect.gen(function* () {
354+
const candidates = [
355+
// Development: running from src directory
356+
path.resolve(__dirname, "./layerResolverCli.ts"),
357+
// npm package: files included at package-root/src/
358+
path.resolve(__dirname, "../src/layerResolverCli.ts"),
359+
// Compiled binary: look relative to executable
360+
path.resolve(path.dirname(process.execPath), "../src/layerResolverCli.ts"),
361+
path.resolve(path.dirname(process.execPath), "../../src/layerResolverCli.ts"),
362+
];
363+
364+
for (const candidate of candidates) {
365+
const exists = yield* Effect.tryPromise({
366+
try: () => fs.access(candidate).then(() => true),
367+
catch: () => false,
368+
});
369+
370+
if (exists) {
371+
console.log(`Found layerResolverCli.ts at ${candidate}`);
372+
return candidate;
373+
}
374+
}
375+
376+
// Fallback to first candidate and let it fail with a clear error
377+
console.log(`layerResolverCli.ts not found in any of: ${candidates.join(", ")}`);
378+
return candidates[0];
379+
});

0 commit comments

Comments
 (0)