0.0.4
Proof of concept for a bridge between Deno and npm packages
Attributes
Includes Deno configuration
Repository
Current version released
3 years ago
Dependencies
std
Versions
npm_bridge
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.
Step 1: Setup
In the root of your application:
- Create a deno.json file and add a “npm” task:
{ "tasks": { "npm": "deno run -A --no-check --reload https://deno.land/x/npm_bridge/main.ts" } }
Now run these commands similarly to as you would with npm:
- Run
deno task npm init
to initialize a npm_deps.json file. - Add dependencies (ex.
deno task npm install ts-morph
,deno task npm i --save-dev mkdirp
)
Step 2: Use dependencies
- Import and use the package via a bare specifier:
// 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
Use Binary Dependencies
To use a binary dependency, create a new entry in your deno.json that references
the ./npm_deps/<package-name>.bin.js
file:
{
"tasks": {
// ...
"mkdirp": "deno run -A --unstable ./npm_deps/mkdirp.bin.js"
}
// ...
}
Now try it out:
deno task mkdirp subdir/newdir
What this does
- Runs
npm install
with the dependencies you specified. - Analyzes the
node_modules
folder and creates wrapper ESM modules around the CJS code. - Creates an import map to map bare specifiers to the wrapper ESM modules and to map import specifiers with no extensions to extensions.
- Updates or adds the import map to your deno.json file.
Subcommands
deno 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.