-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9be34d5
commit 6dce393
Showing
13 changed files
with
309 additions
and
55 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
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
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
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
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
93 changes: 93 additions & 0 deletions
93
projects/cdk/schematics/ng-update/v4/steps/migrate-root.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,93 @@ | ||
import { | ||
type DevkitFileSystem, | ||
getActiveProject, | ||
getPackageJsonDependency, | ||
Node, | ||
} from 'ng-morph'; | ||
|
||
import type {TuiSchema} from '../../../ng-add/schema'; | ||
import {addUniqueImport} from '../../../utils/add-unique-import'; | ||
import {infoLog, REPLACE_SYMBOL, SMALL_TAB_SYMBOL} from '../../../utils/colored-log'; | ||
import {getNamedImportReferences} from '../../../utils/get-named-import-references'; | ||
import {removeImport} from '../../../utils/import-manipulations'; | ||
|
||
export function migrateRoot(fileSystem: DevkitFileSystem, options: TuiSchema): void { | ||
!options['skip-logs'] && | ||
infoLog(`${SMALL_TAB_SYMBOL}${REPLACE_SYMBOL} updating TuiRoot`); | ||
|
||
const refs = [ | ||
...getNamedImportReferences('TuiRootModule', '@taiga-ui/core'), | ||
...getNamedImportReferences( | ||
'TuiProprietaryRootModule', | ||
'@taiga-ui/proprietary-core', | ||
), | ||
...getNamedImportReferences( | ||
'TuiProprietaryRoot2023Module', | ||
'@taiga-ui/proprietary-core', | ||
), | ||
]; | ||
|
||
for (const ref of refs) { | ||
if (ref.wasForgotten()) { | ||
return; | ||
} | ||
|
||
const parent = ref.getParent(); | ||
|
||
if (Node.isImportSpecifier(parent)) { | ||
removeImport(parent); | ||
addUniqueImport( | ||
parent.getSourceFile().getFilePath(), | ||
'TuiRoot', | ||
'@taiga-ui/core', | ||
); | ||
} else { | ||
replaceRootIdentifier(ref, fileSystem); | ||
} | ||
} | ||
} | ||
|
||
function replaceRootIdentifier(ref: Node, fileSystem: DevkitFileSystem): void { | ||
const callExpression = ref.getParentWhile(Node.isCallExpression); | ||
|
||
if ( | ||
callExpression && | ||
callExpression.getExpression().getText() === 'importProvidersFrom' | ||
) { | ||
ref.replaceWithText(''); | ||
addProviders(callExpression, fileSystem); | ||
} else { | ||
ref.replaceWithText('TuiRoot'); | ||
} | ||
} | ||
|
||
function addProviders(callExpression: Node, fileSystem: DevkitFileSystem): void { | ||
const array = callExpression.getParentWhile(Node.isArrayLiteralExpression); | ||
|
||
if (!array) { | ||
return; | ||
} | ||
|
||
array.addElement('NG_EVENT_PLUGINS'); | ||
addUniqueImport( | ||
array.getSourceFile().getFilePath(), | ||
'NG_EVENT_PLUGINS', | ||
'@taiga-ui/event-plugins', | ||
); | ||
|
||
getActiveProject(); | ||
const proprietary = getPackageJsonDependency( | ||
fileSystem.tree, | ||
'@taiga-ui/proprietary-core', | ||
); | ||
|
||
if (proprietary) { | ||
array.addElement('TBANK_PROVIDERS'); | ||
|
||
addUniqueImport( | ||
array.getSourceFile().getFilePath(), | ||
'TBANK_PROVIDERS', | ||
'@taiga-ui/proprietary', | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.