knip 2.33.3 → 2.33.4
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 +2 -0
- package/dist/WorkspaceWorker.js +12 -17
- package/dist/binaries/bash-parser.js +1 -1
- package/dist/index.js +17 -16
- package/dist/plugins/_template/index.js +14 -3
- package/dist/plugins/_template/types.d.ts +1 -0
- package/dist/plugins/angular/index.js +11 -11
- package/dist/plugins/ava/index.js +13 -12
- package/dist/plugins/babel/index.js +8 -5
- package/dist/plugins/capacitor/index.js +4 -2
- package/dist/plugins/changesets/index.js +7 -5
- package/dist/plugins/commitizen/index.js +4 -3
- package/dist/plugins/commitizen/types.d.ts +1 -1
- package/dist/plugins/commitlint/index.js +4 -2
- package/dist/plugins/cspell/index.js +4 -2
- package/dist/plugins/cspell/types.d.ts +1 -1
- package/dist/plugins/cypress/index.js +7 -4
- package/dist/plugins/drizzle/index.js +4 -4
- package/dist/plugins/eslint/fallback.js +6 -1
- package/dist/plugins/eslint/helpers.d.ts +2 -2
- package/dist/plugins/eslint/helpers.js +7 -7
- package/dist/plugins/eslint/index.d.ts +0 -1
- package/dist/plugins/eslint/index.js +3 -4
- package/dist/plugins/gatsby/index.js +5 -8
- package/dist/plugins/github-actions/index.d.ts +1 -1
- package/dist/plugins/github-actions/index.js +5 -4
- package/dist/plugins/husky/index.js +4 -2
- package/dist/plugins/jest/index.js +8 -8
- package/dist/plugins/jest/types.d.ts +3 -0
- package/dist/plugins/jest/types.js +1 -0
- package/dist/plugins/lefthook/index.js +5 -4
- package/dist/plugins/lint-staged/index.js +7 -7
- package/dist/plugins/markdownlint/index.js +5 -4
- package/dist/plugins/mocha/index.js +8 -7
- package/dist/plugins/mocha/types.d.ts +4 -0
- package/dist/plugins/mocha/types.js +1 -0
- package/dist/plugins/npm-package-json-lint/index.js +4 -3
- package/dist/plugins/nx/index.js +5 -4
- package/dist/plugins/nyc/index.js +4 -3
- package/dist/plugins/nyc/types.d.ts +3 -0
- package/dist/plugins/nyc/types.js +1 -0
- package/dist/plugins/playwright/index.d.ts +1 -1
- package/dist/plugins/playwright/index.js +7 -6
- package/dist/plugins/playwright-ct/index.js +11 -6
- package/dist/plugins/postcss/index.js +6 -5
- package/dist/plugins/prettier/index.js +3 -3
- package/dist/plugins/prettier/types.d.ts +8 -0
- package/dist/plugins/prettier/types.js +1 -0
- package/dist/plugins/release-it/index.js +10 -9
- package/dist/plugins/remark/index.js +6 -5
- package/dist/plugins/remix/index.js +1 -5
- package/dist/plugins/rollup/index.js +1 -1
- package/dist/plugins/semantic-release/index.js +5 -4
- package/dist/plugins/semantic-release/types.d.ts +1 -1
- package/dist/plugins/storybook/index.js +13 -11
- package/dist/plugins/stryker/index.js +9 -6
- package/dist/plugins/stylelint/index.js +6 -5
- package/dist/plugins/typedoc/index.js +4 -3
- package/dist/plugins/typedoc/types.d.ts +1 -1
- package/dist/plugins/typescript/index.js +13 -10
- package/dist/plugins/vite/index.js +4 -2
- package/dist/plugins/vitest/index.d.ts +1 -1
- package/dist/plugins/vitest/index.js +8 -8
- package/dist/plugins/webpack/index.js +25 -15
- package/dist/plugins/webpack/types.d.ts +2 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/plugins.d.ts +1 -1
- package/dist/typescript/SourceFileManager.js +3 -3
- package/dist/util/debug.d.ts +3 -3
- package/dist/util/debug.js +10 -8
- package/dist/util/glob.js +1 -1
- package/dist/util/path.js +1 -1
- package/dist/util/plugin.js +7 -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/README.md
CHANGED
|
@@ -87,6 +87,8 @@ npm install -D knip
|
|
|
87
87
|
|
|
88
88
|
Knip supports LTS versions of Node.js, and currently requires at least Node.js v16.17 or v18.6.
|
|
89
89
|
|
|
90
|
+
Since v2.33.0, the Bun runtime is also supported.
|
|
91
|
+
|
|
90
92
|
### Default Configuration
|
|
91
93
|
|
|
92
94
|
Knip has good defaults and aims for no or little configuration. The (simplified) default config:
|
package/dist/WorkspaceWorker.js
CHANGED
|
@@ -64,7 +64,7 @@ export class WorkspaceWorker {
|
|
|
64
64
|
}
|
|
65
65
|
this.enabledPlugins = getKeysByValue(this.enabled, true);
|
|
66
66
|
const enabledPluginNames = this.enabledPlugins.map(name => plugins[name].NAME);
|
|
67
|
-
debugLogObject(`Enabled plugins (${this.name})`, enabledPluginNames);
|
|
67
|
+
debugLogObject(this.name, `Enabled plugins (${this.name})`, enabledPluginNames);
|
|
68
68
|
}
|
|
69
69
|
async initReferencedDependencies() {
|
|
70
70
|
const { dependencies, hostDependencies, installedBinaries, hasTypesIncluded } = await npm.findDependencies({
|
|
@@ -82,7 +82,8 @@ export class WorkspaceWorker {
|
|
|
82
82
|
this.hasTypesIncluded = hasTypesIncluded;
|
|
83
83
|
}
|
|
84
84
|
getConfigForPlugin(pluginName) {
|
|
85
|
-
|
|
85
|
+
const config = this.config[pluginName];
|
|
86
|
+
return typeof config === 'undefined' || typeof config === 'boolean' ? nullConfig : config;
|
|
86
87
|
}
|
|
87
88
|
getEntryFilePatterns() {
|
|
88
89
|
const { entry } = this.config;
|
|
@@ -108,8 +109,8 @@ export class WorkspaceWorker {
|
|
|
108
109
|
const patterns = [];
|
|
109
110
|
for (const [pluginName, plugin] of Object.entries(plugins)) {
|
|
110
111
|
const pluginConfig = this.getConfigForPlugin(pluginName);
|
|
111
|
-
if (this.enabled[pluginName]
|
|
112
|
-
const { entry, project } = pluginConfig
|
|
112
|
+
if (this.enabled[pluginName]) {
|
|
113
|
+
const { entry, project } = pluginConfig;
|
|
113
114
|
patterns.push(...(project ?? entry ?? ('PROJECT_FILE_PATTERNS' in plugin ? plugin.PROJECT_FILE_PATTERNS : [])));
|
|
114
115
|
}
|
|
115
116
|
}
|
|
@@ -120,7 +121,7 @@ export class WorkspaceWorker {
|
|
|
120
121
|
for (const [pluginName, plugin] of Object.entries(plugins)) {
|
|
121
122
|
const pluginConfig = this.getConfigForPlugin(pluginName);
|
|
122
123
|
if (this.enabled[pluginName] && pluginConfig) {
|
|
123
|
-
const { config } = pluginConfig
|
|
124
|
+
const { config } = pluginConfig;
|
|
124
125
|
const defaultConfigFiles = 'CONFIG_FILE_PATTERNS' in plugin ? plugin.CONFIG_FILE_PATTERNS : [];
|
|
125
126
|
patterns.push(...(config ?? defaultConfigFiles));
|
|
126
127
|
}
|
|
@@ -160,7 +161,7 @@ export class WorkspaceWorker {
|
|
|
160
161
|
const pluginConfig = this.getConfigForPlugin(pluginName);
|
|
161
162
|
if (pluginConfig) {
|
|
162
163
|
const defaultConfig = 'CONFIG_FILE_PATTERNS' in plugin ? plugin.CONFIG_FILE_PATTERNS : [];
|
|
163
|
-
return
|
|
164
|
+
return pluginConfig.config ?? defaultConfig;
|
|
164
165
|
}
|
|
165
166
|
return [];
|
|
166
167
|
}
|
|
@@ -168,6 +169,7 @@ export class WorkspaceWorker {
|
|
|
168
169
|
return [...this.rootIgnore, ...this.config.ignore.map(pattern => prependDirToPattern(this.name, pattern))];
|
|
169
170
|
}
|
|
170
171
|
async findDependenciesByPlugins() {
|
|
172
|
+
const name = this.name;
|
|
171
173
|
const cwd = this.dir;
|
|
172
174
|
const ignore = this.getIgnorePatterns();
|
|
173
175
|
for (const [pluginName, plugin] of Object.entries(plugins)) {
|
|
@@ -181,22 +183,15 @@ export class WorkspaceWorker {
|
|
|
181
183
|
const allConfigFilePaths = await _pureGlob({ patterns, cwd, ignore, gitignore: false });
|
|
182
184
|
const configFilePaths = allConfigFilePaths.filter(filePath => !filePath.endsWith('package.json') ||
|
|
183
185
|
get(this.manifest, 'PACKAGE_JSON_PATH' in plugin ? plugin.PACKAGE_JSON_PATH : pluginName));
|
|
184
|
-
debugLogArray(
|
|
185
|
-
if (
|
|
186
|
-
if (typeof pluginConfig !== 'boolean' && pluginConfig.entry !== null && pluginConfig.entry.length > 0) {
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (patterns.length === 0)
|
|
186
|
+
debugLogArray([name, plugin.NAME], 'config file paths', configFilePaths);
|
|
187
|
+
if (configFilePaths.length === 0)
|
|
193
188
|
configFilePaths.push(FAKE_PATH);
|
|
194
189
|
const pluginDependencies = new Set();
|
|
195
190
|
for (const configFilePath of configFilePaths) {
|
|
196
191
|
const dependencies = await plugin.findDependencies(configFilePath, {
|
|
197
192
|
cwd,
|
|
198
193
|
manifest: this.manifest,
|
|
199
|
-
config: pluginConfig
|
|
194
|
+
config: pluginConfig,
|
|
200
195
|
isProduction: this.isProduction,
|
|
201
196
|
});
|
|
202
197
|
dependencies.forEach(specifier => {
|
|
@@ -212,7 +207,7 @@ export class WorkspaceWorker {
|
|
|
212
207
|
}
|
|
213
208
|
});
|
|
214
209
|
}
|
|
215
|
-
debugLogArray(
|
|
210
|
+
debugLogArray([name, plugin.NAME], 'dependencies', pluginDependencies);
|
|
216
211
|
}
|
|
217
212
|
}
|
|
218
213
|
}
|
|
@@ -52,7 +52,7 @@ export const getBinariesFromScript = (script, { cwd, manifest, knownGlobalsOnly
|
|
|
52
52
|
return parsed?.commands ? getBinariesFromNodes(parsed.commands) : [];
|
|
53
53
|
}
|
|
54
54
|
catch (error) {
|
|
55
|
-
debugLogObject('Bash parser error', error);
|
|
55
|
+
debugLogObject('*', 'Bash parser error', error);
|
|
56
56
|
return [];
|
|
57
57
|
}
|
|
58
58
|
};
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { loadTSConfig } from './util/tsconfig-loader.js';
|
|
|
17
17
|
import { WorkspaceWorker } from './WorkspaceWorker.js';
|
|
18
18
|
export const main = async (unresolvedConfiguration) => {
|
|
19
19
|
const { cwd, tsConfigFile, gitignore, isStrict, isProduction, isIgnoreInternal, isShowProgress, isIncludeEntryExports, } = unresolvedConfiguration;
|
|
20
|
-
debugLogObject('Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
|
|
20
|
+
debugLogObject('*', 'Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
|
|
21
21
|
const chief = new ConfigurationChief({ cwd, isProduction });
|
|
22
22
|
const deputy = new DependencyDeputy({ isStrict });
|
|
23
23
|
const factory = new PrincipalFactory();
|
|
@@ -35,8 +35,9 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
35
35
|
const collector = new IssueCollector({ cwd, rules, filters });
|
|
36
36
|
const enabledPluginsStore = new Map();
|
|
37
37
|
deputy.addIgnored(chief.config.ignoreBinaries, chief.config.ignoreDependencies);
|
|
38
|
-
|
|
39
|
-
debugLogObject('Included
|
|
38
|
+
const o = () => workspaces.map(w => ({ pkgName: w.pkgName, name: w.name, config: w.config, ancestors: w.ancestors }));
|
|
39
|
+
debugLogObject('*', 'Included workspaces', () => workspaces.map(w => w.pkgName));
|
|
40
|
+
debugLogObject('*', 'Included workspace configs', o);
|
|
40
41
|
const handleReferencedDependency = ({ specifier, containingFilePath, principal, workspace, }) => {
|
|
41
42
|
if (isInternal(specifier)) {
|
|
42
43
|
const filePath = principal.resolveModule(specifier, containingFilePath)?.resolvedFileName;
|
|
@@ -82,7 +83,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
82
83
|
for (const workspace of workspaces) {
|
|
83
84
|
const { name, dir, config, ancestors, pkgName, manifestPath, manifest } = workspace;
|
|
84
85
|
const { paths, ignoreDependencies, ignoreBinaries } = config;
|
|
85
|
-
streamer.cast(`Analyzing workspace
|
|
86
|
+
streamer.cast(`Analyzing workspace ${name}...`);
|
|
86
87
|
deputy.addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries });
|
|
87
88
|
const { compilerOptions, definitionPaths } = await loadTSConfig(join(dir, tsConfigFile ?? 'tsconfig.json'));
|
|
88
89
|
const principal = factory.getPrincipal({ cwd: dir, paths, compilerOptions, compilers, pkgName });
|
|
@@ -100,10 +101,10 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
100
101
|
});
|
|
101
102
|
await worker.init();
|
|
102
103
|
principal.addEntryPaths(definitionPaths);
|
|
103
|
-
debugLogArray(`
|
|
104
|
+
debugLogArray(name, `Definition paths`, definitionPaths);
|
|
104
105
|
const sharedGlobOptions = { cwd, workingDir: dir, gitignore, ignore: worker.getIgnorePatterns() };
|
|
105
106
|
const entryPathsFromManifest = await getEntryPathFromManifest(cwd, dir, manifest);
|
|
106
|
-
debugLogArray(
|
|
107
|
+
debugLogArray(name, 'Entry paths in package.json', entryPathsFromManifest);
|
|
107
108
|
principal.addEntryPaths(entryPathsFromManifest);
|
|
108
109
|
const dependencies = await worker.findAllDependencies();
|
|
109
110
|
const { referencedDependencies, hostDependencies, installedBinaries, hasTypesIncluded, enabledPlugins, entryFilePatterns, productionEntryFilePatterns, } = dependencies;
|
|
@@ -119,18 +120,18 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
119
120
|
{
|
|
120
121
|
const patterns = worker.getProductionEntryFilePatterns(negatedEntryPatterns);
|
|
121
122
|
const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
|
|
122
|
-
debugLogArray(`
|
|
123
|
+
debugLogArray(name, `Entry paths`, workspaceEntryPaths);
|
|
123
124
|
principal.addEntryPaths(workspaceEntryPaths);
|
|
124
125
|
}
|
|
125
126
|
{
|
|
126
127
|
const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns: productionEntryFilePatterns });
|
|
127
|
-
debugLogArray(`
|
|
128
|
+
debugLogArray(name, `Production plugin entry paths`, pluginWorkspaceEntryPaths);
|
|
128
129
|
principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
|
|
129
130
|
}
|
|
130
131
|
{
|
|
131
132
|
const patterns = worker.getProductionProjectFilePatterns(negatedEntryPatterns);
|
|
132
133
|
const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
|
|
133
|
-
debugLogArray(`
|
|
134
|
+
debugLogArray(name, `Project paths`, workspaceProjectPaths);
|
|
134
135
|
workspaceProjectPaths.forEach(projectPath => principal.addProjectPath(projectPath));
|
|
135
136
|
}
|
|
136
137
|
}
|
|
@@ -138,31 +139,31 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
138
139
|
{
|
|
139
140
|
const patterns = worker.getEntryFilePatterns();
|
|
140
141
|
const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
|
|
141
|
-
debugLogArray(`
|
|
142
|
+
debugLogArray(name, `Entry paths`, workspaceEntryPaths);
|
|
142
143
|
principal.addEntryPaths(workspaceEntryPaths);
|
|
143
144
|
}
|
|
144
145
|
{
|
|
145
146
|
const patterns = worker.getProjectFilePatterns([...productionEntryFilePatterns]);
|
|
146
147
|
const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
|
|
147
|
-
debugLogArray(`
|
|
148
|
+
debugLogArray(name, `Project paths`, workspaceProjectPaths);
|
|
148
149
|
workspaceProjectPaths.forEach(projectPath => principal.addProjectPath(projectPath));
|
|
149
150
|
}
|
|
150
151
|
{
|
|
151
152
|
const patterns = [...entryFilePatterns, ...productionEntryFilePatterns];
|
|
152
153
|
const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
|
|
153
|
-
debugLogArray(`
|
|
154
|
+
debugLogArray(name, `Plugin entry paths`, pluginWorkspaceEntryPaths);
|
|
154
155
|
principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
|
|
155
156
|
}
|
|
156
157
|
{
|
|
157
158
|
const patterns = worker.getPluginProjectFilePatterns();
|
|
158
159
|
const pluginWorkspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
|
|
159
|
-
debugLogArray(`
|
|
160
|
+
debugLogArray(name, `Plugin project paths`, pluginWorkspaceProjectPaths);
|
|
160
161
|
pluginWorkspaceProjectPaths.forEach(projectPath => principal.addProjectPath(projectPath));
|
|
161
162
|
}
|
|
162
163
|
{
|
|
163
164
|
const patterns = compact(worker.getPluginConfigPatterns());
|
|
164
165
|
const configurationEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
|
|
165
|
-
debugLogArray(`
|
|
166
|
+
debugLogArray(name, `Plugin configuration paths`, configurationEntryPaths);
|
|
166
167
|
principal.addEntryPaths(configurationEntryPaths, { skipExportsAnalysis: true });
|
|
167
168
|
}
|
|
168
169
|
}
|
|
@@ -171,7 +172,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
const principals = factory.getPrincipals();
|
|
174
|
-
debugLog(`Installed ${principals.length} principals for ${workspaces.length} workspaces`);
|
|
175
|
+
debugLog('*', `Installed ${principals.length} principals for ${workspaces.length} workspaces`);
|
|
175
176
|
const analyzedFiles = new Set();
|
|
176
177
|
const exportedSymbols = new Map();
|
|
177
178
|
const importedSymbols = new Map();
|
|
@@ -244,7 +245,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
244
245
|
size = principal.entryPaths.size;
|
|
245
246
|
const resolvedFiles = principal.getUsedResolvedFiles();
|
|
246
247
|
const files = resolvedFiles.filter(filePath => !analyzedFiles.has(filePath));
|
|
247
|
-
debugLogArray(`Analyzing used resolved files [P${principals.indexOf(principal) + 1}/${++round}]`, files);
|
|
248
|
+
debugLogArray('*', `Analyzing used resolved files [P${principals.indexOf(principal) + 1}/${++round}]`, files);
|
|
248
249
|
files.forEach(filePath => {
|
|
249
250
|
analyzeSourceFile(filePath);
|
|
250
251
|
analyzedFiles.add(filePath);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { timerify } from '../../util/Performance.js';
|
|
2
2
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
|
+
import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
|
|
3
4
|
export const NAME = '';
|
|
4
5
|
export const ENABLERS = [''];
|
|
5
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
@@ -7,8 +8,18 @@ export const CONFIG_FILE_PATTERNS = [];
|
|
|
7
8
|
export const ENTRY_FILE_PATTERNS = [];
|
|
8
9
|
export const PRODUCTION_ENTRY_FILE_PATTERNS = [];
|
|
9
10
|
export const PROJECT_FILE_PATTERNS = [];
|
|
10
|
-
const findPluginDependencies = async (configFilePath,
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const findPluginDependencies = async (configFilePath, options) => {
|
|
12
|
+
const { manifest, config, isProduction } = options;
|
|
13
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
14
|
+
? manifest.plugin
|
|
15
|
+
: await load(configFilePath);
|
|
16
|
+
if (!localConfig)
|
|
17
|
+
return [];
|
|
18
|
+
const entryPatterns = (config?.entry ?? localConfig.entryPathsOrPatterns ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
|
|
19
|
+
const productionPatterns = config.entry ? [] : PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
|
|
20
|
+
if (isProduction)
|
|
21
|
+
return [...entryPatterns, ...productionPatterns];
|
|
22
|
+
const dependencies = localConfig?.plugins ?? [];
|
|
23
|
+
return [...dependencies, ...entryPatterns, ...productionPatterns];
|
|
13
24
|
};
|
|
14
25
|
export const findDependencies = timerify(findPluginDependencies);
|
|
@@ -6,26 +6,26 @@ export const NAME = 'Angular';
|
|
|
6
6
|
export const ENABLERS = ['@angular/cli'];
|
|
7
7
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
8
8
|
export const CONFIG_FILE_PATTERNS = ['angular.json'];
|
|
9
|
-
const findPluginDependencies = async (configFilePath,
|
|
10
|
-
const { cwd } =
|
|
11
|
-
const
|
|
12
|
-
if (!
|
|
9
|
+
const findPluginDependencies = async (configFilePath, options) => {
|
|
10
|
+
const { cwd } = options;
|
|
11
|
+
const localConfig = await load(configFilePath);
|
|
12
|
+
if (!localConfig?.projects)
|
|
13
13
|
return [];
|
|
14
14
|
const dependencies = new Set();
|
|
15
|
-
for (const project of Object.values(
|
|
15
|
+
for (const project of Object.values(localConfig.projects)) {
|
|
16
16
|
if (!project.architect)
|
|
17
17
|
return [];
|
|
18
18
|
for (const target of Object.values(project.architect)) {
|
|
19
|
-
const { options } = target;
|
|
19
|
+
const { options: opts } = target;
|
|
20
20
|
const [packageName] = typeof target.builder === 'string' ? target.builder.split(':') : [];
|
|
21
21
|
if (typeof packageName === 'string')
|
|
22
22
|
dependencies.add(packageName);
|
|
23
|
-
if (
|
|
24
|
-
if ('main' in
|
|
25
|
-
dependencies.add(join(cwd,
|
|
23
|
+
if (opts) {
|
|
24
|
+
if ('main' in opts && typeof opts.main === 'string') {
|
|
25
|
+
dependencies.add(join(cwd, opts.main));
|
|
26
26
|
}
|
|
27
|
-
if ('tsConfig' in
|
|
28
|
-
const tsConfigDependencies = await findTypeScriptDependencies(join(cwd,
|
|
27
|
+
if ('tsConfig' in opts && typeof opts.tsConfig === 'string') {
|
|
28
|
+
const tsConfigDependencies = await findTypeScriptDependencies(join(cwd, opts.tsConfig), options);
|
|
29
29
|
tsConfigDependencies.forEach(dependency => dependencies.add(dependency));
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -18,19 +18,20 @@ export const ENTRY_FILE_PATTERNS = [
|
|
|
18
18
|
'!**/__tests__/**/__{helper,fixture}?(s)__/**/*',
|
|
19
19
|
'!**/test?(s)/**/{helper,fixture}?(s)/**/*',
|
|
20
20
|
];
|
|
21
|
-
const findAvaDependencies = async (configFilePath,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
21
|
+
const findAvaDependencies = async (configFilePath, options) => {
|
|
22
|
+
const { cwd, manifest, isProduction, config } = options;
|
|
23
|
+
let localConfig = configFilePath.endsWith('package.json')
|
|
24
|
+
? manifest.ava
|
|
25
|
+
: await load(configFilePath);
|
|
26
|
+
if (typeof localConfig === 'function')
|
|
27
|
+
localConfig = localConfig();
|
|
28
|
+
const entryPatterns = (config.entry ?? localConfig?.files ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
|
|
29
|
+
if (isProduction || !localConfig)
|
|
27
30
|
return entryPatterns;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const cmd = `node ${otherArgs.join(' ')} ${requireArgs.join(' ')}`;
|
|
33
|
-
const dependencies = _getDependenciesFromScripts([cmd], {
|
|
31
|
+
const nodeArgs = localConfig.nodeArguments ?? [];
|
|
32
|
+
const requireArgs = (localConfig.require ?? []).map(require => `--require ${require}`);
|
|
33
|
+
const fakeCommand = `node ${nodeArgs.join(' ')} ${requireArgs.join(' ')}`;
|
|
34
|
+
const dependencies = _getDependenciesFromScripts([fakeCommand], {
|
|
34
35
|
cwd,
|
|
35
36
|
manifest,
|
|
36
37
|
knownGlobalsOnly: true,
|
|
@@ -23,10 +23,13 @@ export const getDependenciesFromConfig = (config) => {
|
|
|
23
23
|
const findBabelDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
24
24
|
if (isProduction)
|
|
25
25
|
return [];
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
let localConfig = configFilePath.endsWith('package.json')
|
|
27
|
+
? manifest.babel
|
|
28
|
+
: await load(configFilePath);
|
|
29
|
+
if (typeof localConfig === 'function')
|
|
30
|
+
localConfig = localConfig(api);
|
|
31
|
+
if (!localConfig)
|
|
32
|
+
return [];
|
|
33
|
+
return getDependenciesFromConfig(localConfig);
|
|
31
34
|
};
|
|
32
35
|
export const findDependencies = timerify(findBabelDependencies);
|
|
@@ -7,7 +7,9 @@ export const CONFIG_FILE_PATTERNS = ['capacitor.config.ts'];
|
|
|
7
7
|
const findCapacitorDependencies = async (configFilePath, { isProduction }) => {
|
|
8
8
|
if (isProduction)
|
|
9
9
|
return [];
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const localConfig = await load(configFilePath);
|
|
11
|
+
if (!localConfig)
|
|
12
|
+
return [];
|
|
13
|
+
return localConfig.includePlugins ?? [];
|
|
12
14
|
};
|
|
13
15
|
export const findDependencies = timerify(findCapacitorDependencies);
|
|
@@ -7,11 +7,13 @@ export const CONFIG_FILE_PATTERNS = ['.changeset/config.json'];
|
|
|
7
7
|
const findChangesetsDependencies = async (configFilePath, { isProduction }) => {
|
|
8
8
|
if (isProduction)
|
|
9
9
|
return [];
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const localConfig = await load(configFilePath);
|
|
11
|
+
if (!localConfig)
|
|
12
|
+
return [];
|
|
13
|
+
return Array.isArray(localConfig.changelog)
|
|
14
|
+
? [localConfig.changelog[0]]
|
|
15
|
+
: typeof localConfig.changelog === 'string'
|
|
16
|
+
? [localConfig.changelog]
|
|
15
17
|
: [];
|
|
16
18
|
};
|
|
17
19
|
export const findDependencies = timerify(findChangesetsDependencies);
|
|
@@ -8,10 +8,11 @@ export const CONFIG_FILE_PATTERNS = ['.czrc', '.cz.json', 'package.json'];
|
|
|
8
8
|
const findPluginDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
9
9
|
if (isProduction)
|
|
10
10
|
return [];
|
|
11
|
-
const
|
|
11
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
12
12
|
? manifest.config?.commitizen
|
|
13
13
|
: await load(configFilePath);
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (!localConfig)
|
|
15
|
+
return [];
|
|
16
|
+
return localConfig.path ? [localConfig.path] : [];
|
|
16
17
|
};
|
|
17
18
|
export const findDependencies = timerify(findPluginDependencies);
|
|
@@ -12,9 +12,11 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
12
12
|
const findCommitLintDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
13
13
|
if (isProduction)
|
|
14
14
|
return [];
|
|
15
|
-
const
|
|
15
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
16
16
|
? manifest.commitlint
|
|
17
17
|
: await load(configFilePath);
|
|
18
|
-
|
|
18
|
+
if (!localConfig)
|
|
19
|
+
return [];
|
|
20
|
+
return localConfig.extends ? [localConfig.extends].flat() : [];
|
|
19
21
|
};
|
|
20
22
|
export const findDependencies = timerify(findCommitLintDependencies);
|
|
@@ -12,8 +12,10 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
12
12
|
const findCspellDependencies = async (configFilePath, { isProduction }) => {
|
|
13
13
|
if (isProduction)
|
|
14
14
|
return [];
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
const localConfig = await load(configFilePath);
|
|
16
|
+
if (!localConfig)
|
|
17
|
+
return [];
|
|
18
|
+
const imports = localConfig.import ?? [];
|
|
17
19
|
return imports;
|
|
18
20
|
};
|
|
19
21
|
export const findDependencies = timerify(findCspellDependencies);
|
|
@@ -10,11 +10,14 @@ const SUPPORT_FILE_PATTERNS = [
|
|
|
10
10
|
'cypress/plugins/index.js',
|
|
11
11
|
];
|
|
12
12
|
export const ENTRY_FILE_PATTERNS = [...TEST_FILE_PATTERNS, ...SUPPORT_FILE_PATTERNS];
|
|
13
|
-
export const findDependencies = async (configFilePath) => {
|
|
14
|
-
const config =
|
|
15
|
-
|
|
13
|
+
export const findDependencies = async (configFilePath, options) => {
|
|
14
|
+
const { config } = options;
|
|
15
|
+
const localConfig = await load(configFilePath);
|
|
16
|
+
if (!localConfig)
|
|
16
17
|
return [];
|
|
17
|
-
|
|
18
|
+
if (config.entry)
|
|
19
|
+
return config.entry.map(toEntryPattern);
|
|
20
|
+
const patterns = [localConfig.e2e?.specPattern ?? [], localConfig.component?.specPattern ?? []].flat();
|
|
18
21
|
const entryPatterns = (patterns.length > 0 ? patterns : TEST_FILE_PATTERNS).map(toEntryPattern);
|
|
19
22
|
return [...entryPatterns, ...SUPPORT_FILE_PATTERNS.map(toEntryPattern)];
|
|
20
23
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { timerify } from '../../util/Performance.js';
|
|
2
2
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
|
-
import {
|
|
3
|
+
import { toProductionEntryPattern } from '../../util/protocols.js';
|
|
4
4
|
export const NAME = 'Drizzle';
|
|
5
5
|
export const ENABLERS = ['drizzle-kit'];
|
|
6
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
7
7
|
export const CONFIG_FILE_PATTERNS = ['drizzle.config.{ts,js,json}'];
|
|
8
8
|
const findDrizzleDependencies = async (configFilePath) => {
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
9
|
+
const localConfig = await load(configFilePath);
|
|
10
|
+
if (!localConfig?.schema)
|
|
11
11
|
return [];
|
|
12
|
-
return [
|
|
12
|
+
return [localConfig.schema].flat().map(toProductionEntryPattern);
|
|
13
13
|
};
|
|
14
14
|
export const findDependencies = timerify(findDrizzleDependencies);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import createJITI from 'jiti';
|
|
2
2
|
import transform from 'jiti/dist/babel.js';
|
|
3
|
+
import { FAKE_PATH } from '../../util/loader.js';
|
|
3
4
|
import { timerify } from '../../util/Performance.js';
|
|
4
5
|
const rushstackMatch = /require\(("|')@rushstack\/(eslint-config\/patch|eslint-patch)\/modern-module-resolution("|')\)/;
|
|
5
6
|
const jiti = createJITI(process.cwd(), {
|
|
@@ -9,5 +10,9 @@ const jiti = createJITI(process.cwd(), {
|
|
|
9
10
|
return transform(opts);
|
|
10
11
|
},
|
|
11
12
|
});
|
|
12
|
-
const load = (configFilePath) =>
|
|
13
|
+
const load = (configFilePath) => {
|
|
14
|
+
if (configFilePath === FAKE_PATH)
|
|
15
|
+
return;
|
|
16
|
+
return jiti(configFilePath);
|
|
17
|
+
};
|
|
13
18
|
export const fallback = timerify(load);
|
|
@@ -4,10 +4,10 @@ import type { PackageJson } from '@npmcli/package-json';
|
|
|
4
4
|
type Manifest = PackageJson & {
|
|
5
5
|
eslintConfig?: ESLintConfig;
|
|
6
6
|
};
|
|
7
|
-
type GetDependenciesDeep = (configFilePath: string,
|
|
7
|
+
type GetDependenciesDeep = (configFilePath: string, options: {
|
|
8
8
|
cwd: string;
|
|
9
9
|
manifest: Manifest;
|
|
10
|
-
}) => Promise<Set<string>>;
|
|
10
|
+
}, dependencies?: Set<string>) => Promise<Set<string>>;
|
|
11
11
|
export declare const getDependenciesDeep: GetDependenciesDeep;
|
|
12
12
|
export declare const resolvePluginSpecifier: (specifier: string) => string;
|
|
13
13
|
export declare const resolveExtendSpecifier: (specifier: string) => string | undefined;
|
|
@@ -24,25 +24,25 @@ const getDependencies = (config) => {
|
|
|
24
24
|
...overrides,
|
|
25
25
|
]);
|
|
26
26
|
};
|
|
27
|
-
export const getDependenciesDeep = async (configFilePath, dependencies = new Set()
|
|
27
|
+
export const getDependenciesDeep = async (configFilePath, options, dependencies = new Set()) => {
|
|
28
28
|
const addAll = (deps) => deps.forEach(dependency => dependencies.add(dependency));
|
|
29
|
-
const
|
|
29
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
30
30
|
? options.manifest[PACKAGE_JSON_PATH]
|
|
31
31
|
: /(\.(jsonc?|ya?ml)|rc)$/.test(configFilePath)
|
|
32
32
|
? await load(configFilePath)
|
|
33
33
|
: await fallback(configFilePath);
|
|
34
|
-
if (
|
|
35
|
-
if (
|
|
36
|
-
for (const extend of [
|
|
34
|
+
if (localConfig) {
|
|
35
|
+
if (localConfig.extends) {
|
|
36
|
+
for (const extend of [localConfig.extends].flat()) {
|
|
37
37
|
if (isInternal(extend)) {
|
|
38
38
|
const filePath = toAbsolute(extend, dirname(configFilePath));
|
|
39
39
|
const extendConfigFilePath = _resolve(filePath);
|
|
40
40
|
dependencies.add(extendConfigFilePath);
|
|
41
|
-
addAll(await getDependenciesDeep(extendConfigFilePath,
|
|
41
|
+
addAll(await getDependenciesDeep(extendConfigFilePath, options, dependencies));
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
addAll(getDependencies(
|
|
45
|
+
addAll(getDependencies(localConfig));
|
|
46
46
|
}
|
|
47
47
|
return dependencies;
|
|
48
48
|
};
|
|
@@ -4,5 +4,4 @@ export declare const ENABLERS: string[];
|
|
|
4
4
|
export declare const PACKAGE_JSON_PATH = "eslintConfig";
|
|
5
5
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
6
6
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
7
|
-
export declare const ENTRY_FILE_PATTERNS: never[];
|
|
8
7
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -14,13 +14,12 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
14
14
|
'.eslintrc.{yml,yaml}',
|
|
15
15
|
'package.json',
|
|
16
16
|
];
|
|
17
|
-
export const ENTRY_FILE_PATTERNS = [];
|
|
18
17
|
const findESLintDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
|
|
19
|
-
if (configFilePath.endsWith('eslint.config.js'))
|
|
20
|
-
return [];
|
|
21
18
|
if (isProduction)
|
|
22
19
|
return [];
|
|
23
|
-
|
|
20
|
+
if (configFilePath.endsWith('eslint.config.js'))
|
|
21
|
+
return [];
|
|
22
|
+
const dependencies = await getDependenciesDeep(configFilePath, { cwd, manifest });
|
|
24
23
|
return Array.from(dependencies);
|
|
25
24
|
};
|
|
26
25
|
export const findDependencies = timerify(findESLintDependencies);
|
|
@@ -4,10 +4,7 @@ import { toProductionEntryPattern } from '../../util/protocols.js';
|
|
|
4
4
|
export const NAME = 'Gatsby';
|
|
5
5
|
export const ENABLERS = ['gatsby', 'gatsby-cli'];
|
|
6
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
7
|
-
export const CONFIG_FILE_PATTERNS = [
|
|
8
|
-
'gatsby-{config,node}.{js,jsx,ts,tsx}',
|
|
9
|
-
'plugins/**/gatsby-node.{js,jsx,ts,tsx}',
|
|
10
|
-
];
|
|
7
|
+
export const CONFIG_FILE_PATTERNS = ['gatsby-{config,node}.{js,jsx,ts,tsx}', 'plugins/**/gatsby-node.{js,jsx,ts,tsx}'];
|
|
11
8
|
export const PRODUCTION_ENTRY_FILE_PATTERNS = [
|
|
12
9
|
'gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
|
|
13
10
|
'src/api/**/*.{js,ts}',
|
|
@@ -17,17 +14,17 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
|
|
|
17
14
|
'plugins/**/gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
|
|
18
15
|
];
|
|
19
16
|
const findGatsbyDependencies = async (configFilePath, { isProduction }) => {
|
|
20
|
-
const
|
|
17
|
+
const localConfig = await load(configFilePath);
|
|
21
18
|
const entryPatterns = PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
|
|
22
|
-
if (isProduction)
|
|
19
|
+
if (isProduction || !localConfig)
|
|
23
20
|
return entryPatterns;
|
|
24
21
|
if (/gatsby-config/.test(configFilePath)) {
|
|
25
|
-
return
|
|
22
|
+
return localConfig.plugins.map(plugin => (typeof plugin === 'string' ? plugin : plugin.resolve));
|
|
26
23
|
}
|
|
27
24
|
if (/gatsby-node/.test(configFilePath)) {
|
|
28
25
|
const plugins = new Set();
|
|
29
26
|
const actions = { setBabelPlugin: plugin => plugins.add(plugin.name) };
|
|
30
|
-
const _config =
|
|
27
|
+
const _config = localConfig;
|
|
31
28
|
if (typeof _config.onCreateBabelConfig === 'function') {
|
|
32
29
|
_config.onCreateBabelConfig({ actions });
|
|
33
30
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
|
|
2
2
|
export declare const NAME = "GitHub Actions";
|
|
3
|
-
export declare const ENABLERS = "This plugin is enabled when a `.yml` file is found in the `.github/workflows` folder.";
|
|
3
|
+
export declare const ENABLERS = "This plugin is enabled when a `.yml` or `.yaml` file is found in the `.github/workflows` folder.";
|
|
4
4
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
5
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
6
|
export declare const findDependencies: GenericPluginCallback;
|