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] node v10.0 lacks fs.promises #2654

Merged
merged 1 commit into from Feb 12, 2021
Merged

Conversation

ljharb
Copy link
Collaborator

@ljharb ljharb commented Feb 8, 2021

In this node version, fall back to util.promisify of the callback version.

Maybe fixes #2623. Maybe fixes #2652. Maybe fixes #2625.

Updated the tests to run on the .0s as well.

This is likely blocked until npm/node-gyp#5 and npm/run-script#21 are landed, released, and updated here.

@wraithgar
Copy link
Member

I believe this is why npm7 doesn't run under node8 also, at least the biggest hurdle. Fixing this COULD have negative repercussions to people who currently are installing npm7 on node8, in that it could now break in new less visible ways.

It may be worth discussing making sure that npm7 won't install itself outside its engine.node bounds before we fix this.

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 8, 2021

@wraithgar that is easily avoidable by sticking some syntax in the npm cli entrypoint that breaks on node 8 - for example:

/* npm requires node 10+ */ (async function* () {})

@wraithgar
Copy link
Member

Ideally we do this in a way that you can't install at all, having an npm that refuses to run after it's installed is no different than having one that is broken after it's installed. And since we're already planning on solving the other issue, it could be better to do that first. #2612

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 8, 2021

I don't mind the order, but to me it seems far more important to ensure npm works on the engines it supports than to ensure it fails to install on the engines it doesn't support :-)

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 8, 2021

Either way, the dependent PRs could presumably be landed sooner?

@wraithgar
Copy link
Member

I don't mind the order, but to me it seems far more important to ensure npm works on the engines it supports than to ensure it fails to install on the engines it doesn't support :-)

This is a good point. Another thing that had been floated was updating the engines declaration since these v10 versions have security vulnerabilities associated with them. However the discussion around updating a semver minor in engines.node and what that represents in your own package's version is one that isn't extremely clear.

I'll +1 this but am still nervous about what npm is going to do in node8. We'd best get the other issue solved sooner than later also.

@wraithgar wraithgar self-requested a review February 9, 2021 15:23
Copy link
Member

@wraithgar wraithgar left a comment

Choose a reason for hiding this comment

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

Coverage checks seem to be failing now.

@ruyadorno
Copy link
Collaborator

yeah, it needs a test that simulates node<10 by mocking fs returning an object without a promises property

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 9, 2021

To be clear; per-job coverage checks will always fail in a project that has platform version fallbacks.

Separately, this PR’s tests will fail until the dependent PRs are merged and released, and the deps are updated here.

@wraithgar
Copy link
Member

I am nervous about having checkmarks not be green on PRs, that really does train us to ignore CI tests.

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 9, 2021

@wraithgar having them sit there red shouldn't be training anyone :-) only merging through a red x would do that.

I'll mark this as a draft for now since the others aren't landed yet.

@ljharb ljharb marked this pull request as draft February 9, 2021 17:36
@ljharb ljharb force-pushed the latest branch 3 times, most recently from dc2ca45 to 5daf858 Compare February 10, 2021 17:02
@ljharb
Copy link
Collaborator Author

ljharb commented Feb 10, 2021

What do i do with the npm doctor tests? On the .0 nodes, the not ok output for node -v is correct, so the if (err) t.fail code isn't correct, but i'm not sure the best way to tweak the test.

@ljharb ljharb force-pushed the latest branch 2 times, most recently from 2041b9c to a2aa1fa Compare February 10, 2021 17:37
@isaacs
Copy link
Contributor

isaacs commented Feb 10, 2021

What do i do with the npm doctor tests? On the .0 nodes, the not ok output for node -v is correct, so the if (err) t.fail code isn't correct, but i'm not sure the best way to tweak the test.

Clobber process.version and mock the fetch for available node versions. This is a good idea anyway, so our test isn't dependent on the node version being run.

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 11, 2021

OK, I've updated the doctor tests. Presumably these commits should remain separate when landing.

I'll look at the snapshot test failures next.

@darcyclarke darcyclarke added Release 7.x work is associated with a specific npm 7 release release: next These items should be addressed in the next release labels Feb 11, 2021
@wraithgar wraithgar removed the release: next These items should be addressed in the next release label Feb 11, 2021
@ljharb
Copy link
Collaborator Author

ljharb commented Feb 11, 2021

Turns out node v10.0 has some really ghostly Object.entries behavior, sometimes, with an Error instance, which is why the snapshot tests are failing.

