knip 5.71.0 → 5.72.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.
Files changed (52) hide show
  1. package/dist/ConfigurationChief.d.ts +6 -0
  2. package/dist/ConsoleStreamer.js +1 -1
  3. package/dist/compilers/index.d.ts +10 -0
  4. package/dist/compilers/index.js +3 -0
  5. package/dist/compilers/scss.d.ts +6 -0
  6. package/dist/compilers/scss.js +14 -0
  7. package/dist/graph/analyze.js +19 -8
  8. package/dist/graph-explorer/explorer.d.ts +1 -1
  9. package/dist/graph-explorer/explorer.js +1 -1
  10. package/dist/graph-explorer/operations/{build-trace-tree.d.ts → build-exports-tree.d.ts} +4 -1
  11. package/dist/graph-explorer/operations/build-exports-tree.js +96 -0
  12. package/dist/graph-explorer/operations/is-referenced.js +4 -4
  13. package/dist/graph-explorer/utils.d.ts +1 -2
  14. package/dist/graph-explorer/utils.js +0 -15
  15. package/dist/graph-explorer/walk-down.d.ts +2 -1
  16. package/dist/graph-explorer/walk-down.js +7 -10
  17. package/dist/plugins/index.d.ts +1 -0
  18. package/dist/plugins/index.js +2 -0
  19. package/dist/plugins/rsbuild/index.js +8 -0
  20. package/dist/plugins/rsbuild/types.d.ts +1 -0
  21. package/dist/plugins/storybook/index.js +12 -4
  22. package/dist/plugins/storybook/types.d.ts +5 -0
  23. package/dist/plugins/svgo/index.js +1 -1
  24. package/dist/plugins/svgr/index.d.ts +3 -0
  25. package/dist/plugins/svgr/index.js +24 -0
  26. package/dist/plugins/svgr/types.d.ts +3 -0
  27. package/dist/plugins/svgr/types.js +1 -0
  28. package/dist/plugins/vite/index.js +4 -0
  29. package/dist/plugins/vitest/index.js +1 -1
  30. package/dist/schema/configuration.d.ts +10 -0
  31. package/dist/schema/plugins.d.ts +5 -0
  32. package/dist/schema/plugins.js +1 -0
  33. package/dist/types/PluginNames.d.ts +2 -2
  34. package/dist/types/PluginNames.js +1 -0
  35. package/dist/types/module-graph.d.ts +2 -3
  36. package/dist/typescript/ast-helpers.d.ts +1 -1
  37. package/dist/typescript/ast-helpers.js +0 -3
  38. package/dist/typescript/get-imports-and-exports.js +74 -11
  39. package/dist/typescript/resolve-module-names.js +5 -4
  40. package/dist/util/Performance.js +4 -2
  41. package/dist/util/create-options.d.ts +10 -0
  42. package/dist/util/create-options.js +7 -3
  43. package/dist/util/module-graph.js +0 -1
  44. package/dist/util/resolve.d.ts +3 -2
  45. package/dist/util/resolve.js +25 -2
  46. package/dist/util/trace.d.ts +2 -10
  47. package/dist/util/trace.js +42 -36
  48. package/dist/version.d.ts +1 -1
  49. package/dist/version.js +1 -1
  50. package/package.json +7 -7
  51. package/schema.json +4 -0
  52. package/dist/graph-explorer/operations/build-trace-tree.js +0 -51
@@ -527,6 +527,11 @@ export declare class ConfigurationChief {
527
527
  entry?: string | string[] | undefined;
528
528
  project?: string | string[] | undefined;
529
529
  } | undefined;
530
+ svgr?: string | boolean | string[] | {
531
+ config?: string | string[] | undefined;
532
+ entry?: string | string[] | undefined;
533
+ project?: string | string[] | undefined;
534
+ } | undefined;
530
535
  syncpack?: string | boolean | string[] | {
531
536
  config?: string | string[] | undefined;
532
537
  entry?: string | string[] | undefined;
@@ -761,6 +766,7 @@ export declare class ConfigurationChief {
761
766
  stylelint?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
762
767
  svelte?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
763
768
  svgo?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
769
+ svgr?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
764
770
  syncpack?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
765
771
  tailwind?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
766
772
  taskfile?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -3,7 +3,7 @@ export class ConsoleStreamer {
3
3
  isWatch = false;
4
4
  lines = 0;
5
5
  constructor(options) {
6
- this.isEnabled = options.isShowProgress && !options.isDebug;
6
+ this.isEnabled = options.isShowProgress;
7
7
  this.isWatch = options.isWatch;
8
8
  }
9
9
  clearLines(count) {
@@ -479,6 +479,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
479
479
  entry?: string | string[] | undefined;
480
480
  project?: string | string[] | undefined;
481
481
  } | undefined;
482
+ svgr?: string | boolean | string[] | {
483
+ config?: string | string[] | undefined;
484
+ entry?: string | string[] | undefined;
485
+ project?: string | string[] | undefined;
486
+ } | undefined;
482
487
  syncpack?: string | boolean | string[] | {
483
488
  config?: string | string[] | undefined;
484
489
  entry?: string | string[] | undefined;
@@ -1075,6 +1080,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1075
1080
  entry?: string | string[] | undefined;
1076
1081
  project?: string | string[] | undefined;
1077
1082
  } | undefined;
1083
+ svgr?: string | boolean | string[] | {
1084
+ config?: string | string[] | undefined;
1085
+ entry?: string | string[] | undefined;
1086
+ project?: string | string[] | undefined;
1087
+ } | undefined;
1078
1088
  syncpack?: string | boolean | string[] | {
1079
1089
  config?: string | string[] | undefined;
1080
1090
  entry?: string | string[] | undefined;
@@ -2,6 +2,7 @@ import Astro from './astro.js';
2
2
  import AstroMDX from './astro-mdx.js';
3
3
  import MDX from './mdx.js';
4
4
  import Prisma from './prisma.js';
5
+ import SCSS from './scss.js';
5
6
  import Svelte from './svelte.js';
6
7
  import CSS from './tailwind.js';
7
8
  import Vue from './vue.js';
@@ -33,6 +34,8 @@ const compilers = new Map([
33
34
  ['.css', CSS],
34
35
  ['.mdx', MDX],
35
36
  ['.prisma', Prisma],
37
+ ['.sass', SCSS],
38
+ ['.scss', SCSS],
36
39
  ['.svelte', Svelte],
37
40
  ['.vue', Vue],
38
41
  ]);
@@ -0,0 +1,6 @@
1
+ import type { HasDependency } from './types.js';
2
+ declare const _default: {
3
+ condition: (hasDependency: HasDependency) => boolean;
4
+ compiler: (text: string) => string;
5
+ };
6
+ export default _default;
@@ -0,0 +1,14 @@
1
+ const condition = (hasDependency) => hasDependency('sass') || hasDependency('sass-embedded') || hasDependency('node-sass');
2
+ const importMatcher = /@(?:use|import|forward)\s+['"](pkg:)?([^'"]+)['"]/g;
3
+ const toRelative = (specifier) => (specifier.startsWith('.') ? specifier : `./${specifier}`);
4
+ const compiler = (text) => {
5
+ const imports = [];
6
+ let match;
7
+ let index = 0;
8
+ while ((match = importMatcher.exec(text))) {
9
+ if (match[2])
10
+ imports.push(`import _$${index++} from '${match[1] ? match[2] : toRelative(match[2])}';`);
11
+ }
12
+ return imports.join('\n');
13
+ };
14
+ export default { condition, compiler };
@@ -1,16 +1,17 @@
1
1
  import { createGraphExplorer } from '../graph-explorer/explorer.js';
2
2
  import { getIssueType, hasStrictlyEnumReferences } from '../graph-explorer/utils.js';
3
3
  import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
4
+ import { toRelative } from '../util/path.js';
4
5
  import { findMatch } from '../util/regex.js';
5
6
  import { getShouldIgnoreHandler, getShouldIgnoreTagHandler } from '../util/tag.js';
6
- import { printTraceNode } from '../util/trace.js';
7
+ import { formatTrace } from '../util/trace.js';
7
8
  export const analyze = async ({ analyzedFiles, counselor, chief, collector, deputy, entryPaths, factory, graph, streamer, unreferencedFiles, options, }) => {
8
9
  const shouldIgnore = getShouldIgnoreHandler(options.isProduction);
9
10
  const shouldIgnoreTags = getShouldIgnoreTagHandler(options.tags);
10
11
  const explorer = createGraphExplorer(graph, entryPaths);
11
12
  const ignoreExportsUsedInFile = chief.config.ignoreExportsUsedInFile;
12
- const isExportedItemReferenced = (exportedItem) => exportedItem.refs[1] ||
13
- (exportedItem.refs[0] > 0 &&
13
+ const isExportReferencedInFile = (exportedItem) => exportedItem.self[1] ||
14
+ (exportedItem.self[0] > 0 &&
14
15
  (typeof ignoreExportsUsedInFile === 'object'
15
16
  ? exportedItem.type !== 'unknown' && !!ignoreExportsUsedInFile[exportedItem.type]
16
17
  : ignoreExportsUsedInFile));
@@ -38,7 +39,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
38
39
  const [isReferenced, reExportingEntryFile] = explorer.isReferenced(filePath, identifier, {
39
40
  includeEntryExports: isIncludeEntryExports,
40
41
  });
41
- if ((isReferenced || exportedItem.refs[1]) && isIgnored) {
42
+ if ((isReferenced || exportedItem.self[1]) && isIgnored) {
42
43
  for (const tagName of exportedItem.jsDocTags) {
43
44
  if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
44
45
  collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
@@ -47,7 +48,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
47
48
  }
48
49
  if (isIgnored)
49
50
  continue;
50
- if (reExportingEntryFile) {
51
+ if (reExportingEntryFile && !isReferenced) {
51
52
  if (!isIncludeEntryExports) {
52
53
  continue;
53
54
  }
@@ -66,7 +67,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
66
67
  continue;
67
68
  if (shouldIgnore(member.jsDocTags))
68
69
  continue;
69
- if (member.refs[0] === 0) {
70
+ if (member.self[0] === 0) {
70
71
  const id = `${identifier}.${member.identifier}`;
71
72
  const [isMemberReferenced] = explorer.isReferenced(filePath, id, {
72
73
  includeEntryExports: true,
@@ -130,7 +131,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
130
131
  if (hasStrictlyNsRefs &&
131
132
  ((!options.includedIssueTypes.nsTypes && isType) || !(options.includedIssueTypes.nsExports || isType)))
132
133
  continue;
133
- if (!isExportedItemReferenced(exportedItem)) {
134
+ if (!isExportReferencedInFile(exportedItem)) {
134
135
  if (isIgnored)
135
136
  continue;
136
137
  if (!options.isSkipLibs && principal?.hasExternalReferences(filePath, exportedItem))
@@ -229,8 +230,18 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
229
230
  await analyzeGraph();
230
231
  if (options.isTrace) {
231
232
  const nodes = explorer.buildExportsTree({ filePath: options.traceFile, identifier: options.traceExport });
233
+ nodes.sort((a, b) => a.filePath.localeCompare(b.filePath) || a.identifier.localeCompare(b.identifier));
234
+ const toRel = (path) => toRelative(path, options.cwd);
235
+ const isReferenced = (node) => {
236
+ if (explorer.isReferenced(node.filePath, node.identifier, { includeEntryExports: false })[0])
237
+ return true;
238
+ if (explorer.hasStrictlyNsReferences(node.filePath, node.identifier)[0])
239
+ return true;
240
+ const exportItem = graph.get(node.filePath)?.exports.get(node.identifier);
241
+ return exportItem ? isExportReferencedInFile(exportItem) : false;
242
+ };
232
243
  for (const node of nodes)
233
- printTraceNode(node, options);
244
+ console.log(formatTrace(node, toRel, isReferenced(node)));
234
245
  }
235
246
  return analyzeGraph;
236
247
  };
@@ -7,5 +7,5 @@ export declare const createGraphExplorer: (graph: ModuleGraph, entryPaths: Set<s
7
7
  buildExportsTree: (options: {
8
8
  filePath?: string;
9
9
  identifier?: string;
10
- }) => import("./operations/build-trace-tree.js").TreeNode[];
10
+ }) => import("./operations/build-exports-tree.js").TreeNode[];
11
11
  };
@@ -1,4 +1,4 @@
1
- import { buildExportsTree } from './operations/build-trace-tree.js';
1
+ import { buildExportsTree } from './operations/build-exports-tree.js';
2
2
  import { hasStrictlyNsReferences } from './operations/has-strictly-ns-references.js';
3
3
  import { isReferenced } from './operations/is-referenced.js';
4
4
  export const createGraphExplorer = (graph, entryPaths) => {
@@ -1,8 +1,11 @@
1
1
  import type { Identifier, ModuleGraph } from '../../types/module-graph.js';
2
+ import type { Via } from '../walk-down.js';
2
3
  export interface TreeNode {
3
4
  filePath: string;
4
5
  identifier: string;
5
- hasRef: boolean;
6
+ originalId: string | undefined;
7
+ via: Via | undefined;
8
+ refs: string[];
6
9
  isEntry: boolean;
7
10
  children: TreeNode[];
8
11
  }
@@ -0,0 +1,96 @@
1
+ import { CONTINUE } from '../constants.js';
2
+ import { walkDown } from '../walk-down.js';
3
+ export const buildExportsTree = (graph, entryPaths, options) => {
4
+ const traces = [];
5
+ const processFile = (filePath, file) => {
6
+ for (const exportId of options.identifier ? [options.identifier] : file.exports.keys()) {
7
+ if (!options.identifier || file.exports.has(exportId)) {
8
+ const trace = buildExportTree(graph, entryPaths, filePath, exportId);
9
+ if (trace)
10
+ traces.push(trace);
11
+ }
12
+ }
13
+ };
14
+ if (options.filePath) {
15
+ const file = graph.get(options.filePath);
16
+ if (file)
17
+ processFile(options.filePath, file);
18
+ }
19
+ else {
20
+ for (const [filePath, file] of graph)
21
+ processFile(filePath, file);
22
+ }
23
+ return traces;
24
+ };
25
+ const buildExportTree = (graph, entryPaths, filePath, identifier) => {
26
+ const file = graph.get(filePath);
27
+ const rootNode = {
28
+ filePath,
29
+ identifier,
30
+ refs: filterRefs(file?.imported?.refs, identifier),
31
+ isEntry: entryPaths.has(filePath),
32
+ children: [],
33
+ originalId: undefined,
34
+ via: undefined,
35
+ };
36
+ const nodeMap = new Map();
37
+ nodeMap.set(`${filePath}:${identifier}`, rootNode);
38
+ walkDown(graph, filePath, identifier, (sourceFile, sourceId, importingFile, id, isEntry, via) => {
39
+ const importMaps = graph.get(importingFile)?.imports.internal.get(sourceFile);
40
+ const importRefs = importMaps?.refs;
41
+ const ns = id.split('.')[0];
42
+ if (via === 'importNS' && !hasRelevantRef(importRefs, id) && !isNsReExported(importMaps, ns))
43
+ return CONTINUE;
44
+ const key = `${importingFile}:${id}`;
45
+ const isRenamed = via.endsWith('As') && sourceId !== ns;
46
+ const refs = filterRefs(importRefs, id);
47
+ const childNode = nodeMap.get(key) ?? {
48
+ filePath: importingFile,
49
+ identifier: id,
50
+ originalId: isRenamed ? sourceId : undefined,
51
+ via,
52
+ refs,
53
+ isEntry,
54
+ children: [],
55
+ };
56
+ nodeMap.set(key, childNode);
57
+ let parentNode = nodeMap.get(`${sourceFile}:${sourceId}`);
58
+ if (!parentNode) {
59
+ for (const [k, v] of nodeMap) {
60
+ if (k.startsWith(`${sourceFile}:${sourceId}.`) || k === `${sourceFile}:${sourceId}`) {
61
+ parentNode = v;
62
+ break;
63
+ }
64
+ }
65
+ }
66
+ (parentNode ?? rootNode).children.push(childNode);
67
+ return CONTINUE;
68
+ }, entryPaths);
69
+ pruneReExportStarOnlyBranches(rootNode);
70
+ return rootNode;
71
+ };
72
+ const filterRefs = (refs, id) => {
73
+ if (!refs)
74
+ return [];
75
+ return Array.from(refs).filter(ref => id === ref || id.startsWith(`${ref}.`) || ref.startsWith(`${id}.`));
76
+ };
77
+ const hasRelevantRef = (refs, id) => {
78
+ if (!refs || refs.size === 0)
79
+ return false;
80
+ return Array.from(refs).some(ref => ref === id || ref.startsWith(`${id}.`));
81
+ };
82
+ const isNsReExported = (importMaps, ns) => {
83
+ if (!importMaps)
84
+ return false;
85
+ return importMaps.reExportedAs.has(ns) || importMaps.reExportedNs.has(ns);
86
+ };
87
+ const hasNonReExportStar = (node) => {
88
+ if (node.via && node.via !== 'reExportStar')
89
+ return true;
90
+ return node.children.some(child => hasNonReExportStar(child));
91
+ };
92
+ const pruneReExportStarOnlyBranches = (node) => {
93
+ node.children = node.children.filter(child => hasNonReExportStar(child));
94
+ for (const child of node.children)
95
+ pruneReExportStarOnlyBranches(child);
96
+ };
@@ -5,8 +5,6 @@ export const isReferenced = (graph, entryPaths, filePath, id, options) => {
5
5
  const check = (currentPath, currentId) => {
6
6
  const isEntryFile = entryPaths.has(currentPath);
7
7
  let reExportingEntryFile = isEntryFile ? currentPath : undefined;
8
- if (isEntryFile && !options.includeEntryExports)
9
- return [false, reExportingEntryFile];
10
8
  if (seen.has(currentPath))
11
9
  return [false, reExportingEntryFile];
12
10
  seen.add(currentPath);
@@ -16,8 +14,6 @@ export const isReferenced = (graph, entryPaths, filePath, id, options) => {
16
14
  if (!identifier || !file) {
17
15
  return [false, reExportingEntryFile];
18
16
  }
19
- const directSources = getPassThroughReExportSources(file, identifier);
20
- const starSources = getStarReExportSources(file);
21
17
  const followSources = (sources, nextId) => {
22
18
  for (const byFilePath of sources) {
23
19
  if (seen.has(byFilePath))
@@ -62,6 +58,8 @@ export const isReferenced = (graph, entryPaths, filePath, id, options) => {
62
58
  return [true, reExportingEntryFile];
63
59
  }
64
60
  }
61
+ if (isEntryFile && !options.includeEntryExports)
62
+ return [false, reExportingEntryFile];
65
63
  const aliasMap = getAliasReExportMap(file, identifier);
66
64
  if (aliasMap) {
67
65
  for (const [alias, sources] of aliasMap) {
@@ -70,6 +68,8 @@ export const isReferenced = (graph, entryPaths, filePath, id, options) => {
70
68
  return [true, reExportingEntryFile];
71
69
  }
72
70
  }
71
+ const directSources = getPassThroughReExportSources(file, identifier);
72
+ const starSources = getStarReExportSources(file);
73
73
  if (directSources) {
74
74
  if (followSources(directSources, currentId))
75
75
  return [true, reExportingEntryFile];
@@ -1,4 +1,3 @@
1
- import type { ImportMaps, ModuleGraph } from '../types/module-graph.js';
2
- export declare const hasNamespaceMemberReference: (graph: ModuleGraph, importingFile: string, importedFile: string, namespace: string, member: string) => boolean | null;
1
+ import type { ImportMaps } from '../types/module-graph.js';
3
2
  export declare const hasStrictlyEnumReferences: (importsForExport: ImportMaps | undefined, identifier: string) => boolean;
4
3
  export declare const getIssueType: (hasOnlyNsReference: boolean, isType: boolean) => "exports" | "nsExports" | "types" | "nsTypes";
@@ -1,18 +1,3 @@
1
- import { OPAQUE } from '../constants.js';
2
- export const hasNamespaceMemberReference = (graph, importingFile, importedFile, namespace, member) => {
3
- const importerNode = graph.get(importingFile);
4
- if (!importerNode)
5
- return null;
6
- const importMap = importerNode.imports.internal.get(importedFile);
7
- if (!importMap)
8
- return null;
9
- if (importMap.imported.get(OPAQUE))
10
- return true;
11
- if (importMap.refs.size === 0)
12
- return false;
13
- const refKey = member ? `${namespace}.${member}` : namespace;
14
- return refKey ? importMap.refs.has(refKey) : null;
15
- };
16
1
  export const hasStrictlyEnumReferences = (importsForExport, identifier) => {
17
2
  if (!importsForExport || !importsForExport.refs.has(identifier))
18
3
  return false;
@@ -1,4 +1,5 @@
1
1
  import type { ModuleGraph } from '../types/module-graph.js';
2
- type Visitor = (sourceFile: string, identifier: string, importingFile: string, identifierPath: string, isEntry: boolean, isReExport: boolean) => 'continue' | 'stop' | undefined;
2
+ export type Via = 'import' | 'importAs' | 'importNS' | 'reExport' | 'reExportAs' | 'reExportNS' | 'reExportStar';
3
+ type Visitor = (sourceFile: string, identifier: string, importingFile: string, identifierPath: string, isEntry: boolean, via: Via) => 'continue' | 'stop' | undefined;
3
4
  export declare const walkDown: (graph: ModuleGraph, filePath: string, identifier: string, visitor: Visitor, entryPaths: Set<string>, visited?: Set<string>) => boolean;
4
5
  export {};
@@ -1,5 +1,4 @@
1
1
  import { STOP } from './constants.js';
2
- import { hasNamespaceMemberReference } from './utils.js';
3
2
  import { getAliasReExportMap, getPassThroughReExportSources, getStarReExportSources } from './visitors.js';
4
3
  export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visited = new Set()) => {
5
4
  const key = `${filePath}:${identifier}`;
@@ -18,7 +17,7 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
18
17
  if (importedByFiles) {
19
18
  for (const importingFile of importedByFiles) {
20
19
  const isEntry = entryPaths.has(importingFile);
21
- if (visitor(filePath, id, importingFile, id, isEntry, false) === STOP)
20
+ if (visitor(filePath, id, importingFile, id, isEntry, 'import') === STOP)
22
21
  return true;
23
22
  }
24
23
  }
@@ -27,17 +26,15 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
27
26
  for (const [alias, byFilePaths] of importedAsAliases) {
28
27
  for (const importingFile of byFilePaths) {
29
28
  const isEntry = entryPaths.has(importingFile);
30
- if (visitor(filePath, id, importingFile, alias, isEntry, false) === STOP)
29
+ if (visitor(filePath, id, importingFile, alias, isEntry, 'importAs') === STOP)
31
30
  return true;
32
31
  }
33
32
  }
34
33
  }
35
34
  for (const [namespace, byFilePaths] of imported.importedNs) {
36
35
  for (const importingFile of byFilePaths) {
37
- if (hasNamespaceMemberReference(graph, importingFile, filePath, namespace, identifier) === false)
38
- continue;
39
36
  const isEntry = entryPaths.has(importingFile);
40
- if (visitor(filePath, identifier, importingFile, `${namespace}.${identifier}`, isEntry, false) === STOP) {
37
+ if (visitor(filePath, identifier, importingFile, `${namespace}.${identifier}`, isEntry, 'importNS') === STOP) {
41
38
  return true;
42
39
  }
43
40
  }
@@ -48,7 +45,7 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
48
45
  if (passThroughSources) {
49
46
  for (const reExportingFile of passThroughSources) {
50
47
  const isEntry = entryPaths.has(reExportingFile);
51
- if (visitor(filePath, id, reExportingFile, id, isEntry, true) === STOP) {
48
+ if (visitor(filePath, id, reExportingFile, id, isEntry, 'reExport') === STOP) {
52
49
  done = true;
53
50
  break;
54
51
  }
@@ -65,7 +62,7 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
65
62
  for (const [alias, sources] of aliasReExportMap) {
66
63
  for (const reExportingFile of sources) {
67
64
  const isEntry = entryPaths.has(reExportingFile);
68
- if (visitor(filePath, id, reExportingFile, alias, isEntry, true) === STOP) {
65
+ if (visitor(filePath, id, reExportingFile, alias, isEntry, 'reExportAs') === STOP) {
69
66
  done = true;
70
67
  break;
71
68
  }
@@ -86,7 +83,7 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
86
83
  for (const [namespace, sources] of imported.reExportedNs) {
87
84
  for (const reExportingFile of sources) {
88
85
  const isEntry = entryPaths.has(reExportingFile);
89
- if (visitor(filePath, identifier, reExportingFile, `${namespace}.${identifier}`, isEntry, true) === STOP) {
86
+ if (visitor(filePath, identifier, reExportingFile, `${namespace}.${identifier}`, isEntry, 'reExportNS') === STOP) {
90
87
  done = true;
91
88
  break;
92
89
  }
@@ -104,7 +101,7 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
104
101
  if (starSources) {
105
102
  for (const reExportingFile of starSources) {
106
103
  const isEntry = entryPaths.has(reExportingFile);
107
- if (visitor(filePath, id, reExportingFile, id, isEntry, true) === STOP) {
104
+ if (visitor(filePath, id, reExportingFile, id, isEntry, 'reExportStar') === STOP) {
108
105
  done = true;
109
106
  break;
110
107
  }
@@ -94,6 +94,7 @@ export declare const Plugins: {
94
94
  stylelint: import("../types/config.js").Plugin;
95
95
  svelte: import("../types/config.js").Plugin;
96
96
  svgo: import("../types/config.js").Plugin;
97
+ svgr: import("../types/config.js").Plugin;
97
98
  syncpack: import("../types/config.js").Plugin;
98
99
  tailwind: import("../types/config.js").Plugin;
99
100
  taskfile: import("../types/config.js").Plugin;
@@ -93,6 +93,7 @@ import { default as stryker } from './stryker/index.js';
93
93
  import { default as stylelint } from './stylelint/index.js';
94
94
  import { default as svelte } from './svelte/index.js';
95
95
  import { default as svgo } from './svgo/index.js';
96
+ import { default as svgr } from './svgr/index.js';
96
97
  import { default as syncpack } from './syncpack/index.js';
97
98
  import { default as tailwind } from './tailwind/index.js';
98
99
  import { default as taskfile } from './taskfile/index.js';
@@ -213,6 +214,7 @@ export const Plugins = {
213
214
  stylelint,
214
215
  svelte,
215
216
  svgo,
217
+ svgr,
216
218
  syncpack,
217
219
  tailwind,
218
220
  taskfile,
@@ -23,6 +23,14 @@ const resolveConfig = async (config) => {
23
23
  }
24
24
  }
25
25
  }
26
+ if (source?.preEntry) {
27
+ const entry = source.preEntry;
28
+ if (typeof entry === 'string')
29
+ entries.add(entry);
30
+ else if (Array.isArray(entry))
31
+ for (const e of entry)
32
+ entries.add(e);
33
+ }
26
34
  };
27
35
  checkSource(config.source);
28
36
  if (config.environments) {
@@ -6,6 +6,7 @@ export type RsbuildConfig = {
6
6
  plugins?: unknown[];
7
7
  source?: {
8
8
  entry?: Entry;
9
+ preEntry?: string | string[];
9
10
  };
10
11
  environments?: {
11
12
  [k: string]: Pick<RsbuildConfig, 'plugins' | 'source'>;
@@ -1,4 +1,4 @@
1
- import { toDeferResolve, toDependency, toEntry } from '../../util/input.js';
1
+ import { toConfig, toDeferResolve, toDependency, toEntry } from '../../util/input.js';
2
2
  import { join, relative } from '../../util/path.js';
3
3
  import { hasDependency } from '../../util/plugin.js';
4
4
  const title = 'Storybook';
@@ -10,7 +10,7 @@ const restEntry = ['.{storybook,rnstorybook}/{manager,preview,index,vitest.setup
10
10
  const entry = [...restEntry, ...stories];
11
11
  const project = ['.{storybook,rnstorybook}/**/*.{js,jsx,ts,tsx,mts}'];
12
12
  const resolveConfig = async (localConfig, options) => {
13
- const { cwd, configFileDir } = options;
13
+ const { cwd, configFileDir, configFilePath } = options;
14
14
  const strs = typeof localConfig?.stories === 'function' ? await localConfig.stories(stories) : localConfig?.stories;
15
15
  const relativePatterns = strs?.map(pattern => {
16
16
  if (typeof pattern === 'string')
@@ -29,13 +29,21 @@ const resolveConfig = async (localConfig, options) => {
29
29
  ? [`@storybook/builder-${builder}`, `@storybook/manager-${builder}`]
30
30
  : [builder]
31
31
  : [];
32
- const framework = typeof localConfig.framework === 'string' ? localConfig.framework : localConfig.framework?.name;
33
- const frameworks = framework ? [framework] : [];
32
+ const framework = localConfig.framework;
33
+ const frameworkName = typeof framework === 'string' ? framework : framework?.name;
34
+ const frameworks = frameworkName ? [frameworkName] : [];
35
+ const viteConfigPath = typeof framework === 'object' &&
36
+ framework?.name === '@storybook/react-vite' &&
37
+ framework?.options?.builder?.viteConfigPath;
38
+ const configs = viteConfigPath
39
+ ? [toConfig('vite', viteConfigPath, { dir: cwd, containingFilePath: configFilePath })]
40
+ : [];
34
41
  return [
35
42
  ...patterns.map(id => toEntry(id)),
36
43
  ...addons.map(id => toDeferResolve(id)),
37
44
  ...builderPackages.map(id => toDependency(id)),
38
45
  ...frameworks.map(id => toDependency(id)),
46
+ ...configs,
39
47
  ];
40
48
  };
41
49
  const plugin = {
@@ -15,6 +15,11 @@ export type StorybookConfig = {
15
15
  };
16
16
  framework?: string | {
17
17
  name?: string;
18
+ options?: {
19
+ builder?: {
20
+ viteConfigPath?: string;
21
+ };
22
+ };
18
23
  };
19
24
  };
20
25
  export {};
@@ -1,6 +1,6 @@
1
1
  import { hasDependency } from '../../util/plugin.js';
2
2
  const title = 'SVGO';
3
- const enablers = ['svgo'];
3
+ const enablers = ['svgo', '@svgr/plugin-svgo'];
4
4
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
5
  const entry = ['svgo.config.{js,cjs,mjs}'];
6
6
  const plugin = {
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.js';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,24 @@
1
+ import { toDependency } from '../../util/input.js';
2
+ import { hasDependency } from '../../util/plugin.js';
3
+ const title = 'SVGR';
4
+ const enablers = ['@svgr/cli', '@svgr/core'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const config = ['.svgrrc', '.svgrrc.{yaml,yml,json,js}', 'svgr.config.{js,cjs}', 'package.json'];
7
+ const resolveConfig = async (config) => {
8
+ const inputs = [];
9
+ if (config.plugins) {
10
+ for (const plugin of config.plugins) {
11
+ if (typeof plugin === 'string')
12
+ inputs.push(toDependency(plugin));
13
+ }
14
+ }
15
+ return inputs;
16
+ };
17
+ const plugin = {
18
+ title,
19
+ enablers,
20
+ isEnabled,
21
+ config,
22
+ resolveConfig,
23
+ };
24
+ export default plugin;
@@ -0,0 +1,3 @@
1
+ export type SvgrConfig = {
2
+ plugins?: (string | unknown)[];
3
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -10,6 +10,9 @@ const resolveFromAST = (sourceFile) => {
10
10
  const babelPlugins = getReactBabelPlugins(sourceFile);
11
11
  return babelPlugins.map(plugin => toDependency(plugin));
12
12
  };
13
+ const args = {
14
+ config: true,
15
+ };
13
16
  const plugin = {
14
17
  title,
15
18
  enablers,
@@ -17,5 +20,6 @@ const plugin = {
17
20
  config,
18
21
  resolveConfig,
19
22
  resolveFromAST,
23
+ args,
20
24
  };
21
25
  export default plugin;
@@ -13,7 +13,7 @@ const entry = ['**/*.{bench,test,test-d,spec}.?(c|m)[jt]s?(x)', ...mocks];
13
13
  const isVitestCoverageCommand = /vitest(.+)--coverage(?:\.enabled(?:=true)?)?/;
14
14
  const hasScriptWithCoverage = (scripts) => scripts ? Object.values(scripts).some(script => isVitestCoverageCommand.test(script)) : false;
15
15
  const findConfigDependencies = (localConfig, options) => {
16
- const { manifest, cwd: dir } = options;
16
+ const { manifest, configFileDir: dir } = options;
17
17
  const testConfig = localConfig.test;
18
18
  if (!testConfig)
19
19
  return [];
@@ -477,6 +477,11 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
477
477
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
478
478
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
479
479
  }, z.core.$strip>]>>;
480
+ svgr: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
481
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
482
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
483
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
484
+ }, z.core.$strip>]>>;
480
485
  syncpack: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
481
486
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
482
487
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -1073,6 +1078,11 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
1073
1078
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1074
1079
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1075
1080
  }, z.core.$strip>]>>;
1081
+ svgr: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
1082
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1083
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1084
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1085
+ }, z.core.$strip>]>>;
1076
1086
  syncpack: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
1077
1087
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1078
1088
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;