Skip to content

Commit e8912c3

Browse files
authored
Fixes immutablePatterns when running an install from a subdirectory (yarnpkg#6410)
## What's the problem this PR addresses? The `checksumHash` function was retrieving relative paths from the globing. When it subsequently tried to access those files when the user was anywhere else but the root it crashed. ## How did you fix it? We now join the paths with the base directory before accessing them. ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent 48004ff commit e8912c3

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

.yarn/versions/30b3d908.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-link"
18+
- "@yarnpkg/plugin-nm"
19+
- "@yarnpkg/plugin-npm"
20+
- "@yarnpkg/plugin-npm-cli"
21+
- "@yarnpkg/plugin-pack"
22+
- "@yarnpkg/plugin-patch"
23+
- "@yarnpkg/plugin-pnp"
24+
- "@yarnpkg/plugin-pnpm"
25+
- "@yarnpkg/plugin-stage"
26+
- "@yarnpkg/plugin-typescript"
27+
- "@yarnpkg/plugin-version"
28+
- "@yarnpkg/plugin-workspace-tools"
29+
- "@yarnpkg/builder"
30+
- "@yarnpkg/doctor"
31+
- "@yarnpkg/extensions"
32+
- "@yarnpkg/nm"
33+
- "@yarnpkg/pnpify"
34+
- "@yarnpkg/sdks"

packages/acceptance-tests/pkg-tests-specs/sources/features/immutablePatterns.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,20 @@ describe(`Features`, () => {
159159
},
160160
),
161161
);
162+
163+
it(`shouldn't fail when running an install from a subdirectory`,
164+
makeTemporaryEnv(
165+
{},
166+
async ({path, run, source}) => {
167+
await xfs.writeFilePromise(ppath.join(path, Filename.rc), `immutablePatterns: [".pnp.cjs"]`);
168+
169+
const subPath = ppath.join(path, `subdir`);
170+
await xfs.mkdirPromise(subPath);
171+
172+
await run(`install`, {cwd: subPath});
173+
await run(`install`, `--immutable`, {cwd: subPath});
174+
},
175+
),
176+
);
162177
});
163178
});

packages/yarnpkg-core/sources/hashUtils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {PortablePath, xfs, npath, FakeFS} from '@yarnpkg/fslib';
2-
import {createHash, BinaryLike} from 'crypto';
3-
import fastGlob from 'fast-glob';
1+
import {PortablePath, xfs, npath, FakeFS, ppath} from '@yarnpkg/fslib';
2+
import {createHash, BinaryLike} from 'crypto';
3+
import fastGlob from 'fast-glob';
44

55
export function makeHash<T extends string = string>(...args: Array<BinaryLike | null>): T {
66
const hash = createHash(`sha512`);
@@ -70,7 +70,7 @@ export async function checksumPattern(pattern: string, {cwd}: {cwd: PortablePath
7070
const hashes = await Promise.all(listing.map(async entry => {
7171
const parts: Array<Buffer> = [Buffer.from(entry)];
7272

73-
const p = npath.toPortablePath(entry);
73+
const p = ppath.join(cwd, npath.toPortablePath(entry));
7474
const stat = await xfs.lstatPromise(p);
7575

7676
if (stat.isSymbolicLink())

0 commit comments

Comments
 (0)