mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 03:23:57 +08:00
Since version 10.1 we added declaration maps for local library builds, to improve the DX. With this change we add it to existing project. See: #17920
85 lines
3.0 KiB
TypeScript
85 lines
3.0 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* 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 { EmptyTree } from '@angular-devkit/schematics';
|
|
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
|
|
import { Builders, ProjectType, WorkspaceSchema } from '../../utility/workspace-models';
|
|
|
|
function createWorkSpaceConfig(tree: UnitTestTree) {
|
|
const angularConfig: WorkspaceSchema = {
|
|
version: 1,
|
|
projects: {
|
|
lib: {
|
|
root: '/project/lib',
|
|
sourceRoot: '/project/lib/src',
|
|
projectType: ProjectType.Library,
|
|
prefix: 'lib',
|
|
architect: {
|
|
build: {
|
|
builder: Builders.NgPackagr,
|
|
options: {
|
|
tsConfig: 'projects/lib/tsconfig.lib.json',
|
|
},
|
|
configurations: {
|
|
production: {
|
|
tsConfig: 'projects/lib/tsconfig.lib.prod.json',
|
|
},
|
|
},
|
|
// tslint:disable-next-line: no-any
|
|
} as any,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
|
|
}
|
|
|
|
describe(`Migration to add 'declarationMap' compiler option`, () => {
|
|
const schematicName = 'add-declaration-map-compiler-option';
|
|
|
|
const schematicRunner = new SchematicTestRunner(
|
|
'migrations',
|
|
require.resolve('../migration-collection.json'),
|
|
);
|
|
|
|
let tree: UnitTestTree;
|
|
beforeEach(() => {
|
|
tree = new UnitTestTree(new EmptyTree());
|
|
createWorkSpaceConfig(tree);
|
|
const tsConfig = JSON.stringify({ compilerOptions: {} }, undefined, 2);
|
|
tree.create('/projects/lib/tsconfig.lib.json', tsConfig);
|
|
tree.create('/projects/lib/tsconfig.lib.prod.json', tsConfig);
|
|
});
|
|
|
|
it(`should be added with a value of 'false' in a prod tsconfig`, async () => {
|
|
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
|
|
const { compilerOptions } = JSON.parse(newTree.readContent('/projects/lib/tsconfig.lib.prod.json'));
|
|
expect(compilerOptions.declarationMap).toBeFalse();
|
|
});
|
|
|
|
it(`should be added with a value of 'true' in a non prod tsconfig`, async () => {
|
|
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
|
|
const { compilerOptions } = JSON.parse(newTree.readContent('/projects/lib/tsconfig.lib.json'));
|
|
expect(compilerOptions.declarationMap).toBeTrue();
|
|
});
|
|
|
|
it('should not be overriden when already set', async () => {
|
|
const tsConfigPath = '/projects/lib/tsconfig.lib.json';
|
|
tree.overwrite(tsConfigPath, JSON.stringify({
|
|
compilerOptions: {
|
|
declarationMap: false,
|
|
},
|
|
}, undefined, 2));
|
|
|
|
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
|
|
const { compilerOptions } = JSON.parse(newTree.readContent(tsConfigPath));
|
|
expect(compilerOptions.declarationMap).toBeFalse();
|
|
});
|
|
});
|