forked from webpro-nl/knip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
40 lines (30 loc) · 1.51 KB
/
Copy pathindex.ts
File metadata and controls
40 lines (30 loc) · 1.51 KB
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
import { _getDependenciesFromScripts } from '../../binaries/index.js';
import { compact } from '../../util/array.js';
import { timerify } from '../../util/Performance.js';
import { hasDependency, load } from '../../util/plugin.js';
import type { NxProjectConfiguration } from './types.js';
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
export const NAME = 'Nx';
/** @public */
export const ENABLERS = ['nx', /^@nrwl\//];
export const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
export const CONFIG_FILE_PATTERNS = ['project.json', '{apps,libs}/**/project.json'];
const findNxDependencies: GenericPluginCallback = async (configFilePath, { cwd, manifest }) => {
const config: NxProjectConfiguration = await load(configFilePath);
if (!config) return [];
const targets = config.targets ? Object.values(config.targets) : [];
const executors = compact(
targets
.map(target => target?.executor)
.filter(executor => executor && !executor.startsWith('.'))
.map(executor => executor?.split(':')[0])
);
const scripts = compact(
targets
.filter(target => target.executor === 'nx:run-commands')
.flatMap(target => target.options?.commands ?? (target.options?.command ? [target.options.command] : []))
);
const dependencies = _getDependenciesFromScripts(scripts, { cwd, manifest });
return [...executors, ...dependencies];
};
export const findDependencies = timerify(findNxDependencies);