Skip to content

Commit 0f63a01

Browse files
committed
Restore Angular 14 compatibility
1 parent f70b559 commit 0f63a01

12 files changed

+192
-17
lines changed

angular.json

+7-12
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
"outputPath": "dist/ng2-charts-demo",
2121
"index": "src/index.html",
2222
"main": "src/main.ts",
23-
"polyfills": [
24-
"zone.js"
25-
],
23+
"polyfills": "src/polyfills.ts",
2624
"tsConfig": "tsconfig.app.json",
2725
"assets": [
2826
"src/favicon.ico",
@@ -97,17 +95,16 @@
9795
"test": {
9896
"builder": "@angular-devkit/build-angular:karma",
9997
"options": {
100-
"polyfills": [
101-
"zone.js",
102-
"zone.js/testing"
103-
],
98+
"main": "src/test.ts",
99+
"karmaConfig": "karma.conf.js",
100+
"polyfills": "src/polyfills.ts",
104101
"tsConfig": "tsconfig.spec.json",
105102
"assets": [
106103
"src/favicon.ico",
107104
"src/assets"
108105
],
109106
"styles": [
110-
"@angular/material/prebuilt-themes/deeppurple-amber.css",
107+
"node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
111108
"src/styles.scss"
112109
],
113110
"scripts": []
@@ -177,11 +174,9 @@
177174
"test": {
178175
"builder": "@angular-devkit/build-angular:karma",
179176
"options": {
177+
"main": "projects/ng2-charts/src/test.ts",
180178
"tsConfig": "projects/ng2-charts/tsconfig.spec.json",
181-
"polyfills": [
182-
"zone.js",
183-
"zone.js/testing"
184-
]
179+
"karmaConfig": "projects/ng2-charts/karma.conf.js"
185180
}
186181
},
187182
"lint": {

karma.conf.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-coverage'),
11+
require('karma-chrome-launcher'),
12+
require('karma-jasmine-html-reporter'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
clearContext: false // leave Jasmine Spec Runner output visible in browser
17+
},
18+
coverageIstanbulReporter: {
19+
dir: require('path').join(__dirname, '../coverage/ng2-charts-demo'),
20+
reports: ['html', 'lcovonly', 'text-summary'],
21+
fixWebpackSourcePaths: true
22+
},
23+
reporters: ['progress', 'kjhtml'],
24+
port: 9876,
25+
colors: true,
26+
logLevel: config.LOG_INFO,
27+
autoWatch: true,
28+
browsers: ['Chrome', 'ChromeHeadless'],
29+
singleRun: false,
30+
restartOnFileChange: true
31+
});
32+
};

projects/ng2-charts/karma.conf.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-coverage'),
11+
require('karma-chrome-launcher'),
12+
require('karma-jasmine-html-reporter'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
clearContext: false // leave Jasmine Spec Runner output visible in browser
17+
},
18+
coverageIstanbulReporter: {
19+
dir: require('path').join(__dirname, '../../coverage/ng2-charts'),
20+
reports: ['html', 'lcovonly'],
21+
fixWebpackSourcePaths: true
22+
},
23+
reporters: ['progress', 'kjhtml'],
24+
port: 9876,
25+
colors: true,
26+
logLevel: config.LOG_INFO,
27+
autoWatch: true,
28+
browsers: ['Chrome'],
29+
singleRun: false,
30+
restartOnFileChange: true
31+
});
32+
};

projects/ng2-charts/src/test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
2+
3+
// import 'core-js/es7/reflect';
4+
import 'zone.js';
5+
import 'zone.js/testing';
6+
import { getTestBed } from '@angular/core/testing';
7+
import {
8+
BrowserDynamicTestingModule,
9+
platformBrowserDynamicTesting
10+
} from '@angular/platform-browser-dynamic/testing';
11+
12+
declare const require: any;
13+
14+
// First, initialize the Angular testing environment.
15+
getTestBed().initTestEnvironment(
16+
BrowserDynamicTestingModule,
17+
platformBrowserDynamicTesting()
18+
);
19+
// Then we find all the tests.
20+
const context = require.context('./', true, /\.spec\.ts$/);
21+
// And load the modules.
22+
context.keys().map(context);

