nodedeno
Script to convert Node libraries to Deno
- Transform CJS to ESM
- Transform TypeScript to JavaScript
- Any dependency is replaced with
./deps.js - Replace some Node global object like
process.envor__dirnameto Deno equivalents
Example:
const dep = require("my-dependency");
const otherModule = require("./other-module");
module.exports = function foo() {};
module.exports.otherModule = function bar() {};Is converted to:
import { dep } from "./deps.js";
import otherModule from "./other-module.js";
export default function foo() {};
export const otherModule = function bar() {};Usage:
import { convert } from "https://deno.land/x/nodedeno/mod.js"
convert({
from: "node-library/lib",
to: "deno-library/lib",
depsFile: "deps.js",
ignoredFiles: [
"ignored-file-1.js",
"ignored-file-2.js",
],
modules: {
"module-name": "./new-module.js"
},
onConvert(file, code) {
// Here you can make additional changes to the code or filename
return [file, code];
}
})Options
fromThe directory of the source filestoThe destination of the converted filesdepsFileThe dependencies file that will be copied in the destination folder (and renamed todeps.jsignoredFilesAn array of files that won’t be copiedonConvertA callback that will be invoked for every file copied. It allows to make additional changesmodulesAn object to customize some modules resolution.transpileSettrueto convert TypeScript files to Javascript.