-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Path mapping module resolution #5728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
d2fd643
6bed1ba
6844285
cccdd44
25cc97b
62370a0
0377e7a
4e3cba1
cc25f2c
0d0de5a
f18e203
9a9b51f
0130c23
bb9498f
2dbf621
6a63c0d
a81c875
c644fb3
57e7615
6b4bc43
5327868
c06be3a
a399208
39a50fa
635201c
73c94d0
3d4e220
39ad077
9d828e3
cb3e93f
2b2b150
8a8ed0a
adacad3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,10 +250,12 @@ namespace ts { | |
| name: "moduleResolution", | ||
| type: { | ||
| "node": ModuleResolutionKind.NodeJs, | ||
| "classic": ModuleResolutionKind.Classic | ||
| "classic": ModuleResolutionKind.Classic, | ||
| // name is lowercased so we can still use hasProperty(userValue.toLower()) to check if user has entered the right value | ||
| "baseurl": ModuleResolutionKind.BaseUrl, | ||
| }, | ||
| description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, | ||
| error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic, | ||
| error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_classic_or_baseUrl, | ||
| }, | ||
| { | ||
| name: "allowUnusedLabels", | ||
|
|
@@ -280,6 +282,31 @@ namespace ts { | |
| type: "boolean", | ||
| description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file | ||
| }, | ||
| { | ||
| name: "baseUrl", | ||
| type: "string", | ||
| isFilePath: true, | ||
| description: Diagnostics.Base_directory_to_resolve_relative_module_names | ||
| }, | ||
| { | ||
| // this option can only be specified in tsconfig.json | ||
| // use type = object to copy the value as-is | ||
| name: "paths", | ||
| type: "object", | ||
| isTSConfigOnly: true | ||
| }, | ||
| { | ||
| // this option can only be specified in tsconfig.json | ||
| // use type = object to copy the value as-is | ||
| name: "rootDirs", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave a line note |
||
| type: "object", | ||
| isTSConfigOnly: true | ||
| }, | ||
| { | ||
| name: "traceModuleResolution", | ||
| type: "boolean", | ||
| description: Diagnostics.Enable_tracing_of_the_module_resolution_process | ||
| }, | ||
| { | ||
| name: "allowJs", | ||
| type: "boolean", | ||
|
|
@@ -344,31 +371,36 @@ namespace ts { | |
| if (hasProperty(optionNameMap, s)) { | ||
| const opt = optionNameMap[s]; | ||
|
|
||
| // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). | ||
| if (!args[i] && opt.type !== "boolean") { | ||
| errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, opt.name)); | ||
| if (opt.isTSConfigOnly) { | ||
| errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file, opt.name)); | ||
| } | ||
| else { | ||
| // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). | ||
| if (!args[i] && opt.type !== "boolean") { | ||
| errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, opt.name)); | ||
| } | ||
|
|
||
| switch (opt.type) { | ||
| case "number": | ||
| options[opt.name] = parseInt(args[i++]); | ||
| break; | ||
| case "boolean": | ||
| options[opt.name] = true; | ||
| break; | ||
| case "string": | ||
| options[opt.name] = args[i++] || ""; | ||
| break; | ||
| // If not a primitive, the possible types are specified in what is effectively a map of options. | ||
| default: | ||
| let map = <Map<number>>opt.type; | ||
| let key = (args[i++] || "").toLowerCase(); | ||
| if (hasProperty(map, key)) { | ||
| options[opt.name] = map[key]; | ||
| } | ||
| else { | ||
| errors.push(createCompilerDiagnostic((<CommandLineOptionOfCustomType>opt).error)); | ||
| } | ||
| switch (opt.type) { | ||
| case "number": | ||
| options[opt.name] = parseInt(args[i++]); | ||
| break; | ||
| case "boolean": | ||
| options[opt.name] = true; | ||
| break; | ||
| case "string": | ||
| options[opt.name] = args[i++] || ""; | ||
| break; | ||
| // If not a primitive, the possible types are specified in what is effectively a map of options. | ||
| default: | ||
| let map = <Map<number>>opt.type; | ||
| let key = (args[i++] || "").toLowerCase(); | ||
| if (hasProperty(map, key)) { | ||
| options[opt.name] = map[key]; | ||
| } | ||
| else { | ||
| errors.push(createCompilerDiagnostic((<CommandLineOptionOfCustomType>opt).error)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else { | ||
|
|
@@ -471,7 +503,6 @@ namespace ts { | |
| return output; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Parse the contents of a config file (tsconfig.json). | ||
| * @param json The contents of the config file to parse | ||
|
|
@@ -483,12 +514,15 @@ namespace ts { | |
| const { options: optionsFromJsonConfigFile, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath); | ||
|
|
||
| const options = extend(existingOptions, optionsFromJsonConfigFile); | ||
| // set basePath as inferredBaseUrl so baseUrl module resolution strategy can still work even if user have not specified baseUrl explicity | ||
| options.inferredBaseUrl = basePath; | ||
|
|
||
| return { | ||
| options, | ||
| fileNames: getFileNames(), | ||
| errors | ||
| }; | ||
|
|
||
| function getFileNames(): string[] { | ||
| let fileNames: string[] = []; | ||
| if (hasProperty(json, "files")) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -410,6 +410,17 @@ namespace ts { | |
| }; | ||
| } | ||
|
|
||
| /* internal */ | ||
| export function formatMessage(dummy: any, message: DiagnosticMessage): string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need the first argument here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is necessary to skip |
||
| let text = getLocaleSpecificMessage(message); | ||
|
|
||
| if (arguments.length > 2) { | ||
| text = formatStringFromArgs(text, arguments, 2); | ||
| } | ||
|
|
||
| return text; | ||
| } | ||
|
|
||
| export function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic; | ||
| export function createCompilerDiagnostic(message: DiagnosticMessage): Diagnostic { | ||
| let text = getLocaleSpecificMessage(message); | ||
|
|
@@ -860,4 +871,4 @@ namespace ts { | |
| } | ||
| return copiedList; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove "baseURL" from the message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done