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

Resolve symlinked modules correctly #92

Merged
merged 9 commits into from Feb 11, 2020

Conversation

lhorie
Copy link
Contributor

@lhorie lhorie commented Feb 9, 2019

Some systems (e.g. rush, pnpm) use symlinks to create a recursive dependency graph
instead of relying on the hoisting aspect of the node module resolution algorithm (like npm and yarn do)
in these cases, we want to resolve to the real path of a module, so that the tree structure below
only ever tries to run the x module once (rather than once on each module that depends on it)

- node_modules
  - a
    - node_modules
      - symlink to x
  - b
    - node_modules
      - symlink to x

There's an example of a downstream bug here: https://github.com/lhorie/jest-browser-bug (via jestjs/jest#7840)

Some systems (e.g. rush, pnpm) use symlinks to create a recursive dependency graph
instead of relying on the hoisting aspect of the node module resolution algorithm (like npm and yarn do)
in these cases, we want to resolve to the real path of a module, so that the tree structure below
only ever tries to run the `x` module once (rather than once on each module that depends on it)

- node_modules
  - a
    - node_modules
      - symlink to x
  - b
    - node_modules
      - symlink to x
Some systems (e.g. rush, pnpm) use symlinks to create a recursive dependency graph
instead of relying on the hoisting aspect of the node module resolution algorithm (like npm and yarn do)
in these cases, we want to resolve to the real path of a module, so that the tree structure below
only ever tries to run the `x` module once (rather than once on each module that depends on it)

- node_modules
  - a
    - node_modules
      - symlink to x
  - b
    - node_modules
      - symlink to x
@lhorie
Copy link
Contributor Author

lhorie commented Feb 11, 2019

CI now passes for Node 6.

Current CI failures happen on older versions of node on code I didn't touch (due to ES6 syntax).

@lhorie
Copy link
Contributor Author

lhorie commented Apr 3, 2019

@defunctzombie Ping. Is this package still maintained?

package.json Outdated
@@ -8,7 +8,8 @@
"empty.js"
],
"scripts": {
"test": "mocha --reporter list test/*.js"
"test": "mocha --reporter list test/*.js",
"postinstall": "node scripts/setup-symlinks.js"
Copy link
Collaborator

Choose a reason for hiding this comment

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

End users don't need this link to happen so I'd prefer if the module didn't do it for all users.

index.js Outdated
if (notPath) callback(err, path, pkg);
else {
fs.realpath(path, function(notReal, real) {
if (notReal) callback(err, path, pkg);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please follow the code style already present in the document.

@@ -216,6 +216,20 @@ function resolve(id, opts, cb) {
opts = opts || {};
opts.filename = opts.filename || '';

var cb = function(err, path, pkg) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this set of nested functions trying to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. if it's a module name, resolve to it
  2. if it's something in the filesystem, then
    2a) if it's a regular file, resolve to it
    2b) if it's a symlink, resolve to its realpath

- run test setup in test command
- follow code style
@lhorie
Copy link
Contributor Author

lhorie commented Apr 12, 2019

@defunctzombie I made the code style change and moved the test setup script to the test script

@rtsao
Copy link
Contributor

rtsao commented Feb 3, 2020

@defunctzombie Is there anything else that needs to be done for this to be ready to merge?

I suppose get tests passing in older version of node?

@defunctzombie
Copy link
Collaborator

It's fair to say that I don't maintain or keep this module updated very much. Which upstream module(s) depend on this enough to have their maintainers consider picking up this module as well?

@rtsao
Copy link
Contributor

rtsao commented Feb 3, 2020

I see. Jest is currently using this package (see jestjs/jest#9511). I suppose the Jest maintainers might be amenable to taking over ownership (or at the very least forking their own version to address their needs).

@defunctzombie
Copy link
Collaborator

@rtsao I'd be happy to see this PR land if the tests were updated to pass on the versions of node that jest actively supports - I don't care if old node version support is dropped. If you want to prepare another PR building from this one and ping me I can merge it.

I am also happy to have jest maintainers pickup this module or logic if that is easier for them. I do not commit resources to this module.

@rtsao
Copy link
Contributor

rtsao commented Feb 3, 2020

Thanks @defunctzombie!

@lhorie was kind enough to grant me push access so I've just made the changes here.

As of Jest v25, Node 6.x support was removed. Additionally, Node 6.x EOL was April 30, 2019. So I've updated the travis.yml to test against 8.x, 10.x and 12.x and added an npm lockfile so that tests will be deterministic and won't break in the future.

@defunctzombie defunctzombie merged commit d7f9908 into browserify:master Feb 11, 2020
goto-bus-stop added a commit that referenced this pull request Jun 18, 2020
goto-bus-stop added a commit that referenced this pull request Aug 3, 2020
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