-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Use "paths" in tsconfig.json and jsconfig.json #10014
base: main
Are you sure you want to change the base?
Changes from all commits
17de5d1
624fe16
50fdee6
bbc3423
62db52c
3c54eaf
6074968
bfe1be1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,6 @@ function verifyTypeScriptSetup() { | |
: 'react', | ||
reason: 'to support the new JSX transform in React 17', | ||
}, | ||
paths: { value: undefined, reason: 'aliased imports are not supported' }, | ||
}; | ||
|
||
const formatDiagnosticHost = { | ||
|
@@ -165,6 +164,7 @@ function verifyTypeScriptSetup() { | |
getNewLine: () => os.EOL, | ||
}; | ||
|
||
const errors = []; | ||
const messages = []; | ||
let appTsConfig; | ||
let parsedTsConfig; | ||
|
@@ -260,6 +260,44 @@ function verifyTypeScriptSetup() { | |
); | ||
} | ||
|
||
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. Should also probably warn if a user for whatever reason decides to use more than one path (eg: 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. Thanks, I've just done this. I tried implementing multiple path support first but it seems like Webpack 4 does not support this. Webpack 5 does though so when CRA moves to that we can add this feature. I've now created an |
||
if (appTsConfig.compilerOptions.paths != null) { | ||
if ( | ||
semver.lt(ts.version, '4.1.0') && | ||
appTsConfig.compilerOptions.baseUrl == null | ||
) { | ||
errors.push( | ||
`${chalk.cyan('paths')} requires ${chalk.cyan('baseUrl')} to be set` | ||
); | ||
} | ||
// Webpack 4 cannot support multiple locations | ||
for (const path of Object.keys(appTsConfig.compilerOptions.paths)) { | ||
const values = appTsConfig.compilerOptions.paths[path]; | ||
|
||
if (!Array.isArray(values) || values.length > 1) { | ||
errors.push( | ||
`Each path in ${chalk.cyan( | ||
'paths' | ||
)} must have an array with only one location` | ||
); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (errors.length > 0) { | ||
console.error( | ||
chalk.bold( | ||
'The following errors need fixing in your', | ||
chalk.cyan('tsconfig.json') | ||
) | ||
); | ||
errors.forEach(error => { | ||
console.error(' - ' + error); | ||
}); | ||
console.error(); | ||
process.exit(1); | ||
} | ||
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 to allow for the fact that TypeScript 4.1 does not need |
||
|
||
if (messages.length > 0) { | ||
if (firstTimeSetup) { | ||
console.log( | ||
|
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.
All the changes I've made in this file should equally be applied to any
jsconfig.json
that is being used. However, there is no file that does at the moment. Should we have averifyJavaScriptSetup.js
? 👀