knip 5.50.4 → 5.51.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 (68) hide show
  1. package/README.md +1 -1
  2. package/dist/ConfigurationChief.d.ts +4 -1
  3. package/dist/ConfigurationChief.js +3 -0
  4. package/dist/DependencyDeputy.js +11 -0
  5. package/dist/binaries/fallback.js +1 -1
  6. package/dist/binaries/package-manager/bun.js +2 -0
  7. package/dist/cli.js +3 -3
  8. package/dist/compilers/astro.js +5 -1
  9. package/dist/compilers/compilers.js +1 -1
  10. package/dist/compilers/index.d.ts +44 -13
  11. package/dist/compilers/index.js +9 -6
  12. package/dist/compilers/types.d.ts +1 -0
  13. package/dist/graph/build.js +8 -4
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +9 -1
  16. package/dist/plugins/bun/index.d.ts +11 -0
  17. package/dist/plugins/bun/index.js +28 -0
  18. package/dist/plugins/eslint/index.js +1 -2
  19. package/dist/plugins/index.d.ts +37 -10
  20. package/dist/plugins/index.js +8 -2
  21. package/dist/plugins/lint-staged/index.d.ts +0 -1
  22. package/dist/plugins/lint-staged/index.js +0 -2
  23. package/dist/plugins/nano-staged/index.d.ts +10 -0
  24. package/dist/plugins/nano-staged/index.js +33 -0
  25. package/dist/plugins/nano-staged/types.d.ts +7 -0
  26. package/dist/plugins/next/index.js +2 -1
  27. package/dist/plugins/oxlint/index.d.ts +12 -0
  28. package/dist/plugins/oxlint/index.js +16 -0
  29. package/dist/plugins/preconstruct/index.js +2 -2
  30. package/dist/plugins/prettier/index.js +1 -1
  31. package/dist/plugins/relay/index.d.ts +15 -0
  32. package/dist/plugins/relay/index.js +31 -0
  33. package/dist/plugins/relay/types.d.ts +12 -0
  34. package/dist/plugins/relay/types.js +1 -0
  35. package/dist/plugins/tsup/index.js +1 -1
  36. package/dist/plugins/xo/index.js +1 -1
  37. package/dist/schema/configuration.d.ts +241 -70
  38. package/dist/schema/configuration.js +2 -1
  39. package/dist/schema/plugins.d.ts +92 -23
  40. package/dist/schema/plugins.js +4 -1
  41. package/dist/types/PluginNames.d.ts +2 -2
  42. package/dist/types/PluginNames.js +4 -1
  43. package/dist/types/config.d.ts +1 -0
  44. package/dist/typescript/ast-helpers.d.ts +16 -3
  45. package/dist/typescript/ast-helpers.js +21 -15
  46. package/dist/typescript/visitors/dynamic-imports/importCall.js +47 -53
  47. package/dist/typescript/visitors/exports/exportAssignment.js +17 -2
  48. package/dist/typescript/visitors/exports/exportKeyword.js +3 -22
  49. package/dist/util/cli-arguments.d.ts +1 -1
  50. package/dist/util/cli-arguments.js +1 -1
  51. package/dist/util/codeowners.js +1 -1
  52. package/dist/util/glob-core.d.ts +0 -8
  53. package/dist/util/glob-core.js +16 -49
  54. package/dist/util/input.d.ts +3 -1
  55. package/dist/util/parse-and-convert-gitignores.d.ts +8 -0
  56. package/dist/util/parse-and-convert-gitignores.js +40 -0
  57. package/dist/util/to-source-path.d.ts +1 -1
  58. package/dist/util/to-source-path.js +2 -2
  59. package/dist/version.d.ts +1 -1
  60. package/dist/version.js +1 -1
  61. package/package.json +4 -3
  62. package/schema.json +20 -4
  63. package/dist/plugins/tanstack-router/index.d.ts +0 -12
  64. package/dist/plugins/tanstack-router/index.js +0 -46
  65. package/dist/plugins/tanstack-router/resolveFromAST.d.ts +0 -2
  66. package/dist/plugins/tanstack-router/resolveFromAST.js +0 -28
  67. package/dist/plugins/tanstack-router/types.d.ts +0 -7
  68. /package/dist/plugins/{tanstack-router → nano-staged}/types.js +0 -0
@@ -1,7 +1,7 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import picomatch from 'picomatch';
3
3
  import { debugLog } from './debug.js';
