-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { parseArgs } from "jsr:@std/[email protected]/parse-args" | ||
import { parseArgs } from "jsr:@std/[email protected]/parse-args"; | ||
import { | ||
basename, | ||
extname, | ||
|
@@ -7,21 +7,19 @@ import { | |
} from "https://deno.land/[email protected]/path/mod.ts"; | ||
|
||
const argv = parseArgs( | ||
Deno.args, | ||
{ | ||
alias: { | ||
o: ["out"], | ||
}, | ||
boolean: true, | ||
string: ["out"], | ||
default: { | ||
o: "lib", | ||
}, | ||
Deno.args, | ||
{ | ||
alias: { | ||
o: ["out"], | ||
}, | ||
boolean: true, | ||
string: ["out"], | ||
default: { | ||
o: "lib", | ||
}, | ||
}, | ||
); | ||
|
||
|
||
|
||
// resolve the specified directories to fq | ||
let dirs = (argv._ as string[]).map((n) => { | ||
return resolve(n); | ||
|
@@ -51,27 +49,26 @@ if (argv.debug) { | |
|
||
if (!dirs.length || argv.h || argv.help) { | ||
console.log( | ||
`deno run --allow-all cjs-fix-imports [--debug] [--out build/] dir/ dir2/`, | ||
`deno run --allow-all cjs-fix-imports [--debug] [--out build/] dir/ dir2/`, | ||
); | ||
Deno.exit(1); | ||
} | ||
|
||
// create out if not exist | ||
await Deno.lstat(out) | ||
.catch(async () => { | ||
await Deno.mkdir(out); | ||
}); | ||
.catch(async () => { | ||
await Deno.mkdir(out); | ||
}); | ||
|
||
// process each file - remove extensions from requires/import | ||
for (const fn of files) { | ||
const data = await Deno.readFile(fn); | ||
let txt = new TextDecoder().decode(data); | ||
|
||
|
||
let mod = txt.replace(/jsr:@nats-io\/nkeys/gim, "nkeys.js"); | ||
mod = mod.replace(/jsr:@nats-io\/nuid/gim, "nuid"); | ||
mod = mod.replace(/jsr:@nats-io\/nats-core/gim, "@nats-io/nats-core") | ||
if(!fn.endsWith("nkeys.ts") && !fn.endsWith("nuid.ts")) { | ||
mod = mod.replace(/jsr:@nats-io\/nats-core/gim, "@nats-io/nats-core"); | ||
if (!fn.endsWith("nkeys.ts") && !fn.endsWith("nuid.ts")) { | ||
mod = mod.replace(/from\s+"(\S+).[t|j]s"/gim, 'from "$1"'); | ||
} | ||
|
||
|
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
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
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
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