Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making Node.js code compatible with Deno #2

Open
egoist opened this issue Apr 23, 2019 · 9 comments
Open

Making Node.js code compatible with Deno #2

egoist opened this issue Apr 23, 2019 · 9 comments
Labels
open-source-library Feel free to work on it unless someone else has claimed it up-for-grabs Available for those who are interested, make it happen!

Comments

@egoist
Copy link
Owner

egoist commented Apr 23, 2019

Problem

There are many great Node.js libraries that are also useful in Deno ecosystem, it would be a waste of time to reinvent the wheels from scratch for Deno.

Solution

Creating a compiler, probably on top of webpack, to generate Deno-compatible code from Node.js code.

// index.js
const chalk = require('chalk')
module.exports = chalk
denoify ./index.js -o ./dist/index.js
deno dist/index.js # it works

👍 If you like this idea

@egoist egoist added the open-source-library Feel free to work on it unless someone else has claimed it label Apr 23, 2019
@zzz6519003
Copy link

their difference in appearance?

@motss
Copy link

motss commented Apr 23, 2019

How about those rely on Node's core API?

@egoist
Copy link
Owner Author

egoist commented Apr 23, 2019

@motss via polyfills, path url and some other core modules can be shimmed easily. Deno may not have all the APIs that we have in Node.js, we can try to support as many as possible.

@aalemayhu
Copy link

Sounds interesting. Considering that Deno has a different security model would the compiler or whatever is generating the code be aware of this? Or are you thinking of making the generated code "less secure" by being permissive (--allow-all)? Just curious if you have thought about it.

@egoist
Copy link
Owner Author

egoist commented Apr 23, 2019

@scanf The generated code should work the same as normal Deno code, Deno will only ask for permissions when needed.

@egoist egoist added the up-for-grabs Available for those who are interested, make it happen! label Apr 23, 2019
@motss
Copy link

motss commented Apr 23, 2019

How about working with the package author to support Deno?

@egoist
Copy link
Owner Author

egoist commented Apr 23, 2019

@motss that's like working with the package author to support TypeScript 😂which won't work since not everyone has the time / interest in doing so.

@vladimyr
Copy link

denoify ./index.js -o ./dist/index.js
deno dist/index.js # it works

Which is more or less same as:

npx webrunify ./index.js > ./dist/index.js
deno dist/index.js

Where webrunify is bundler made on top of browserify that produces ES module bundles in rollup like fashion: https://github.com/brechtcs/webrunify

However, bundling stuff together is an easy part. Next wall you'll gonna hit is unfortunate fact that your compiler can't produce bundles that are guaranteed to pass typescript's type checking. That is important because deno forces type checking of js files (aka your resulting bundle): https://github.com/denoland/deno/blob/9dfebbc/js/compiler.ts#L162 (docs)

So you essentially need to prepend your bundle with // @ts-nocheck pragma 😩

@vladimyr
Copy link

There is also webpack powered PoC: https://github.com/reggi/node-to-deno

Also let me point you to two related deno issues/discussions:

Discussion: Use of NPM modules within deno
denoland/deno#1397

No typing check for js files
denoland/deno#1432

But I'm just a reader who did few local tests, @reggi knows all nasty details and what is needed here is his expertise :neckbeard:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-library Feel free to work on it unless someone else has claimed it up-for-grabs Available for those who are interested, make it happen!
Projects
None yet
Development

No branches or pull requests

5 participants