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

module: fix check for package.json at volume root #34595

Closed
wants to merge 1 commit into from
Closed

module: fix check for package.json at volume root #34595

wants to merge 1 commit into from

Conversation

DerekNonGeneric
Copy link
Contributor

@DerekNonGeneric DerekNonGeneric commented Aug 1, 2020

This commit converts the "read package scope" algorithm's while loop
into a do-while loop.

Fixes: #33438

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this one. I must admit I did try it but couldn't replicate the issue locally myself. Are your manual tests definitely working on both Windows and linux here?

lib/internal/modules/cjs/loader.js Show resolved Hide resolved
@DerekNonGeneric
Copy link
Contributor Author

DerekNonGeneric commented Aug 3, 2020

I must admit I did try it but couldn't replicate the issue locally myself.

Perhaps try the following reduction? (Make sure the files actually get created.)

$ sudo echo '{ "type": "module" }' > /package.json
$ sudo echo 'export {}' > /index.js
$ node /index.js

Are your manual tests definitely working on both Windows and linux here?

I have had successful manual testing on Debian WSL.

Built this on Windows locally and it fails.


I imagine automated testing is going to involve https://hub.docker.com/_/microsoft-windows-nanoserver. 😄

@GeoffreyBooth
Copy link
Member

I was able to reproduce it via #33438 (comment). To truly fix this I think you need to do that again, and then check out the CoffeeScript repo and run its tests (/path/to/this-prs/node ./bin/cake test from the CoffeeScript repo root). That would reproduce the CITGM failure. Get the CoffeeScript tests to pass with the node from your PR and you've fixed it.

@guybedford
Copy link
Contributor

@DerekNonGeneric the above sounds like a good success criteria here to me... if you're able to do that do let us know.

@DerekNonGeneric
Copy link
Contributor Author

@guybedford, sorry for the delay. Admittedly I'm having trouble interpreting the last couple of comments. Is the intention to forgo Windows support in this PR and simply ensure that POSIX filesystem root is functioning as expected? Please keep me posted! In the meantime, I'll be looking into how close this PR is to minimally addressing the referenced issue.

@guybedford
Copy link
Contributor

I think it's just about testing that it works in Windows and posix.

@DerekNonGeneric
Copy link
Contributor Author

DerekNonGeneric commented Aug 12, 2020

Just as a brief update to this: the reason why it wasn't working for me on Windows was due to what seems like my two test files from the reduction having the wrong encoding. After re-creating these files w/ proper UTF-8 encoding, I was able to perform successful manual testing on Windows, so this solution does indeed work as expected.

I'm still thinking about what the best approach would be to get some automated testing done here.

@DerekNonGeneric
Copy link
Contributor Author

DerekNonGeneric commented Aug 12, 2020

I'm still thinking about what the best approach would be to get some automated testing done here.

I'm not exactly sure what the most appropriate strategy would be to take here. A few thoughts…

  • Use Docker to create a Windows VM w/ these two reduction files in the root dir
  • Expose the readPackageScope function for testing-only purposes and feed it a few Windows paths (or similar faking)

@jkrems, I know you've handled a lot of the ESM testing in the past, do you have a preference?

@DerekNonGeneric DerekNonGeneric added esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. test Issues and PRs related to the tests. windows Issues and PRs related to the Windows platform. labels Aug 12, 2020
@jkrems
Copy link
Contributor

jkrems commented Aug 12, 2020

Quite honestly: To me this would be a matter of "weigh risk of regression and impact of regression against the effort of writing and maintaining a test". The first two seem really low here which to me means: There's likely something more valuable to do with your time than to try too hard to find a great automated test.

There may be some things you can do with chroot but that would require special child process execution and wouldn't be cross-platform. So my position here would be: Document the commands you used to test it manually and call it a day.

@DerekNonGeneric
Copy link
Contributor Author

The first two seem really low here […]

Agree completely.

Document the commands you used to test it manually and call it a day.

I ran the CoffeeScript tests using this PR's built executable (on Windows to boot) as @GeoffreyBooth suggested in #34595 (comment). The result follows.

passed 1456 tests in 16.26 seconds

I think this PR is ready for review now as all other checks have passed. :)

/cc @nodejs/modules-active-members

@DerekNonGeneric DerekNonGeneric marked this pull request as ready for review August 13, 2020 00:17
@DerekNonGeneric DerekNonGeneric added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. test Issues and PRs related to the tests. windows Issues and PRs related to the Windows platform. labels Aug 13, 2020
lib/internal/modules/cjs/loader.js Outdated Show resolved Hide resolved
lib/internal/modules/cjs/loader.js Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
@guybedford
Copy link
Contributor

@DerekNonGeneric if the comments are too much I'm happy to push some changes if you prefer.

@DerekNonGeneric
Copy link
Contributor Author

