1 | const { realpathSync } = require("fs");
|
2 | const { sync: readPackage } = require("read-pkg-up");
|
3 |
|
4 | const { packageJson: pkg } = readPackage({ cwd: realpathSync(process.cwd()) });
|
5 | const hasIn = (key, name) => {
|
6 | for (const x in pkg[key] || {}) {
|
7 | if (x === name) return true;
|
8 | }
|
9 | return false;
|
10 | };
|
11 | const keys = ["dependencies", "devDependencies", "peerDependencies"];
|
12 | const hasInDeps = (name) => keys.some((k) => hasIn(k, name));
|
13 |
|
14 | module.exports = {
|
15 | extends: ["./", hasInDeps("react") && "./react"].filter(Boolean),
|
16 | overrides: [
|
17 | hasInDeps("jest") && {
|
18 | files: [
|
19 | "*.{test,spec}.{js,ts,jsx,tsx}",
|
20 | "**/__tests__/**/*.{js,ts,jsx,tsx}",
|
21 | ],
|
22 | extends: "./jest",
|
23 | },
|
24 | hasInDeps("typescript") && {
|
25 | files: ["*.{ts,tsx}"],
|
26 | extends: "./typescript-without-type",
|
27 | },
|
28 | hasInDeps("jest") &&
|
29 | hasInDeps("typescript") && {
|
30 | files: [
|
31 | "*.{test,spec}.{js,ts,jsx,tsx}",
|
32 | "**/__tests__/**/*.{js,ts,jsx,tsx}",
|
33 | ],
|
34 | extends: "./jest-and-typescript",
|
35 | },
|
36 | ].filter(Boolean),
|
37 | };
|