Skip to content
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

Fix getOptionsHash when two options has different props but same values. #1170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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