Skip to content

Commit 0e64ceb

Browse files
Fix getOptionsHash when two options has different props but same values. (#1170)
* Fix getOptionsHash when two options has different props but same values. * Swap map for forEach * fix `appendTsSuffixTo` use `RegExp | string` instead of `RegExp` for correct serialization in `thread-loader` * Bump version v8.0.3 Co-authored-by: John Reilly <johnny_reilly@hotmail.com>
1 parent 562b631 commit 0e64ceb

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v8.0.3
4+
* [Fix the wrong instance caching when using `appendTsSuffixTo` and `appendTsxSuffixTo` together](https://github.com/TypeStrong/ts-loader/pull/1170) - thanks @meowtec
5+
36
## v8.0.2
47

58
* [Fix 2 issues with experimentalWatchApi](https://github.com/TypeStrong/ts-loader/pull/1159) - thanks @appzuka

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,23 @@ of your code.
498498
#### appendTsSuffixTo
499499
| Type | Default Value |
500500
|------|--------------|
501-
| `RegExp[]` | `[]`|
501+
| `(RegExp | string)[]` | `[]`|
502502

503503
#### appendTsxSuffixTo
504504
| Type | Default Value |
505505
|------|--------------|
506-
| `RegExp[]` | `[]`|
506+
| `(RegExp | string)[]` | `[]`|
507507

508508
A list of regular expressions to be matched against filename. If filename matches one of the regular expressions, a `.ts` or `.tsx` suffix will be appended to that filename.
509+
If you're using [HappyPack](https://github.com/amireh/happypack) or [thread-loader](https://github.com/webpack-contrib/thread-loader) with `ts-loader`, you need use the `string` type for the regular expressions, not `RegExp` object.
510+
511+
```js
512+
// change this:
513+
{ appendTsSuffixTo: [/\.vue$/] }
514+
// to:
515+
{ appendTsSuffixTo: ['\\.vue$'] }
516+
```
517+
509518

510519
This is useful for `*.vue` [file format](https://vuejs.org/v2/guide/single-file-components.html) for now. (Probably will benefit from the new single file format in the future.)
511520

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "8.0.2",
3+
"version": "8.0.3",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ function setModuleMeta(
160160
*/
161161
function getOptionsHash(loaderOptions: LoaderOptions) {
162162
const hash = crypto.createHash('sha256');
163-
Object.values(loaderOptions).map((v: any) => {
164-
if (v) {
165-
hash.update(v.toString());
163+
Object.keys(loaderOptions).forEach(key => {
164+
const value = loaderOptions[key];
165+
if (value) {
166+
hash.update(key + value.toString());
166167
}
167168
});
168169
return hash.digest('hex').substring(0, 16);

src/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ export interface LoaderOptions {
266266
onlyCompileBundledFiles: boolean;
267267
colors: boolean;
268268
compilerOptions: typescript.CompilerOptions;
269-
appendTsSuffixTo: RegExp[];
270-
appendTsxSuffixTo: RegExp[];
269+
appendTsSuffixTo: (RegExp | string)[];
270+
appendTsxSuffixTo: (RegExp | string)[];
271271
happyPackMode: boolean;
272272
getCustomTransformers:
273273
| string

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function makeError(
137137
}
138138

139139
export function appendSuffixIfMatch(
140-
patterns: RegExp[],
140+
patterns: (RegExp | string)[],
141141
filePath: string,
142142
suffix: string
143143
): string {
@@ -152,7 +152,7 @@ export function appendSuffixIfMatch(
152152
}
153153

154154
export function appendSuffixesIfMatch(
155-
suffixDict: { [suffix: string]: RegExp[] },
155+
suffixDict: { [suffix: string]: (RegExp | string)[] },
156156
filePath: string
157157
): string {
158158
let amendedPath = filePath;

0 commit comments

Comments
 (0)