Skip to content

Commit baea1b7

Browse files
authored
fix: improve node codemod node modules resolution (#1491)
* fix(runner): improve node_modules resolution for node codemod execution * chore: Add changeset
1 parent cbbb499 commit baea1b7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.changeset/gold-geckos-tap.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@codemod-com/runner": patch
3+
"codemod": patch
4+
---
5+
6+
fix: Improve node modules resolution for node codemod symlinking step

packages/runner/src/runner.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,22 @@ export class Runner {
500500
join(codemod.path, "cdmd_dist", "index.js"),
501501
randomMjs,
502502
);
503-
const cliNodeModules = join(dirname(__dirname), "node_modules");
503+
const cliNodeModules = module.paths.find(
504+
(path) =>
505+
fs.existsSync(join(path, "@codemod.com")) &&
506+
fs.existsSync(join(path, "@codemod.com", "workflow")),
507+
);
508+
509+
if (!cliNodeModules) {
510+
throw new Error("Could not find cli node_modules");
511+
}
512+
504513
const symlinkedPackages: string[] = [];
505514
const cliNodeModulesDir = await fs.promises.readdir(cliNodeModules);
506515
const targetNodeModulesDir = join(process.cwd(), "node_modules");
507516

508517
for (const dir of cliNodeModulesDir) {
509-
if (fs.existsSync(join(targetNodeModulesDir, dir)) || dir === ".bin") {
518+
if (fs.existsSync(join(targetNodeModulesDir, dir))) {
510519
continue;
511520
}
512521

0 commit comments

Comments
 (0)