angular-docs-cn/scripts/ci/update-deps-to-dist-packages.js
Paul Gschwendtner 5615928df9 build: no longer run tslint from within gulp task (#35800)
Switches our tslint setup to the standard `tslint.json` linter excludes.
The set of files that need to be linted is specified through a Yarn script.

For IDEs, open files are linted with the closest tslint configuration, if the
tslint IDE extension is set up, and the source file is not excluded.

We cannot use the language service plugin for tslint as we have multiple nested
tsconfig files, and we don't want to add the plugin to each tsconfig. We
could reduce that bloat by just extending from a top-level tsconfig that
defines the language service plugin, but unfortunately the tslint plugin does
not allow the use of tslint configs which are not part of the tsconfig project.

This is problematic since the tslint configuration is at the project root, and we
don't want to copy tslint configurations next to each tsconfig file.

Additionally, linting of `d.ts` files has been re-enabled. This has been
disabled in the past and a TODO has been left. This commit fixes the
lint issues and re-enables linting.

PR Close #35800
2020-03-03 09:20:49 -08:00

72 lines
2.6 KiB
JavaScript

/**
* @license
* Copyright Google Inc. 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
*/
/*
* This script updates a package.json file by replacing all dependencies and devDependencies
* such that all packages from the @angular scope point to the packages-dist directory.
*
* Please be aware that updating of versions might introduce compatibility issues. For instance,
* if a peer dependency of Angular, e.g. "typescript" changes, the package.json that is updated
* by this script will not have updated the "typescript" dependency to satisfy the peer dependency
* requirement. As a result, incompatibility errors might occur.
*/
'use strict';
const {yellow, green} = require('chalk');
const {existsSync, writeFileSync} = require('fs');
const {resolve} = require('path');
const [, , packageJsonPath, packagesDistRoot] = process.argv;
const packageJson = require(packageJsonPath);
const updated = [];
const skipped = [];
function updateDeps(dependencies) {
for (const packageName of Object.keys(dependencies)) {
// We're only interested to update packages in the @angular scope
if (!packageName.startsWith('@angular/')) {
continue;
}
// Within the packages-dist directory there's no scope name
const packageNameWithoutScope = packageName.replace('@angular/', '');
const packagePath = resolve(packagesDistRoot, packageNameWithoutScope);
// Check whether the package exists in packages-dist. Not all packages
// in the @angular scope are published from the main Angular repo.
if (existsSync(packagePath)) {
// Update the dependency to point to the packages-dist location.
dependencies[packageName] = `file:${packagePath}`;
updated.push(packageName);
} else {
skipped.push(packageName);
}
}
}
// Update dependencies from @angular scope to those in the packages-dist folder
updateDeps(packageJson.dependencies);
updateDeps(packageJson.devDependencies);
// Write the updated package.json contents
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
// Log all packages that were updated
if (updated.length > 0) {
console.info(green(`Updated ${packageJsonPath} to packages in ${packagesDistRoot}:`));
console.info(` ${updated.join('\n ')}\n`);
}
// Log the packages that were skipped, as they were not present in the packages-dist directory
if (skipped.length > 0) {
console.info(yellow(`Did not update packages that were not present in ${packagesDistRoot}:`));
console.info(` ${skipped.join('\n ')}\n`);
}