Skip to content

feat: support angular@20 #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d1eb0de
test: upgrade demo to 20-next
pieh Apr 11, 2025
a8de33c
chore(demo): ensure min supported node version
pieh Apr 11, 2025
d023e2a
chore: manual migration of app.config.server.ts
pieh Apr 11, 2025
074bc3c
Merge remote-tracking branch 'origin/main' into chore/try-20
pieh Apr 18, 2025
f931f0b
chore: bump
pieh Apr 18, 2025
498862f
chore: bump to rc.0
pieh May 13, 2025
b3f6f44
Merge remote-tracking branch 'origin/main' into chore/try-20
pieh May 13, 2025
353e63a
chore: bump to newest rc
pieh May 20, 2025
32181e1
Merge remote-tracking branch 'origin/main' into chore/try-20
pieh May 20, 2025
c98527c
test: add 20-rc fixtures
pieh May 20, 2025
d308467
fix: add angular-20 server.ts signature
pieh May 20, 2025
9f2ffc7
fix: handle case of outputPath not being explicitly defined
pieh May 20, 2025
7fb6080
chore: remove outputPath from demo's angular.json to follow newly sca…
pieh May 20, 2025
0c284ee
fix: nx handling
pieh May 20, 2025
1f18438
test: install new fixtures deps
pieh May 20, 2025
c7cdd32
chore: skip angular@20 on not supported node versions
pieh May 20, 2025
581d156
chore: bump node18 version a bit to match node18 compatible angular m…
pieh May 20, 2025
23ebfa0
chore: add node22 to test matrix
pieh May 20, 2025
2e80a23
chore: don't suggest common engine for Angular 20
pieh May 20, 2025
9a50e78
docs: refresh readme for Angular 20
pieh May 20, 2025
9463872
chore: bump min to 20.19
pieh May 21, 2025
dea254f
fix: add link to repo readme for more details
pieh May 22, 2025
e154ae0
chore: upgrade demo and recreate angular-20 fixtures using most recen…
pieh May 23, 2025
189b651
Merge remote-tracking branch 'origin/main' into chore/try-20
pieh May 23, 2025
f650742
chore: sync lock files
pieh May 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [18.19.0, 20.13.1]
node-version: [18.19.1, 20.19.1, 22]
exclude:
- os: macOS-latest
node-version: 18.19.0
node-version: 18.19.1
- os: windows-latest
node-version: 18.19.0
node-version: 18.19.1
- os: macOS-latest
node-version: 20.19.1
- os: windows-latest
node-version: 20.19.1
fail-fast: false

steps:
Expand All @@ -31,6 +35,6 @@ jobs:
name: NPM Install
- name: Linting
run: npm run format:ci
if: "${{ matrix.node-version == '20.13.1' }}"
if: "${{ matrix.node-version == '20.19.1' }}"
- name: Run tests
run: npm run test
51 changes: 27 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ Netlify automatically detects Angular projects and sets up the latest version of

There's no further configuration needed from Netlify users.

### For Angular 19
### For Angular 19 and Angular 20

If you are using Server-Side Rendering you will need to install Angular Runtime in your Angular project to be able to import required utilities to successfully deploy request handler to Netlify. See [Manual Installation](#manual-installation) for installations details. See [Request handling](#request-handling) for more information about request handler.

### Manual Installation

If you need to pin this plugin to a specific version or if you are using Server-Side Rendering with Angular 19, you will need to install the plugin manually.
If you need to pin this plugin to a specific version or if you are using Server-Side Rendering with Angular 19 or Angular 20, you will need to install the plugin manually.

Install it via your package manager:

Expand Down Expand Up @@ -77,9 +77,10 @@ To test this in local development, run your Angular project using `netlify serve
```sh
netlify serve
```
### App Engine Developer Preview usage with Angular@19

If you opt into the App Engine Developer Preview accessing `Request` and `Context` objects is streamlined. Instead of custom Netlify prefixed providers, you should use the standardized injection tokens for those provided by `@angular/core` instead:
### App Engine usage

With App Engine accessing `Request` and `Context` objects is streamlined. Instead of custom Netlify prefixed providers, you should use the standardized injection tokens for those provided by `@angular/core` instead:

```diff
+import { REQUEST, REQUEST_CONTEXT } from '@angular/core'
Expand All @@ -101,6 +102,8 @@ export class FooComponent {
}
```

Note that App Engine in Angular 19 is in Developer Preview and requires explicit opt-in.

## Request handling

Starting with Angular@19. The build plugin makes use of the `server.ts` file to handle requests. The default Angular scaffolding generates incompatible code for Netlify so the build plugin will swap it for compatible `server.ts` file automatically if it detects default version being used.
Expand All @@ -111,52 +114,52 @@ Make sure you have `@netlify/angular-runtime` version 2.2.0 or later installed i

If you need to customize the request handling, you can do so by copying one of code snippets below to your `server.ts` file.

If you did not opt into the App Engine Developer Preview:
If you are using Angular 20 or Angular 19 with App Engine Developer Preview:

```ts
import { CommonEngine } from '@angular/ssr/node'
import { render } from '@netlify/angular-runtime/common-engine.mjs'
import { AngularAppEngine, createRequestHandler } from '@angular/ssr'
import { getContext } from '@netlify/angular-runtime/context.mjs'

const commonEngine = new CommonEngine()
const angularAppEngine = new AngularAppEngine()

export async function netlifyAppEngineHandler(request: Request): Promise<Response> {
const context = getContext()

export async function netlifyCommonEngineHandler(request: Request, context: any): Promise<Response> {
// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// if (pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }

return await render(commonEngine)
const result = await angularAppEngine.handle(request, context)
return result || new Response('Not found', { status: 404 })
}

/**
* The request handler used by the Angular CLI (dev-server and during build).
*/
export const reqHandler = createRequestHandler(netlifyAppEngineHandler)
```

If you opted into the App Engine Developer Preview:
If you are using Angular 19 and did not opt into the App Engine Developer Preview:

```ts
import { AngularAppEngine, createRequestHandler } from '@angular/ssr'
import { getContext } from '@netlify/angular-runtime/context.mjs'

const angularAppEngine = new AngularAppEngine()
import { CommonEngine } from '@angular/ssr/node'
import { render } from '@netlify/angular-runtime/common-engine.mjs'

export async function netlifyAppEngineHandler(request: Request): Promise<Response> {
const context = getContext()
const commonEngine = new CommonEngine()

export async function netlifyCommonEngineHandler(request: Request, context: any): Promise<Response> {
// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// if (pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }

const result = await angularAppEngine.handle(request, context)
return result || new Response('Not found', { status: 404 })
return await render(commonEngine)
}

/**
* The request handler used by the Angular CLI (dev-server and during build).
*/
export const reqHandler = createRequestHandler(netlifyAppEngineHandler)
```

### Limitations
Expand Down
37 changes: 23 additions & 14 deletions demo.test.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import assert from 'node:assert'
import { versions } from 'node:process'
import { test } from 'node:test'

test('edge function config', async () => {
const { config } = await import('./demo/.netlify/edge-functions/angular-ssr/angular-ssr.mjs')
import { satisfies } from 'semver'

const excludedPathsWithMaskedHashes = config.excludedPath.map((path) => path.replace(/-[A-Z\d]{8}\./, '-HASHHASH.'))
test(
'edge function config',
{
skip: !satisfies(versions.node, '>=20.11'),
},
async () => {
const { config } = await import('./demo/.netlify/edge-functions/angular-ssr/angular-ssr.mjs')

assert.deepEqual(excludedPathsWithMaskedHashes, [
'/.netlify/*',
'/favicon.ico',
'/heroes/index.html',
'/index.csr.html',
'/main-HASHHASH.js',
'/polyfills-HASHHASH.js',
'/styles-HASHHASH.css',
'/heroes',
])
})
const excludedPathsWithMaskedHashes = config.excludedPath.map((path) => path.replace(/-[A-Z\d]{8}\./, '-HASHHASH.'))

assert.deepEqual(excludedPathsWithMaskedHashes, [
'/.netlify/*',
'/favicon.ico',
'/heroes/index.html',
'/index.csr.html',
'/main-HASHHASH.js',
'/polyfills-HASHHASH.js',
'/styles-HASHHASH.css',
'/heroes',
])
},
)
35 changes: 30 additions & 5 deletions demo/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"builder": "@angular/build:application",
"options": {
"outputPath": "dist/demo",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
Expand Down Expand Up @@ -59,7 +58,7 @@
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"builder": "@angular/build:dev-server",
"configurations": {
"production": {
"buildTarget": "demo:build:production"
Expand All @@ -71,13 +70,13 @@
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"builder": "@angular/build:extract-i18n",
"options": {
"buildTarget": "demo:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"builder": "@angular/build:karma",
"options": {
"polyfills": [
"zone.js",
Expand All @@ -99,5 +98,31 @@
},
"cli": {
"analytics": false
},
"schematics": {
"@schematics/angular:component": {
"type": "component"
},
"@schematics/angular:directive": {
"type": "directive"
},
"@schematics/angular:service": {
"type": "service"
},
"@schematics/angular:guard": {
"typeSeparator": "."
},
"@schematics/angular:interceptor": {
"typeSeparator": "."
},
"@schematics/angular:module": {
"typeSeparator": "."
},
"@schematics/angular:pipe": {
"typeSeparator": "."
},
"@schematics/angular:resolver": {
"typeSeparator": "."
}
}
}
Loading