Skip to content

Commit 19ff89e

Browse files
authored
Merge pull request #194 from webpack/bugfix/pnp-dep
PnP tracks dependency to the .pnp.js file
2 parents 83f9a90 + b7055a0 commit 19ff89e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/PnpPlugin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,26 @@ module.exports = class PnpPlugin {
2323
const issuer = `${request.path}/`;
2424

2525
let resolution;
26+
let apiResolution;
2627
try {
2728
resolution = this.pnpApi.resolveToUnqualified(req, issuer, {
2829
considerBuiltins: false
2930
});
31+
if (resolveContext.fileDependencies) {
32+
apiResolution = this.pnpApi.resolveToUnqualified("pnpapi", issuer, {
33+
considerBuiltins: false
34+
});
35+
}
3036
} catch (error) {
3137
return callback(error);
3238
}
3339

3440
if (resolution === req) return callback();
3541

42+
if (apiResolution) {
43+
resolveContext.fileDependencies.add(apiResolution);
44+
}
45+
3646
const obj = {
3747
...request,
3848
path: resolution,

test/pnp.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ describe("pnp", () => {
6262
done();
6363
});
6464
});
65+
it("should track dependency to the pnp api", done => {
66+
pnpApi.mocks.set(
67+
"pkg/dir/index.js",
68+
path.resolve(fixture, "pkg/dir/index.js")
69+
);
70+
pnpApi.mocks.set("pnpapi", path.resolve(fixture, ".pnp.js"));
71+
const fileDependencies = new Set();
72+
resolver.resolve(
73+
{},
74+
__dirname,
75+
"pkg/dir/index.js",
76+
{ fileDependencies },
77+
(err, result) => {
78+
if (err) return done(err);
79+
result.should.equal(path.resolve(fixture, "pkg/dir/index.js"));
80+
Array.from(fileDependencies).should.containEql(
81+
path.resolve(fixture, ".pnp.js")
82+
);
83+
done();
84+
}
85+
);
86+
});
6587
it("should resolve module names with package.json", done => {
6688
pnpApi.mocks.set("pkg", path.resolve(fixture, "pkg"));
6789
resolver.resolve({}, __dirname, "pkg", {}, (err, result) => {

0 commit comments

Comments
 (0)