diff --git a/package.json b/package.json index b9f789492..4a547e10c 100644 --- a/package.json +++ b/package.json @@ -170,7 +170,7 @@ "eslint": "^7.26.0", "eslint-config-prettier": "~8.3.0", "eslint-plugin-import": "~2.23.4", - "eslint-plugin-jsdoc": "~35.1.3", + "eslint-plugin-jsdoc": "~36.0.2", "eslint-plugin-prefer-arrow": "~1.2.2", "eslint-plugin-prettier": "~3.4.0", "lint-staged": "^10.5.3" diff --git a/schematics/collection.json b/schematics/collection.json index 719300c22..67d020323 100644 --- a/schematics/collection.json +++ b/schematics/collection.json @@ -12,6 +12,7 @@ }, "ng-update": { "factory": "./ng-update/index#updateToV12", + "schema": "./ng-update/upgrade-rules/v12/schema.json", "description": "Create an Alain workspace." }, "application": { diff --git a/schematics/ng-update/index.ts b/schematics/ng-update/index.ts index ae930ba63..8e9f52dc0 100644 --- a/schematics/ng-update/index.ts +++ b/schematics/ng-update/index.ts @@ -18,8 +18,9 @@ export function updateToV117(): Rule { return chain([v117Rule]); } -export function updateToV12(): Rule { - return chain([v12Rule, createMigrationSchematicRule(TargetVersion.V12, migrations, ruleUpgradeData, postUpdate)]); +export function updateToV12(schema: any): Rule { + const rule = v12Rule(schema); + return chain([rule, createMigrationSchematicRule(TargetVersion.V12, migrations, ruleUpgradeData, postUpdate)]); } /** Post-update schematic to be called when update is finished. */ diff --git a/schematics/ng-update/upgrade-rules/v12/index.spec.ts b/schematics/ng-update/upgrade-rules/v12/index.spec.ts index 1c44b9785..7a915de7e 100644 --- a/schematics/ng-update/upgrade-rules/v12/index.spec.ts +++ b/schematics/ng-update/upgrade-rules/v12/index.spec.ts @@ -146,4 +146,210 @@ describe('Schematic: ng-update: v12Rule', () => { const content = tree.readContent(filePath); expect(content).toContain(`@angular-eslint/builder:lint`); }); + + it(`#2027: 'set' on proxy: trap returned falsish for property 'defaultConfiguration'`, async () => { + const filePath = `/angular.json`; + tree.overwrite( + filePath, + `{ + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "version": 1, + "newProjectRoot": "projects", + "projects": { + "app-ui": { + "projectType": "application", + "schematics": { + "@schematics/angular:component": { + "style": "less" + } + }, + "root": "", + "sourceRoot": "src", + "prefix": "app", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:browser", + "options": { + "outputPath": "dist/app-ui", + "index": "src/index.html", + "main": "src/main.ts", + "polyfills": "src/polyfills.ts", + "tsConfig": "tsconfig.app.json", + "assets": [ + "src/favicon.ico", + "src/assets", + { + "glob": "**/*", + "input": "./node_modules/leaflet/dist/images", + "output": "assets/" + }, + "src/manifest.webmanifest", + { + "glob": "**/*", + "input": "./node_modules/monaco-editor/min/vs", + "output": "/assets/vs/" + } + ], + "styles": ["./src/styles.less", "./node_modules/leaflet/dist/leaflet.css"], + "scripts": ["node_modules/jszip/dist/jszip.min.js", + "node_modules/xlsx/dist/xlsx.mini.min.js" + ], + "allowedCommonJsDependencies": [ + "@angular/common/locales/zh", + "@ant-design/colors", + "@stomp/rx-stomp", + "babylonjs-gui", + "babylonjs-loaders", + "css-element-queries", + "fabric", + "file-saver", + "humanize-duration", + "sockjs-client", + "util", + "zrender/lib/svg/svg", + "zrender/lib/vml/vml", + "ajv", + "date-fns", + "ajv-formats", + "echarts/dist/extension/bmap.min" + ], + "vendorChunk": true, + "extractLicenses": false, + "buildOptimizer": false, + "sourceMap": true, + "optimization": false, + "namedChunks": true + }, + "configurations": { + "production": { + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.prod.ts" + } + ], + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "namedChunks": false, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": true, + "budgets": [ + { + "type": "initial", + "maximumWarning": "2mb", + "maximumError": "12mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "6kb", + "maximumError": "2mb" + } + ], + "serviceWorker": true, + "ngswConfigPath": "ngsw-config.json" + } + }, + "defaultConfiguration": "" + }, + "serve": { + "builder": "@angular-devkit/build-angular:dev-server", + "options": { + "browserTarget": "app-ui:build", + "proxyConfig": "proxy.conf.json" + }, + "configurations": { + "production": { + "browserTarget": "app-ui:build:production" + } + } + }, + "extract-i18n": { + "builder": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "app-ui:build" + } + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "src/test.ts", + "polyfills": "src/polyfills.ts", + "tsConfig": "tsconfig.spec.json", + "karmaConfig": "karma.conf.js", + "assets": ["src/favicon.ico", "src/assets", "src/manifest.webmanifest"], + "styles": ["src/styles.less"], + "scripts": [] + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": ["tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json"], + "exclude": ["**/node_modules/**"] + } + }, + "e2e": { + "builder": "@angular-devkit/build-angular:protractor", + "options": { + "protractorConfig": "e2e/protractor.conf.js", + "devServerTarget": "app-ui:serve" + }, + "configurations": { + "production": { + "devServerTarget": "app-ui:serve:production" + } + } + } + } + } + }, + "defaultProject": "app-ui", + "cli": { + "analytics": false + }, + "schematics": { + "ng-alain:module": { + "routing": true, + "spec": false + }, + "ng-alain:list": { + "spec": false + }, + "ng-alain:edit": { + "spec": false, + "modal": true + }, + "ng-alain:view": { + "spec": false, + "modal": true + }, + "ng-alain:curd": { + "spec": false + }, + "@schematics/angular:module": { + "routing": true, + "spec": false + }, + "@schematics/angular:component": { + "spec": false, + "flat": false, + "inlineStyle": true, + "inlineTemplate": false + }, + "@schematics/angular:directive": { + "spec": false + }, + "@schematics/angular:service": { + "spec": false + } + } + } + ` + ); + await runMigration(); + const content = tree.readContent(filePath); + expect(content).toContain(`@angular-eslint/builder:lint`); + }); }); diff --git a/schematics/ng-update/upgrade-rules/v12/index.ts b/schematics/ng-update/upgrade-rules/v12/index.ts index 2b5f01c8f..3a8817575 100644 --- a/schematics/ng-update/upgrade-rules/v12/index.ts +++ b/schematics/ng-update/upgrade-rules/v12/index.ts @@ -23,6 +23,7 @@ import { } from '../../../utils'; import { LINT_STAGED, LINT_STAGED_CONFIG } from '../../../utils/code-style'; import { addESLintRule, UpgradeMainVersions } from '../../../utils/versions'; +import { Schema } from './schema'; // 修正 angular.json 的格式 function fixAngularJson(context: SchematicContext): Rule { @@ -170,12 +171,11 @@ function finished(): Rule { }; } -export function v12Rule(): Rule { +export function v12Rule(options: Schema): Rule { return async (tree: Tree, context: SchematicContext) => { - logStart(context, `Upgrade @delon/* version number`); + logStart(context, `Upgrade @delon/* version number ${JSON.stringify(options)}`); UpgradeMainVersions(tree); - return chain([ - fixAngularJson(context), + const rules = [ migrateESLint(tree, context), addESLintRule(context), upgradeThirdVersion(), @@ -183,6 +183,10 @@ export function v12Rule(): Rule { upgradeHusky(), formatJson(), finished() - ]); + ]; + if (options.fixAngularJson !== false) { + rules.splice(0, 0, fixAngularJson(context)); + } + return chain(rules); }; } diff --git a/schematics/ng-update/upgrade-rules/v12/schema.json b/schematics/ng-update/upgrade-rules/v12/schema.json new file mode 100644 index 000000000..d1daacf9c --- /dev/null +++ b/schematics/ng-update/upgrade-rules/v12/schema.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/schema", + "$id": "SchematicsNgUpdateV12", + "title": "Ng Alain Update V12", + "type": "object", + "properties": { + "fixAngularJson": { + "type": "boolean", + "default": true, + "description": "Automatically correct the Angular.json format, Default: true" + } + } +} diff --git a/schematics/ng-update/upgrade-rules/v12/schema.ts b/schematics/ng-update/upgrade-rules/v12/schema.ts new file mode 100644 index 000000000..0425ffe52 --- /dev/null +++ b/schematics/ng-update/upgrade-rules/v12/schema.ts @@ -0,0 +1,4 @@ +export interface Schema { + /** Automatically correct the Angular.json format, Default: true */ + fixAngularJson: Boolean; +}