Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: migrate to Angular v17 #1642

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

Merged
merged 19 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"prefer-rest-params": "warn",
"no-prototype-builtins": "warn",
"no-empty": "warn"
Expand Down
15 changes: 7 additions & 8 deletions apps/demos/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,31 @@
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "demos:build",
"port": 4300
"port": 4300,
"buildTarget": "demos:build"
},
"configurations": {
"production": {
"browserTarget": "demos:build:production"
"buildTarget": "demos:build:production"
},
"npm": {
"browserTarget": "demos:build:npm"
"buildTarget": "demos:build:npm"
},
"zoneless": {
"browserTarget": "demos:build:zoneless"
"buildTarget": "demos:build:zoneless"
}
}
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "demos:build"
"buildTarget": "demos:build"
}
},
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/demos/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/demos/jest.config.ts"
},
"outputs": ["{workspaceRoot}/coverage/apps/demos"]
}
Expand Down
34 changes: 23 additions & 11 deletions apps/demos/src/app/features/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,41 @@ import { Component } from '@angular/core';
selector: 'rxa-home',
template: `
<h1>Welcome to RxAngular Demos!</h1>
<h3>Explore various sections that will guide you through features of RxAngular.</h3>
<h3>
Explore various sections that will guide you through features of
RxAngular.
</h3>

<ul>
<li><h4>🏁 Fundamentals</h4></li>
Demos presenting fundamental rules and functionalities existing in Angular that are good to know before you start your journey with RxAngular.
Demos presenting fundamental rules and functionalities existing in Angular
that are good to know before you start your journey with RxAngular.

<li><h4>🧰 Template</h4></li>
Playground for different functionalities of the <code>@rx-angular/template</code> package.
Playground for different functionalities of the
<code>&#64;rx-angular/template</code>
package.

<li><h4>📋 Tutorials</h4></li>
Tutorials for features existing in the <code>@rx-angular</code> packages.
Tutorials for features existing in the
<code>&#64;rx-angular</code>
packages.

<li><h4>🧮 Integrations</h4></li>
<code>@rx-angular/state</code> integrated with different libraries and patterns.
<code>&#64;rx-angular/state</code>
integrated with different libraries and patterns.

<li><h4>🔬 Experiments</h4></li>
Experiments with features, that are still under development. ⚠️Warning! ⚠️Unstable or broken features may lay ahead!
Experiments with features, that are still under development. ⚠️Warning!
⚠️Unstable or broken features may lay ahead!
</ul>
`,
styles: [`
code {
background: black;
}
`]
styles: [
`
code {
background: black;
}
`,
],
})
export class HomeComponent {}
11 changes: 5 additions & 6 deletions apps/ssr/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,25 @@
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "ssr:build"
"buildTarget": "ssr:build"
},
"configurations": {
"production": {
"browserTarget": "ssr:build:production"
"buildTarget": "ssr:build:production"
}
}
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "ssr:build"
"buildTarget": "ssr:build"
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/ssr"],
"options": {
"jestConfig": "apps/ssr/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/ssr/jest.config.ts"
}
},
"server": {
Expand All @@ -102,7 +101,7 @@
}
},
"serve-ssr": {
"executor": "@nguniversal/builders:ssr-dev-server",
"executor": "@angular-devkit/build-angular:ssr-dev-server",
"options": {
"browserTarget": "ssr:build",
"serverTarget": "ssr:server"
Expand Down
52 changes: 32 additions & 20 deletions apps/ssr/server.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
import 'zone.js/node';

import { ngExpressEngine } from '@nguniversal/express-engine';
import * as express from 'express';
import { join } from 'path';

import { AppServerModule } from './src/main.server';
import { APP_BASE_HREF } from '@angular/common';
import { existsSync } from 'fs';
import { CommonEngine } from '@angular/ssr';
import * as express from 'express';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import bootstrap from './src/main.server';

// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/apps/ssr/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? join(distFolder, 'index.original.html')
: join(distFolder, 'index.html');

// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
}));
const commonEngine = new CommonEngine();

server.set('view engine', 'html');
server.set('views', distFolder);

// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
server.get(
'*.*',
express.static(distFolder, {
maxAge: '1y',
})
);

// All regular routes use the Angular engine
server.get('*', (req, res, next) => {
const { protocol, originalUrl, baseUrl, headers } = req;

// All regular routes use the Universal engine
server.get('*', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
commonEngine
.render({
bootstrap,
documentFilePath: indexHtml,
url: `${protocol}://${headers.host}${originalUrl}`,
publicPath: distFolder,
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
})
.then((html) => res.send(html))
.catch((err) => next(err));
});

return server;
}

function run(): void {
const port = process.env.PORT || 4000;
const port = process.env['PORT'] || 4000;

// Start up the Node server
const server = app();
Expand All @@ -52,9 +64,9 @@ function run(): void {
// The below code is to ensure that the server is run only when not requiring the bundle.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = mainModule && mainModule.filename || '';
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}

export * from './src/main.server';
export default bootstrap;
6 changes: 6 additions & 0 deletions apps/ssr/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { isPlatformServer } from '@angular/common';
import { Component, Inject, NgZone, OnInit, PLATFORM_ID } from '@angular/core';
import { rxState } from '@rx-angular/state';
import { RxFor } from '@rx-angular/template/for';
import { RxLet } from '@rx-angular/template/let';
import { RxPush } from '@rx-angular/template/push';
import { RxUnpatch } from '@rx-angular/template/unpatch';
import { of } from 'rxjs';

@Component({
selector: 'rx-angular-root',
standalone: true,
template: `
<div id="let" *rxLet="color$; let color">{{ color }}</div>
<div id="push">{{ color$ | push }}</div>
<div id="unpatch" [unpatch]="['click']" (click)="onClick()"></div>
<div class="for" *rxFor="let color of colors$">{{ color }}</div>
`,
imports: [RxPush, RxLet, RxUnpatch, RxFor],
})
export class AppComponent implements OnInit {
private readonly state = rxState<{ color: string; colors: string[] }>(
Expand Down
9 changes: 9 additions & 0 deletions apps/ssr/src/app/app.config.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering } from '@angular/platform-server';
import { appConfig } from './app.config';

const serverConfig: ApplicationConfig = {
providers: [provideServerRendering()],
};

export const config = mergeApplicationConfig(appConfig, serverConfig);
7 changes: 7 additions & 0 deletions apps/ssr/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ApplicationConfig } from '@angular/core';

import { provideClientHydration } from '@angular/platform-browser';

export const appConfig: ApplicationConfig = {
providers: [provideClientHydration()],
};
21 changes: 0 additions & 21 deletions apps/ssr/src/app/app.module.ts

This file was deleted.

14 changes: 0 additions & 14 deletions apps/ssr/src/app/app.server.module.ts

This file was deleted.

12 changes: 5 additions & 7 deletions apps/ssr/src/main.server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { config } from './app/app.config.server';

import { environment } from './environments/environment';
const bootstrap = () => bootstrapApplication(AppComponent, config);

if (environment.production) {
enableProdMode();
}

export { AppServerModule } from './app/app.server.module';
export default bootstrap;
20 changes: 6 additions & 14 deletions apps/ssr/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
enableProdMode();
}

document.addEventListener('DOMContentLoaded', () => {
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));
});
bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err)
);
2 changes: 1 addition & 1 deletion libs/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"url": "https://github.com/rx-angular/rx-angular.git"
},
"peerDependencies": {
"@angular/core": "^16.0.0",
"@angular/core": "^17.0.0",
"rxjs": "^6.5.3 || ^7.4.0"
},
"dependencies": {
Expand Down
1 change: 0 additions & 1 deletion libs/cdk/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "libs/cdk/jest.config.ts",
"passWithNoTests": true,
"codeCoverage": true
},
"outputs": ["{workspaceRoot}/coverage/cdk"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ describe('cdk migration 1.0.0-beta.1', () => {

tree.create(filePath, fileInput);

return runner
.runSchematicAsync(`update-1.0.0-beta.1`, {}, tree)
.toPromise();
return runner.runSchematic(`update-1.0.0-beta.1`, {}, tree);
}
});
6 changes: 5 additions & 1 deletion libs/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "1.0.0",
"peerDependencies": {
"eslint": ">=8.0.0",
"typescript": ">=4.3.5"
"typescript": ">=4.3.5",
"@typescript-eslint/parser": "^6.10.0"
},
"dependencies": {
"@typescript-eslint/utils": "^6.10.0"
}
}
3 changes: 1 addition & 2 deletions libs/eslint-plugin/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/eslint-plugin"],
"options": {
"jestConfig": "libs/eslint-plugin/jest.config.ts",
"passWithNoTests": true
"jestConfig": "libs/eslint-plugin/jest.config.ts"
}
},
"build": {
Expand Down
Loading