@schematics/angular 19.0.0-next.0 → 19.0.0-next.10

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.
Files changed (38) hide show
  1. package/LICENSE +5 -5
  2. package/app-shell/index.js +48 -73
  3. package/application/index.js +2 -2
  4. package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template +1 -1
  5. package/component/index.js +1 -0
  6. package/component/schema.d.ts +4 -0
  7. package/component/schema.json +5 -0
  8. package/config/files/karma.conf.js.template +0 -1
  9. package/directive/index.js +1 -0
  10. package/migrations/migration-collection.json +11 -1
  11. package/migrations/update-ssr-imports/migration.d.ts +15 -0
  12. package/migrations/update-ssr-imports/migration.js +93 -0
  13. package/migrations/update-workspace-config/migration.d.ts +33 -0
  14. package/migrations/update-workspace-config/migration.js +77 -0
  15. package/package.json +4 -4
  16. package/server/files/application-builder/ngmodule-src/app/app.module.server.ts.template +13 -0
  17. package/server/files/application-builder/ngmodule-src/app/app.routes.server.ts.template +8 -0
  18. package/server/files/application-builder/standalone-src/app/app.config.server.ts.template +14 -0
  19. package/server/files/application-builder/standalone-src/app/app.routes.server.ts.template +8 -0
  20. package/server/files/server-builder/ngmodule-src/main.server.ts.template +1 -0
  21. package/server/files/server-builder/standalone-src/main.server.ts.template +7 -0
  22. package/server/index.js +17 -8
  23. package/service-worker/files/ngsw-config.json.template +1 -0
  24. package/ssr/files/application-builder/server.ts.template +36 -44
  25. package/ssr/files/server-builder/server.ts.template +2 -2
  26. package/ssr/index.js +17 -21
  27. package/third_party/github.com/Microsoft/TypeScript/lib/typescript.d.ts +244 -156
  28. package/third_party/github.com/Microsoft/TypeScript/lib/typescript.js +4617 -3454
  29. package/utility/latest-versions/package.json +3 -3
  30. package/utility/latest-versions.js +2 -2
  31. package/utility/workspace-models.d.ts +1 -5
  32. package/workspace/files/__dot__editorconfig.template +1 -0
  33. package/workspace/files/tsconfig.json.template +1 -7
  34. /package/server/files/{src → application-builder/ngmodule-src}/main.server.ts.template +0 -0
  35. /package/server/files/{standalone-src → application-builder/standalone-src}/main.server.ts.template +0 -0
  36. /package/server/files/{src → server-builder/ngmodule-src}/app/app.module.server.ts.template +0 -0
  37. /package/server/files/{root → server-builder/root}/tsconfig.server.json.template +0 -0
  38. /package/server/files/{standalone-src → server-builder/standalone-src}/app/app.config.server.ts.template +0 -0
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2017 Google, Inc.
3
+ Copyright (c) 2010-2024 Google LLC. https://angular.dev/license
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -19,7 +19,6 @@ const change_1 = require("../utility/change");
19
19
  const ng_ast_utils_1 = require("../utility/ng-ast-utils");
20
20
  const util_1 = require("../utility/standalone/util");
21
21
  const workspace_1 = require("../utility/workspace");
22
- const workspace_models_1 = require("../utility/workspace-models");
23
22
  const APP_SHELL_ROUTE = 'shell';
24
23
  function getSourceFile(host, path) {
25
24
  const content = host.readText(path);
@@ -106,59 +105,6 @@ function validateProject(mainPath) {
106
105
  }
107
106
  };
108
107
  }
