mirror of https://github.com/webpack/webpack.git
Merge pull request #10405 from webpack/feature/pnp-3
improve caching support for PnP version 3 (yarn 2 berry)
This commit is contained in:
commit
f3d6bdd455
|
|
@ -5,6 +5,9 @@ declare namespace NodeJS {
|
|||
interface Process {
|
||||
binding(internalModule: string): any;
|
||||
}
|
||||
interface ProcessVersions {
|
||||
pnp: "1" | "3";
|
||||
}
|
||||
}
|
||||
|
||||
declare module "neo-async" {
|
||||
|
|
|
|||
|
|
@ -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 [];
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue