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

fix(exports): node 13.0-13.6 require a string fallback #6

Merged
merged 1 commit into from Oct 13, 2020
Merged

fix(exports): node 13.0-13.6 require a string fallback #6

merged 1 commit into from Oct 13, 2020

Conversation

ljharb
Copy link
Contributor

@ljharb ljharb commented Oct 11, 2020

package.json’s "engines" field claims cliui supports node >= 6; node v13.0-v13.6 are included in this semver range. This change is required to be able to require() from escalade successfully in these versions.

See yargs/yargs#1776

I've manually tested this; it fixes the bug. Since the behavior can only be observed by installing escalade into a node_modules folder and then trying to require it, it's exceedingly difficult to test in CI.

package.json’s "engines" field claims cliui supports node >= 6; node v13.0-v13.6 are included in this semver range. This change is required to be able to require() from escalade successfully in these versions.

See yargs/yargs#1776
@codecov-io
Copy link

Codecov Report

Merging #6 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master        #6   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines           20        20           
=========================================
  Hits            20        20           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7174879...dc59bd0. Read the comment docs.

Copy link
Owner

@lukeed lukeed left a comment

Choose a reason for hiding this comment

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

Hey,

I checked out the imports locally. TIL!

However, why is it pointing to the CommonJS files? In Node 13.0-13.6, export is supported.
I know this means require wouldn't work, but still. Sending the CommonJS file would make something like a kleur/colors module (with named exports only) fail; for example:

// Node 13.4, with this PR's approach
import * as colors from 'kleur/colors';
//=> { default: { red, blue, ... } }

import { red } from 'kleur/colors';
// SyntaxError: The requested module 'kleur/colors' does not provide an export named 'red'

// Node 14.x
import * as colors from 'kleur/colors';
//=> { red, blue, ... }

import { red } from 'kleur/colors';
// OK

So it'd skip the immediate module-loader error, but it either requires an interop-check in all places or fails silently because the exports don't align.

@ljharb
Copy link
Contributor Author

ljharb commented Oct 13, 2020

You can't require ESM files, and the bug I'm trying to fix is being able to require yargs (which requires escalade) in node v13.0-v13.6.

It's impossible to support both CJS and ESM in those versions, and since CJS can be both required and imported, that's the only approach that makes sense imo.

@ljharb
Copy link
Contributor Author

ljharb commented Oct 13, 2020

In other words, I think CJS is a far, far more important consumer than ESM, because most node users aren't using ESM yet - and because for escalade to be consumed as ESM, everything that consumes it must also consume with ESM. Being ESM-only is viral - being CJS-only is not.

@lukeed
Copy link
Owner

lukeed commented Oct 13, 2020

Gotcha :) While certainly not ideal, I agree it's the safer/wider support range.
In some future version, the engines list can outlaw those Node versions... but really, I wish there was some way to ban Node 13.0-13.6 outright (or maybe all odd, non-latest versions in general). This range continually causes headache for ESM adoption and there's just zero reason to be using one of these Node versions.

Anyway, thanks!

@lukeed lukeed merged commit a2297e1 into lukeed:master Oct 13, 2020
@ljharb ljharb deleted the patch-1 branch October 13, 2020 06:03
@lukeed
Copy link
Owner

lukeed commented Oct 13, 2020

Published escalade@3.1.1

@ljharb
Copy link
Contributor Author

ljharb commented Oct 13, 2020

Thank you!

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