knip 5.30.6 → 5.31.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 (46) hide show
  1. package/dist/ConfigurationValidator.d.ts +6 -6
  2. package/dist/IssueFixer.d.ts +4 -4
  3. package/dist/IssueFixer.js +9 -12
  4. package/dist/WorkspaceWorker.d.ts +2 -2
  5. package/dist/compilers/index.d.ts +1 -1
  6. package/dist/constants.d.ts +5 -0
  7. package/dist/constants.js +5 -0
  8. package/dist/index.js +7 -3
  9. package/dist/reporters/symbols.js +2 -2
  10. package/dist/types/exports.d.ts +1 -1
  11. package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +1 -1
  12. package/dist/typescript/visitors/dynamic-imports/importType.d.ts +1 -1
  13. package/dist/typescript/visitors/dynamic-imports/index.d.ts +1 -1
  14. package/dist/typescript/visitors/dynamic-imports/jsDocType.d.ts +1 -1
  15. package/dist/typescript/visitors/dynamic-imports/propertyAccessCall.d.ts +1 -1
  16. package/dist/typescript/visitors/dynamic-imports/requireCall.d.ts +1 -1
  17. package/dist/typescript/visitors/exports/exportAssignment.d.ts +1 -1
  18. package/dist/typescript/visitors/exports/exportAssignment.js +2 -1
  19. package/dist/typescript/visitors/exports/exportDeclaration.d.ts +1 -1
  20. package/dist/typescript/visitors/exports/exportDeclaration.js +6 -2
  21. package/dist/typescript/visitors/exports/exportKeyword.d.ts +1 -1
  22. package/dist/typescript/visitors/exports/exportKeyword.js +9 -7
  23. package/dist/typescript/visitors/exports/exportsAccessExpression.d.ts +1 -1
  24. package/dist/typescript/visitors/exports/exportsAccessExpression.js +2 -1
  25. package/dist/typescript/visitors/exports/index.d.ts +1 -1
  26. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
  27. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +4 -3
  28. package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
  29. package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
  30. package/dist/typescript/visitors/imports/index.d.ts +1 -1
  31. package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
  32. package/dist/typescript/visitors/scripts/bun.d.ts +1 -1
  33. package/dist/typescript/visitors/scripts/execa.d.ts +1 -1
  34. package/dist/typescript/visitors/scripts/index.d.ts +1 -1
  35. package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
  36. package/dist/util/fs.d.ts +0 -1
  37. package/dist/util/fs.js +2 -17
  38. package/dist/util/glob-core.js +1 -1
  39. package/dist/util/jiti.d.ts +1 -2
  40. package/dist/util/jiti.js +3 -8
  41. package/dist/util/loader.js +2 -12
  42. package/dist/util/remove-export.d.ts +8 -0
  43. package/dist/util/remove-export.js +68 -0
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +1 -1
  46. package/package.json +2 -2
@@ -2775,9 +2775,9 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
2775
2775
  ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
2776
2776
  ignoreWorkspaces?: string[] | undefined;
2777
2777
  includeEntryExports?: boolean | undefined;
