-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
add appendTsxSuffixTo option #581
Changes from 10 commits
9c3753a
694662a
7042560
e0fb71a
5afa608
e6efd1e
90b66b8
61e3464
9f606c7
5b11cae
e19b1a3
07ffb08
d841e82
75ec7e8
4a0fca6
3a1c6a6
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 |
---|---|---|
|
@@ -26,7 +26,8 @@ function loader(this: interfaces.Webpack, contents: string) { | |
} | ||
|
||
const rawFilePath = path.normalize(this.resourcePath); | ||
const filePath = utils.appendTsSuffixIfMatch(options.appendTsSuffixTo, rawFilePath); | ||
let filePath = utils.appendTsSuffixIfMatch(options.appendTsSuffixTo, rawFilePath); | ||
filePath = utils.appendTsxSuffixIfMatch(options.appendTsxSuffixTo, filePath); | ||
const fileVersion = updateFileInCache(filePath, contents, instance); | ||
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. Could this be 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. I'm sorry i already code that but forgot to save... |
||
|
||
const { outputText, sourceMapText } = options.transpileOnly | ||
|
@@ -83,6 +84,7 @@ function getLoaderOptions(loader: interfaces.Webpack) { | |
visualStudioErrorFormat: false, | ||
compilerOptions: {}, | ||
appendTsSuffixTo: [], | ||
appendTsxSuffixTo: [], | ||
transformers: {}, | ||
entryFileIsJs: false, | ||
happyPackMode: false, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,17 @@ export function appendTsSuffixIfMatch(patterns: RegExp[], path: string): string | |
return path; | ||
} | ||
|
||
export function appendTsxSuffixIfMatch(patterns: RegExp[], path: string): string { | ||
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. Having pondered I think it might make for nicer code to combine Here's my reasoning: Wherever That being the case, I think it might make sense to have an Is that okay with you? I'm quite focused on keeping the source of ts-loader as comprehensible as possible to ease contributions by others. 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. I've just commit. |
||
if (patterns.length > 0) { | ||
for (let regexp of patterns) { | ||
if (path.match(regexp)) { | ||
return path + '.tsx'; | ||
} | ||
} | ||
} | ||
return path; | ||
} | ||
|
||
/** | ||
* Recursively collect all possible dependants of passed file | ||
*/ | ||
|
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.
Come the first uses
rawFilePath
and the second usesfilePath
?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.
So why this:
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.
The only different is when filename is matched by both options.appendTsxSuffixTo and options.appendTsSuffixTo.
In that case, if both part use rawFilePath then
.tsx
append will overwrite.ts
, but i think it should become.ts.tsx
so user may know that their regexes has collision.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.
Right - thanks for that. Is it likely that people will use
appendTsxSuffixTo
andappendTsSuffixTo
together? Or is it an either / or thing?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.
They can use it together if they want (declare at a single place and then reuse for example), i can code it more generic but after consider backward-compability i chose this method.