Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATA: node: module resolution #3191

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/plenty-deers-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@typescript/ata": patch
---

Improve `node:` module resolution
Renegade334 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion packages/ata/src/edgeCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const mapModuleNameToModule = (moduleSpecifier: string) => {
"http2",
"https",
"inspector",
"inspector/promises",
"module",
"net",
"os",
Expand Down Expand Up @@ -57,7 +58,7 @@ export const mapModuleNameToModule = (moduleSpecifier: string) => {
"zlib",
]

if (builtInNodeMods.includes(moduleSpecifier.replace("node:", ""))) {
if (moduleSpecifier.indexOf("node:") === 0 || builtInNodeMods.includes(moduleSpecifier)) {
return "node"
}

Expand Down
5 changes: 5 additions & 0 deletions packages/ata/tests/edgeCases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ describe(mapModuleNameToModule, () => {
expect(mapModuleNameToModule("node:fs")).toEqual("node")
})

it("handles mandatorily-prefixed node: identifiers", () => {
expect(mapModuleNameToModule("node:test")).toEqual("node")
expect(mapModuleNameToModule("test")).toEqual("test")
})

it("strips module filepaths", () => {
expect(mapModuleNameToModule("lodash/identity")).toEqual("lodash")
expect(mapModuleNameToModule("@org/lodash/identity")).toEqual("@org/lodash")
Expand Down