Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix getOptionsHash when two options has different props but same valu…
…es. (#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>
  • Loading branch information
meowtec and johnnyreilly committed Aug 24, 2020
1 parent 562b631 commit 0e64ceb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog

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

## v8.0.2

* [Fix 2 issues with experimentalWatchApi](https://github.com/TypeStrong/ts-loader/pull/1159) - thanks @appzuka
Expand Down
13 changes: 11 additions & 2 deletions README.md
Expand Up @@ -498,14 +498,23 @@ of your code.
#### appendTsSuffixTo
| Type | Default Value |
|------|--------------|
| `RegExp[]` | `[]`|
| `(RegExp | string)[]` | `[]`|

#### appendTsxSuffixTo
| Type | Default Value |
|------|--------------|
| `RegExp[]` | `[]`|
| `(RegExp | string)[]` | `[]`|

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.
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.

```js
// change this:
{ appendTsSuffixTo: [/\.vue$/] }
// to:
{ appendTsSuffixTo: ['\\.vue$'] }
```


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.)

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "8.0.2",
"version": "8.0.3",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Expand Up @@ -160,9 +160,10 @@ function setModuleMeta(
*/
function getOptionsHash(loaderOptions: LoaderOptions) {
const hash = crypto.createHash('sha256');
Object.values(loaderOptions).map((v: any) => {
if (v) {
hash.update(v.toString());
Object.keys(loaderOptions).forEach(key => {
const value = loaderOptions[key];
if (value) {
hash.update(key + value.toString());
}
});
return hash.digest('hex').substring(0, 16);
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces.ts
Expand Up @@ -266,8 +266,8 @@ export interface LoaderOptions {
onlyCompileBundledFiles: boolean;
colors: boolean;
compilerOptions: typescript.CompilerOptions;
appendTsSuffixTo: RegExp[];
appendTsxSuffixTo: RegExp[];
appendTsSuffixTo: (RegExp | string)[];
appendTsxSuffixTo: (RegExp | string)[];
happyPackMode: boolean;
getCustomTransformers:
| string
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Expand Up @@ -137,7 +137,7 @@ export function makeError(
}

export function appendSuffixIfMatch(
patterns: RegExp[],
patterns: (RegExp | string)[],
filePath: string,
suffix: string
): string {
Expand All @@ -152,7 +152,7 @@ export function appendSuffixIfMatch(
}

export function appendSuffixesIfMatch(
suffixDict: { [suffix: string]: RegExp[] },
suffixDict: { [suffix: string]: (RegExp | string)[] },
filePath: string
): string {
let amendedPath = filePath;
Expand Down

0 comments on commit 0e64ceb

Please sign in to comment.