knip 6.24.0 → 6.25.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/ConfigurationChief.d.ts +13 -1
- package/dist/ConfigurationChief.js +3 -0
- package/dist/ProjectPrincipal.d.ts +2 -0
- package/dist/ProjectPrincipal.js +4 -1
- package/dist/binaries/bash-parser.js +55 -83
- package/dist/binaries/index.js +3 -0
- package/dist/compilers/index.d.ts +29 -5
- package/dist/constants.d.ts +5 -1
- package/dist/constants.js +5 -0
- package/dist/graph/analyze.js +37 -2
- package/dist/graph/build.js +9 -0
- package/dist/graph-explorer/explorer.d.ts +1 -0
- package/dist/graph-explorer/explorer.js +2 -0
- package/dist/graph-explorer/operations/find-all-cycles.d.ts +3 -0
- package/dist/graph-explorer/operations/find-all-cycles.js +43 -0
- package/dist/graph-explorer/operations/find-cycles.js +3 -9
- package/dist/graph-explorer/utils.d.ts +10 -1
- package/dist/graph-explorer/utils.js +53 -0
- package/dist/plugins/bun/index.js +28 -14
- package/dist/plugins/eve/index.d.ts +3 -0
- package/dist/plugins/eve/index.js +22 -0
- package/dist/plugins/execa/visitors/execa.js +10 -18
- package/dist/plugins/fumadocs/index.d.ts +3 -0
- package/dist/plugins/fumadocs/index.js +18 -0
- package/dist/plugins/graphql-codegen/index.js +9 -7
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/jest/index.js +13 -3
- package/dist/plugins/next/index.js +23 -10
- package/dist/plugins/node/index.js +4 -1
- package/dist/plugins/pnpm/index.js +21 -1
- package/dist/plugins/pnpm/types.d.ts +6 -0
- package/dist/plugins/pnpm/types.js +1 -0
- package/dist/plugins/prettier/index.js +19 -3
- package/dist/plugins/prettier/types.d.ts +6 -1
- package/dist/plugins/rspack/index.js +5 -0
- package/dist/plugins/serverless-framework/index.js +12 -1
- package/dist/plugins/serverless-framework/types.d.ts +5 -2
- package/dist/plugins/storybook/index.js +7 -0
- package/dist/plugins/typedoc/index.js +9 -3
- package/dist/plugins/typedoc/types.d.ts +2 -0
- package/dist/plugins/vite/visitors/importMetaGlob.js +1 -8
- package/dist/plugins/webpack/visitors/requireContext.js +2 -13
- package/dist/plugins/yarn/index.js +13 -4
- package/dist/plugins/yarn/types.d.ts +10 -0
- package/dist/plugins/yarn/types.js +1 -0
- package/dist/plugins/zx/visitors/zx.js +4 -4
- package/dist/reporters/cycles.d.ts +3 -0
- package/dist/reporters/cycles.js +79 -0
- package/dist/reporters/index.d.ts +1 -0
- package/dist/reporters/index.js +2 -0
- package/dist/reporters/json.d.ts +3 -0
- package/dist/reporters/json.js +2 -1
- package/dist/reporters/util/util.d.ts +3 -1
- package/dist/reporters/util/util.js +5 -1
- package/dist/schema/configuration.d.ts +40 -6
- package/dist/schema/configuration.js +6 -0
- package/dist/schema/plugins.d.ts +10 -0
- package/dist/schema/plugins.js +2 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +2 -0
- package/dist/types/config.d.ts +9 -0
- package/dist/types/issues.d.ts +3 -0
- package/dist/types/module-graph.d.ts +7 -0
- package/dist/types/package-json.d.ts +4 -1
- package/dist/typescript/ast-nodes.d.ts +3 -1
- package/dist/typescript/ast-nodes.js +9 -1
- package/dist/typescript/get-imports-and-exports.js +10 -0
- package/dist/typescript/glob-imports.d.ts +3 -0
- package/dist/typescript/glob-imports.js +49 -0
- package/dist/typescript/resolve-module-names.d.ts +2 -0
- package/dist/typescript/resolve-module-names.js +35 -1
- package/dist/typescript/visitors/calls.js +4 -6
- package/dist/typescript/visitors/imports.js +8 -8
- package/dist/typescript/visitors/script-visitors.js +4 -4
- package/dist/typescript/visitors/walk.js +2 -3
- package/dist/util/cli-arguments.d.ts +2 -1
- package/dist/util/cli-arguments.js +4 -2
- package/dist/util/create-options.d.ts +32 -5
- package/dist/util/create-options.js +4 -1
- package/dist/util/get-included-issue-types.d.ts +1 -0
- package/dist/util/get-included-issue-types.js +4 -2
- package/dist/util/issue-initializers.js +1 -1
- package/dist/util/load-tsconfig.js +17 -4
- package/dist/util/module-graph.js +1 -0
- package/dist/util/modules.js +25 -4
- package/dist/util/scripts.d.ts +7 -0
- package/dist/util/scripts.js +75 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +40 -1
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import type { Import, ImportMaps, ModuleGraph } from '../types/module-graph.ts';
|
|
1
|
+
import type { FileNode, Import, ImportMaps, ModuleGraph } from '../types/module-graph.ts';
|
|
2
|
+
export declare const getIgnoredCycleImportFlags: (includeDynamicImports: boolean) => number;
|
|
2
3
|
export declare const getExportedIdentifiers: (graph: ModuleGraph, filePath: string, visited?: Set<string>) => Map<string, boolean>;
|
|
4
|
+
export declare const getRuntimeSuccessors: (node: FileNode, ignoredFlags?: number) => Set<string>;
|
|
5
|
+
export declare const getRuntimeImport: (node: FileNode, filePath: string, ignoredFlags?: number) => {
|
|
6
|
+
kind: string;
|
|
7
|
+
specifier: string;
|
|
8
|
+
pos: number;
|
|
9
|
+
line: number;
|
|
10
|
+
col: number;
|
|
11
|
+
} | undefined;
|
|
3
12
|
export declare const hasStrictlyEnumReferences: (importsForExport: ImportMaps | undefined, identifier: string) => boolean;
|
|
4
13
|
export declare const getIssueType: (hasOnlyNsReference: boolean, isType: boolean) => "exports" | "nsExports" | "nsTypes" | "types";
|
|
5
14
|
export declare const findImportRef: (graph: ModuleGraph, importingFile: string, importedFile: string, identifier: string) => Import | undefined;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { IMPORT_FLAGS, IMPORT_STAR, OPAQUE, SIDE_EFFECTS } from '../constants.js';
|
|
1
2
|
import { getCachedExportedIdentifiers, setCachedExportedIdentifiers } from './cache.js';
|
|
2
3
|
import { forEachAliasReExport, forEachNamespaceReExport, forEachPassThroughReExport, getStarReExportSources, } from './visitors.js';
|
|
4
|
+
const IGNORED_CYCLE_IMPORT_FLAGS = IMPORT_FLAGS.ENTRY | IMPORT_FLAGS.DYNAMIC;
|
|
5
|
+
export const getIgnoredCycleImportFlags = (includeDynamicImports) => includeDynamicImports ? IMPORT_FLAGS.ENTRY : IGNORED_CYCLE_IMPORT_FLAGS;
|
|
3
6
|
export const getExportedIdentifiers = (graph, filePath, visited = new Set()) => {
|
|
4
7
|
if (visited.has(filePath))
|
|
5
8
|
return new Map();
|
|
@@ -49,6 +52,56 @@ export const getExportedIdentifiers = (graph, filePath, visited = new Set()) =>
|
|
|
49
52
|
setCachedExportedIdentifiers(graph, filePath, identifiers);
|
|
50
53
|
return identifiers;
|
|
51
54
|
};
|
|
55
|
+
export const getRuntimeSuccessors = (node, ignoredFlags = IGNORED_CYCLE_IMPORT_FLAGS) => {
|
|
56
|
+
const successors = new Set();
|
|
57
|
+
for (const _import of node.imports.imports) {
|
|
58
|
+
if (_import.filePath &&
|
|
59
|
+
!_import.isTypeOnly &&
|
|
60
|
+
!(_import.modifiers & ignoredFlags) &&
|
|
61
|
+
node.imports.internal.has(_import.filePath)) {
|
|
62
|
+
successors.add(_import.filePath);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return successors;
|
|
66
|
+
};
|
|
67
|
+
const getImportKind = (importMaps, identifier, modifiers) => {
|
|
68
|
+
if (modifiers & IMPORT_FLAGS.DYNAMIC)
|
|
69
|
+
return 'dynamicImport';
|
|
70
|
+
if (identifier === IMPORT_STAR && importMaps.reExport.has(IMPORT_STAR))
|
|
71
|
+
return 'reExportStar';
|
|
72
|
+
if (identifier && importMaps.reExportNs.has(identifier))
|
|
73
|
+
return 'reExportNS';
|
|
74
|
+
if (identifier && importMaps.reExportAs.has(identifier))
|
|
75
|
+
return 'reExportAs';
|
|
76
|
+
if (identifier && importMaps.reExport.has(identifier))
|
|
77
|
+
return 'reExport';
|
|
78
|
+
if (identifier === IMPORT_STAR && importMaps.importNs.size > 0)
|
|
79
|
+
return 'importNS';
|
|
80
|
+
if (identifier && importMaps.importAs.has(identifier))
|
|
81
|
+
return 'importAs';
|
|
82
|
+
if (identifier === OPAQUE)
|
|
83
|
+
return 'dynamicImport';
|
|
84
|
+
if (identifier === SIDE_EFFECTS)
|
|
85
|
+
return 'sideEffectImport';
|
|
86
|
+
return 'import';
|
|
87
|
+
};
|
|
88
|
+
export const getRuntimeImport = (node, filePath, ignoredFlags = IGNORED_CYCLE_IMPORT_FLAGS) => {
|
|
89
|
+
const importMaps = node.imports.internal.get(filePath);
|
|
90
|
+
if (!importMaps)
|
|
91
|
+
return;
|
|
92
|
+
let result;
|
|
93
|
+
for (const _import of node.imports.imports) {
|
|
94
|
+
if (_import.filePath !== filePath || _import.isTypeOnly || _import.modifiers & ignoredFlags)
|
|
95
|
+
continue;
|
|
96
|
+
if (!result || _import.line < result.line || (_import.line === result.line && _import.col < result.col)) {
|
|
97
|
+
result = _import;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!result)
|
|
101
|
+
return;
|
|
102
|
+
const { specifier, pos, line, col, identifier, modifiers } = result;
|
|
103
|
+
return { kind: getImportKind(importMaps, identifier, modifiers), specifier, pos, line, col };
|
|
104
|
+
};
|
|
52
105
|
export const hasStrictlyEnumReferences = (importsForExport, identifier) => {
|
|
53
106
|
if (!importsForExport || !importsForExport.refs.has(identifier))
|
|
54
107
|
return false;
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
import { isFile } from '../../util/fs.js';
|
|
2
|
+
import { toDeferResolve, toEntry, toIgnore } from '../../util/input.js';
|
|
1
3
|
import parseArgs from '../../util/parse-args.js';
|
|
2
|
-
import {
|
|
4
|
+
import { getScriptCommands } from '../../util/scripts.js';
|
|
3
5
|
const title = 'Bun';
|
|
4
|
-
const enablers =
|
|
5
|
-
const hasBunTest = (scripts) => scripts && Object.values(scripts).some(script => /(?<=^|\s)bun test/.test(script));
|
|
6
|
-
const isEnabled = ({ manifest }) => !!hasBunTest(manifest.scripts);
|
|
7
|
-
const config = ['bunfig.toml'];
|
|
6
|
+
const enablers = 'This plugin is enabled when a `bun.lock` or `bun.lockb` file is found or a `bun test` script is configured.';
|
|
8
7
|
const patterns = ['**/*.{test,spec}.{js,jsx,ts,tsx}', '**/*_{test,spec}.{js,jsx,ts,tsx}'];
|
|
8
|
+
const getBunTest = (script) => {
|
|
9
|
+
for (const { binary, args } of getScriptCommands(script)) {
|
|
10
|
+
if (binary !== 'bun')
|
|
11
|
+
continue;
|
|
12
|
+
const parsed = parseArgs(args, { string: ['timeout', 'rerun-each', 'preload'] });
|
|
13
|
+
if (parsed._[0] === 'test')
|
|
14
|
+
return parsed;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const hasBunTest = (scripts) => scripts && Object.values(scripts).some(script => typeof script === 'string' && getBunTest(script));
|
|
18
|
+
const isEnabled = ({ cwd, manifest }) => isFile(cwd, 'bun.lock') || isFile(cwd, 'bun.lockb') || !!hasBunTest(manifest.scripts);
|
|
19
|
+
const config = ['bunfig.toml'];
|
|
9
20
|
const resolveConfig = localConfig => {
|
|
10
21
|
const preload = localConfig.test?.preload ?? [];
|
|
11
22
|
return preload.map(specifier => toDeferResolve(specifier));
|
|
@@ -20,17 +31,20 @@ const toPatterns = (arg) => {
|
|
|
20
31
|
};
|
|
21
32
|
const resolve = options => {
|
|
22
33
|
const scripts = { ...options.rootManifest?.scripts, ...options.manifest.scripts };
|
|
34
|
+
const inputs = [toIgnore('bun', 'dependencies')];
|
|
23
35
|
for (const script of Object.values(scripts)) {
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
if (typeof script !== 'string')
|
|
37
|
+
continue;
|
|
38
|
+
const parsed = getBunTest(script);
|
|
39
|
+
if (!parsed)
|
|
40
|
+
continue;
|
|
41
|
+
const targets = parsed._.slice(1);
|
|
42
|
+
for (const pattern of targets.length === 0 ? patterns : targets.flatMap(toPatterns))
|
|
43
|
+
inputs.push(toEntry(pattern));
|
|
44
|
+
for (const specifier of [parsed.preload ?? []].flat())
|
|
45
|
+
inputs.push(toDeferResolve(specifier));
|
|
32
46
|
}
|
|
33
|
-
return
|
|
47
|
+
return inputs;
|
|
34
48
|
};
|
|
35
49
|
const plugin = {
|
|
36
50
|
title,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { hasDependency } from '../../util/plugin.js';
|
|
2
|
+
const title = 'eve';
|
|
3
|
+
const enablers = ['eve'];
|
|
4
|
+
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
5
|
+
const extensions = '{js,jsx,ts,tsx,mjs,cjs,mts,cts}';
|
|
6
|
+
const rootAgentFileNames = '{agent,instructions,instrumentation,sandbox}';
|
|
7
|
+
const subagentFileNames = '{agent,instructions,sandbox}';
|
|
8
|
+
const production = [
|
|
9
|
+
`{,agent/}${rootAgentFileNames}.${extensions}`,
|
|
10
|
+
`{,agent/}sandbox/sandbox.${extensions}`,
|
|
11
|
+
`{,agent/}{channels,connections,hooks,skills,tools,schedules}/**/*.${extensions}`,
|
|
12
|
+
`{,agent/}subagents/**/${subagentFileNames}.${extensions}`,
|
|
13
|
+
`{,agent/}subagents/**/sandbox/sandbox.${extensions}`,
|
|
14
|
+
`{,agent/}subagents/**/{connections,hooks,skills,tools}/**/*.${extensions}`,
|
|
15
|
+
];
|
|
16
|
+
const plugin = {
|
|
17
|
+
title,
|
|
18
|
+
enablers,
|
|
19
|
+
isEnabled,
|
|
20
|
+
production,
|
|
21
|
+
};
|
|
22
|
+
export default plugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSafeScriptFromArgs,
|
|
1
|
+
import { getSafeScriptFromArgs, getScriptFromArg, getScriptFromTemplate } from '../../../typescript/ast-nodes.js';
|
|
2
2
|
const tags = new Set(['$', '$sync']);
|
|
3
3
|
const methods = new Set(['execa', 'execaSync', 'execaCommand', 'execaCommandSync', 'execaNode', '$sync']);
|
|
4
4
|
export function createExecaVisitor(ctx) {
|
|
@@ -10,18 +10,12 @@ export function createExecaVisitor(ctx) {
|
|
|
10
10
|
: tag.type === 'CallExpression' && tag.callee.type === 'Identifier'
|
|
11
11
|
? tag.callee.name
|
|
12
12
|
: undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
else if (tagName && tags.has(tagName)) {
|
|
20
|
-
for (const q of node.quasi.quasis) {
|
|
21
|
-
if (q.value.raw)
|
|
22
|
-
ctx.addScript(q.value.raw);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
13
|
+
const isNode = tagName === 'execaNode';
|
|
14
|
+
if (!isNode && !(tagName && tags.has(tagName)))
|
|
15
|
+
return;
|
|
16
|
+
const script = getScriptFromTemplate(node.quasi);
|
|
17
|
+
if (script)
|
|
18
|
+
ctx.addScript(isNode ? `node ${script}` : script);
|
|
25
19
|
},
|
|
26
20
|
CallExpression(node) {
|
|
27
21
|
if (node.callee.type !== 'Identifier' || !methods.has(node.callee.name))
|
|
@@ -33,11 +27,9 @@ export function createExecaVisitor(ctx) {
|
|
|
33
27
|
ctx.addScript(`node ${script}`);
|
|
34
28
|
}
|
|
35
29
|
else if (fnName.startsWith('execaCommand')) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
ctx.addScript(val);
|
|
40
|
-
}
|
|
30
|
+
const script = getScriptFromArg(node.arguments[0]);
|
|
31
|
+
if (script)
|
|
32
|
+
ctx.addScript(script);
|
|
41
33
|
}
|
|
42
34
|
else {
|
|
43
35
|
const script = getSafeScriptFromArgs(node.arguments[0], node.arguments[1]);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import MDX from '../../compilers/mdx.js';
|
|
2
|
+
import { hasDependency } from '../../util/plugin.js';
|
|
3
|
+
const title = 'Fumadocs';
|
|
4
|
+
const enablers = ['fumadocs-core', 'fumadocs-mdx', 'fumadocs-ui'];
|
|
5
|
+
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
6
|
+
const entry = ['source.config.{js,ts,mjs}', 'content/**/*.mdx'];
|
|
7
|
+
const registerCompilers = ({ registerCompiler, hasDependency }) => {
|
|
8
|
+
if (hasDependency('fumadocs-mdx'))
|
|
9
|
+
registerCompiler({ extension: '.mdx', compiler: MDX.compiler });
|
|
10
|
+
};
|
|
11
|
+
const plugin = {
|
|
12
|
+
title,
|
|
13
|
+
enablers,
|
|
14
|
+
isEnabled,
|
|
15
|
+
entry,
|
|
16
|
+
registerCompilers,
|
|
17
|
+
};
|
|
18
|
+
export default plugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { toDependency, toEntry } from '../../util/input.js';
|
|
1
|
+
import { toDependency, toEntry, toProductionEntry } from '../../util/input.js';
|
|
2
2
|
import { get } from '../../util/object.js';
|
|
3
|
-
import { isInternal } from '../../util/path.js';
|
|
3
|
+
import { isInternal, join } from '../../util/path.js';
|
|
4
4
|
import { hasDependency } from '../../util/plugin.js';
|
|
5
5
|
import { isConfigurationOutput, isGraphqlConfigTypes, isGraphqlProjectsConfigTypes } from './types.js';
|
|
6
6
|
const title = 'GraphQL Codegen';
|
|
@@ -24,15 +24,17 @@ const getPluginPackageName = (name) => {
|
|
|
24
24
|
return name;
|
|
25
25
|
return `@graphql-codegen/${name}`;
|
|
26
26
|
};
|
|
27
|
-
const resolveConfig = config => {
|
|
27
|
+
const resolveConfig = (config, options) => {
|
|
28
28
|
const codegenConfigs = isGraphqlProjectsConfigTypes(config)
|
|
29
29
|
? Object.values(config.projects).flatMap(project => project.extensions?.codegen ?? [])
|
|
30
30
|
: isGraphqlConfigTypes(config)
|
|
31
31
|
? [config.extensions?.codegen]
|
|
32
32
|
: [config];
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const generateConfigs = codegenConfigs.filter((config) => Boolean(config?.generates));
|
|
34
|
+
const generateSet = generateConfigs.flatMap(config => Object.values(config.generates));
|
|
35
|
+
const outputs = generateConfigs
|
|
36
|
+
.flatMap(config => Object.keys(config.generates))
|
|
37
|
+
.map(output => toProductionEntry(join(options.configFileDir, output.endsWith('/') ? `${output}**` : output)));
|
|
36
38
|
const configurationOutput = generateSet.filter(isConfigurationOutput);
|
|
37
39
|
const presets = configurationOutput
|
|
38
40
|
.map(configOutput => (configOutput.preset ? configOutput.preset : undefined))
|
|
@@ -58,7 +60,7 @@ const resolveConfig = config => {
|
|
|
58
60
|
return [toEntry(plugin)];
|
|
59
61
|
return [toDependency(getPluginPackageName(plugin))];
|
|
60
62
|
});
|
|
61
|
-
return [...presets, ...flatPlugins, ...nestedPlugins].map(id =>
|
|
63
|
+
return [...presets, ...flatPlugins, ...nestedPlugins, ...outputs].map(id => typeof id === 'string' ? toDependency(id) : id);
|
|
62
64
|
};
|
|
63
65
|
const plugin = {
|
|
64
66
|
title,
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare const Plugins: {
|
|
|
29
29
|
drizzle: import("../types/config.ts").Plugin;
|
|
30
30
|
eleventy: import("../types/config.ts").Plugin;
|
|
31
31
|
eslint: import("../types/config.ts").Plugin;
|
|
32
|
+
eve: import("../types/config.ts").Plugin;
|
|
32
33
|
execa: import("../types/config.ts").Plugin;
|
|
33
34
|
expo: import("../types/config.ts").Plugin;
|
|
34
35
|
'expressive-code': {
|
|
@@ -38,6 +39,7 @@ export declare const Plugins: {
|
|
|
38
39
|
config: string[];
|
|
39
40
|
};
|
|
40
41
|
fast: import("../types/config.ts").Plugin;
|
|
42
|
+
fumadocs: import("../types/config.ts").Plugin;
|
|
41
43
|
gatsby: import("../types/config.ts").Plugin;
|
|
42
44
|
'github-action': import("../types/config.ts").Plugin;
|
|
43
45
|
'github-actions': import("../types/config.ts").Plugin;
|
package/dist/plugins/index.js
CHANGED
|
@@ -28,10 +28,12 @@ import { default as dotenv } from './dotenv/index.js';
|
|
|
28
28
|
import { default as drizzle } from './drizzle/index.js';
|
|
29
29
|
import { default as eleventy } from './eleventy/index.js';
|
|
30
30
|
import { default as eslint } from './eslint/index.js';
|
|
31
|
+
import { default as eve } from './eve/index.js';
|
|
31
32
|
import { default as execa } from './execa/index.js';
|
|
32
33
|
import { default as expo } from './expo/index.js';
|
|
33
34
|
import { default as expressiveCode } from './expressive-code/index.js';
|
|
34
35
|
import { default as fast } from './fast/index.js';
|
|
36
|
+
import { default as fumadocs } from './fumadocs/index.js';
|
|
35
37
|
import { default as gatsby } from './gatsby/index.js';
|
|
36
38
|
import { default as githubAction } from './github-action/index.js';
|
|
37
39
|
import { default as githubActions } from './github-actions/index.js';
|
|
@@ -186,10 +188,12 @@ export const Plugins = {
|
|
|
186
188
|
drizzle,
|
|
187
189
|
eleventy,
|
|
188
190
|
eslint,
|
|
191
|
+
eve,
|
|
189
192
|
execa,
|
|
190
193
|
expo,
|
|
191
194
|
'expressive-code': expressiveCode,
|
|
192
195
|
fast,
|
|
196
|
+
fumadocs,
|
|
193
197
|
gatsby,
|
|
194
198
|
'github-action': githubAction,
|
|
195
199
|
'github-actions': githubActions,
|
|
@@ -3,6 +3,7 @@ import { _glob, _dirGlob } from '../../util/glob.js';
|
|
|
3
3
|
import { toDeferResolve, toEntry } from '../../util/input.js';
|
|
4
4
|
import { isInternal, join, normalize, toAbsolute } from '../../util/path.js';
|
|
5
5
|
import { hasDependency } from '../../util/plugin.js';
|
|
6
|
+
import { getDependenciesFromConfig } from '../babel/index.js';
|
|
6
7
|
import { getReportersDependencies, resolveExtensibleConfig } from './helpers.js';
|
|
7
8
|
const title = 'Jest';
|
|
8
9
|
const enablers = ['jest'];
|
|
@@ -11,6 +12,7 @@ const config = ['jest.config.{js,ts,mjs,cjs,mts,cts,json}', 'package.json'];
|
|
|
11
12
|
const mocks = ['**/__mocks__/**/*.[jt]s?(x)'];
|
|
12
13
|
const entry = ['**/__tests__/**/*.?(c|m)[jt]s?(x)', '**/?(*.)+(spec|test).?(c|m)[jt]s?(x)', ...mocks];
|
|
13
14
|
const rootDirRe = /<rootDir>/;
|
|
15
|
+
const isBabelJest = (transformer) => transformer[0] === 'babel-jest';
|
|
14
16
|
const resolveDependencies = async (config, rootDir, options) => {
|
|
15
17
|
const { configFileDir } = options;
|
|
16
18
|
if (config?.preset) {
|
|
@@ -46,9 +48,17 @@ const resolveDependencies = async (config, rootDir, options) => {
|
|
|
46
48
|
const resolvers = config.resolver ? [config.resolver] : [];
|
|
47
49
|
const reporters = getReportersDependencies(config, options);
|
|
48
50
|
const watchPlugins = config.watchPlugins?.map(watchPlugin => (typeof watchPlugin === 'string' ? watchPlugin : watchPlugin[0])) ?? [];
|
|
49
|
-
const transform =
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
const transform = [];
|
|
52
|
+
for (const transformer of config.transform ? Object.values(config.transform) : []) {
|
|
53
|
+
if (typeof transformer === 'string') {
|
|
54
|
+
transform.push(transformer);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
transform.push(transformer[0]);
|
|
58
|
+
if (isBabelJest(transformer))
|
|
59
|
+
transform.push(...getDependenciesFromConfig(transformer[1]));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
52
62
|
const moduleNameMapper = (config.moduleNameMapper
|
|
53
63
|
? Object.values(config.moduleNameMapper).map(mapper => (typeof mapper === 'string' ? mapper : mapper[0]))
|
|
54
64
|
: []).filter(value => !/\$[0-9]/.test(value));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDirectory } from '../../util/fs.js';
|
|
1
2
|
import { toConfig, toProductionEntry } from '../../util/input.js';
|
|
2
3
|
import { join } from '../../util/path.js';
|
|
3
4
|
import { hasDependency } from '../../util/plugin.js';
|
|
@@ -5,29 +6,41 @@ import { getPageExtensions } from './resolveFromAST.js';
|
|
|
5
6
|
const title = 'Next.js';
|
|
6
7
|
const enablers = ['next'];
|
|
7
8
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
8
|
-
const config = ['next.config.{js,ts,cjs,mjs}'];
|
|
9
|
+
const config = ['next.config.{js,ts,cjs,mjs,mts}'];
|
|
9
10
|
const defaultPageExtensions = ['{js,jsx,ts,tsx}'];
|
|
10
11
|
const productionEntryFilePatterns = [
|
|
11
12
|
'app/{,[(]*[)]/}{manifest,robots}.{js,ts}',
|
|
12
13
|
'app/**/sitemap.{js,ts}',
|
|
13
14
|
'app/**/{icon,apple-icon,opengraph-image,twitter-image}.{js,jsx,ts,tsx}',
|
|
14
15
|
];
|
|
15
|
-
const
|
|
16
|
+
const rootOrSrc = '{,src/}';
|
|
17
|
+
const getRouterDirPrefix = (cwd, name) => {
|
|
18
|
+
if (!cwd)
|
|
19
|
+
return rootOrSrc;
|
|
20
|
+
if (isDirectory(cwd, name))
|
|
21
|
+
return '';
|
|
22
|
+
if (isDirectory(cwd, `src/${name}`))
|
|
23
|
+
return 'src/';
|
|
24
|
+
return rootOrSrc;
|
|
25
|
+
};
|
|
26
|
+
const getEntryFilePatterns = (pageExtensions = defaultPageExtensions, cwd) => {
|
|
16
27
|
const ext = pageExtensions.length === 1 ? pageExtensions[0] : `{${pageExtensions.join(',')}}`;
|
|
28
|
+
const appDirPrefix = getRouterDirPrefix(cwd, 'app');
|
|
29
|
+
const pagesDirPrefix = getRouterDirPrefix(cwd, 'pages');
|
|
17
30
|
return [
|
|
18
|
-
...productionEntryFilePatterns,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
]
|
|
31
|
+
...productionEntryFilePatterns.map(pattern => `${appDirPrefix}${pattern}`),
|
|
32
|
+
`${rootOrSrc}{instrumentation,instrumentation-client,middleware,proxy}.${ext}`,
|
|
33
|
+
`${appDirPrefix}app/global-{error,not-found}.${ext}`,
|
|
34
|
+
`${appDirPrefix}app/**/{default,error,forbidden,loading,not-found,unauthorized}.${ext}`,
|
|
35
|
+
`${appDirPrefix}app/**/{layout,page,route,template}.${ext}`,
|
|
36
|
+
`${pagesDirPrefix}pages/**/*.${ext}`,
|
|
37
|
+
];
|
|
25
38
|
};
|
|
26
39
|
const production = getEntryFilePatterns();
|
|
27
40
|
const resolveFromAST = (program, { configFileDir }) => {
|
|
28
41
|
const pageExtensions = getPageExtensions(program);
|
|
29
42
|
const extensions = pageExtensions.length > 0 ? pageExtensions : defaultPageExtensions;
|
|
30
|
-
const patterns = [...getEntryFilePatterns(extensions), 'next-env.d.ts'];
|
|
43
|
+
const patterns = [...getEntryFilePatterns(extensions, configFileDir), 'next-env.d.ts'];
|
|
31
44
|
return patterns.map(id => toProductionEntry(join(configFileDir, id)));
|
|
32
45
|
};
|
|
33
46
|
const commands = new Set(['dev', 'build', 'start']);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toEntry, toProductionEntry } from '../../util/input.js';
|
|
2
|
+
import { getScriptCommands } from '../../util/scripts.js';
|
|
2
3
|
const title = 'Node.js';
|
|
3
4
|
const isEnabled = () => true;
|
|
4
5
|
const patterns = [
|
|
@@ -7,7 +8,9 @@ const patterns = [
|
|
|
7
8
|
'**/test.{cjs,mjs,js,cts,mts,ts}',
|
|
8
9
|
'**/test/**/*.{cjs,mjs,js,cts,mts,ts}',
|
|
9
10
|
];
|
|
10
|
-
const hasNodeTest = (scripts) => scripts &&
|
|
11
|
+
const hasNodeTest = (scripts) => scripts &&
|
|
12
|
+
Object.values(scripts).some(script => typeof script === 'string' &&
|
|
13
|
+
getScriptCommands(script).some(({ binary, args }) => (binary === 'node' || binary === 'nub') && args.includes('--test')));
|
|
11
14
|
const entry = ['server.js'];
|
|
12
15
|
const resolve = options => {
|
|
13
16
|
const entries = entry.map(id => toProductionEntry(id));
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import { isFile } from '../../util/fs.js';
|
|
2
|
+
import { toDependency, toEntry } from '../../util/input.js';
|
|
2
3
|
const title = 'pnpm';
|
|
4
|
+
const enablers = 'This plugin is enabled when a `pnpm-lock.yaml` or `pnpm-workspace.yaml` file is found in the root directory, or when `pnpm@` is specified in the `packageManager` field of `package.json`.';
|
|
3
5
|
const isEnabled = async ({ cwd, manifest }) => manifest.packageManager?.startsWith('pnpm@') || isFile(cwd, 'pnpm-lock.yaml') || isFile(cwd, 'pnpm-workspace.yaml');
|
|
4
6
|
const isRootOnly = true;
|
|
5
|
-
const
|
|
7
|
+
const entry = ['.pnpmfile.{cjs,mjs}'];
|
|
8
|
+
const config = ['package.json', 'pnpm-workspace.yaml'];
|
|
9
|
+
const resolveConfig = config => {
|
|
10
|
+
const inputs = entry.map(toEntry);
|
|
11
|
+
const packageExtensions = config?.pnpm?.packageExtensions || config?.packageExtensions;
|
|
12
|
+
if (packageExtensions) {
|
|
13
|
+
for (const extension of Object.values(packageExtensions)) {
|
|
14
|
+
if (extension.peerDependencies) {
|
|
15
|
+
for (const dep of Object.keys(extension.peerDependencies)) {
|
|
16
|
+
inputs.push(toDependency(dep));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return inputs;
|
|
22
|
+
};
|
|
6
23
|
const plugin = {
|
|
7
24
|
title,
|
|
25
|
+
enablers,
|
|
8
26
|
isEnabled,
|
|
9
27
|
isRootOnly,
|
|
28
|
+
entry,
|
|
10
29
|
config,
|
|
30
|
+
resolveConfig,
|
|
11
31
|
};
|
|
12
32
|
export default plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -12,9 +12,25 @@ const config = [
|
|
|
12
12
|
const resolveConfig = config => {
|
|
13
13
|
if (typeof config === 'string')
|
|
14
14
|
return [toDeferResolve(config)];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const result = new Set();
|
|
16
|
+
const processOptions = (options) => {
|
|
17
|
+
if (Array.isArray(options.plugins)) {
|
|
18
|
+
for (const plugin of options.plugins) {
|
|
19
|
+
if (typeof plugin === 'string') {
|
|
20
|
+
result.add(toDependency(plugin));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
processOptions(config);
|
|
26
|
+
if (config.overrides) {
|
|
27
|
+
for (const override of config.overrides) {
|
|
28
|
+
if (override.options) {
|
|
29
|
+
processOptions(override.options);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Array.from(result);
|
|
18
34
|
};
|
|
19
35
|
const args = {
|
|
20
36
|
config: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type PrettierOptions = {
|
|
2
2
|
plugins?: (string | {
|
|
3
3
|
parsers?: Record<string, unknown>;
|
|
4
4
|
printers?: Record<string, unknown>;
|
|
@@ -6,3 +6,8 @@ export type PrettierConfig = {
|
|
|
6
6
|
options?: Record<string, unknown>;
|
|
7
7
|
})[];
|
|
8
8
|
};
|
|
9
|
+
export type PrettierConfig = PrettierOptions & {
|
|
10
|
+
overrides?: {
|
|
11
|
+
options?: PrettierOptions;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { hasDependency } from '../../util/plugin.js';
|
|
2
2
|
import { findWebpackDependenciesFromConfig } from '../webpack/index.js';
|
|
3
|
+
import { createRequireContextVisitor } from '../webpack/visitors/requireContext.js';
|
|
3
4
|
const title = 'Rspack';
|
|
4
5
|
const enablers = ['@rspack/core'];
|
|
5
6
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
@@ -8,11 +9,15 @@ const resolveConfig = async (localConfig, options) => {
|
|
|
8
9
|
const inputs = await findWebpackDependenciesFromConfig(localConfig, options);
|
|
9
10
|
return inputs.filter(input => !input.specifier.startsWith('builtin:'));
|
|
10
11
|
};
|
|
12
|
+
const registerVisitors = ({ ctx, registerVisitor }) => {
|
|
13
|
+
registerVisitor(createRequireContextVisitor(ctx));
|
|
14
|
+
};
|
|
11
15
|
const plugin = {
|
|
12
16
|
title,
|
|
13
17
|
enablers,
|
|
14
18
|
isEnabled,
|
|
15
19
|
config,
|
|
16
20
|
resolveConfig,
|
|
21
|
+
registerVisitors,
|
|
17
22
|
};
|
|
18
23
|
export default plugin;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { arrayify } from '../../util/array.js';
|
|
1
2
|
import { toDependency, toProductionEntry } from '../../util/input.js';
|
|
2
3
|
import { isInternal, join } from '../../util/path.js';
|
|
3
4
|
import { hasDependency } from '../../util/plugin.js';
|
|
@@ -10,13 +11,23 @@ const handlerToEntry = (handler) => {
|
|
|
10
11
|
return toProductionEntry(`${handler.slice(0, dot)}.{js,ts}`);
|
|
11
12
|
};
|
|
12
13
|
const pluginToInput = (plugin, dir) => isInternal(plugin) ? toProductionEntry(join(dir, plugin)) : toDependency(plugin);
|
|
14
|
+
const getInjectEntries = (esbuild, dir) => esbuild && typeof esbuild === 'object' ? arrayify(esbuild.inject).map(id => toProductionEntry(join(dir, id))) : [];
|
|
13
15
|
const resolveConfig = async (config, options) => {
|
|
14
16
|
const functions = config.functions
|
|
15
17
|
? Object.values(config.functions).flatMap(fn => (fn.handler ? [handlerToEntry(fn.handler)] : []))
|
|
16
18
|
: [];
|
|
17
19
|
const plugins = config.plugins?.filter((plugin) => typeof plugin === 'string') ?? [];
|
|
18
20
|
const esbuild = config.custom?.esbuild || config.build?.esbuild ? [toDependency('esbuild', { optional: true })] : [];
|
|
19
|
-
|
|
21
|
+
const injectEntries = [
|
|
22
|
+
...getInjectEntries(config.custom?.esbuild, options.configFileDir),
|
|
23
|
+
...getInjectEntries(config.build?.esbuild, options.configFileDir),
|
|
24
|
+
];
|
|
25
|
+
return [
|
|
26
|
+
...functions,
|
|
27
|
+
...plugins.map(plugin => pluginToInput(plugin, options.configFileDir)),
|
|
28
|
+
...esbuild,
|
|
29
|
+
...injectEntries,
|
|
30
|
+
];
|
|
20
31
|
};
|
|
21
32
|
const plugin = {
|
|
22
33
|
title,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export type PluginConfig = {
|
|
2
2
|
build?: {
|
|
3
|
-
esbuild?:
|
|
3
|
+
esbuild?: EsbuildConfig;
|
|
4
4
|
};
|
|
5
5
|
custom?: {
|
|
6
|
-
esbuild?:
|
|
6
|
+
esbuild?: EsbuildConfig;
|
|
7
7
|
};
|
|
8
8
|
functions?: Record<string, ServerlessFunction>;
|
|
9
9
|
plugins?: unknown[];
|
|
10
10
|
};
|
|
11
|
+
export type EsbuildConfig = {
|
|
12
|
+
inject?: string[];
|
|
13
|
+
} | boolean;
|
|
11
14
|
type ServerlessFunction = {
|
|
12
15
|
handler?: string;
|
|
13
16
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import MDX from '../../compilers/mdx.js';
|
|
1
2
|
import { toConfig, toDeferResolve, toDependency, toEntry } from '../../util/input.js';
|
|
2
3
|
import { join, relative } from '../../util/path.js';
|
|
3
4
|
import { hasDependency } from '../../util/plugin.js';
|
|
@@ -54,6 +55,11 @@ const resolveConfig = async (localConfig, options) => {
|
|
|
54
55
|
...configs,
|
|
55
56
|
];
|
|
56
57
|
};
|
|
58
|
+
const registerCompilers = ({ registerCompiler, hasDependency }) => {
|
|
59
|
+
if (hasDependency('@storybook/addon-docs') || hasDependency('@storybook/addon-essentials')) {
|
|
60
|
+
registerCompiler({ extension: '.mdx', compiler: MDX.compiler });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
57
63
|
const plugin = {
|
|
58
64
|
title,
|
|
59
65
|
enablers,
|
|
@@ -62,5 +68,6 @@ const plugin = {
|
|
|
62
68
|
entry,
|
|
63
69
|
project,
|
|
64
70
|
resolveConfig,
|
|
71
|
+
registerCompilers,
|
|
65
72
|
};
|
|
66
73
|
export default plugin;
|