diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b98823e..72d2ba63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.4.13 + +* [Merge in `compilerOptions` prior to calling `parseJsonConfigFileContent`](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/176) (#176) + ## v0.4.12 * [Add `compilerOptions` option](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/173) (#173) diff --git a/package.json b/package.json index ca410d34..bec26d17 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fork-ts-checker-webpack-plugin", - "version": "0.4.12", + "version": "0.4.13", "description": "Runs typescript type checker and linter on separate process.", "main": "lib/index.js", "types": "lib/types/index.d.ts", diff --git a/src/IncrementalChecker.ts b/src/IncrementalChecker.ts index 69b626ad..cc549547 100644 --- a/src/IncrementalChecker.ts +++ b/src/IncrementalChecker.ts @@ -72,17 +72,20 @@ export class IncrementalChecker { } static loadProgramConfig(configFile: string, compilerOptions: object) { + const tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config; + + tsconfig.compilerOptions = tsconfig.compilerOptions || {}; + tsconfig.compilerOptions = { + ...tsconfig.compilerOptions, + ...compilerOptions + }; + const parsed = ts.parseJsonConfigFileContent( - // Regardless of the setting in the tsconfig.json we want isolatedModules to be false - Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, { - isolatedModules: false - }), + tsconfig, ts.sys, path.dirname(configFile) ); - parsed.options = { ...parsed.options, ...compilerOptions }; - return parsed; } diff --git a/src/VueProgram.ts b/src/VueProgram.ts index 9a52f544..f4be2481 100644 --- a/src/VueProgram.ts +++ b/src/VueProgram.ts @@ -30,17 +30,21 @@ export class VueProgram { } }; + const tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config; + + tsconfig.compilerOptions = tsconfig.compilerOptions || {}; + tsconfig.compilerOptions = { + ...tsconfig.compilerOptions, + ...compilerOptions + }; + const parsed = ts.parseJsonConfigFileContent( - // Regardless of the setting in the tsconfig.json we want isolatedModules to be false - Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, { - isolatedModules: false - }), + tsconfig, parseConfigHost, path.dirname(configFile) ); parsed.options.allowNonTsExtensions = true; - parsed.options = { ...parsed.options, ...compilerOptions }; return parsed; } diff --git a/test/unit/IncrementalChecker.spec.js b/test/unit/IncrementalChecker.spec.js index bcb1c3c9..3a32aa71 100644 --- a/test/unit/IncrementalChecker.spec.js +++ b/test/unit/IncrementalChecker.spec.js @@ -8,20 +8,28 @@ var sinon = require('sinon'); describe('[UNIT] IncrementalChecker', function() { var IncrementalChecker; + var parseJsonConfigFileContentStub; beforeEach(function() { - var parseJsonConfigFileContentStub = sinon.stub().returns({ - options: { - foo: true - } - }); - var readConfigFileStub = sinon.stub().returns({ - config: {} + parseJsonConfigFileContentStub = sinon.spy(function(tsconfig) { + return { + options: tsconfig.compilerOptions + }; }); + var readConfigFile = function() { + return { + config: { + compilerOptions: { + foo: true + } + } + }; + }; + mockRequire('typescript', { parseJsonConfigFileContent: parseJsonConfigFileContentStub, - readConfigFile: readConfigFileStub, + readConfigFile, sys: {} }); @@ -68,14 +76,17 @@ describe('[UNIT] IncrementalChecker', function() { }); describe('loadProgramConfig', function() { - it('merges compilerOptions into returned options', function() { - var result = IncrementalChecker.loadProgramConfig('tsconfig.foo.json', { + it('merges compilerOptions into config file options', function() { + IncrementalChecker.loadProgramConfig('tsconfig.foo.json', { bar: false }); - expect(result.options).to.deep.equal({ - foo: true, - bar: false + expect(parseJsonConfigFileContentStub.calledOnce).to.equal(true); + expect(parseJsonConfigFileContentStub.args[0][0]).to.deep.equal({ + compilerOptions: { + foo: true, + bar: false + } }); }); }); diff --git a/test/unit/VueProgram.spec.js b/test/unit/VueProgram.spec.js index 9991cc0d..2b78b27e 100644 --- a/test/unit/VueProgram.spec.js +++ b/test/unit/VueProgram.spec.js @@ -7,20 +7,28 @@ var sinon = require('sinon'); describe('[UNIT] VueProgram', function() { var VueProgram; + var parseJsonConfigFileContentStub; beforeEach(function() { - var parseJsonConfigFileContentStub = sinon.stub().returns({ - options: { - foo: true - } - }); - var readConfigFileStub = sinon.stub().returns({ - config: {} + parseJsonConfigFileContentStub = sinon.spy(function(tsconfig) { + return { + options: tsconfig.compilerOptions + }; }); + var readConfigFile = function() { + return { + config: { + compilerOptions: { + foo: true + } + } + }; + }; + mockRequire('typescript', { parseJsonConfigFileContent: parseJsonConfigFileContentStub, - readConfigFile: readConfigFileStub, + readConfigFile, sys: {}, ScriptKind: ts.ScriptKind }); @@ -165,15 +173,18 @@ describe('[UNIT] VueProgram', function() { expect(result.options.allowNonTsExtensions).to.equal(true); }); - it('merges compilerOptions into returned options', function() { - var result = VueProgram.loadProgramConfig('tsconfig.foo.json', { + it('merges compilerOptions into config file options', function() { + VueProgram.loadProgramConfig('tsconfig.foo.json', { bar: false }); - expect(result.options).to.deep.equal({ - foo: true, - bar: false, - allowNonTsExtensions: true + expect(parseJsonConfigFileContentStub.calledOnce).to.equal(true); + expect(parseJsonConfigFileContentStub.args[0][0]).to.deep.equal({ + compilerOptions: { + allowNonTsExtensions: true, + foo: true, + bar: false + } }); }); });