Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda6ef62

Browse files
committed
fix(@schematics/angular): ensure app-shell schematic consistently useswithAppShell
Previously, Webpack-based builders did not utilize this option.
1 parent689ab8a commitda6ef62

File tree

2 files changed

+2
-140
lines changed

2 files changed

+2
-140
lines changed

‎packages/schematics/angular/app-shell/index.ts

Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,23 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import{
10-
Rule,
11-
SchematicsException,
12-
Tree,
13-
chain,
14-
noop,
15-
schematic,
16-
}from'@angular-devkit/schematics';
9+
import{Rule,SchematicsException,Tree,chain,schematic}from'@angular-devkit/schematics';
1710
import{dirname,join}from'node:path/posix';
1811
importtsfrom'../third_party/github.com/Microsoft/TypeScript/lib/typescript';
1912
import{
20-
addSymbolToNgModuleMetadata,
2113
findNode,
2214
findNodes,
2315
getDecoratorMetadata,
2416
getSourceNodes,
2517
insertImport,
26-
isImported,
2718
}from'../utility/ast-utils';
2819
import{applyToUpdateRecorder}from'../utility/change';
2920
import{getAppModulePath,isStandaloneApp}from'../utility/ng-ast-utils';
30-
import{isUsingApplicationBuilder,targetBuildNotFoundError}from'../utility/project-targets';
21+
import{targetBuildNotFoundError}from'../utility/project-targets';
3122
import{findBootstrapApplicationCall,getMainFilePath}from'../utility/standalone/util';
3223
import{getWorkspace}from'../utility/workspace';
3324
import{SchemaasAppShellOptions}from'./schema';
3425

35-
constAPP_SHELL_ROUTE='shell';
36-
3726
functiongetSourceFile(host:Tree,path:string):ts.SourceFile{
3827
constcontent=host.readText(path);
3928
constsource=ts.createSourceFile(path,content,ts.ScriptTarget.Latest,true);
@@ -156,126 +145,6 @@ function getMetadataProperty(metadata: ts.Node, propertyName: string): ts.Proper
156145
returnproperty;
157146
}
158147

