fix(pnp): make sure that the package locator is fetched with a trailing slash#6882
Merged
arcanis merged 2 commits intoyarnpkg:masterfrom Jan 14, 2019
Merged
Conversation
Member
|
Hey, thanks for investigating! We use the trailing slash to differentiate when the source is a file ( Can you instead try changing |
... fetched with a trailing slash
I could not get P'n'P working on a project using `critical`[1] and
traced it down to a lookup of a package locator without a trailing
slash.
A `require('resolve').sync('fg-loadcss')` from `inline-critical`[2]
would fail to resolve as the `locatorsByLocations` lookup in `.pnp.js`
would be using a key without a trailing slash, i.e.:
```
"../../.cache/yarn/v4/npm-inline-critical-4.0.7-3ffba6a869f39215c8bb00ed2dd6b872e7f98adc/node_modules/inline-critical"
```
`findPackageLocator` is invoked with `location` parameter (notice no
trailing slash):
```
location = "/home/zregvart/.cache/yarn/v4/npm-inline-critical-4.0.7-3ffba6a869f39215c8bb00ed2dd6b872e7f98adc/node_modules/inline-critical"
```
from `resolveToUnqualified` with parameters:
```
request = "fg-loadcss/package.json"
issuer = "/home/zregvart/.cache/yarn/v4/npm-inline-critical-4.0.7-3ffba6a869f39215c8bb00ed2dd6b872e7f98adc/node_modules/inline-critical"
```
All starting from `loadNodeModulesSync` in `resolve`'s `sync.js`[3]
that ends up having `absoluteStart` without the trailing slash.
Not sure if this is the most correct way of fixing this issue, by just
ensuring that the trailing slash needed for the lookup is added if
missing.
All tests from `yarn test` and from `packages/pkg-tests`
`yarn jest yarn.test.js` pass, so it seems like a start.
This is how to reproduce:
package.json:
```json
{
"name": "require-failure",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"install": "node --require ./.pnp.js index.js"
},
"devDependencies": {
"critical": "^1.3.4"
},
"installConfig": {
"pnp": true
}
}
```
index.js:
```javascript
require('critical').generate({
inline: true,
html: '<!DOCTYPE html><html><head><link rel="stylesheet" href="site.css"></head><body><h1>Hello</h1></body></html>'
});
```
site.css:
```css
h1 { font-weight: bold; }
```
Not sure how to create a package test from that example (sorry).
[1] https://github.com/addyosmani/critical
[2] https://github.com/bezoerb/inline-critical/blob/340db21f6a2454ed74ede7a0b317d4c4e177770d/index.js#L32
[3] https://github.com/browserify/resolve/blob/254bb4029df2f8d20a33043dfabd8e5cabfa37df/lib/sync.js#L52
ab84ee6 to
ee7bf5d
Compare
Contributor
Author
|
@arcanis thanks for the suggestion, looks much better to my layman eyes at least. |
asfgit
pushed a commit
to apache/camel-website
that referenced
this pull request
Jan 7, 2019
... version We need a patched version of Yarn that includes a fix for properly resolving dependencies in certain cases[1]. [1] yarnpkg/yarn#6882
asfgit
pushed a commit
to apache/camel-website
that referenced
this pull request
Jan 7, 2019
... version We need a patched version of Yarn that includes a fix for properly resolving dependencies in certain cases[1]. [1] yarnpkg/yarn#6882
Member
|
Thanks! This should be available soon through our nightlies builds 🙂 |
cacheflow
added a commit
to cacheflow/yarn
that referenced
this pull request
Feb 14, 2019
* master: (67 commits) Include key info for "expected hoisted" invariant (yarnpkg#7009) refactor: remove unnecessary checks (yarnpkg#6955) fix: drive letter casing for win32 pnp (yarnpkg#7007) Don’t call `release` with an exit code (yarnpkg#6981) Check os and platform even when engines is not present in package.json (yarnpkg#6976) Fix handling of non-offline errors (yarnpkg#6968) Treat the ignore-scripts in yarnrc as a synonym to the cli arg (yarnpkg#6983) fix(pnp): make sure pnp module is again the first preloaded module. (yarnpkg#6951) refactor: remove unused imports (yarnpkg#6956) Add 1.14.0 to changelog (yarnpkg#6967) 1.15.0-0 v1.14.0 Fix suggested command after unlinking a package (yarnpkg#6931) Update CHANGELOG.md fix(pnp): make sure pnp module is the first preloaded module. (yarnpkg#6942) fix(pnp): make sure that the package locator is fetched with a trailing slash (yarnpkg#6882) Improve rendering of Chocolatey package description (yarnpkg#6899) Fixing dynamic require missing from webpack (yarnpkg#6908) feat(policies): Use github access token when requesting releases (yarnpkg#6912) Fixes PnP detection across workspaces (yarnpkg#6878) ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I could not get P'n'P working on a project using
critical[1] and traced it down to a lookup of a package locator without a trailing slash.A
require('resolve').sync('fg-loadcss')frominline-critical[2] would fail to resolve as thelocatorsByLocationslookup in.pnp.jswould be using a key without a trailing slash, i.e.:findPackageLocatoris invoked withlocationparameter (notice no trailing slash):from
resolveToUnqualifiedwith parameters:All starting from
loadNodeModulesSyncinresolve'ssync.js[3] that ends up havingabsoluteStartwithout the trailing slash.Not sure if this is the most correct way of fixing this issue, by just ensuring that the trailing slash needed for the lookup is added if missing.
All tests from
yarn testand frompackages/pkg-testsyarn jest yarn.test.jspass, so it seems like a start.Test plan
This is how to reproduce:
package.json:
{ "name": "require-failure", "version": "1.0.0", "main": "index.js", "license": "MIT", "scripts": { "install": "node --require ./.pnp.js index.js" }, "devDependencies": { "critical": "^1.3.4" }, "installConfig": { "pnp": true } }index.js:
site.css:
Not sure how to create a package test from that example (sorry).
[1] https://github.com/addyosmani/critical
[2] https://github.com/bezoerb/inline-critical/blob/340db21f6a2454ed74ede7a0b317d4c4e177770d/index.js#L32
[3] https://github.com/browserify/resolve/blob/254bb4029df2f8d20a33043dfabd8e5cabfa37df/lib/sync.js#L52