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

Support "browser" deep module references #62

Closed
justinbmeyer opened this issue Jan 19, 2015 · 2 comments
Closed

Support "browser" deep module references #62

justinbmeyer opened this issue Jan 19, 2015 · 2 comments

Comments

@justinbmeyer
Copy link
Contributor

I would like to support re-pathing "deep" directory references with the browser config. This was brought up here in node-browser-resolve. And it was suggested here that the changes partly belong in node-resolve.

To make this change, I will need to change node-resolve to make a better attempt to find the package.json and opts hook that supports repathing.

loadAsDirectory, given a path like x = "../node_modules/foo/bar" will look for package.json in "../node_modules/package.json".

If given a path without node_modules like: x = "/Users/justin/dev/project/foo/bar", it will look for package.json in each folder until it finds it.

If a "deep" module reference is being resolved, a package.json is found, and an opts.pathFilter is found, opts.pathFinder(pkg, x, relativeX) will be called where:

  • pkg - the package data
  • x - the moduleId attempted to be resolved
  • relativeX - the moduleId path relative to the package.json location.

If opts.pathFilter returns a value, the returned value will be joined from the package.json location and passed to loadAsFile. Otherwise, x will be used with loadAsFile.

Example:

loadAsDirectory("/Users/justin/dev/project/foo/bar") 
  opts.pathFilter(pkg, "/Users/justin/dev/project/foo/bar", "./foo/bar") //-> "./browser/foo/bar"
  loadAsFile("/Users/justin/dev/project/browser/foo/bar", pkg)

Thoughts on this, the changes, and the choice of the pathFilter name and arguments? Thanks!

/cc @defunctzombie

@justinbmeyer
Copy link
Contributor Author

Actually, it seems that loadAsFile will need this behavior too.

@ljharb
Copy link
Member

ljharb commented Jun 17, 2018

This seems addressed.

@ljharb ljharb closed this as completed Jun 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants