From 3f8aa9d8c7dc7eff06516c04ba08764bb044cb6b Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 8 Sep 2023 09:34:22 +0000 Subject: [PATCH] feat(@schematics/angular): update` ng new` to use the esbuild application builder based builder This commit updates the `ng generate application` to use the esbuild `application` builder. This also updates the schematics to support both `browser` and `application` builders. BREAKING CHANGE: `rootModuleClassName`, `rootModuleFileName` and `main` options have been removed from the public `pwa` and `app-shell` schematics. --- packages/angular/pwa/pwa/index.ts | 5 +- packages/angular/pwa/pwa/index_spec.ts | 183 ++++++------- packages/angular/ssr/package.json | 3 + .../application-builder/server.ts.template | 53 ++++ .../{ => server-builder}/server.ts.template | 4 +- .../angular/ssr/schematics/ng-add/index.ts | 155 +++++++---- .../ssr/schematics/ng-add/index_spec.ts | 100 +++++-- .../angular/ssr/schematics/ng-add/schema.json | 17 -- .../src/builders/app-shell/render-worker.ts | 8 +- .../src/builders/prerender/render-worker.ts | 28 +- .../schematics/angular/app-shell/index.ts | 101 +++---- .../angular/app-shell/index_spec.ts | 88 +++--- .../schematics/angular/app-shell/schema.json | 21 -- .../schematics/angular/application/index.ts | 7 +- .../angular/application/index_spec.ts | 4 +- packages/schematics/angular/collection.json | 8 +- .../schematics/angular/environments/index.ts | 8 +- .../angular/environments/index_spec.ts | 28 +- .../files/root/tsconfig.server.json.template | 2 +- .../src/app/app.module.server.ts.template} | 2 +- .../server/files/src/main.server.ts.template | 1 + .../app/app.config.server.ts.template | 0 .../standalone-src/main.server.ts.template | 0 .../angular/{universal => server}/index.ts | 109 ++++++-- .../schematics/angular/server/index_spec.ts | 254 ++++++++++++++++++ .../schematics/angular/server/schema.json | 23 ++ .../angular/service-worker/index.ts | 62 ++--- .../angular/service-worker/index_spec.ts | 79 ++++-- .../src/__main@stripTsExtension__.ts.template | 2 - .../angular/universal/index_spec.ts | 242 ----------------- .../schematics/angular/universal/schema.json | 40 --- .../angular/utility/standalone/util.ts | 6 +- .../angular/utility/workspace-models.ts | 3 +- .../workspace/files/tsconfig.json.template | 1 + .../server/platform-server-build-optimizer.ts | 2 +- .../server/platform-server-standalone.ts | 2 +- .../e2e/tests/build/server/platform-server.ts | 2 +- 37 files changed, 953 insertions(+), 700 deletions(-) create mode 100644 packages/angular/ssr/schematics/ng-add/files/application-builder/server.ts.template rename packages/angular/ssr/schematics/ng-add/files/{ => server-builder}/server.ts.template (92%) rename packages/schematics/angular/{universal => server}/files/root/tsconfig.server.json.template (88%) rename packages/schematics/angular/{universal/files/src/app/__rootModuleFileName__.template => server/files/src/app/app.module.server.ts.template} (86%) create mode 100644 packages/schematics/angular/server/files/src/main.server.ts.template rename packages/schematics/angular/{universal => server}/files/standalone-src/app/app.config.server.ts.template (100%) rename packages/schematics/angular/{universal => server}/files/standalone-src/main.server.ts.template (100%) rename packages/schematics/angular/{universal => server}/index.ts (60%) create mode 100644 packages/schematics/angular/server/index_spec.ts create mode 100644 packages/schematics/angular/server/schema.json delete mode 100644 packages/schematics/angular/universal/files/src/__main@stripTsExtension__.ts.template delete mode 100644 packages/schematics/angular/universal/index_spec.ts delete mode 100644 packages/schematics/angular/universal/schema.json diff --git a/packages/angular/pwa/pwa/index.ts b/packages/angular/pwa/pwa/index.ts index 2b4996f0f324..0389e686a40e 100644 --- a/packages/angular/pwa/pwa/index.ts +++ b/packages/angular/pwa/pwa/index.ts @@ -114,7 +114,10 @@ export default function (options: PwaOptions): Rule { const buildTargets = []; const testTargets = []; for (const target of project.targets.values()) { - if (target.builder === '@angular-devkit/build-angular:browser') { + if ( + target.builder === '@angular-devkit/build-angular:browser' || + target.builder === '@angular-devkit/build-angular:application' + ) { buildTargets.push(target); } else if (target.builder === '@angular-devkit/build-angular:karma') { testTargets.push(target); diff --git a/packages/angular/pwa/pwa/index_spec.ts b/packages/angular/pwa/pwa/index_spec.ts index 9657b0493b31..e6b0d4e576bb 100644 --- a/packages/angular/pwa/pwa/index_spec.ts +++ b/packages/angular/pwa/pwa/index_spec.ts @@ -52,122 +52,123 @@ describe('PWA Schematic', () => { ); }); - it('should run the service worker schematic', (done) => { - schematicRunner - .runSchematic('ng-add', defaultOptions, appTree) - - .then((tree) => { - const configText = tree.readContent('/angular.json'); - const config = JSON.parse(configText); - const swFlag = config.projects.bar.architect.build.options.serviceWorker; - expect(swFlag).toEqual(true); - done(); - }, done.fail); - }); - - it('should create icon files', (done) => { + it('should create icon files', async () => { const dimensions = [72, 96, 128, 144, 152, 192, 384, 512]; const iconPath = '/projects/bar/src/assets/icons/icon-'; - schematicRunner - .runSchematic('ng-add', defaultOptions, appTree) - - .then((tree) => { - dimensions.forEach((d) => { - const path = `${iconPath}${d}x${d}.png`; - expect(tree.exists(path)).toEqual(true); - }); - done(); - }, done.fail); + const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); + + dimensions.forEach((d) => { + const path = `${iconPath}${d}x${d}.png`; + expect(tree.exists(path)).toBeTrue(); + }); }); - it('should create a manifest file', (done) => { - schematicRunner - .runSchematic('ng-add', defaultOptions, appTree) + it('should run the service worker schematic', async () => { + const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); + const configText = tree.readContent('/angular.json'); + const config = JSON.parse(configText); + const swFlag = config.projects.bar.architect.build.configurations.production.serviceWorker; - .then((tree) => { - expect(tree.exists('/projects/bar/src/manifest.webmanifest')).toEqual(true); - done(); - }, done.fail); + expect(swFlag).toBe('projects/bar/ngsw-config.json'); }); - it('should set the name & short_name in the manifest file', (done) => { - schematicRunner - .runSchematic('ng-add', defaultOptions, appTree) + it('should create a manifest file', async () => { + const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); + expect(tree.exists('/projects/bar/src/manifest.webmanifest')).toBeTrue(); + }); + + it('should set the name & short_name in the manifest file', async () => { + const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); - .then((tree) => { - const manifestText = tree.readContent('/projects/bar/src/manifest.webmanifest'); - const manifest = JSON.parse(manifestText); + const manifestText = tree.readContent('/projects/bar/src/manifest.webmanifest'); + const manifest = JSON.parse(manifestText); - expect(manifest.name).toEqual(defaultOptions.title); - expect(manifest.short_name).toEqual(defaultOptions.title); - done(); - }, done.fail); + expect(manifest.name).toEqual(defaultOptions.title); + expect(manifest.short_name).toEqual(defaultOptions.title); }); - it('should set the name & short_name in the manifest file when no title provided', (done) => { + it('should set the name & short_name in the manifest file when no title provided', async () => { const options = { ...defaultOptions, title: undefined }; - schematicRunner - .runSchematic('ng-add', options, appTree) + const tree = await schematicRunner.runSchematic('ng-add', options, appTree); - .then((tree) => { - const manifestText = tree.readContent('/projects/bar/src/manifest.webmanifest'); - const manifest = JSON.parse(manifestText); + const manifestText = tree.readContent('/projects/bar/src/manifest.webmanifest'); + const manifest = JSON.parse(manifestText); - expect(manifest.name).toEqual(defaultOptions.project); - expect(manifest.short_name).toEqual(defaultOptions.project); - done(); - }, done.fail); + expect(manifest.name).toEqual(defaultOptions.project); + expect(manifest.short_name).toEqual(defaultOptions.project); }); - it('should update the index file', (done) => { - schematicRunner - .runSchematic('ng-add', defaultOptions, appTree) - - .then((tree) => { - const content = tree.readContent('projects/bar/src/index.html'); + it('should update the index file', async () => { + const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); + const content = tree.readContent('projects/bar/src/index.html'); - expect(content).toMatch(//); - expect(content).toMatch(//); - expect(content).toMatch( - /