build: migrate from gulp to ng-dev for running formatting (#36726)

Migrates away from gulp to ng-dev for running our formatter.
Additionally, provides a deprecation warning for any attempted
usage of the previous `gulp format:*` tasks.

PR Close #36726
This commit is contained in:
Joey Perrott
2020-04-24 12:32:18 -07:00
committed by Andrew Kushnir
parent 7b5a0ba8c3
commit 2365bb89d7
7 changed files with 48 additions and 474 deletions
+2 -1
View File
@@ -278,7 +278,8 @@ jobs:
- run: 'yarn bazel:lint ||
(echo -e "\n.bzl files have lint errors. Please run ''yarn bazel:lint-fix''"; exit 1)'
- run: yarn -s lint --branch $CI_GIT_BASE_REVISION
- run: yarn -s tslint
- run: yarn -s ng-dev format changed $CI_GIT_BASE_REVISION --check
- run: yarn -s ts-circular-deps:check
- run: yarn -s ng-dev pullapprove verify
- run: yarn -s ng-dev commit-message validate-range --range $CI_COMMIT_RANGE
-1
View File
@@ -54,7 +54,6 @@
"!packages/common/src/i18n/currencies.ts",
"!packages/common/src/i18n/locale_en.ts",
"modules/benchmarks/**/*.{js,ts}",
"modules/e2e_util/**/*.{js,ts}",
"modules/playground/**/*.{js,ts}",
"tools/**/*.{js,ts}",
"!tools/gulp-tasks/cldr/extract.js",
+26 -23
View File
@@ -26,33 +26,36 @@ function loadTask(fileName, taskName) {
return task(gulp);
}
//#######################################################
// A format and enforce task for different sets of files.
//#######################################################
// All source files.
gulp.task('format:all', loadTask('format', 'format'));
gulp.task('format:all:enforce', loadTask('format', 'enforce'));
// Untracked source code files.
gulp.task('format:untracked', loadTask('format', 'format-untracked'));
gulp.task('format:untracked:enforce', loadTask('format', 'enforce-untracked'));
// Changed, tracked source code files.
gulp.task('format:diff', loadTask('format', 'format-diff'));
gulp.task('format:diff:enforce', loadTask('format', 'enforce-diff'));
// Changed, both tracked and untracked, source code files.
gulp.task('format:changed', ['format:untracked', 'format:diff']);
gulp.task('format:changed:enforce', ['format:untracked:enforce', 'format:diff:enforce']);
// Alias for `format:changed` that formerly formatted all files.
gulp.task('format', ['format:changed']);
gulp.task('lint', ['format:changed:enforce']);
gulp.task('source-map-test', loadTask('source-map-test'));
gulp.task('changelog', loadTask('changelog'));
gulp.task('changelog:zonejs', loadTask('changelog-zonejs'));
gulp.task('check-env', () => {/* this is a noop because the env test ran already above */});
gulp.task('cldr:extract', loadTask('cldr', 'extract'));
gulp.task('cldr:gen-closure-locale', loadTask('cldr', 'closure'));
// TODO(josephperrott): Remove old task entries and deprecation notice after deprecation period.
/** Notify regarding `gulp format:*` deprecation. */
function gulpFormatDeprecationNotice() {
console.info(`######################################################################`)
console.info(`gulp format is deprecated in favor of running the formatter via ng-dev`);
console.info();
console.info(`You can find more usage information by running:`);
console.info(` yarn ng-dev format --help`);
console.info();
console.info(`For more on the rationale and effects of this deprecation visit:`);
console.info(` https://github.com/angular/angular/pull/36726#issue-406278018`);
console.info(`######################################################################`)
process.exit(1);
}
gulp.task('format:all', gulpFormatDeprecationNotice);
gulp.task('format:all:enforce', gulpFormatDeprecationNotice);
gulp.task('format:untracked', gulpFormatDeprecationNotice);
gulp.task('format:untracked:enforce', gulpFormatDeprecationNotice);
gulp.task('format:diff', gulpFormatDeprecationNotice);
gulp.task('format:diff:enforce', gulpFormatDeprecationNotice);
gulp.task('format:changed', gulpFormatDeprecationNotice);
gulp.task('format:changed:enforce', gulpFormatDeprecationNotice);
gulp.task('format', gulpFormatDeprecationNotice);
gulp.task('lint', gulpFormatDeprecationNotice);
+1 -5
View File
@@ -29,7 +29,7 @@
"//circleci-win-comment": "See the test-win circleci job for why these are needed. If they are not needed anymore, remove them.",
"circleci-win-ve": "bazelisk test --build_tag_filters=-ivy-only --test_tag_filters=-ivy-only,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/...",
"circleci-win-ivy": "bazelisk test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/...",
"lint": "yarn -s tslint && yarn gulp lint",
"lint": "yarn -s tslint && yarn -s ng-dev format changed --check",
"tslint": "tsc -p tools/tsconfig.json && tslint -c tslint.json \"+(packages|modules|scripts|tools)/**/*.+(js|ts)\"",
"public-api:check": "node goldens/public-api/manage.js test",
"public-api:update": "node goldens/public-api/manage.js accept",
@@ -167,11 +167,7 @@
"firefox-profile": "1.0.3",
"glob": "7.1.2",
"gulp": "3.9.1",
"gulp-clang-format": "^1.0.27",
"gulp-conventional-changelog": "^2.0.3",
"gulp-filter": "^5.1.0",
"gulp-git": "^2.7.0",
"gulp-tslint": "8.1.2",
"husky": "^4.2.3",
"inquirer": "^7.1.0",
"jpm": "1.3.1",
-29
View File
@@ -15,23 +15,6 @@ module.exports = (gulp) => (done) => {
};
```
E.g. The `format.js` file contains two tasks:
```js
module.exports = {
// Check source code for formatting errors (clang-format)
enforce: (gulp) => () => {
...
},
// Format the source code with clang-format (see .clang-format)
format: (gulp) => () => {
...
}
};
```
## Loading Tasks
The tasks are loaded in the gulp file, by requiring them. There is a helper called `loadTask(fileName, taskName)`
@@ -42,15 +25,3 @@ E.g. Loading the task that will run the build, from a task file that contains on
```js
gulp.task('build.sh', loadTask('build'));
```
E.g. Loading the task that will enforce formatting, from a task file that contains more than one task:
```js
gulp.task('format:enforce', loadTask('format', 'enforce'));
```
E.g. Loading a task that has dependencies:
```js
gulp.task('lint', ['format:enforce'], loadTask('lint'));
```
-162
View File
@@ -1,162 +0,0 @@
/**
* @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
*/
const {I18N_FOLDER, I18N_DATA_FOLDER} = require('./cldr/extract');
// clang-format entry points
const srcsToFmt = [
'dev-infra/**/*.{js,ts}',
'packages/**/*.{js,ts}',
'!packages/zone.js', // Ignore the `zone.js/` directory itself. (The contents are still matched.)
`!${I18N_DATA_FOLDER}/**/*.{js,ts}`,
`!${I18N_FOLDER}/available_locales.ts`,
`!${I18N_FOLDER}/currencies.ts`,
`!${I18N_FOLDER}/locale_en.ts`,
'modules/benchmarks/**/*.{js,ts}',
'modules/e2e_util/**/*.{js,ts}',
'modules/playground/**/*.{js,ts}',
'tools/**/*.{js,ts}',
'!tools/gulp-tasks/cldr/extract.js',
'!tools/public_api_guard/**/*.d.ts',
'!tools/ts-api-guardian/test/fixtures/**',
'./*.{js,ts}',
'!**/node_modules/**',
'!**/dist/**',
'!**/built/**',
'!shims_for_IE.js',
];
/**
* Gulp stream that wraps the gulp-git status,
* only returns untracked files, and converts
* the stdout into a stream of files.
*/
function gulpStatus() {
const Vinyl = require('vinyl');
const path = require('path');
const gulpGit = require('gulp-git');
const through = require('through2');
const srcStream = through.obj();
const opt = {cwd: process.cwd()};
// https://git-scm.com/docs/git-status#_short_format
const RE_STATUS = /((\s\w)|(\w+)|\?{0,2})\s([\w\+\-\/\\\.]+)(\s->\s)?([\w\+\-\/\\\.]+)*\n{0,1}/gm;
gulpGit.status({args: '--porcelain', quiet: true}, function(err, stdout) {
if (err) return srcStream.emit('error', err);
const data = stdout.toString();
let currentMatch;
while ((currentMatch = RE_STATUS.exec(data)) !== null) {
// status
const status = currentMatch[1].trim().toLowerCase();
// We only care about untracked files and renamed files
if (!new RegExp(/r|\?/i).test(status)) {
continue;
}
// file path
const currentFilePath = currentMatch[4];
// new file path in case its been moved
const newFilePath = currentMatch[6];
const filePath = newFilePath || currentFilePath;
srcStream.write(new Vinyl({
path: path.resolve(opt.cwd, filePath),
cwd: opt.cwd,
}));
RE_STATUS.lastIndex++;
}
srcStream.end();
});
return srcStream;
}
module.exports = {
// Check source code for formatting errors with clang-format
enforce: (gulp) => () => {
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
return gulp.src(srcsToFmt).pipe(
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
},
// Check only the untracked source code files for formatting errors with .clang-format
'enforce-untracked': (gulp) => () => {
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
const gulpFilter = require('gulp-filter');
return gulpStatus()
.pipe(gulpFilter(srcsToFmt))
.pipe(format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
},
// Check only the changed source code files diffed from the provided branch for formatting
// errors with clang-format
'enforce-diff': (gulp) => () => {
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
const gulpFilter = require('gulp-filter');
const minimist = require('minimist');
const gulpGit = require('gulp-git');
const args = minimist(process.argv.slice(2));
const branch = args.branch || 'master';
return gulpGit.diff(branch, {log: false})
.pipe(gulpFilter(srcsToFmt))
.pipe(format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
},
// Format the source code with clang-format (see .clang-format)
format: (gulp) => () => {
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
return gulp.src(srcsToFmt, {base: '.'})
.pipe(format.format('file', clangFormat))
.pipe(gulp.dest('.'));
},
// Format only the untracked source code files with clang-format (see .clang-format)
'format-untracked': (gulp) => () => {
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
const gulpFilter = require('gulp-filter');
return gulpStatus()
.pipe(gulpFilter(srcsToFmt))
.pipe(format.format('file', clangFormat))
.pipe(gulp.dest('.'));
},
// Format only the changed source code files diffed from the provided branch with clang-format
// (see .clang-format)
'format-diff': (gulp) => () => {
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
const gulpFilter = require('gulp-filter');
const minimist = require('minimist');
const gulpGit = require('gulp-git');
const args = minimist(process.argv.slice(2));
const branch = args.branch || 'master';
return gulpGit.diff(branch, {log: false})
.pipe(gulpFilter(srcsToFmt))
.pipe(format.format('file', clangFormat))
.pipe(gulp.dest('.'));
}
};
+19 -253
View File
File diff suppressed because it is too large Load Diff