Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions .yarn/versions/c9849542.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch
"@yarnpkg/libzip": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/fslib"
- "@yarnpkg/nm"
- "@yarnpkg/pnp"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {execUtils} from '@yarnpkg/core';
import {Filename, ppath, xfs} from '@yarnpkg/fslib';
import {tests} from 'pkg-tests-core';

Expand Down Expand Up @@ -198,6 +199,71 @@ describe(`Cache`, () => {
}),
);

test(`it should not confuse the cache key when merging an upgraded cache key branch into a feature branch`, makeTemporaryEnv({
dependencies: {
[`depA`]: `npm:no-deps@1.0.0`,
[`depB`]: `npm:no-deps@1.0.1`,
[`depC`]: `npm:no-deps@1.1.0`,
},
}, async ({path, run, source}) => {
await run(`install`);

// First we create the main branch; it contains a bunch of various dependencies

await execUtils.execvp(`git`, [`init`], {cwd: path});

await execUtils.execvp(`git`, [`add`, `.`], {cwd: path});
await execUtils.execvp(`git`, [`commit`, `-m`, `test`], {cwd: path});

// We now create a new feature branch derived from the base one, and we add a new dependency

await execUtils.execvp(`git`, [`checkout`, `-b`, `feature`], {cwd: path});

await run(`add`, `depX@npm:no-deps@2.0.0`);

await execUtils.execvp(`git`, [`add`, `.`], {cwd: path});
await execUtils.execvp(`git`, [`commit`, `-m`, `new dep`], {cwd: path});

// Meanwhile, the base branch is updated with a new Yarn version:
//
// - we add an extra byte at the end of each file in the cache, to simulate a change in how zip archives are generated
// - we run an install with a new cache version and we persist the new checksums

await execUtils.execvp(`git`, [`checkout`, `-`], {cwd: path});

await run(`install`, {
cacheVersionOverride: `2`,
zipDataEpilogue: `<arbitrary data>`,
});

//throw new Error(`lol`);

await execUtils.execvp(`git`, [`add`, `.`], {cwd: path});
await execUtils.execvp(`git`, [`commit`, `-m`, `fake upgrade`], {cwd: path});

// Going back to our feature branch, we now merge the updated base branch into it

await execUtils.execvp(`git`, [`checkout`, `-`], {cwd: path});

await execUtils.execvp(`git`, [`merge`, `-`], {cwd: path});

// Running an install should work fine

await run(`install`, {
cacheVersionOverride: `2`,
zipDataEpilogue: `<arbitrary data>`,
});

// However, once we remove the cache and try to reinstall, we used to get an error because the wrong cache key had been encoded in the lockfile

await xfs.removePromise(ppath.join(path, `.yarn/cache`));

await run(`install`, {
cacheVersionOverride: `2`,
zipDataEpilogue: `<arbitrary data>`,
});
}));

test(
`it should ignore changes in the cache compression, if cacheMigrationMode=required-only`,
makeTemporaryEnv({
Expand Down
1 change: 1 addition & 0 deletions packages/yarnpkg-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const IGNORED_ENV_VARIABLES = new Set([
`injectNpmUser`,
`injectNpmPassword`,
`injectNpm2FaToken`,
`zipDataEpilogue`,
`cacheCheckpointOverride`,
`cacheVersionOverride`,
`lockfileVersionOverride`,
Expand Down
19 changes: 1 addition & 18 deletions packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1969,23 +1969,6 @@ export class Project {

manifest.bin = new Map(pkg.bin);

let entryChecksum: string | undefined;
const checksum = this.storedChecksums.get(pkg.locatorHash);
if (typeof checksum !== `undefined`) {
const cacheKeyIndex = checksum.indexOf(`/`);
if (cacheKeyIndex === -1)
throw new Error(`Assertion failed: Expected the checksum to reference its cache key`);

const entryCacheKey = checksum.slice(0, cacheKeyIndex);
const hash = checksum.slice(cacheKeyIndex + 1);

if (entryCacheKey === cacheKey) {
entryChecksum = hash;
} else {
entryChecksum = checksum;
}
}

optimizedLockfile[key] = {
...manifest.exportTo({}, {
compatibilityMode: false,
Expand All @@ -1994,7 +1977,7 @@ export class Project {
linkType: pkg.linkType.toLowerCase(),

resolution: structUtils.stringifyLocator(pkg),
checksum: entryChecksum,
checksum: this.storedChecksums.get(pkg.locatorHash),

conditions: pkg.conditions || undefined,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/sources/worker-zip/index.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions packages/yarnpkg-libzip/sources/ZipFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,12 @@ export class ZipFS extends BasePortableFakeFS {
else if (rc > size)
throw new Error(`Overread`);

const memory = this.libzip.HEAPU8.subarray(buffer, buffer + size);
return Buffer.from(memory);
let result = Buffer.from(this.libzip.HEAPU8.subarray(buffer, buffer + size));

if (process.env.YARN_IS_TEST_ENV && process.env.YARN_ZIP_DATA_EPILOGUE)
result = Buffer.concat([result, Buffer.from(process.env.YARN_ZIP_DATA_EPILOGUE)]);

return result;
} finally {
this.libzip.free(buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

Loading