DerekNonGeneric commented Aug 13, 2020

@guybedford, sure, whatever would be easiest. I'd like it if we could finish this one off tonight if possible.

lib/internal/modules/cjs/loader.js Outdated Show resolved Hide resolved
lib/internal/modules/cjs/loader.js Outdated Show resolved Hide resolved
lib/internal/modules/cjs/loader.js Outdated Show resolved Hide resolved
lib/internal/modules/cjs/loader.js Outdated Show resolved Hide resolved
lib/internal/modules/cjs/loader.js Outdated Show resolved Hide resolved
@guybedford
Copy link
Contributor

@DerekNonGeneric sure I've pushed up a new commit with the suggestions, including @ljharb's changes again too. Please test it out if you can on the original cases as I only tested on unix here. And if you need Windows testing help let me know.

@nodejs-github-bot
Copy link
Collaborator

@DerekNonGeneric DerekNonGeneric added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 13, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 13, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/32770/

@mmarchini mmarchini added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 15, 2020
@github-actions github-actions bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Aug 15, 2020
@github-actions
Copy link
Contributor

Commit Queue failed
- Loading data for nodejs/node/pull/34595
✔  Done loading data for nodejs/node/pull/34595
----------------------------------- PR info ------------------------------------
Title      module: fix check for package.json at volume root (#34595)
Author     Derek Lewis  (@DerekNonGeneric)
Branch     DerekNonGeneric:fix/root-package-scope -> nodejs:master
Labels     ES Modules, author ready, module
Commits    1
 - module: fix check for package.json at volume root
Committers 1
 - Derek Lewis 
PR-URL: https://github.com/nodejs/node/pull/34595
Fixes: https://github.com/nodejs/node/issues/33438
Reviewed-By: Jan Krems 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/34595
Fixes: https://github.com/nodejs/node/issues/33438
Reviewed-By: Jan Krems 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last review:
   ⚠  - module: fix check for package.json at volume root
   ℹ  Last Full PR CI on 2020-08-13T22:27:22Z: https://ci.nodejs.org/job/node-test-pull-request/32770/
- Querying data of job/node-test-pull-request/32770/
✔  Build data downloaded
   ℹ  This PR was created on Sat, 01 Aug 2020 20:53:18 GMT
   ✔  Approvals: 1
   ✔  - Jan Krems (@jkrems): https://github.com/nodejs/node/pull/34595#pullrequestreview-466996890
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

@mmarchini mmarchini added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Aug 15, 2020
@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 15, 2020
@github-actions
Copy link
Contributor

Landed in 0347574

@github-actions github-actions bot closed this Aug 15, 2020
nodejs-github-bot pushed a commit that referenced this pull request Aug 15, 2020
This patch converts the "read package scope" algorithm's while loop
into a do-while loop enabling items at the filesystem root dir to
be considered within the scope of a sibling package.json also at the
filesystem root dir.

Fixes: #33438

Co-authored-by: Guy Bedford <guybedford@gmail.com>

PR-URL: #34595
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
MylesBorins pushed a commit that referenced this pull request Aug 17, 2020
This patch converts the "read package scope" algorithm's while loop
into a do-while loop enabling items at the filesystem root dir to
be considered within the scope of a sibling package.json also at the
filesystem root dir.

Fixes: #33438

Co-authored-by: Guy Bedford <guybedford@gmail.com>

PR-URL: #34595
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
@danielleadams danielleadams mentioned this pull request Aug 20, 2020
BethGriggs pushed a commit that referenced this pull request Aug 20, 2020
This patch converts the "read package scope" algorithm's while loop
into a do-while loop enabling items at the filesystem root dir to
be considered within the scope of a sibling package.json also at the
filesystem root dir.

Fixes: #33438

Co-authored-by: Guy Bedford <guybedford@gmail.com>

PR-URL: #34595
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
guybedford pushed a commit to guybedford/node that referenced this pull request Sep 28, 2020
This patch converts the "read package scope" algorithm's while loop
into a do-while loop enabling items at the filesystem root dir to
be considered within the scope of a sibling package.json also at the
filesystem root dir.

Fixes: nodejs#33438

Co-authored-by: Guy Bedford <guybedford@gmail.com>

PR-URL: nodejs#34595
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
codebytere pushed a commit that referenced this pull request Oct 1, 2020
This patch converts the "read package scope" algorithm's while loop
into a do-while loop enabling items at the filesystem root dir to
be considered within the scope of a sibling package.json also at the
filesystem root dir.

Fixes: #33438

Co-authored-by: Guy Bedford <guybedford@gmail.com>

PR-URL: #34595
Backport-PR-URL: #35385
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
@codebytere codebytere mentioned this pull request Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ES modules] package.json located in root path can't be resolved when checking type field
8 participants