knip 5.62.0 → 5.63.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 +22 -24
- package/dist/CacheConsultant.d.ts +3 -9
- package/dist/CacheConsultant.js +5 -5
- package/dist/ConfigurationChief.d.ts +588 -38
- package/dist/ConfigurationChief.js +43 -124
- package/dist/ConsoleStreamer.d.ts +2 -3
- package/dist/ConsoleStreamer.js +2 -2
- package/dist/DependencyDeputy.d.ts +2 -6
- package/dist/IssueCollector.d.ts +4 -12
- package/dist/IssueCollector.js +10 -10
- package/dist/IssueFixer.d.ts +3 -14
- package/dist/IssueFixer.js +11 -21
- package/dist/PrincipalFactory.d.ts +3 -2
- package/dist/PrincipalFactory.js +11 -11
- package/dist/ProjectPrincipal.d.ts +5 -3
- package/dist/ProjectPrincipal.js +17 -11
- package/dist/WorkspaceWorker.d.ts +4 -9
- package/dist/WorkspaceWorker.js +8 -12
- package/dist/binaries/bash-parser.js +1 -1
- package/dist/binaries/fallback.js +4 -2
- package/dist/binaries/package-manager/pnpm.js +6 -1
- package/dist/cli.js +43 -60
- package/dist/compilers/index.d.ts +34 -4
- package/dist/graph/analyze.d.ts +3 -8
- package/dist/graph/analyze.js +24 -27
- package/dist/graph/build.d.ts +3 -17
- package/dist/graph/build.js +60 -47
- package/dist/index.d.ts +3 -6
- package/dist/index.js +23 -62
- package/dist/plugins/astro/index.d.ts +1 -0
- package/dist/plugins/astro/index.js +4 -0
- package/dist/plugins/index.d.ts +24 -1
- package/dist/plugins/index.js +6 -0
- package/dist/plugins/lefthook/index.js +2 -0
- package/dist/plugins/node-modules-inspector/index.d.ts +12 -0
- package/dist/plugins/node-modules-inspector/index.js +17 -0
- package/dist/plugins/nuxt/index.js +4 -3
- package/dist/plugins/nuxt/types.d.ts +3 -2
- package/dist/plugins/playwright/index.js +8 -1
- package/dist/plugins/playwright/types.d.ts +20 -14
- package/dist/plugins/pnpm/index.d.ts +7 -0
- package/dist/plugins/pnpm/index.js +8 -0
- package/dist/plugins/preconstruct/index.js +2 -1
- package/dist/plugins/react-router/index.js +18 -8
- package/dist/plugins/rsbuild/index.js +28 -2
- package/dist/plugins/rsbuild/types.d.ts +11 -0
- package/dist/plugins/rslib/index.d.ts +10 -0
- package/dist/plugins/rslib/index.js +15 -0
- package/dist/plugins/rslib/types.d.ts +1 -0
- package/dist/plugins/rspack/index.js +1 -1
- package/dist/plugins/typescript/index.d.ts +1 -1
- package/dist/plugins.js +3 -2
- package/dist/reporters/codeclimate.d.ts +1 -1
- package/dist/reporters/codeclimate.js +10 -10
- package/dist/reporters/codeowners.d.ts +1 -1
- package/dist/reporters/codeowners.js +5 -5
- package/dist/reporters/compact.d.ts +1 -1
- package/dist/reporters/compact.js +7 -7
- package/dist/reporters/disclosure.d.ts +1 -1
- package/dist/reporters/disclosure.js +2 -2
- package/dist/reporters/index.d.ts +6 -6
- package/dist/reporters/json.d.ts +1 -1
- package/dist/reporters/json.js +3 -3
- package/dist/reporters/markdown.d.ts +1 -1
- package/dist/reporters/markdown.js +4 -4
- package/dist/reporters/symbols.js +4 -2
- package/dist/reporters/util/configuration-hints.d.ts +1 -1
- package/dist/reporters/util/configuration-hints.js +58 -23
- package/dist/reporters/util/util.d.ts +2 -4
- package/dist/reporters/util/util.js +6 -6
- package/dist/reporters/watch.d.ts +3 -4
- package/dist/reporters/watch.js +5 -5
- package/dist/schema/configuration.d.ts +176 -8
- package/dist/schema/plugins.d.ts +69 -0
- package/dist/schema/plugins.js +3 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +3 -0
- package/dist/types/config.d.ts +4 -10
- package/dist/types/entries.d.ts +3 -0
- package/dist/types/entries.js +1 -0
- package/dist/types/issues.d.ts +4 -3
- package/dist/types/{cli.d.ts → options.d.ts} +2 -2
- package/dist/types/options.js +1 -0
- package/dist/types/package-json.d.ts +5 -0
- package/dist/types/project.d.ts +1 -7
- package/dist/types/tsconfig-json.d.ts +14 -0
- package/dist/types/tsconfig-json.js +1 -0
- package/dist/typescript/ast-helpers.js +1 -1
- package/dist/typescript/get-imports-and-exports.d.ts +2 -2
- package/dist/typescript/get-imports-and-exports.js +9 -10
- package/dist/util/Performance.js +16 -6
- package/dist/util/cli-arguments.d.ts +1 -2
- package/dist/util/cli-arguments.js +3 -13
- package/dist/util/create-options.d.ts +1219 -0
- package/dist/util/create-options.js +112 -0
- package/dist/util/debug.js +3 -4
- package/dist/util/errors.d.ts +1 -1
- package/dist/util/file-entry-cache.js +3 -3
- package/dist/util/fs.d.ts +1 -1
- package/dist/util/get-included-issue-types.d.ts +9 -13
- package/dist/util/get-included-issue-types.js +10 -16
- package/dist/util/get-referenced-inputs.js +1 -1
- package/dist/util/glob-core.d.ts +1 -1
- package/dist/util/glob-core.js +8 -7
- package/dist/util/glob.d.ts +1 -0
- package/dist/util/glob.js +1 -1
- package/dist/util/input.d.ts +1 -1
- package/dist/util/input.js +1 -1
- package/dist/util/is-identifier-referenced.d.ts +1 -1
- package/dist/util/is-identifier-referenced.js +19 -19
- package/dist/util/load-config.d.ts +1 -0
- package/dist/util/load-config.js +24 -0
- package/dist/util/package-json.d.ts +2 -1
- package/dist/util/package-json.js +24 -12
- package/dist/util/parse-and-convert-gitignores.js +2 -0
- package/dist/util/path.d.ts +4 -4
- package/dist/util/path.js +5 -7
- package/dist/util/reporter.js +3 -3
- package/dist/util/require.js +1 -2
- package/dist/util/table.js +1 -3
- package/dist/util/tag.d.ts +1 -1
- package/dist/util/to-source-path.d.ts +1 -1
- package/dist/util/to-source-path.js +5 -5
- package/dist/util/trace.d.ts +6 -6
- package/dist/util/trace.js +18 -22
- package/dist/util/watch.d.ts +2 -5
- package/dist/util/watch.js +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +10 -15
- package/schema.json +12 -0
- package/dist/util/unwrap-function.d.ts +0 -1
- package/dist/util/unwrap-function.js +0 -13
- /package/dist/{types/cli.js → plugins/rslib/types.js} +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { partitionCompilers } from '../compilers/index.js';
|
|
2
|
+
import { KNIP_CONFIG_LOCATIONS } from '../constants.js';
|
|
3
|
+
import { knipConfigurationSchema } from '../schema/configuration.js';
|
|
4
|
+
import { ConfigurationError } from './errors.js';
|
|
5
|
+
import { findFile, loadJSON } from './fs.js';
|
|
6
|
+
import { getIncludedIssueTypes, shorthandDeps, shorthandFiles, shorthandTypes } from './get-included-issue-types.js';
|
|
7
|
+
import { defaultRules } from './issue-initializers.js';
|
|
8
|
+
import { loadResolvedConfigFile } from './load-config.js';
|
|
9
|
+
import { _load } from './loader.js';
|
|
10
|
+
import { getKeysByValue } from './object.js';
|
|
11
|
+
import { isAbsolute, join, normalize, toAbsolute, toPosix } from './path.js';
|
|
12
|
+
import { splitTags } from './tag.js';
|
|
13
|
+
const pcwd = process.cwd();
|
|
14
|
+
export const createOptions = async (options) => {
|
|
15
|
+
const { parsedCLIArgs = {}, ...rest } = options;
|
|
16
|
+
const cwd = normalize(toPosix(toAbsolute(options.cwd ?? parsedCLIArgs.directory ?? pcwd, pcwd)));
|
|
17
|
+
const manifestPath = findFile(cwd, 'package.json');
|
|
18
|
+
const manifest = manifestPath && (await loadJSON(manifestPath));
|
|
19
|
+
if (!(manifestPath && manifest)) {
|
|
20
|
+
throw new ConfigurationError('Unable to find package.json');
|
|
21
|
+
}
|
|
22
|
+
let configFilePath;
|
|
23
|
+
for (const configPath of parsedCLIArgs.config ? [parsedCLIArgs.config] : KNIP_CONFIG_LOCATIONS) {
|
|
24
|
+
const resolvedConfigFilePath = isAbsolute(configPath) ? configPath : findFile(cwd, configPath);
|
|
25
|
+
if (resolvedConfigFilePath) {
|
|
26
|
+
configFilePath = resolvedConfigFilePath;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (parsedCLIArgs.config && !configFilePath && !manifest.knip) {
|
|
31
|
+
throw new ConfigurationError(`Unable to find ${parsedCLIArgs.config} or package.json#knip`);
|
|
32
|
+
}
|
|
33
|
+
const loadedConfig = Object.assign({}, manifest.knip, configFilePath ? await loadResolvedConfigFile(configFilePath) : {});
|
|
34
|
+
const parsedConfig = knipConfigurationSchema.parse(partitionCompilers(loadedConfig));
|
|
35
|
+
if (!configFilePath && manifest.knip)
|
|
36
|
+
configFilePath = manifestPath;
|
|
37
|
+
const pnpmWorkspacesPath = findFile(cwd, 'pnpm-workspace.yaml');
|
|
38
|
+
const pnpmWorkspaces = pnpmWorkspacesPath && (await _load(pnpmWorkspacesPath));
|
|
39
|
+
const workspaces = pnpmWorkspaces?.packages ??
|
|
40
|
+
(manifest.workspaces
|
|
41
|
+
? Array.isArray(manifest.workspaces)
|
|
42
|
+
? manifest.workspaces
|
|
43
|
+
: (manifest.workspaces.packages ?? [])
|
|
44
|
+
: []);
|
|
45
|
+
const isStrict = rest.isStrict ?? parsedCLIArgs.strict ?? false;
|
|
46
|
+
const isProduction = rest.isProduction ?? parsedCLIArgs.production ?? isStrict;
|
|
47
|
+
const rules = { ...defaultRules, ...parsedConfig.rules };
|
|
48
|
+
const excludesFromRules = getKeysByValue(rules, 'off');
|
|
49
|
+
const includedIssueTypes = getIncludedIssueTypes({
|
|
50
|
+
isProduction,
|
|
51
|
+
exclude: [...excludesFromRules, ...(parsedConfig.exclude ?? [])],
|
|
52
|
+
include: parsedConfig.include ?? [],
|
|
53
|
+
excludeOverrides: rest.excludedIssueTypes ?? parsedCLIArgs.exclude ?? [],
|
|
54
|
+
includeOverrides: [
|
|
55
|
+
...(rest.includedIssueTypes ?? parsedCLIArgs.include ?? []),
|
|
56
|
+
...(parsedCLIArgs.dependencies ? shorthandDeps : []),
|
|
57
|
+
...(parsedCLIArgs.exports ? shorthandTypes : []),
|
|
58
|
+
...(parsedCLIArgs.files ? shorthandFiles : []),
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
const fixTypes = rest.fixTypes ?? parsedCLIArgs['fix-type'] ?? [];
|
|
62
|
+
const isFixFiles = parsedCLIArgs['allow-remove-files'] && (fixTypes.length === 0 || fixTypes.includes('files'));
|
|
63
|
+
const isIncludeLibs = parsedCLIArgs['include-libs'] ?? rest.isIncludeLibs ?? false;
|
|
64
|
+
const isReportClassMembers = includedIssueTypes.classMembers;
|
|
65
|
+
const tags = splitTags(parsedCLIArgs.tags ?? rest.tags ?? parsedConfig.tags ?? parsedCLIArgs['experimental-tags'] ?? []);
|
|
66
|
+
return {
|
|
67
|
+
cacheLocation: parsedCLIArgs['cache-location'] ?? join(cwd, 'node_modules', '.cache', 'knip'),
|
|
68
|
+
config: parsedCLIArgs.config,
|
|
69
|
+
configFilePath,
|
|
70
|
+
cwd,
|
|
71
|
+
dependencies: parsedCLIArgs.dependencies ?? false,
|
|
72
|
+
experimentalTags: tags,
|
|
73
|
+
exports: parsedCLIArgs.exports ?? false,
|
|
74
|
+
files: parsedCLIArgs.files ?? false,
|
|
75
|
+
fixTypes,
|
|
76
|
+
gitignore: parsedCLIArgs['no-gitignore'] ? false : (rest.gitignore ?? true),
|
|
77
|
+
includedIssueTypes,
|
|
78
|
+
isCache: parsedCLIArgs.cache ?? false,
|
|
79
|
+
isDebug: parsedCLIArgs.debug ?? false,
|
|
80
|
+
isDisableConfigHints: parsedCLIArgs['no-config-hints'] || isProduction || Boolean(parsedCLIArgs.workspace),
|
|
81
|
+
isFix: parsedCLIArgs.fix ?? rest.isFix ?? false,
|
|
82
|
+
isFixDependencies: fixTypes.length === 0 || fixTypes.includes('dependencies'),
|
|
83
|
+
isFixFiles,
|
|
84
|
+
isFixUnusedExports: fixTypes.length === 0 || fixTypes.includes('exports'),
|
|
85
|
+
isFixUnusedTypes: fixTypes.length === 0 || fixTypes.includes('types'),
|
|
86
|
+
isFormat: parsedCLIArgs.format ?? rest.isFormat ?? false,
|
|
87
|
+
isIncludeEntryExports: parsedCLIArgs['include-entry-exports'] ?? rest.isIncludeEntryExports ?? false,
|
|
88
|
+
isIsolateWorkspaces: rest.isIsolateWorkspaces ?? parsedCLIArgs['isolate-workspaces'] ?? false,
|
|
89
|
+
isProduction,
|
|
90
|
+
isReportClassMembers,
|
|
91
|
+
isReportDependencies: includedIssueTypes.dependencies ||
|
|
92
|
+
includedIssueTypes.unlisted ||
|
|
93
|
+
includedIssueTypes.unresolved ||
|
|
94
|
+
includedIssueTypes.binaries,
|
|
95
|
+
isReportTypes: includedIssueTypes.types || includedIssueTypes.nsTypes || includedIssueTypes.enumMembers,
|
|
96
|
+
isReportValues: includedIssueTypes.exports || includedIssueTypes.nsExports || isReportClassMembers,
|
|
97
|
+
isShowProgress: parsedCLIArgs['no-progress'] === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function',
|
|
98
|
+
isSkipLibs: !(isIncludeLibs || includedIssueTypes.classMembers),
|
|
99
|
+
isStrict,
|
|
100
|
+
isTrace: parsedCLIArgs.trace ?? false,
|
|
101
|
+
isTreatConfigHintsAsErrors: parsedCLIArgs['treat-config-hints-as-errors'] ?? parsedConfig.treatConfigHintsAsErrors ?? false,
|
|
102
|
+
isWatch: parsedCLIArgs.watch ?? rest.isWatch ?? false,
|
|
103
|
+
parsedConfig,
|
|
104
|
+
rules,
|
|
105
|
+
tags,
|
|
106
|
+
traceExport: parsedCLIArgs['trace-export'],
|
|
107
|
+
traceFile: parsedCLIArgs['trace-file'],
|
|
108
|
+
tsConfigFile: parsedCLIArgs.tsConfig,
|
|
109
|
+
workspace: rest.workspace ?? parsedCLIArgs.workspace,
|
|
110
|
+
workspaces,
|
|
111
|
+
};
|
|
112
|
+
};
|
package/dist/util/debug.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import util from 'node:util';
|
|
1
|
+
import util, { parseArgs } from 'node:util';
|
|
2
2
|
import picocolors from 'picocolors';
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const IS_DEBUG_ENABLED = debug ?? false;
|
|
3
|
+
const { values } = parseArgs({ strict: false, options: { debug: { type: 'boolean' } } });
|
|
4
|
+
const IS_DEBUG_ENABLED = values.debug ?? false;
|
|
6
5
|
const IS_COLORS = !process.env.NO_COLOR;
|
|
7
6
|
const noop = () => { };
|
|
8
7
|
const inspectOptions = { maxArrayLength: null, depth: null, colors: IS_COLORS };
|
package/dist/util/errors.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare class ConfigurationError extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class LoaderError extends Error {
|
|
8
8
|
}
|
|
9
|
-
export declare const isKnownError: (error: Error) => error is
|
|
9
|
+
export declare const isKnownError: (error: Error) => error is ZodError<any> | ConfigurationError | LoaderError;
|
|
10
10
|
export declare const isDisplayReason: (error: Error) => error is ErrorWithCause;
|
|
11
11
|
export declare const isConfigurationError: (error: Error) => error is ConfigurationError;
|
|
12
12
|
export declare const getKnownError: (error: Error) => Error;
|
|
@@ -4,7 +4,7 @@ import { deserialize, serialize } from 'node:v8';
|
|
|
4
4
|
import { timerify } from './Performance.js';
|
|
5
5
|
import { debugLog } from './debug.js';
|
|
6
6
|
import { isDirectory, isFile } from './fs.js';
|
|
7
|
-
import {
|
|
7
|
+
import { dirname, isAbsolute, resolve } from './path.js';
|
|
8
8
|
const createCache = (filePath) => {
|
|
9
9
|
try {
|
|
10
10
|
return deserialize(fs.readFileSync(filePath));
|
|
@@ -19,7 +19,7 @@ export class FileEntryCache {
|
|
|
19
19
|
cache = new Map();
|
|
20
20
|
normalizedEntries = new Map();
|
|
21
21
|
constructor(cacheId, _path) {
|
|
22
|
-
this.filePath =
|
|
22
|
+
this.filePath = path.resolve(_path, cacheId);
|
|
23
23
|
if (isFile(this.filePath))
|
|
24
24
|
this.cache = create(this.filePath);
|
|
25
25
|
this.removeNotFoundFiles();
|
|
@@ -72,7 +72,7 @@ export class FileEntryCache {
|
|
|
72
72
|
}
|
|
73
73
|
removeEntry(entryName) {
|
|
74
74
|
if (!isAbsolute(entryName))
|
|
75
|
-
entryName = resolve(
|
|
75
|
+
entryName = resolve(entryName);
|
|
76
76
|
this.normalizedEntries.delete(entryName);
|
|
77
77
|
this.cache.delete(entryName);
|
|
78
78
|
}
|
package/dist/util/fs.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare const findFile: (workingDir: string, fileName: string) => string
|
|
|
4
4
|
export declare const loadFile: (filePath: string) => Promise<string>;
|
|
5
5
|
export declare const loadJSON: (filePath: string) => Promise<any>;
|
|
6
6
|
export declare const loadYAML: (filePath: string) => Promise<unknown>;
|
|
7
|
-
export declare const loadTOML: (filePath: string) => Promise<
|
|
7
|
+
export declare const loadTOML: (filePath: string) => Promise<import("smol-toml").TomlTable>;
|
|
8
8
|
export declare const parseJSON: (filePath: string, contents: string) => Promise<any>;
|
|
9
9
|
export declare const parseYAML: (contents: string) => unknown;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import type { Report } from '../types/issues.js';
|
|
2
|
-
|
|
3
|
-
includedIssueTypes: string[];
|
|
4
|
-
excludedIssueTypes: string[];
|
|
5
|
-
isDependenciesShorthand: boolean;
|
|
6
|
-
isExportsShorthand: boolean;
|
|
7
|
-
isFilesShorthand: boolean;
|
|
8
|
-
};
|
|
9
|
-
type Options = {
|
|
2
|
+
type GetIncludedIssueTypesOptions = {
|
|
10
3
|
isProduction?: boolean;
|
|
11
|
-
include
|
|
12
|
-
exclude
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
include: string[];
|
|
5
|
+
exclude: string[];
|
|
6
|
+
includeOverrides?: string[];
|
|
7
|
+
excludeOverrides?: string[];
|
|
15
8
|
};
|
|
16
9
|
export declare const defaultExcludedIssueTypes: string[];
|
|
17
|
-
export declare const
|
|
10
|
+
export declare const shorthandDeps: string[];
|
|
11
|
+
export declare const shorthandTypes: string[];
|
|
12
|
+
export declare const shorthandFiles: string[];
|
|
13
|
+
export declare const getIncludedIssueTypes: (options: GetIncludedIssueTypesOptions) => Report;
|
|
18
14
|
export {};
|
|
@@ -3,27 +3,21 @@ import { ConfigurationError } from './errors.js';
|
|
|
3
3
|
export const defaultExcludedIssueTypes = ['classMembers', 'nsExports', 'nsTypes'];
|
|
4
4
|
const defaultIssueTypes = ISSUE_TYPES.filter(type => !defaultExcludedIssueTypes.includes(type));
|
|
5
5
|
const normalize = (values) => values.flatMap(value => value.split(','));
|
|
6
|
-
export const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export const shorthandDeps = ['dependencies', 'optionalPeerDependencies', 'unlisted', 'binaries', 'unresolved'];
|
|
7
|
+
export const shorthandTypes = ['types', 'nsTypes', 'enumMembers', 'duplicates'];
|
|
8
|
+
export const shorthandFiles = ['files'];
|
|
9
|
+
export const getIncludedIssueTypes = (options) => {
|
|
10
|
+
const incl = normalize(options.includeOverrides ?? []);
|
|
11
|
+
const excl = normalize(options.excludeOverrides ?? []);
|
|
12
|
+
for (const type of [...incl, ...excl, ...options.include, ...options.exclude]) {
|
|
10
13
|
if (!ISSUE_TYPES.includes(type))
|
|
11
14
|
throw new ConfigurationError(`Invalid issue type: ${type}`);
|
|
12
15
|
}
|
|
13
|
-
const excludes = exclude.filter(exclude => !incl.includes(exclude));
|
|
14
|
-
const includes = include.filter(include => !excl.includes(include));
|
|
15
|
-
if (cliArgs.isDependenciesShorthand) {
|
|
16
|
-
incl = [...incl, 'dependencies', 'optionalPeerDependencies', 'unlisted', 'binaries', 'unresolved'];
|
|
17
|
-
}
|
|
18
|
-
if (cliArgs.isExportsShorthand) {
|
|
19
|
-
incl = [...incl, 'exports', 'types', 'enumMembers', 'duplicates'];
|
|
20
|
-
}
|
|
21
|
-
if (cliArgs.isFilesShorthand) {
|
|
22
|
-
incl = [...incl, 'files'];
|
|
23
|
-
}
|
|
16
|
+
const excludes = options.exclude.filter(exclude => !incl.includes(exclude));
|
|
17
|
+
const includes = options.include.filter(include => !excl.includes(include));
|
|
24
18
|
const _include = [...incl, ...includes];
|
|
25
19
|
const _exclude = [...excl, ...excludes];
|
|
26
|
-
if (isProduction) {
|
|
20
|
+
if (options.isProduction) {
|
|
27
21
|
_exclude.push('devDependencies');
|
|
28
22
|
}
|
|
29
23
|
else {
|
|
@@ -83,7 +83,7 @@ export const getReferencedInputsHandler = (collector, deputy, chief, isGitIgnore
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
debugLog(workspace.name, `Unable to resolve ${toDebugString(input)}`);
|
|
86
|
+
debugLog(workspace.name, `Unable to resolve ${toDebugString(input, chief.cwd)}`);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
};
|
package/dist/util/glob-core.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export declare const findAndParseGitignores: (cwd: string) => Promise<{
|
|
|
14
14
|
ignores: Set<string>;
|
|
15
15
|
unignores: string[];
|
|
16
16
|
}>;
|
|
17
|
-
export declare function glob(
|
|
17
|
+
export declare function glob(_patterns: string[], options: GlobOptions): Promise<string[]>;
|
|
18
18
|
export declare function getGitIgnoredHandler(options: Options): Promise<(path: string) => boolean>;
|
|
19
19
|
export {};
|
package/dist/util/glob-core.js
CHANGED
|
@@ -5,7 +5,7 @@ import fg, {} from 'fast-glob';
|
|
|
5
5
|
import picomatch from 'picomatch';
|
|
6
6
|
import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
|
|
7
7
|
import { timerify } from './Performance.js';
|
|
8
|
-
import { compact } from './array.js';
|
|
8
|
+
import { compact, partition } from './array.js';
|
|
9
9
|
import { debugLogObject } from './debug.js';
|
|
10
10
|
import { isDirectory, isFile } from './fs.js';
|
|
11
11
|
import { parseAndConvertGitignorePatterns } from './parse-and-convert-gitignores.js';
|
|
@@ -126,13 +126,14 @@ export const findAndParseGitignores = async (cwd) => {
|
|
|
126
126
|
return { gitignoreFiles, ignores, unignores };
|
|
127
127
|
};
|
|
128
128
|
const _parseFindGitignores = timerify(findAndParseGitignores);
|
|
129
|
-
export async function glob(
|
|
130
|
-
if (Array.isArray(
|
|
129
|
+
export async function glob(_patterns, options) {
|
|
130
|
+
if (Array.isArray(_patterns) && _patterns.length === 0)
|
|
131
131
|
return [];
|
|
132
132
|
const hasCache = cachedGlobIgnores.has(options.dir);
|
|
133
133
|
const willCache = !hasCache && options.gitignore && options.label;
|
|
134
134
|
const cachedIgnores = options.gitignore ? cachedGlobIgnores.get(options.dir) : undefined;
|
|
135
|
-
const _ignore =
|
|
135
|
+
const _ignore = [];
|
|
136
|
+
const [negatedPatterns, patterns] = partition(_patterns, pattern => pattern.startsWith('!'));
|
|
136
137
|
if (options.gitignore) {
|
|
137
138
|
if (willCache) {
|
|
138
139
|
let dir = options.dir;
|
|
@@ -151,16 +152,16 @@ export async function glob(patterns, options) {
|
|
|
151
152
|
else {
|
|
152
153
|
_ignore.push(...GLOBAL_IGNORE_PATTERNS);
|
|
153
154
|
}
|
|
154
|
-
const ignore = cachedIgnores || compact(_ignore);
|
|
155
155
|
if (willCache)
|
|
156
156
|
cachedGlobIgnores.set(options.dir, compact(_ignore));
|
|
157
|
-
const
|
|
157
|
+
const ignorePatterns = (cachedIgnores || _ignore).concat(negatedPatterns);
|
|
158
|
+
const { dir, label, ...fgOptions } = { ...options, ignore: ignorePatterns };
|
|
158
159
|
const paths = await fg.glob(patterns, fgOptions);
|
|
159
160
|
const name = relative(options.cwd, dir) || ROOT_WORKSPACE_NAME;
|
|
160
161
|
debugLogObject(name, label ? `Finding ${label}` : 'Finding paths', () => ({
|
|
161
162
|
patterns,
|
|
162
163
|
...fgOptions,
|
|
163
|
-
ignore: hasCache ? `// using cache from ${name}` :
|
|
164
|
+
ignore: hasCache ? `// using cache from ${name}` : ignorePatterns,
|
|
164
165
|
paths,
|
|
165
166
|
}));
|
|
166
167
|
return paths;
|
package/dist/util/glob.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ interface GlobOptions {
|
|
|
6
6
|
name?: boolean;
|
|
7
7
|
label?: string;
|
|
8
8
|
}
|
|
9
|
+
export declare const removeProductionSuffix: (pattern: string) => string;
|
|
9
10
|
export declare const prependDirToPattern: (dir: string, pattern: string) => string;
|
|
10
11
|
export declare const negate: (pattern: string) => string;
|
|
11
12
|
export declare const hasProductionSuffix: (pattern: string) => boolean;
|
package/dist/util/glob.js
CHANGED
|
@@ -9,7 +9,7 @@ const prependDirToPatterns = (cwd, dir, patterns) => {
|
|
|
9
9
|
const relativePath = relative(cwd, dir);
|
|
10
10
|
return compact([patterns].flat().map(p => removeProductionSuffix(prepend(p, relativePath)))).sort(negatedLast);
|
|
11
11
|
};
|
|
12
|
-
const removeProductionSuffix = (pattern) => pattern.replace(/!$/, '');
|
|
12
|
+
export const removeProductionSuffix = (pattern) => pattern.replace(/!$/, '');
|
|
13
13
|
const negatedLast = (pattern) => (pattern.startsWith('!') ? 1 : -1);
|
|
14
14
|
export const prependDirToPattern = (dir, pattern) => {
|
|
15
15
|
if (pattern.startsWith('!'))
|
package/dist/util/input.d.ts
CHANGED
|
@@ -54,5 +54,5 @@ export declare const toAlias: (specifier: string, prefix: string | string[], opt
|
|
|
54
54
|
export declare const isAlias: (input: Input) => input is AliasInput;
|
|
55
55
|
export declare const toIgnore: (specifier: string, issueType: IssueType) => IgnoreInput;
|
|
56
56
|
export declare const isIgnore: (input: Input) => input is IgnoreInput;
|
|
57
|
-
export declare const toDebugString: (input: Input) => string;
|
|
57
|
+
export declare const toDebugString: (input: Input, cwd: string) => string;
|
|
58
58
|
export {};
|
package/dist/util/input.js
CHANGED
|
@@ -67,4 +67,4 @@ export const toIgnore = (specifier, issueType) => ({
|
|
|
67
67
|
issueType,
|
|
68
68
|
});
|
|
69
69
|
export const isIgnore = (input) => input.type === 'ignore';
|
|
70
|
-
export const toDebugString = (input) => `${input.type}:${isAbsolute(input.specifier) ? toRelative(input.specifier) : input.specifier}${input.containingFilePath ? ` (${toRelative(input.containingFilePath)})` : ''}`;
|
|
70
|
+
export const toDebugString = (input, cwd) => `${input.type}:${isAbsolute(input.specifier) ? toRelative(input.specifier, cwd) : input.specifier}${input.containingFilePath ? ` (${toRelative(input.containingFilePath, cwd)})` : ''}`;
|
|
@@ -5,5 +5,5 @@ type Result = {
|
|
|
5
5
|
reExportingEntryFile: undefined | string;
|
|
6
6
|
traceNode: TraceNode;
|
|
7
7
|
};
|
|
8
|
-
export declare const getIsIdentifierReferencedHandler: (graph: ModuleGraph, entryPaths: Set<string
|
|
8
|
+
export declare const getIsIdentifierReferencedHandler: (graph: ModuleGraph, entryPaths: Set<string>, isTrace: boolean) => (filePath: string, id: string, isIncludeEntryExports?: boolean, traceNode?: TraceNode, seen?: Set<string>) => Result;
|
|
9
9
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IMPORT_STAR } from '../constants.js';
|
|
2
|
-
import { addNodes, createNode
|
|
3
|
-
export const getIsIdentifierReferencedHandler = (graph, entryPaths) => {
|
|
2
|
+
import { addNodes, createNode } from './trace.js';
|
|
3
|
+
export const getIsIdentifierReferencedHandler = (graph, entryPaths, isTrace) => {
|
|
4
4
|
const isIdentifierReferenced = (filePath, id, isIncludeEntryExports = false, traceNode = createNode(filePath), seen = new Set()) => {
|
|
5
5
|
let isReferenced = false;
|
|
6
6
|
let reExportingEntryFile = entryPaths.has(filePath) ? filePath : undefined;
|
|
@@ -86,23 +86,6 @@ export const getIsIdentifierReferencedHandler = (graph, entryPaths) => {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
const reExported = file.reExported.get(identifier) ?? file.reExported.get(IMPORT_STAR);
|
|
90
|
-
if (reExported) {
|
|
91
|
-
for (const byFilePath of reExported) {
|
|
92
|
-
if (!seen.has(byFilePath)) {
|
|
93
|
-
const child = createNode(byFilePath);
|
|
94
|
-
traceNode.children.add(child);
|
|
95
|
-
const result = isIdentifierReferenced(byFilePath, id, isIncludeEntryExports, child, seen);
|
|
96
|
-
if (result.reExportingEntryFile)
|
|
97
|
-
reExportingEntryFile = result.reExportingEntryFile;
|
|
98
|
-
if (result.isReferenced) {
|
|
99
|
-
isReferenced = true;
|
|
100
|
-
if (!isTrace)
|
|
101
|
-
return { isReferenced, reExportingEntryFile, traceNode };
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
89
|
const reExportedAs = file.reExportedAs.get(identifier);
|
|
107
90
|
if (reExportedAs) {
|
|
108
91
|
for (const [alias, byFilePaths] of reExportedAs) {
|
|
@@ -123,6 +106,23 @@ export const getIsIdentifierReferencedHandler = (graph, entryPaths) => {
|
|
|
123
106
|
}
|
|
124
107
|
}
|
|
125
108
|
}
|
|
109
|
+
const reExported = file.reExported.get(identifier) ?? file.reExported.get(IMPORT_STAR);
|
|
110
|
+
if (reExported) {
|
|
111
|
+
for (const byFilePath of reExported) {
|
|
112
|
+
if (!seen.has(byFilePath)) {
|
|
113
|
+
const child = createNode(byFilePath);
|
|
114
|
+
traceNode.children.add(child);
|
|
115
|
+
const result = isIdentifierReferenced(byFilePath, id, isIncludeEntryExports, child, seen);
|
|
116
|
+
if (result.reExportingEntryFile)
|
|
117
|
+
reExportingEntryFile = result.reExportingEntryFile;
|
|
118
|
+
if (result.isReferenced) {
|
|
119
|
+
isReferenced = true;
|
|
120
|
+
if (!isTrace)
|
|
121
|
+
return { isReferenced, reExportingEntryFile, traceNode };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
126
|
for (const [namespace, byFilePaths] of file.reExportedNs.entries()) {
|
|
127
127
|
for (const byFilePath of byFilePaths) {
|
|
128
128
|
if (!seen.has(byFilePath)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadResolvedConfigFile(configPath: string): Promise<any>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { debugLogObject } from './debug.js';
|
|
2
|
+
import { ConfigurationError } from './errors.js';
|
|
3
|
+
import { _load } from './loader.js';
|
|
4
|
+
const unwrapFunction = async (maybeFunction) => {
|
|
5
|
+
if (typeof maybeFunction === 'function') {
|
|
6
|
+
try {
|
|
7
|
+
return await maybeFunction();
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
debugLogObject('*', 'Error executing function:', error);
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return maybeFunction;
|
|
15
|
+
};
|
|
16
|
+
export async function loadResolvedConfigFile(configPath) {
|
|
17
|
+
const loadedValue = await _load(configPath);
|
|
18
|
+
try {
|
|
19
|
+
return await unwrapFunction(loadedValue);
|
|
20
|
+
}
|
|
21
|
+
catch (_error) {
|
|
22
|
+
throw new ConfigurationError(`Error running the function from ${configPath}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -7,5 +7,6 @@ interface ExtendedPackageJson extends PackageJson {
|
|
|
7
7
|
}
|
|
8
8
|
export declare const load: (filePath: string) => Promise<ExtendedPackageJson>;
|
|
9
9
|
export declare const save: (filePath: string, content: ExtendedPackageJson) => Promise<void>;
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const getEntrySpecifiersFromManifest: (manifest: PackageJson) => Set<string>;
|
|
11
|
+
export declare const getManifestImportDependencies: (manifest: PackageJson) => Set<string>;
|
|
11
12
|
export {};
|
|
@@ -45,7 +45,7 @@ export const save = async (filePath, content) => {
|
|
|
45
45
|
const fileContent = `${JSON.stringify(content, null, space)}\n`.replace(/\n/g, EOL);
|
|
46
46
|
await writeFile(filePath, fileContent);
|
|
47
47
|
};
|
|
48
|
-
export const
|
|
48
|
+
export const getEntrySpecifiersFromManifest = (manifest) => {
|
|
49
49
|
const { main, module, browser, bin, exports, types, typings } = manifest;
|
|
50
50
|
const entryPaths = new Set();
|
|
51
51
|
if (typeof main === 'string')
|
|
@@ -54,13 +54,15 @@ export const getEntryPathsFromManifest = (manifest) => {
|
|
|
54
54
|
entryPaths.add(module);
|
|
55
55
|
if (typeof browser === 'string')
|
|
56
56
|
entryPaths.add(browser);
|
|
57
|
-
if (bin)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
if (typeof bin === 'string')
|
|
58
|
+
entryPaths.add(bin);
|
|
59
|
+
if (bin && typeof bin === 'object')
|
|
60
|
+
for (const id of Object.values(bin))
|
|
61
|
+
entryPaths.add(id);
|
|
62
|
+
if (typeof types === 'string')
|
|
63
|
+
entryPaths.add(types);
|
|
64
|
+
if (typeof typings === 'string')
|
|
65
|
+
entryPaths.add(typings);
|
|
64
66
|
if (exports) {
|
|
65
67
|
for (const item of getEntriesFromExports(exports)) {
|
|
66
68
|
if (item === './*')
|
|
@@ -72,9 +74,19 @@ export const getEntryPathsFromManifest = (manifest) => {
|
|
|
72
74
|
entryPaths.add(expanded);
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
|
-
if (typeof types === 'string')
|
|
76
|
-
entryPaths.add(types);
|
|
77
|
-
if (typeof typings === 'string')
|
|
78
|
-
entryPaths.add(typings);
|
|
79
77
|
return entryPaths;
|
|
80
78
|
};
|
|
79
|
+
export const getManifestImportDependencies = (manifest) => {
|
|
80
|
+
const dependencies = new Set();
|
|
81
|
+
if (!manifest.imports)
|
|
82
|
+
return dependencies;
|
|
83
|
+
for (const [entry, exportValue] of Object.entries(manifest.imports)) {
|
|
84
|
+
if (!entry.startsWith('#'))
|
|
85
|
+
continue;
|
|
86
|
+
for (const item of getEntriesFromExports(exportValue)) {
|
|
87
|
+
if (!item.startsWith('.') && !item.startsWith('!'))
|
|
88
|
+
dependencies.add(item);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return dependencies;
|
|
92
|
+
};
|
|
@@ -7,6 +7,8 @@ export const convertGitignoreToPicomatchIgnorePatterns = (pattern) => {
|
|
|
7
7
|
pattern = pattern.slice(0, -1);
|
|
8
8
|
if (pattern.startsWith('*/**/'))
|
|
9
9
|
pattern = pattern.slice(5);
|
|
10
|
+
if (pattern === '*' || pattern === '**')
|
|
11
|
+
return { negated, patterns: [pattern, pattern] };
|
|
10
12
|
if (pattern.startsWith('/'))
|
|
11
13
|
pattern = pattern.slice(1);
|
|
12
14
|
else if (!pattern.startsWith('**/'))
|
package/dist/util/path.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ export declare const extname: (path: string) => string;
|
|
|
4
4
|
export declare const basename: (path: string, suffix?: string) => string;
|
|
5
5
|
export declare const join: (...paths: string[]) => string;
|
|
6
6
|
export declare const toPosix: (value: string) => string;
|
|
7
|
-
export declare const cwd: string;
|
|
8
7
|
export declare const resolve: (...paths: string[]) => string;
|
|
9
|
-
export declare const relative: (from: string, to
|
|
8
|
+
export declare const relative: (from: string, to: string) => string;
|
|
10
9
|
export declare const isInNodeModules: (filePath: string) => boolean;
|
|
11
|
-
export declare const toAbsolute: (id: string, base
|
|
12
|
-
export declare const toRelative: (id: string) => string;
|
|
10
|
+
export declare const toAbsolute: (id: string, base: string) => string;
|
|
11
|
+
export declare const toRelative: (id: string, base: string) => string;
|
|
13
12
|
export declare const isInternal: (id: string) => boolean;
|
|
13
|
+
export declare const normalize: (path: string) => string;
|
package/dist/util/path.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import parsedArgValues from './cli-arguments.js';
|
|
3
|
-
const { directory } = parsedArgValues;
|
|
4
2
|
export const isAbsolute = path.isAbsolute;
|
|
5
3
|
export const dirname = path.posix.dirname;
|
|
6
4
|
export const extname = path.posix.extname;
|
|
7
5
|
export const basename = path.posix.basename;
|
|
8
6
|
export const join = path.posix.join;
|
|
9
7
|
export const toPosix = (value) => value.split(path.sep).join(path.posix.sep);
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
12
|
-
export const relative = (from, to) => toPosix(path.relative(to ? from : cwd, to ?? from));
|
|
8
|
+
export const resolve = path.posix.resolve;
|
|
9
|
+
export const relative = (from, to) => toPosix(path.relative(from, to));
|
|
13
10
|
export const isInNodeModules = (filePath) => filePath.includes('node_modules');
|
|
14
|
-
export const toAbsolute = (id, base
|
|
15
|
-
export const toRelative = (id) => (isAbsolute(id) ? relative(id) : id);
|
|
11
|
+
export const toAbsolute = (id, base) => (isAbsolute(id) ? id : join(base, id));
|
|
12
|
+
export const toRelative = (id, base) => (isAbsolute(id) ? relative(base, id) : id);
|
|
16
13
|
export const isInternal = (id) => (id.startsWith('.') || isAbsolute(id)) && !isInNodeModules(id);
|
|
14
|
+
export const normalize = path.posix.normalize;
|
package/dist/util/reporter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import internalReporters from '../reporters/index.js';
|
|
2
2
|
import { _load } from './loader.js';
|
|
3
|
-
import { isInternal, resolve } from './path.js';
|
|
3
|
+
import { isAbsolute, isInternal, resolve } from './path.js';
|
|
4
4
|
export const runPreprocessors = async (processors, data) => {
|
|
5
|
-
const preprocessors = await Promise.all(processors.map(proc => _load(isInternal(proc) ? resolve(proc) : proc)));
|
|
5
|
+
const preprocessors = await Promise.all(processors.map(proc => _load(isInternal(proc) && !isAbsolute(proc) ? resolve(proc) : proc)));
|
|
6
6
|
return preprocessors.length === 0
|
|
7
7
|
? Promise.resolve(data)
|
|
8
8
|
: runPreprocessors(preprocessors.slice(1), preprocessors[0](data));
|
|
@@ -11,7 +11,7 @@ export const runReporters = async (reporter, options) => {
|
|
|
11
11
|
const reporters = await Promise.all(reporter.map(async (reporter) => {
|
|
12
12
|
return reporter in internalReporters
|
|
13
13
|
? internalReporters[reporter]
|
|
14
|
-
: await _load(isInternal(reporter) ? resolve(reporter) : reporter);
|
|
14
|
+
: await _load(isInternal(reporter) && !isAbsolute(reporter) ? resolve(reporter) : reporter);
|
|
15
15
|
}));
|
|
16
16
|
for (const reporter of reporters)
|
|
17
17
|
await reporter(options);
|
package/dist/util/require.js
CHANGED
package/dist/util/table.js
CHANGED
|
@@ -55,9 +55,7 @@ export class Table {
|
|
|
55
55
|
this.rows.unshift(headerRow);
|
|
56
56
|
}
|
|
57
57
|
const columnWidths = columns.reduce((acc, col) => {
|
|
58
|
-
acc[col] = Math.max(...this.rows.map(row => row[col]?.formatted
|
|
59
|
-
? stripVTControlCharacters(row[col].formatted).length
|
|
60
|
-
: String(row[col]?.value || '').length));
|
|
58
|
+
acc[col] = Math.max(...this.rows.map(row => stripVTControlCharacters(row[col]?.formatted ?? String(row[col].value || '')).length));
|
|
61
59
|
return acc;
|
|
62
60
|
}, {});
|
|
63
61
|
const separatorWidth = (columns.length - 1) * COLUMN_SEPARATOR.length;
|
package/dist/util/tag.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Tags } from '../types/
|
|
1
|
+
import type { Tags } from '../types/options.js';
|
|
2
2
|
export declare const splitTags: (rawTags: string[]) => Tags;
|
|
3
3
|
export declare const shouldIgnore: (jsDocTags: Set<string>, tags: Tags) => boolean;
|
|
4
4
|
export declare const getShouldIgnoreHandler: (isProduction: boolean) => (jsDocTags: Set<string>) => boolean;
|
|
@@ -2,5 +2,5 @@ import type { CompilerOptions } from 'typescript';
|
|
|
2
2
|
import type { ConfigurationChief, Workspace } from '../ConfigurationChief.js';
|
|
3
3
|
export declare const augmentWorkspace: (workspace: Workspace, dir: string, compilerOptions: CompilerOptions) => void;
|
|
4
4
|
export declare const getToSourcePathHandler: (chief: ConfigurationChief) => (filePath: string) => string | undefined;
|
|
5
|
-
export declare const getToSourcePathsHandler: (chief: ConfigurationChief) => (specifiers: Set<string>,
|
|
5
|
+
export declare const getToSourcePathsHandler: (chief: ConfigurationChief) => (specifiers: Set<string>, dir: string, extensions?: string) => Promise<string[]>;
|
|
6
6
|
export type ToSourceFilePath = ReturnType<typeof getToSourcePathHandler>;
|