knip 2.1.3 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/dist/{configuration-chief.js → ConfigurationChief.js} +39 -38
- package/dist/{dependency-deputy.d.ts → DependencyDeputy.d.ts} +4 -2
- package/dist/{dependency-deputy.js → DependencyDeputy.js} +29 -10
- package/dist/{principal-factory.d.ts → PrincipalFactory.d.ts} +1 -1
- package/dist/{principal-factory.js → PrincipalFactory.js} +1 -1
- package/dist/{project-principal.d.ts → ProjectPrincipal.d.ts} +7 -4
- package/dist/{project-principal.js → ProjectPrincipal.js} +6 -4
- package/dist/{workspace-worker.d.ts → WorkspaceWorker.d.ts} +1 -1
- package/dist/{workspace-worker.js → WorkspaceWorker.js} +0 -2
- package/dist/binaries/index.d.ts +2 -2
- package/dist/binaries/index.js +12 -16
- package/dist/binaries/resolvers/fallback.js +8 -4
- package/dist/binaries/resolvers/npx.js +3 -1
- package/dist/binaries/types.d.ts +1 -5
- package/dist/cli.js +1 -1
- package/dist/index.js +57 -47
- package/dist/manifest/index.d.ts +1 -3
- package/dist/manifest/index.js +11 -25
- package/dist/plugins/_template/index.js +1 -1
- package/dist/plugins/ava/index.js +4 -6
- package/dist/plugins/babel/index.js +1 -1
- package/dist/plugins/capacitor/index.js +1 -1
- package/dist/plugins/changesets/index.js +1 -1
- package/dist/plugins/commitizen/index.js +1 -1
- package/dist/plugins/commitlint/index.js +1 -1
- package/dist/plugins/cspell/index.js +1 -1
- package/dist/plugins/eslint/index.js +1 -1
- package/dist/plugins/gatsby/index.js +1 -1
- package/dist/plugins/github-actions/index.js +4 -6
- package/dist/plugins/husky/index.js +4 -6
- package/dist/plugins/jest/index.js +1 -1
- package/dist/plugins/lefthook/index.js +4 -6
- package/dist/plugins/lint-staged/index.js +7 -7
- package/dist/plugins/markdownlint/index.js +1 -1
- package/dist/plugins/mocha/index.js +1 -1
- package/dist/plugins/npm-package-json-lint/index.js +1 -1
- package/dist/plugins/nx/index.js +4 -4
- package/dist/plugins/nyc/index.js +1 -1
- package/dist/plugins/postcss/index.js +1 -1
- package/dist/plugins/prettier/index.js +1 -1
- package/dist/plugins/release-it/index.js +4 -4
- package/dist/plugins/remark/index.js +1 -1
- package/dist/plugins/semantic-release/index.js +1 -1
- package/dist/plugins/storybook/index.js +1 -1
- package/dist/plugins/stryker/index.js +1 -1
- package/dist/plugins/typedoc/index.js +1 -1
- package/dist/plugins/typescript/index.js +1 -1
- package/dist/plugins/vitest/index.js +1 -1
- package/dist/plugins/webpack/index.js +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/{ast.d.ts → exports.d.ts} +0 -10
- package/dist/types/imports.d.ts +14 -0
- package/dist/types/imports.js +1 -0
- package/dist/types/plugins.d.ts +1 -2
- package/dist/types/workspace.d.ts +1 -0
- package/dist/typescript/SourceFile.d.ts +1 -0
- package/dist/typescript/getImportsAndExports.d.ts +29 -0
- package/dist/typescript/getImportsAndExports.js +158 -0
- package/dist/typescript/visitors/exports/exportAssignment.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportAssignment.js +8 -0
- package/dist/typescript/visitors/exports/exportDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportDeclaration.js +13 -0
- package/dist/typescript/visitors/exports/exportKeyword.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportKeyword.js +77 -0
- package/dist/typescript/visitors/exports/index.d.ts +3 -0
- package/dist/typescript/visitors/exports/index.js +6 -0
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +3 -0
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +31 -0
- package/dist/typescript/visitors/helpers.d.ts +3 -0
- package/dist/typescript/visitors/helpers.js +3 -0
- package/dist/typescript/visitors/imports/importCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/importCall.js +35 -0
- package/dist/typescript/visitors/imports/importDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/importDeclaration.js +32 -0
- package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/importEqualsDeclaration.js +11 -0
- package/dist/typescript/visitors/imports/index.d.ts +3 -0
- package/dist/typescript/visitors/imports/index.js +17 -0
- package/dist/typescript/visitors/imports/jsDocType.d.ts +3 -0
- package/dist/typescript/visitors/imports/jsDocType.js +11 -0
- package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/reExportDeclaration.js +21 -0
- package/dist/typescript/visitors/imports/requireCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/requireCall.js +46 -0
- package/dist/typescript/visitors/imports/requireResolveCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/requireResolveCall.js +14 -0
- package/dist/typescript/visitors/index.d.ts +10 -0
- package/dist/typescript/visitors/index.js +15 -0
- package/dist/typescript/visitors/scripts/index.d.ts +3 -0
- package/dist/typescript/visitors/scripts/index.js +3 -0
- package/dist/typescript/visitors/scripts/zx.d.ts +3 -0
- package/dist/typescript/visitors/scripts/zx.js +8 -0
- package/dist/util/array.d.ts +0 -1
- package/dist/util/array.js +0 -7
- package/dist/util/compilers.d.ts +5 -4
- package/dist/util/compilers.js +1 -3
- package/dist/util/glob.js +1 -1
- package/dist/util/loader.js +1 -1
- package/dist/util/plugin.js +1 -1
- package/dist/util/require.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/typescript/ast-walker.d.ts +0 -16
- package/dist/typescript/ast-walker.js +0 -364
- package/dist/{configuration-chief.d.ts → ConfigurationChief.d.ts} +0 -0
- package/dist/{configuration-validator.d.ts → ConfigurationValidator.d.ts} +6 -6
- /package/dist/{configuration-validator.js → ConfigurationValidator.js} +0 -0
- /package/dist/{console-streamer.d.ts → ConsoleStreamer.d.ts} +0 -0
- /package/dist/{console-streamer.js → ConsoleStreamer.js} +0 -0
- /package/dist/{issue-collector.d.ts → IssueCollector.d.ts} +0 -0
- /package/dist/{issue-collector.js → IssueCollector.js} +0 -0
- /package/dist/types/{ast.js → exports.js} +0 -0
- /package/dist/util/{performance.d.ts → Performance.d.ts} +0 -0
- /package/dist/util/{performance.js → Performance.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _getDependenciesFromScripts } from './binaries/index.js';
|
|
2
|
+
import { ConfigurationChief } from './ConfigurationChief.js';
|
|
3
|
+
import { ConsoleStreamer } from './ConsoleStreamer.js';
|
|
3
4
|
import { ROOT_WORKSPACE_NAME } from './constants.js';
|
|
4
|
-
import { DependencyDeputy } from './
|
|
5
|
-
import { IssueCollector } from './
|
|
6
|
-
import { PrincipalFactory } from './
|
|
5
|
+
import { DependencyDeputy } from './DependencyDeputy.js';
|
|
6
|
+
import { IssueCollector } from './IssueCollector.js';
|
|
7
|
+
import { PrincipalFactory } from './PrincipalFactory.js';
|
|
7
8
|
import { compact } from './util/array.js';
|
|
8
9
|
import { debugLogObject, debugLogArray, debugLog } from './util/debug.js';
|
|
9
10
|
import { LoaderError } from './util/errors.js';
|
|
@@ -14,7 +15,7 @@ import { dirname, isInNodeModules, join, isInternal, isAbsolute } from './util/p
|
|
|
14
15
|
import { _resolveSpecifier, _tryResolve } from './util/require.js';
|
|
15
16
|
import { _require } from './util/require.js';
|
|
16
17
|
import { loadTSConfig as loadCompilerOptions } from './util/tsconfig-loader.js';
|
|
17
|
-
import { WorkspaceWorker } from './
|
|
18
|
+
import { WorkspaceWorker } from './WorkspaceWorker.js';
|
|
18
19
|
export const main = async (unresolvedConfiguration) => {
|
|
19
20
|
const { cwd, tsConfigFile, gitignore, isStrict, isProduction, isShowProgress } = unresolvedConfiguration;
|
|
20
21
|
debugLogObject('Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
|
|
@@ -29,17 +30,55 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
29
30
|
const workspaces = chief.getEnabledWorkspaces();
|
|
30
31
|
const report = chief.getIssueTypesToReport();
|
|
31
32
|
debugLogObject('Included workspaces', workspaces);
|
|
33
|
+
const handleReferencedDependency = ({ specifier, containingFilePath, principal, workspace, }) => {
|
|
34
|
+
if (isInternal(specifier)) {
|
|
35
|
+
const absSpecifier = isAbsolute(specifier) ? specifier : join(dirname(containingFilePath), specifier);
|
|
36
|
+
const filePath = _tryResolve(absSpecifier, containingFilePath);
|
|
37
|
+
if (filePath) {
|
|
38
|
+
principal.addEntryPath(filePath);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
collector.addIssue({ type: 'unresolved', filePath: containingFilePath, symbol: specifier });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (isInNodeModules(specifier)) {
|
|
46
|
+
const packageName = getPackageNameFromFilePath(specifier);
|
|
47
|
+
const isHandled = deputy.maybeAddReferencedExternalDependency(workspace, packageName);
|
|
48
|
+
if (!isHandled)
|
|
49
|
+
collector.addIssue({ type: 'unlisted', filePath: containingFilePath, symbol: specifier });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const packageName = getPackageNameFromModuleSpecifier(specifier);
|
|
53
|
+
const isHandled = deputy.maybeAddReferencedExternalDependency(workspace, packageName);
|
|
54
|
+
if (!isHandled)
|
|
55
|
+
collector.addIssue({ type: 'unlisted', filePath: containingFilePath, symbol: specifier });
|
|
56
|
+
if (specifier !== packageName) {
|
|
57
|
+
const otherWorkspace = chief.findWorkspaceByPackageName(packageName);
|
|
58
|
+
if (otherWorkspace) {
|
|
59
|
+
const filePath = _resolveSpecifier(otherWorkspace.dir, specifier);
|
|
60
|
+
if (filePath) {
|
|
61
|
+
principal.addEntryPath(filePath);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
collector.addIssue({ type: 'unresolved', filePath: containingFilePath, symbol: specifier });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
32
71
|
const enabledPluginsStore = new Map();
|
|
33
72
|
for (const workspace of workspaces) {
|
|
34
73
|
const { name, dir, config, ancestors } = workspace;
|
|
35
|
-
const { paths, ignoreDependencies } = config;
|
|
74
|
+
const { paths, ignoreDependencies, ignoreBinaries } = config;
|
|
36
75
|
const isRoot = name === ROOT_WORKSPACE_NAME;
|
|
37
76
|
streamer.cast(`Analyzing workspace (${name})...`);
|
|
38
77
|
const manifestPath = isRoot ? chief.manifestPath : findFile(dir, 'package.json');
|
|
39
78
|
const manifest = isRoot ? chief.manifest : manifestPath && _require(manifestPath);
|
|
40
79
|
if (!manifestPath || !manifest)
|
|
41
80
|
throw new LoaderError(`Unable to load package.json for ${name}`);
|
|
42
|
-
deputy.addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies });
|
|
81
|
+
deputy.addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries });
|
|
43
82
|
const compilerOptions = await loadCompilerOptions(join(dir, tsConfigFile ?? 'tsconfig.json'));
|
|
44
83
|
const principal = factory.getPrincipal({ cwd: dir, report: report, paths, compilerOptions, compilers });
|
|
45
84
|
const worker = new WorkspaceWorker({
|
|
@@ -122,40 +161,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
122
161
|
deputy.setInstalledBinaries(name, installedBinaries);
|
|
123
162
|
enabledPluginsStore.set(name, enabledPlugins);
|
|
124
163
|
referencedDependencies.forEach(([containingFilePath, specifier]) => {
|
|
125
|
-
|
|
126
|
-
const absSpecifier = isAbsolute(specifier) ? specifier : join(dirname(containingFilePath), specifier);
|
|
127
|
-
const filePath = _tryResolve(absSpecifier, containingFilePath);
|
|
128
|
-
if (filePath) {
|
|
129
|
-
principal.addEntryPath(filePath);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
collector.addIssue({ type: 'unresolved', filePath: containingFilePath, symbol: specifier });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
if (isInNodeModules(specifier)) {
|
|
137
|
-
const packageName = getPackageNameFromFilePath(specifier);
|
|
138
|
-
const isHandled = deputy.maybeAddReferencedExternalDependency(workspace, packageName);
|
|
139
|
-
if (!isHandled)
|
|
140
|
-
collector.addIssue({ type: 'unlisted', filePath: containingFilePath, symbol: specifier });
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
const packageName = getPackageNameFromModuleSpecifier(specifier);
|
|
144
|
-
const isHandled = deputy.maybeAddReferencedExternalDependency(workspace, packageName);
|
|
145
|
-
if (!isHandled)
|
|
146
|
-
collector.addIssue({ type: 'unlisted', filePath: containingFilePath, symbol: specifier });
|
|
147
|
-
const otherWorkspace = chief.findWorkspaceByPackageName(packageName);
|
|
148
|
-
if (otherWorkspace && specifier !== packageName) {
|
|
149
|
-
const filePath = _resolveSpecifier(otherWorkspace.dir, specifier);
|
|
150
|
-
if (filePath) {
|
|
151
|
-
principal.addEntryPath(filePath);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
collector.addIssue({ type: 'unresolved', filePath: containingFilePath, symbol: specifier });
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
164
|
+
handleReferencedDependency({ specifier, containingFilePath, principal, workspace });
|
|
159
165
|
});
|
|
160
166
|
}
|
|
161
167
|
const principals = factory.getPrincipals();
|
|
@@ -167,10 +173,11 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
167
173
|
collector.counters.processed++;
|
|
168
174
|
const workspace = chief.findWorkspaceByFilePath(filePath);
|
|
169
175
|
if (workspace) {
|
|
170
|
-
const { imports, exports,
|
|
176
|
+
const { imports, exports, scripts } = principal.analyzeSourceFile(filePath);
|
|
171
177
|
const { internal, external, unresolved } = imports;
|
|
172
|
-
|
|
173
|
-
|
|
178
|
+
const { exported, duplicate } = exports;
|
|
179
|
+
if (exported.size > 0)
|
|
180
|
+
exportedSymbols.set(filePath, exported);
|
|
174
181
|
for (const [specifierFilePath, importItems] of internal.entries()) {
|
|
175
182
|
const packageName = getPackageNameFromModuleSpecifier(importItems.specifier);
|
|
176
183
|
const importedWorkspace = chief.findWorkspaceByPackageName(packageName);
|
|
@@ -196,7 +203,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
205
|
}
|
|
199
|
-
|
|
206
|
+
duplicate.forEach(symbols => {
|
|
200
207
|
const symbol = symbols.join('|');
|
|
201
208
|
collector.addIssue({ type: 'duplicates', filePath, symbol, symbols });
|
|
202
209
|
});
|
|
@@ -209,6 +216,9 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
209
216
|
unresolved.forEach(moduleSpecifier => {
|
|
210
217
|
collector.addIssue({ type: 'unresolved', filePath, symbol: moduleSpecifier });
|
|
211
218
|
});
|
|
219
|
+
_getDependenciesFromScripts(scripts, { cwd: dirname(filePath) }).forEach(specifier => {
|
|
220
|
+
handleReferencedDependency({ specifier, containingFilePath: filePath, principal, workspace });
|
|
221
|
+
});
|
|
212
222
|
}
|
|
213
223
|
};
|
|
214
224
|
const isExportedInEntryFile = (importedModule) => {
|
|
@@ -273,7 +283,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
273
283
|
if (['enum', 'type', 'interface'].includes(exportedItem.type)) {
|
|
274
284
|
collector.addIssue({ type: 'types', filePath, symbol, symbolType: exportedItem.type });
|
|
275
285
|
}
|
|
276
|
-
else {
|
|
286
|
+
else if (!importedModule.isDynamic || !principal.hasExternalReferences(filePath, exportedItem)) {
|
|
277
287
|
collector.addIssue({ type: 'exports', filePath, symbol });
|
|
278
288
|
}
|
|
279
289
|
}
|
package/dist/manifest/index.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type { WorkspaceConfiguration } from '../types/config.js';
|
|
2
1
|
import type { InstalledBinaries, PeerDependencies } from '../types/workspace.js';
|
|
3
2
|
import type { PackageJson } from 'type-fest';
|
|
4
3
|
type Options = {
|
|
5
|
-
config: WorkspaceConfiguration;
|
|
6
4
|
manifest: PackageJson;
|
|
7
5
|
isProduction: boolean;
|
|
8
6
|
isStrict: boolean;
|
|
9
7
|
dir: string;
|
|
10
8
|
cwd: string;
|
|
11
9
|
};
|
|
12
|
-
export declare const findDependencies: ({
|
|
10
|
+
export declare const findDependencies: ({ manifest, isProduction, isStrict, dir, cwd }: Options) => Promise<{
|
|
13
11
|
dependencies: string[];
|
|
14
12
|
peerDependencies: PeerDependencies;
|
|
15
13
|
installedBinaries: InstalledBinaries;
|
package/dist/manifest/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { timerify } from '../util/
|
|
1
|
+
import { _getDependenciesFromScripts } from '../binaries/index.js';
|
|
2
|
+
import { timerify } from '../util/Performance.js';
|
|
3
3
|
import { getPackageManifest } from './helpers.js';
|
|
4
|
-
const findManifestDependencies = async ({
|
|
5
|
-
const { ignoreBinaries } = config;
|
|
4
|
+
const findManifestDependencies = async ({ manifest, isProduction, isStrict, dir, cwd }) => {
|
|
6
5
|
const scriptFilter = isProduction ? ['start', 'postinstall'] : [];
|
|
7
|
-
const referencedDependencies = new Set();
|
|
8
6
|
const peerDependencies = new Map();
|
|
9
7
|
const scripts = Object.entries(manifest.scripts ?? {}).reduce((scripts, [scriptName, script]) => {
|
|
10
8
|
if (script && (scriptFilter.length === 0 || scriptFilter.includes(scriptName))) {
|
|
@@ -12,11 +10,7 @@ const findManifestDependencies = async ({ config, manifest, isProduction, isStri
|
|
|
12
10
|
}
|
|
13
11
|
return scripts;
|
|
14
12
|
}, []);
|
|
15
|
-
const
|
|
16
|
-
cwd: dir,
|
|
17
|
-
manifest,
|
|
18
|
-
ignore: ignoreBinaries,
|
|
19
|
-
});
|
|
13
|
+
const dependencies = _getDependenciesFromScripts(scripts, { cwd: dir, manifest });
|
|
20
14
|
const installedBinaries = new Map();
|
|
21
15
|
const packageNames = [
|
|
22
16
|
...Object.keys(manifest.dependencies ?? {}),
|
|
@@ -34,6 +28,12 @@ const findManifestDependencies = async ({ config, manifest, isProduction, isStri
|
|
|
34
28
|
else {
|
|
35
29
|
installedBinaries.set(binaryName, new Set([packageName]));
|
|
36
30
|
}
|
|
31
|
+
if (installedBinaries.has(packageName)) {
|
|
32
|
+
installedBinaries.get(packageName)?.add(binaryName);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
installedBinaries.set(packageName, new Set([binaryName]));
|
|
36
|
+
}
|
|
37
37
|
});
|
|
38
38
|
const packagePeerDependencies = Object.keys(manifest.peerDependencies ?? {});
|
|
39
39
|
packagePeerDependencies.forEach(packagePeerDependency => {
|
|
@@ -46,22 +46,8 @@ const findManifestDependencies = async ({ config, manifest, isProduction, isStri
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
for (const binaryName of referencedBinaries) {
|
|
50
|
-
if (installedBinaries.has(binaryName)) {
|
|
51
|
-
const packageNames = Array.from(installedBinaries.get(binaryName) ?? []);
|
|
52
|
-
const packageName = packageNames.length === 1 ? packageNames[0] : binaryName;
|
|
53
|
-
referencedDependencies.add(packageName);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
referencedDependencies.add(binaryName);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
ignoreBinaries.forEach(binaryName => {
|
|
60
|
-
const packageNames = installedBinaries.get(binaryName);
|
|
61
|
-
packageNames?.forEach(packageName => referencedDependencies.add(packageName));
|
|
62
|
-
});
|
|
63
49
|
return {
|
|
64
|
-
dependencies
|
|
50
|
+
dependencies,
|
|
65
51
|
peerDependencies,
|
|
66
52
|
installedBinaries,
|
|
67
53
|
};
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { timerify } from '../../util/
|
|
1
|
+
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
|
+
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
export const NAME = 'Ava';
|
|
5
5
|
export const ENABLERS = ['ava'];
|
|
6
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
7
7
|
export const CONFIG_FILE_PATTERNS = ['ava.config.{js,cjs,mjs}', 'package.json'];
|
|
8
|
-
const findAvaDependencies = async (configFilePath, { cwd, manifest
|
|
8
|
+
const findAvaDependencies = async (configFilePath, { cwd, manifest }) => {
|
|
9
9
|
const config = configFilePath.endsWith('package.json') ? manifest.ava : await load(configFilePath);
|
|
10
10
|
const requireArgs = (config?.require ?? []).map(require => `--require ${require}`);
|
|
11
11
|
const otherArgs = config?.nodeArguments ?? [];
|
|
12
12
|
const cmd = `node ${otherArgs.join(' ') + ' '}${requireArgs.join(' ')}`;
|
|
13
|
-
|
|
13
|
+
return _getDependenciesFromScripts([cmd], {
|
|
14
14
|
cwd,
|
|
15
15
|
manifest,
|
|
16
|
-
ignore: workspaceConfig.ignoreBinaries,
|
|
17
16
|
knownGlobalsOnly: true,
|
|
18
17
|
});
|
|
19
|
-
return binaries;
|
|
20
18
|
};
|
|
21
19
|
export const findDependencies = timerify(findAvaDependencies);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
|
-
import { timerify } from '../../util/
|
|
2
|
+
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
import { resolvePresetName, resolvePluginName, api } from './helpers.js';
|
|
5
5
|
export const NAME = 'Babel';
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
2
|
import { _firstGlob } from '../../util/glob.js';
|
|
3
3
|
import { getValuesByKeyDeep } from '../../util/object.js';
|
|
4
|
-
import { timerify } from '../../util/
|
|
4
|
+
import { timerify } from '../../util/Performance.js';
|
|
5
5
|
import { load } from '../../util/plugin.js';
|
|
6
6
|
export const NAME = 'GitHub Actions';
|
|
7
7
|
export const ENABLERS = 'This plugin is enabled when a `.yml` file is found in the `.github/workflows` folder.';
|
|
8
8
|
export const isEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.yml'] }));
|
|
9
9
|
export const CONFIG_FILE_PATTERNS = ['.github/workflows/*.yml', '.github/**/action.{yml,yaml}'];
|
|
10
|
-
const findGithubActionsDependencies = async (configFilePath, { cwd, manifest
|
|
10
|
+
const findGithubActionsDependencies = async (configFilePath, { cwd, manifest }) => {
|
|
11
11
|
const config = await load(configFilePath);
|
|
12
12
|
if (!config)
|
|
13
13
|
return [];
|
|
14
14
|
const scripts = getValuesByKeyDeep(config, 'run').filter((value) => typeof value === 'string');
|
|
15
|
-
|
|
15
|
+
return _getDependenciesFromScripts(scripts, {
|
|
16
16
|
cwd,
|
|
17
17
|
manifest,
|
|
18
|
-
ignore: workspaceConfig.ignoreBinaries,
|
|
19
18
|
knownGlobalsOnly: true,
|
|
20
19
|
});
|
|
21
|
-
return [...binaries, ...entryFiles];
|
|
22
20
|
};
|
|
23
21
|
export const findDependencies = timerify(findGithubActionsDependencies);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
|
-
import {
|
|
3
|
-
import { timerify } from '../../util/
|
|
2
|
+
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
3
|
+
import { timerify } from '../../util/Performance.js';
|
|
4
4
|
import { hasDependency } from '../../util/plugin.js';
|
|
5
5
|
export const NAME = 'husky';
|
|
6
6
|
export const ENABLERS = ['husky'];
|
|
@@ -10,14 +10,12 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
10
10
|
'.husky/pre-{applypatch,commit,merge-commit,push,rebase,receive}',
|
|
11
11
|
'.husky/post-{checkout,commit,merge,rewrite}',
|
|
12
12
|
];
|
|
13
|
-
const findHuskyDependencies = async (configFilePath, { cwd, manifest
|
|
13
|
+
const findHuskyDependencies = async (configFilePath, { cwd, manifest }) => {
|
|
14
14
|
const script = readFileSync(configFilePath);
|
|
15
|
-
|
|
15
|
+
return _getDependenciesFromScripts(String(script), {
|
|
16
16
|
cwd,
|
|
17
17
|
manifest,
|
|
18
|
-
ignore: workspaceConfig.ignoreBinaries,
|
|
19
18
|
knownGlobalsOnly: true,
|
|
20
19
|
});
|
|
21
|
-
return [...binaries, ...entryFiles];
|
|
22
20
|
};
|
|
23
21
|
export const findDependencies = timerify(findHuskyDependencies);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAbsolute, join, dirname, isInternal } from '../../util/path.js';
|
|
2
|
-
import { timerify } from '../../util/
|
|
2
|
+
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
export const NAME = 'Jest';
|
|
5
5
|
export const ENABLERS = ['jest'];
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
2
|
import { getValuesByKeyDeep } from '../../util/object.js';
|
|
3
|
-
import { timerify } from '../../util/
|
|
3
|
+
import { timerify } from '../../util/Performance.js';
|
|
4
4
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
5
5
|
export const NAME = 'Lefthook';
|
|
6
6
|
export const ENABLERS = ['lefthook', '@arkweid/lefthook'];
|
|
7
7
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
8
8
|
export const CONFIG_FILE_PATTERNS = ['lefthook.yml'];
|
|
9
|
-
const findLefthookDependencies = async (configFilePath, { cwd, manifest
|
|
9
|
+
const findLefthookDependencies = async (configFilePath, { cwd, manifest }) => {
|
|
10
10
|
const config = await load(configFilePath);
|
|
11
11
|
if (!config)
|
|
12
12
|
return [];
|
|
13
13
|
const scripts = getValuesByKeyDeep(config, 'run').filter((value) => typeof value === 'string');
|
|
14
|
-
|
|
14
|
+
return _getDependenciesFromScripts(scripts, {
|
|
15
15
|
cwd,
|
|
16
16
|
manifest,
|
|
17
|
-
ignore: workspaceConfig.ignoreBinaries,
|
|
18
17
|
knownGlobalsOnly: true,
|
|
19
18
|
});
|
|
20
|
-
return [...binaries, ...entryFiles];
|
|
21
19
|
};
|
|
22
20
|
export const findDependencies = timerify(findLefthookDependencies);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { timerify } from '../../util/
|
|
1
|
+
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
|
+
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
export const NAME = 'lint-staged';
|
|
5
5
|
export const ENABLERS = ['lint-staged'];
|
|
@@ -12,7 +12,7 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
12
12
|
'lint-staged.config.{js,mjs,cjs}',
|
|
13
13
|
'package.json',
|
|
14
14
|
];
|
|
15
|
-
const findLintStagedDependencies = async (configFilePath, { cwd, manifest
|
|
15
|
+
const findLintStagedDependencies = async (configFilePath, { cwd, manifest }) => {
|
|
16
16
|
let config = configFilePath.endsWith('package.json')
|
|
17
17
|
? manifest['lint-staged']
|
|
18
18
|
: await load(configFilePath);
|
|
@@ -21,12 +21,12 @@ const findLintStagedDependencies = async (configFilePath, { cwd, manifest, works
|
|
|
21
21
|
if (typeof config === 'function') {
|
|
22
22
|
config = config();
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const dependencies = new Set();
|
|
25
25
|
for (const entry of Object.values(config).flat()) {
|
|
26
26
|
const scripts = [typeof entry === 'function' ? await entry([]) : entry].flat();
|
|
27
|
-
const options = { cwd, manifest
|
|
28
|
-
|
|
27
|
+
const options = { cwd, manifest };
|
|
28
|
+
_getDependenciesFromScripts(scripts, options).forEach(identifier => dependencies.add(identifier));
|
|
29
29
|
}
|
|
30
|
-
return Array.from(
|
|
30
|
+
return Array.from(dependencies);
|
|
31
31
|
};
|
|
32
32
|
export const findDependencies = timerify(findLintStagedDependencies);
|
package/dist/plugins/nx/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
2
|
import { compact } from '../../util/array.js';
|
|
3
|
-
import { timerify } from '../../util/
|
|
3
|
+
import { timerify } from '../../util/Performance.js';
|
|
4
4
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
5
5
|
export const NAME = 'Nx';
|
|
6
6
|
export const ENABLERS = [/^@nrwl\//];
|
|
@@ -18,7 +18,7 @@ const findNxDependencies = async (configFilePath, { cwd, manifest }) => {
|
|
|
18
18
|
const scripts = compact(targets
|
|
19
19
|
.filter(target => target.executor === 'nx:run-commands')
|
|
20
20
|
.flatMap(target => (target.options?.commands ?? target.options?.command ? [target.options.command] : [])));
|
|
21
|
-
const
|
|
22
|
-
return [...executors, ...
|
|
21
|
+
const dependencies = _getDependenciesFromScripts(scripts, { cwd, manifest, knownGlobalsOnly: true });
|
|
22
|
+
return [...executors, ...dependencies];
|
|
23
23
|
};
|
|
24
24
|
export const findDependencies = timerify(findNxDependencies);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { timerify } from '../../util/
|
|
1
|
+
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
|
+
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
export const NAME = 'Release It';
|
|
5
5
|
export const ENABLERS = ['release-it'];
|
|
@@ -18,7 +18,7 @@ const findReleaseItDependencies = async (configFilePath, { cwd, manifest }) => {
|
|
|
18
18
|
return [];
|
|
19
19
|
const plugins = config.plugins ? Object.keys(config.plugins) : [];
|
|
20
20
|
const scripts = config.hooks ? Object.values(config.hooks).flat() : [];
|
|
21
|
-
const
|
|
22
|
-
return [...plugins, ...
|
|
21
|
+
const dependencies = _getDependenciesFromScripts(scripts, { cwd, manifest });
|
|
22
|
+
return [...plugins, ...dependencies];
|
|
23
23
|
};
|
|
24
24
|
export const findDependencies = timerify(findReleaseItDependencies);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
2
|
import { isInternal } from '../../util/path.js';
|
|
3
|
-
import { timerify } from '../../util/
|
|
3
|
+
import { timerify } from '../../util/Performance.js';
|
|
4
4
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
5
5
|
export const NAME = 'TypeScript';
|
|
6
6
|
export const ENABLERS = ['typescript'];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
|
-
import { timerify } from '../../util/
|
|
2
|
+
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
import { getEnvPackageName, getExternalReporters } from './helpers.js';
|
|
5
5
|
export const NAME = 'Vitest';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
|
-
import { timerify } from '../../util/
|
|
2
|
+
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
import { getDependenciesFromConfig } from '../babel/index.js';
|
|
5
5
|
export const NAME = 'Webpack';
|
package/dist/types/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { ConfigurationValidator } from '../
|
|
2
|
+
import { ConfigurationValidator } from '../ConfigurationValidator.js';
|
|
3
3
|
import * as Plugins from '../plugins/index.js';
|
|
4
4
|
import type { SyncCompilers, AsyncCompilers } from '../types/compilers.js';
|
|
5
5
|
export type RawConfiguration = z.infer<typeof ConfigurationValidator>;
|