Skip to content

Instantly share code, notes, and snippets.

@jollytoad
Created April 8, 2024 12:36
Show Gist options
  • Save jollytoad/dd93032b3d63db4529268c7445aee8fe to your computer and use it in GitHub Desktop.
Save jollytoad/dd93032b3d63db4529268c7445aee8fe to your computer and use it in GitHub Desktop.
Replace underscore with dashes in strings that look like Deno `@std` imports
import { walk } from "jsr:@std/fs@^0.221.0/walk";
export async function fixStdLibImports(root: string) {
for await (const entry of walk(root, { exts: [".ts"] })) {
const content = await Deno.readTextFile(entry.path);
const replaced = content.replaceAll(/"@std\/([^"]+)"/g, (str) => {
return str.replaceAll("_", "-");
});
if (replaced !== content) {
console.log(entry.path);
await Deno.writeTextFile(entry.path, replaced);
}
}
}
if (import.meta.main) {
await fixStdLibImports(Deno.cwd());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment