From 506cb1b02e9482c27afa5e9a55fda414a6e483c3 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Wed, 30 Nov 2022 19:11:08 -0500 Subject: [PATCH] downgrade to Angular 13 build system --- CONTRIBUTORS.md | 6 +++ README.md | 2 +- angular.json | 32 ++++++++------ app/.browserslistrc | 16 +++++++ app/karma.conf.js | 44 ++++++++++++++++++++ app/src/environments/environment.prod.ts | 3 ++ app/src/environments/environment.ts | 16 +++++++ app/src/main.ts | 7 ++++ app/src/polyfills.ts | 53 ++++++++++++++++++++++++ app/src/test.ts | 26 ++++++++++++ app/tsconfig.app.json | 3 +- app/tsconfig.spec.json | 4 ++ lib/.browserslistrc | 16 +++++++ lib/karma.conf.js | 44 ++++++++++++++++++++ lib/ng-package.json | 7 +--- lib/package.json | 4 +- lib/src/test.ts | 27 ++++++++++++ lib/tsconfig.lib.json | 1 + lib/tsconfig.spec.json | 3 ++ package.json | 41 +++++++++--------- tsconfig.json | 8 ++-- 21 files changed, 316 insertions(+), 47 deletions(-) create mode 100644 app/.browserslistrc create mode 100644 app/karma.conf.js create mode 100644 app/src/environments/environment.prod.ts create mode 100644 app/src/environments/environment.ts create mode 100644 app/src/polyfills.ts create mode 100644 app/src/test.ts create mode 100644 lib/.browserslistrc create mode 100644 lib/karma.conf.js create mode 100644 lib/src/test.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f0dccaf..00ad739 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -4,6 +4,12 @@ Information for people wanting to contribute code to this project. +## Special Monorepo Note + +Building this package only works (from a TypeScript perspective) if the outer monorepo is +fully BUILT, not in dev-mode. + + ## Important Directories This repo was initially created with Angular CLI, which is why certain directories are where they are: diff --git a/README.md b/README.md index 40c5917..f6c10de 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ This project is built and maintained by [irustm](https://github.com/irustm) in p ## Supported Angular Versions -`@fullcalendar/angular` version 5 supports Angular 9 - 15. +`@fullcalendar/angular` version 5 supports Angular 12 - 15. diff --git a/angular.json b/angular.json index d1cfcf3..d4bf154 100644 --- a/angular.json +++ b/angular.json @@ -27,18 +27,20 @@ "test": { "builder": "@angular-devkit/build-angular:karma", "options": { + "main": "lib/src/test.ts", "tsConfig": "lib/tsconfig.spec.json", - "polyfills": [ - "zone.js", - "zone.js/testing" - ] + "karmaConfig": "lib/karma.conf.js" } } } }, "app": { "projectType": "application", - "schematics": {}, + "schematics": { + "@schematics/angular:application": { + "strict": true + } + }, "root": "app", "sourceRoot": "app/src", "prefix": "app", @@ -49,9 +51,7 @@ "outputPath": "dist/app", "index": "app/src/index.html", "main": "app/src/main.ts", - "polyfills": [ - "zone.js" - ], + "polyfills": "app/src/polyfills.ts", "tsConfig": "app/tsconfig.app.json", "styles": [ "app/src/styles.css" @@ -72,6 +72,12 @@ "maximumError": "4kb" } ], + "fileReplacements": [ + { + "replace": "app/src/environments/environment.ts", + "with": "app/src/environments/environment.prod.ts" + } + ], "outputHashing": "all" }, "development": { @@ -106,11 +112,10 @@ "test": { "builder": "@angular-devkit/build-angular:karma", "options": { - "polyfills": [ - "zone.js", - "zone.js/testing" - ], + "main": "app/src/test.ts", + "polyfills": "app/src/polyfills.ts", "tsConfig": "app/tsconfig.spec.json", + "karmaConfig": "app/karma.conf.js", "styles": [ "app/src/styles.css" ], @@ -119,5 +124,6 @@ } } } - } + }, + "defaultProject": "lib" } diff --git a/app/.browserslistrc b/app/.browserslistrc new file mode 100644 index 0000000..4f9ac26 --- /dev/null +++ b/app/.browserslistrc @@ -0,0 +1,16 @@ +# This file is used by the build system to adjust CSS and JS output to support the specified browsers below. +# For additional information regarding the format and rule options, please see: +# https://github.com/browserslist/browserslist#queries + +# For the full list of supported browsers by the Angular framework, please see: +# https://angular.io/guide/browser-support + +# You can see what browsers were selected by your queries by running: +# npx browserslist + +last 1 Chrome version +last 1 Firefox version +last 2 Edge major versions +last 2 Safari major versions +last 2 iOS major versions +Firefox ESR diff --git a/app/karma.conf.js b/app/karma.conf.js new file mode 100644 index 0000000..8507930 --- /dev/null +++ b/app/karma.conf.js @@ -0,0 +1,44 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + jasmine: { + // you can add configuration options for Jasmine here + // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html + // for example, you can disable the random execution with `random: false` + // or set a specific seed with `seed: 4321` + }, + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + jasmineHtmlReporter: { + suppressAll: true // removes the duplicated traces + }, + coverageReporter: { + dir: require('path').join(__dirname, '../coverage/app'), + subdir: '.', + reporters: [ + { type: 'html' }, + { type: 'text-summary' } + ] + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/app/src/environments/environment.prod.ts b/app/src/environments/environment.prod.ts new file mode 100644 index 0000000..3612073 --- /dev/null +++ b/app/src/environments/environment.prod.ts @@ -0,0 +1,3 @@ +export const environment = { + production: true +}; diff --git a/app/src/environments/environment.ts b/app/src/environments/environment.ts new file mode 100644 index 0000000..f56ff47 --- /dev/null +++ b/app/src/environments/environment.ts @@ -0,0 +1,16 @@ +// This file can be replaced during build by using the `fileReplacements` array. +// `ng build` replaces `environment.ts` with `environment.prod.ts`. +// The list of file replacements can be found in `angular.json`. + +export const environment = { + production: false +}; + +/* + * For easier debugging in development mode, you can import the following file + * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. + * + * This import should be commented out in production mode because it will have a negative impact + * on performance if an error is thrown. + */ +// import 'zone.js/plugins/zone-error'; // Included with Angular CLI. diff --git a/app/src/main.ts b/app/src/main.ts index dbf3201..c7291d1 100644 --- a/app/src/main.ts +++ b/app/src/main.ts @@ -1,5 +1,12 @@ +import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + import { AppModule } from './app.module'; +import { environment } from './environments/environment'; + +if (environment.production) { + enableProdMode(); +} platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.error(err)); diff --git a/app/src/polyfills.ts b/app/src/polyfills.ts new file mode 100644 index 0000000..429bb9e --- /dev/null +++ b/app/src/polyfills.ts @@ -0,0 +1,53 @@ +/** + * This file includes polyfills needed by Angular and is loaded before the app. + * You can add your own extra polyfills to this file. + * + * This file is divided into 2 sections: + * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. + * 2. Application imports. Files imported after ZoneJS that should be loaded before your main + * file. + * + * The current setup is for so-called "evergreen" browsers; the last versions of browsers that + * automatically update themselves. This includes recent versions of Safari, Chrome (including + * Opera), Edge on the desktop, and iOS and Chrome on mobile. + * + * Learn more in https://angular.io/guide/browser-support + */ + +/*************************************************************************************************** + * BROWSER POLYFILLS + */ + +/** + * By default, zone.js will patch all possible macroTask and DomEvents + * user can disable parts of macroTask/DomEvents patch by setting following flags + * because those flags need to be set before `zone.js` being loaded, and webpack + * will put import in the top of bundle, so user need to create a separate file + * in this directory (for example: zone-flags.ts), and put the following flags + * into that file, and then add the following code before importing zone.js. + * import './zone-flags'; + * + * The flags allowed in zone-flags.ts are listed here. + * + * The following flags will work for all browsers. + * + * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame + * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick + * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames + * + * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js + * with the following flag, it will bypass `zone.js` patch for IE/Edge + * + * (window as any).__Zone_enable_cross_context_check = true; + * + */ + +/*************************************************************************************************** + * Zone JS is required by default for Angular itself. + */ +import 'zone.js'; // Included with Angular CLI. + + +/*************************************************************************************************** + * APPLICATION IMPORTS + */ diff --git a/app/src/test.ts b/app/src/test.ts new file mode 100644 index 0000000..00025da --- /dev/null +++ b/app/src/test.ts @@ -0,0 +1,26 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/testing'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +declare const require: { + context(path: string, deep?: boolean, filter?: RegExp): { + (id: string): T; + keys(): string[]; + }; +}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting(), +); + +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); diff --git a/app/tsconfig.app.json b/app/tsconfig.app.json index bdda72e..963b2b6 100644 --- a/app/tsconfig.app.json +++ b/app/tsconfig.app.json @@ -6,7 +6,8 @@ "types": [] }, "files": [ - "src/main.ts" + "src/main.ts", + "src/polyfills.ts" ], "include": [ "src/**/*.d.ts" diff --git a/app/tsconfig.spec.json b/app/tsconfig.spec.json index c030e37..3670807 100644 --- a/app/tsconfig.spec.json +++ b/app/tsconfig.spec.json @@ -7,6 +7,10 @@ "jasmine" ] }, + "files": [ + "src/test.ts", + "src/polyfills.ts" + ], "include": [ "src/**/*.spec.ts", "src/**/*.d.ts" diff --git a/lib/.browserslistrc b/lib/.browserslistrc new file mode 100644 index 0000000..4f9ac26 --- /dev/null +++ b/lib/.browserslistrc @@ -0,0 +1,16 @@ +# This file is used by the build system to adjust CSS and JS output to support the specified browsers below. +# For additional information regarding the format and rule options, please see: +# https://github.com/browserslist/browserslist#queries + +# For the full list of supported browsers by the Angular framework, please see: +# https://angular.io/guide/browser-support + +# You can see what browsers were selected by your queries by running: +# npx browserslist + +last 1 Chrome version +last 1 Firefox version +last 2 Edge major versions +last 2 Safari major versions +last 2 iOS major versions +Firefox ESR diff --git a/lib/karma.conf.js b/lib/karma.conf.js new file mode 100644 index 0000000..bd94b14 --- /dev/null +++ b/lib/karma.conf.js @@ -0,0 +1,44 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + jasmine: { + // you can add configuration options for Jasmine here + // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html + // for example, you can disable the random execution with `random: false` + // or set a specific seed with `seed: 4321` + }, + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + jasmineHtmlReporter: { + suppressAll: true // removes the duplicated traces + }, + coverageReporter: { + dir: require('path').join(__dirname, '../coverage/lib'), + subdir: '.', + reporters: [ + { type: 'html' }, + { type: 'text-summary' } + ] + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/lib/ng-package.json b/lib/ng-package.json index 77d929a..840284a 100644 --- a/lib/ng-package.json +++ b/lib/ng-package.json @@ -3,8 +3,5 @@ "dest": "../dist/lib", "lib": { "entryFile": "src/public-api.ts" - }, - "allowedNonPeerDependencies": [ - "fast-deep-equal" - ] -} + } +} \ No newline at end of file diff --git a/lib/package.json b/lib/package.json index 42576b3..1867045 100644 --- a/lib/package.json +++ b/lib/package.json @@ -18,8 +18,8 @@ "tslib": "^2.3.0" }, "peerDependencies": { - "@angular/common": "9 - 15", - "@angular/core": "9 - 15", + "@angular/common": "12 - 15", + "@angular/core": "12 - 15", "@fullcalendar/core": "6.0.0-beta.2" } } diff --git a/lib/src/test.ts b/lib/src/test.ts new file mode 100644 index 0000000..bcca659 --- /dev/null +++ b/lib/src/test.ts @@ -0,0 +1,27 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js'; +import 'zone.js/testing'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +declare const require: { + context(path: string, deep?: boolean, filter?: RegExp): { + (id: string): T; + keys(): string[]; + }; +}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting(), +); + +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); diff --git a/lib/tsconfig.lib.json b/lib/tsconfig.lib.json index 7916d4e..ad897a8 100644 --- a/lib/tsconfig.lib.json +++ b/lib/tsconfig.lib.json @@ -9,6 +9,7 @@ "types": [] }, "exclude": [ + "src/test.ts", "**/*.spec.ts" ] } diff --git a/lib/tsconfig.spec.json b/lib/tsconfig.spec.json index 30919c2..69bd43a 100644 --- a/lib/tsconfig.spec.json +++ b/lib/tsconfig.spec.json @@ -7,6 +7,9 @@ "jasmine" ] }, + "files": [ + "src/test.ts" + ], "include": [ "**/*.spec.ts", "**/*.d.ts" diff --git a/package.json b/package.json index 4b9dee4..f46ce3b 100644 --- a/package.json +++ b/package.json @@ -17,37 +17,38 @@ }, "private": true, "dependencies": { - "@angular/animations": "^15.0.0", - "@angular/common": "^15.0.0", - "@angular/compiler": "^15.0.0", - "@angular/core": "^15.0.0", - "@angular/forms": "^15.0.0", - "@angular/platform-browser": "^15.0.0", - "@angular/platform-browser-dynamic": "^15.0.0", - "@angular/router": "^15.0.0", + "@angular/animations": "~13.3.0", + "@angular/common": "~13.3.0", + "@angular/compiler": "~13.3.0", + "@angular/core": "~13.3.0", + "@angular/forms": "~13.3.0", + "@angular/platform-browser": "~13.3.0", + "@angular/platform-browser-dynamic": "~13.3.0", + "@angular/router": "~13.3.0", "@fullcalendar/core": "6.0.0-beta.2", "@fullcalendar/daygrid": "6.0.0-beta.2", "@fullcalendar/interaction": "6.0.0-beta.2", "rxjs": "~7.5.0", "tslib": "^2.3.0", - "zone.js": "~0.12.0" + "zone.js": "~0.11.4" }, "dependenciesNote": [ "Keep lib/package.json synced!" ], "devDependencies": { - "@angular-devkit/build-angular": "^15.0.0", - "@angular/cli": "~15.0.0", - "@angular/compiler-cli": "^15.0.0", - "@types/jasmine": "~4.3.0", - "jasmine-core": "~4.5.0", - "karma": "~6.4.0", + "@angular-devkit/build-angular": "~13.3.10", + "@angular/cli": "~13.3.10", + "@angular/compiler-cli": "~13.3.0", + "@types/jasmine": "~3.10.0", + "@types/node": "^12.11.1", + "jasmine-core": "~4.0.0", + "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", - "karma-coverage": "~2.2.0", - "karma-jasmine": "~5.1.0", - "karma-jasmine-html-reporter": "~2.0.0", - "ng-packagr": "^15.0.0", - "typescript": "~4.8.2" + "karma-coverage": "~2.1.0", + "karma-jasmine": "~4.0.0", + "karma-jasmine-html-reporter": "~1.7.0", + "ng-packagr": "^13.0.0", + "typescript": "~4.6.4" }, "publishConfig": { "directory": "./dist/lib", diff --git a/tsconfig.json b/tsconfig.json index adc367e..d3b88ae 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,6 @@ { "compileOnSave": false, "compilerOptions": { - "allowSyntheticDefaultImports": true, "baseUrl": "./", "outDir": "./dist/out-tsc", "forceConsistentCasingInFileNames": true, @@ -22,11 +21,10 @@ "experimentalDecorators": true, "moduleResolution": "node", "importHelpers": true, - "target": "ES2022", - "module": "ES2022", - "useDefineForClassFields": false, + "target": "es2017", + "module": "es2020", "lib": [ - "ES2022", + "es2020", "dom" ] },