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

Use native Node.js functions when available #12458

Merged

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Dec 8, 2020

Q                       A
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This is the same as #12439 but for fs.mkdirSync(path, { recursive: true }) and for process.allowedNodeEnvironmentFlags: we use the native implementation when available, and fallback to the polyfill when it's not.

This allows us to more easily prepare a Babel 8 prerelease, in the spirit of #12440, by simply toggling the BABEL_8_BREAKING env variable.

  • fs.mkdirSync(filepath, { recursive: true }) is polyfilled at build time as parseFloat(process.versions.node) >= 10.12 ? fs.mkdirSync : require("make-dir").sync (we can't easily feature-check because we need to polyfill the recursive option)
  • process.allowedNodeEnvironmentFlags is polyfilled as process.allowedNodeEnvironmentFlags || require("node-environment-flags").

Note that during local development those polyfills aren't injected since they aren't needed, but we are testing them on CI (with Node.js 6 and 8).

@nicolo-ribaudo nicolo-ribaudo added PR: Internal 🏠 A type of pull request used for our changelog categories babel-8-dev → main labels Dec 8, 2020
},
// require.resolve's paths option has been introduced in Node.js 8.9
// https://nodejs.org/api/modules.html#modules_require_resolve_request_options
replacement: template({ syntacticPlaceholders: true })`
Copy link
Member Author

Choose a reason for hiding this comment

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

This polyfill was already there, I only moved it.

@babel-bot
Copy link
Collaborator

babel-bot commented Dec 8, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/34336/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 8, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ffe2c04:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo
Copy link
Member Author

I opened this PR because I already had it ready, but if you don't think that the added co.plexoty in babel.config.js file is worth it (I'm not 100% sure) I am ok with closing this.

Copy link
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

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

so this doesn't remove the dep, just makes a plugin that toggles on or off the require to the dep based on node version - sounds fine since we will remove in v8 - and CI test should cover it? assuming that this shouldn't break anything in a patch

@nicolo-ribaudo
Copy link
Member Author

Exactly, we are testing both the behaviors: on Node.js > 10 we test the new built-in functions, while the old functions are tested on Node.js 6 and 8.

The dependency is still there (because of the polyfill), but this PR makes it so that we will only have to update package.json for Babel 8 and not the actual code.

@nicolo-ribaudo nicolo-ribaudo merged commit 98aa72c into babel:main Dec 8, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the backport-remove-node-polyfills branch December 8, 2020 23:03
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2021
@nicolo-ribaudo nicolo-ribaudo added this to the v8.0.0 milestone Aug 8, 2023
@JLHwung JLHwung added PR: Internal (next major) 🏠 A type of pull request used for our changelog categories for next major release and removed PR: Internal 🏠 A type of pull request used for our changelog categories babel 8 labels Aug 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal (next major) 🏠 A type of pull request used for our changelog categories for next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants