knip 5.53.0 → 5.54.0
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/dist/IssueFixer.d.ts +1 -1
- package/dist/IssueFixer.js +13 -3
- package/dist/PrincipalFactory.js +3 -17
- package/dist/ProjectPrincipal.d.ts +2 -2
- package/dist/ProjectPrincipal.js +14 -3
- package/dist/WorkspaceWorker.d.ts +0 -1
- package/dist/WorkspaceWorker.js +4 -19
- package/dist/cli.js +2 -1
- package/dist/graph/build.js +8 -5
- package/dist/index.js +15 -4
- package/dist/plugins/ava/index.d.ts +1 -2
- package/dist/plugins/ava/index.js +2 -7
- package/dist/plugins/bun/index.d.ts +2 -2
- package/dist/plugins/bun/index.js +2 -2
- package/dist/plugins/cucumber/index.d.ts +1 -2
- package/dist/plugins/cucumber/index.js +2 -5
- package/dist/plugins/cypress/index.d.ts +1 -2
- package/dist/plugins/cypress/index.js +6 -9
- package/dist/plugins/cypress/types.d.ts +8 -0
- package/dist/plugins/eleventy/helpers.d.ts +10 -2
- package/dist/plugins/eleventy/index.d.ts +3 -6
- package/dist/plugins/eleventy/index.js +11 -16
- package/dist/plugins/eleventy/types.d.ts +9 -7
- package/dist/plugins/expo/index.d.ts +2 -5
- package/dist/plugins/expo/index.js +4 -6
- package/dist/plugins/github-action/index.d.ts +2 -2
- package/dist/plugins/github-action/index.js +2 -2
- package/dist/plugins/index.d.ts +14 -28
- package/dist/plugins/jest/index.d.ts +1 -2
- package/dist/plugins/jest/index.js +4 -12
- package/dist/plugins/karma/index.d.ts +1 -3
- package/dist/plugins/karma/index.js +0 -10
- package/dist/plugins/ladle/index.d.ts +1 -2
- package/dist/plugins/ladle/index.js +4 -7
- package/dist/plugins/metro/index.d.ts +2 -3
- package/dist/plugins/metro/index.js +17 -14
- package/dist/plugins/mocha/index.d.ts +1 -2
- package/dist/plugins/mocha/index.js +2 -6
- package/dist/plugins/msw/index.d.ts +2 -2
- package/dist/plugins/msw/index.js +2 -2
- package/dist/plugins/netlify/index.d.ts +1 -2
- package/dist/plugins/netlify/index.js +4 -7
- package/dist/plugins/node/index.d.ts +2 -2
- package/dist/plugins/node/index.js +2 -2
- package/dist/plugins/nuxt/index.d.ts +2 -2
- package/dist/plugins/nuxt/index.js +2 -2
- package/dist/plugins/playwright/index.d.ts +1 -3
- package/dist/plugins/playwright/index.js +5 -7
- package/dist/plugins/playwright-ct/index.d.ts +0 -1
- package/dist/plugins/playwright-ct/index.js +1 -2
- package/dist/plugins/postcss/index.js +3 -1
- package/dist/plugins/preconstruct/index.d.ts +1 -1
- package/dist/plugins/preconstruct/index.js +2 -2
- package/dist/plugins/react-cosmos/index.d.ts +1 -2
- package/dist/plugins/react-cosmos/index.js +4 -6
- package/dist/plugins/react-router/index.d.ts +2 -2
- package/dist/plugins/react-router/index.js +2 -2
- package/dist/plugins/relay/index.d.ts +2 -2
- package/dist/plugins/relay/index.js +2 -2
- package/dist/plugins/rspack/index.js +2 -3
- package/dist/plugins/size-limit/index.d.ts +2 -1
- package/dist/plugins/size-limit/index.js +10 -0
- package/dist/plugins/storybook/index.d.ts +1 -2
- package/dist/plugins/storybook/index.js +2 -5
- package/dist/plugins/svelte/index.d.ts +2 -1
- package/dist/plugins/svelte/index.js +7 -0
- package/dist/plugins/vite/index.d.ts +0 -1
- package/dist/plugins/vite/index.js +1 -2
- package/dist/plugins/vitest/index.d.ts +1 -3
- package/dist/plugins/vitest/index.js +35 -24
- package/dist/plugins/vitest/types.d.ts +12 -0
- package/dist/plugins/vue/index.js +2 -5
- package/dist/plugins/webpack/index.d.ts +1 -5
- package/dist/plugins/webpack/index.js +36 -17
- package/dist/plugins/wrangler/index.d.ts +2 -2
- package/dist/plugins/wrangler/index.js +2 -2
- package/dist/plugins.js +1 -1
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config.d.ts +0 -2
- package/dist/types/project.d.ts +0 -1
- package/dist/util/cli-arguments.d.ts +2 -1
- package/dist/util/cli-arguments.js +2 -0
- package/dist/util/glob-core.d.ts +5 -6
- package/dist/util/glob-core.js +30 -31
- package/dist/util/input.d.ts +7 -1
- package/dist/util/input.js +7 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
package/dist/IssueFixer.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare class IssueFixer {
|
|
|
18
18
|
constructor({ isEnabled, cwd, fixTypes, isRemoveFiles }: Fixer);
|
|
19
19
|
addUnusedTypeNode(filePath: string, fixes: Fixes | undefined): void;
|
|
20
20
|
addUnusedExportNode(filePath: string, fixes: Fixes | undefined): void;
|
|
21
|
-
fixIssues(issues: Issues): Promise<
|
|
21
|
+
fixIssues(issues: Issues): Promise<Set<string>>;
|
|
22
22
|
private markExportFixed;
|
|
23
23
|
private removeUnusedFiles;
|
|
24
24
|
private removeUnusedExports;
|
package/dist/IssueFixer.js
CHANGED
|
@@ -38,9 +38,13 @@ export class IssueFixer {
|
|
|
38
38
|
this.unusedExportNodes.set(filePath, new Set(fixes));
|
|
39
39
|
}
|
|
40
40
|
async fixIssues(issues) {
|
|
41
|
+
const touchedFiles = new Set();
|
|
41
42
|
await this.removeUnusedFiles(issues);
|
|
42
|
-
await this.removeUnusedExports(issues)
|
|
43
|
-
|
|
43
|
+
for (const filePath of await this.removeUnusedExports(issues))
|
|
44
|
+
touchedFiles.add(filePath);
|
|
45
|
+
for (const filePath of await this.removeUnusedDependencies(issues))
|
|
46
|
+
touchedFiles.add(filePath);
|
|
47
|
+
return touchedFiles;
|
|
44
48
|
}
|
|
45
49
|
markExportFixed(issues, filePath) {
|
|
46
50
|
const relPath = relative(filePath);
|
|
@@ -63,6 +67,7 @@ export class IssueFixer {
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
async removeUnusedExports(issues) {
|
|
70
|
+
const touchedFiles = new Set();
|
|
66
71
|
const filePaths = new Set([...this.unusedTypeNodes.keys(), ...this.unusedExportNodes.keys()]);
|
|
67
72
|
for (const filePath of filePaths) {
|
|
68
73
|
const types = (this.isFixUnusedTypes && this.unusedTypeNodes.get(filePath)) || [];
|
|
@@ -71,13 +76,16 @@ export class IssueFixer {
|
|
|
71
76
|
if (exportPositions.length > 0) {
|
|
72
77
|
const sourceFileText = exportPositions.reduce((text, [start, end, flags]) => removeExport({ text, start, end, flags }), await readFile(filePath, 'utf-8'));
|
|
73
78
|
await writeFile(filePath, sourceFileText);
|
|
79
|
+
touchedFiles.add(filePath);
|
|
74
80
|
this.markExportFixed(issues, filePath);
|
|
75
81
|
}
|
|
76
82
|
}
|
|
83
|
+
return touchedFiles;
|
|
77
84
|
}
|
|
78
85
|
async removeUnusedDependencies(issues) {
|
|
86
|
+
const touchedFiles = new Set();
|
|
79
87
|
if (!this.isFixDependencies)
|
|
80
|
-
return;
|
|
88
|
+
return touchedFiles;
|
|
81
89
|
const filePaths = new Set([...Object.keys(issues.dependencies), ...Object.keys(issues.devDependencies)]);
|
|
82
90
|
for (const filePath of filePaths) {
|
|
83
91
|
const absFilePath = join(this.cwd, filePath);
|
|
@@ -99,6 +107,8 @@ export class IssueFixer {
|
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
await save(absFilePath, pkg);
|
|
110
|
+
touchedFiles.add(filePath);
|
|
102
111
|
}
|
|
112
|
+
return touchedFiles;
|
|
103
113
|
}
|
|
104
114
|
}
|
package/dist/PrincipalFactory.js
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { ProjectPrincipal } from './ProjectPrincipal.js';
|
|
3
3
|
import { debugLog } from './util/debug.js';
|
|
4
|
-
import {
|
|
5
|
-
const mapToAbsolutePaths = (paths, cwd) => Object.keys(paths).reduce((result, key) => {
|
|
6
|
-
result[key] = paths[key].map(entry => toAbsolute(entry, cwd));
|
|
7
|
-
return result;
|
|
8
|
-
}, {});
|
|
9
|
-
const mergePaths = (cwd, compilerOptions, paths = {}) => {
|
|
10
|
-
const basePath = typeof compilerOptions.pathsBasePath === 'string' ? compilerOptions.pathsBasePath : cwd;
|
|
11
|
-
const compilerPaths = !compilerOptions.baseUrl && compilerOptions.paths
|
|
12
|
-
? mapToAbsolutePaths(compilerOptions.paths, basePath)
|
|
13
|
-
: compilerOptions.paths;
|
|
14
|
-
const extraPaths = mapToAbsolutePaths(paths, cwd);
|
|
15
|
-
compilerOptions.paths = { ...compilerPaths, ...extraPaths };
|
|
16
|
-
return compilerOptions;
|
|
17
|
-
};
|
|
4
|
+
import { toRelative } from './util/path.js';
|
|
18
5
|
export class PrincipalFactory {
|
|
19
6
|
principals = new Set();
|
|
20
7
|
createPrincipal(options) {
|
|
21
|
-
const { cwd, compilerOptions, isFile,
|
|
22
|
-
options.compilerOptions = mergePaths(cwd, compilerOptions, paths);
|
|
8
|
+
const { cwd, compilerOptions, isFile, pkgName, isIsolateWorkspaces, compilers } = options;
|
|
23
9
|
if (isFile && compilerOptions.module !== ts.ModuleKind.CommonJS)
|
|
24
10
|
compilerOptions.moduleResolution ??= ts.ModuleResolutionKind.Bundler;
|
|
25
11
|
const principal = this.findReusablePrincipal(compilerOptions);
|
|
@@ -48,7 +34,7 @@ export class PrincipalFactory {
|
|
|
48
34
|
principal.principal.compilerOptions.moduleResolution ??= compilerOptions.moduleResolution;
|
|
49
35
|
for (const p of Object.keys(paths ?? {}))
|
|
50
36
|
principal.pathKeys.add(p);
|
|
51
|
-
principal.principal.addPaths(paths);
|
|
37
|
+
principal.principal.addPaths(paths, cwd);
|
|
52
38
|
principal.principal.addCompilers(compilers);
|
|
53
39
|
principal.wsDirs.add(cwd);
|
|
54
40
|
principal.pkgNames.add(pkgName);
|
|
@@ -3,7 +3,7 @@ import { CacheConsultant } from './CacheConsultant.js';
|
|
|
3
3
|
import type { AsyncCompilers, SyncCompilers } from './compilers/types.js';
|
|
4
4
|
import type { GetImportsAndExportsOptions } from './types/config.js';
|
|
5
5
|
import type { Export, ExportMember, FileNode, ModuleGraph } from './types/module-graph.js';
|
|
6
|
-
import type { PrincipalOptions } from './types/project.js';
|
|
6
|
+
import type { Paths, PrincipalOptions } from './types/project.js';
|
|
7
7
|
import { SourceFileManager } from './typescript/SourceFileManager.js';
|
|
8
8
|
import type { ResolveModuleNames } from './typescript/resolve-module-names.js';
|
|
9
9
|
import type { ToSourceFilePath } from './util/to-source-path.js';
|
|
@@ -32,7 +32,7 @@ export declare class ProjectPrincipal {
|
|
|
32
32
|
findReferences?: ts.LanguageService['findReferences'];
|
|
33
33
|
constructor({ compilerOptions, cwd, compilers, isSkipLibs, isWatch, pkgName, toSourceFilePath, isCache, cacheLocation, }: PrincipalOptions);
|
|
34
34
|
init(): void;
|
|
35
|
-
addPaths(paths:
|
|
35
|
+
addPaths(paths: Paths, basePath: string): void;
|
|
36
36
|
addCompilers(compilers: [SyncCompilers, AsyncCompilers]): void;
|
|
37
37
|
private createProgram;
|
|
38
38
|
private hasAcceptedExtension;
|
package/dist/ProjectPrincipal.js
CHANGED
|
@@ -8,7 +8,7 @@ import { _getImportsAndExports } from './typescript/get-imports-and-exports.js';
|
|
|
8
8
|
import { timerify } from './util/Performance.js';
|
|
9
9
|
import { compact } from './util/array.js';
|
|
10
10
|
import { getPackageNameFromModuleSpecifier, isStartsLikePackageName, sanitizeSpecifier } from './util/modules.js';
|
|
11
|
-
import { dirname, extname, isInNodeModules, join } from './util/path.js';
|
|
11
|
+
import { dirname, extname, isInNodeModules, join, toAbsolute } from './util/path.js';
|
|
12
12
|
const baseCompilerOptions = {
|
|
13
13
|
allowJs: true,
|
|
14
14
|
allowSyntheticDefaultImports: true,
|
|
@@ -78,8 +78,19 @@ export class ProjectPrincipal {
|
|
|
78
78
|
this.backend.resolveModuleNames = resolveModuleNames;
|
|
79
79
|
this.backend.languageServiceHost = languageServiceHost;
|
|
80
80
|
}
|
|
81
|
-
addPaths(paths) {
|
|
82
|
-
|
|
81
|
+
addPaths(paths, basePath) {
|
|
82
|
+
if (!paths)
|
|
83
|
+
return;
|
|
84
|
+
this.compilerOptions.paths ??= {};
|
|
85
|
+
for (const key in paths) {
|
|
86
|
+
const prefixes = paths[key].map(prefix => toAbsolute(prefix, basePath));
|
|
87
|
+
if (key in this.compilerOptions.paths) {
|
|
88
|
+
this.compilerOptions.paths[key] = compact([...this.compilerOptions.paths[key], ...prefixes]);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this.compilerOptions.paths[key] = prefixes;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
83
94
|
}
|
|
84
95
|
addCompilers(compilers) {
|
|
85
96
|
this.syncCompilers = new Map([...this.syncCompilers, ...compilers[0]]);
|
package/dist/WorkspaceWorker.js
CHANGED
|
@@ -235,7 +235,7 @@ export class WorkspaceWorker {
|
|
|
235
235
|
for (const id of config.entry)
|
|
236
236
|
addInput(toInput(id));
|
|
237
237
|
}
|
|
238
|
-
else if ((!plugin.
|
|
238
|
+
else if ((!plugin.resolveConfig && !plugin.resolveFromAST) ||
|
|
239
239
|
(configFilePaths.filter(path => basename(path) !== 'package.json').length === 0 &&
|
|
240
240
|
(!this.configFilesMap.get(wsName)?.get(pluginName) ||
|
|
241
241
|
this.configFilesMap.get(wsName)?.get(pluginName)?.size === 0))) {
|
|
@@ -251,9 +251,6 @@ export class WorkspaceWorker {
|
|
|
251
251
|
const fd = isManifest ? undefined : this.cache.getFileDescriptor(configFilePath);
|
|
252
252
|
if (fd?.meta?.data && !fd.changed) {
|
|
253
253
|
const data = fd.meta.data;
|
|
254
|
-
if (data.resolveEntryPaths)
|
|
255
|
-
for (const id of data.resolveEntryPaths)
|
|
256
|
-
addInput(id, configFilePath);
|
|
257
254
|
if (data.resolveConfig)
|
|
258
255
|
for (const id of data.resolveConfig)
|
|
259
256
|
addInput(id, configFilePath);
|
|
@@ -270,22 +267,10 @@ export class WorkspaceWorker {
|
|
|
270
267
|
configFileName: basename(configFilePath),
|
|
271
268
|
};
|
|
272
269
|
const cache = {};
|
|
273
|
-
let loadedConfig;
|
|
274
|
-
if (plugin.resolveEntryPaths && !seen.get(wsName)?.has(configFilePath)) {
|
|
275
|
-
if (!loadedConfig)
|
|
276
|
-
loadedConfig = await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName);
|
|
277
|
-
if (loadedConfig) {
|
|
278
|
-
const inputs = await plugin.resolveEntryPaths(loadedConfig, resolveOpts);
|
|
279
|
-
for (const input of inputs)
|
|
280
|
-
addInput(input, configFilePath);
|
|
281
|
-
cache.resolveEntryPaths = inputs;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
270
|
if (plugin.resolveConfig && !seen.get(wsName)?.has(configFilePath)) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const inputs = await plugin.resolveConfig(loadedConfig, resolveOpts);
|
|
271
|
+
const localConfig = await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName);
|
|
272
|
+
if (localConfig) {
|
|
273
|
+
const inputs = await plugin.resolveConfig(localConfig, resolveOpts);
|
|
289
274
|
for (const input of inputs)
|
|
290
275
|
addInput(input, configFilePath);
|
|
291
276
|
cache.resolveConfig = inputs;
|
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import { splitTags } from './util/tag.js';
|
|
|
10
10
|
import { isTrace } from './util/trace.js';
|
|
11
11
|
import { version } from './version.js';
|
|
12
12
|
const defaultCacheLocation = join(cwd, 'node_modules', '.cache', 'knip');
|
|
13
|
-
const { 'allow-remove-files': isRemoveFiles = false, cache: isCache = false, 'cache-location': cacheLocation = defaultCacheLocation, debug: isDebug = false, dependencies: isDependenciesShorthand = false, exclude: excludedIssueTypes = [], 'experimental-tags': experimentalTags = [], exports: isExportsShorthand = false, files: isFilesShorthand = false, fix: isFix = false, 'fix-type': fixTypes = [], help: isHelp, include: includedIssueTypes = [], 'include-entry-exports': isIncludeEntryExports = false, 'include-libs': isIncludeLibs = false, 'isolate-workspaces': isIsolateWorkspaces = false, 'max-issues': maxIssues = '0', 'no-config-hints': isDisableConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = isDebug || isTrace, preprocessor = [], 'preprocessor-options': preprocessorOptions = '', production: isProduction = false, reporter = ['symbols'], 'reporter-options': reporterOptions = '', strict: isStrict = false, tags = [], 'treat-config-hints-as-errors': treatConfigHintsAsErrors = false, tsConfig, version: isVersion, watch: isWatch = false, workspace: rawWorkspaceArg, } = parsedArgValues;
|
|
13
|
+
const { 'allow-remove-files': isRemoveFiles = false, cache: isCache = false, 'cache-location': cacheLocation = defaultCacheLocation, debug: isDebug = false, dependencies: isDependenciesShorthand = false, exclude: excludedIssueTypes = [], 'experimental-tags': experimentalTags = [], exports: isExportsShorthand = false, files: isFilesShorthand = false, fix: isFix = false, format: isFormat = false, 'fix-type': fixTypes = [], help: isHelp, include: includedIssueTypes = [], 'include-entry-exports': isIncludeEntryExports = false, 'include-libs': isIncludeLibs = false, 'isolate-workspaces': isIsolateWorkspaces = false, 'max-issues': maxIssues = '0', 'no-config-hints': isDisableConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = isDebug || isTrace, preprocessor = [], 'preprocessor-options': preprocessorOptions = '', production: isProduction = false, reporter = ['symbols'], 'reporter-options': reporterOptions = '', strict: isStrict = false, tags = [], 'treat-config-hints-as-errors': treatConfigHintsAsErrors = false, tsConfig, version: isVersion, watch: isWatch = false, workspace: rawWorkspaceArg, } = parsedArgValues;
|
|
14
14
|
if (isHelp) {
|
|
15
15
|
console.log(helpText);
|
|
16
16
|
process.exit(0);
|
|
@@ -36,6 +36,7 @@ const run = async () => {
|
|
|
36
36
|
isExportsShorthand,
|
|
37
37
|
isFilesShorthand,
|
|
38
38
|
isFix: isFix || fixTypes.length > 0,
|
|
39
|
+
isFormat,
|
|
39
40
|
isDisableConfigHints,
|
|
40
41
|
isIncludeEntryExports,
|
|
41
42
|
isIncludeLibs,
|
package/dist/graph/build.js
CHANGED
|
@@ -6,10 +6,10 @@ import { perfObserver } from '../util/Performance.js';
|
|
|
6
6
|
import { debugLog, debugLogArray } from '../util/debug.js';
|
|
7
7
|
import { getReferencedInputsHandler } from '../util/get-referenced-inputs.js';
|
|
8
8
|
import { _glob, negate } from '../util/glob.js';
|
|
9
|
-
import { isConfig, isDeferResolveEntry, isDeferResolveProductionEntry, isEntry, isProductionEntry, isProject, toProductionEntry, } from '../util/input.js';
|
|
9
|
+
import { isAlias, isConfig, isDeferResolveEntry, isDeferResolveProductionEntry, isEntry, isProductionEntry, isProject, toProductionEntry, } from '../util/input.js';
|
|
10
10
|
import { getOrCreateFileNode, updateImportMap } from '../util/module-graph.js';
|
|
11
11
|
import { getEntryPathsFromManifest } from '../util/package-json.js';
|
|
12
|
-
import { dirname, isAbsolute, join, relative } from '../util/path.js';
|
|
12
|
+
import { dirname, isAbsolute, join, relative, toRelative } from '../util/path.js';
|
|
13
13
|
import {} from '../util/tag.js';
|
|
14
14
|
import { augmentWorkspace, getToSourcePathHandler, getToSourcePathsHandler } from '../util/to-source-path.js';
|
|
15
15
|
import { loadTSConfig } from '../util/tsconfig-loader.js';
|
|
@@ -29,7 +29,7 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
|
|
|
29
29
|
}
|
|
30
30
|
for (const workspace of workspaces) {
|
|
31
31
|
const { name, dir, ancestors, pkgName } = workspace;
|
|
32
|
-
streamer.cast(`Analyzing workspace ${name}...`);
|
|
32
|
+
streamer.cast(`Analyzing workspace (${name})...`);
|
|
33
33
|
const manifest = chief.getManifestForWorkspace(name);
|
|
34
34
|
if (!manifest) {
|
|
35
35
|
continue;
|
|
@@ -79,7 +79,6 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
|
|
|
79
79
|
}
|
|
80
80
|
const principal = factory.createPrincipal({
|
|
81
81
|
cwd: dir,
|
|
82
|
-
paths: config.paths,
|
|
83
82
|
isFile,
|
|
84
83
|
compilerOptions,
|
|
85
84
|
compilers,
|
|
@@ -91,6 +90,7 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
|
|
|
91
90
|
isCache,
|
|
92
91
|
cacheLocation,
|
|
93
92
|
});
|
|
93
|
+
principal.addPaths(config.paths, dir);
|
|
94
94
|
const inputsFromPlugins = await worker.runPlugins();
|
|
95
95
|
for (const id of inputsFromPlugins)
|
|
96
96
|
inputs.add(Object.assign(id, { skipExportsAnalysis: !id.allowIncludeExports }));
|
|
@@ -123,6 +123,9 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
|
|
|
123
123
|
else if (isProject(input)) {
|
|
124
124
|
projectFilePatterns.add(isAbsolute(specifier) ? relative(dir, specifier) : specifier);
|
|
125
125
|
}
|
|
126
|
+
else if (isAlias(input)) {
|
|
127
|
+
principal.addPaths({ [input.specifier]: input.prefixes }, input.dir ?? dir);
|
|
128
|
+
}
|
|
126
129
|
else if (!isConfig(input)) {
|
|
127
130
|
const ws = (input.containingFilePath && chief.findWorkspaceByFilePath(input.containingFilePath)) || workspace;
|
|
128
131
|
const resolvedFilePath = getReferencedInternalFilePath(input, ws);
|
|
@@ -276,7 +279,7 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
|
|
|
276
279
|
streamer.cast('Running async compilers...');
|
|
277
280
|
await principal.runAsyncCompilers();
|
|
278
281
|
}
|
|
279
|
-
streamer.cast(
|
|
282
|
+
streamer.cast(`Analyzing source files (${toRelative(principal.cwd) || '.'})...`);
|
|
280
283
|
let size = principal.entryPaths.size;
|
|
281
284
|
let round = 0;
|
|
282
285
|
do {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { watch } from 'node:fs';
|
|
2
|
+
import { formatly } from 'formatly';
|
|
2
3
|
import { ConfigurationChief } from './ConfigurationChief.js';
|
|
3
4
|
import { ConsoleStreamer } from './ConsoleStreamer.js';
|
|
4
5
|
import { DependencyDeputy } from './DependencyDeputy.js';
|
|
@@ -7,11 +8,11 @@ import { IssueFixer } from './IssueFixer.js';
|
|
|
7
8
|
import { PrincipalFactory } from './PrincipalFactory.js';
|
|
8
9
|
import { analyze } from './graph/analyze.js';
|
|
9
10
|
import { build } from './graph/build.js';
|
|
10
|
-
import { debugLogObject } from './util/debug.js';
|
|
11
|
+
import { debugLogArray, debugLogObject } from './util/debug.js';
|
|
11
12
|
import { getGitIgnoredHandler } from './util/glob-core.js';
|
|
12
13
|
import { getWatchHandler } from './util/watch.js';
|
|
13
14
|
export const main = async (unresolvedConfiguration) => {
|
|
14
|
-
const { cacheLocation, cwd, excludedIssueTypes, fixTypes, gitignore, includedIssueTypes, isCache, isDebug, isDependenciesShorthand, isExportsShorthand, isFilesShorthand, isFix, isDisableConfigHints, isIncludeEntryExports, isIncludeLibs, isIsolateWorkspaces, isProduction, isRemoveFiles, isShowProgress, isStrict, isWatch, tags, tsConfigFile, workspace, } = unresolvedConfiguration;
|
|
15
|
+
const { cacheLocation, cwd, excludedIssueTypes, fixTypes, gitignore, includedIssueTypes, isCache, isDebug, isDependenciesShorthand, isExportsShorthand, isFilesShorthand, isFix, isFormat, isDisableConfigHints, isIncludeEntryExports, isIncludeLibs, isIsolateWorkspaces, isProduction, isRemoveFiles, isShowProgress, isStrict, isWatch, tags, tsConfigFile, workspace, } = unresolvedConfiguration;
|
|
15
16
|
debugLogObject('*', 'Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
|
|
16
17
|
const chief = new ConfigurationChief({ cwd, isProduction, isStrict, isIncludeEntryExports, workspace });
|
|
17
18
|
const deputy = new DependencyDeputy({ isProduction, isStrict });
|
|
@@ -101,8 +102,18 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
101
102
|
});
|
|
102
103
|
watch('.', { recursive: true }, watchHandler);
|
|
103
104
|
}
|
|
104
|
-
if (isFix)
|
|
105
|
-
await fixer.fixIssues(issues);
|
|
105
|
+
if (isFix) {
|
|
106
|
+
const touchedFiles = await fixer.fixIssues(issues);
|
|
107
|
+
if (isFormat) {
|
|
108
|
+
const report = await formatly(Array.from(touchedFiles), { cwd });
|
|
109
|
+
if (report.ran && report.result.code === 0) {
|
|
110
|
+
debugLogArray('*', `Formatted files using ${report.formatter.name} (${report.formatter.runner})`, touchedFiles);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
debugLogObject('*', 'Formatting files failed', report);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
106
117
|
if (!isWatch)
|
|
107
118
|
streamer.clear();
|
|
108
119
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IsPluginEnabled, ResolveConfig
|
|
1
|
+
import type { IsPluginEnabled, ResolveConfig } from '../../types/config.js';
|
|
2
2
|
import type { AvaConfig } from './types.js';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
title: string;
|
|
@@ -6,7 +6,6 @@ declare const _default: {
|
|
|
6
6
|
isEnabled: IsPluginEnabled;
|
|
7
7
|
config: string[];
|
|
8
8
|
entry: string[];
|
|
9
|
-
resolveEntryPaths: ResolveEntryPaths<AvaConfig>;
|
|
10
9
|
resolveConfig: ResolveConfig<AvaConfig>;
|
|
11
10
|
};
|
|
12
11
|
export default _default;
|
|
@@ -16,18 +16,14 @@ const entry = [
|
|
|
16
16
|
'!**/__tests__/**/__{helper,fixture}?(s)__/**/*',
|
|
17
17
|
'!**/test?(s)/**/{helper,fixture}?(s)/**/*',
|
|
18
18
|
];
|
|
19
|
-
const resolveEntryPaths = localConfig => {
|
|
20
|
-
if (typeof localConfig === 'function')
|
|
21
|
-
localConfig = localConfig();
|
|
22
|
-
return (localConfig?.files ?? entry).map(id => toEntry(id));
|
|
23
|
-
};
|
|
24
19
|
const resolveConfig = async (localConfig, options) => {
|
|
25
20
|
if (typeof localConfig === 'function')
|
|
26
21
|
localConfig = localConfig();
|
|
22
|
+
const files = (localConfig?.files ?? entry).map(id => toEntry(id));
|
|
27
23
|
const nodeArgs = localConfig.nodeArguments ?? [];
|
|
28
24
|
const requireArgs = (localConfig.require ?? []).map(require => `--require ${require}`);
|
|
29
25
|
const fakeCommand = `node ${nodeArgs.join(' ')} ${requireArgs.join(' ')}`;
|
|
30
|
-
return options.getInputsFromScripts(fakeCommand, { knownBinsOnly: true });
|
|
26
|
+
return files.concat(options.getInputsFromScripts(fakeCommand, { knownBinsOnly: true }));
|
|
31
27
|
};
|
|
32
28
|
export default {
|
|
33
29
|
title,
|
|
@@ -35,6 +31,5 @@ export default {
|
|
|
35
31
|
isEnabled,
|
|
36
32
|
config,
|
|
37
33
|
entry,
|
|
38
|
-
resolveEntryPaths,
|
|
39
34
|
resolveConfig,
|
|
40
35
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ResolveConfig } from '../../types/config.js';
|
|
2
2
|
import type { PackageJson } from '../../types/package-json.js';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
title: string;
|
|
@@ -6,6 +6,6 @@ declare const _default: {
|
|
|
6
6
|
isEnabled: () => boolean;
|
|
7
7
|
config: string[];
|
|
8
8
|
packageJsonPath: (id: PackageJson) => PackageJson;
|
|
9
|
-
|
|
9
|
+
resolveConfig: ResolveConfig<PackageJson>;
|
|
10
10
|
};
|
|
11
11
|
export default _default;
|
|
@@ -5,7 +5,7 @@ const enablers = ['bun'];
|
|
|
5
5
|
const isEnabled = () => true;
|
|
6
6
|
const config = ['package.json'];
|
|
7
7
|
const packageJsonPath = (id) => id;
|
|
8
|
-
const
|
|
8
|
+
const resolveConfig = localConfig => {
|
|
9
9
|
const scripts = localConfig.scripts;
|
|
10
10
|
if (scripts) {
|
|
11
11
|
const testScripts = Object.keys(scripts).filter(script => /(?<=^|\s)bun test/.test(scripts[script]));
|
|
@@ -24,5 +24,5 @@ export default {
|
|
|
24
24
|
isEnabled,
|
|
25
25
|
config,
|
|
26
26
|
packageJsonPath,
|
|
27
|
-
|
|
27
|
+
resolveConfig,
|
|
28
28
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IsPluginEnabled, ResolveConfig
|
|
1
|
+
import type { IsPluginEnabled, ResolveConfig } from '../../types/config.js';
|
|
2
2
|
import type { CucumberConfig } from './types.js';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
title: string;
|
|
@@ -6,7 +6,6 @@ declare const _default: {
|
|
|
6
6
|
isEnabled: IsPluginEnabled;
|
|
7
7
|
config: string[];
|
|
8
8
|
entry: string[];
|
|
9
|
-
resolveEntryPaths: ResolveEntryPaths<CucumberConfig>;
|
|
10
9
|
resolveConfig: ResolveConfig<CucumberConfig>;
|
|
11
10
|
};
|
|
12
11
|
export default _default;
|
|
@@ -5,13 +5,11 @@ const enablers = ['@cucumber/cucumber'];
|
|
|
5
5
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
6
6
|
const config = ['cucumber.{json,yaml,yml,js,cjs,mjs}'];
|
|
7
7
|
const entry = ['features/**/*.@(js|cjs|mjs)'];
|
|
8
|
-
const resolveEntryPaths = config => {
|
|
9
|
-
return (config?.import ? config.import : []).map(id => toEntry(id));
|
|
10
|
-
};
|
|
11
8
|
const resolveConfig = config => {
|
|
9
|
+
const imports = (config?.import ? config.import : entry).map(id => toEntry(id));
|
|
12
10
|
const formatters = config?.format ? config.format : [];
|
|
13
11
|
const requires = config?.require ? config.require : [];
|
|
14
|
-
return [...formatters, ...requires].map(toDeferResolve);
|
|
12
|
+
return imports.concat([...formatters, ...requires].map(toDeferResolve));
|
|
15
13
|
};
|
|
16
14
|
export default {
|
|
17
15
|
title,
|
|
@@ -19,6 +17,5 @@ export default {
|
|
|
19
17
|
isEnabled,
|
|
20
18
|
config,
|
|
21
19
|
entry,
|
|
22
|
-
resolveEntryPaths,
|
|
23
20
|
resolveConfig,
|
|
24
21
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IsPluginEnabled, ResolveConfig
|
|
1
|
+
import type { IsPluginEnabled, ResolveConfig } from '../../types/config.js';
|
|
2
2
|
import type { CypressConfig } from './types.js';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
title: string;
|
|
@@ -6,7 +6,6 @@ declare const _default: {
|
|
|
6
6
|
isEnabled: IsPluginEnabled;
|
|
7
7
|
config: string[];
|
|
8
8
|
entry: string[];
|
|
9
|
-
resolveEntryPaths: ResolveEntryPaths;
|
|
10
9
|
resolveConfig: ResolveConfig<CypressConfig>;
|
|
11
10
|
};
|
|
12
11
|
export default _default;
|
|
@@ -13,17 +13,15 @@ const SUPPORT_FILE_PATTERNS = [
|
|
|
13
13
|
'cypress/plugins/index.js',
|
|
14
14
|
];
|
|
15
15
|
const entry = [...TEST_FILE_PATTERNS, ...SUPPORT_FILE_PATTERNS];
|
|
16
|
-
const
|
|
16
|
+
const resolveConfig = async (localConfig, options) => {
|
|
17
17
|
const specPatterns = [localConfig.e2e?.specPattern ?? [], localConfig.component?.specPattern ?? []].flat();
|
|
18
18
|
const supportFiles = [localConfig.e2e?.supportFile || [], localConfig.component?.supportFile || []].flat();
|
|
19
|
+
const inputs = await resolveDependencies(localConfig, options);
|
|
19
20
|
return [
|
|
20
|
-
...(
|
|
21
|
-
...(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const resolveConfig = async (config, options) => {
|
|
25
|
-
const inputs = await resolveDependencies(config, options);
|
|
26
|
-
return inputs.map(toDeferResolve);
|
|
21
|
+
...inputs.map(toDeferResolve),
|
|
22
|
+
...(specPatterns.length > 0 ? specPatterns : TEST_FILE_PATTERNS).map(id => toEntry(id)),
|
|
23
|
+
...(supportFiles.length > 0 ? supportFiles : SUPPORT_FILE_PATTERNS).map(id => toEntry(id)),
|
|
24
|
+
];
|
|
27
25
|
};
|
|
28
26
|
export default {
|
|
29
27
|
title,
|
|
@@ -31,6 +29,5 @@ export default {
|
|
|
31
29
|
isEnabled,
|
|
32
30
|
config,
|
|
33
31
|
entry,
|
|
34
|
-
resolveEntryPaths,
|
|
35
32
|
resolveConfig,
|
|
36
33
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { EleventyConfig } from './types.js';
|
|
2
1
|
export declare class DummyEleventyConfig {
|
|
3
2
|
_getUniqueId(): void;
|
|
4
3
|
reset(): void;
|
|
@@ -135,4 +134,13 @@ export declare class DummyEleventyConfig {
|
|
|
135
134
|
};
|
|
136
135
|
templateFormatsAdded: {};
|
|
137
136
|
}
|
|
138
|
-
export declare const defaultEleventyConfig:
|
|
137
|
+
export declare const defaultEleventyConfig: {
|
|
138
|
+
dir: {
|
|
139
|
+
input: string;
|
|
140
|
+
output: string;
|
|
141
|
+
includes: string;
|
|
142
|
+
layouts: string;
|
|
143
|
+
data: string;
|
|
144
|
+
};
|
|
145
|
+
templateFormats: string;
|
|
146
|
+
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import type { IsPluginEnabled, ResolveConfig
|
|
2
|
-
import {
|
|
3
|
-
import type { EleventyConfig } from './types.js';
|
|
4
|
-
type T = Partial<EleventyConfig> | ((arg: DummyEleventyConfig) => Promise<Partial<EleventyConfig>>);
|
|
1
|
+
import type { IsPluginEnabled, ResolveConfig } from '../../types/config.js';
|
|
2
|
+
import type { EleventyConfigOrFn } from './types.js';
|
|
5
3
|
declare const _default: {
|
|
6
4
|
title: string;
|
|
7
5
|
enablers: string[];
|
|
8
6
|
isEnabled: IsPluginEnabled;
|
|
9
7
|
config: string[];
|
|
10
8
|
production: string[];
|
|
11
|
-
|
|
12
|
-
resolveConfig: ResolveConfig<T>;
|
|
9
|
+
resolveConfig: ResolveConfig<EleventyConfigOrFn>;
|
|
13
10
|
};
|
|
14
11
|
export default _default;
|
|
@@ -9,16 +9,17 @@ const enablers = ['@11ty/eleventy'];
|
|
|
9
9
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
10
10
|
const config = ['.eleventy.js', 'eleventy.config.{js,cjs,mjs}'];
|
|
11
11
|
const production = ['posts/**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}'];
|
|
12
|
-
const
|
|
12
|
+
const resolveConfig = async (localConfig, options) => {
|
|
13
13
|
const { configFileDir } = options;
|
|
14
14
|
const dummyUserConfig = new DummyEleventyConfig();
|
|
15
15
|
if (typeof localConfig === 'function')
|
|
16
|
-
localConfig = await localConfig(dummyUserConfig);
|
|
16
|
+
localConfig = (await localConfig(dummyUserConfig));
|
|
17
17
|
const inputDir = localConfig?.dir?.input || defaultEleventyConfig.dir.input;
|
|
18
18
|
const dataDir = localConfig?.dir?.data || defaultEleventyConfig.dir.data;
|
|
19
19
|
const templateFormats = localConfig.templateFormats || defaultEleventyConfig.templateFormats;
|
|
20
20
|
const exts = DEFAULT_EXTENSIONS.map(extname => extname.slice(1)).join(',');
|
|
21
21
|
const copiedEntries = new Set();
|
|
22
|
+
const copiedPackages = new Set();
|
|
22
23
|
for (const path of Object.keys(dummyUserConfig.passthroughCopies)) {
|
|
23
24
|
const isDir = !path.includes('*') && isDirectory(join(configFileDir, path));
|
|
24
25
|
if (isDir) {
|
|
@@ -28,23 +29,18 @@ const resolveEntryPaths = async (localConfig, options) => {
|
|
|
28
29
|
copiedEntries.add(path);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
return [
|
|
32
|
-
join(inputDir, dataDir, '**/*.{js,cjs,mjs}'),
|
|
33
|
-
join(inputDir, `**/*.{${typeof templateFormats === 'string' ? templateFormats : templateFormats.join(',')}}`),
|
|
34
|
-
join(inputDir, '**/*.11tydata.js'),
|
|
35
|
-
...copiedEntries,
|
|
36
|
-
].map(id => toProductionEntry(id));
|
|
37
|
-
};
|
|
38
|
-
const resolveConfig = async (localConfig) => {
|
|
39
|
-
const dummyUserConfig = new DummyEleventyConfig();
|
|
40
|
-
if (typeof localConfig === 'function')
|
|
41
|
-
localConfig = await localConfig(dummyUserConfig);
|
|
42
|
-
const copiedPackages = new Set();
|
|
43
32
|
for (const path of Object.keys(dummyUserConfig.passthroughCopies)) {
|
|
44
33
|
if (isInNodeModules(path))
|
|
45
34
|
copiedPackages.add(path);
|
|
46
35
|
}
|
|
47
|
-
return
|
|
36
|
+
return Array.from(copiedPackages)
|
|
37
|
+
.map(id => toDeferResolve(id))
|
|
38
|
+
.concat([
|
|
39
|
+
join(inputDir, dataDir, '**/*.{js,cjs,mjs}'),
|
|
40
|
+
join(inputDir, `**/*.{${typeof templateFormats === 'string' ? templateFormats : templateFormats.join(',')}}`),
|
|
41
|
+
join(inputDir, '**/*.11tydata.js'),
|
|
42
|
+
...copiedEntries,
|
|
43
|
+
].map(id => toProductionEntry(id)));
|
|
48
44
|
};
|
|
49
45
|
export default {
|
|
50
46
|
title,
|
|
@@ -52,6 +48,5 @@ export default {
|
|
|
52
48
|
isEnabled,
|
|
53
49
|
config,
|
|
54
50
|
production,
|
|
55
|
-
resolveEntryPaths,
|
|
56
51
|
resolveConfig,
|
|
57
52
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import type { DummyEleventyConfig } from './helpers.js';
|
|
1
2
|
export type EleventyConfig = {
|
|
2
|
-
dir
|
|
3
|
-
input
|
|
4
|
-
output
|
|
5
|
-
includes
|
|
6
|
-
layouts
|
|
7
|
-
data
|
|
3
|
+
dir?: {
|
|
4
|
+
input?: string;
|
|
5
|
+
output?: string;
|
|
6
|
+
includes?: string;
|
|
7
|
+
layouts?: string;
|
|
8
|
+
data?: string;
|
|
8
9
|
};
|
|
9
|
-
templateFormats
|
|
10
|
+
templateFormats?: string | string[];
|
|
10
11
|
};
|
|
12
|
+
export type EleventyConfigOrFn = Partial<EleventyConfig> | ((arg: DummyEleventyConfig) => Promise<Partial<EleventyConfig>>);
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import type { IsPluginEnabled, ResolveConfig
|
|
1
|
+
import type { IsPluginEnabled, ResolveConfig } from '../../types/config.js';
|
|
2
2
|
import type { ExpoConfig } from './types.js';
|
|
3
|
-
export declare const docs: {
|
|
4
|
-
production: string[];
|
|
5
|
-
};
|
|
6
3
|
declare const _default: {
|
|
7
4
|
title: string;
|
|
8
5
|
enablers: string[];
|
|
9
6
|
isEnabled: IsPluginEnabled;
|
|
10
7
|
config: string[];
|
|
11
|
-
|
|
8
|
+
production: string[];
|
|
12
9
|
resolveConfig: ResolveConfig<ExpoConfig>;
|
|
13
10
|
};
|
|
14
11
|
export default _default;
|