Proof of concept for a bridge between Deno and npm packages
MIT License
This is a proof of concept I threw together in a few hours. DO NOT USE THIS AS IT LIKELY WON'T WORK. I haven't implemented a lot.
Proof of concept for a bridge between Deno and npm packages.
Works similarly to using npm in Node.
In the root of your application, create a deno.json file and add a npm
& npx
task:
{
"tasks": {
"npm": "deno run -A --no-check https://deno.land/x/npm_bridge@{VERSION}/npm.ts",
"npx": "deno run -A --no-check https://deno.land/x/npm_bridge@{VERSION}/npx.ts"
}
}
Now run these commands similarly to as you would with npm:
deno task npm init
- Initialize a npm_deps.json file (similar todeno task npm install <package-name>
- Add a dependency.
deno task npm i <package-name>
deno task npm i --save-dev <package-name>
Import and use the package via a bare specifier.
For example, if we did deno task npm i ts-morph
above:
// main.ts
import { Project } from "ts-morph";
const project = new Project();
const sourceFile = project.createSourceFile("test.ts", "class MyClass {}");
console.log(sourceFile.getClassOrThrow("MyClass").getName());
Run it:
deno run --allow-read --allow-env --unstable main.ts
To use a binary dependency, run deno task npx <binary-name>
.
For example:
deno task npx --allow-write=. mkdirp subdir/newdir
You may wish to alias these in another deno task.
npm install
with the dependencies you specified.node_modules
folder and creates wrapper ESM modules around thedeno task npm init
Initializes a npm_deps.json file.
deno task npm install
Installs the packages specified in npm_deps.json into a npm_deps folder.
deno task npm install <package-name>
Adds a package to the npm_deps.json dependencies
and installs it.
deno task npm install --save-dev <package-name>
Adds a package to the npm_deps.json devDependencies
and installs it.
deno task npx <...deno-args> <sub-command> <...sub-command-args>
For running a sub command.