This repository was archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathis-ngcc-necessary.ts
61 lines (50 loc) · 2.15 KB
/
is-ngcc-necessary.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as chalk from 'chalk';
import { existsSync, readFileSync } from 'fs';
import { resolve } from 'path';
const packages = Object.keys(JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf8')).dependencies);
const knownNonNgccPackages = new Set<string>(JSON.parse(readFileSync(resolve(__dirname, './non-ngcc-packages.json'), 'utf8')));
console.log(chalk.gray('Checking for packages that no longer need ngcc processing...'));
const ngccPackages = [];
const nonNgccPackages = [];
for (const packageName of packages) {
if (knownNonNgccPackages.has(packageName)) {
continue;
}
const packagePath = resolve(__dirname, '../node_modules', packageName);
const packageJson = JSON.parse(readFileSync(resolve(packagePath, 'package.json'), 'utf8'));
const typingsPath = packageJson.typings || packageJson.types || guessTypingsFromPackageJson(packagePath, packageJson);
if (!typingsPath) {
continue;
}
const metadataPath = resolve(packagePath, typingsPath.replace(/\.d\.ts$/, '') + '.metadata.json');
if (existsSync(metadataPath)) {
ngccPackages.push(packagePath);
} else {
nonNgccPackages.push(packagePath);
}
}
console.log(chalk.gray(`${ngccPackages.length} out of ${packages.length} packages still need ngcc processing.`));
if (nonNgccPackages.length > 0) {
console.error(chalk.red('The following packages no longer need to be processed by ngcc. Please add them to `./infra/non-ngcc-packages.json`.'));
for (const packageName of nonNgccPackages) {
console.error(chalk.yellow(`- ${packageName}`));
}
process.exit(1);
}
process.exit(0);
// HELPERS COPIED FROM NGCC
function guessTypingsFromPackageJson(packagePath: string, packageJson: any) {
const SUPPORTED_FORMAT_PROPERTIES = ['fesm2015', 'fesm5', 'es2015', 'esm2015', 'esm5', 'main', 'module', 'browser'];
for (const prop of SUPPORTED_FORMAT_PROPERTIES) {
const field = packageJson[prop];
if (typeof field !== 'string') {
continue;
}
const relativeTypingsPath = field.replace(/\.js$/, '.d.ts');
const typingsPath = resolve(packagePath, relativeTypingsPath);
if (existsSync(typingsPath)) {
return typingsPath;
}
}
return null;
}