Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 0f01603

Browse files
alan-agius4danbucholtz
authored andcommitted
fix(build): fix extends in ts-config.json (#910)
1 parent be30a40 commit 0f01603

File tree

3 files changed

+52
-55
lines changed

3 files changed

+52
-55
lines changed

src/build.spec.ts

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as Constants from './util/constants';
22
import { BuildContext } from './util/interfaces';
33
import * as helpers from './util/helpers';
4-
import * as build from './build';
4+
import * as build from './build';
55

66
import * as bundle from './bundle';
77
import * as copy from './copy';
8-
import * as clean from './clean';
8+
import * as clean from './clean';
99
import * as lint from './lint';
1010
import * as minify from './minify';
1111
import * as ngc from './ngc';
@@ -17,16 +17,15 @@ import * as transpile from './transpile';
1717
describe('build', () => {
1818
beforeEach(() => {
1919
spyOn(clean, 'clean');
20-
spyOn(helpers, 'readFileAsync').and.callFake(() => {
21-
return Promise.resolve(`{
22-
"compilerOptions": {
20+
spyOn(helpers, helpers.readFileAsync.name).and.returnValue(Promise.resolve());
21+
spyOn(transpile, transpile.getTsConfigAsync.name).and.callFake(() => {
22+
return Promise.resolve({
23+
"options": {
2324
"sourceMap": true
2425
}
25-
}
26-
`);
26+
});
2727
});
2828

29-
3029
spyOn(bundle, bundle.bundle.name).and.returnValue(Promise.resolve());
3130
spyOn(copy, copy.copy.name).and.returnValue(Promise.resolve());
3231
spyOn(minify, minify.minifyCss.name).and.returnValue(Promise.resolve());
@@ -135,61 +134,58 @@ describe('test project requirements before building', () => {
135134
spyOn(helpers, 'readFileAsync').and.returnValue(Promise.reject(error));
136135

137136
return build.build({}).catch((e) => {
138-
expect(helpers.readFileAsync).toHaveBeenCalledTimes(2);
137+
expect(helpers.readFileAsync).toHaveBeenCalledTimes(1);
139138
expect(e).toEqual(error);
140139
});
141140
});
142141

143142
it('should fail if IONIC_TS_CONFIG file does not exist', () => {
144143
process.env[Constants.ENV_APP_ENTRY_POINT] = 'src/app/main.ts';
145144
process.env[Constants.ENV_TS_CONFIG] = 'tsConfig.js';
146-
const error = new Error('App entry point was not found');
145+
const error = new Error('Config was not found');
147146

148-
spyOn(helpers, 'readFileAsync').and.callFake((filePath: string) => {
149-
if (filePath === 'src/app/main.ts') {
150-
return Promise.resolve('allgood');
151-
}
152-
return Promise.reject(error);
153-
});
147+
spyOn(helpers, helpers.readFileAsync.name).and.returnValues(Promise.resolve());
148+
spyOn(transpile, transpile.getTsConfigAsync.name).and.returnValues(Promise.reject(error));
154149

155150
return build.build({}).catch((e) => {
156-
expect(helpers.readFileAsync).toHaveBeenCalledTimes(2);
151+
expect(transpile.getTsConfigAsync).toHaveBeenCalledTimes(1);
152+
expect(helpers.readFileAsync).toHaveBeenCalledTimes(1);
157153
expect(e).toEqual(error);
158154
});
159155
});
160156

161157
it('should fail fataly if IONIC_TS_CONFIG file does not contain valid JSON', () => {
162158
process.env[Constants.ENV_APP_ENTRY_POINT] = 'src/app/main.ts';
163159
process.env[Constants.ENV_TS_CONFIG] = 'tsConfig.js';
164-
spyOn(helpers, 'readFileAsync').and.callFake(() => {
160+
spyOn(transpile, transpile.getTsConfigAsync.name).and.callFake(() => {
165161
return Promise.resolve(`{
166-
"compilerOptions" {
162+
"options" {
167163
"sourceMap": false
168164
}
169165
}
170166
`);
171167
});
172168

173169
return build.build({}).catch((e) => {
174-
expect(helpers.readFileAsync).toHaveBeenCalledTimes(2);
170+
expect(transpile.getTsConfigAsync).toHaveBeenCalledTimes(1);
175171
expect(e.isFatal).toBeTruthy();
176172
});
177173
});
178174

179175
it('should fail fataly if IONIC_TS_CONFIG file does not contain compilerOptions.sourceMap === true', () => {
180176
process.env[Constants.ENV_APP_ENTRY_POINT] = 'src/app/main.ts';
181177
process.env[Constants.ENV_TS_CONFIG] = 'tsConfig.js';
182-
spyOn(helpers, 'readFileAsync').and.callFake(() => {
178+
spyOn(transpile, transpile.getTsConfigAsync.name).and.callFake(() => {
183179
return Promise.resolve(`{
184-
"compilerOptions": {
180+
"options": {
185181
"sourceMap": false
186182
}
187183
}
188184
`);
189185
});
190186

191187
return build.build({}).catch((e) => {
192-
expect(helpers.readFileAsync).toHaveBeenCalledTimes(2);
188+
expect(transpile.getTsConfigAsync).toHaveBeenCalledTimes(1);
193189
expect(e.isFatal).toBeTruthy();
194190
});
195191
});
@@ -208,18 +204,17 @@ describe('test project requirements before building', () => {
208204
spyOn(postprocess, postprocess.postprocess.name).and.returnValue(Promise.resolve());
209205
spyOn(preprocess, preprocess.preprocess.name).and.returnValue(Promise.resolve());
210206
spyOn(sass, sass.sass.name).and.returnValue(Promise.resolve());
207+
spyOn(helpers, helpers.readFileAsync.name).and.returnValue(Promise.resolve());
211208
spyOn(transpile, transpile.transpile.name).and.returnValue(Promise.resolve());
212-
spyOn(helpers, helpers.readFileAsync.name).and.callFake(() => {
213-
return Promise.resolve(`{
214-
"compilerOptions": {
215-
"sourceMap": true
216-
}
209+
spyOn(transpile, transpile.getTsConfigAsync.name).and.returnValue(Promise.resolve({
210+
"options": {
211+
"sourceMap": true
217212
}
218-
`);
219-
});
213+
}));
220214

221215
return build.build({}).then(() => {
222-
expect(helpers.readFileAsync).toHaveBeenCalledTimes(2);
216+
expect(transpile.getTsConfigAsync).toHaveBeenCalledTimes(1);
217+
expect(helpers.readFileAsync).toHaveBeenCalledTimes(1);
223218
});
224219
});
225220
});

src/build.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { lint, lintUpdate } from './lint';
1010
import { Logger } from './logger/logger';
1111
import { minifyCss, minifyJs } from './minify';
1212
import { ngc } from './ngc';
13+
import { getTsConfigAsync, TsConfig } from './transpile';
1314
import { postprocess } from './postprocess';
1415
import { preprocess, preprocessUpdate } from './preprocess';
1516
import { sass, sassUpdate } from './sass';
@@ -34,20 +35,20 @@ export function build(context: BuildContext) {
3435
function buildWorker(context: BuildContext) {
3536
return Promise.resolve().then(() => {
3637
// load any 100% required files to ensure they exist
37-
return validateRequiredFilesExist();
38+
return validateRequiredFilesExist(context);
3839
})
39-
.then(([_, tsConfigContents]) => {
40-
return validateTsConfigSettings(tsConfigContents);
41-
})
42-
.then(() => {
43-
return buildProject(context);
44-
});
40+
.then(([_, tsConfigContents]) => {
41+
return validateTsConfigSettings(tsConfigContents);
42+
})
43+
.then(() => {
44+
return buildProject(context);
45+
});
4546
}
4647

47-
function validateRequiredFilesExist() {
48+
function validateRequiredFilesExist(context: BuildContext) {
4849
return Promise.all([
4950
readFileAsync(process.env[Constants.ENV_APP_ENTRY_POINT]),
50-
readFileAsync(process.env[Constants.ENV_TS_CONFIG])
51+
getTsConfigAsync(context, process.env[Constants.ENV_TS_CONFIG])
5152
]).catch((error) => {
5253
if (error.code === 'ENOENT' && error.path === process.env[Constants.ENV_APP_ENTRY_POINT]) {
5354
error = new BuildError(`${error.path} was not found. The "main.dev.ts" and "main.prod.ts" files have been deprecated. Please create a new file "main.ts" containing the content of "main.dev.ts", and then delete the deprecated files.
@@ -68,15 +69,12 @@ function validateRequiredFilesExist() {
6869
});
6970
}
7071

71-
function validateTsConfigSettings(tsConfigFileContents: string) {
72+
function validateTsConfigSettings(tsConfigFileContents: TsConfig) {
7273

7374
return new Promise((resolve, reject) => {
7475
try {
75-
const tsConfigJson = JSON.parse(tsConfigFileContents);
76-
const isValid = tsConfigJson.hasOwnProperty('compilerOptions') &&
77-
tsConfigJson.compilerOptions.hasOwnProperty('sourceMap') &&
78-
tsConfigJson.compilerOptions.sourceMap === true;
79-
76+
const isValid = tsConfigFileContents.options &&
77+
tsConfigFileContents.options.sourceMap === true;
8078
if (!isValid) {
8179
const error = new BuildError(['The "tsconfig.json" file must have compilerOptions.sourceMap set to true.',
8280
'For more information please see the default Ionic project tsconfig.json file here:',
@@ -285,7 +283,7 @@ function buildUpdateTasks(changedFiles: ChangedFile[], context: BuildContext) {
285283
filePath: outputCssFile
286284
};
287285

288-
context.fileCache.set(outputCssFile, { path: outputCssFile, content: outputCssFile});
286+
context.fileCache.set(outputCssFile, { path: outputCssFile, content: outputCssFile });
289287

290288
resolveValue.changedFiles.push(changedFile);
291289
});
@@ -299,7 +297,7 @@ function buildUpdateTasks(changedFiles: ChangedFile[], context: BuildContext) {
299297
filePath: outputCssFile
300298
};
301299

302-
context.fileCache.set(outputCssFile, { path: outputCssFile, content: outputCssFile});
300+
context.fileCache.set(outputCssFile, { path: outputCssFile, content: outputCssFile });
303301

304302
resolveValue.changedFiles.push(changedFile);
305303
});
@@ -324,7 +322,7 @@ function loadFiles(changedFiles: ChangedFile[], context: BuildContext) {
324322
const promise = readFileAsync(changedFile.filePath);
325323
promises.push(promise);
326324
promise.then((content: string) => {
327-
context.fileCache.set(changedFile.filePath, { path: changedFile.filePath, content: content});
325+
context.fileCache.set(changedFile.filePath, { path: changedFile.filePath, content: content });
328326
});
329327
}
330328
}

src/transpile.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function transpileWorker(context: BuildContext, workerConfig: TranspileWo
8888
tsConfig.options.sourceMap = false;
8989

9090
} else {
91-
// build the ts source maps if the bundler is going to use source maps
91+
// build the ts source maps if the bundler is going to use source maps
9292
tsConfig.options.sourceMap = buildJsSourceMaps(context);
9393
}
9494

@@ -113,8 +113,8 @@ export function transpileWorker(context: BuildContext, workerConfig: TranspileWo
113113
cachedProgram = program;
114114

115115
const tsDiagnostics = program.getSyntacticDiagnostics()
116-
.concat(program.getSemanticDiagnostics())
117-
.concat(program.getOptionsDiagnostics());
116+
.concat(program.getSemanticDiagnostics())
117+
.concat(program.getOptionsDiagnostics());
118118

119119
const diagnostics = runTypeScriptDiagnostics(context, tsDiagnostics);
120120

@@ -300,6 +300,10 @@ function writeTranspiledFilesCallback(fileCache: FileCache, sourcePath: string,
300300
}
301301
}
302302

303+
export async function getTsConfigAsync(context: BuildContext, tsConfigPath?: string): Promise<TsConfig> {
304+
return await getTsConfig(context, tsConfigPath);
305+
}
306+
303307
export function getTsConfig(context: BuildContext, tsConfigPath?: string): TsConfig {
304308
let config: TsConfig = null;
305309
tsConfigPath = tsConfigPath || getTsConfigPath(context);
@@ -317,9 +321,9 @@ export function getTsConfig(context: BuildContext, tsConfigPath?: string): TsCon
317321

318322
} else {
319323
const parsedConfig = ts.parseJsonConfigFileContent(
320-
tsConfigFile.config,
321-
ts.sys, context.rootDir,
322-
{}, tsConfigPath);
324+
tsConfigFile.config,
325+
ts.sys, context.rootDir,
326+
{}, tsConfigPath);
323327

324328
const diagnostics = runTypeScriptDiagnostics(context, parsedConfig.errors);
325329

0 commit comments

Comments
 (0)