projects/ng2-charts/tsconfig.lib.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33
"extends": "../../tsconfig.json",
44
"compilerOptions": {
55
"outDir": "../../out-tsc/lib",
6+
"target": "es2020",
67
"declaration": true,
78
"declarationMap": true,
89
"inlineSources": true,
9-
"types": []
10+
"types": [],
11+
"lib": [
12+
"dom",
13+
"es2018"
14+
]
15+
},
16+
"angularCompilerOptions": {
17+
"skipTemplateCodegen": true,
18+
"strictMetadataEmit": true,
19+
"enableResourceInlining": true
1020
},
1121
"exclude": [
22+
"src/test.ts",
1223
"**/*.spec.ts"
1324
]
1425
}

projects/ng2-charts/tsconfig.lib.prod.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"declarationMap": false
66
},
77
"angularCompilerOptions": {
8+
"enableIvy": true,
89
"compilationMode": "partial"
910
}
1011
}

projects/ng2-charts/tsconfig.spec.json

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"jasmine"
88
]
99
},
10+
"files": [
11+
"src/test.ts"
12+
],
1013
"include": [
1114
"**/*.spec.ts",
1215
"**/*.d.ts"

src/polyfills.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* This file includes polyfills needed by Angular and is loaded before the app.
3+
* You can add your own extra polyfills to this file.
4+
*
5+
* This file is divided into 2 sections:
6+
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7+
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8+
* file.
9+
*
10+
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11+
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12+
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13+
*
14+
* Learn more in https://angular.io/guide/browser-support
15+
*/
16+
17+
/***************************************************************************************************
18+
* BROWSER POLYFILLS
19+
*/
20+
21+
/**
22+
* By default, zone.js will patch all possible macroTask and DomEvents
23+
* user can disable parts of macroTask/DomEvents patch by setting following flags
24+
* because those flags need to be set before `zone.js` being loaded, and webpack
25+
* will put import in the top of bundle, so user need to create a separate file
26+
* in this directory (for example: zone-flags.ts), and put the following flags
27+
* into that file, and then add the following code before importing zone.js.
28+
* import './zone-flags';
29+
*
30+
* The flags allowed in zone-flags.ts are listed here.
31+
*
32+
* The following flags will work for all browsers.
33+
*
34+
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
35+
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
36+
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
37+
*
38+
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
39+
* with the following flag, it will bypass `zone.js` patch for IE/Edge
40+
*
41+
* (window as any).__Zone_enable_cross_context_check = true;
42+
*
43+
*/
44+
45+
/***************************************************************************************************
46+
* Zone JS is required by default for Angular itself.
47+
*/
48+
import 'zone.js'; // Included with Angular CLI.
49+
50+
51+
/***************************************************************************************************
52+
* APPLICATION IMPORTS
53+
*/

src/test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
2+
3+
import 'zone.js/testing';
4+
import { getTestBed } from '@angular/core/testing';
5+
import {
6+
BrowserDynamicTestingModule,
7+
platformBrowserDynamicTesting
8+
} from '@angular/platform-browser-dynamic/testing';
9+
10+
declare const require: any;
11+
12+
// First, initialize the Angular testing environment.
13+
getTestBed().initTestEnvironment(
14+
BrowserDynamicTestingModule,
15+
platformBrowserDynamicTesting()
16+
);
17+
// Then we find all the tests.
18+
const context = require.context('./', true, /\.spec\.ts$/);
19+
// And load the modules.
20+
context.keys().map(context);

tsconfig.app.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
]
99
},
1010
"files": [
11-
"src/main.ts"
11+
"src/main.ts",
12+
"src/polyfills.ts"
1213
],
1314
"include": [
1415
"src/**/*.d.ts"

tsconfig.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"skipLibCheck": true,
1616
"moduleResolution": "node",
1717
"importHelpers": true,
18-
"target": "ES2022",
18+
"target": "es2020",
1919
"module": "es2020",
2020
"lib": [
2121
"es2018",
@@ -26,8 +26,7 @@
2626
"dist/ng2-charts/ng2-charts",
2727
"dist/ng2-charts"
2828
]
29-
},
30-
"useDefineForClassFields": false
29+
}
3130
},
3231
"angularCompilerOptions": {
3332
"enableI18nLegacyMessageIdFormat": false,

tsconfig.spec.json

+6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
12
{
23
"extends": "./tsconfig.json",
34
"compilerOptions": {
45
"outDir": "./out-tsc/spec",
56
"types": [
7+
"node",
68
"jasmine"
79
]
810
},
11+
"files": [
12+
"src/test.ts",
13+
"src/polyfills.ts"
14+
],
915
"include": [
1016
"src/**/*.spec.ts",
1117
"src/**/*.d.ts"

0 commit comments

Comments
 (0)