Changing front

This commit is contained in:
2023-01-16 17:44:37 +01:00
parent 0b8a93b256
commit 4fe4be7730
48586 changed files with 4725790 additions and 17464 deletions

View File

@@ -0,0 +1,29 @@
{
"schematics": {
"remove-browserslist-config": {
"version": "15.0.0",
"factory": "./update-15/remove-browserslist-config",
"description": "Remove Browserslist configuration files that matches the Angular CLI default configuration."
},
"remove-platform-server-exports": {
"version": "15.0.0",
"factory": "./update-15/remove-platform-server-exports",
"description": "Remove exported `@angular/platform-server` `renderModule` method. The `renderModule` method is now exported by the Angular CLI."
},
"update-typescript-target": {
"version": "15.0.0",
"factory": "./update-15/update-typescript-target",
"description": "Update TypeScript compiler `target` and set `useDefineForClassFields`. These changes are for IDE purposes as TypeScript compiler options `target` and `useDefineForClassFields` are set to `ES2022` and `false` respectively by the Angular CLI. To control ECMA version and features use the Browerslist configuration."
},
"update-workspace-config": {
"version": "15.0.0",
"factory": "./update-15/update-workspace-config",
"description": "Remove options from 'angular.json' that are no longer supported by the official builders."
},
"update-karma-main-file": {
"version": "15.0.0",
"factory": "./update-15/update-karma-main-file",
"description": "Remove no longer needed require calls in Karma builder main file."
}
}
}

View File

@@ -0,0 +1,10 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Rule } from '@angular-devkit/schematics';
export declare const DEFAULT_BROWSERS: string[];
export default function (): Rule;

View File

@@ -0,0 +1,94 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_BROWSERS = void 0;
const core_1 = require("@angular-devkit/core");
const validBrowserslistConfigFilenames = new Set(['browserslist', '.browserslistrc']);
exports.DEFAULT_BROWSERS = [
'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',
];
function* visit(directory) {
for (const path of directory.subfiles) {
if (validBrowserslistConfigFilenames.has(path)) {
yield (0, core_1.join)(directory.path, path);
}
}
for (const path of directory.subdirs) {
if (path === 'node_modules') {
continue;
}
yield* visit(directory.dir(path));
}
}
function default_1() {
return async (tree, { logger }) => {
let browserslist;
try {
browserslist = (await Promise.resolve().then(() => __importStar(require('browserslist')))).default;
}
catch {
logger.warn('Skipping migration because the "browserslist" package could not be loaded.');
return;
}
// Set the defaults to match the defaults in build-angular.
browserslist.defaults = exports.DEFAULT_BROWSERS;
const defaultSupportedBrowsers = new Set(browserslist(exports.DEFAULT_BROWSERS));
const es5Browsers = new Set(browserslist(['supports es6-module']));
for (const path of visit(tree.root)) {
const { defaults: browsersListConfig, ...otherConfigs } = browserslist.parseConfig(tree.readText(path));
if (Object.keys(otherConfigs).length) {
// The config contains additional sections.
continue;
}
const browserslistInProject = browserslist(
// Exclude from the list ES5 browsers which are not supported.
browsersListConfig.map((s) => `${s} and supports es6-module`), {
ignoreUnknownVersions: true,
});
if (defaultSupportedBrowsers.size !== browserslistInProject.length) {
continue;
}
const shouldDelete = browserslistInProject.every((browser) => defaultSupportedBrowsers.has(browser));
if (shouldDelete) {
// All browsers are the same as the default config.
// Delete file as it's redundant.
tree.delete(path);
}
}
};
}
exports.default = default_1;

View File

@@ -0,0 +1,9 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Rule } from '@angular-devkit/schematics';
export default function (): Rule;

View File

