2018-09-11 03:38:28 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2018-09-11 03:38:28 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as path from 'path';
|
2021-02-04 06:46:51 -05:00
|
|
|
import * as ts from 'typescript';
|
2018-09-11 03:38:28 -04:00
|
|
|
|
|
|
|
import {readConfiguration} from '../src/perform_compile';
|
|
|
|
|
2020-04-07 15:43:43 -04:00
|
|
|
import {setup, TestSupport} from './test_support';
|
2018-09-11 03:38:28 -04:00
|
|
|
|
|
|
|
describe('perform_compile', () => {
|
|
|
|
let support: TestSupport;
|
|
|
|
let basePath: string;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
support = setup();
|
|
|
|
basePath = support.basePath;
|
|
|
|
});
|
|
|
|
|
|
|
|
function writeSomeConfigs() {
|
|
|
|
support.writeFiles({
|
|
|
|
'tsconfig-level-1.json': `{
|
|
|
|
"extends": "./tsconfig-level-2.json",
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"annotateForClosureCompiler": true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
'tsconfig-level-2.json': `{
|
|
|
|
"extends": "./tsconfig-level-3.json",
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"skipMetadataEmit": true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
'tsconfig-level-3.json': `{
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"annotateForClosureCompiler": false,
|
|
|
|
"annotationsAs": "decorators"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should merge tsconfig "angularCompilerOptions"', () => {
|
|
|
|
writeSomeConfigs();
|
|
|
|
const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json'));
|
|
|
|
expect(options.annotateForClosureCompiler).toBe(true);
|
|
|
|
expect(options.annotationsAs).toBe('decorators');
|
|
|
|
expect(options.skipMetadataEmit).toBe(true);
|
|
|
|
});
|
|
|
|
|
2019-08-21 02:46:40 -04:00
|
|
|
it(`should return 'enableIvy: true' when enableIvy is not defined in "angularCompilerOptions"`,
|
|
|
|
() => {
|
|
|
|
writeSomeConfigs();
|
|
|
|
const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json'));
|
|
|
|
expect(options.enableIvy).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should return 'enableIvy: false' when enableIvy is disabled in "angularCompilerOptions"`,
|
|
|
|
() => {
|
|
|
|
writeSomeConfigs();
|
|
|
|
support.writeFiles({
|
|
|
|
'tsconfig-level-3.json': `{
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"enableIvy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json'));
|
|
|
|
expect(options.enableIvy).toBe(false);
|
|
|
|
});
|
2021-02-04 06:46:51 -05:00
|
|
|
|
|
|
|
it('should override options defined in tsconfig with those defined in `existingOptions`', () => {
|
|
|
|
support.writeFiles({
|
|
|
|
'tsconfig-level-1.json': `{
|
|
|
|
"compilerOptions": {
|
|
|
|
"target": "es2020"
|
|
|
|
},
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"annotateForClosureCompiler": true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
});
|
|
|
|
|
|
|
|
const {options} = readConfiguration(
|
|
|
|
path.resolve(basePath, 'tsconfig-level-1.json'),
|
|
|
|
{annotateForClosureCompiler: false, target: ts.ScriptTarget.ES2015, enableIvy: false});
|
|
|
|
|
|
|
|
expect(options).toEqual(jasmine.objectContaining({
|
|
|
|
enableIvy: false,
|
|
|
|
target: ts.ScriptTarget.ES2015,
|
|
|
|
annotateForClosureCompiler: false,
|
|
|
|
}));
|
|
|
|
});
|
2021-02-08 10:35:08 -05:00
|
|
|
|
2021-03-29 23:24:03 -04:00
|
|
|
it('should merge tsconfig "angularCompilerOptions" when extends points to node package', () => {
|
2021-02-08 10:35:08 -05:00
|
|
|
support.writeFiles({
|
|
|
|
'tsconfig-level-1.json': `{
|
|
|
|
"extends": "@angular-ru/tsconfig",
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"enableIvy": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
'node_modules/@angular-ru/tsconfig/tsconfig.json': `{
|
|
|
|
"compilerOptions": {
|
|
|
|
"strict": true
|
|
|
|
},
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"skipMetadataEmit": true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
'node_modules/@angular-ru/tsconfig/package.json': `{
|
|
|
|
"name": "@angular-ru/tsconfig",
|
|
|
|
"version": "0.0.0",
|
|
|
|
"main": "./tsconfig.json"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json'));
|
|
|
|
expect(options).toEqual(jasmine.objectContaining({
|
|
|
|
strict: true,
|
|
|
|
skipMetadataEmit: true,
|
|
|
|
enableIvy: false,
|
|
|
|
}));
|
|
|
|
});
|
2021-03-29 23:24:03 -04:00
|
|
|
|
|
|
|
it('should merge tsconfig "angularCompilerOptions" when extends points to an extension less non rooted file',
|
|
|
|
() => {
|
|
|
|
support.writeFiles({
|
|
|
|
'tsconfig-level-1.json': `{
|
|
|
|
"extends": "@1stg/tsconfig/angular",
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"enableIvy": false
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
'node_modules/@1stg/tsconfig/angular.json': `{
|
|
|
|
"compilerOptions": {
|
|
|
|
"strict": true
|
|
|
|
},
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"skipMetadataEmit": true
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
'node_modules/@1stg/tsconfig/package.json': `{
|
|
|
|
"name": "@1stg/tsconfig",
|
|
|
|
"version": "0.0.0"
|
|
|
|
}`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json'));
|
|
|
|
expect(options).toEqual(jasmine.objectContaining({
|
|
|
|
strict: true,
|
|
|
|
skipMetadataEmit: true,
|
|
|
|
enableIvy: false,
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should merge tsconfig "angularCompilerOptions" when extends points to a non rooted file without json extension',
|
|
|
|
() => {
|
|
|
|
support.writeFiles({
|
|
|
|
'tsconfig-level-1.json': `{
|
|
|
|
"extends": "./tsconfig.app",
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"enableIvy": false
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
'tsconfig.app.json': `{
|
|
|
|
"compilerOptions": {
|
|
|
|
"strict": true
|
|
|
|
},
|
|
|
|
"angularCompilerOptions": {
|
|
|
|
"skipMetadataEmit": true
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json'));
|
|
|
|
expect(options).toEqual(jasmine.objectContaining({
|
|
|
|
strict: true,
|
|
|
|
skipMetadataEmit: true,
|
|
|
|
enableIvy: false,
|
|
|
|
}));
|
|
|
|
});
|
2018-09-11 03:38:28 -04:00
|
|
|
});
|