-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@schematics/angular): add migration to remove solution style tsc…
…onfig Following the issues highlighted in https://docs.google.com/document/d/1eB6cGCG_2ircfS5GzpDC9dBgikeYYcMxghVH5sDESHw/edit?usp=sharing and discussions held with the TypeScript team. Together with the TypeScript team it was decided that the best course of action is to rollback this feature. In future, it is not excluded that solution style tsconfigs are re-introduced. Closes #18040, closes #18130 and closes #18170
- Loading branch information
1 parent
8b96e52
commit 8fb5259
Showing
4 changed files
with
94 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/schematics/angular/migrations/update-10/remove-solution-style-tsconfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @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 { Path, dirname, join, normalize, resolve } from '@angular-devkit/core'; | ||
import { DirEntry, Rule } from '@angular-devkit/schematics'; | ||
import { JSONFile } from '../../utility/json-file'; | ||
|
||
function* visitExtendedJsonFiles(directory: DirEntry): IterableIterator<Path> { | ||
for (const path of directory.subfiles) { | ||
if (!path.endsWith('.json')) { | ||
continue; | ||
} | ||
|
||
const entry = directory.file(path); | ||
const content = entry?.content.toString(); | ||
if (content?.includes('tsconfig.base.json')) { | ||
yield join(directory.path, path); | ||
} | ||
} | ||
|
||
for (const path of directory.subdirs) { | ||
if (path === 'node_modules' || path.startsWith('.')) { | ||
continue; | ||
} | ||
|
||
yield* visitExtendedJsonFiles(directory.dir(path)); | ||
} | ||
} | ||
|
||
export default function (): Rule { | ||
return (host, context) => { | ||
const logger = context.logger; | ||
|
||
const tsConfig = new JSONFile(host, 'tsconfig.json'); | ||
const files = tsConfig.get(['files']); | ||
if (!(Array.isArray(files) && files.length === 0)) { | ||
logger.info('Migration has already been executed.'); | ||
|
||
return; | ||
} | ||
|
||
if (host.exists('tsconfig.base.json')) { | ||
host.overwrite('tsconfig.json', host.read('tsconfig.base.json') || ''); | ||
host.delete('tsconfig.base.json'); | ||
} | ||
|
||
// Iterate over all tsconfig files and change the extends from 'tsconfig.base.json' to 'tsconfig.json'. | ||
const extendsJsonPath = ['extends']; | ||
for (const path of visitExtendedJsonFiles(host.root)) { | ||
const tsConfigDir = dirname(normalize(path)); | ||
let tsConfigJson; | ||
|
||
try { | ||
tsConfigJson = new JSONFile(host, path); | ||
const extendsValue = tsConfigJson.get(extendsJsonPath); | ||
|
||
if (typeof extendsValue === 'string' && '/tsconfig.base.json' === resolve(tsConfigDir, normalize(extendsValue))) { | ||
// tsconfig extends the workspace tsconfig path. | ||
tsConfig.modify(extendsJsonPath, extendsValue.replace('tsconfig.base.json', 'tsconfig.json')); | ||
} | ||
} catch (error) { | ||
logger.warn( | ||
`${error.message || error}\n` + | ||
'If this is a TypeScript configuration file you will need to update the "extends" value manually.', | ||
); | ||
|
||
continue; | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 0 additions & 141 deletions
141
packages/schematics/angular/migrations/update-10/solution-style-tsconfig.ts
This file was deleted.
Oops, something went wrong.