Skip to content

Commit

Permalink
Merge in compilerOptions prior to parseJsonConfigFileContent() call
Browse files Browse the repository at this point in the history
  • Loading branch information
ianschmitz committed Oct 26, 2018
1 parent 79ce006 commit 0be3a8a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 38 deletions.
15 changes: 9 additions & 6 deletions src/IncrementalChecker.ts
Expand Up @@ -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;
}

Expand Down
14 changes: 9 additions & 5 deletions src/VueProgram.ts
Expand Up @@ -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;
}
Expand Down
37 changes: 24 additions & 13 deletions test/unit/IncrementalChecker.spec.js
Expand Up @@ -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: {}
});

Expand Down Expand Up @@ -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
}
});
});
});
Expand Down
39 changes: 25 additions & 14 deletions test/unit/VueProgram.spec.js
Expand Up @@ -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
});
Expand Down Expand Up @@ -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
}
});
});
});
Expand Down

0 comments on commit 0be3a8a

Please sign in to comment.