vscode/build/gulpfile.hygiene.js

52 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-11-25 02:09:31 +08:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
2020-09-22 20:37:04 +08:00
const gulp = require('gulp');
const es = require('event-stream');
const path = require('path');
const task = require('./lib/task');
2021-01-07 16:15:05 +08:00
const { hygiene } = require('./hygiene');
2016-02-18 23:02:16 +08:00
2022-03-01 06:32:12 +08:00
/**
* @param {string} actualPath
*/
2019-09-11 22:49:49 +08:00
function checkPackageJSON(actualPath) {
2020-09-22 20:37:04 +08:00
const actual = require(path.join(__dirname, '..', actualPath));
const rootPackageJSON = require('../package.json');
const checkIncluded = (set1, set2) => {
2022-06-08 23:49:21 +08:00
for (const depName in set1) {
2021-01-07 04:21:51 +08:00
const depVersion = set1[depName];
const rootDepVersion = set2[depName];
if (!rootDepVersion) {
// missing in root is allowed
continue;
}
if (depVersion !== rootDepVersion) {
this.emit(
'error',
`The dependency ${depName} in '${actualPath}' (${depVersion}) is different than in the root package.json (${rootDepVersion})`
);
}
}
};
checkIncluded(actual.dependencies, rootPackageJSON.dependencies);
checkIncluded(actual.devDependencies, rootPackageJSON.devDependencies);
2019-09-11 22:49:49 +08:00
}
2020-09-22 20:37:04 +08:00
const checkPackageJSONTask = task.define('check-package-json', () => {
return gulp.src('package.json').pipe(
2020-09-22 17:12:35 +08:00
es.through(function () {
2020-09-22 20:37:04 +08:00
checkPackageJSON.call(this, 'remote/package.json');
checkPackageJSON.call(this, 'remote/web/package.json');
checkPackageJSON.call(this, 'build/package.json');
2020-09-22 17:12:35 +08:00
})
);
2019-09-11 22:49:49 +08:00
});
gulp.task(checkPackageJSONTask);
2021-01-07 16:15:05 +08:00
const hygieneTask = task.define('hygiene', task.series(checkPackageJSONTask, () => hygiene(undefined, false)));
2021-01-07 04:21:51 +08:00
gulp.task(hygieneTask);