Skip to content

Commit d1b5b6d

Browse files
fix: resolve aliases pointing at a package directory ending in .js (#21542)
* fix: resolve aliases pointing at a package directory ending in .js The `.js` -> `.ts` extensionAlias that `experiments.typescript` installs made `ExtensionAliasPlugin` resolve such a request as an exact file only, so a package directory named `pkg.js` became unreachable. Fixed in enhanced-resolve (webpack/enhanced-resolve#641); take the release and add a regression test. * test: pin the extensionAlias in the regression case Relying on the `experiments.typescript` "auto" default made the case a no-op below Node.js 22.6, where the alias is never installed. * build: lock enhanced-resolve 5.24.4
1 parent 9cdcc57 commit d1b5b6d

7 files changed

Lines changed: 50 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Resolve aliases pointing at a package directory whose name ends with `.js` again.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"acorn": "^8.16.0",
106106
"browserslist": "^4.28.1",
107107
"chrome-trace-event": "^1.0.2",
108-
"enhanced-resolve": "^5.24.2",
108+
"enhanced-resolve": "^5.24.4",
109109
"es-module-lexer": "^2.1.0",
110110
"eslint-scope": "5.1.1",
111111
"events": "^3.2.0",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
it("should resolve an aliased package directory whose name ends with .js", () => {
4+
expect(require("vendor/pkg.js")).toBe("pkg.js");
5+
});

‎test/configCases/typescript/alias-to-package-directory/node_modules/pkg.js/lib/main.js‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/configCases/typescript/alias-to-package-directory/node_modules/pkg.js/package.json‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
3+
const path = require("path");
4+
5+
// The `.js` -> `.ts` extensionAlias that `experiments.typescript` installs must
6+
// not make a package directory named `pkg.js` unresolvable. Pinned here instead
7+
// of via `experiments.typescript` so the case also runs below Node.js 22.6.
8+
9+
/** @type {import("../../../../").Configuration} */
10+
module.exports = {
11+
entry: "./index.js",
12+
resolve: {
13+
alias: {
14+
vendor: path.resolve(__dirname, "node_modules")
15+
},
16+
extensionAlias: {
17+
".js": [".js", ".ts"],
18+
".cjs": [".cjs", ".cts"],
19+
".mjs": [".mjs", ".mts"]
20+
}
21+
}
22+
};

‎yarn.lock‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4288,14 +4288,22 @@ encodeurl@^2.0.0:
42884288
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-2.0.0.tgz#7b8ea898077d7e409d3ac45474ea38eaf0857a58"
42894289
integrity sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==
42904290

4291-
enhanced-resolve@^5.17.1, enhanced-resolve@^5.24.2:
4291+
enhanced-resolve@^5.17.1:
42924292
version "5.24.3"
42934293
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.24.3.tgz#406bbf1ec20971265a30254f08030fce6a8207fe"
42944294
integrity sha512-PwKooW9JUzh5chmYfHM3IQl5OkK2u2Nm011MgeZrss3JmFraUx/fqrf78kk8GUMYoibx/14MdwTl/1WKkG7TpQ==
42954295
dependencies:
42964296
graceful-fs "^4.2.4"
42974297
tapable "^2.3.3"
42984298

4299+
enhanced-resolve@^5.24.4:
4300+
version "5.24.4"
4301+
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.24.4.tgz#ec1f25ece12a37cc299762b412fa6c5962d52227"
4302+
integrity sha512-GVoi+ICHocoOIU7qVVM48wOJziRsqrsyqlI0Ce0LdowRn6v3bcH2zUa9kp85ncx0nwIb9/HOCOLS3fdThDG/XQ==
4303+
dependencies:
4304+
graceful-fs "^4.2.4"
4305+
tapable "^2.3.3"
4306+
42994307
enquirer@^2.4.1:
43004308
version "2.4.1"
43014309
resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.4.1.tgz#93334b3fbd74fc7097b224ab4a8fb7e40bf4ae56"

0 commit comments

Comments
 (0)