2778
- compilers?: Record<string, ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
2779
- syncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => string> | undefined;
2780
- asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => Promise<string>> | undefined;
2778
+ compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
2779
+ syncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => string> | undefined;
2780
+ asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>> | undefined;
2781
2781
  astro?: string | boolean | string[] | {
2782
2782
  config?: string | string[] | undefined;
2783
2783
  entry?: string | string[] | undefined;
@@ -3552,9 +3552,9 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
3552
3552
  ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
3553
3553
  ignoreWorkspaces?: string[] | undefined;
3554
3554
  includeEntryExports?: boolean | undefined;
3555
- compilers?: Record<string, ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
3556
- syncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => string> | undefined;
3557
- asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => Promise<string>> | undefined;
3555
+ compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
3556
+ syncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => string> | undefined;
3557
+ asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>> | undefined;
3558
3558
  astro?: string | boolean | string[] | {
3559
3559
  config?: string | string[] | undefined;
3560
3560
  entry?: string | string[] | undefined;
@@ -1,4 +1,4 @@
1
- import type { Fixes } from './types/exports.js';
1
+ import type { Fix, Fixes } from './types/exports.js';
2
2
  import type { Issues } from './types/issues.js';
3
3
  interface Fixer {
4
4
  isEnabled: boolean;
@@ -13,15 +13,15 @@ export declare class IssueFixer {
13
13
  isFixDependencies: boolean;
14
14
  isFixUnusedTypes: boolean;
15
15
  isFixUnusedExports: boolean;
16
- unusedTypeNodes: Map<string, Set<[number, number]>>;
17
- unusedExportNodes: Map<string, Set<[number, number]>>;
16
+ unusedTypeNodes: Map<string, Set<Fix>>;
17
+ unusedExportNodes: Map<string, Set<Fix>>;
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
21
  fixIssues(issues: Issues): Promise<void>;
22
22
  private markExportFixed;
23
23
  private removeUnusedFiles;
24
- private removeUnusedExportKeywords;
24
+ private removeUnusedExports;
25
25
  private removeUnusedDependencies;
26
26
  }
27
27
  export {};
@@ -1,6 +1,7 @@
1
1
  import { readFile, rm, writeFile } from 'node:fs/promises';
2
2
  import { load, save } from './util/package-json.js';
3
3
  import { join, relative } from './util/path.js';
4
+ import { removeExport } from './util/remove-export.js';
4
5
  export class IssueFixer {
5
6
  isEnabled = false;
6
7
  cwd = process.cwd();
@@ -38,13 +39,13 @@ export class IssueFixer {
38
39
  }
39
40
  async fixIssues(issues) {
40
41
  await this.removeUnusedFiles(issues);
41
- await this.removeUnusedExportKeywords(issues);
42
+ await this.removeUnusedExports(issues);
42
43
  await this.removeUnusedDependencies(issues);
43
44
  }
44
45
  markExportFixed(issues, filePath) {
45
46
  const relPath = relative(filePath);
46
47
  const types = [
47
- ...(this.isFixUnusedTypes ? ['types', 'nsTypes'] : []),
48
+ ...(this.isFixUnusedTypes ? ['types', 'nsTypes', 'classMembers', 'enumMembers'] : []),
48
49
  ...(this.isFixUnusedExports ? ['exports', 'nsExports'] : []),
49
50
  ];
50
51
  for (const type of types) {
@@ -61,19 +62,15 @@ export class IssueFixer {
61
62
  issue.isFixed = true;
62
63
  }
63
64
  }
64
- async removeUnusedExportKeywords(issues) {
65
+ async removeUnusedExports(issues) {
65
66
  const filePaths = new Set([...this.unusedTypeNodes.keys(), ...this.unusedExportNodes.keys()]);
66
67
  for (const filePath of filePaths) {
67
- const exportPositions = [
68
- ...(this.isFixUnusedTypes ? (this.unusedTypeNodes.get(filePath) ?? []) : []),
69
- ...(this.isFixUnusedExports ? (this.unusedExportNodes.get(filePath) ?? []) : []),
70
- ].sort((a, b) => b[0] - a[0]);
68
+ const types = (this.isFixUnusedTypes && this.unusedTypeNodes.get(filePath)) || [];
69
+ const exports = (this.isFixUnusedExports && this.unusedExportNodes.get(filePath)) || [];
70
+ const exportPositions = [...types, ...exports].filter(fix => fix !== undefined).sort((a, b) => b[0] - a[0]);
71
71
  if (exportPositions.length > 0) {
72
- const sourceFileText = exportPositions.reduce((text, [start, end]) => text.substring(0, start) + text.substring(end), await readFile(filePath, 'utf-8'));
73
- const withoutEmptyReExports = sourceFileText
74
- .replaceAll(/export \{[ ,]+\} from ('|")[^'"]+('|");?\r?\n?/g, '')
75
- .replaceAll(/export \{[ ,]+\};?\r?\n?/g, '');
76
- await writeFile(filePath, withoutEmptyReExports);
72
+ const sourceFileText = exportPositions.reduce((text, [start, end, flags]) => removeExport({ text, start, end, flags }), await readFile(filePath, 'utf-8'));
73
+ await writeFile(filePath, sourceFileText);
77
74
  this.markExportFixed(issues, filePath);
78
75
  }
79
76
  }
@@ -34,7 +34,7 @@ export declare class WorkspaceWorker {
34
34
  isStrict: boolean;
35
35
  rootIgnore: Configuration['ignore'];
36
36
  negatedWorkspacePatterns: string[];
37
- enabledPluginsMap: Record<"astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo", boolean>;
37
+ enabledPluginsMap: Record<"angular" | "astro" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "drizzle" | "eleventy" | "eslint" | "gatsby" | "githubActions" | "graphqlCodegen" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "lintStaged" | "lockfileLint" | "lostPixel" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nodeTestRunner" | "npmPackageJsonLint" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "playwrightCt" | "postcss" | "preconstruct" | "prettier" | "reactCosmos" | "releaseIt" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "semanticRelease" | "sentry" | "simpleGitHooks" | "sizeLimit" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vercelOg" | "vike" | "vite" | "vitest" | "vue" | "webdriverIo" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie", boolean>;
38
38
  enabledPlugins: PluginName[];
39
39
  enabledPluginsInAncestors: string[];
40
40
  cache: CacheConsultant<CacheItem>;
@@ -55,7 +55,7 @@ export declare class WorkspaceWorker {
55
55
  entryFilePatterns: Set<string>;
56
56
  productionEntryFilePatterns: Set<string>;
57
57
  referencedDependencies: ReferencedDependencies;
58
- enabledPlugins: ("astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo")[];
58
+ enabledPlugins: ("angular" | "astro" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "drizzle" | "eleventy" | "eslint" | "gatsby" | "githubActions" | "graphqlCodegen" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "lintStaged" | "lockfileLint" | "lostPixel" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nodeTestRunner" | "npmPackageJsonLint" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "playwrightCt" | "postcss" | "preconstruct" | "prettier" | "reactCosmos" | "releaseIt" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "semanticRelease" | "sentry" | "simpleGitHooks" | "sizeLimit" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vercelOg" | "vike" | "vite" | "vitest" | "vue" | "webdriverIo" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie")[];
59
59
  }>;
60
60
  onDispose(): void;
61
61
  }
@@ -17,7 +17,7 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
17
17
  ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
18
18
  ignoreWorkspaces?: string[] | undefined;
19
19
  includeEntryExports?: boolean | undefined;
20
- compilers?: Record<string, ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
20
+ compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
21
21
  astro?: string | boolean | string[] | {
22
22
  config?: string | string[] | undefined;
23
23
  entry?: string | string[] | undefined;
@@ -17,3 +17,8 @@ export declare const FOREIGN_FILE_EXTENSIONS: Set<string>;
17
17
  export declare const IGNORE_DEFINITELY_TYPED: Set<string>;
18
18
  export declare const ISSUE_TYPES: IssueType[];
19
19
  export declare const ISSUE_TYPE_TITLE: Record<IssueType, string>;
20
+ export declare const FIX_FLAGS: {
21
+ readonly NONE: 0;
22
+ readonly OBJECT_BINDING: number;
23
+ readonly EMPTY_DECLARATION: number;
24
+ };
package/dist/constants.js CHANGED
@@ -180,3 +180,8 @@ export const ISSUE_TYPE_TITLE = {
180
180
  classMembers: 'Unused exported class members',
181
181
  duplicates: 'Duplicate exports',
182
182
  };
183
+ export const FIX_FLAGS = {
184
+ NONE: 0,
185
+ OBJECT_BINDING: 1 << 0,
186
+ EMPTY_DECLARATION: 1 << 1,
187
+ };
package/dist/index.js CHANGED
@@ -290,7 +290,7 @@ export const main = async (unresolvedConfiguration) => {
290
290
  }
291
291
  const importsForExport = file.imported;
292
292
  for (const [identifier, exportedItem] of exportItems.entries()) {
293
- if (exportedItem.isReExport)
293
+ if (!isFix && exportedItem.isReExport)
294
294
  continue;
295
295
  if (shouldIgnore(exportedItem.jsDocTags))
296
296
  continue;
@@ -331,7 +331,7 @@ export const main = async (unresolvedConfiguration) => {
331
331
  if (!isReferenced) {
332
332
  if (isIgnored)
333
333
  continue;
334
- collector.addIssue({
334
+ const isIssueAdded = collector.addIssue({
335
335
  type: 'enumMembers',
336
336
  filePath,
337
337
  workspace: workspace.name,
@@ -341,6 +341,8 @@ export const main = async (unresolvedConfiguration) => {
341
341
  line: member.line,
342
342
  col: member.col,
343
343
  });
344
+ if (isFix && isIssueAdded && member.fix)
345
+ fixer.addUnusedTypeNode(filePath, [member.fix]);
344
346
  }
345
347
  else if (isIgnored) {
346
348
  for (const tagName of exportedItem.jsDocTags) {
@@ -364,7 +366,7 @@ export const main = async (unresolvedConfiguration) => {
364
366
  }
365
367
  continue;
366
368
  }
367
- collector.addIssue({
369
+ const isIssueAdded = collector.addIssue({
368
370
  type: 'classMembers',
369
371
  filePath,
370
372
  workspace: workspace.name,
@@ -374,6 +376,8 @@ export const main = async (unresolvedConfiguration) => {
374
376
  line: member.line,
375
377
  col: member.col,
376
378
  });
379
+ if (isFix && isIssueAdded && member.fix)
380
+ fixer.addUnusedTypeNode(filePath, [member.fix]);
377
381
  }
378
382
  }
379
383
  continue;
@@ -15,7 +15,7 @@ const logIssueRecord = (issues) => {
15
15
  const pos = issue.line === undefined ? '' : `:${issue.line}${issue.col === undefined ? '' : `:${issue.col}`}`;
16
16
  const cell = `${relative(issue.filePath)}${pos}`;
17
17
  table.cell('filePath', print(cell));
18
- issue.isFixed && table.cell('fixed', print('(fixed)'));
18
+ issue.isFixed && table.cell('fixed', print('(removed)'));
19
19
  table.newRow();
20
20
  }
21
21
  console.log(table.sort(['filePath', 'parentSymbol', 'symbol']).print().trim());
@@ -35,7 +35,7 @@ export default ({ report, issues, tagHints, configurationHints, noConfigHints, i
35
35
  for (const issue of issuesForType) {
36
36
  const relPath = toRelative(issue.filePath);
37
37
  if (issue.isFixed)
38
- console.log(picocolors.gray(`${relPath} (deleted)`));
38
+ console.log(picocolors.gray(`${relPath} (removed)`));
39
39
  else if (issue.severity === 'warn')
40
40
  console.log(picocolors.gray(relPath));
41
41
  else
@@ -1,7 +1,7 @@
1
1
  import type ts from 'typescript';
2
2
  import type { SymbolType } from './issues.js';
3
3
  type Identifier = string;
4
- type ExportPosTuple = [number, number];
4
+ type ExportPosTuple = [number, number, number];
5
5
  export type Fix = ExportPosTuple | undefined;
6
6
  export type Fixes = Array<ExportPosTuple>;
7
7
  export type ExportNode = {
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import type ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined)[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[])[];
3
3
  export default _default;
@@ -1,4 +1,4 @@
1
1
  import ts from 'typescript';
2
2
  import type { ImportNode } from '../../../types/imports.js';
3
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => ImportNode | ImportNode[] | undefined;
3
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | ImportNode | ImportNode[];
4
4
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
3
3
  export default _default;
@@ -1,10 +1,11 @@
1
1
  import ts from 'typescript';
2
+ import { FIX_FLAGS } from '../../../constants.js';
2
3
  import { SymbolType } from '../../../types/issues.js';
3
4
  import { exportVisitor as visit } from '../index.js';
4
5
  export default visit(() => true, (node, { isFixExports }) => {
5
6
  if (ts.isExportAssignment(node)) {
6
7
  const pos = node.getChildAt(1).getStart();
7
- const fix = isFixExports ? [node.getStart(), node.getEnd() + 1] : undefined;
8
+ const fix = isFixExports ? [node.getStart(), node.getEnd() + 1, FIX_FLAGS.NONE] : undefined;
8
9
  const symbol = node.getSourceFile().locals?.get(node.expression.escapedText);
9
10
  return { node, symbol, identifier: 'default', type: SymbolType.UNKNOWN, pos, fix };
10
11
  }
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
3
3
  export default _default;
@@ -1,10 +1,11 @@
1
1
  import ts from 'typescript';
2
+ import { FIX_FLAGS } from '../../../constants.js';
2
3
  import { SymbolType } from '../../../types/issues.js';
3
4
  import { exportVisitor as visit } from '../index.js';
4
5
  export default visit(() => true, (node, { isFixExports, isFixTypes }) => {
5
6
  if (ts.isExportDeclaration(node)) {
6
7
  if (node.exportClause && ts.isNamedExports(node.exportClause)) {
7
- const type = node.isTypeOnly ? SymbolType.TYPE : SymbolType.UNKNOWN;
8
+ const nodeType = node.isTypeOnly ? SymbolType.TYPE : SymbolType.UNKNOWN;
8
9
  const sourceFile = node.getSourceFile();
9
10
  const declarations = sourceFile.getNamedDeclarations?.();
10
11
  return node.exportClause.elements.map(element => {
@@ -12,7 +13,10 @@ export default visit(() => true, (node, { isFixExports, isFixTypes }) => {
12
13
  const propName = element.propertyName?.text;
13
14
  const symbol = declarations?.get(propName ?? identifier)?.[0]?.symbol;
14
15
  const pos = element.name.pos;
15
- const fix = isFixExports || isFixTypes ? [element.getStart(), element.getEnd()] : undefined;
16
+ const type = element.isTypeOnly ? SymbolType.TYPE : nodeType;
17
+ const fix = (isFixExports && type !== SymbolType.TYPE) || (isFixTypes && type === SymbolType.TYPE)
18
+ ? [element.getStart(), element.getEnd(), FIX_FLAGS.OBJECT_BINDING | FIX_FLAGS.EMPTY_DECLARATION]
19
+ : undefined;
16
20
  return { node: element, symbol, identifier, type, pos, fix };
17
21
  });
18
22
  }
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
3
3
  export default _default;
@@ -1,4 +1,5 @@
1
1
  import ts from 'typescript';
2
+ import { FIX_FLAGS } from '../../../constants.js';
2
3
  import { SymbolType } from '../../../types/issues.js';
3
4
  import { compact } from '../../../util/array.js';
4
5
  import { getDefaultKeywordNode, getExportKeywordNode, isGetOrSetAccessorDeclaration, isPrivateMember, stripQuotes, } from '../../ast-helpers.js';
@@ -6,15 +7,16 @@ import { exportVisitor as visit } from '../index.js';
6
7
  export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClassMembers }) => {
7
8
  const exportKeyword = getExportKeywordNode(node);
8
9
  if (exportKeyword) {
9
- const getFix = (node, defaultKeyword) => isFixExports ? [node.getStart(), (defaultKeyword ?? node).getEnd() + 1] : undefined;
10
- const getElementFix = (node) => (isFixExports ? [node.getStart(), node.getEnd()] : undefined);
11
- const getTypeFix = (node) => (isFixTypes ? [node.getStart(), node.getEnd() + 1] : undefined);
10
+ const getFix = (node, defaultKeyword) => isFixExports ? [node.getStart(), (defaultKeyword ?? node).getEnd() + 1, FIX_FLAGS.NONE] : undefined;
11
+ const getTypeFix = (node) => isFixTypes ? [node.getStart(), node.getEnd() + 1, FIX_FLAGS.NONE] : undefined;
12
12
  if (ts.isVariableStatement(node)) {
13
13
  return node.declarationList.declarations.flatMap(declaration => {
14
14
  if (ts.isObjectBindingPattern(declaration.name)) {
15
15
  return compact(declaration.name.elements.map(element => {
16
16
  if (ts.isIdentifier(element.name)) {
17
- const fix = getElementFix(element);
17
+ const fix = isFixExports
18
+ ? [element.getStart(), element.getEnd(), FIX_FLAGS.OBJECT_BINDING]
19
+ : undefined;
18
20
  return {
19
21
  node: element,
20
22
  identifier: element.name.escapedText.toString(),
@@ -28,7 +30,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
28
30
  if (ts.isArrayBindingPattern(declaration.name)) {
29
31
  return compact(declaration.name.elements.map(element => {
30
32
  if (ts.isBindingElement(element)) {
31
- const fix = getElementFix(element);
33
+ const fix = isFixExports ? [element.getStart(), element.getEnd(), FIX_FLAGS.NONE] : undefined;
32
34
  return {
33
35
  node: element,
34
36
  identifier: element.getText(),
@@ -67,7 +69,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
67
69
  identifier: member.name.getText(),
68
70
  pos: member.name.getStart() + (ts.isComputedPropertyName(member.name) ? 1 : 0),
69
71
  type: SymbolType.MEMBER,
70
- fix: undefined,
72
+ fix: isFixTypes ? [member.getStart(), member.getEnd(), FIX_FLAGS.NONE] : undefined,
71
73
  }))
72
74
  : [];
73
75
  return { node, identifier, type: SymbolType.CLASS, pos, members, fix };
@@ -93,7 +95,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
93
95
  identifier: stripQuotes(member.name.getText()),
94
96
  pos: member.name.getStart(),
95
97
  type: SymbolType.MEMBER,
96
- fix: undefined,
98
+ fix: isFixTypes ? [member.getStart(), member.getEnd(), FIX_FLAGS.OBJECT_BINDING] : undefined,
97
99
  }));
98
100
  return { node, identifier, type: SymbolType.ENUM, pos, members, fix };
99
101
  }
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
3
3
  export default _default;
@@ -1,4 +1,5 @@
1
1
  import ts from 'typescript';
2
+ import { FIX_FLAGS } from '../../../constants.js';
2
3
  import { SymbolType } from '../../../types/issues.js';
3
4
  import { isJS } from '../helpers.js';
4
5
  import { exportVisitor as visit } from '../index.js';
@@ -7,7 +8,7 @@ export default visit(isJS, (node, { isFixExports }) => {
7
8
  if (ts.isIdentifier(node.left.expression) && node.left.expression.escapedText === 'exports') {
8
9
  const identifier = node.left.name.getText();
9
10
  const pos = node.left.name.pos;
10
- const fix = isFixExports ? [node.getStart(), node.getEnd()] : undefined;
11
+ const fix = isFixExports ? [node.getStart(), node.getEnd(), FIX_FLAGS.NONE] : undefined;
11
12
  return {
12
13
  node: node.left.name,
13
14
  identifier,
@@ -1,3 +1,3 @@
1
1
  import type ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined)[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[])[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
3
3
  export default _default;
@@ -1,4 +1,5 @@
1
1
  import ts from 'typescript';
2
+ import { FIX_FLAGS } from '../../../constants.js';
2
3
  import { SymbolType } from '../../../types/issues.js';
3
4
  import { hasRequireCall, isModuleExportsAccess, stripQuotes } from '../../ast-helpers.js';
4
5
  import { isJS } from '../helpers.js';
@@ -11,7 +12,7 @@ export default visit(isJS, (node, { isFixExports }) => {
11
12
  isModuleExportsAccess(node.expression.left.expression)) {
12
13
  const identifier = node.expression.left.name.getText();
13
14
  const pos = node.expression.left.name.pos;
14
- const fix = isFixExports ? [node.getStart(), node.getEnd()] : undefined;
15
+ const fix = isFixExports ? [node.getStart(), node.getEnd(), FIX_FLAGS.NONE] : undefined;
15
16
  return {
16
17
  node: node.expression.left.name,
17
18
  identifier,
@@ -24,7 +25,7 @@ export default visit(isJS, (node, { isFixExports }) => {
24
25
  const expr = node.expression.right;
25
26
  if (ts.isObjectLiteralExpression(expr) && expr.properties.every(ts.isShorthandPropertyAssignment)) {
26
27
  return expr.properties.map(node => {
27
- const fix = isFixExports ? [node.getStart(), node.getEnd()] : undefined;
28
+ const fix = isFixExports ? [node.getStart(), node.getEnd(), FIX_FLAGS.NONE] : undefined;
28
29
  return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.getStart(), fix };
29
30
  });
30
31
  }
@@ -40,7 +41,7 @@ export default visit(isJS, (node, { isFixExports }) => {
40
41
  isModuleExportsAccess(node.expression.left.expression)) {
41
42
  const identifier = stripQuotes(node.expression.left.argumentExpression.getText());
42
43
  const pos = node.expression.left.argumentExpression.pos;
43
- const fix = isFixExports ? [node.getStart(), node.getEnd()] : undefined;
44
+ const fix = isFixExports ? [node.getStart(), node.getEnd(), FIX_FLAGS.NONE] : undefined;
44
45
  return {
45
46
  node: node.expression.left.argumentExpression,
46
47
  identifier,
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import type ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined)[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[])[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | string | string[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | string | string[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import type ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => string | string[] | undefined)[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | string | string[])[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | string | string[];
3
3
  export default _default;
package/dist/util/fs.d.ts CHANGED
@@ -7,5 +7,4 @@ export declare const loadYAML: (filePath: string) => Promise<unknown>;
7
7
  export declare const loadTOML: (filePath: string) => Promise<Record<string, import("smol-toml").TomlPrimitive>>;
8
8
  export declare const parseJSON: (filePath: string, contents: string) => Promise<any>;
9
9
  export declare const parseYAML: (contents: string) => unknown;
10
- export declare function isTypeModule(path: string): boolean;
11
10
  export declare const _loadJSON: (filePath: string) => Promise<any>;
package/dist/util/fs.js CHANGED
@@ -1,11 +1,11 @@
1
- import { readFileSync, statSync } from 'node:fs';
1
+ import { statSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import yaml from 'js-yaml';
4
4
  import { parse as parseTOML } from 'smol-toml';
5
5
  import stripJsonComments from 'strip-json-comments';
6
6
  import { timerify } from './Performance.js';
7
7
  import { LoaderError } from './errors.js';
8
- import { dirname, join } from './path.js';
8
+ import { join } from './path.js';
9
9
  export const isDirectory = (filePath) => {
10
10
  try {
11
11
  return statSync(filePath).isDirectory();
@@ -58,19 +58,4 @@ export const parseJSON = async (filePath, contents) => {
58
58
  export const parseYAML = (contents) => {
59
59
  return yaml.load(contents);
60
60
  };
61
- export function isTypeModule(path) {
62
- while (path && path !== '.' && path !== '/') {
63
- path = dirname(path);
64
- try {
65
- const pkg = readFileSync(join(path, 'package.json'), 'utf-8');
66
- try {
67
- return JSON.parse(pkg).type === 'module';
68
- }
69
- catch { }
70
- break;
71
- }
72
- catch { }
73
- }
74
- return false;
75
- }
76
61
  export const _loadJSON = timerify(loadJSON);
@@ -36,7 +36,7 @@ export const parseAndConvertGitignorePatterns = (patterns, ancestor) => {
36
36
  .split(/\r?\n/)
37
37
  .filter(line => line.trim() && !line.startsWith('#'))
38
38
  .flatMap(line => {
39
- const pattern = line.replace(/(?<!\\)#.*/, '').trim();
39
+ const pattern = line.replace(/^\\(?=#)/, '').trim();
40
40
  if (ancestor && matchFrom) {
41
41
  if (pattern.match(matchFrom))
42
42
  return [pattern.replace(matchFrom, '$1')];
@@ -1,2 +1 @@
1
- export declare const jitiCJS: any;
2
- export declare const jitiESM: any;
1
+ export declare const jiti: import("jiti").Jiti;
package/dist/util/jiti.js CHANGED
@@ -1,17 +1,12 @@
1
1
  import { fileURLToPath } from 'node:url';
2
- import createJITI, {} from 'jiti';
3
- import { DEFAULT_EXTENSIONS } from '../constants.js';
2
+ import { createJiti } from 'jiti';
4
3
  import { join } from './path.js';
5
4
  const empty = join(fileURLToPath(import.meta.url), '../empty.js');
6
5
  const options = {
7
- interopDefault: true,
8
- extensions: DEFAULT_EXTENSIONS,
9
- esmResolve: false,
10
6
  alias: {
11
7
  '@rushstack/eslint-config/patch/modern-module-resolution': empty,
12
8
  '@rushstack/eslint-patch/modern-module-resolution': empty,
13
9
  },
14
10
  };
15
- const createLoader = (options) => createJITI(process.cwd(), options);
16
- export const jitiCJS = createLoader(options);
17
- export const jitiESM = createLoader({ ...options, esmResolve: true });
11
+ const createLoader = (options) => createJiti(process.cwd(), options);
12
+ export const jiti = createLoader(options);
@@ -1,9 +1,7 @@
1
- import { pathToFileURL } from 'node:url';
2
1
  import { timerify } from './Performance.js';
3
2
  import { LoaderError } from './errors.js';
4
3
  import { loadFile, loadJSON, loadTOML, loadYAML, parseJSON, parseYAML } from './fs.js';
5
- import { isTypeModule } from './fs.js';
6
- import { jitiCJS, jitiESM } from './jiti.js';
4
+ import { jiti } from './jiti.js';
7
5
  import { extname, isInternal } from './path.js';
8
6
  const load = async (filePath) => {
9
7
  try {
@@ -33,15 +31,7 @@ const load = async (filePath) => {
33
31
  if (ext === '.toml') {
34
32
  return await loadTOML(filePath);
35
33
  }
36
- if (ext === '.mjs' || (ext === '.js' && isTypeModule(filePath))) {
37
- const fileUrl = pathToFileURL(filePath);
38
- const imported = await import(fileUrl.href);
39
- return imported.default ?? imported;
40
- }
41
- if (ext === '.mts' || ((ext === '.ts' || ext === '.tsx') && isTypeModule(filePath))) {
42
- return await jitiESM(filePath);
43
- }
44
- return await jitiCJS(filePath);
34
+ return await jiti.import(filePath);
45
35
  }
46
36
  catch (error) {
47
37
  throw new LoaderError(`Error loading ${filePath}`, { cause: error });
@@ -0,0 +1,8 @@
1
+ interface FixerOptions {
2
+ text: string;
3
+ start: number;
4
+ end: number;
5
+ flags: number;
6
+ }
7
+ export declare const removeExport: ({ text, start, end, flags }: FixerOptions) => string;
8
+ export {};
@@ -0,0 +1,68 @@
1
+ import { FIX_FLAGS } from '../constants.js';
2
+ const getOpeningBracketIndex = (text) => {
3
+ let bracketOpenIndex = -1;
4
+ let j = text.length - 1;
5
+ while (j >= 0) {
6
+ const char = text[j];
7
+ if (char === '{') {
8
+ bracketOpenIndex = j;
9
+ break;
10
+ }
11
+ if (!/\s/.test(char) && char !== ',') {
12
+ if (text.substring(j - 3, j + 1) === 'type') {
13
+ j = j - 4;
14
+ continue;
15
+ }
16
+ break;
17
+ }
18
+ j--;
19
+ }
20
+ return bracketOpenIndex;
21
+ };
22
+ export const removeExport = ({ text, start, end, flags }) => {
23
+ const beforeStart = text.substring(0, start);
24
+ const afterEnd = text.substring(end);
25
+ if (flags % FIX_FLAGS.NONE)
26
+ return beforeStart + afterEnd;
27
+ const subject = text.substring(start, end).trim();
28
+ if (subject === 'export' || subject === 'export default')
29
+ return beforeStart + afterEnd;
30
+ let closingBracketOffset = -1;
31
+ let commaOffset = -1;
32
+ if (flags & FIX_FLAGS.OBJECT_BINDING) {
33
+ let i = 0;
34
+ while (i <= afterEnd.length) {
35
+ const char = afterEnd[i];
36
+ if (char === ',') {
37
+ commaOffset = i + 1;
38
+ }
39
+ else if (char === '}') {
40
+ closingBracketOffset = i + 1;
41
+ break;
42
+ }
43
+ else if (!/\s/.test(char))
44
+ break;
45
+ i++;
46
+ }
47
+ }
48
+ if (flags & FIX_FLAGS.EMPTY_DECLARATION && closingBracketOffset !== -1) {
49
+ const openingBracketIndex = getOpeningBracketIndex(beforeStart);
50
+ if (closingBracketOffset !== -1 && openingBracketIndex !== -1) {
51
+ const beforeBracket = beforeStart.substring(0, openingBracketIndex).trim();
52
+ const exportLength = beforeBracket.endsWith('export') ? 6 : beforeBracket.endsWith('export type') ? 12 : 0;
53
+ const exportKeywordOffset = beforeBracket.length - exportLength;
54
+ if (exportLength) {
55
+ const fromBracket = afterEnd.substring(closingBracketOffset).trim();
56
+ if (fromBracket.startsWith('from')) {
57
+ const specifierQuoteMatch = afterEnd.match(/['"][^'"]+['"]/);
58
+ if (specifierQuoteMatch?.index) {
59
+ const fromSpecifierLength = specifierQuoteMatch.index + specifierQuoteMatch[0].length;
60
+ return beforeBracket.substring(0, exportKeywordOffset) + afterEnd.substring(fromSpecifierLength);
61
+ }
62
+ }
63
+ return beforeBracket.substring(0, exportKeywordOffset) + afterEnd.substring(closingBracketOffset);
64
+ }
65
+ }
66
+ }
67
+ return beforeStart + (commaOffset === -1 ? afterEnd : afterEnd.substring(commaOffset));
68
+ };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.30.6";
1
+ export declare const version = "5.31.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.30.6';
1
+ export const version = '5.31.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.30.6",
3
+ "version": "5.31.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "easy-table": "1.2.0",
67
67
  "enhanced-resolve": "^5.17.1",
68
68
  "fast-glob": "^3.3.2",
69
- "jiti": "^1.21.6",
69
+ "jiti": "^2.1.0",
70
70
  "js-yaml": "^4.1.0",
71
71
  "minimist": "^1.2.8",
72
72
  "picocolors": "^1.0.0",