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

build: update _ to - in workspace converter script #4357

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 17 additions & 5 deletions _tools/convert_to_workspace.ts
Expand Up @@ -192,7 +192,7 @@ for await (const entry of walk(cwd)) {
replacedImports.push([specifier, newSpecifier]);
} else {
const newSpecifier = "@std/" +
target.replace(/(\.d)?\.ts$/, "").replace(/\/mod$/, "");
fixPackagePath(target).replace(/(\.d)?\.ts$/, "").replace(/\/mod$/, "");
replacedImports.push([specifier, newSpecifier]);
}
}
Expand All @@ -203,7 +203,7 @@ for await (const entry of walk(cwd)) {
"",
);
const newSpecifier = "@std/" +
target.replace(/(\.d)?\.ts$/, "").replace(/\/mod$/, "");
fixPackagePath(target).replace(/(\.d)?\.ts$/, "").replace(/\/mod$/, "");
replacedImports.push([specifier, newSpecifier]);
}

Expand All @@ -227,7 +227,7 @@ for (const pkg of packages) {
exports = Object.fromEntries(exportsList);
}
const denoJson = {
name: `@std/${pkg}`,
name: `@std/${fixPackageName(pkg)}`,
version: VERSION,
exports,
};
Expand All @@ -242,12 +242,24 @@ for (const pkg of packages) {
);
}

function fixPackageName(pkg: string) {
return pkg.replaceAll("_", "-");
}

function fixPackagePath(path: string) {
const packageName = /^[^/]+/.exec(path);
if (packageName) {
return path.replace(packageName[0], fixPackageName(packageName[0]));
}
return path;
}

// Generate `deno.json` file.
const denoJson = JSON.parse(await Deno.readTextFile("deno.json"));
denoJson.workspaces = orderedPackages.map((pkg) => `./${pkg}`);
for (const pkg of packages) {
denoJson.imports[`@std/${pkg}`] = `jsr:@std/${pkg}@^${VERSION}`;
denoJson.imports[`@std/${pkg}/`] = `jsr:/@std/${pkg}@^${VERSION}/`;
const fixedPkg = fixPackageName(pkg);
denoJson.imports[`@std/${fixedPkg}`] = `jsr:@std/${fixedPkg}@^${VERSION}`;
}
await Deno.writeTextFile(
"deno.json",
Expand Down