main
ts 39 lines 1.1 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 import chalk from 'chalk';
9 import {config} from '../config';
10
11 const packageJsonRE = /package\.json$/;
12 const knownIncompatibleLibrariesUsage = new Set();
13
14 export default {
15 run(source: string, path: string): void {
16 if (packageJsonRE.exec(path) !== null) {
17 const contents = JSON.parse(source);
18 const deps = contents.dependencies;
19 if (deps != null) {
20 for (const library of config.knownIncompatibleLibraries) {
21 if (Object.hasOwn(deps, library)) {
22 knownIncompatibleLibrariesUsage.add(library);
23 }
24 }
25 }
26 }
27 },
28
29 report(): void {
30 if (knownIncompatibleLibrariesUsage.size > 0) {
31 console.log(chalk.red(`Found the following incompatible libraries:`));
32 for (const library of knownIncompatibleLibrariesUsage) {
33 console.log(library);
34 }
35 } else {
36 console.log(chalk.green(`Found no usage of incompatible libraries.`));
37 }
38 },
39 };