Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/gulpfile.hygiene.ts
4770 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import gulp from 'gulp';
6
import es from 'event-stream';
7
import path from 'path';
8
import fs from 'fs';
9
import * as task from './lib/task.ts';
10
import { hygiene } from './hygiene.ts';
11
12
const dirName = path.dirname(new URL(import.meta.url).pathname);
13
14
function checkPackageJSON(this: NodeJS.ReadWriteStream, actualPath: string) {
15
const actual = JSON.parse(fs.readFileSync(path.join(dirName, '..', actualPath), 'utf8'));
16
const rootPackageJSON = JSON.parse(fs.readFileSync(path.join(dirName, '..', 'package.json'), 'utf8'));
17
const checkIncluded = (set1: Record<string, string>, set2: Record<string, string>) => {
18
for (const depName in set1) {
19
const depVersion = set1[depName];
20
const rootDepVersion = set2[depName];
21
if (!rootDepVersion) {
22
// missing in root is allowed
23
continue;
24
}
25
if (depVersion !== rootDepVersion) {
26
this.emit(
27
'error',
28
`The dependency ${depName} in '${actualPath}' (${depVersion}) is different than in the root package.json (${rootDepVersion})`
29
);
30
}
31
}
32
};
33
34
checkIncluded(actual.dependencies, rootPackageJSON.dependencies);
35
checkIncluded(actual.devDependencies, rootPackageJSON.devDependencies);
36
}
37
38
const checkPackageJSONTask = task.define('check-package-json', () => {
39
return gulp.src('package.json').pipe(
40
es.through(function () {
41
checkPackageJSON.call(this, 'remote/package.json');
42
checkPackageJSON.call(this, 'remote/web/package.json');
43
checkPackageJSON.call(this, 'build/package.json');
44
})
45
);
46
});
47
gulp.task(checkPackageJSONTask);
48
49
const hygieneTask = task.define('hygiene', task.series(checkPackageJSONTask, () => hygiene(undefined, false)));
50
gulp.task(hygieneTask);
51
52