knip 6.12.2 → 6.13.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/DependencyDeputy.d.ts +1 -1
  2. package/dist/ProjectPrincipal.d.ts +3 -2
  3. package/dist/ProjectPrincipal.js +5 -3
  4. package/dist/WorkspaceWorker.d.ts +1 -1
  5. package/dist/WorkspaceWorker.js +1 -1
  6. package/dist/compilers/compilers.js +4 -1
  7. package/dist/constants.js +1 -0
  8. package/dist/graph/analyze.js +1 -1
  9. package/dist/graph/build.d.ts +1 -1
  10. package/dist/graph/build.js +2 -2
  11. package/dist/graph-explorer/operations/is-referenced.js +5 -5
  12. package/dist/plugins/astro/resolveFromAST.js +2 -1
  13. package/dist/plugins/babel/helpers.d.ts +0 -38
  14. package/dist/plugins/execa/visitors/execa.js +1 -1
  15. package/dist/plugins/jest/index.js +10 -5
  16. package/dist/plugins/knex/index.js +5 -0
  17. package/dist/plugins/knex/visitors/clientCall.d.ts +2 -0
  18. package/dist/plugins/knex/visitors/clientCall.js +83 -0
  19. package/dist/plugins/nuxt/helpers.js +1 -1
  20. package/dist/plugins/pino/visitors/transportCall.js +1 -1
  21. package/dist/plugins/sst/resolveFromAST.js +1 -1
  22. package/dist/plugins/vite/visitors/importMetaGlob.js +1 -1
  23. package/dist/plugins/webpack/visitors/requireContext.js +1 -1
  24. package/dist/run.js +3 -2
  25. package/dist/typescript/ast-helpers.d.ts +0 -1
  26. package/dist/typescript/ast-helpers.js +1 -3
  27. package/dist/typescript/{visitors/helpers.d.ts → ast-nodes.d.ts} +3 -3
  28. package/dist/typescript/{visitors/helpers.js → ast-nodes.js} +3 -3
  29. package/dist/typescript/follow-imports.js +1 -1
  30. package/dist/typescript/get-imports-and-exports.d.ts +1 -1
  31. package/dist/typescript/get-imports-and-exports.js +1 -1
  32. package/dist/typescript/resolve-module-names.d.ts +3 -3
  33. package/dist/typescript/resolve-module-names.js +29 -1
  34. package/dist/typescript/visitors/calls.js +1 -1
  35. package/dist/typescript/visitors/exports.js +1 -1
  36. package/dist/typescript/visitors/imports.js +1 -1
  37. package/dist/typescript/visitors/members.js +1 -1
  38. package/dist/typescript/visitors/walk.d.ts +1 -1
  39. package/dist/typescript/visitors/walk.js +1 -1
  40. package/dist/util/load-tsconfig.d.ts +2 -0
  41. package/dist/util/load-tsconfig.js +19 -14
  42. package/dist/util/to-source-path.d.ts +5 -0
  43. package/dist/util/to-source-path.js +47 -22
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +1 -1
  46. package/package.json +4 -4
@@ -14,7 +14,7 @@ export declare class DependencyDeputy {
14
14
  installedBinaries: Map<string, InstalledBinaries>;
15
15
  hasTypesIncluded: Map<string, Set<string>>;
16
16
  constructor({ isProduction, isStrict, isReportDependencies }: MainOptions);
17
- addWorkspace({ name, cwd, dir, manifestPath, manifestStr, manifest, ignoreDependencies: id, ignoreBinaries: ib, ignoreUnresolved: iu }: {
17
+ addWorkspace({ name, cwd, dir, manifestPath, manifestStr, manifest, ignoreDependencies: id, ignoreBinaries: ib, ignoreUnresolved: iu, }: {
18
18
  name: string;
19
19
  cwd: string;
20
20
  dir: string;
@@ -6,7 +6,7 @@ import type { FileNode, ModuleGraph } from './types/module-graph.ts';
6
6
  import type { Paths } from './types/project.ts';
7
7
  import { SourceFileManager } from './typescript/SourceFileManager.ts';
8
8
  import type { MainOptions } from './util/create-options.ts';
9
- import type { ToSourceFilePath } from './util/to-source-path.ts';
9
+ import type { ToSourceFilePath, WorkspaceManifestHandler } from './util/to-source-path.ts';
10
10
  export declare class ProjectPrincipal {
11
11
  entryPaths: Set<string>;
12
12
  projectPaths: Set<string>;
@@ -22,11 +22,12 @@ export declare class ProjectPrincipal {
22
22
  private extensions;
23
23
  cache: CacheConsultant<FileNode>;
24
24
  toSourceFilePath: ToSourceFilePath;
25
+ private findWorkspaceManifestImports;
25
26
  fileManager: SourceFileManager;
26
27
  private resolveModule;
27
28
  resolvedFiles: Set<string>;
28
29
  deletedFiles: Set<string>;
29
- constructor(options: MainOptions, toSourceFilePath: ToSourceFilePath);
30
+ constructor(options: MainOptions, toSourceFilePath: ToSourceFilePath, findWorkspaceManifestImports?: WorkspaceManifestHandler);
30
31
  addCompilers(compilers: [SyncCompilers, AsyncCompilers]): void;
31
32
  addPaths(paths: Paths, basePath: string): void;
32
33
  addRootDirs(rootDirs: string[]): void;
@@ -1,5 +1,5 @@
1
1
  import { extractSpecifiers } from './typescript/follow-imports.js';
2
- import { parseFile } from './typescript/visitors/helpers.js';
2
+ import { parseFile } from './typescript/ast-nodes.js';
3
3
  import { CacheConsultant } from './CacheConsultant.js';
4
4
  import { getCompilerExtensions } from './compilers/index.js';
5
5
  import { DEFAULT_EXTENSIONS } from './constants.js';
@@ -31,13 +31,15 @@ export class ProjectPrincipal {
31
31
  extensions = new Set(DEFAULT_EXTENSIONS);
32
32
  cache;
33
33
  toSourceFilePath;
34
+ findWorkspaceManifestImports;
34
35
  fileManager;
35
36
  resolveModule = () => undefined;
36
37
  resolvedFiles = new Set();
37
38
  deletedFiles = new Set();
38
- constructor(options, toSourceFilePath) {
39
+ constructor(options, toSourceFilePath, findWorkspaceManifestImports) {
39
40
  this.cache = new CacheConsultant('root', options);
40
41
  this.toSourceFilePath = toSourceFilePath;
42
+ this.findWorkspaceManifestImports = findWorkspaceManifestImports;
41
43
  this.pluginVisitorObjects.push(createBunShellVisitor(this.pluginCtx));
42
44
  this.fileManager = new SourceFileManager({
43
45
  compilers: [this.syncCompilers, this.asyncCompilers],
@@ -84,7 +86,7 @@ export class ProjectPrincipal {
84
86
  const customCompilerExtensions = getCompilerExtensions([this.syncCompilers, this.asyncCompilers]);
85
87
  const pathsOrUndefined = Object.keys(this.paths).length > 0 ? this.paths : undefined;
86
88
  const rootDirsOrUndefined = this.rootDirs.length > 1 ? this.rootDirs : undefined;
87
- this.resolveModule = createCustomModuleResolver({ paths: pathsOrUndefined, rootDirs: rootDirsOrUndefined }, customCompilerExtensions, this.toSourceFilePath);
89
+ this.resolveModule = createCustomModuleResolver({ paths: pathsOrUndefined, rootDirs: rootDirsOrUndefined }, customCompilerExtensions, this.toSourceFilePath, this.findWorkspaceManifestImports);
88
90
  }
89
91
  readFile(filePath) {
90
92
  return this.fileManager.readFile(filePath);
@@ -47,7 +47,7 @@ export declare class WorkspaceWorker {
47
47
  enabledPluginsInAncestors: string[];
48
48
  cache: CacheConsultant<CacheItem>;
49
49
  configFilesMap: Map<string, Map<PluginName, Set<string>>>;
50
- constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, readFile, configFilesMap, options }: WorkspaceManagerOptions);
50
+ constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, readFile, configFilesMap, options, }: WorkspaceManagerOptions);
51
51
  init(): Promise<void>;
52
52
  private determineEnabledPlugins;
53
53
  private getConfigForPlugin;
@@ -7,7 +7,7 @@ import { getFilteredScripts } from './manifest/helpers.js';
7
7
  import { PluginEntries, Plugins } from './plugins.js';
8
8
  import { createManifest } from './util/package-json.js';
9
9
  import { collectStringLiterals, isExternalReExportsOnly } from './typescript/ast-helpers.js';
10
- import { parseFile } from './typescript/visitors/helpers.js';
10
+ import { parseFile } from './typescript/ast-nodes.js';
11
11
  import { compact } from './util/array.js';
12
12
  import { debugLogArray, debugLogObject } from './util/debug.js';
13
13
  import { _glob, hasNoProductionSuffix, hasProductionSuffix, negate } from './util/glob.js';
@@ -1,12 +1,15 @@
1
1
  export const fencedCodeBlockMatcher = /```[\s\S]*?```/g;
2
2
  export const inlineCodeMatcher = /`[^`]+`/g;
3
3
  const scriptExtractor = /<script\b(?:[^>"']|"[^"]*"|'[^']*')*>([\s\S]*?)<\/script>/gm;
4
+ const blockCommentMatcher = /\/\*[\s\S]*?\*\//g;
5
+ const lineCommentMatcher = /^[ \t]*\/\/.*$/gm;
4
6
  export const importMatcher = /import[^'"]+['"][^'"]+['"]/g;
5
7
  export const importsWithinScripts = (text) => {
6
8
  const scripts = [];
7
9
  let scriptMatch;
8
10
  while ((scriptMatch = scriptExtractor.exec(text))) {
9
- for (const importMatch of scriptMatch[1].matchAll(importMatcher)) {
11
+ const body = scriptMatch[1].replace(blockCommentMatcher, '').replace(lineCommentMatcher, '');
12
+ for (const importMatch of body.matchAll(importMatcher)) {
10
13
  scripts.push(importMatch);
11
14
  }
12
15
  }
package/dist/constants.js CHANGED
@@ -65,6 +65,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
65
65
  'groups',
66
66
  'gzip',
67
67
  'head',
68
+ 'hg',
68
69
  'id',
69
70
  'join',
70
71
  'kill',
@@ -1,7 +1,7 @@
1
1
  import { createGraphExplorer } from '../graph-explorer/explorer.js';
2
2
  import { getIssueType, hasStrictlyEnumReferences } from '../graph-explorer/utils.js';
3
3
  import traceReporter from '../reporters/trace.js';
4
- import { shouldCountRefs } from '../typescript/visitors/helpers.js';
4
+ import { shouldCountRefs } from '../typescript/ast-nodes.js';
5
5
  import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
6
6
  import { perfObserver } from '../util/Performance.js';
7
7
  import { findMatch } from '../util/regex.js';
@@ -17,7 +17,7 @@ interface BuildOptions {
17
17
  workspaces: Workspace[];
18
18
  options: MainOptions;
19
19
  }
20
- export declare function build({ chief, collector, counselor, deputy, principal, isGitIgnored, streamer, workspaces, options }: BuildOptions): Promise<{
20
+ export declare function build({ chief, collector, counselor, deputy, principal, isGitIgnored, streamer, workspaces, options, }: BuildOptions): Promise<{
21
21
  graph: ModuleGraph;
22
22
  entryPaths: Set<string>;
23
23
  analyzedFiles: Set<string>;
@@ -58,7 +58,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
58
58
  const dependencies = deputy.getDependencies(name);
59
59
  const baseConfig = chief.getConfigForWorkspace(name);
60
60
  const tsConfigFilePath = join(dir, options.tsConfigFile ?? 'tsconfig.json');
61
- const { isFile, compilerOptions, fileNames, include, exclude } = await loadTSConfig(tsConfigFilePath);
61
+ const { isFile, compilerOptions, fileNames, include, exclude, sourceMapPairs } = await loadTSConfig(tsConfigFilePath);
62
62
  const [definitionPaths, tscSourcePaths] = partition(fileNames, filePath => IS_DTS.test(filePath));
63
63
  const worker = new WorkspaceWorker({
64
64
  name,
@@ -91,7 +91,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
91
91
  const config = chief.getConfigForWorkspace(name, extensions);
92
92
  worker.config = config;
93
93
  const pluginSourceMaps = await worker.resolveSourceMaps();
94
- augmentWorkspace(workspace, dir, isFile ? compilerOptions : undefined, pluginSourceMaps);
94
+ augmentWorkspace(workspace, dir, isFile ? compilerOptions : undefined, [...pluginSourceMaps, ...sourceMapPairs]);
95
95
  const inputs = new Set();
96
96
  if (definitionPaths.length > 0) {
97
97
  debugLogArray(name, 'Definition paths', definitionPaths);
@@ -15,7 +15,7 @@ const hasOnlyNsRefs = (file) => {
15
15
  };
16
16
  export const isReferenced = (graph, entryPaths, filePath, id, options) => {
17
17
  const seen = new Set();
18
- const walkDown = (path, id) => {
18
+ const walkDown = (path, id, viaStar = false) => {
19
19
  const isEntryFile = entryPaths.has(path);
20
20
  let reExportingEntryFile = isEntryFile ? path : undefined;
21
21
  if (seen.has(path))
@@ -25,13 +25,13 @@ export const isReferenced = (graph, entryPaths, filePath, id, options) => {
25
25
  const identifier = restIds.shift();
26
26
  const file = graph.get(path)?.importedBy;
27
27
  if (!identifier || !file) {
28
- return [false, reExportingEntryFile];
28
+ return [isEntryFile && viaStar && restIds.length > 0, reExportingEntryFile];
29
29
  }
30
- const follow = (sources, nextId) => {
30
+ const follow = (sources, nextId, nextViaStar = viaStar) => {
31
31
  for (const byFilePath of sources) {
32
32
  if (seen.has(byFilePath))
33
33
  continue;
34
- const result = walkDown(byFilePath, nextId);
34
+ const result = walkDown(byFilePath, nextId, nextViaStar);
35
35
  if (result[1])
36
36
  reExportingEntryFile = result[1];
37
37
  if (result[0])
@@ -87,7 +87,7 @@ export const isReferenced = (graph, entryPaths, filePath, id, options) => {
87
87
  return [true, reExportingEntryFile];
88
88
  }
89
89
  else if (starSources) {
90
- if (follow(starSources, id))
90
+ if (follow(starSources, id, true))
91
91
  return [true, reExportingEntryFile];
92
92
  }
93
93
  for (const [namespace, sources] of file.reExportNs) {
@@ -1,4 +1,5 @@
1
- import { collectPropertyValues, findProperty, getPropertyKey, getStringValue, hasImportSpecifier, resolveObjectArg, } from '../../typescript/ast-helpers.js';
1
+ import { getStringValue } from '../../typescript/ast-nodes.js';
2
+ import { collectPropertyValues, findProperty, getPropertyKey, hasImportSpecifier, resolveObjectArg, } from '../../typescript/ast-helpers.js';
2
3
  export const getSrcDir = (program) => {
3
4
  const values = collectPropertyValues(program, 'srcDir');
4
5
  return values.size > 0 ? Array.from(values)[0] : 'src';
@@ -1,41 +1,4 @@
1
1
  export declare const resolveName: (identifier: string, namespace: 'preset' | 'plugin') => string;
2
- declare function cacheFn(): undefined;
3
- declare namespace cacheFn {
4
- var forever: () => {
5
- (): undefined;
6
- forever: any;
7
- never: () => any;
8
- using: () => any;
9
- invalidate: () => any;
10
- };
11
- }
12
- declare namespace cacheFn {
13
- var never: () => {
14
- (): undefined;
15
- forever: () => any;
16
- never: any;
17
- using: () => any;
18
- invalidate: () => any;
19
- };
20
- }
21
- declare namespace cacheFn {
22
- var using: () => {
23
- (): undefined;
24
- forever: () => any;
25
- never: () => any;
26
- using: any;
27
- invalidate: () => any;
28
- };
29
- }
30
- declare namespace cacheFn {
31
- var invalidate: () => {
32
- (): undefined;
33
- forever: () => any;
34
- never: () => any;
35
- using: () => any;
36
- invalidate: any;
37
- };
38
- }
39
2
  export declare const api: {
40
3
  assertVersion: () => boolean;
41
4
  cache: {
@@ -49,4 +12,3 @@ export declare const api: {
49
12
  env: (env?: string) => "development" | true;
50
13
  version: string;
51
14
  };
52
- export {};
@@ -1,4 +1,4 @@
1
- import { getStringValue, isStringLiteral } from '../../../typescript/visitors/helpers.js';
1
+ import { getStringValue, isStringLiteral } from '../../../typescript/ast-nodes.js';
2
2
  const tags = new Set(['$', '$sync']);
3
3
  const methods = new Set(['execa', 'execaSync', 'execaCommand', 'execaCommandSync', '$sync']);
4
4
  export function createExecaVisitor(ctx) {
@@ -1,3 +1,4 @@
1
+ import { _glob, _dirGlob } from '../../util/glob.js';
1
2
  import { toDeferResolve, toEntry } from '../../util/input.js';
2
3
  import { isInternal, join, normalize, toAbsolute } from '../../util/path.js';
3
4
  import { hasDependency } from '../../util/plugin.js';
@@ -8,7 +9,8 @@ const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, en
8
9
  const config = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json'];
9
10
  const mocks = ['**/__mocks__/**/*.[jt]s?(x)'];
10
11
  const entry = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)', ...mocks];
11
- const resolveDependencies = async (config, options) => {
12
+ const rootDirRe = /<rootDir>/;
13
+ const resolveDependencies = async (config, rootDir, options) => {
12
14
  const { configFileDir } = options;
13
15
  if (config?.preset) {
14
16
  const { preset } = config;
@@ -22,10 +24,13 @@ const resolveDependencies = async (config, options) => {
22
24
  const projects = [];
23
25
  for (const project of config.projects ?? []) {
24
26
  if (typeof project === 'string') {
25
- projects.push(project);
27
+ const patterns = [project.replace(rootDirRe, rootDir)];
28
+ const files = await _glob({ patterns, cwd: options.cwd });
29
+ const dirs = await _dirGlob({ patterns, cwd: options.cwd });
30
+ projects.push(...files, ...dirs);
26
31
  }
27
32
  else {
28
- const dependencies = await resolveDependencies(project, options);
33
+ const dependencies = await resolveDependencies(project, rootDir, options);
29
34
  for (const dependency of dependencies)
30
35
  projects.push(dependency);
31
36
  }
@@ -80,8 +85,8 @@ const resolveConfig = async (localConfig, options) => {
80
85
  if (typeof localConfig === 'function')
81
86
  localConfig = await localConfig();
82
87
  const rootDir = localConfig.rootDir ?? configFileDir;
83
- const replaceRootDir = (name) => name.replace(/<rootDir>/, rootDir);
84
- const inputs = await resolveDependencies(localConfig, options);
88
+ const replaceRootDir = (name) => name.replace(rootDirRe, rootDir);
89
+ const inputs = await resolveDependencies(localConfig, rootDir, options);
85
90
  const entries = localConfig.testMatch
86
91
  ? localConfig.testMatch.map(replaceRootDir).map(id => toEntry(id))
87
92
  : entry.map(id => toEntry(id));
@@ -1,6 +1,7 @@
1
1
  import { toDependency, toEntry } from '../../util/input.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
3
  import { clientToPackages } from './helpers.js';
4
+ import { createKnexClientVisitor } from './visitors/clientCall.js';
4
5
  const title = 'Knex';
5
6
  const enablers = ['knex'];
6
7
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -27,11 +28,15 @@ const resolveConfig = config => {
27
28
  const configs = 'client' in config && config.client ? [config] : Object.values(config);
28
29
  return configs.flatMap(cfg => (typeof cfg === 'object' && cfg !== null ? processKnexConfig(cfg) : []));
29
30
  };
31
+ const registerVisitors = ({ ctx, registerVisitor }) => {
32
+ registerVisitor(createKnexClientVisitor(ctx));
33
+ };
30
34
  const plugin = {
31
35
  title,
32
36
  enablers,
33
37
  isEnabled,
34
38
  config,
35
39
  resolveConfig,
40
+ registerVisitors,
36
41
  };
37
42
  export default plugin;
@@ -0,0 +1,2 @@
1
+ import type { PluginVisitorContext, PluginVisitorObject } from '../../../types/config.ts';
2
+ export declare function createKnexClientVisitor(ctx: PluginVisitorContext): PluginVisitorObject;
@@ -0,0 +1,83 @@
1
+ import { IMPORT_FLAGS } from '../../../constants.js';
2
+ import { getStringValue, isStringLiteral } from '../../../typescript/ast-nodes.js';
3
+ import { clientToPackages } from '../helpers.js';
4
+ const KNEX = 'knex';
5
+ export function createKnexClientVisitor(ctx) {
6
+ const defaultNames = new Set();
7
+ const namedNames = new Set();
8
+ const addClientPackages = (obj, pos) => {
9
+ for (const prop of obj.properties) {
10
+ if (prop.type !== 'Property' || prop.computed || prop.key.type !== 'Identifier')
11
+ continue;
12
+ if (prop.key.name !== 'client')
13
+ continue;
14
+ if (!isStringLiteral(prop.value))
15
+ return;
16
+ const client = getStringValue(prop.value);
17
+ if (!client)
18
+ return;
19
+ for (const pkg of clientToPackages(client)) {
20
+ ctx.addImport(pkg, pos, IMPORT_FLAGS.NONE);
21
+ }
22
+ return;
23
+ }
24
+ };
25
+ return {
26
+ Program() {
27
+ defaultNames.clear();
28
+ namedNames.clear();
29
+ },
30
+ ImportDeclaration(node) {
31
+ if (!isStringLiteral(node.source) || getStringValue(node.source) !== KNEX)
32
+ return;
33
+ for (const spec of node.specifiers ?? []) {
34
+ if (spec.type === 'ImportDefaultSpecifier') {
35
+ defaultNames.add(spec.local.name);
36
+ }
37
+ else if (spec.type === 'ImportSpecifier') {
38
+ if (spec.imported.type === 'Identifier' && spec.imported.name === KNEX) {
39
+ namedNames.add(spec.local.name);
40
+ }
41
+ }
42
+ }
43
+ },
44
+ VariableDeclarator(node) {
45
+ if (node.init?.type !== 'CallExpression' ||
46
+ node.init.callee.type !== 'Identifier' ||
47
+ node.init.callee.name !== 'require' ||
48
+ !isStringLiteral(node.init.arguments[0]) ||
49
+ getStringValue(node.init.arguments[0]) !== KNEX)
50
+ return;
51
+ if (node.id.type === 'Identifier') {
52
+ defaultNames.add(node.id.name);
53
+ }
54
+ else if (node.id.type === 'ObjectPattern') {
55
+ for (const prop of node.id.properties) {
56
+ if (prop.type === 'Property' &&
57
+ prop.key.type === 'Identifier' &&
58
+ prop.key.name === KNEX &&
59
+ prop.value.type === 'Identifier') {
60
+ namedNames.add(prop.value.name);
61
+ }
62
+ }
63
+ }
64
+ },
65
+ CallExpression(node) {
66
+ if (defaultNames.size === 0 && namedNames.size === 0)
67
+ return;
68
+ const arg = node.arguments[0];
69
+ if (arg?.type !== 'ObjectExpression')
70
+ return;
71
+ const callee = node.callee;
72
+ const isDirectCall = callee.type === 'Identifier' && (defaultNames.has(callee.name) || namedNames.has(callee.name));
73
+ const isNamespaceCall = callee.type === 'MemberExpression' &&
74
+ !callee.computed &&
75
+ callee.object.type === 'Identifier' &&
76
+ defaultNames.has(callee.object.name) &&
77
+ callee.property.type === 'Identifier' &&
78
+ callee.property.name === KNEX;
79
+ if (isDirectCall || isNamespaceCall)
80
+ addClientPackages(arg, arg.start);
81
+ },
82
+ };
83
+ }
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';
2
2
  import { createRequire } from 'node:module';
3
3
  import { Visitor } from 'oxc-parser';
4
4
  import { scriptBodies } from '../../compilers/compilers.js';
5
- import { parseFile } from '../../typescript/visitors/helpers.js';
5
+ import { parseFile } from '../../typescript/ast-nodes.js';
6
6
  import { basename, dirname, isInNodeModules, join } from '../../util/path.js';
7
7
  export const getVueSfc = (cwd) => {
8
8
  try {
@@ -1,5 +1,5 @@
1
1
  import { IMPORT_FLAGS } from '../../../constants.js';
2
- import { getStringValue, isStringLiteral } from '../../../typescript/visitors/helpers.js';
2
+ import { getStringValue, isStringLiteral } from '../../../typescript/ast-nodes.js';
3
3
  import { isInternal } from '../../../util/path.js';
4
4
  const PINO = 'pino';
5
5
  export function createPinoTransportVisitor(ctx) {
@@ -1,6 +1,6 @@
1
1
  import { Visitor } from 'oxc-parser';
2
2
  import { collectPropertyValues, getImportMap } from '../../typescript/ast-helpers.js';
3
- import { parseFile } from '../../typescript/visitors/helpers.js';
3
+ import { parseFile } from '../../typescript/ast-nodes.js';
4
4
  import { toDeferResolveProductionEntry } from '../../util/input.js';
5
5
  import { dirname } from '../../util/path.js';
6
6
  import { _resolveSync } from '../../util/resolve.js';
@@ -1,7 +1,7 @@
1
1
  import { IMPORT_FLAGS } from '../../../constants.js';
2
2
  import { _syncGlob } from '../../../util/glob.js';
3
3
  import { dirname, isAbsolute, join } from '../../../util/path.js';
4
- import { getStringValue, isStringLiteral } from '../../../typescript/visitors/helpers.js';
4
+ import { getStringValue, isStringLiteral } from '../../../typescript/ast-nodes.js';
5
5
  export function createImportMetaGlobVisitor(ctx) {
6
6
  return {
7
7
  CallExpression(node) {
@@ -1,7 +1,7 @@
1
1
  import { IMPORT_FLAGS } from '../../../constants.js';
2
2
  import { _syncGlob } from '../../../util/glob.js';
3
3
  import { dirname, join, toRelative } from '../../../util/path.js';
4
- import { getStringValue, isStringLiteral } from '../../../typescript/visitors/helpers.js';
4
+ import { getStringValue, isStringLiteral } from '../../../typescript/ast-nodes.js';
5
5
  export function createRequireContextVisitor(ctx) {
6
6
  return {
7
7
  CallExpression(node) {
package/dist/run.js CHANGED
@@ -11,7 +11,7 @@ import watchReporter from './reporters/watch.js';
11
11
  import { debugLogObject } from './util/debug.js';
12
12
  import { flushGlobCache, initGlobCache } from './util/glob-cache.js';
13
13
  import { getGitIgnoredHandler } from './util/glob-core.js';
14
- import { getModuleSourcePathHandler } from './util/to-source-path.js';
14
+ import { getModuleSourcePathHandler, getWorkspaceManifestHandler } from './util/to-source-path.js';
15
15
  import { getSessionHandler } from './util/watch.js';
16
16
  export const run = async (options) => {
17
17
  debugLogObject('*', 'Unresolved configuration', options);
@@ -27,7 +27,8 @@ export const run = async (options) => {
27
27
  const workspaces = await chief.getWorkspaces();
28
28
  const isGitIgnored = await getGitIgnoredHandler(options, new Set(workspaces.map(w => w.dir)));
29
29
  const toSourceFilePath = getModuleSourcePathHandler(chief);
30
- const principal = new ProjectPrincipal(options, toSourceFilePath);
30
+ const findWorkspaceManifestImports = getWorkspaceManifestHandler(chief);
31
+ const principal = new ProjectPrincipal(options, toSourceFilePath, findWorkspaceManifestImports);
31
32
  collector.setWorkspaceFilter(chief.workspaceFilePathFilter);
32
33
  collector.setIgnoreIssues(chief.config.ignoreIssues);
33
34
  debugLogObject('*', 'Included workspaces', () => workspaces.map(w => w.pkgName));
@@ -1,5 +1,4 @@
1
1
  import type { ParseResult, Program } from 'oxc-parser';
2
- export declare const getStringValue: (node: any) => string | undefined;
3
2
  export declare const getPropertyKey: (prop: any) => string | undefined;
4
3
  export declare const getImportMap: (program: Program) => Map<string, string>;
5
4
  export declare const getDefaultImportName: (importMap: Map<string, string>, specifier: string) => string | undefined;
@@ -1,9 +1,7 @@
1
1
  import { Visitor } from 'oxc-parser';
2
2
  import stripJsonComments from 'strip-json-comments';
3
3
  import { extname, isInternal } from '../util/path.js';
4
- import { parseFile } from './visitors/helpers.js';
5
- const isStringLiteral = (node) => node?.type === 'StringLiteral' || (node?.type === 'Literal' && typeof node.value === 'string');
6
- export const getStringValue = (node) => (isStringLiteral(node) ? node.value : undefined);
4
+ import { getStringValue, isStringLiteral, parseFile } from './ast-nodes.js';
7
5
  export const getPropertyKey = (prop) => prop?.key?.type === 'Identifier' ? prop.key.name : getStringValue(prop?.key);
8
6
  export const getImportMap = (program) => {
9
7
  const importMap = new Map();
@@ -1,7 +1,7 @@
1
1
  import { type TSEnumDeclaration, type TSModuleDeclaration } from 'oxc-parser';
2
- import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile } from '../../types/config.ts';
3
- import type { SymbolType } from '../../types/issues.ts';
4
- import type { ExportMember } from '../../types/module-graph.ts';
2
+ import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile } from '../types/config.ts';
3
+ import type { SymbolType } from '../types/issues.ts';
4
+ import type { ExportMember } from '../types/module-graph.ts';
5
5
  export declare const parseFile: (filePath: string, sourceText: string) => import("oxc-parser").ParseResult;
6
6
  export type ResolveModule = (specifier: string, containingFile: string) => ResolvedModule | undefined;
7
7
  export interface ResolvedModule {
@@ -1,7 +1,7 @@
1
1
  import { parseSync, rawTransferSupported, } from 'oxc-parser';
2
- import { DEFAULT_EXTENSIONS, FIX_FLAGS, SYMBOL_TYPE } from '../../constants.js';
3
- import { extname } from '../../util/path.js';
4
- import { EMPTY_TAGS } from './jsdoc.js';
2
+ import { DEFAULT_EXTENSIONS, FIX_FLAGS, SYMBOL_TYPE } from '../constants.js';
3
+ import { extname } from '../util/path.js';
4
+ import { EMPTY_TAGS } from './visitors/jsdoc.js';
5
5
  const defaultParseOptions = {
6
6
  sourceType: 'unambiguous',
7
7
  experimentalRawTransfer: rawTransferSupported(),
@@ -1,6 +1,6 @@
1
1
  import { Visitor } from 'oxc-parser';
2
2
  import { isInNodeModules } from '../util/path.js';
3
- import { getStringValue, isStringLiteral, stripQuotes } from './visitors/helpers.js';
3
+ import { getStringValue, isStringLiteral, stripQuotes } from './ast-nodes.js';
4
4
  const _requireSpecs = [];
5
5
  const _requireVisitor = new Visitor({
6
6
  CallExpression(node) {
@@ -1,5 +1,5 @@
1
1
  import type { ParseResult, Visitor } from 'oxc-parser';
2
2
  import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile, PluginVisitorContext } from '../types/config.ts';
3
3
  import type { FileNode } from '../types/module-graph.ts';
4
- import { type ResolveModule } from './visitors/helpers.ts';
4
+ import { type ResolveModule } from './ast-nodes.ts';
5
5
  export declare const _getImportsAndExports: (filePath: string, sourceText: string, resolveModule: ResolveModule, options: GetImportsAndExportsOptions, ignoreExportsUsedInFile: IgnoreExportsUsedInFile, skipExportsForFile: boolean, visitor: Visitor, pluginCtx: PluginVisitorContext | undefined, cachedParseResult?: ParseResult) => FileNode;
@@ -6,7 +6,7 @@ import { timerify } from '../util/Performance.js';
6
6
  import { dirname, isInNodeModules, resolve } from '../util/path.js';
7
7
  import { shouldIgnore } from '../util/tag.js';
8
8
  import { extractImportsFromComments } from './comments.js';
9
- import { buildLineStarts, getLineAndCol, parseFile, shouldCountRefs, } from './visitors/helpers.js';
9
+ import { buildLineStarts, getLineAndCol, parseFile, shouldCountRefs, } from './ast-nodes.js';
10
10
  import { buildJSDocTagLookup } from './visitors/jsdoc.js';
11
11
  import { walkAST } from './visitors/walk.js';
12
12
  const getImportsAndExports = (filePath, sourceText, resolveModule, options, ignoreExportsUsedInFile, skipExportsForFile, visitor, pluginCtx, cachedParseResult) => {
@@ -1,7 +1,7 @@
1
- import type { ToSourceFilePath } from '../util/to-source-path.ts';
2
- import type { ResolveModule } from './visitors/helpers.ts';
1
+ import type { ToSourceFilePath, WorkspaceManifestHandler } from '../util/to-source-path.ts';
2
+ import type { ResolveModule } from './ast-nodes.ts';
3
3
  export declare function clearModuleResolutionCaches(): void;
4
4
  export declare function createCustomModuleResolver(compilerOptions: {
5
5
  paths?: Record<string, string[]>;
6
6
  rootDirs?: string[];
7
- }, customCompilerExtensions: string[], toSourceFilePath: ToSourceFilePath): ResolveModule;
7
+ }, customCompilerExtensions: string[], toSourceFilePath: ToSourceFilePath, findWorkspaceManifestImports?: WorkspaceManifestHandler): ResolveModule;
@@ -5,6 +5,23 @@ import { sanitizeSpecifier } from '../util/modules.js';
5
5
  import { timerify } from '../util/Performance.js';
6
6
  import { dirname, extname, isAbsolute, isInNodeModules, join } from '../util/path.js';
7
7
  import { _createSyncModuleResolver, _resolveModuleSync } from '../util/resolve.js';
8
+ function pickStringTarget(value) {
9
+ if (typeof value === 'string')
10
+ return value;
11
+ if (!value || typeof value !== 'object' || Array.isArray(value))
12
+ return;
13
+ const obj = value;
14
+ for (const key of ['default', 'node', 'import', 'require']) {
15
+ const v = pickStringTarget(obj[key]);
16
+ if (v)
17
+ return v;
18
+ }
19
+ for (const v of Object.values(obj)) {
20
+ const s = pickStringTarget(v);
21
+ if (s)
22
+ return s;
23
+ }
24
+ }
8
25
  const moduleResolutionCaches = [];
9
26
  export function clearModuleResolutionCaches() {
10
27
  for (const cache of moduleResolutionCaches)
@@ -25,7 +42,7 @@ function compilePathMappings(paths) {
25
42
  }
26
43
  return mappings.length > 0 ? mappings : undefined;
27
44
  }
28
- export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath) {
45
+ export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, findWorkspaceManifestImports) {
29
46
  const customCompilerExtensionsSet = new Set(customCompilerExtensions);
30
47
  const hasCustomExts = customCompilerExtensionsSet.size > 0;
31
48
  const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions, ...DTS_EXTENSIONS];
@@ -83,6 +100,17 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
83
100
  }
84
101
  }
85
102
  }
103
+ if (specifier.startsWith('#') && findWorkspaceManifestImports) {
104
+ const ws = findWorkspaceManifestImports(containingFile);
105
+ if (ws) {
106
+ const target = pickStringTarget(ws.imports[specifier]);
107
+ if (target?.startsWith('.')) {
108
+ const sourcePath = toSourceFilePath(join(ws.dir, target));
109
+ if (sourcePath)
110
+ return toResult(sourcePath);
111
+ }
112
+ }
113
+ }
86
114
  if (rootDirs && !isAbsolute(specifier)) {
87
115
  const containingDir = dirname(containingFile);
88
116
  for (const srcRoot of rootDirs) {
@@ -1,6 +1,6 @@
1
1
  import { IMPORT_FLAGS, OPAQUE } from '../../constants.js';
2
2
  import { addValue } from '../../util/module-graph.js';
3
- import { getStringValue, isStringLiteral } from './helpers.js';
3
+ import { getStringValue, isStringLiteral } from '../ast-nodes.js';
4
4
  function extractInlineDirnamePath(node, s) {
5
5
  if (node?.type !== 'CallExpression')
6
6
  return undefined;
@@ -1,6 +1,6 @@
1
1
  import { ALIAS_TAG, FIX_FLAGS, IMPORT_FLAGS, IMPORT_STAR, SYMBOL_TYPE } from '../../constants.js';
2
2
  import { addNsValue, addValue } from '../../util/module-graph.js';
3
- import { extractEnumMembers, extractNamespaceMembers, getLineAndCol, getStringValue, isStringLiteral, } from './helpers.js';
3
+ import { extractEnumMembers, extractNamespaceMembers, getLineAndCol, getStringValue, isStringLiteral, } from '../ast-nodes.js';
4
4
  import { EMPTY_TAGS } from './jsdoc.js';
5
5
  const getName = (n) => (n?.type === 'Identifier' ? n.name : undefined);
6
6
  const hasExplicitFunctionReturnType = (node) => !!node &&
@@ -1,7 +1,7 @@
1
1
  import { IMPORT_FLAGS, IMPORT_STAR, OPAQUE } from '../../constants.js';
2
2
  import { addValue } from '../../util/module-graph.js';
3
3
  import { isInNodeModules } from '../../util/path.js';
4
- import { getStringValue, isStringLiteral } from './helpers.js';
4
+ import { getStringValue, isStringLiteral } from '../ast-nodes.js';
5
5
  export function handleVariableDeclarator(node, s) {
6
6
  const init = node.init;
7
7
  if (!init)
@@ -1,6 +1,6 @@
1
1
  import { OPAQUE } from '../../constants.js';
2
2
  import { addValue } from '../../util/module-graph.js';
3
- import { getStringValue, isStringLiteral } from './helpers.js';
3
+ import { getStringValue, isStringLiteral } from '../ast-nodes.js';
4
4
  import { isShadowed } from './walk.js';
5
5
  export function handleMemberExpression(node, s) {
6
6
  if (node.object.type === 'MemberExpression' && node.object.object.type === 'MemberExpression') {
@@ -4,7 +4,7 @@ import type { GetImportsAndExportsOptions } from '../../types/config.ts';
4
4
  import type { Fix } from '../../types/exports.ts';
5
5
  import type { IssueSymbol, SymbolType } from '../../types/issues.ts';
6
6
  import type { Export, ExportMember, ImportMap, ImportMaps } from '../../types/module-graph.ts';
7
- import { type ResolveModule } from './helpers.ts';
7
+ import { type ResolveModule } from '../ast-nodes.ts';
8
8
  interface WalkContext {
9
9
  lineStarts: number[];
10
10
  skipExports: boolean;
@@ -2,7 +2,7 @@ import { Visitor, visitorKeys, } from 'oxc-parser';
2
2
  import { FIX_FLAGS, IMPORT_FLAGS, OPAQUE, SYMBOL_TYPE } from '../../constants.js';
3
3
  import { addValue } from '../../util/module-graph.js';
4
4
  import { isInNodeModules } from '../../util/path.js';
5
- import { getLineAndCol, getStringValue, isStringLiteral } from './helpers.js';
5
+ import { getLineAndCol, getStringValue, isStringLiteral } from '../ast-nodes.js';
6
6
  import { EMPTY_TAGS } from './jsdoc.js';
7
7
  import { handleCallExpression, handleNewExpression } from './calls.js';
8
8
  import { handleExportAssignment, handleExportDefault, handleExportNamed, handleExpressionStatement, } from './exports.js';
@@ -1,3 +1,4 @@
1
+ import type { SourceMap } from '../types/config.ts';
1
2
  import type { CompilerOptions } from '../types/project.ts';
2
3
  interface TSConfigInfo {
3
4
  isFile: boolean;
@@ -5,6 +6,7 @@ interface TSConfigInfo {
5
6
  fileNames: string[];
6
7
  include: string[] | undefined;
7
8
  exclude: string[] | undefined;
9
+ sourceMapPairs: SourceMap[];
8
10
  }
9
11
  export declare const loadTSConfig: (tsConfigFilePath: string) => Promise<TSConfigInfo>;
10
12
  export {};
@@ -52,12 +52,11 @@ const resolveReference = (refPath, dir) => {
52
52
  const withTsconfig = join(abs, 'tsconfig.json');
53
53
  return isFile(withTsconfig) ? withTsconfig : undefined;
54
54
  };
55
- const fillFromReferences = (target, references, dir, visited) => {
55
+ const absDir = (path, dir) => toAbsolute(path, dir).replace(/\/+$/, '');
56
+ const walkReferences = (target, references, dir, visited, pairs) => {
56
57
  if (!references?.length)
57
58
  return;
58
59
  for (const ref of references) {
59
- if (target.outDir && target.rootDir)
60
- return;
61
60
  const refPath = resolveReference(ref.path, dir);
62
61
  if (!refPath || visited.has(refPath))
63
62
  continue;
@@ -65,12 +64,16 @@ const fillFromReferences = (target, references, dir, visited) => {
65
64
  const refConfig = parseTsconfig(refPath);
66
65
  const refDir = dirname(refPath);
67
66
  const refOpts = refConfig.compilerOptions;
68
- if (refOpts?.outDir && !target.outDir)
69
- target.outDir = toAbsolute(refOpts.outDir, refDir).replace(/\/+$/, '');
70
- if (refOpts?.rootDir && !target.rootDir)
71
- target.rootDir = toAbsolute(refOpts.rootDir, refDir).replace(/\/+$/, '');
72
- if (!refOpts?.outDir || !refOpts?.rootDir)
73
- fillFromReferences(target, refConfig.references, refDir, visited);
67
+ const refOutDir = refOpts?.outDir ? absDir(refOpts.outDir, refDir) : undefined;
68
+ const refRootDir = refOpts?.rootDir ? absDir(refOpts.rootDir, refDir) : undefined;
69
+ if (refOutDir && refRootDir && refOutDir !== refRootDir)
70
+ pairs.push({ srcDir: refRootDir, outDir: refOutDir });
71
+ if (refOutDir && !target.outDir)
72
+ target.outDir = refOutDir;
73
+ if (refRootDir && !target.rootDir)
74
+ target.rootDir = refRootDir;
75
+ if (!refOutDir || !refRootDir)
76
+ walkReferences(target, refConfig.references, refDir, visited, pairs);
74
77
  }
75
78
  };
76
79
  const EMPTY = {
@@ -78,6 +81,7 @@ const EMPTY = {
78
81
  fileNames: [],
79
82
  include: undefined,
80
83
  exclude: undefined,
84
+ sourceMapPairs: [],
81
85
  };
82
86
  export const loadTSConfig = async (tsConfigFilePath) => {
83
87
  if (!isFile(tsConfigFilePath))
@@ -87,23 +91,24 @@ export const loadTSConfig = async (tsConfigFilePath) => {
87
91
  const dir = dirname(tsConfigFilePath);
88
92
  const compilerOptions = (config.compilerOptions ?? {});
89
93
  if (compilerOptions.outDir)
90
- compilerOptions.outDir = toAbsolute(compilerOptions.outDir, dir).replace(/\/+$/, '');
94
+ compilerOptions.outDir = absDir(compilerOptions.outDir, dir);
91
95
  if (compilerOptions.rootDir)
92
- compilerOptions.rootDir = toAbsolute(compilerOptions.rootDir, dir).replace(/\/+$/, '');
96
+ compilerOptions.rootDir = absDir(compilerOptions.rootDir, dir);
93
97
  if (compilerOptions.paths) {
94
98
  compilerOptions.pathsBasePath ??= dir;
95
99
  }
96
100
  if (compilerOptions.rootDirs) {
97
101
  compilerOptions.rootDirs = compilerOptions.rootDirs.map((d) => (isAbsolute(d) ? d : join(dir, d)));
98
102
  }
99
- if ((!compilerOptions.outDir || !compilerOptions.rootDir) && config.references?.length) {
100
- fillFromReferences(compilerOptions, config.references, dir, new Set([tsConfigFilePath]));
103
+ const sourceMapPairs = [];
104
+ if (config.references?.length) {
105
+ walkReferences(compilerOptions, config.references, dir, new Set([tsConfigFilePath]), sourceMapPairs);
101
106
  }
102
107
  const include = resolvePatterns(config.include, dir, true);
103
108
  const exclude = resolvePatterns(config.exclude, dir, true);
104
109
  const files = resolvePatterns(config.files, dir);
105
110
  const fileNames = expandFileNames(dir, compilerOptions, include, exclude, files);
106
- return { isFile: true, compilerOptions, fileNames, include, exclude };
111
+ return { isFile: true, compilerOptions, fileNames, include, exclude, sourceMapPairs };
107
112
  }
108
113
  catch {
109
114
  return { isFile: true, ...EMPTY };
@@ -2,6 +2,11 @@ import type { SourceMap } from '../types/config.ts';
2
2
  import type { CompilerOptions } from '../types/project.ts';
3
3
  import type { ConfigurationChief, Workspace } from '../ConfigurationChief.ts';
4
4
  export declare const augmentWorkspace: (workspace: Workspace, dir: string, compilerOptions: CompilerOptions | undefined, pluginSourceMaps?: SourceMap[]) => void;
5
+ export type WorkspaceManifestHandler = (filePath: string) => {
6
+ dir: string;
7
+ imports: unknown;
8
+ } | undefined;
9
+ export declare const getWorkspaceManifestHandler: (chief: ConfigurationChief) => WorkspaceManifestHandler;
5
10
  export declare const getModuleSourcePathHandler: (chief: ConfigurationChief) => (filePath: string) => string | undefined;
6
11
  export declare const getToSourcePathsHandler: (chief: ConfigurationChief) => (specifiers: Set<string>, dir: string, extensions: (string | undefined) | undefined, label: string) => Promise<string[]>;
7
12
  export declare const toSourceMappedSpecifiers: (ws: Workspace | undefined, absSpecifier: string, extensions?: string) => string[];
@@ -17,17 +17,41 @@ export const augmentWorkspace = (workspace, dir, compilerOptions, pluginSourceMa
17
17
  const all = compilerOptions ? [...pluginSourceMaps, tsconfigSourceMap(dir, compilerOptions)] : pluginSourceMaps;
18
18
  if (all.length === 0)
19
19
  return;
20
- workspace.sourceMaps = all.sort((a, b) => b.outDir.length - a.outDir.length);
20
+ const seen = new Set();
21
+ const unique = [];
22
+ for (const sm of all) {
23
+ const key = `${sm.srcDir}\0${sm.outDir}`;
24
+ if (seen.has(key))
25
+ continue;
26
+ seen.add(key);
27
+ unique.push(sm);
28
+ }
29
+ workspace.sourceMaps = unique.sort((a, b) => b.outDir.length - a.outDir.length);
21
30
  };
22
31
  const isUnderOutDir = (absPath, outDir) => absPath === outDir || absPath.startsWith(`${outDir}/`);
23
- const isUnderSrcDir = (absPath, srcDir) => absPath === srcDir || absPath.startsWith(`${srcDir}/`);
32
+ const rewriteOne = (pair, absSpecifier, extensions) => {
33
+ if (pair.srcDir === pair.outDir || !isUnderOutDir(absSpecifier, pair.outDir))
34
+ return;
35
+ return pair.srcDir + absSpecifier.slice(pair.outDir.length).replace(matchExt, extensions);
36
+ };
24
37
  const rewritePattern = (sourceMaps, absSpecifier, extensions) => {
25
- for (const { srcDir, outDir } of sourceMaps) {
26
- if (!isUnderSrcDir(absSpecifier, srcDir) && isUnderOutDir(absSpecifier, outDir)) {
27
- return srcDir + absSpecifier.slice(outDir.length).replace(matchExt, extensions);
28
- }
38
+ for (const sm of sourceMaps) {
39
+ const r = rewriteOne(sm, absSpecifier, extensions);
40
+ if (r)
41
+ return r;
29
42
  }
30
43
  };
44
+ export const getWorkspaceManifestHandler = (chief) => {
45
+ return (filePath) => {
46
+ const workspace = chief.findWorkspaceByFilePath(filePath);
47
+ if (!workspace)
48
+ return;
49
+ const manifest = chief.workspacePackages.get(workspace.name)?.manifest;
50
+ if (!manifest?.imports)
51
+ return;
52
+ return { dir: workspace.dir, imports: manifest.imports };
53
+ };
54
+ };
31
55
  export const getModuleSourcePathHandler = (chief) => {
32
56
  const toSourceMapCache = new Map();
33
57
  return (filePath) => {
@@ -36,21 +60,22 @@ export const getModuleSourcePathHandler = (chief) => {
36
60
  if (toSourceMapCache.has(filePath))
37
61
  return toSourceMapCache.get(filePath);
38
62
  const workspace = chief.findWorkspaceByFilePath(filePath);
39
- if (!workspace?.sourceMaps)
40
- return;
41
- for (const { srcDir, outDir } of workspace.sourceMaps) {
42
- if (!(isUnderOutDir(filePath, outDir) || srcDir === outDir))
43
- continue;
44
- const basePath = (srcDir + filePath.slice(outDir.length)).replace(matchExt, '');
45
- const srcFilePath = findFileWithExtensions(basePath, sourceExtensions);
46
- if (srcFilePath) {
47
- toSourceMapCache.set(filePath, srcFilePath);
48
- if (srcFilePath !== filePath) {
63
+ let result;
64
+ if (workspace?.sourceMaps) {
65
+ for (const { srcDir, outDir } of workspace.sourceMaps) {
66
+ if (!(isUnderOutDir(filePath, outDir) || srcDir === outDir))
67
+ continue;
68
+ const basePath = (srcDir + filePath.slice(outDir.length)).replace(matchExt, '');
69
+ const srcFilePath = findFileWithExtensions(basePath, sourceExtensions);
70
+ if (srcFilePath && srcFilePath !== filePath) {
49
71
  debugLog('*', `Source mapping ${toRelative(filePath, chief.cwd)} → ${toRelative(srcFilePath, chief.cwd)}`);
50
- return srcFilePath;
72
+ result = srcFilePath;
73
+ break;
51
74
  }
52
75
  }
53
76
  }
77
+ toSourceMapCache.set(filePath, result);
78
+ return result;
54
79
  };
55
80
  };
56
81
  export const getToSourcePathsHandler = (chief) => {
@@ -69,11 +94,11 @@ export const getToSourcePathsHandler = (chief) => {
69
94
  };
70
95
  export const toSourceMappedSpecifiers = (ws, absSpecifier, extensions = defaultExtensions) => {
71
96
  const out = [];
72
- if (!ws?.sourceMaps)
73
- return out;
74
- for (const { srcDir, outDir } of ws.sourceMaps) {
75
- if (!isUnderSrcDir(absSpecifier, srcDir) && isUnderOutDir(absSpecifier, outDir)) {
76
- out.push(srcDir + absSpecifier.slice(outDir.length).replace(matchExt, extensions));
97
+ if (ws?.sourceMaps) {
98
+ for (const sm of ws.sourceMaps) {
99
+ const r = rewriteOne(sm, absSpecifier, extensions);
100
+ if (r)
101
+ out.push(r);
77
102
  }
78
103
  }
79
104
  return out;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.12.2";
1
+ export declare const version = "6.13.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.12.2';
1
+ export const version = '6.13.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.12.2",
3
+ "version": "6.13.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
@@ -82,14 +82,14 @@
82
82
  "get-tsconfig": "4.14.0",
83
83
  "jiti": "^2.7.0",
84
84
  "minimist": "^1.2.8",
85
- "oxc-parser": "^0.128.0",
85
+ "oxc-parser": "^0.130.0",
86
86
  "oxc-resolver": "^11.19.1",
87
87
  "picomatch": "^4.0.4",
88
88
  "smol-toml": "^1.6.1",
89
89
  "strip-json-comments": "5.0.3",
90
90
  "tinyglobby": "^0.2.16",
91
91
  "unbash": "^3.0.0",
92
- "yaml": "^2.8.2",
92
+ "yaml": "^2.9.0",
93
93
  "zod": "^4.1.11"
94
94
  },
95
95
  "devDependencies": {
@@ -98,7 +98,7 @@
98
98
  "@types/minimist": "^1.2.5",
99
99
  "@types/picomatch": "^4.0.1",
100
100
  "@types/webpack": "^5.28.5",
101
- "@typescript/native-preview": "7.0.0-dev.20260415.1",
101
+ "@typescript/native-preview": "7.0.0-dev.20260512.1",
102
102
  "@wdio/types": "^9.20.0",
103
103
  "codeclimate-types": "^0.3.1",
104
104
  "prettier": "^3.8.1",