-
-
Notifications
You must be signed in to change notification settings - Fork 184
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 doesn't resolve real path for basedir
if it is relative path
#177
Comments
It seems like you're not setting the What happens if you set that option? |
I update the test case and the bug still exists. malash/resolve-issue-177@c5ea1c8 In fact |
hmm, i'm trying to reproduce this error, and i do get this failure: However, after |
@ljharb I will clarify it. When running it equals to
so the
which is a symlink to
|
OK, but the error says "from node_modules/@my-scope/package-b" - and then "../../node_modules/jquery'" - so, the final path it's looking for is "node_modules/jquery" (inside package-a) - but package-a doesn't have jquery listed as a dependency, and it's not present on disk. |
(and package-b doesn't have jquery either) |
No. The final path is not First, I fixed the
The current logic equals to
It's a non-exist path. The correct way should be:
That line could be refactor like this ( just for demo ): // if not preserveSymlinks
path.resolve(fs.realpathSync(basedir), x)
// else
path.resolve(basedir, x)
|
Got it, thanks for explaining. |
OK, so part of the problem is that the basedir you're passing in isn't resolved - it's relative to package-a/index, but that's not information that resolve can retain - so you first have to This makes the first assertion pass, but the second still fails for me. |
Normally the For this issue the inconsistency is that user have to resolve real path of basedir for relative path but not NPM package. // packages/package-a/index.js
console.log(resolve.sync("jquery", { basedir: basedir }));
console.log(resolve.sync("../../node_modules/jquery", { basedir: fs.realpathSync(basedir) }));
|
Compression between // preserveSymlinks === false
// will search NPM package from
// * packages/package-b/node_modules
// * packages/node_modules
// * node_modules
console.log(resolve.sync('jquery', { basedir: basedir, preserveSymlinks: false }));
console.log(resolve.sync('../../node_modules/jquery', { basedir: fs.realpathSync(basedir), preserveSymlinks: false }));
// preserveSymlinks === true
// will search NPM package from
// * packages/package-a/node_modules/@my-scope/packages/package-b/node_modules
// * packages/package-a/node_modules/@my-scope/packages/node_modules
// * packages/package-a/node_modules/@my-scope/node_modules
// * packages/package-a/node_modules/node_modules
// * packages/package-a/node_modules
// * packages/node_modules
// * node_modules
console.log(resolve.sync('jquery', { basedir: basedir, preserveSymlinks: true }));
console.log(resolve.sync('../../../../../node_modules/jquery', { basedir: basedir, preserveSymlinks: true })); |
@ljharb Thank you very much for your commit. This commit works for me. |
Thank you for your excellent repro case! |
- [New] `async`/`sync`/`node-modules-paths`: Adds support for “paths” being a function (#172, #173) - [New] Implements a "normalize-options" pseudo-hook (#174) - [Fix] `sync`/`async`: fix `preserveSymlinks` option (#177) - [Fix] `sync`/`async`: when package.json `main` is not a string, throw an error (#178) - [Deps] update `path-parse` - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `object-keys`, `safe-publish-latest`, `tape` - [Tests] up to `node` `v11.4`, `v10.14`, `v8.14`, `v6.15` - [Tests] better failure messages
Did this breaking change get resolved before publishing v1.9.0?
Line 57 in 04e6c79
vs. what I think was published at tag v1.9.0. https://github.com/browserify/resolve/blob/v1.9.0/lib/sync.js#L36 |
@john-kurkowski v1.9.0 does not include any of the breaking changes. I cherry-picked commits onto the v1.8.1 tag, and released, and merged the v1.9.0 tag back to master. |
@ljharb what are the plans on releasing this fix? Having issues with this in ionic-team/stencil#1310.
Problem is that with path
, but
and makes the code fail. When I replaced I'm not that familiar with the topic so what would you suggest? Is this more related to bad code that needs to be fixed, or should I wait for the fix? |
@simonhaenisch it’s released in v1.9.0. If you’re still seeing a problem, please file a new issue and we can talk it out there. |
resolve
doesn't resolve real path forbasedir
if it is relative path.I'v created a bad case example ( by lerna ) here https://github.com/malash/resolve-bad-case
The issue is related to #130 .
The issue effected peerigon/extract-loader#48 and may affect #163 .
@zkochan @ljharb
The text was updated successfully, but these errors were encountered: