Skip to content

Commit 0be3a8a

Browse files
committed
Merge in compilerOptions prior to parseJsonConfigFileContent() call
1 parent 79ce006 commit 0be3a8a

File tree

4 files changed

+67
-38
lines changed

4 files changed

+67
-38
lines changed

src/IncrementalChecker.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ export class IncrementalChecker {
7272
}
7373

7474
static loadProgramConfig(configFile: string, compilerOptions: object) {
75+
const tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
76+
77+
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
78+
tsconfig.compilerOptions = {
79+
...tsconfig.compilerOptions,
80+
...compilerOptions
81+
};
82+
7583
const parsed = ts.parseJsonConfigFileContent(
76-
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
77-
Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, {
78-
isolatedModules: false
79-
}),
84+
tsconfig,
8085
ts.sys,
8186
path.dirname(configFile)
8287
);
8388

84-
parsed.options = { ...parsed.options, ...compilerOptions };
85-
8689
return parsed;
8790
}
8891

src/VueProgram.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,21 @@ export class VueProgram {
3030
}
3131
};
3232

33+
const tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
34+
35+
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
36+
tsconfig.compilerOptions = {
37+
...tsconfig.compilerOptions,
38+
...compilerOptions
39+
};
40+
3341
const parsed = ts.parseJsonConfigFileContent(
34-
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
35-
Object.assign(ts.readConfigFile(configFile, ts.sys.readFile).config, {
36-
isolatedModules: false
37-
}),
42+
tsconfig,
3843
parseConfigHost,
3944
path.dirname(configFile)
4045
);
4146

4247
parsed.options.allowNonTsExtensions = true;
43-
parsed.options = { ...parsed.options, ...compilerOptions };
4448

4549
return parsed;
4650
}

test/unit/IncrementalChecker.spec.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,28 @@ var sinon = require('sinon');
88

99
describe('[UNIT] IncrementalChecker', function() {
1010
var IncrementalChecker;
11+
var parseJsonConfigFileContentStub;
1112

1213
beforeEach(function() {
13-
var parseJsonConfigFileContentStub = sinon.stub().returns({
14-
options: {
15-
foo: true
16-
}
17-
});
18-
var readConfigFileStub = sinon.stub().returns({
19-
config: {}
14+
parseJsonConfigFileContentStub = sinon.spy(function(tsconfig) {
15+
return {
16+
options: tsconfig.compilerOptions
17+
};
2018
});
2119

20+
var readConfigFile = function() {
21+
return {
22+
config: {
23+
compilerOptions: {
24+
foo: true
25+
}
26+
}
27+
};
28+
};
29+
2230
mockRequire('typescript', {
2331
parseJsonConfigFileContent: parseJsonConfigFileContentStub,
24-
readConfigFile: readConfigFileStub,
32+
readConfigFile,
2533
sys: {}
2634
});
2735

@@ -68,14 +76,17 @@ describe('[UNIT] IncrementalChecker', function() {
6876
});
6977

7078
describe('loadProgramConfig', function() {
71-
it('merges compilerOptions into returned options', function() {
72-
var result = IncrementalChecker.loadProgramConfig('tsconfig.foo.json', {
79+
it('merges compilerOptions into config file options', function() {
80+
IncrementalChecker.loadProgramConfig('tsconfig.foo.json', {
7381
bar: false
7482
});
7583

76-
expect(result.options).to.deep.equal({
77-
foo: true,
78-
bar: false
84+
expect(parseJsonConfigFileContentStub.calledOnce).to.equal(true);
85+
expect(parseJsonConfigFileContentStub.args[0][0]).to.deep.equal({
86+
compilerOptions: {
87+
foo: true,
88+
bar: false
89+
}
7990
});
8091
});
8192
});

test/unit/VueProgram.spec.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,28 @@ var sinon = require('sinon');
77

88
describe('[UNIT] VueProgram', function() {
99
var VueProgram;
10+
var parseJsonConfigFileContentStub;
1011

1112
beforeEach(function() {
12-
var parseJsonConfigFileContentStub = sinon.stub().returns({
13-
options: {
14-
foo: true
15-
}
16-
});
17-
var readConfigFileStub = sinon.stub().returns({
18-
config: {}
13+
parseJsonConfigFileContentStub = sinon.spy(function(tsconfig) {
14+
return {
15+
options: tsconfig.compilerOptions
16+
};
1917
});
2018

19+
var readConfigFile = function() {
20+
return {
21+
config: {
22+
compilerOptions: {
23+
foo: true
24+
}
25+
}
26+
};
27+
};
28+
2129
mockRequire('typescript', {
2230
parseJsonConfigFileContent: parseJsonConfigFileContentStub,
23-
readConfigFile: readConfigFileStub,
31+
readConfigFile,
2432
sys: {},
2533
ScriptKind: ts.ScriptKind
2634
});
@@ -165,15 +173,18 @@ describe('[UNIT] VueProgram', function() {
165173
expect(result.options.allowNonTsExtensions).to.equal(true);
166174
});
167175

168-
it('merges compilerOptions into returned options', function() {
169-
var result = VueProgram.loadProgramConfig('tsconfig.foo.json', {
176+
it('merges compilerOptions into config file options', function() {
177+
VueProgram.loadProgramConfig('tsconfig.foo.json', {
170178
bar: false
171179
});
172180

173-
expect(result.options).to.deep.equal({
174-
foo: true,
175-
bar: false,
176-
allowNonTsExtensions: true
181+
expect(parseJsonConfigFileContentStub.calledOnce).to.equal(true);
182+
expect(parseJsonConfigFileContentStub.args[0][0]).to.deep.equal({
183+
compilerOptions: {
184+
allowNonTsExtensions: true,
185+
foo: true,
186+
bar: false
187+
}
177188
});
178189
});
179190
});

0 commit comments

Comments
 (0)