Skip to content

Commit 4a6b0da

Browse files
committed
Fix tests and place watchApi usage behind experimentalWatchApi option
1 parent 7add160 commit 4a6b0da

File tree

12 files changed

+26
-18
lines changed

12 files changed

+26
-18
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v3.3.0
4+
5+
- [Added support for the new watch api of TypeScript compiler.](https://github.com/TypeStrong/ts-loader/pull/685) nb This feature has been placed behind a new `experimentalWatchApi` option until it has been thoroughly tested. All being well it is likely to become the default behaviour for ts-loader in future - thanks @sheetalkamat!
6+
37
## v3.2.0
48

59
- [Add new loader option `contextAsConfigBasePath`](https://github.com/TypeStrong/ts-loader/pull/681) - thanks @christiantinauer

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"scripts": {
@@ -64,7 +64,7 @@
6464
"mkdirp": "^0.5.1",
6565
"mocha": "^4.0.0",
6666
"rimraf": "^2.6.2",
67-
"typescript": "^2.7.0-rc",
67+
"typescript": "^2.7.0-dev.20180120",
6868
"webpack": "^3.6.0"
6969
}
7070
}

src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function getLoaderOptions(loader: Webpack) {
111111
}
112112

113113
type ValidLoaderOptions = keyof LoaderOptions;
114-
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'contextAsConfigBasePath', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs' /* DEPRECATED */, 'onlyCompileBundledFiles', 'happyPackMode', 'getCustomTransformers'];
114+
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'contextAsConfigBasePath', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs' /* DEPRECATED */, 'onlyCompileBundledFiles', 'happyPackMode', 'getCustomTransformers', 'experimentalWatchApi'];
115115

116116
/**
117117
* Validate the supplied loader options.
@@ -140,7 +140,6 @@ function makeLoaderOptions(instanceName: string, configFileOptions: Partial<Load
140140
logInfoToStdOut: false,
141141
compiler: 'typescript',
142142
configFile: 'tsconfig.json',
143-
contextAsConfigBasePath: false,
144143
transpileOnly: false,
145144
compilerOptions: {},
146145
appendTsSuffixTo: [],
@@ -149,7 +148,9 @@ function makeLoaderOptions(instanceName: string, configFileOptions: Partial<Load
149148
entryFileCannotBeJs: false,
150149
happyPackMode: false,
151150
colors: true,
152-
onlyCompileBundledFiles: false
151+
onlyCompileBundledFiles: false,
152+
// When the watch API usage stabilises look to remove this option and make watch usage the default behaviour when available
153+
experimentalWatchApi: false
153154
} as Partial<LoaderOptions>, configFileOptions, loaderOptions);
154155

155156
options.ignoreDiagnostics = arrify(options.ignoreDiagnostics).map(Number);

src/instances.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ function successfulTypeScriptInstance(
167167
colors
168168
};
169169

170-
if (compiler.createWatchProgram) {
171-
console.log("Using watch api");
170+
if (loaderOptions.experimentalWatchApi && compiler.createWatchProgram) {
171+
log.logInfo("Using watch api");
172+
172173
// If there is api available for watch, use it instead of language service
173174
const watchHost = makeWatchHost(scriptRegex, log, loader, instance, loaderOptions.appendTsSuffixTo, loaderOptions.appendTsxSuffixTo);
174175
instance.watchOfFilesAndCompilerOptions = compiler.createWatchProgram(watchHost);

src/interfaces.ts

+2
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ export interface LoaderOptions {
278278
instance: string;
279279
compiler: string;
280280
configFile: string;
281+
/** DEPRECATED */
281282
contextAsConfigBasePath: boolean;
282283
transpileOnly: boolean;
283284
ignoreDiagnostics: number[];
@@ -291,6 +292,7 @@ export interface LoaderOptions {
291292
entryFileCannotBeJs: boolean;
292293
happyPackMode: boolean;
293294
getCustomTransformers?(): typescript.CustomTransformers | undefined;
295+
experimentalWatchApi: boolean;
294296
}
295297

296298
export interface TSFile {

test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.5/bundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
/* 0 */
6868
/***/ (function(module, exports) {
6969

70-
throw new Error("Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption\n\nPlease take a look at the options you are supplying; the following are valid options:\nsilent / logLevel / logInfoToStdOut / instance / compiler / contextAsConfigBasePath / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers\n\n at validateLoaderOptions (C:/source/ts-loader/dist/index.js:92:19)\n at getLoaderOptions (C:/source/ts-loader/dist/index.js:75:5)\n at Object.loader (C:/source/ts-loader/dist/index.js:23:19)");
70+
throw new Error("Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption\n\nPlease take a look at the options you are supplying; the following are valid options:\nsilent / logLevel / logInfoToStdOut / instance / compiler / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers\n\n at validateLoaderOptions (C:/source/ts-loader/dist/index.js:92:19)\n at getLoaderOptions (C:/source/ts-loader/dist/index.js:75:5)\n at Object.loader (C:/source/ts-loader/dist/index.js:23:19)");
7171

7272
/***/ })
7373
/******/ ]);

test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.5/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ERROR in ./.test/validateLoaderOptionNames/app.ts
66
Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption
77

88
Please take a look at the options you are supplying; the following are valid options:
9-
silent / logLevel / logInfoToStdOut / instance / compiler / contextAsConfigBasePath / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers
9+
silent / logLevel / logInfoToStdOut / instance / compiler / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers
1010

1111
at validateLoaderOptions (dist\index.js:92:19)
1212
at getLoaderOptions (dist\index.js:75:5)

test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.6/bundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
/* 0 */
6868
/***/ (function(module, exports) {
6969

70-
throw new Error("Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption\n\nPlease take a look at the options you are supplying; the following are valid options:\nsilent / logLevel / logInfoToStdOut / instance / compiler / contextAsConfigBasePath / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers\n\n at validateLoaderOptions (C:/source/ts-loader/dist/index.js:92:19)\n at getLoaderOptions (C:/source/ts-loader/dist/index.js:75:5)\n at Object.loader (C:/source/ts-loader/dist/index.js:23:19)");
70+
throw new Error("Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption\n\nPlease take a look at the options you are supplying; the following are valid options:\nsilent / logLevel / logInfoToStdOut / instance / compiler / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers\n\n at validateLoaderOptions (C:/source/ts-loader/dist/index.js:92:19)\n at getLoaderOptions (C:/source/ts-loader/dist/index.js:75:5)\n at Object.loader (C:/source/ts-loader/dist/index.js:23:19)");
7171

7272
/***/ })
7373
/******/ ]);

test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.6/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ERROR in ./.test/validateLoaderOptionNames/app.ts
66
Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption
77

88
Please take a look at the options you are supplying; the following are valid options:
9-
silent / logLevel / logInfoToStdOut / instance / compiler / contextAsConfigBasePath / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers
9+
silent / logLevel / logInfoToStdOut / instance / compiler / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers
1010

1111
at validateLoaderOptions (dist\index.js:92:19)
1212
at getLoaderOptions (dist\index.js:75:5)

test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.7/bundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
/* 0 */
6868
/***/ (function(module, exports) {
6969

70-
throw new Error("Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption\n\nPlease take a look at the options you are supplying; the following are valid options:\nsilent / logLevel / logInfoToStdOut / instance / compiler / contextAsConfigBasePath / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers\n\n at validateLoaderOptions (C:/source/ts-loader/dist/index.js:92:19)\n at getLoaderOptions (C:/source/ts-loader/dist/index.js:75:5)\n at Object.loader (C:/source/ts-loader/dist/index.js:23:19)");
70+
throw new Error("Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption\n\nPlease take a look at the options you are supplying; the following are valid options:\nsilent / logLevel / logInfoToStdOut / instance / compiler / contextAsConfigBasePath / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers / experimentalWatchApi\n\n at validateLoaderOptions (C:/source/ts-loader/dist/index.js:92:19)\n at getLoaderOptions (C:/source/ts-loader/dist/index.js:75:5)\n at Object.loader (C:/source/ts-loader/dist/index.js:23:19)");
7171

7272
/***/ })
7373
/******/ ]);

test/comparison-tests/validateLoaderOptionNames/expectedOutput-2.7/output.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Asset Size Chunks Chunk Names
2-
bundle.js 3.17 kB 0 [emitted] main
3-
[0] ./.test/validateLoaderOptionNames/app.ts 702 bytes {0} [built] [failed] [1 error]
2+
bundle.js 3.22 kB 0 [emitted] main
3+
[0] ./.test/validateLoaderOptionNames/app.ts 751 bytes {0} [built] [failed] [1 error]
44

55
ERROR in ./.test/validateLoaderOptionNames/app.ts
66
Module build failed: Error: ts-loader was supplied with an unexpected loader option: notRealOption
77

88
Please take a look at the options you are supplying; the following are valid options:
9-
silent / logLevel / logInfoToStdOut / instance / compiler / contextAsConfigBasePath / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers
9+
silent / logLevel / logInfoToStdOut / instance / compiler / contextAsConfigBasePath / configFile / transpileOnly / ignoreDiagnostics / errorFormatter / colors / compilerOptions / appendTsSuffixTo / appendTsxSuffixTo / entryFileCannotBeJs / onlyCompileBundledFiles / happyPackMode / getCustomTransformers / experimentalWatchApi
1010

1111
at validateLoaderOptions (dist\index.js:92:19)
1212
at getLoaderOptions (dist\index.js:75:5)

yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -3362,9 +3362,9 @@ type-is@~1.6.15:
33623362
media-typer "0.3.0"
33633363
mime-types "~2.1.15"
33643364

3365-
typescript@^2.7.0-rc:
3366-
version "2.7.0-rc"
3367-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.0-rc.tgz#bf86a065a3a0be1e072c3fb7d64e8976f33b8365"
3365+
typescript@^2.7.0-dev.20180120:
3366+
version "2.7.0-dev.20180120"
3367+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.0-dev.20180120.tgz#64470f65617bc9cdd95b23dcedf210f83aa73771"
33683368

33693369
33703370
version "3.1.6"

0 commit comments

Comments
 (0)