Skip to content

Commit 1a517f6

Browse files
feat: added the tsconfig option for the resolver options (#20400)
1 parent 7b3b0f7 commit 1a517f6

File tree

9 files changed

+282
-14
lines changed

9 files changed

+282
-14
lines changed

.changeset/perky-masks-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": minor
3+
---
4+
5+
Added the `tsconfig` option for the `resolver` options (replacement for `tsconfig-paths-webpack-plugin`). Can be `false` (disabled), `true` (use the default `tsconfig.json` file to search for it), a string path to `tsconfig.json`, or an object with `configFile` and `references` options.

declarations/WebpackOptions.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,22 @@ export interface ResolveOptions {
17461746
* Enable resolving symlinks to the original location.
17471747
*/
17481748
symlinks?: boolean;
1749+
/**
1750+
* TypeScript config for paths mapping. Can be `false` (disabled), `true` (use default `tsconfig.json`), a string path to `tsconfig.json`, or an object with `configFile` and `references` options.
1751+
*/
1752+
tsconfig?:
1753+
| boolean
1754+
| string
1755+
| {
1756+
/**
1757+
* A path to the tsconfig file.
1758+
*/
1759+
configFile?: string;
1760+
/**
1761+
* References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths.
1762+
*/
1763+
references?: "auto" | string;
1764+
};
17491765
/**
17501766
* Enable caching of successfully resolved requests (cache entries are not revalidated).
17511767
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"acorn-import-phases": "^1.0.3",
9696
"browserslist": "^4.28.1",
9797
"chrome-trace-event": "^1.0.2",
98-
"enhanced-resolve": "^5.17.4",
98+
"enhanced-resolve": "^5.19.0",
9999
"es-module-lexer": "^2.0.0",
100100
"eslint-scope": "5.1.1",
101101
"events": "^3.2.0",

schemas/WebpackOptions.check.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemas/WebpackOptions.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4513,6 +4513,38 @@
45134513
"description": "Enable resolving symlinks to the original location.",
45144514
"type": "boolean"
45154515
},
4516+
"tsconfig": {
4517+
"description": "TypeScript config for paths mapping. Can be `false` (disabled), `true` (use default `tsconfig.json`), a string path to `tsconfig.json`, or an object with `configFile` and `references` options.",
4518+
"anyOf": [
4519+
{
4520+
"type": "boolean"
4521+
},
4522+
{
4523+
"type": "string"
4524+
},
4525+
{
4526+
"type": "object",
4527+
"additionalProperties": false,
4528+
"properties": {
4529+
"configFile": {
4530+
"description": "A path to the tsconfig file.",
4531+
"type": "string"
4532+
},
4533+
"references": {
4534+
"description": "References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths.",
4535+
"anyOf": [
4536+
{
4537+
"enum": ["auto"]
4538+
},
4539+
{
4540+
"type": "string"
4541+
}
4542+
]
4543+
}
4544+
}
4545+
}
4546+
]
4547+
},
45164548
"unsafeCache": {
45174549
"description": "Enable caching of successfully resolved requests (cache entries are not revalidated).",
45184550
"anyOf": [

test/Validation.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("Validation", () => {
5151
});
5252
};
5353

54-
const createTestCaseWithoutError = (name, config, fn) => {
54+
const createTestCaseWithoutError = (name, config) => {
5555
it(`should success validation for ${name}`, () => {
5656
let errored;
5757

@@ -656,10 +656,31 @@ describe("Validation", () => {
656656
`)
657657
);
658658

659+
createTestCaseOnlyValidate(
660+
"resolve invalid",
661+
{ resolve: { tsconfig: 10 } },
662+
(msg) =>
663+
expect(msg).toMatchInlineSnapshot(`
664+
"Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
665+
- configuration.resolve.tsconfig should be one of these:
666+
object { alias?, aliasFields?, byDependency?, cache?, cachePredicate?, cacheWithContext?, conditionNames?, descriptionFiles?, enforceExtension?, exportsFields?, extensionAlias?, extensions?, fallback?, fileSystem?, fullySpecified?, importsFields?, mainFields?, mainFiles?, modules?, plugins?, preferAbsolute?, preferRelative?, resolver?, restrictions?, roots?, symlinks?, tsconfig?, unsafeCache?, useSyncFileSystemCalls? }
667+
-> TypeScript config for paths mapping. Can be \`false\` (disabled), \`true\` (use default \`tsconfig.json\`), a string path to \`tsconfig.json\`, or an object with \`configFile\` and \`references\` options.
668+
Details:
669+
* configuration.resolve.tsconfig should be a boolean.
670+
* configuration.resolve.tsconfig should be a string.
671+
* configuration.resolve.tsconfig should be an object:
672+
object { configFile?, references? }"
673+
`)
674+
);
675+
659676
createTestCaseWithoutError("experiments", {
660677
experiments: { unknown: true }
661678
});
662679

680+
createTestCaseWithoutError("resolve", {
681+
resolve: { tsconfig: true }
682+
});
683+
663684
describe("did you mean", () => {
664685
createTestCase(
665686
"module.rules",

test/__snapshots__/Cli.basictest.js.snap

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9260,6 +9260,60 @@ Object {
92609260
"multiple": false,
92619261
"simpleType": "boolean",
92629262
},
9263+
"resolve-loader-tsconfig": Object {
9264+
"configs": Array [
9265+
Object {
9266+
"description": "TypeScript config for paths mapping. Can be \`false\` (disabled), \`true\` (use default \`tsconfig.json\`), a string path to \`tsconfig.json\`, or an object with \`configFile\` and \`references\` options.",
9267+
"multiple": false,
9268+
"path": "resolveLoader.tsconfig",
9269+
"type": "boolean",
9270+
},
9271+
Object {
9272+
"description": "TypeScript config for paths mapping. Can be \`false\` (disabled), \`true\` (use default \`tsconfig.json\`), a string path to \`tsconfig.json\`, or an object with \`configFile\` and \`references\` options.",
9273+
"multiple": false,
9274+
"path": "resolveLoader.tsconfig",
9275+
"type": "string",
9276+
},
9277+
],
9278+
"description": "TypeScript config for paths mapping. Can be \`false\` (disabled), \`true\` (use default \`tsconfig.json\`), a string path to \`tsconfig.json\`, or an object with \`configFile\` and \`references\` options.",
9279+
"multiple": false,
9280+
"simpleType": "string",
9281+
},
9282+
"resolve-loader-tsconfig-config-file": Object {
9283+
"configs": Array [
9284+
Object {
9285+
"description": "A path to the tsconfig file.",
9286+
"multiple": false,
9287+
"path": "resolveLoader.tsconfig.configFile",
9288+
"type": "string",
9289+
},
9290+
],
9291+
"description": "A path to the tsconfig file.",
9292+
"multiple": false,
9293+
"simpleType": "string",
9294+
},
9295+
"resolve-loader-tsconfig-references": Object {
9296+
"configs": Array [
9297+
Object {
9298+
"description": "References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths.",
9299+
"multiple": false,
9300+
"path": "resolveLoader.tsconfig.references",
9301+
"type": "enum",
9302+
"values": Array [
9303+
"auto",
9304+
],
9305+
},
9306+
Object {
9307+
"description": "References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths.",
9308+
"multiple": false,
9309+
"path": "resolveLoader.tsconfig.references",
9310+
"type": "string",
9311+
},
9312+
],
9313+
"description": "References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths.",
9314+
"multiple": false,
9315+
"simpleType": "string",
9316+
},
92639317
"resolve-loader-unsafe-cache": Object {
92649318
"configs": Array [
92659319
Object {
@@ -9461,6 +9515,60 @@ Object {
94619515
"multiple": false,
94629516
"simpleType": "boolean",
94639517
},
9518+
"resolve-tsconfig": Object {
9519+
"configs": Array [
9520+
Object {
9521+
"description": "TypeScript config for paths mapping. Can be \`false\` (disabled), \`true\` (use default \`tsconfig.json\`), a string path to \`tsconfig.json\`, or an object with \`configFile\` and \`references\` options.",
9522+
"multiple": false,
9523+
"path": "resolve.tsconfig",
9524+
"type": "boolean",
9525+
},
9526+
Object {
9527+
"description": "TypeScript config for paths mapping. Can be \`false\` (disabled), \`true\` (use default \`tsconfig.json\`), a string path to \`tsconfig.json\`, or an object with \`configFile\` and \`references\` options.",
9528+
"multiple": false,
9529+
"path": "resolve.tsconfig",
9530+
"type": "string",
9531+
},
9532+
],
9533+
"description": "TypeScript config for paths mapping. Can be \`false\` (disabled), \`true\` (use default \`tsconfig.json\`), a string path to \`tsconfig.json\`, or an object with \`configFile\` and \`references\` options.",
9534+
"multiple": false,
9535+
"simpleType": "string",
9536+
},
9537+
"resolve-tsconfig-config-file": Object {
9538+
"configs": Array [
9539+
Object {
9540+
"description": "A path to the tsconfig file.",
9541+
"multiple": false,
9542+
"path": "resolve.tsconfig.configFile",
9543+
"type": "string",
9544+
},
9545+
],
9546+
"description": "A path to the tsconfig file.",
9547+
"multiple": false,
9548+
"simpleType": "string",
9549+
},
9550+
"resolve-tsconfig-references": Object {
9551+
"configs": Array [
9552+
Object {
9553+
"description": "References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths.",
9554+
"multiple": false,
9555+
"path": "resolve.tsconfig.references",
9556+
"type": "enum",
9557+
"values": Array [
9558+
"auto",
9559+
],
9560+
},
9561+
Object {
9562+
"description": "References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths.",
9563+
"multiple": false,
9564+
"path": "resolve.tsconfig.references",
9565+
"type": "string",
9566+
},
9567+
],
9568+
"description": "References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths.",
9569+
"multiple": false,
9570+
"simpleType": "string",
9571+
},
94649572
"resolve-unsafe-cache": Object {
94659573
"configs": Array [
94669574
Object {

0 commit comments

Comments
 (0)