Created
April 8, 2024 12:36
-
-
Save jollytoad/dd93032b3d63db4529268c7445aee8fe to your computer and use it in GitHub Desktop.
Replace underscore with dashes in strings that look like Deno `@std` imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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