mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 06:41:45 +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
49 lines
1.4 KiB
TypeScript
49 lines
1.4 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 { Rule, Tree } from '@angular-devkit/schematics';
|
|
import { JSONFile } from '../../utility/json-file';
|
|
import { getWorkspace } from '../../utility/workspace';
|
|
import { Builders } from '../../utility/workspace-models';
|
|
|
|
export default function (): Rule {
|
|
return async host => {
|
|
const workspace = await getWorkspace(host);
|
|
|
|
for (const [, project] of workspace.projects) {
|
|
for (const [, target] of project.targets) {
|
|
if (target.builder !== Builders.NgPackagr) {
|
|
continue;
|
|
}
|
|
|
|
if (!target.configurations) {
|
|
continue;
|
|
}
|
|
|
|
for (const options of Object.values(target.configurations)) {
|
|
addDeclarationMapValue(host, options?.tsConfig, false);
|
|
}
|
|
|
|
addDeclarationMapValue(host, target.options?.tsConfig, true);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
function addDeclarationMapValue(host: Tree, tsConfigPath: unknown, value: boolean): void {
|
|
if (typeof tsConfigPath !== 'string') {
|
|
return;
|
|
}
|
|
|
|
const declarationMapPath = ['compilerOptions', 'declarationMap'];
|
|
const file = new JSONFile(host, tsConfigPath);
|
|
if (file.get(declarationMapPath) === undefined) {
|
|
file.modify(declarationMapPath, value);
|
|
}
|
|
}
|