Skip to content

Commit aa8723a

Browse files
lneveupimterry
authored andcommitted
Add support for Yarn 3 (standard-things#902)
Since Yarn 3, Plug'n'Play hooks file is now called .pnp.cjs
1 parent 618b6f0 commit aa8723a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/hook/pnp.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ import Module from "../module.js"
44

55
import { sep } from "../safe/path.js"
66

7+
import escapeRegExp from "../util/escape-regexp.js"
8+
79
const {
810
FLAGS
911
} = ENV
1012

11-
const YARN_PNP_FILENAME = ".pnp.js"
13+
const yarnPnpFilenameRegExp = new RegExp(`${escapeRegExp(sep)}\\.pnp\\.c?js$`)
1214

1315
function hook(pnp) {
1416
const { _cache } = Module
1517

1618
for (const name in _cache) {
17-
if (name.endsWith(sep + YARN_PNP_FILENAME)) {
19+
if (yarnPnpFilenameRegExp.test(name)) {
1820
Reflect.deleteProperty(_cache, name)
1921
break
2022
}
2123
}
2224

2325
for (const request of FLAGS.preloadModules) {
24-
if (request.endsWith(sep + YARN_PNP_FILENAME)) {
26+
if (yarnPnpFilenameRegExp.test(request)) {
2527
Module._preloadModules([request])
2628
pnp._resolveFilename = Module._resolveFilename
2729
break

0 commit comments

Comments
 (0)