4
- import { convertGitignoreToPicomatchIgnorePatterns } from './glob-core.js';
4
+ import { convertGitignoreToPicomatchIgnorePatterns } from './parse-and-convert-gitignores.js';
5
5
  export function parseCodeowners(content) {
6
6
  const matchers = content
7
7
  .split(/\r?\n/)
@@ -10,14 +10,6 @@ type GlobOptions = {
10
10
  label?: string;
11
11
  } & FastGlobOptionsWithoutCwd;
12
12
  type FastGlobOptionsWithoutCwd = Pick<FastGlobOptions, 'onlyDirectories' | 'ignore' | 'absolute' | 'dot'>;
13
- export declare const convertGitignoreToPicomatchIgnorePatterns: (pattern: string) => {
14
- negated: boolean;
15
- patterns: string[];
16
- };
17
- export declare const parseAndConvertGitignorePatterns: (patterns: string, ancestor?: string) => {
18
- negated: boolean;
19
- patterns: string[];
20
- }[];
21
13
  export declare const findAndParseGitignores: (cwd: string) => Promise<{
22
14
  gitignoreFiles: string[];
23
15
  ignores: Set<string>;
@@ -8,51 +8,12 @@ import { timerify } from './Performance.js';
8
8
  import { compact } from './array.js';
9
9
  import { debugLogObject } from './debug.js';
10
10
  import { isFile } from './fs.js';
11
+ import { parseAndConvertGitignorePatterns } from './parse-and-convert-gitignores.js';
11
12
  import { dirname, join, relative, toPosix } from './path.js';
12
13
  const walk = promisify(_walk);
13
14
  const _picomatch = timerify(picomatch);
14
15
  const cachedGitIgnores = new Map();
15
16
  const cachedGlobIgnores = new Map();
16
- export const convertGitignoreToPicomatchIgnorePatterns = (pattern) => {
17
- const negated = pattern[0] === '!';
18
- if (negated)
19
- pattern = pattern.slice(1);
20
- let extPattern;
21
- if (pattern.endsWith('/'))
22
- pattern = pattern.slice(0, -1);
23
- if (pattern.startsWith('*/**/'))
24
- pattern = pattern.slice(5);
25
- if (pattern.startsWith('/'))
26
- pattern = pattern.slice(1);
27
- else if (!pattern.startsWith('**/'))
28
- pattern = `**/${pattern}`;
29
- if (pattern.endsWith('/*'))
30
- extPattern = pattern;
31
- else
32
- extPattern = `${pattern}/**`;
33
- return { negated, patterns: [pattern, extPattern] };
34
- };
35
- export const parseAndConvertGitignorePatterns = (patterns, ancestor) => {
36
- const matchFrom = ancestor ? new RegExp(`^(!?/?)(${ancestor})`) : undefined;
37
- return patterns
38
- .split(/\r?\n/)
39
- .filter(line => line.trim() && !line.startsWith('#'))
40
- .flatMap(line => {
41
- const pattern = line.replace(/^\\(?=#)/, '').trim();
42
- if (ancestor && matchFrom) {
43
- if (pattern.match(matchFrom))
44
- return [pattern.replace(matchFrom, '$1')];
45
- if (pattern.startsWith('/**/'))
46
- return [pattern.slice(1)];
47
- if (pattern.startsWith('!/**/'))
48
- return [`!${pattern.slice(2)}`];
49
- if (pattern.startsWith('/') || pattern.startsWith('!/'))
50
- return [];
51
- }
52
- return [pattern];
53
- })
54
- .map(pattern => convertGitignoreToPicomatchIgnorePatterns(pattern));
55
- };
56
17
  const findAncestorGitignoreFiles = (cwd) => {
57
18
  const gitignorePaths = [];
58
19
  let dir = dirname(cwd);
@@ -129,7 +90,7 @@ export const findAndParseGitignores = async (cwd) => {
129
90
  }
130
91
  const cacheDir = ancestor ? cwd : dir;
131
92
  const cacheForDir = cachedGitIgnores.get(cwd);
132
- if (ancestor && cacheForDir) {
93
+ if (cacheForDir) {
133
94
  for (const pattern of dirIgnores)
134
95
  cacheForDir?.ignores.add(pattern);
135
96
  cacheForDir.unignores = Array.from(new Set([...cacheForDir.unignores, ...dirUnignores]));
@@ -162,9 +123,9 @@ const _parseFindGitignores = timerify(findAndParseGitignores);
162
123
  export async function glob(patterns, options) {
163
124
  if (Array.isArray(patterns) && patterns.length === 0)
164
125
  return [];
165
- const canCache = options.label && options.gitignore;
166
- const willCache = canCache && !cachedGlobIgnores.has(options.dir);
167
- const cachedIgnores = canCache && cachedGlobIgnores.get(options.dir);
126
+ const hasCache = cachedGlobIgnores.has(options.dir);
127
+ const willCache = !hasCache && options.gitignore && options.label;
128
+ const cachedIgnores = options.gitignore ? cachedGlobIgnores.get(options.dir) : undefined;
168
129
  const _ignore = options.gitignore && Array.isArray(options.ignore) ? [...options.ignore] : [];
169
130
  if (options.gitignore) {
170
131
  if (willCache) {
@@ -185,19 +146,25 @@ export async function glob(patterns, options) {
185
146
  _ignore.push(...GLOBAL_IGNORE_PATTERNS);
186
147
  }
187
148
  const ignore = cachedIgnores || compact(_ignore);
149
+ if (willCache)
150
+ cachedGlobIgnores.set(options.dir, compact(_ignore));
188
151
  const { dir, label, ...fgOptions } = { ...options, ignore };
189
152
  const paths = await fg.glob(patterns, fgOptions);
190
- debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, label ? `Finding ${label}` : 'Finding paths', () => ({ patterns, ...fgOptions, ignore: cachedIgnores ? `// identical to ${dir}` : ignore, paths }));
191
- if (willCache)
192
- cachedGlobIgnores.set(options.dir, ignore);
153
+ const name = relative(options.cwd, dir);
154
+ debugLogObject(name || ROOT_WORKSPACE_NAME, label ? `Finding ${label}` : 'Finding paths', () => ({
155
+ patterns,
156
+ ...fgOptions,
157
+ ignore: hasCache ? `// identical to ${name}` : ignore,
158
+ paths,
159
+ }));
193
160
  return paths;
194
161
  }
195
162
  export async function getGitIgnoredHandler(options) {
196
163
  cachedGitIgnores.clear();
197
164
  if (options.gitignore === false)
198
165
  return () => false;
199
- const gitignore = await _parseFindGitignores(options.cwd);
200
- const matcher = _picomatch(Array.from(gitignore.ignores), { ignore: gitignore.unignores });
166
+ const { ignores, unignores } = await _parseFindGitignores(options.cwd);
167
+ const matcher = _picomatch(Array.from(ignores), { ignore: unignores });
201
168
  const isGitIgnored = (filePath) => matcher(relative(options.cwd, filePath));
202
169
  return timerify(isGitIgnored);
203
170
  }
@@ -7,7 +7,8 @@ export interface Input {
7
7
  optional?: boolean;
8
8
  dir?: string;
9
9
  containingFilePath?: string;
10
- skipExportsAnalysis?: string;
10
+ allowIncludeExports?: boolean;
11
+ skipExportsAnalysis?: boolean;
11
12
  }
12
13
  export interface ConfigInput extends Input {
13
14
  type: 'config';
@@ -18,6 +19,7 @@ type Options = {
18
19
  optional?: boolean;
19
20
  dir?: string;
20
21
  containingFilePath?: string;
22
+ allowIncludeExports?: boolean;
21
23
  };
22
24
  export declare const fromBinary: (input: Input) => string;
23
25
  export declare const toBinary: (specifier: string, options?: Options) => Input;
@@ -0,0 +1,8 @@
1
+ export declare const convertGitignoreToPicomatchIgnorePatterns: (pattern: string) => {
2
+ negated: boolean;
3
+ patterns: string[];
4
+ };
5
+ export declare const parseAndConvertGitignorePatterns: (patterns: string, ancestor?: string) => {
6
+ negated: boolean;
7
+ patterns: string[];
8
+ }[];
@@ -0,0 +1,40 @@
1
+ export const convertGitignoreToPicomatchIgnorePatterns = (pattern) => {
2
+ const negated = pattern[0] === '!';
3
+ if (negated)
4
+ pattern = pattern.slice(1);
5
+ let extPattern;
6
+ if (pattern.endsWith('/'))
7
+ pattern = pattern.slice(0, -1);
8
+ if (pattern.startsWith('*/**/'))
9
+ pattern = pattern.slice(5);
10
+ if (pattern.startsWith('/'))
11
+ pattern = pattern.slice(1);
12
+ else if (!pattern.startsWith('**/'))
13
+ pattern = `**/${pattern}`;
14
+ if (pattern.endsWith('/*'))
15
+ extPattern = pattern;
16
+ else
17
+ extPattern = `${pattern}/**`;
18
+ return { negated, patterns: [pattern, extPattern] };
19
+ };
20
+ export const parseAndConvertGitignorePatterns = (patterns, ancestor) => {
21
+ const matchFrom = ancestor ? new RegExp(`^(!?/?)(${ancestor})`) : undefined;
22
+ return patterns
23
+ .split(/\r?\n/)
24
+ .filter(line => line.trim() && !line.startsWith('#'))
25
+ .flatMap(line => {
26
+ const pattern = line.replace(/^\\(?=#)/, '').trim();
27
+ if (ancestor && matchFrom) {
28
+ if (pattern.match(matchFrom))
29
+ return [pattern.replace(matchFrom, '$1')];
30
+ if (pattern.startsWith('/**/'))
31
+ return [pattern.slice(1)];
32
+ if (pattern.startsWith('!/**/'))
33
+ return [`!${pattern.slice(2)}`];
34
+ if (pattern.startsWith('/') || pattern.startsWith('!/'))
35
+ return [];
36
+ }
37
+ return [pattern];
38
+ })
39
+ .map(pattern => convertGitignoreToPicomatchIgnorePatterns(pattern));
40
+ };
@@ -1,5 +1,5 @@
1
1
  import type { CompilerOptions } from 'typescript';
2
2
  import type { ConfigurationChief, Workspace } from '../ConfigurationChief.js';
3
3
  export declare const augmentWorkspace: (workspace: Workspace, dir: string, compilerOptions: CompilerOptions) => void;
4
- export declare const getToSourcePathHandler: (chief: ConfigurationChief) => (filePath: string) => string | undefined;
4
+ export declare const getToSourcePathHandler: (chief: ConfigurationChief) => (filePath: string, extensions?: string) => string | undefined;
5
5
  export type ToSourceFilePath = ReturnType<typeof getToSourcePathHandler>;
@@ -14,7 +14,7 @@ export const augmentWorkspace = (workspace, dir, compilerOptions) => {
14
14
  };
15
15
  export const getToSourcePathHandler = (chief) => {
16
16
  const toSourceMapCache = new Map();
17
- return (filePath) => {
17
+ return (filePath, extensions = defaultExtensions) => {
18
18
  if (!isInternal(filePath) || hasTSExt.test(filePath))
19
19
  return;
20
20
  if (toSourceMapCache.has(filePath))
@@ -23,7 +23,7 @@ export const getToSourcePathHandler = (chief) => {
23
23
  if (workspace?.srcDir && workspace.outDir) {
24
24
  if ((!filePath.startsWith(workspace.srcDir) && filePath.startsWith(workspace.outDir)) ||
25
25
  (workspace.srcDir === workspace.outDir && hasDTSExt.test(filePath))) {
26
- const pattern = filePath.replace(workspace.outDir, workspace.srcDir).replace(matchExt, defaultExtensions);
26
+ const pattern = filePath.replace(workspace.outDir, workspace.srcDir).replace(matchExt, extensions);
27
27
  const [srcFilePath] = fastGlob.sync(pattern);
28
28
  toSourceMapCache.set(filePath, srcFilePath);
29
29
  if (srcFilePath && srcFilePath !== filePath) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.50.4";
1
+ export declare const version = "5.51.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.50.4';
1
+ export const version = '5.51.0';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.50.4",
4
- "description": "Find and fix unused files, dependencies and exports in your TypeScript and JavaScript projects",
3
+ "version": "5.51.0",
4
+ "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
7
7
  "type": "git",
@@ -43,6 +43,7 @@
43
43
  "test": "bun test test/*.test.ts test/**/*.test.ts",
44
44
  "test:watch": "bun test test/*.test.ts test/**/*.test.ts --reporter=junit --reporter-outfile=junit.xml || bun test --watch $(grep -o 'name=\"[^\"]*\".*failures=\"[^0]' junit.xml | grep -v 'name=\"bun test\"' | grep -o 'name=\"[^\"]*\"' | cut -d'\"' -f2)",
45
45
  "test:node": "glob -c \"npx -y tsx --test --import ./transform-test.js\" \"test/**/*.test.ts\"",
46
+ "test:smoke": "bun test test/*.test.ts test/{plugins,util}/*.test.ts",
46
47
  "watch": "npm link && tsc --watch",
47
48
  "prebuild": "npm run generate-plugin-defs && node rmdir.js dist",
48
49
  "build": "tsc",
@@ -89,7 +90,7 @@
89
90
  "@wdio/types": "^9.5.0",
90
91
  "codeclimate-types": "^0.3.1",
91
92
  "glob": "^10.4.2",
92
- "release-it": "^19.0.0-next.3",
93
+ "release-it": "^19.0.1",
93
94
  "type-fest": "^4.31.0",
94
95
  "typescript": "^5.5.2"
95
96
  },
package/schema.json CHANGED
@@ -168,6 +168,10 @@
168
168
  "$ref": "#/definitions/ruleValue"
169
169
  }
170
170
  }
171
+ },
172
+ "treatConfigHintsAsErrors": {
173
+ "title": "Exit with non-zero code (1) if there are any configuration hints",
174
+ "type": "boolean"
171
175
  }
172
176
  },
173
177
  "unevaluatedProperties": false,
@@ -311,6 +315,10 @@
311
315
  "title": "Babel plugin configuration (https://knip.dev/reference/plugins/babel)",
312
316
  "$ref": "#/definitions/plugin"
313
317
  },
318
+ "bun": {
319
+ "title": "bun plugin configuration (https://knip.dev/reference/plugins/bun)",
320
+ "$ref": "#/definitions/plugin"
321
+ },
314
322
  "c8": {
315
323
  "title": "c8 plugin configuration (https://knip.dev/reference/plugins/c8)",
316
324
  "$ref": "#/definitions/plugin"
@@ -447,6 +455,10 @@
447
455
  "title": "Mocha plugin configuration (https://knip.dev/reference/plugins/msw)",
448
456
  "$ref": "#/definitions/plugin"
449
457
  },
458
+ "nano-staged": {
459
+ "title": "nano-staged plugin configuration (https://knip.dev/reference/plugins/nano-staged)",
460
+ "$ref": "#/definitions/plugin"
461
+ },
450
462
  "nest": {
451
463
  "title": "nest plugin configuration (https://knip.dev/reference/plugins/nest)",
452
464
  "$ref": "#/definitions/plugin"
@@ -491,6 +503,10 @@
491
503
  "title": "oclif plugin configuration (https://knip.dev/reference/plugins/oclif)",
492
504
  "$ref": "#/definitions/plugin"
493
505
  },
506
+ "oxlint": {
507
+ "title": "oxlint plugin configuration (https://knip.dev/reference/plugins/oxlint)",
508
+ "$ref": "#/definitions/plugin"
509
+ },
494
510
  "playwright": {
495
511
  "title": "Playwright plugin configuration (https://knip.dev/reference/plugins/playwright)",
496
512
  "$ref": "#/definitions/plugin"
@@ -523,6 +539,10 @@
523
539
  "title": "react-router plugin configuration (https://knip.dev/reference/plugins/react-router)",
524
540
  "$ref": "#/definitions/plugin"
525
541
  },
542
+ "relay": {
543
+ "title": "relay plugin configuration (https://knip.dev/reference/plugins/relay)",
544
+ "$ref": "#/definitions/plugin"
545
+ },
526
546
  "release-it": {
527
547
  "title": "Release It plugin configuration (https://knip.dev/reference/plugins/release-it)",
528
548
  "$ref": "#/definitions/plugin"
@@ -595,10 +615,6 @@
595
615
  "title": "tailwind plugin configuration (https://knip.dev/reference/plugins/tailwind)",
596
616
  "$ref": "#/definitions/plugin"
597
617
  },
598
- "tanstack-router": {
599
- "title": "tanstack-router plugin configuration (https://knip.dev/reference/plugins/tanstack-router)",
600
- "$ref": "#/definitions/plugin"
601
- },
602
618
  "travis": {
603
619
  "title": "travis plugin configuration (https://knip.dev/reference/plugins/travis)",
604
620
  "$ref": "#/definitions/plugin"
@@ -1,12 +0,0 @@
1
- import type { IsPluginEnabled, ResolveEntryPaths, ResolveFromAST } from '../../types/config.js';
2
- import type { TanstackRouterConfig } from './types.js';
3
- declare const _default: {
4
- title: string;
5
- enablers: string[];
6
- isEnabled: IsPluginEnabled;
7
- config: string[];
8
- production: string[];
9
- resolveEntryPaths: ResolveEntryPaths<TanstackRouterConfig>;
10
- resolveFromAST: ResolveFromAST;
11
- };
12
- export default _default;
@@ -1,46 +0,0 @@
1
- import { toEntry } from '../../util/input.js';
2
- import { extname, join } from '../../util/path.js';
3
- import { hasDependency } from '../../util/plugin.js';
4
- import { getCustomConfig } from './resolveFromAST.js';
5
- const title = 'TanStack Router';
6
- const enablers = ['@tanstack/react-router', '@tanstack/router-plugin', '@tanstack/router-cli'];
7
- const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
- const config = [
9
- 'tsr.config.json',
10
- 'vite.config.{js,mjs,ts,cjs,mts,cts}',
11
- 'rs{pack,build}.config.{js,mjs,ts,cjs,mts,cts}',
12
- 'webpack.config.{js,mjs,ts,cjs,mts,cts}',
13
- ];
14
- const production = ['./src/routeTree.gen.ts', './src/routes/**/*.{ts,tsx}', '!src/routes/**/-*/**'];
15
- const getEntryPatterns = (config) => {
16
- const dir = config.routesDirectory ?? 'src/routes';
17
- const entries = [
18
- toEntry(join(config.generatedRouteTree ?? './src/routeTree.gen.ts')),
19
- toEntry(join(dir, '**', `${config.routeFilePrefix ?? ''}*`)),
20
- toEntry(join(`!${dir}`, '**', `${config.routeFileIgnorePrefix ?? '-'}*`)),
21
- ];
22
- if (config.routeFileIgnorePattern) {
23
- entries.push(toEntry(join(`!${dir}`, '**', `*${config.routeFileIgnorePattern}*`)));
24
- }
25
- return entries;
26
- };
27
- const resolveEntryPaths = (localConfig, options) => {
28
- if (extname(options.configFileName) !== '.json')
29
- return [];
30
- return getEntryPatterns(localConfig);
31
- };
32
- const resolveFromAST = (sourceFile, options) => {
33
- if (extname(options.configFileName) === '.json')
34
- return [];
35
- const resolvedConfig = getCustomConfig(sourceFile);
36
- return getEntryPatterns(resolvedConfig);
37
- };
38
- export default {
39
- title,
40
- enablers,
41
- isEnabled,
42
- config,
43
- production,
44
- resolveEntryPaths,
45
- resolveFromAST,
46
- };
@@ -1,2 +0,0 @@
1
- import ts from 'typescript';
2
- export declare const getCustomConfig: (sourceFile: ts.SourceFile) => Record<string, string>;
@@ -1,28 +0,0 @@
1
- import ts from 'typescript';
2
- import { getPropertyValueEntries } from '../../typescript/ast-helpers.js';
3
- const CONFIG_KEYS = new Set([
4
- 'routeFilePrefix',
5
- 'routeFileIgnorePrefix',
6
- 'routeFileIgnorePattern',
7
- 'routesDirectory',
8
- 'generatedRouteTree',
9
- ]);
10
- const FUNCTIONS = new Set(['TanStackRouterVite', 'TanStackRouterRspack', 'TanStackRouterWebpack']);
11
- export const getCustomConfig = (sourceFile) => {
12
- const config = {};
13
- function visit(node) {
14
- if (ts.isCallExpression(node)) {
15
- const callee = node.expression;
16
- if (ts.isIdentifier(callee) && FUNCTIONS.has(callee.text)) {
17
- const firstArg = node.arguments[0];
18
- if (ts.isObjectLiteralExpression(firstArg)) {
19
- for (const [key, value] of getPropertyValueEntries(firstArg, CONFIG_KEYS))
20
- config[key] = value;
21
- }
22
- }
23
- }
24
- ts.forEachChild(node, visit);
25
- }
26
- visit(sourceFile);
27
- return config;
28
- };
@@ -1,7 +0,0 @@
1
- export type TanstackRouterConfig = {
2
- routeFilePrefix?: string;
3
- routeFileIgnorePrefix?: string;
4
- routeFileIgnorePattern?: string;
5
- routesDirectory?: string;
6
- generatedRouteTree?: string;
7
- };