Merge pull request #10405 from webpack/feature/pnp-3

improve caching support for PnP version 3 (yarn 2 berry)
This commit is contained in:
Tobias Koppers 2020-02-18 09:18:59 +01:00 committed by GitHub
commit f3d6bdd455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 8 deletions

3
declarations.d.ts vendored
View File

@ -5,6 +5,9 @@ declare namespace NodeJS {
interface Process {
binding(internalModule: string): any;
}
interface ProcessVersions {
pnp: "1" | "3";
}
}
declare module "neo-async" {

View File

@ -174,9 +174,10 @@ const applyCacheDefaults = (cache, { name, mode }) => {
const dir = pkgDir.sync(cwd);
if (!dir) {
return path.resolve(cwd, ".cache/webpack");
// @ts-ignore
} else if (process.versions.pnp === "1") {
return path.resolve(dir, ".pnp/.cache/webpack");
} else if (process.versions.pnp === "3") {
return path.resolve(dir, ".yarn/.cache/webpack");
} else {
return path.resolve(dir, "node_modules/.cache/webpack");
}
@ -194,17 +195,25 @@ const applyCacheDefaults = (cache, { name, mode }) => {
break;
}
F(cache, "managedPaths", () => {
const match = /^(.+?[\\/]node_modules)[\\/]/.exec(
// eslint-disable-next-line node/no-extraneous-require
require.resolve("watchpack")
);
if (match) {
return [match[1]];
if (process.versions.pnp === "3") {
const match = /^(.+?)[\\/]cache[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
require.resolve("watchpack")
);
if (match) {
return [path.resolve(match[1], "unplugged")];
}
} else {
const match = /^(.+?[\\/]node_modules)[\\/]/.exec(
// eslint-disable-next-line node/no-extraneous-require
require.resolve("watchpack")
);
if (match) {
return [match[1]];
}
}
return [];
});
F(cache, "immutablePaths", () => {
// @ts-ignore
if (process.versions.pnp === "1") {
const match = /^(.+?[\\/]v4)[\\/]npm-watchpack-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec(
require.resolve("watchpack")
@ -212,6 +221,13 @@ const applyCacheDefaults = (cache, { name, mode }) => {
if (match) {
return [match[1]];
}
} else if (process.versions.pnp === "3") {
const match = /^(.+?)[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
require.resolve("watchpack")
);
if (match) {
return [match[1]];
}
}
return [];
});