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.env
or__dirname
to 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://raw.githubusercontent.com/oscarotero/nodedeno/main/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
from
The directory of the source filesto
The destination of the converted filesdepsFile
The dependencies file that will be copied in the destination folder (and renamed todeps.js
ignoredFiles
An array of files that won’t be copiedonConvert
A callback that will be invoked for every file copied. It allows to make additional changesmodules
An object to customize some modules resolution.transpile
Settrue
to convert TypeScript files to Javascript.