109
- function addAppShellConfigToWorkspace(options) {
110
- return (host, context) => {
111
- return (0, workspace_1.updateWorkspace)((workspace) => {
112
- const project = workspace.projects.get(options.project);
113
- if (!project) {
114
- return;
115
- }
116
- const buildTarget = project.targets.get('build');
117
- if (buildTarget?.builder === workspace_models_1.Builders.Application) {
118
- // Application builder configuration.
119
- const prodConfig = buildTarget.configurations?.production;
120
- if (!prodConfig) {
121
- throw new schematics_1.SchematicsException(`A "production" configuration is not defined for the "build" builder.`);
122
- }
123
- prodConfig.appShell = true;
124
- return;
125
- }
126
- // Webpack based builders configuration.
127
- // Validation of targets is handled already in the main function.
128
- // Duplicate keys means that we have configurations in both server and build builders.
129
- const serverConfigKeys = project.targets.get('server')?.configurations ?? {};
130
- const buildConfigKeys = project.targets.get('build')?.configurations ?? {};
131
- const configurationNames = Object.keys({
132
- ...serverConfigKeys,
133
- ...buildConfigKeys,
134
- });
135
- const configurations = {};
136
- for (const key of configurationNames) {
137
- if (!serverConfigKeys[key]) {
138
- context.logger.warn(`Skipped adding "${key}" configuration to "app-shell" target as it's missing from "server" target.`);
139
- continue;
140
- }
141
- if (!buildConfigKeys[key]) {
142
- context.logger.warn(`Skipped adding "${key}" configuration to "app-shell" target as it's missing from "build" target.`);
143
- continue;
144
- }
145
- configurations[key] = {
146
- browserTarget: `${options.project}:build:${key}`,
147
- serverTarget: `${options.project}:server:${key}`,
148
- };
149
- }
150
- project.targets.add({
151
- name: 'app-shell',
152
- builder: workspace_models_1.Builders.AppShell,
153
- defaultConfiguration: configurations['production'] ? 'production' : undefined,
154
- options: {
155
- route: APP_SHELL_ROUTE,
156
- },
157
- configurations,
158
- });
159
- });
160
- };
161
- }
162
108
  function addRouterModule(mainPath) {
163
109
  return (host) => {
164
110
  const modulePath = (0, ng_ast_utils_1.getAppModulePath)(host, mainPath);
@@ -237,13 +183,12 @@ function addStandaloneServerRoute(options) {
237
183
  if (!host.exists(configFilePath)) {
238
184
  throw new schematics_1.SchematicsException(`Cannot find "${configFilePath}".`);
239
185
  }
186
+ const recorder = host.beginUpdate(configFilePath);
240
187
  let configSourceFile = getSourceFile(host, configFilePath);
241
188
  if (!(0, ast_utils_1.isImported)(configSourceFile, 'ROUTES', '@angular/router')) {
242
189
  const routesChange = (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'ROUTES', '@angular/router');
243
- const recorder = host.beginUpdate(configFilePath);
244
190
  if (routesChange) {
245
191
  (0, change_1.applyToUpdateRecorder)(recorder, [routesChange]);
246
- host.commitUpdate(recorder);
247
192
  }
248
193
  }
249
194
  configSourceFile = getSourceFile(host, configFilePath);
@@ -252,29 +197,59 @@ function addStandaloneServerRoute(options) {
252
197
  throw new schematics_1.SchematicsException(`Cannot find the "providers" configuration in "${configFilePath}".`);
253
198
  }
254
199
  // Add route to providers literal.
255
- const newProvidersLiteral = typescript_1.default.factory.updateArrayLiteralExpression(providersLiteral, [
256
- ...providersLiteral.elements,
257
- typescript_1.default.factory.createObjectLiteralExpression([
258
- typescript_1.default.factory.createPropertyAssignment('provide', typescript_1.default.factory.createIdentifier('ROUTES')),
259
- typescript_1.default.factory.createPropertyAssignment('multi', typescript_1.default.factory.createIdentifier('true')),
260
- typescript_1.default.factory.createPropertyAssignment('useValue', typescript_1.default.factory.createArrayLiteralExpression([
261
- typescript_1.default.factory.createObjectLiteralExpression([
262
- typescript_1.default.factory.createPropertyAssignment('path', typescript_1.default.factory.createIdentifier(`'${APP_SHELL_ROUTE}'`)),
263
- typescript_1.default.factory.createPropertyAssignment('component', typescript_1.default.factory.createIdentifier('AppShellComponent')),
264
- ], true),
265
- ], true)),
266
- ], true),
267
- ]);
268
- const recorder = host.beginUpdate(configFilePath);
269
200
  recorder.remove(providersLiteral.getStart(), providersLiteral.getWidth());
270
- const printer = typescript_1.default.createPrinter();
271
- recorder.insertRight(providersLiteral.getStart(), printer.printNode(typescript_1.default.EmitHint.Unspecified, newProvidersLiteral, configSourceFile));
201
+ const updatedProvidersString = [
202
+ ...providersLiteral.elements.map((element) => ' ' + element.getText()),
203
+ ` {
204
+ provide: ROUTES,
205
+ multi: true,
206
+ useValue: [{
207
+ path: '${APP_SHELL_ROUTE}',
208
+ component: AppShellComponent
209
+ }]
210
+ }\n `,
211
+ ];
212
+ recorder.insertRight(providersLiteral.getStart(), `[\n${updatedProvidersString.join(',\n')}]`);
272
213
  // Add AppShellComponent import
273
214
  const appShellImportChange = (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'AppShellComponent', './app-shell/app-shell.component');
274
215
  (0, change_1.applyToUpdateRecorder)(recorder, [appShellImportChange]);
275
216
  host.commitUpdate(recorder);
276
217
  };
277
218
  }
219
+ function addServerRoutingConfig(options) {
220
+ return async (host) => {
221
+ const workspace = await (0, workspace_1.getWorkspace)(host);
222
+ const project = workspace.projects.get(options.project);
223
+ if (!project) {
224
+ throw new schematics_1.SchematicsException(`Project name "${options.project}" doesn't not exist.`);
225
+ }
226
+ const configFilePath = (0, posix_1.join)(project.sourceRoot ?? 'src', 'app/app.routes.server.ts');
227
+ if (!host.exists(configFilePath)) {
228
+ throw new schematics_1.SchematicsException(`Cannot find "${configFilePath}".`);
229
+ }
230
+ const sourceFile = getSourceFile(host, configFilePath);
231
+ const nodes = (0, ast_utils_1.getSourceNodes)(sourceFile);
232
+ // Find the serverRoutes variable declaration
233
+ const serverRoutesNode = nodes.find((node) => typescript_1.default.isVariableDeclaration(node) &&
234
+ node.initializer &&
235
+ typescript_1.default.isArrayLiteralExpression(node.initializer) &&
236
+ node.type &&
237
+ typescript_1.default.isArrayTypeNode(node.type) &&
238
+ node.type.getText().includes('ServerRoute'));
239
+ if (!serverRoutesNode) {
240
+ throw new schematics_1.SchematicsException(`Cannot find the "ServerRoute" configuration in "${configFilePath}".`);
241
+ }
242
+ const recorder = host.beginUpdate(configFilePath);
243
+ const arrayLiteral = serverRoutesNode.initializer;
244
+ const firstElementPosition = arrayLiteral.elements[0]?.getStart() ?? arrayLiteral.getStart() + 1;
245
+ const newRouteString = `{
246
+ path: '${APP_SHELL_ROUTE}',
247
+ renderMode: RenderMode.AppShell
248
+ },\n`;
249
+ recorder.insertLeft(firstElementPosition, newRouteString);
250
+ host.commitUpdate(recorder);
251
+ };
252
+ }
278
253
  function default_1(options) {
279
254
  return async (tree) => {
280
255
  const browserEntryPoint = await (0, util_1.getMainFilePath)(tree, options.project);
@@ -282,9 +257,9 @@ function default_1(options) {
282
257
  return (0, schematics_1.chain)([
283
258
  validateProject(browserEntryPoint),
284
259
  (0, schematics_1.schematic)('server', options),
285
- addAppShellConfigToWorkspace(options),
286
260
  isStandalone ? (0, schematics_1.noop)() : addRouterModule(browserEntryPoint),
287
261
  isStandalone ? addStandaloneServerRoute(options) : addServerRoutes(options),
262
+ addServerRoutingConfig(options),
288
263
  (0, schematics_1.schematic)('component', {
289
264
  name: 'app-shell',
290
265
  module: 'app.module.server.ts',
@@ -164,8 +164,8 @@ function addAppToWorkspaceFile(options, appDir, folderName) {
164
164
  },
165
165
  {
166
166
  type: 'anyComponentStyle',
167
- maximumWarning: '2kB',
168
- maximumError: '4kB',
167
+ maximumWarning: '4kB',
168
+ maximumError: '8kB',
169
169
  },
170
170
  ];
171
171
  }
@@ -19,6 +19,6 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%
19
19
  encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
20
20
  changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
21
21
  })
22
- export class <%= classify(name) %><%= classify(type) %> {
22
+ export <% if(exportDefault) {%>default <%}%>class <%= classify(name) %><%= classify(type) %> {
23
23
 
24
24
  }
@@ -42,6 +42,7 @@ function default_1(options) {
42
42
  options.selector =
43
43
  options.selector || buildSelector(options, (project && project.prefix) || '');
44
44
  (0, validation_1.validateHtmlSelector)(options.selector);
45
+ (0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
45
46
  const skipStyleFile = options.inlineStyle || options.style === schema_1.Style.None;
46
47
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
47
48
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
@@ -14,6 +14,10 @@ export interface Schema {
14
14
  * The declaring NgModule exports this component.
15
15
  */
16
16
  export?: boolean;
17
+ /**
18
+ * Use default export for the component instead of a named export.
19
+ */
20
+ exportDefault?: boolean;
17
21
  /**
18
22
  * Create the new files at the top level of the current project.
19
23
  */
@@ -130,6 +130,11 @@
130
130
  "type": "boolean",
131
131
  "default": false,
132
132
  "description": "The declaring NgModule exports this component."
133
+ },
134
+ "exportDefault": {
135
+ "type": "boolean",
136
+ "default": false,
137
+ "description": "Use default export for the component instead of a named export."
133
138
  }
134
139
  },
135
140
  "required": ["name", "project"]
@@ -19,7 +19,6 @@ module.exports = function (config) {
19
19
  // for example, you can disable the random execution with `random: false`
20
20
  // or set a specific seed with `seed: 4321`
21
21
  },
22
- clearContext: false // leave Jasmine Spec Runner output visible in browser
23
22
  },
24
23
  jasmineHtmlReporter: {
25
24
  suppressAll: true // removes the duplicated traces
@@ -40,6 +40,7 @@ function default_1(options) {
40
40
  options.path = parsedPath.path;
41
41
  options.selector = options.selector || buildSelector(options, project.prefix || '');
42
42
  (0, validation_1.validateHtmlSelector)(options.selector);
43
+ (0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
43
44
  const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
44
45
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
45
46
  (0, schematics_1.applyTemplates)({
@@ -1,11 +1,21 @@
1
1
  {
2
2
  "schematics": {
3
3
  "use-application-builder": {
4
- "version": "18.0.0",
4
+ "version": "19.0.0",
5
5
  "factory": "./use-application-builder/migration",
6
6
  "description": "Migrate application projects to the new build system. Application projects that are using the '@angular-devkit/build-angular' package's 'browser' and/or 'browser-esbuild' builders will be migrated to use the new 'application' builder. You can read more about this, including known issues and limitations, here: https://angular.dev/tools/cli/build-system-migration",
7
7
  "optional": true,
8
8
  "documentation": "tools/cli/build-system-migration"
9
+ },
10
+ "update-workspace-config": {
11
+ "version": "19.0.0",
12
+ "factory": "./update-workspace-config/migration",
13
+ "description": "Update the workspace configuration by replacing deprecated options in 'angular.json' for compatibility with the latest Angular CLI changes."
14
+ },
15
+ "update-ssr-imports": {
16
+ "version": "19.0.0",
17
+ "factory": "./update-ssr-imports/migration",
18
+ "description": "Update '@angular/ssr' import paths to use the new '/node' entry point when 'CommonEngine' is detected."
9
19
  }
10
20
  }
11
21
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import { Rule } from '@angular-devkit/schematics';
9
+ /**
10
+ * Schematics rule that identifies and updates import declarations in TypeScript files.
11
+ * Specifically, it modifies imports of '@angular/ssr' by appending '/node' if the
12
+ * `CommonEngine` is used from the old entry point.
13
+ *
14
+ */
15
+ export default function (): Rule;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.default = default_1;
34
+ const ts = __importStar(require("../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
35
+ function* visit(directory) {
36
+ for (const path of directory.subfiles) {
37
+ if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {
38
+ const entry = directory.file(path);
39
+ if (entry) {
40
+ const content = entry.content;
41
+ if (content.includes('CommonEngine') && !content.includes('@angular/ssr/node')) {
42
+ const source = ts.createSourceFile(entry.path, content.toString().replace(/^\uFEFF/, ''), ts.ScriptTarget.Latest, true);
43
+ yield source;
44
+ }
45
+ }
46
+ }
47
+ }
48
+ for (const path of directory.subdirs) {
49
+ if (path === 'node_modules' || path.startsWith('.')) {
50
+ continue;
51
+ }
52
+ yield* visit(directory.dir(path));
53
+ }
54
+ }
55
+ /**
56
+ * Schematics rule that identifies and updates import declarations in TypeScript files.
57
+ * Specifically, it modifies imports of '@angular/ssr' by appending '/node' if the
58
+ * `CommonEngine` is used from the old entry point.
59
+ *
60
+ */
61
+ function default_1() {
62
+ return (tree) => {
63
+ for (const sourceFile of visit(tree.root)) {
64
+ let recorder;
65
+ const allImportDeclarations = sourceFile.statements.filter((n) => ts.isImportDeclaration(n));
66
+ if (allImportDeclarations.length === 0) {
67
+ continue;
68
+ }
69
+ const ssrImports = allImportDeclarations.filter((n) => ts.isStringLiteral(n.moduleSpecifier) && n.moduleSpecifier.text === '@angular/ssr');
70
+ for (const ssrImport of ssrImports) {
71
+ const ssrNamedBinding = getNamedImports(ssrImport);
72
+ if (ssrNamedBinding) {
73
+ const isUsingOldEntryPoint = ssrNamedBinding.elements.some((e) => e.name.text.startsWith('CommonEngine'));
74
+ if (!isUsingOldEntryPoint) {
75
+ continue;
76
+ }
77
+ recorder ??= tree.beginUpdate(sourceFile.fileName);
78
+ recorder.insertRight(ssrImport.moduleSpecifier.getEnd() - 1, '/node');
79
+ }
80
+ }
81
+ if (recorder) {
82
+ tree.commitUpdate(recorder);
83
+ }
84
+ }
85
+ };
86
+ }
87
+ function getNamedImports(importDeclaration) {
88
+ const namedBindings = importDeclaration?.importClause?.namedBindings;
89
+ if (namedBindings && ts.isNamedImports(namedBindings)) {
90
+ return namedBindings;
91
+ }
92
+ return undefined;
93
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import { Rule } from '@angular-devkit/schematics';
9
+ /**
10
+ * Main entry point for the migration rule.
11
+ *
12
+ * This schematic migration performs updates to the Angular workspace configuration
13
+ * to ensure that application projects are properly configured with polyfills
14
+ * required for internationalization (`localize`).
15
+ *
16
+ * It specifically targets application projects that use either the `application`
17
+ * or `browser-esbuild` builders.
18
+ *
19
+ * The migration process involves:
20
+ *
21
+ * 1. Iterating over all projects in the workspace.
22
+ * 2. Checking each project to determine if it is an application-type project.
23
+ * 3. For each application project, examining the associated build targets.
24
+ * 4. If a build target's `localize` option is enabled but the polyfill
25
+ * `@angular/localize/init` is missing from the `polyfills` array, the polyfill
26
+ * is automatically added to ensure proper internationalization support.
27
+ *
28
+ * Additionally, this migration updates projects that use the `dev-server` or `extract-i18n`
29
+ * builders to ensure that deprecated `browserTarget` options are migrated to the
30
+ * newer `buildTarget` field.
31
+ *
32
+ */
33
+ export default function (): Rule;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.default = default_1;
11
+ const workspace_1 = require("../../utility/workspace");
12
+ const workspace_models_1 = require("../../utility/workspace-models");
13
+ /**
14
+ * Main entry point for the migration rule.
15
+ *
16
+ * This schematic migration performs updates to the Angular workspace configuration
17
+ * to ensure that application projects are properly configured with polyfills
18
+ * required for internationalization (`localize`).
19
+ *
20
+ * It specifically targets application projects that use either the `application`
21
+ * or `browser-esbuild` builders.
22
+ *
23
+ * The migration process involves:
24
+ *
25
+ * 1. Iterating over all projects in the workspace.
26
+ * 2. Checking each project to determine if it is an application-type project.
27
+ * 3. For each application project, examining the associated build targets.
28
+ * 4. If a build target's `localize` option is enabled but the polyfill
29
+ * `@angular/localize/init` is missing from the `polyfills` array, the polyfill
30
+ * is automatically added to ensure proper internationalization support.
31
+ *
32
+ * Additionally, this migration updates projects that use the `dev-server` or `extract-i18n`
33
+ * builders to ensure that deprecated `browserTarget` options are migrated to the
34
+ * newer `buildTarget` field.
35
+ *
36
+ */
37
+ function default_1() {
38
+ return (0, workspace_1.updateWorkspace)((workspace) => {
39
+ for (const project of workspace.projects.values()) {
40
+ if (project.extensions.projectType !== workspace_models_1.ProjectType.Application) {
41
+ continue;
42
+ }
43
+ for (const target of project.targets.values()) {
44
+ if (target.builder === workspace_models_1.Builders.DevServer || target.builder === workspace_models_1.Builders.ExtractI18n) {
45
+ // Migrate `browserTarget` to `buildTarget`
46
+ for (const [, options] of (0, workspace_1.allTargetOptions)(target, false)) {
47
+ if (options['browserTarget'] && !options['buildTarget']) {
48
+ options['buildTarget'] = options['browserTarget'];
49
+ }
50
+ delete options['browserTarget'];
51
+ }
52
+ }
53
+ // Check if the target uses application-related builders
54
+ if (target.builder !== workspace_models_1.Builders.BuildApplication &&
55
+ target.builder !== workspace_models_1.Builders.Application &&
56
+ target.builder !== workspace_models_1.Builders.BrowserEsbuild) {
57
+ continue;
58
+ }
59
+ // Check if polyfills include '@angular/localize/init'
60
+ const polyfills = target.options?.['polyfills'];
61
+ if (Array.isArray(polyfills) &&
62
+ polyfills.some((polyfill) => typeof polyfill === 'string' && polyfill.startsWith('@angular/localize'))) {
63
+ // Skip if the polyfill is already present
64
+ continue;
65
+ }
66
+ // Add '@angular/localize/init' polyfill if localize option is enabled
67
+ for (const [, options] of (0, workspace_1.allTargetOptions)(target, false)) {
68
+ if (options['localize']) {
69
+ target.options ??= {};
70
+ (target.options['polyfills'] ??= []).push('@angular/localize/init');
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ });
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematics/angular",
3
- "version": "19.0.0-next.0",
3
+ "version": "19.0.0-next.10",
4
4
  "description": "Schematics specific to Angular",
5
5
  "homepage": "https://github.com/angular/angular-cli",
6
6
  "keywords": [
@@ -22,11 +22,11 @@
22
22
  },
23
23
  "schematics": "./collection.json",
24
24
  "dependencies": {
25
- "@angular-devkit/core": "19.0.0-next.0",
26
- "@angular-devkit/schematics": "19.0.0-next.0",
25
+ "@angular-devkit/core": "19.0.0-next.10",
26
+ "@angular-devkit/schematics": "19.0.0-next.10",
27
27
  "jsonc-parser": "3.3.1"
28
28
  },
29
- "packageManager": "yarn@4.4.0",
29
+ "packageManager": "yarn@4.5.0",
30
30
  "repository": {
31
31
  "type": "git",
32
32
  "url": "https://github.com/angular/angular-cli.git"
@@ -0,0 +1,13 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { ServerModule } from '@angular/platform-server';
3
+ import { provideServerRoutesConfig } from '@angular/ssr';
4
+ import { AppComponent } from './app.component';
5
+ import { AppModule } from './app.module';
6
+ import { serverRoutes } from './app.routes.server';
7
+
8
+ @NgModule({
9
+ imports: [AppModule, ServerModule],
10
+ providers: [provideServerRoutesConfig(serverRoutes)],
11
+ bootstrap: [AppComponent],
12
+ })
13
+ export class AppServerModule {}
@@ -0,0 +1,8 @@
1
+ import { RenderMode, ServerRoute } from '@angular/ssr';
2
+
3
+ export const serverRoutes: ServerRoute[] = [
4
+ {
5
+ path: '**',
6
+ renderMode: RenderMode.Prerender
7
+ }
8
+ ];
@@ -0,0 +1,14 @@
1
+ import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
2
+ import { provideServerRendering } from '@angular/platform-server';
3
+ import { provideServerRoutesConfig } from '@angular/ssr';
4
+ import { appConfig } from './app.config';
5
+ import { serverRoutes } from './app.routes.server';
6
+
7
+ const serverConfig: ApplicationConfig = {
8
+ providers: [
9
+ provideServerRendering(),
10
+ provideServerRoutesConfig(serverRoutes)
11
+ ]
12
+ };
13
+
14
+ export const config = mergeApplicationConfig(appConfig, serverConfig);
@@ -0,0 +1,8 @@
1
+ import { RenderMode, ServerRoute } from '@angular/ssr';
2
+
3
+ export const serverRoutes: ServerRoute[] = [
4
+ {
5
+ path: '**',
6
+ renderMode: RenderMode.Prerender
7
+ }
8
+ ];
@@ -0,0 +1 @@
1
+ export { AppServerModule as default } from './app/app.module.server';
@@ -0,0 +1,7 @@
1
+ import { bootstrapApplication } from '@angular/platform-browser';
2
+ import { AppComponent } from './app/app.component';
3
+ import { config } from './app/app.config.server';
4
+
5
+ const bootstrap = () => bootstrapApplication(AppComponent, config);
6
+
7
+ export default bootstrap;