-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1956 from timdeschryver/fix-ng-add
feat(core): adds angular 18 support
- Loading branch information
Showing
10 changed files
with
40 additions
and
83 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -103,4 +103,4 @@ | |
"ts-node": "^10.9.1", | ||
"typescript": "~5.4.5" | ||
} | ||
} | ||
} |
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
82 changes: 12 additions & 70 deletions
82
projects/schematics/src/ng-add/actions/add-standalone-import.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 |
---|---|---|
@@ -1,78 +1,20 @@ | ||
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; | ||
import { | ||
addFunctionalProvidersToStandaloneBootstrap, | ||
callsProvidersFunction, | ||
} from '@schematics/angular/private/standalone'; | ||
import { insertImport } from '@schematics/angular/utility/ast-utils'; | ||
import { InsertChange } from '@schematics/angular/utility/change'; | ||
import * as ts from 'typescript'; | ||
import { getProject, readIntoSourceFile } from '../../utils/angular-utils'; | ||
import { Rule, SchematicContext, Tree, chain } from '@angular-devkit/schematics'; | ||
import { addRootProvider } from '@schematics/angular/utility'; | ||
import { getProject } from '../../utils/angular-utils'; | ||
import { NgAddOptions } from '../models/ng-add-options'; | ||
|
||
export function addStandaloneConfigsToProviders(options: NgAddOptions): Rule { | ||
return (host: Tree, context: SchematicContext) => { | ||
const project = getProject(host); | ||
|
||
const { fileName, configName } = options.standaloneInfo!; | ||
|
||
const standaloneConfigs = [ | ||
{ | ||
target: `${project.sourceRoot}/main.ts`, | ||
configName, | ||
configPath: `./auth/${fileName}`, | ||
}, | ||
]; | ||
|
||
standaloneConfigs.forEach(({ target, configName, configPath }) => { | ||
addProvider(host, context, configName, configPath, target); | ||
}); | ||
|
||
const [projectName] = getProject(host); | ||
const { fileName } = options.standaloneInfo!; | ||
|
||
context.logger.info(`✅️ All imports done, please add the 'provideRouter()' as well if you don't have it provided yet.`); | ||
|
||
return host; | ||
return chain([ | ||
addRootProvider(projectName, ({code, external}) => { | ||
external('authConfig', `./auth/${fileName}`); | ||
return code`${external('provideAuth', 'angular-auth-oidc-client')}(authConfig)`; | ||
}), | ||
]); | ||
}; | ||
} | ||
|
||
function addProvider(host: Tree, context: SchematicContext, configName: string, configPath: string, target: string) { | ||
const sourcefile = readIntoSourceFile(host, target); | ||
const providerFn = 'provideAuth'; | ||
if (callsProvidersFunction(host, sourcefile.fileName, providerFn)) { | ||
// exit because the store config is already provided | ||
return host; | ||
} | ||
|
||
const patchedConfigFile = addFunctionalProvidersToStandaloneBootstrap( | ||
host, | ||
sourcefile.fileName, | ||
providerFn, | ||
'angular-auth-oidc-client', | ||
[ts.factory.createIdentifier('authConfig')] | ||
); | ||
|
||
const configFileContent = host.read(patchedConfigFile); | ||
const source = ts.createSourceFile( | ||
patchedConfigFile, | ||
configFileContent?.toString('utf-8') || '', | ||
ts.ScriptTarget.Latest, | ||
true | ||
); | ||
|
||
|
||
const change = insertImport( | ||
source as any, // Angular uses the TS 5.1 compiler internally for schematics? | ||
patchedConfigFile, | ||
configName, | ||
configPath | ||
); | ||
|
||
const recorder = host.beginUpdate(patchedConfigFile); | ||
|
||
if (change instanceof InsertChange) { | ||
recorder.insertLeft(change.pos, change.toAdd); | ||
} | ||
|
||
host.commitUpdate(recorder); | ||
|
||
return host; | ||
|
||
} |
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