Skip to content

Commit b8c8e0f

Browse files
authored
Merge pull request #266 from webpack/bugfix/pnp-fully-specified
remove fullySpecified when resolving a module request with PnP
2 parents 1489524 + e5575b1 commit b8c8e0f

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

lib/PnpPlugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ module.exports = class PnpPlugin {
7777
...request,
7878
path: resolution,
7979
request: undefined,
80-
ignoreSymlinks: true
80+
ignoreSymlinks: true,
81+
fullySpecified:
82+
request.fullySpecified && !/^(@[^/]+\/)?[^/]+$/.test(req)
8183
};
8284
resolver.doResolve(
8385
target,

test/pnp.js

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ try {
2626

2727
describe("pnp", () => {
2828
let pnpApi;
29+
let resolverFuzzy;
2930
let resolver;
3031
if (isAdmin) {
3132
before(() => {
@@ -49,7 +50,7 @@ describe("pnp", () => {
4950
}
5051
}
5152
});
52-
resolver = ResolverFactory.createResolver({
53+
resolverFuzzy = ResolverFactory.createResolver({
5354
extensions: [".ts", ".js"],
5455
aliasFields: ["browser"],
5556
fileSystem: nodeFileSystem,
@@ -59,6 +60,16 @@ describe("pnp", () => {
5960
pnpApi,
6061
modules: ["node_modules", path.resolve(fixture, "../pnp-a")]
6162
});
63+
resolver = ResolverFactory.createResolver({
64+
aliasFields: ["browser"],
65+
fileSystem: nodeFileSystem,
66+
fullySpecified: true,
67+
alias: {
68+
alias: path.resolve(fixture, "pkg")
69+
},
70+
pnpApi,
71+
modules: ["node_modules", path.resolve(fixture, "../pnp-a")]
72+
});
6273
});
6374
it("should resolve by going through the pnp api", done => {
6475
pnpApi.mocks.set(
@@ -71,6 +82,13 @@ describe("pnp", () => {
7182
done();
7283
});
7384
});
85+
it("should not resolve a not fully specified request when fullySpecified is set", done => {
86+
pnpApi.mocks.set("pkg/dir/index", path.resolve(fixture, "pkg/dir/index"));
87+
resolver.resolve({}, __dirname, "pkg/dir/index", {}, (err, result) => {
88+
err.should.be.instanceof(Error);
89+
done();
90+
});
91+
});
7492
it("should track dependency to the pnp api", done => {
7593
pnpApi.mocks.set(
7694
"pkg/dir/index.js",
@@ -114,11 +132,19 @@ describe("pnp", () => {
114132
isAdmin
115133
? done => {
116134
pnpApi.mocks.set("pkg/symlink", path.resolve(fixture, "pkg/symlink"));
117-
resolver.resolve({}, __dirname, "pkg/symlink", {}, (err, result) => {
118-
if (err) return done(err);
119-
result.should.equal(path.resolve(fixture, "pkg/symlink/index.js"));
120-
done();
121-
});
135+
resolverFuzzy.resolve(
136+
{},
137+
__dirname,
138+
"pkg/symlink",
139+
{},
140+
(err, result) => {
141+
if (err) return done(err);
142+
result.should.equal(
143+
path.resolve(fixture, "pkg/symlink/index.js")
144+
);
145+
done();
146+
}
147+
);
122148
}
123149
: undefined
124150
);
@@ -127,7 +153,7 @@ describe("pnp", () => {
127153
"@user/pkg/typescript",
128154
path.resolve(fixture, "pkg/typescript")
129155
);
130-
resolver.resolve(
156+
resolverFuzzy.resolve(
131157
{},
132158
__dirname,
133159
"@user/pkg/typescript",
@@ -144,13 +170,19 @@ describe("pnp", () => {
144170
"pkg/package-alias",
145171
path.resolve(fixture, "pkg/package-alias")
146172
);
147-
resolver.resolve({}, __dirname, "pkg/package-alias", {}, (err, result) => {
148-
if (err) return done(err);
149-
result.should.equal(
150-
path.resolve(fixture, "pkg/package-alias/browser.js")
151-
);
152-
done();
153-
});
173+
resolverFuzzy.resolve(
174+
{},
175+
__dirname,
176+
"pkg/package-alias",
177+
{},
178+
(err, result) => {
179+
if (err) return done(err);
180+
result.should.equal(
181+
path.resolve(fixture, "pkg/package-alias/browser.js")
182+
);
183+
done();
184+
}
185+
);
154186
});
155187
it("should prefer normal modules over pnp resolves", done => {
156188
pnpApi.mocks.set("m1/a.js", path.resolve(fixture, "pkg/a.js"));

0 commit comments

Comments
 (0)