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

feat: additive global context for npm packages (first pass) #1

Open
wants to merge 15 commits into
base: branch_v4.8.3
Choose a base branch
from
Prev Previous commit
Support npm package references with leading /
  • Loading branch information
dsherret committed Nov 22, 2022
commit d56d1e156a3055dec315e5bc8a33df96b572d4d3
8 changes: 6 additions & 2 deletions src/compiler/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace ts.deno {
if (!text.startsWith("npm:")) {
throw new Error(`Not an npm specifier: ${text}`);
}
text = text.replace(/^npm:/, "");
text = text.replace(/^npm:\/?/, "");
const parts = text.split("/");
const namePartLen = text.startsWith("@") ? 2 : 1;
if (parts.length < namePartLen) {
Expand All @@ -207,8 +207,12 @@ namespace ts.deno {
versionReq = lastNamePart.substring(lastAtIndex + 1);
nameParts[nameParts.length - 1] = lastNamePart.substring(0, lastAtIndex);
}
const name = nameParts.join("/");
if (name.length === 0) {
throw new Error(`Npm specifier did not have a name: ${text}`);
}
return {
name: nameParts.join("/"),
name,
versionReq,
subPath: parts.length > nameParts.length ? parts.slice(nameParts.length).join("/") : undefined,
};
Expand Down