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

feat(node): provide node compatible timer APIs in commonjs wrapper #1834

Merged
merged 3 commits into from Jan 19, 2022

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Jan 19, 2022

This PR provides node-compatible timer APIs in commonJS wrapper function. This works around the error TypeError: this.peakMemoryInterval.unref is not a function while executing yarn in node compatible mode. ref: https://github.com/yarnpkg/yarn/blob/3119382885ea373d3c13d6a846de743eca8c914b/src/reporters/base-reporter.js#L169

part of denoland/deno#13420

"(function (exports, require, module, __filename, __dirname) { ",
// We provide non standard timer APIs in the CommonJS wrapper
// to avoid exposing them in global namespace.
"(function (exports, require, module, __filename, __dirname, setTimeout, clearTimeout, setInterval, clearInterval) { ",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this doesn't break any third-party code...

aside: in the future we should use v8::script_compiler::compile_function_in_context() but that's not currently exposed by deno.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll handle that when rewriting all of this in Rust

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an improvement but that would still make packages using ESM modules that use global APIs break. However since I don't know of any packages that use ESM and depend on globals let's just merge it.

@kt3k kt3k merged commit 62e3b5b into denoland:main Jan 19, 2022
@kt3k kt3k deleted the feat/provider-timers-in-commonjs-wrapper branch January 19, 2022 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants