Skip to content

Commit

Permalink
fix: use hyphens for JSR package exports (#4424)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Mar 19, 2024
1 parent e99375a commit e749d4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
23 changes: 9 additions & 14 deletions _tools/convert_to_workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,16 @@ for (const { specifier, dependencies } of graph.modules) {
const fromPkg = from.split("/")[0]!;
for (const dep of dependencies ?? []) {
if (dep.code) {
const to = relative(cwd, fromFileUrl(dep.code.specifier)).replaceAll(
"\\",
"/",
);
const to = relative(cwd, fromFileUrl(dep.code.specifier))
.replaceAll("\\", "/");
const toPkg = to.split("/")[0]!;
if (fromPkg !== toPkg) {
pkgDeps.get(fromPkg)!.add(toPkg);
}
}
if (dep.types) {
const to = relative(cwd, fromFileUrl(dep.types.specifier)).replaceAll(
"\\",
"/",
);
const to = relative(cwd, fromFileUrl(dep.types.specifier))
.replaceAll("\\", "/");
const toPkg = to.split("/")[0]!;
if (fromPkg !== toPkg) {
pkgDeps.get(fromPkg)!.add(toPkg);
Expand Down Expand Up @@ -182,10 +178,8 @@ for await (const entry of walk(cwd)) {
const target = relative(cwd, path).replaceAll("\\", "/");
const pkg = target.split("/")[0];
if (pkg === currentPkg) {
let newSpecifier = relative(dirname(entry.path), target).replaceAll(
"\\",
"/",
);
let newSpecifier = relative(dirname(entry.path), target)
.replaceAll("\\", "/");
if (!newSpecifier.startsWith(".")) {
newSpecifier = "./" + newSpecifier;
}
Expand Down Expand Up @@ -249,9 +243,10 @@ function fixPackageName(pkg: string) {
function fixPackagePath(path: string) {
const packageName = /^[^/]+/.exec(path);
if (packageName) {
return path.replace(packageName[0], fixPackageName(packageName[0]));
return path.replace(packageName[0], fixPackageName(packageName[0]))
.replaceAll("_", "-");
}
return path;
return path.replaceAll("_", "-");
}

// Generate `deno.json` file.
Expand Down
2 changes: 1 addition & 1 deletion _tools/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function discoverExports(pkg: string) {
if (name.includes("/testdata/")) continue; // testdata files
if (name.endsWith("/deno.json")) continue; // deno.json files

const key = "." + name.replace(/\/mod$/, "");
const key = "." + name.replace(/\/mod$/, "").replaceAll("_", "-");
exports.push([key, "." + path]);
}
exports.sort((a, b) => a[0].localeCompare(b[0]));
Expand Down

0 comments on commit e749d4e

Please sign in to comment.