@@ -0,0 +1,102 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const ts = __importStar(require("../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
function* visit(directory) {
for (const path of directory.subfiles) {
if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {
const entry = directory.file(path);
if (entry) {
const content = entry.content;
if (content.includes('@angular/platform-server') && content.includes('renderModule')) {
const source = ts.createSourceFile(entry.path, content.toString().replace(/^\uFEFF/, ''), ts.ScriptTarget.Latest, true);
yield source;
}
}
}
}
for (const path of directory.subdirs) {
if (path === 'node_modules' || path.startsWith('.')) {
continue;
}
yield* visit(directory.dir(path));
}
}
function default_1() {
return (tree) => {
for (const sourceFile of visit(tree.root)) {
let recorder;
let printer;
ts.forEachChild(sourceFile, function analyze(node) {
if (!(ts.isExportDeclaration(node) &&
node.moduleSpecifier &&
ts.isStringLiteral(node.moduleSpecifier) &&
node.moduleSpecifier.text === '@angular/platform-server' &&
node.exportClause &&
ts.isNamedExports(node.exportClause))) {
// Not a @angular/platform-server named export.
return;
}
const exportClause = node.exportClause;
const newElements = [];
for (const element of exportClause.elements) {
if (element.name.text !== 'renderModule') {
newElements.push(element);
}
}
if (newElements.length === exportClause.elements.length) {
// No changes
return;
}
recorder !== null && recorder !== void 0 ? recorder : (recorder = tree.beginUpdate(sourceFile.fileName));
if (newElements.length) {
// Update named exports as there are leftovers.
const newExportClause = ts.factory.updateNamedExports(exportClause, newElements);
printer !== null && printer !== void 0 ? printer : (printer = ts.createPrinter());
const fix = printer.printNode(ts.EmitHint.Unspecified, newExportClause, sourceFile);
const index = exportClause.getStart();
const length = exportClause.getWidth();
recorder.remove(index, length).insertLeft(index, fix);
}
else {
// Delete export as no exports remain.
recorder.remove(node.getStart(), node.getWidth());
}
ts.forEachChild(node, analyze);
});
if (recorder) {
tree.commitUpdate(recorder);
}
}
};
}
exports.default = default_1;

View File

@@ -0,0 +1,9 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Rule } from '@angular-devkit/schematics';
export default function (): Rule;

View File

@@ -0,0 +1,106 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const ts = __importStar(require("../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
const utility_1 = require("../../utility");
const workspace_1 = require("../../utility/workspace");
const workspace_models_1 = require("../../utility/workspace-models");
function default_1() {
return async (host) => {
for (const file of await findTestMainFiles(host)) {
updateTestFile(host, file);
}
};
}
exports.default = default_1;
async function findTestMainFiles(host) {
const testFiles = new Set();
const workspace = await (0, utility_1.readWorkspace)(host);
// find all test.ts files.
for (const project of workspace.projects.values()) {
for (const target of project.targets.values()) {
if (target.builder !== workspace_models_1.Builders.Karma) {
continue;
}
for (const [, options] of (0, workspace_1.allTargetOptions)(target)) {
if (typeof options.main === 'string') {
testFiles.add(options.main);
}
}
}
}
return testFiles;
}
function updateTestFile(host, file) {
const content = host.readText(file);
if (!content.includes('require.context')) {
return;
}
const sourceFile = ts.createSourceFile(file, content.replace(/^\uFEFF/, ''), ts.ScriptTarget.Latest, true);
const usedVariableNames = new Set();
const recorder = host.beginUpdate(sourceFile.fileName);
ts.forEachChild(sourceFile, (node) => {
var _a, _b;
if (ts.isVariableStatement(node)) {
const variableDeclaration = node.declarationList.declarations[0];
if ((_a = ts.getModifiers(node)) === null || _a === void 0 ? void 0 : _a.some((m) => m.kind === ts.SyntaxKind.DeclareKeyword)) {
// `declare const require`
if (variableDeclaration.name.getText() !== 'require') {
return;
}
}
else {
// `const context = require.context('./', true, /\.spec\.ts$/);`
if (!((_b = variableDeclaration.initializer) === null || _b === void 0 ? void 0 : _b.getText().startsWith('require.context'))) {
return;
}
// add variable name as used.
usedVariableNames.add(variableDeclaration.name.getText());
}
// Delete node.
recorder.remove(node.getFullStart(), node.getFullWidth());
}
if (usedVariableNames.size &&
ts.isExpressionStatement(node) && // context.keys().map(context);
ts.isCallExpression(node.expression) && // context.keys().map(context);
ts.isPropertyAccessExpression(node.expression.expression) && // context.keys().map
ts.isCallExpression(node.expression.expression.expression) && // context.keys()
ts.isPropertyAccessExpression(node.expression.expression.expression.expression) && // context.keys
ts.isIdentifier(node.expression.expression.expression.expression.expression) && // context
usedVariableNames.has(node.expression.expression.expression.expression.expression.getText())) {
// `context.keys().map(context);`
// `context.keys().forEach(context);`
recorder.remove(node.getFullStart(), node.getFullWidth());
}
});
host.commitUpdate(recorder);
}

View File

@@ -0,0 +1,9 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Rule } from '@angular-devkit/schematics';
export default function (): Rule;

View File

@@ -0,0 +1,75 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
const json_file_1 = require("../../utility/json-file");
const workspace_1 = require("../../utility/workspace");
const workspace_models_1 = require("../../utility/workspace-models");
function default_1() {
return async (host, context) => {
// Workspace level tsconfig
updateTarget(host, 'tsconfig.json');
const workspace = await (0, workspace_1.getWorkspace)(host);
// Find all tsconfig which are refereces used by builders
for (const [, project] of workspace.projects) {
for (const [targetName, target] of project.targets) {
// Update all other known CLI builders that use a tsconfig
const tsConfigs = [target.options || {}, ...Object.values(target.configurations || {})]
.filter((opt) => typeof (opt === null || opt === void 0 ? void 0 : opt.tsConfig) === 'string')
.map((opt) => opt.tsConfig);
const uniqueTsConfigs = new Set(tsConfigs);
for (const tsConfig of uniqueTsConfigs) {
if (host.exists(tsConfig)) {
continue;
}
uniqueTsConfigs.delete(tsConfig);
context.logger.warn(`'${tsConfig}' referenced in the '${targetName}' target does not exist.`);
}
if (!uniqueTsConfigs.size) {
continue;
}
switch (target.builder) {
case workspace_models_1.Builders.Server:
case workspace_models_1.Builders.Karma:
case workspace_models_1.Builders.Browser:
case workspace_models_1.Builders.NgPackagr:
for (const tsConfig of uniqueTsConfigs) {
removeOrUpdateTarget(host, tsConfig);
}
break;
}
}
}
};
}
exports.default = default_1;
function removeOrUpdateTarget(host, tsConfigPath) {
const json = new json_file_1.JSONFile(host, tsConfigPath);
if (typeof json.get(['extends']) === 'string') {
json.remove(['compilerOptions', 'target']);
}
else {
updateTarget(host, tsConfigPath);
}
}
const ESNEXT_ES2022_REGEXP = /^es(?:next|2022)$/i;
function updateTarget(host, tsConfigPath) {
const json = new json_file_1.JSONFile(host, tsConfigPath);
const jsonPath = ['compilerOptions'];
const compilerOptions = json.get(jsonPath);
if (compilerOptions && typeof compilerOptions === 'object') {
const { target } = compilerOptions;
if (typeof target === 'string' && !ESNEXT_ES2022_REGEXP.test(target)) {
json.modify(jsonPath, {
...compilerOptions,
'target': 'ES2022',
'useDefineForClassFields': false,
});
}
}
}

View File

@@ -0,0 +1,9 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Rule } from '@angular-devkit/schematics';
export default function (): Rule;

View File

@@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
const workspace_1 = require("../../utility/workspace");
const workspace_models_1 = require("../../utility/workspace-models");
function default_1() {
return (0, workspace_1.updateWorkspace)((workspace) => {
var _a;
for (const project of workspace.projects.values()) {
for (const target of project.targets.values()) {
if (target.builder !== workspace_models_1.Builders.Server) {
continue;
}
for (const [name, options] of (0, workspace_1.allTargetOptions)(target)) {
delete options.bundleDependencies;
if (name === 'development') {
(_a = options.vendorChunk) !== null && _a !== void 0 ? _a : (options.vendorChunk = true);
}
}
}
}
});
}
exports.default = default_1;