Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/compiler"
---

Fix module resolution issue for self type module
7 changes: 2 additions & 5 deletions packages/compiler/src/module-resolver/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,8 @@ export async function resolveModule(
const pkgFile = resolvePath(dir, "package.json");
if (!(await isFile(host, pkgFile))) continue;
const pkg = await readPackage(host, pkgFile);
if (pkg.name === name) {
return loadPackage(dir, pkg);
} else {
return undefined;
}
if (pkg.name !== name) continue;
return loadPackage(dir, pkg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way it is done now is the correct way according the the node resolution spec, you only lookup to the first parent package.json for resolving self. What is the use case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case happened in our cadl-ranch test where during generation our emitter dist code is in the same folder with tsp code and emitter is not released yet.

}
return undefined;
}
Expand Down