159-
functionaddServerRoutes(options:AppShellOptions):Rule{
160-
returnasync(host:Tree)=>{
161-
// The workspace gets updated so this needs to be reloaded
162-
constworkspace=awaitgetWorkspace(host);
163-
constproject=workspace.projects.get(options.project);
164-
if(!project){
165-
thrownewSchematicsException(`Invalid project name (${options.project})`);
166-
}
167-
168-
constmodulePath=getServerModulePath(host,project.sourceRoot||'src','main.server.ts');
169-
if(modulePath===null){
170-
thrownewSchematicsException('Server module not found.');
171-
}
172-
173-
letmoduleSource=getSourceFile(host,modulePath);
174-
if(!isImported(moduleSource,'Routes','@angular/router')){
175-
constrecorder=host.beginUpdate(modulePath);
176-
constroutesChange=insertImport(moduleSource,modulePath,'Routes','@angular/router');
177-
if(routesChange){
178-
applyToUpdateRecorder(recorder,[routesChange]);
179-
}
180-
181-
constimports=getSourceNodes(moduleSource)
182-
.filter((node)=>node.kind===ts.SyntaxKind.ImportDeclaration)
183-
.sort((a,b)=>a.getStart()-b.getStart());
184-
constinsertPosition=imports[imports.length-1].getEnd();
185-
constrouteText=`\n\nconst routes: Routes = [ { path: '${APP_SHELL_ROUTE}', component: AppShell }];`;
186-
recorder.insertRight(insertPosition,routeText);
187-
host.commitUpdate(recorder);
188-
}
189-
190-
moduleSource=getSourceFile(host,modulePath);
191-
if(!isImported(moduleSource,'RouterModule','@angular/router')){
192-
constrecorder=host.beginUpdate(modulePath);
193-
constrouterModuleChange=insertImport(
194-
moduleSource,
195-
modulePath,
196-
'RouterModule',
197-
'@angular/router',
198-
);
199-
200-
if(routerModuleChange){
201-
applyToUpdateRecorder(recorder,[routerModuleChange]);
202-
}
203-
204-
constmetadataChange=addSymbolToNgModuleMetadata(
205-
moduleSource,
206-
modulePath,
207-
'imports',
208-
'RouterModule.forRoot(routes)',
209-
);
210-
if(metadataChange){
211-
applyToUpdateRecorder(recorder,metadataChange);
212-
}
213-
host.commitUpdate(recorder);
214-
}
215-
};
216-
}
217-
218-
functionaddStandaloneServerRoute(options:AppShellOptions):Rule{
219-
returnasync(host:Tree)=>{
220-
constworkspace=awaitgetWorkspace(host);
221-
constproject=workspace.projects.get(options.project);
222-
if(!project){
223-
thrownewSchematicsException(`Project name "${options.project}" doesn't not exist.`);
224-
}
225-
226-
constconfigFilePath=join(project.sourceRoot??'src','app/app.config.server.ts');
227-
if(!host.exists(configFilePath)){
228-
thrownewSchematicsException(`Cannot find "${configFilePath}".`);
229-
}
230-
231-
constrecorder=host.beginUpdate(configFilePath);
232-
letconfigSourceFile=getSourceFile(host,configFilePath);
233-
if(!isImported(configSourceFile,'ROUTES','@angular/router')){
234-
constroutesChange=insertImport(
235-
configSourceFile,
236-
configFilePath,
237-
'ROUTES',
238-
'@angular/router',
239-
);
240-
241-
if(routesChange){
242-
applyToUpdateRecorder(recorder,[routesChange]);
243-
}
244-
}
245-
246-
configSourceFile=getSourceFile(host,configFilePath);
247-
constprovidersLiteral=findNodes(configSourceFile,ts.isPropertyAssignment).find(
248-
(n)=>ts.isArrayLiteralExpression(n.initializer)&&n.name.getText()==='providers',
249-
)?.initializerasts.ArrayLiteralExpression|undefined;
250-
if(!providersLiteral){
251-
thrownewSchematicsException(
252-
`Cannot find the "providers" configuration in "${configFilePath}".`,
253-
);
254-
}
255-
256-
// Add route to providers literal.
257-
recorder.remove(providersLiteral.getStart(),providersLiteral.getWidth());
258-
constupdatedProvidersString=[
259-
...providersLiteral.elements.map((element)=>' '+element.getText()),
260-
` {
261-
provide: ROUTES,
262-
multi: true,
263-
useValue: [{
264-
path: '${APP_SHELL_ROUTE}',
265-
component: AppShell
266-
}]
267-
}\n `,
268-
];
269-
270-
recorder.insertRight(providersLiteral.getStart(),`[\n${updatedProvidersString.join(',\n')}]`);
271-
272-
applyToUpdateRecorder(recorder,[
273-
insertImport(configSourceFile,configFilePath,'AppShell','./app-shell/app-shell'),
274-
]);
275-
host.commitUpdate(recorder);
276-
};
277-
}
278-
279148
functionaddServerRoutingConfig(options:AppShellOptions,isStandalone:boolean):Rule{
280149
returnasync(host:Tree)=>{
281150
constworkspace=awaitgetWorkspace(host);
@@ -335,11 +204,6 @@ export default function (options: AppShellOptions): Rule {
335204
returnchain([
336205
validateProject(browserEntryPoint),
337206
schematic('server',options),
338-
...(isUsingApplicationBuilder(project)
339-
?[noop()]
340-
:isStandalone
341-
?[addStandaloneServerRoute(options)]
342-
:[addServerRoutes(options)]),
343207
addServerRoutingConfig(options,isStandalone),
344208
schematic('component',{
345209
name:'app-shell',

‎packages/schematics/angular/server/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ import {
1414
apply,
1515
applyTemplates,
1616
chain,
17-
filter,
1817
mergeWith,
1918
move,
20-
noop,
2119
strings,
2220
url,
2321
}from'@angular-devkit/schematics';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp