@schematics/angular 19.2.0-next.0 → 19.2.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,17 +106,6 @@ function validateProject(mainPath) {
106
106
  }
107
107
  };
108
108
  }
109
- function addRouterModule(mainPath) {
110
- return (host) => {
111
- const modulePath = (0, ng_ast_utils_1.getAppModulePath)(host, mainPath);
112
- const moduleSource = getSourceFile(host, modulePath);
113
- const changes = (0, ast_utils_1.addImportToModule)(moduleSource, modulePath, 'RouterModule', '@angular/router');
114
- const recorder = host.beginUpdate(modulePath);
115
- (0, change_1.applyToUpdateRecorder)(recorder, changes);
116
- host.commitUpdate(recorder);
117
- return host;
118
- };
119
- }
120
109
  function getMetadataProperty(metadata, propertyName) {
121
110
  const properties = metadata.properties;
122
111
  const property = properties.filter(typescript_1.default.isPropertyAssignment).filter((prop) => {
@@ -202,7 +191,7 @@ function addStandaloneServerRoute(options) {
202
191
  if (!host.exists(configFilePath)) {
203
192
  throw new schematics_1.SchematicsException(`Cannot find "${configFilePath}".`);
204
193
  }
205
- let recorder = host.beginUpdate(configFilePath);
194
+ const recorder = host.beginUpdate(configFilePath);
206
195
  let configSourceFile = getSourceFile(host, configFilePath);
207
196
  if (!(0, ast_utils_1.isImported)(configSourceFile, 'ROUTES', '@angular/router')) {
208
197
  const routesChange = (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'ROUTES', '@angular/router');
@@ -220,62 +209,48 @@ function addStandaloneServerRoute(options) {
220
209
  const updatedProvidersString = [
221
210
  ...providersLiteral.elements.map((element) => ' ' + element.getText()),
222
211
  ` {
223
- provide: ROUTES,
224
- multi: true,
225
- useValue: [{
226
- path: '${APP_SHELL_ROUTE}',
227
- component: AppShellComponent
228
- }]
229
- }\n `,
212
+ provide: ROUTES,
213
+ multi: true,
214
+ useValue: [{
215
+ path: '${APP_SHELL_ROUTE}',
216
+ component: AppShellComponent
217
+ }]
218
+ }\n `,
230
219
  ];
231
220
  recorder.insertRight(providersLiteral.getStart(), `[\n${updatedProvidersString.join(',\n')}]`);
232
- if (options.serverRouting) {
233
- host.commitUpdate(recorder);
234
- configSourceFile = getSourceFile(host, configFilePath);
235
- const functionCall = (0, ast_utils_1.findNodes)(configSourceFile, typescript_1.default.isCallExpression).find((n) => typescript_1.default.isIdentifier(n.expression) && n.expression.getText() === 'provideServerRoutesConfig');
236
- if (!functionCall) {
237
- throw new schematics_1.SchematicsException(`Cannot find the "provideServerRoutesConfig" function call in "${configFilePath}".`);
238
- }
239
- recorder = host.beginUpdate(configFilePath);
240
- recorder.insertLeft(functionCall.end - 1, `, { appShellRoute: '${APP_SHELL_ROUTE}' }`);
241
- }
242
- // Add AppShellComponent import
243
- const appShellImportChange = (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'AppShellComponent', './app-shell/app-shell.component');
244
- (0, change_1.applyToUpdateRecorder)(recorder, [appShellImportChange]);
221
+ (0, change_1.applyToUpdateRecorder)(recorder, [
222
+ (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'AppShellComponent', './app-shell/app-shell.component'),
223
+ ]);
245
224
  host.commitUpdate(recorder);
246
225
  };
247
226
  }
248
- function addServerRoutingConfig(options) {
227
+ function addServerRoutingConfig(options, isStandalone) {
249
228
  return async (host) => {
250
229
  const workspace = await (0, workspace_1.getWorkspace)(host);
251
230
  const project = workspace.projects.get(options.project);
252
231
  if (!project) {
253
232
  throw new schematics_1.SchematicsException(`Project name "${options.project}" doesn't not exist.`);
254
233
  }
255
- const configFilePath = (0, posix_1.join)(project.sourceRoot ?? 'src', 'app/app.routes.server.ts');
256
- if (!host.exists(configFilePath)) {
234
+ const configFilePath = isStandalone
235
+ ? (0, posix_1.join)(project.sourceRoot ?? 'src', 'app/app.config.server.ts')
236
+ : getServerModulePath(host, project.sourceRoot || 'src', 'main.server.ts');
237
+ if (!configFilePath || !host.exists(configFilePath)) {
257
238
  throw new schematics_1.SchematicsException(`Cannot find "${configFilePath}".`);
258
239
  }
259
- const sourceFile = getSourceFile(host, configFilePath);
260
- const nodes = (0, ast_utils_1.getSourceNodes)(sourceFile);
261
- // Find the serverRoutes variable declaration
262
- const serverRoutesNode = nodes.find((node) => typescript_1.default.isVariableDeclaration(node) &&
263
- node.initializer &&
264
- typescript_1.default.isArrayLiteralExpression(node.initializer) &&
265
- node.type &&
266
- typescript_1.default.isArrayTypeNode(node.type) &&
267
- node.type.getText().includes('ServerRoute'));
268
- if (!serverRoutesNode) {
269
- throw new schematics_1.SchematicsException(`Cannot find the "ServerRoute" configuration in "${configFilePath}".`);
240
+ let recorder = host.beginUpdate(configFilePath);
241
+ const configSourceFile = getSourceFile(host, configFilePath);
242
+ const functionCall = (0, ast_utils_1.findNodes)(configSourceFile, typescript_1.default.isCallExpression,
243
+ /** max */ undefined,
244
+ /** recursive */ true).find((n) => typescript_1.default.isIdentifier(n.expression) && n.expression.getText() === 'provideServerRouting');
245
+ if (!functionCall) {
246
+ throw new schematics_1.SchematicsException(`Cannot find the "provideServerRouting" function call in "${configFilePath}".`);
270
247
  }
271
- const recorder = host.beginUpdate(configFilePath);
272
- const arrayLiteral = serverRoutesNode.initializer;
273
- const firstElementPosition = arrayLiteral.elements[0]?.getStart() ?? arrayLiteral.getStart() + 1;
274
- const newRouteString = `{
275
- path: '${APP_SHELL_ROUTE}',
276
- renderMode: RenderMode.AppShell
277
- },\n`;
278
- recorder.insertLeft(firstElementPosition, newRouteString);
248
+ recorder = host.beginUpdate(configFilePath);
249
+ recorder.insertLeft(functionCall.end - 1, `, withAppShell(AppShellComponent)`);
250
+ (0, change_1.applyToUpdateRecorder)(recorder, [
251
+ (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'withAppShell', '@angular/ssr'),
252
+ (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'AppShellComponent', './app-shell/app-shell.component'),
253
+ ]);
279
254
  host.commitUpdate(recorder);
280
255
  };
281
256
  }
@@ -286,10 +261,14 @@ function default_1(options) {
286
261
  return (0, schematics_1.chain)([
287
262
  validateProject(browserEntryPoint),
288
263
  (0, schematics_1.schematic)('server', options),
289
- ...(isStandalone
290
- ? [addStandaloneServerRoute(options)]
291
- : [addRouterModule(browserEntryPoint), addServerRoutes(options)]),
292
- options.serverRouting ? (0, schematics_1.noop)() : addAppShellConfigToWorkspace(options),
264
+ ...(options.serverRouting
265
+ ? [(0, schematics_1.noop)()]
266
+ : isStandalone
267
+ ? [addStandaloneServerRoute(options)]
268
+ : [addServerRoutes(options)]),
269
+ options.serverRouting
270
+ ? addServerRoutingConfig(options, isStandalone)
271
+ : addAppShellConfigToWorkspace(options),
293
272
  (0, schematics_1.schematic)('component', {
294
273
  name: 'app-shell',
295
274
  module: 'app.module.server.ts',
@@ -3,8 +3,7 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%
3
3
  @Component({<% if(!skipSelector) {%>
4
4
  selector: '<%= selector %>',<%}%><% if(standalone) {%>
5
5
  imports: [],<%} else { %>
6
- standalone: false,
7
- <% }%><% if(inlineTemplate) { %>
6
+ standalone: false,<% }%><% if(inlineTemplate) { %>
8
7
  template: `
9
8
  <p>
10
9
  <%= dasherize(name) %> works!
package/library/index.js CHANGED
@@ -38,8 +38,8 @@ function addDependenciesToPackageJson() {
38
38
  },
39
39
  {
40
40
  type: dependencies_1.NodeDependencyType.Dev,
41
- name: '@angular/build',
42
- version: latest_versions_1.latestVersions.AngularBuild,
41
+ name: '@angular-devkit/build-angular',
42
+ version: latest_versions_1.latestVersions.DevkitBuildAngular,
43
43
  },
44
44
  {
45
45
  type: dependencies_1.NodeDependencyType.Dev,
@@ -70,7 +70,7 @@ function addLibToWorkspaceFile(options, projectRoot, projectName) {
70
70
  prefix: options.prefix,
71
71
  targets: {
72
72
  build: {
73
- builder: workspace_models_1.Builders.BuildNgPackagr,
73
+ builder: workspace_models_1.Builders.NgPackagr,
74
74
  defaultConfiguration: 'production',
75
75
  options: {
76
76
  project: `${projectRoot}/ng-package.json`,
@@ -42,6 +42,7 @@ var __importStar = (this && this.__importStar) || (function () {
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  exports.default = default_1;
44
44
  const ts = __importStar(require("../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
45
+ const dependencies_1 = require("../../utility/dependencies");
45
46
  function* visit(directory) {
46
47
  for (const path of directory.subfiles) {
47
48
  if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {
@@ -70,6 +71,9 @@ function* visit(directory) {
70
71
  */
71
72
  function default_1() {
72
73
  return (tree) => {
74
+ if (!(0, dependencies_1.getPackageJsonDependency)(tree, '@angular/ssr')) {
75
+ return;
76
+ }
73
77
  for (const sourceFile of visit(tree.root)) {
74
78
  let recorder;
75
79
  const allImportDeclarations = sourceFile.statements.filter((n) => ts.isImportDeclaration(n));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematics/angular",
3
- "version": "19.2.0-next.0",
3
+ "version": "19.2.0-next.2",
4
4
  "description": "Schematics specific to Angular",
5
5
  "homepage": "https://github.com/angular/angular-cli",
6
6
  "keywords": [
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "schematics": "./collection.json",
24
24
  "dependencies": {
25
- "@angular-devkit/core": "19.2.0-next.0",
26
- "@angular-devkit/schematics": "19.2.0-next.0",
25
+ "@angular-devkit/core": "19.2.0-next.2",
26
+ "@angular-devkit/schematics": "19.2.0-next.2",
27
27
  "jsonc-parser": "3.3.1"
28
28
  },
29
29
  "repository": {
@@ -1,13 +1,13 @@
1
1
  import { NgModule } from '@angular/core';
2
2
  import { ServerModule } from '@angular/platform-server';<% if(serverRouting) { %>
3
- import { provideServerRoutesConfig } from '@angular/ssr';<% } %>
3
+ import { provideServerRouting } from '@angular/ssr';<% } %>
4
4
  import { AppComponent } from './app.component';
5
5
  import { AppModule } from './app.module';<% if(serverRouting) { %>
6
6
  import { serverRoutes } from './app.routes.server';<% } %>
7
7
 
8
8
  @NgModule({
9
9
  imports: [AppModule, ServerModule],<% if(serverRouting) { %>
10
- providers: [provideServerRoutesConfig(serverRoutes)],<% } %>
10
+ providers: [provideServerRouting(serverRoutes)],<% } %>
11
11
  bootstrap: [AppComponent],
12
12
  })
13
13
  export class AppServerModule {}
@@ -1,13 +1,13 @@
1
1
  import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
2
2
  import { provideServerRendering } from '@angular/platform-server';<% if(serverRouting) { %>
3
- import { provideServerRoutesConfig } from '@angular/ssr';<% } %>
3
+ import { provideServerRouting } from '@angular/ssr';<% } %>
4
4
  import { appConfig } from './app.config';<% if(serverRouting) { %>
5
5
  import { serverRoutes } from './app.routes.server';<% } %>
6
6
 
7
7
  const serverConfig: ApplicationConfig = {
8
8
  providers: [
9
9
  provideServerRendering(),<% if(serverRouting) { %>
10
- provideServerRoutesConfig(serverRoutes)<% } %>
10
+ provideServerRouting(serverRoutes)<% } %>
11
11
  ]
12
12
  };
13
13
 
@@ -61,6 +61,6 @@ if (isMainModule(import.meta.url)) {
61
61
  }
62
62
 
63
63
  /**
64
- * The request handler used by the Angular CLI (dev-server and during build).
64
+ * Request handler used by the Angular CLI (for dev-server and during build) or Firebase Cloud Functions.
65
65
  */
66
66
  export const reqHandler = createNodeRequestHandler(app);
@@ -63,3 +63,5 @@ if (isMainModule(import.meta.url)) {
63
63
  console.log(`Node Express server listening on http://localhost:${port}`);
64
64
  });
65
65
  }
66
+
67
+ export default app;
@@ -8,7 +8,7 @@
8
8
  "@types/node": "^18.18.0",
9
9
  "browser-sync": "^3.0.0",
10
10
  "express": "^4.18.2",
11
- "jasmine-core": "~5.5.0",
11
+ "jasmine-core": "~5.6.0",
12
12
  "jasmine-spec-reporter": "~7.0.0",
13
13
  "karma-chrome-launcher": "~3.2.0",
14
14
  "karma-coverage": "~2.2.0",
@@ -15,8 +15,8 @@ exports.latestVersions = {
15
15
  ...dependencies,
16
16
  // As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current
17
17
  Angular: '^19.2.0-next.0',
18
- NgPackagr: '^19.1.0-next.0',
19
- DevkitBuildAngular: '^19.2.0-next.0',
20
- AngularBuild: '^19.2.0-next.0',
21
- AngularSSR: '^19.2.0-next.0',
18
+ NgPackagr: '^19.2.0-next.0',
19
+ DevkitBuildAngular: '^19.2.0-next.2',
20
+ AngularBuild: '^19.2.0-next.2',
21
+ AngularSSR: '^19.2.0-next.2',
22
22
  };