Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface TSInstance {
loaderOptions: LoaderOptions;
files: TSFiles;
languageService?: typescript.LanguageService;
version?: number;
}

interface TSInstances {
Expand Down Expand Up @@ -188,7 +189,8 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
compilerOptions: null,
loaderOptions,
files,
languageService: null
languageService: null,
version: 0
};

var compilerOptions: typescript.CompilerOptions = {
Expand Down Expand Up @@ -323,6 +325,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {

// Create the TypeScript language service
var servicesHost = {
getProjectVersion: () => instance.version+'',
getScriptFileNames: () => Object.keys(files).filter(filePath => scriptRegex.test(filePath)),
getScriptVersion: fileName => {
fileName = path.normalize(fileName);
Expand Down Expand Up @@ -387,7 +390,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {

var languageService = instance.languageService = compiler.createLanguageService(servicesHost, compiler.createDocumentRegistry());

var compilerOptionDiagnostics = languageService.getCompilerOptionsDiagnostics();
var getCompilerOptionDiagnostics = true;

loader._compiler.plugin("after-compile", (compilation, callback) => {
let stats = compilation.stats;
Expand All @@ -411,10 +414,12 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
removeTSLoaderErrors(compilation.errors);

// handle compiler option errors after the first compile
pushArray(
compilation.errors,
formatErrors(compilerOptionDiagnostics, instance, {file: configFilePath || 'tsconfig.json'}));
compilerOptionDiagnostics = [];
if (getCompilerOptionDiagnostics) {
getCompilerOptionDiagnostics = false;
pushArray(
compilation.errors,
formatErrors(languageService.getCompilerOptionsDiagnostics(), instance, {file: configFilePath || 'tsconfig.json'}));
}

// build map of all modules based on normalized filename
// this is used for quick-lookup when trying to find modules
Expand Down Expand Up @@ -460,7 +465,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
pushArray(compilation.errors, formatErrors(errors, instance, {file: filePath}));
}
});

callback();
});

Expand All @@ -475,6 +480,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
if (file) {
file.text = fs.readFileSync(filePath, {encoding: 'utf8'});
file.version++;
instance.version++;
}
});
cb()
Expand Down Expand Up @@ -515,13 +521,18 @@ function loader(contents) {
return;
}

// Update file version
// Update file contents
var file = instance.files[filePath]
if (!file) {
file = instance.files[filePath] = <TSFile>{ version: 0 };
}
file.version++;


if (file.text !== contents) {
file.version++;
file.text = contents;
instance.version++;
}

var outputText: string, sourceMapText: string, diagnostics: typescript.Diagnostic[] = [];

if (options.transpileOnly) {
Expand All @@ -538,10 +549,7 @@ function loader(contents) {
}
else {
let langService = instance.languageService;

// Update file contents
file.text = contents;


// Make this file dependent on *all* definition files in the program
this.clearDependencies();
this.addDependency(filePath);
Expand Down
61 changes: 0 additions & 61 deletions test/declarationWatch/expectedOutput/patch0/bundle.js

This file was deleted.

6 changes: 3 additions & 3 deletions test/declarationWatch/expectedOutput/patch0/output.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.58 kB 0 [emitted] main
chunk {0} bundle.js (main) 112 bytes [rendered]
Asset Size Chunks Chunk Names
bundle.js 1.58 kB 0 main
chunk {0} bundle.js (main) 112 bytes
[0] ./.test/declarationWatch/app.ts 67 bytes {0} [built] [1 error]
[1] ./.test/declarationWatch/dep.ts 45 bytes {0} [built] [1 error]

Expand Down
61 changes: 0 additions & 61 deletions test/declarationWatch/expectedOutput/patch1/bundle.js

This file was deleted.

6 changes: 3 additions & 3 deletions test/declarationWatch/expectedOutput/patch1/output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Asset Size Chunks Chunk Names
bundle.js 1.58 kB 0 [emitted] main
chunk {0} bundle.js (main) 112 bytes [rendered]
Asset Size Chunks Chunk Names
bundle.js 1.58 kB 0 main
chunk {0} bundle.js (main) 112 bytes
[0] ./.test/declarationWatch/app.ts 67 bytes {0} [built]
[1] ./.test/declarationWatch/dep.ts 45 bytes {0} [built]