I'm bumping up the tests to 10.1, and will leave it to yall to bump the engines to 10.1 if that's the best outcome.

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 12, 2021

@ruyadorno because npm uses licensee at the top level in its license validation, and it is a bug that it wasn't there in the first place.

@ruyadorno
Copy link
Collaborator

@ruyadorno because npm uses licensee at the top level in its license validation, and it is a bug that it wasn't there in the first place.

yeah cool, that sounds like a sep PR fix - will make things easier to manage

I can drop the commits but i want to make sure the deps are updated on latest, otherwise the tests here won't pass.

yeah I think specifically the @npmcli/run-script@1.8.3 commit can be dropped on our end at the rebase step of our pull script

@ruyadorno
Copy link
Collaborator

@ruyadorno because npm uses licensee at the top level in its license validation, and it is a bug that it wasn't there in the first place.

yeah cool, that sounds like a sep PR fix - will make things easier to manage

or even better, we can just make sure to add it in the release branch, no need to send a PR

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 12, 2021

right, but for this PR to pass, it has to be in the latest branch :-) the release branch is irrelevant to this PR.

I'll put up separate PRs for the other 3 commits, and once those land, i can rebase this one down to the single commit.

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 12, 2021

OK - once #2683, #2681, and #2682 have all landed in latest, then i'll rebase this PR and it'll be a single commit.

@wraithgar
Copy link
Member

The dependency update is already in the upcoming release branch, so I went ahead and closed that one. I'll look at the other two and start pulling them in if they look good (since this PR was already very heavily vetted I assume it will be a very straightforward process)

@wraithgar
Copy link
Member

Ok the two PRs that aren't the run-script update are in the release branch. I can pull this PR in once it is just the isolated changes.

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 12, 2021

In order for this PR to be rebased to the isolated changes, the other PRs need to be in the LATEST branch (the base branch for this PR). Being in the release branch has no impact on this PR.

Can those PRs be landed in the latest branch?

@wraithgar wraithgar changed the base branch from latest to release/v7.5.4 February 12, 2021 17:30
@wraithgar
Copy link
Member

wraithgar commented Feb 12, 2021

I am going to do some juggling here and see if I can clean this up real quick

ETA, forgot this was a PR from a fork. Hrm.

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 12, 2021

I can rebase it on top of the release branch if you'd like, this is just very bizarre to me :-)

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 12, 2021

Done, this is now a single commit on top of the release branch.

In this node version, fall back to `util.promisify` of the callback version.

Maybe fixes npm#2623. Maybe fixes npm#2652. Maybe fixes npm#2625.

PR-URL: npm#2654
Credit: @ljharb
Close: npm#2654
Reviewed-by: @wraithgar, @ruyadorno
@wraithgar wraithgar merged commit 868954a into npm:release/v7.5.4 Feb 12, 2021
@wraithgar wraithgar added the release: next These items should be addressed in the next release label Feb 12, 2021
@wraithgar
Copy link
Member

Aaand just so we can all see that things are working here in the release branch, with this PR included

Screen Shot 2021-02-12 at 9 46 33 AM

(The first failure was an os/x hiccup)

@ljharb
Copy link
Collaborator Author

ljharb commented Feb 12, 2021

with v7.5.4, my node v10.0 CI builds are passing, yay!

const { promises: { unlink } } = require('fs')
const util = require('util')
const fs = require('fs')
const { unlink } = fs.promises || util.promisify(fs.unlink)

Choose a reason for hiding this comment

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

How does one destructure an unlink property from a promisified function value? It's not following the pattern of lib/utils/reify-finish.js (or any number of dependency updates to address missing fs.promises), so maybe the tests are secretly failing for shrinkwrap? "Not throwing" isn't the same as "correct behavior in alternate circumstance".

-const { unlink } = fs.promises || util.promisify(fs.unlink)
+const { unlink } = fs.promises || { unlink: util.promisify(fs.unlink) }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

whoops, you're right. this was a mistake. i'll put up a quick PR to fix it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that tests aren't actually running in node 10.0, so the failures there wouldn't have shown up in CI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ljharb added a commit to ljharb/cli that referenced this pull request Feb 12, 2021
nlf pushed a commit to ljharb/cli that referenced this pull request Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: next These items should be addressed in the next release Release 7.x work is associated with a specific npm 7 release
Projects
None yet
6 participants