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

std/node: add some Node.js polyfill to require() #3382

Merged
merged 3 commits into from Nov 19, 2019

Conversation

@kevinkassimo
Copy link
Contributor

kevinkassimo commented Nov 19, 2019

Added fs, util, path polyfills for require. Future polyfills could be added in the similar way.

Also added global.ts that sets window.global = window

}
nativeModulePolyfill.set("fs", createNativeModule("fs", nodeFS));
nativeModulePolyfill.set("util", createNativeModule("util", nodeUtil));
nativeModulePolyfill.set("path", createNativeModule("path", nodePath));

This comment has been minimized.

Copy link
@ry

ry Nov 19, 2019

Collaborator

Can you add some documentation of this either to std/node/README.md or the jsdoc for makeRequire ?

This comment has been minimized.

Copy link
@kevinkassimo

kevinkassimo Nov 19, 2019

Author Contributor

Added. Also renamed makeRequire -> createRequire and require.ts -> module.ts. This aligns with https://nodejs.org/dist/latest-v13.x/docs/api/modules.html#modules_module_createrequire_filename better.

@@ -19,6 +19,12 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE

This comment has been minimized.

Copy link
@ry

ry Nov 19, 2019

Collaborator

I think calling this require.ts is better. In this context, the name "require", for me, conjures immediately the notion of Node's require; whereas "module" is much more ambiguous and has a more ES-Modules vibe to it (which is not what we want to connote)

This comment has been minimized.

Copy link
@kevinkassimo

kevinkassimo Nov 19, 2019

Author Contributor

Hmm but on the other hand do we want to expose other stuff from this module that are available from Node's module built-in module?

Since std/node is intended for Node.js compatibility, IMO it might be better to comply...

This comment has been minimized.

Copy link
@ry

ry Nov 19, 2019

Collaborator

ah, right. make sense.

*
* @param filename path or URL to current module
* @return Require function to import CJS modules
*/

This comment has been minimized.

Copy link
@ry

ry Nov 19, 2019

Collaborator

👍

@ry
ry approved these changes Nov 19, 2019
Copy link
Collaborator

ry left a comment

LGTM

@ry ry merged commit 6708fcc into denoland:master Nov 19, 2019
7 checks passed
7 checks passed
test macOS-latest
Details
test windows-2019
Details
test ubuntu-16.04
Details
test_debug ubuntu-16.04
Details
bench ubuntu-16.04
Details
lint ubuntu-16.04
Details
license/cla Contributor License Agreement is signed.
Details
@kevinkassimo kevinkassimo mentioned this pull request Nov 25, 2019
2 of 18 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.