tdepend 0.2.0 → 0.3.1

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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +212 -116
  3. package/dist/api/analyze.d.ts +8 -68
  4. package/dist/api/analyze.js +33 -108
  5. package/dist/api/analyze.js.map +1 -1
  6. package/dist/api/explain.d.ts +22 -0
  7. package/dist/api/explain.js +38 -0
  8. package/dist/api/explain.js.map +1 -0
  9. package/dist/api/export.d.ts +4 -47
  10. package/dist/api/export.js +6 -45
  11. package/dist/api/export.js.map +1 -1
  12. package/dist/api/serialization.d.ts +6 -26
  13. package/dist/api/serialization.js +68 -58
  14. package/dist/api/serialization.js.map +1 -1
  15. package/dist/cli/index.js +11 -129
  16. package/dist/cli/index.js.map +1 -1
  17. package/dist/cli/run.d.ts +12 -0
  18. package/dist/cli/run.js +112 -0
  19. package/dist/cli/run.js.map +1 -0
  20. package/dist/config/loadConfig.d.ts +10 -10
  21. package/dist/config/loadConfig.js +73 -36
  22. package/dist/config/loadConfig.js.map +1 -1
  23. package/dist/config/schema.d.ts +59 -29
  24. package/dist/config/schema.js +45 -51
  25. package/dist/config/schema.js.map +1 -1
  26. package/dist/errors.d.ts +9 -0
  27. package/dist/errors.js +21 -0
  28. package/dist/errors.js.map +1 -0
  29. package/dist/files/collectFiles.d.ts +21 -0
  30. package/dist/files/collectFiles.js +189 -0
  31. package/dist/files/collectFiles.js.map +1 -0
  32. package/dist/fs.d.ts +16 -0
  33. package/dist/fs.js +50 -0
  34. package/dist/fs.js.map +1 -0
  35. package/dist/graph/buildFileGraph.d.ts +33 -0
  36. package/dist/graph/buildFileGraph.js +163 -0
  37. package/dist/graph/buildFileGraph.js.map +1 -0
  38. package/dist/graph/fileGraph.d.ts +20 -0
  39. package/dist/graph/fileGraph.js +75 -0
  40. package/dist/graph/fileGraph.js.map +1 -0
  41. package/dist/index.d.ts +10 -21
  42. package/dist/index.js +6 -29
  43. package/dist/index.js.map +1 -1
  44. package/dist/output/analyzeText.d.ts +7 -0
  45. package/dist/output/analyzeText.js +91 -0
  46. package/dist/output/analyzeText.js.map +1 -0
  47. package/dist/parser/extractSites.d.ts +3 -0
  48. package/dist/parser/extractSites.js +704 -0
  49. package/dist/parser/extractSites.js.map +1 -0
  50. package/dist/parser/loadsTarget.d.ts +10 -0
  51. package/dist/parser/loadsTarget.js +304 -0
  52. package/dist/parser/loadsTarget.js.map +1 -0
  53. package/dist/parser/types.d.ts +30 -0
  54. package/dist/{types/graph.js → parser/types.js} +1 -1
  55. package/dist/parser/types.js.map +1 -0
  56. package/dist/project/discoverProject.d.ts +2 -0
  57. package/dist/project/discoverProject.js +477 -0
  58. package/dist/project/discoverProject.js.map +1 -0
  59. package/dist/project/gitignore.d.ts +13 -0
  60. package/dist/project/gitignore.js +138 -0
  61. package/dist/project/gitignore.js.map +1 -0
  62. package/dist/project/types.d.ts +44 -0
  63. package/dist/{types/parser.js → project/types.js} +1 -1
  64. package/dist/project/types.js.map +1 -0
  65. package/dist/resolver/createResolver.d.ts +4 -0
  66. package/dist/resolver/createResolver.js +276 -0
  67. package/dist/resolver/createResolver.js.map +1 -0
  68. package/dist/resolver/types.d.ts +28 -0
  69. package/dist/resolver/types.js +3 -0
  70. package/dist/resolver/types.js.map +1 -0
  71. package/dist/resolver/workspaceHost.d.ts +12 -0
  72. package/dist/resolver/workspaceHost.js +253 -0
  73. package/dist/resolver/workspaceHost.js.map +1 -0
  74. package/dist/types/api.d.ts +71 -64
  75. package/package.json +24 -25
  76. package/dist/analysis/reporter.d.ts +0 -22
  77. package/dist/analysis/reporter.js +0 -116
  78. package/dist/analysis/reporter.js.map +0 -1
  79. package/dist/graph/cycleDetector.d.ts +0 -2
  80. package/dist/graph/cycleDetector.js +0 -56
  81. package/dist/graph/cycleDetector.js.map +0 -1
  82. package/dist/graph/dependencyGraph.d.ts +0 -10
  83. package/dist/graph/dependencyGraph.js +0 -41
  84. package/dist/graph/dependencyGraph.js.map +0 -1
  85. package/dist/metrics/abstractness.d.ts +0 -2
  86. package/dist/metrics/abstractness.js +0 -10
  87. package/dist/metrics/abstractness.js.map +0 -1
  88. package/dist/metrics/distance.d.ts +0 -1
  89. package/dist/metrics/distance.js +0 -7
  90. package/dist/metrics/distance.js.map +0 -1
  91. package/dist/metrics/index.d.ts +0 -4
  92. package/dist/metrics/index.js +0 -30
  93. package/dist/metrics/index.js.map +0 -1
  94. package/dist/metrics/instability.d.ts +0 -1
  95. package/dist/metrics/instability.js +0 -8
  96. package/dist/metrics/instability.js.map +0 -1
  97. package/dist/parser/fileScanner.d.ts +0 -8
  98. package/dist/parser/fileScanner.js +0 -22
  99. package/dist/parser/fileScanner.js.map +0 -1
  100. package/dist/parser/tsParser.d.ts +0 -18
  101. package/dist/parser/tsParser.js +0 -158
  102. package/dist/parser/tsParser.js.map +0 -1
  103. package/dist/types/graph.d.ts +0 -14
  104. package/dist/types/graph.js.map +0 -1
  105. package/dist/types/parser.d.ts +0 -26
  106. package/dist/types/parser.js.map +0 -1
  107. package/dist/utils/deepMerge.d.ts +0 -1
  108. package/dist/utils/deepMerge.js +0 -23
  109. package/dist/utils/deepMerge.js.map +0 -1
  110. package/dist/utils/log.d.ts +0 -2
  111. package/dist/utils/log.js +0 -9
  112. package/dist/utils/log.js.map +0 -1
  113. package/dist/utils/pathUtils.d.ts +0 -12
  114. package/dist/utils/pathUtils.js +0 -27
  115. package/dist/utils/pathUtils.js.map +0 -1
@@ -0,0 +1,44 @@
1
+ import type * as ts from 'typescript';
2
+ import type { FileSystemLike } from '../fs';
3
+ export interface TsconfigEntry {
4
+ configPath: string;
5
+ options: ts.CompilerOptions;
6
+ fileNames: Set<string>;
7
+ outDir?: string;
8
+ declarationDir?: string;
9
+ rootDir: string;
10
+ }
11
+ export interface Project {
12
+ id: string;
13
+ dir: string;
14
+ dependencies: Set<string>;
15
+ packageJson: object | null;
16
+ }
17
+ export interface WorkspacePackage {
18
+ id: string;
19
+ name: string;
20
+ dir: string;
21
+ packageJson: object;
22
+ }
23
+ export interface ProjectContext {
24
+ rootDir: string;
25
+ gitTopLevel: string | null;
26
+ projects: Project[];
27
+ packages: WorkspacePackage[];
28
+ tsconfigs: TsconfigEntry[];
29
+ projectFor(file: string): Project;
30
+ packageFor(file: string): WorkspacePackage | null;
31
+ optionsFor(file: string): {
32
+ options: ts.CompilerOptions;
33
+ entry: TsconfigEntry | null;
34
+ };
35
+ isIgnored(path: string): boolean;
36
+ unsupported: string[];
37
+ warnings: string[];
38
+ }
39
+ export interface DiscoverOptions {
40
+ fs?: FileSystemLike;
41
+ localExclude?: string[];
42
+ isExcluded?: (rel: string) => boolean;
43
+ isConfigExcluded?: (rel: string) => boolean;
44
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=parser.js.map
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/project/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { type FileSystemLike } from '../fs';
2
+ import type { ProjectContext } from '../project/types';
3
+ import type { ResolveOptions, Resolver } from './types';
4
+ export declare function createResolver(ctx: ProjectContext, analysisFiles: Set<string>, options: ResolveOptions, fs?: FileSystemLike): Resolver;
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.createResolver = createResolver;
40
+ const node_module_1 = require("node:module");
41
+ const node_path_1 = require("node:path");
42
+ const picomatch_1 = __importDefault(require("picomatch"));
43
+ const ts = __importStar(require("typescript"));
44
+ const fs_1 = require("../fs");
45
+ const workspaceHost_1 = require("./workspaceHost");
46
+ const ASSET_EXTENSIONS = new Set([
47
+ '.css',
48
+ '.scss',
49
+ '.sass',
50
+ '.less',
51
+ '.svg',
52
+ '.png',
53
+ '.jpg',
54
+ '.jpeg',
55
+ '.webp',
56
+ '.gif',
57
+ '.ico',
58
+ '.json',
59
+ '.woff',
60
+ '.woff2',
61
+ '.md',
62
+ '.mdx',
63
+ ]);
64
+ const IGNORE_TARGET_SUFFIXES = ['', '/index.ts', '/index.tsx', '.ts', '.tsx'];
65
+ const GITIGNORE_TARGET_SUFFIXES = [
66
+ '',
67
+ '.ts',
68
+ '.tsx',
69
+ '.mts',
70
+ '.cts',
71
+ '.js',
72
+ '.jsx',
73
+ '.mjs',
74
+ '.cjs',
75
+ '/index.ts',
76
+ '/index.tsx',
77
+ '/index.js',
78
+ ];
79
+ function createResolver(ctx, analysisFiles, options, fs = (0, fs_1.nodeFileSystem)()) {
80
+ const host = (0, workspaceHost_1.createWorkspaceHost)(ctx, fs);
81
+ const caches = new Map();
82
+ const workspaceNames = new Set(ctx.packages.map((pkg) => pkg.name));
83
+ const aliasEntries = Object.entries(options.aliases).sort((a, b) => b[0].length - a[0].length);
84
+ const ignoreMatcher = buildMatcher(options.ignoreUnresolved);
85
+ const virtualMatcher = buildMatcher(options.virtual);
86
+ function cacheFor(entry, compilerOptions, fromRel) {
87
+ const key = entry === null ? `fallback:${ctx.projectFor(fromRel).id}` : entry.configPath;
88
+ const existing = caches.get(key);
89
+ if (existing !== undefined)
90
+ return existing;
91
+ const getCanonicalFileName = ts.sys.useCaseSensitiveFileNames
92
+ ? (fileName) => fileName
93
+ : (fileName) => fileName.toLowerCase();
94
+ const created = ts.createModuleResolutionCache(ctx.rootDir, getCanonicalFileName, compilerOptions);
95
+ caches.set(key, created);
96
+ return created;
97
+ }
98
+ function requestedWorkspace(specifier) {
99
+ if (specifier.startsWith('.') || specifier.startsWith('/') || specifier.startsWith('#')) {
100
+ return undefined;
101
+ }
102
+ const name = (0, workspaceHost_1.packageNameOf)(specifier);
103
+ if (!workspaceNames.has(name))
104
+ return undefined;
105
+ const rest = specifier.slice(name.length);
106
+ return { package: name, subpath: rest === '' ? '.' : `.${rest}` };
107
+ }
108
+ function isVirtual(specifier) {
109
+ if (specifier.startsWith('virtual:') || specifier.startsWith('~icons/'))
110
+ return true;
111
+ return virtualMatcher?.(specifier) ?? false;
112
+ }
113
+ function applyAlias(specifier, fromRel) {
114
+ for (const [prefix, replacement] of aliasEntries) {
115
+ if (!specifier.startsWith(prefix))
116
+ continue;
117
+ const rest = specifier.slice(prefix.length);
118
+ const project = ctx.projectFor(fromRel);
119
+ const targetRel = (0, workspaceHost_1.posixJoin)(project.dir, replacement, rest);
120
+ return (0, workspaceHost_1.relativeTo)((0, node_path_1.join)(ctx.rootDir, fromRel), (0, node_path_1.join)(ctx.rootDir, targetRel));
121
+ }
122
+ return undefined;
123
+ }
124
+ function leafClass(fromRel, targetRel) {
125
+ if (!analysisFiles.has(targetRel))
126
+ return 'excluded';
127
+ const fromPackage = ctx.packageFor(fromRel)?.id ?? null;
128
+ const toPackage = ctx.packageFor(targetRel)?.id ?? null;
129
+ return fromPackage === toPackage ? 'internal' : 'workspace';
130
+ }
131
+ function classifyResolved(resolved, specifier, fromRel, requested) {
132
+ const redirected = (0, workspaceHost_1.redirectWorkspacePath)(resolved.resolvedFileName, ctx);
133
+ if (requested === undefined &&
134
+ (resolved.isExternalLibraryImport === true || (0, workspaceHost_1.isNodeModulesPath)((0, fs_1.toPosix)(redirected)))) {
135
+ return { class: 'external', target: { module: specifier } };
136
+ }
137
+ const resolvedRel = (0, workspaceHost_1.rootRelative)(fs, ctx.rootDir, redirected);
138
+ if (resolvedRel === null) {
139
+ return { class: 'unresolved', target: null, reason: 'outside-root', requested };
140
+ }
141
+ const candidates = (0, workspaceHost_1.outputSourceCandidates)(resolvedRel, ctx, fs);
142
+ let targetRel = resolvedRel;
143
+ let mapped;
144
+ if (candidates.length > 0) {
145
+ const existing = candidates.filter((candidate) => (0, fs_1.isFile)(fs, (0, node_path_1.join)(ctx.rootDir, candidate)));
146
+ if (existing.length === 0) {
147
+ return { class: 'unresolved', target: null, reason: 'missing-source-mapping', requested };
148
+ }
149
+ if (existing.length > 1) {
150
+ return { class: 'unresolved', target: null, reason: 'ambiguous-source-mapping', requested };
151
+ }
152
+ targetRel = existing[0];
153
+ mapped = { from: resolvedRel };
154
+ }
155
+ const realTarget = (0, workspaceHost_1.rootRelative)(fs, ctx.rootDir, (0, node_path_1.join)(ctx.rootDir, targetRel));
156
+ const finalTarget = realTarget ?? targetRel;
157
+ return {
158
+ class: leafClass(fromRel, finalTarget),
159
+ target: { file: finalTarget },
160
+ mapped,
161
+ requested,
162
+ };
163
+ }
164
+ function matchesIgnored(candidates) {
165
+ if (ignoreMatcher === null)
166
+ return false;
167
+ return candidates.some((candidate) => ignoreMatcher(candidate));
168
+ }
169
+ function hasNoResolvableEntry(packageName) {
170
+ const pkg = ctx.packages.find((candidate) => candidate.name === packageName);
171
+ if (pkg === undefined)
172
+ return false;
173
+ const manifest = pkg.packageJson;
174
+ return (manifest.exports === undefined &&
175
+ manifest.main === undefined &&
176
+ manifest.types === undefined &&
177
+ manifest.typings === undefined);
178
+ }
179
+ function classifyUnresolved(specifier, fromRel, requested, compilerOptions, aliasTried) {
180
+ const isRelative = specifier.startsWith('./') ||
181
+ specifier.startsWith('../') ||
182
+ specifier === '.' ||
183
+ specifier === '..' ||
184
+ specifier.startsWith('/');
185
+ if (isRelative) {
186
+ const targetRel = (0, workspaceHost_1.posixJoin)((0, workspaceHost_1.posixDirname)(fromRel), specifier);
187
+ if (matchesIgnored(IGNORE_TARGET_SUFFIXES.map((suffix) => `${targetRel}${suffix}`))) {
188
+ return { class: 'ignored', target: null, reason: 'ignore-unresolved' };
189
+ }
190
+ const targetAbs = (0, node_path_1.join)(ctx.rootDir, targetRel);
191
+ if (GITIGNORE_TARGET_SUFFIXES.some((suffix) => ctx.isIgnored(`${targetAbs}${suffix}`))) {
192
+ return { class: 'ignored', target: null, reason: 'gitignored' };
193
+ }
194
+ return { class: 'unresolved', target: null, requested };
195
+ }
196
+ if (specifier.startsWith('#'))
197
+ return { class: 'unresolved', target: null, requested };
198
+ if (matchesIgnored([specifier])) {
199
+ return { class: 'ignored', target: null, reason: 'ignore-unresolved' };
200
+ }
201
+ if (requested !== undefined) {
202
+ const reason = hasNoResolvableEntry(requested.package) ? 'no-resolvable-entry' : undefined;
203
+ return { class: 'unresolved', target: null, requested, reason };
204
+ }
205
+ if (aliasTried || matchesPathsKey(specifier, compilerOptions)) {
206
+ return { class: 'unresolved', target: null };
207
+ }
208
+ if (ctx.projectFor(fromRel).dependencies.has((0, workspaceHost_1.packageNameOf)(specifier))) {
209
+ return { class: 'external', target: { module: specifier }, reason: 'not-installed' };
210
+ }
211
+ return { class: 'unresolved', target: null };
212
+ }
213
+ return {
214
+ resolve(site, parsed) {
215
+ if (site.unsupported !== undefined) {
216
+ return { class: 'unsupported', target: null, reason: site.unsupported };
217
+ }
218
+ const specifier = site.specifier;
219
+ const fromRel = (0, fs_1.toPosix)(parsed.file);
220
+ const fromAbs = (0, node_path_1.join)(ctx.rootDir, fromRel);
221
+ if ((0, node_module_1.isBuiltin)(specifier)) {
222
+ return { class: 'builtin', target: { module: builtinIdentity(specifier) } };
223
+ }
224
+ const requested = requestedWorkspace(specifier);
225
+ if (isVirtual(specifier))
226
+ return { class: 'virtual', target: null, requested };
227
+ if (isAsset(specifier))
228
+ return { class: 'asset', target: null, requested };
229
+ const { options: compilerOptions, entry } = ctx.optionsFor(fromRel);
230
+ const mode = ts.getModeForUsageLocation(parsed.sourceFile, site.node, compilerOptions);
231
+ const cache = cacheFor(entry, compilerOptions, fromRel);
232
+ const direct = ts.resolveModuleName(specifier, fromAbs, compilerOptions, host, cache, undefined, mode);
233
+ if (direct.resolvedModule !== undefined) {
234
+ return classifyResolved(direct.resolvedModule, specifier, fromRel, requested);
235
+ }
236
+ const aliasSpecifier = applyAlias(specifier, fromRel);
237
+ if (aliasSpecifier !== undefined) {
238
+ const aliased = ts.resolveModuleName(aliasSpecifier, fromAbs, compilerOptions, host, cache, undefined, mode);
239
+ if (aliased.resolvedModule !== undefined) {
240
+ return classifyResolved(aliased.resolvedModule, specifier, fromRel, requested);
241
+ }
242
+ }
243
+ return classifyUnresolved(specifier, fromRel, requested, compilerOptions, aliasSpecifier !== undefined);
244
+ },
245
+ };
246
+ }
247
+ function isAsset(specifier) {
248
+ if (specifier.includes('?'))
249
+ return true;
250
+ const base = specifier.split('?')[0];
251
+ const dot = base.lastIndexOf('.');
252
+ if (dot < 0)
253
+ return false;
254
+ return ASSET_EXTENSIONS.has(base.slice(dot).toLowerCase());
255
+ }
256
+ function builtinIdentity(specifier) {
257
+ return specifier.startsWith('node:') ? specifier : `node:${specifier}`;
258
+ }
259
+ function buildMatcher(patterns) {
260
+ const cleaned = patterns.filter((pattern) => pattern !== '');
261
+ if (cleaned.length === 0)
262
+ return null;
263
+ return (0, picomatch_1.default)(cleaned, { dot: true });
264
+ }
265
+ function matchesPathsKey(specifier, options) {
266
+ const paths = options.paths;
267
+ if (paths === undefined)
268
+ return false;
269
+ return Object.keys(paths).some((key) => {
270
+ const star = key.indexOf('*');
271
+ if (star < 0)
272
+ return key === specifier;
273
+ return specifier.startsWith(key.slice(0, star)) && specifier.endsWith(key.slice(star + 1));
274
+ });
275
+ }
276
+ //# sourceMappingURL=createResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createResolver.js","sourceRoot":"","sources":["../../src/resolver/createResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,wCAkPC;AAjTD,6CAAwC;AACxC,yCAAiC;AAEjC,0DAAkC;AAClC,+CAAiC;AAEjC,8BAA6E;AAU7E,mDAUyB;AAEzB,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;IACR,KAAK;IACL,MAAM;CACP,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,CAAC,EAAE,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC9E,MAAM,yBAAyB,GAAG;IAChC,EAAE;IACF,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,WAAW;IACX,YAAY;IACZ,WAAW;CACZ,CAAC;AAEF,SAAgB,cAAc,CAC5B,GAAmB,EACnB,aAA0B,EAC1B,OAAuB,EACvB,KAAqB,IAAA,mBAAc,GAAE;IAErC,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CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,IAAI,GAAG,CAAC;YAAE,OAAO,GAAG,KAAK,SAAS,CAAC;QACvC,OAAO,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { ImportSite, ParsedFile } from '../parser/types';
2
+ export type ResolutionClass = 'builtin' | 'asset' | 'virtual' | 'internal' | 'workspace' | 'excluded' | 'external' | 'ignored' | 'unsupported' | 'unresolved';
3
+ export type Target = {
4
+ file: string;
5
+ } | {
6
+ module: string;
7
+ };
8
+ export interface WorkspaceRequest {
9
+ package: string;
10
+ subpath: string;
11
+ }
12
+ export interface Resolution {
13
+ class: ResolutionClass;
14
+ target: Target | null;
15
+ reason?: string;
16
+ mapped?: {
17
+ from: string;
18
+ };
19
+ requested?: WorkspaceRequest;
20
+ }
21
+ export interface ResolveOptions {
22
+ aliases: Record<string, string>;
23
+ virtual: string[];
24
+ ignoreUnresolved: string[];
25
+ }
26
+ export interface Resolver {
27
+ resolve(site: ImportSite, parsed: ParsedFile): Resolution;
28
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/resolver/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import * as ts from 'typescript';
2
+ import { type FileSystemLike } from '../fs';
3
+ import type { ProjectContext } from '../project/types';
4
+ export declare function posixDirname(path: string): string;
5
+ export declare function posixJoin(...parts: string[]): string;
6
+ export declare function packageNameOf(specifier: string): string;
7
+ export declare function isNodeModulesPath(path: string): boolean;
8
+ export declare function redirectWorkspacePath(path: string, ctx: ProjectContext): string;
9
+ export declare function outputSourceCandidates(path: string, ctx: ProjectContext, fs: FileSystemLike): string[];
10
+ export declare function createWorkspaceHost(ctx: ProjectContext, fs: FileSystemLike): ts.ModuleResolutionHost;
11
+ export declare function rootRelative(fs: FileSystemLike, rootDir: string, path: string): string | null;
12
+ export declare function relativeTo(fromPath: string, toPath: string): string;
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.posixDirname = posixDirname;
37
+ exports.posixJoin = posixJoin;
38
+ exports.packageNameOf = packageNameOf;
39
+ exports.isNodeModulesPath = isNodeModulesPath;
40
+ exports.redirectWorkspacePath = redirectWorkspacePath;
41
+ exports.outputSourceCandidates = outputSourceCandidates;
42
+ exports.createWorkspaceHost = createWorkspaceHost;
43
+ exports.rootRelative = rootRelative;
44
+ exports.relativeTo = relativeTo;
45
+ const node_path_1 = require("node:path");
46
+ const ts = __importStar(require("typescript"));
47
+ const fs_1 = require("../fs");
48
+ function posixDirname(path) {
49
+ return path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : '';
50
+ }
51
+ function posixJoin(...parts) {
52
+ const segments = [];
53
+ for (const part of parts) {
54
+ for (const segment of part.split('/')) {
55
+ if (segment === '' || segment === '.')
56
+ continue;
57
+ if (segment === '..') {
58
+ const last = segments[segments.length - 1];
59
+ if (segments.length > 0 && last !== '..')
60
+ segments.pop();
61
+ else
62
+ segments.push('..');
63
+ continue;
64
+ }
65
+ segments.push(segment);
66
+ }
67
+ }
68
+ return segments.join('/');
69
+ }
70
+ function isUnderDirectory(prefix, path) {
71
+ return path === prefix || path.startsWith(`${prefix}/`);
72
+ }
73
+ function rootRelativePosix(root, posixPath) {
74
+ if (root === '' || root === '/')
75
+ return posixPath.replace(/^\/+/, '');
76
+ if (posixPath === root)
77
+ return '';
78
+ return posixPath.startsWith(`${root}/`) ? posixPath.slice(root.length + 1) : posixPath;
79
+ }
80
+ const BUNDLER_OUTPUT_DIRS = ['dist', 'build', 'out'];
81
+ const LAYOUTS = new WeakMap();
82
+ function layoutOf(ctx) {
83
+ const cached = LAYOUTS.get(ctx);
84
+ if (cached !== undefined)
85
+ return cached;
86
+ const packages = ctx.packages.map((pkg) => ({
87
+ name: pkg.name,
88
+ dirNative: (0, node_path_1.join)(ctx.rootDir, pkg.dir),
89
+ }));
90
+ const outputs = [];
91
+ for (const entry of ctx.tsconfigs) {
92
+ if (entry.rootDir === '')
93
+ continue;
94
+ for (const out of [entry.outDir, entry.declarationDir]) {
95
+ if (out === undefined || out === '')
96
+ continue;
97
+ outputs.push({ out, sources: [entry.rootDir], inferred: false });
98
+ }
99
+ }
100
+ addBundlerOutputs(ctx, outputs);
101
+ const layout = { packages, outputs };
102
+ LAYOUTS.set(ctx, layout);
103
+ return layout;
104
+ }
105
+ // A bundler's output directory appears in no tsconfig. These names are safe to
106
+ // assume because the analysis never treats them as source.
107
+ function addBundlerOutputs(ctx, outputs) {
108
+ const declared = outputs.map((entry) => entry.out);
109
+ for (const pkg of ctx.packages) {
110
+ const configRoots = ctx.tsconfigs
111
+ .filter((entry) => posixDirname(entry.configPath) === pkg.dir)
112
+ .map((entry) => entry.rootDir)
113
+ .filter((root) => isUnderDirectory(pkg.dir, root));
114
+ const sources = [...new Set([...configRoots, posixJoin(pkg.dir, 'src'), pkg.dir])];
115
+ for (const name of BUNDLER_OUTPUT_DIRS) {
116
+ const out = posixJoin(pkg.dir, name);
117
+ if (declared.some((path) => isUnderDirectory(out, path)))
118
+ continue;
119
+ outputs.push({ out, sources, inferred: true });
120
+ }
121
+ }
122
+ }
123
+ function packageNameOf(specifier) {
124
+ const parts = specifier.split('/');
125
+ if (specifier.startsWith('@'))
126
+ return parts.slice(0, 2).join('/');
127
+ return parts[0] ?? '';
128
+ }
129
+ function isNodeModulesPath(path) {
130
+ return path.includes('/node_modules/');
131
+ }
132
+ function redirectWorkspacePath(path, ctx) {
133
+ const posix = (0, fs_1.toPosix)(path);
134
+ const marker = '/node_modules/';
135
+ const markerAt = posix.lastIndexOf(marker);
136
+ if (markerAt < 0)
137
+ return path;
138
+ const rest = posix.slice(markerAt + marker.length);
139
+ const name = packageNameOf(rest);
140
+ const pkg = layoutOf(ctx).packages.find((candidate) => candidate.name === name);
141
+ if (pkg === undefined)
142
+ return path;
143
+ const suffix = rest.slice(name.length);
144
+ return pkg.dirNative + (node_path_1.sep === '/' ? suffix : suffix.split('/').join(node_path_1.sep));
145
+ }
146
+ function isOutputPath(path, ctx) {
147
+ const rel = rootRelativePosix((0, fs_1.toPosix)(ctx.rootDir), (0, fs_1.toPosix)(path));
148
+ return layoutOf(ctx).outputs.some((entry) => isUnderDirectory(entry.out, rel));
149
+ }
150
+ // The first source prefix with a real file wins. An inferred directory is a
151
+ // guess, so it offers only real files: with none, the path is left as it is.
152
+ function outputSourceCandidates(path, ctx, fs) {
153
+ const rel = rootRelativePosix((0, fs_1.toPosix)(ctx.rootDir), (0, fs_1.toPosix)(path));
154
+ const candidates = [];
155
+ for (const entry of layoutOf(ctx).outputs) {
156
+ if (!isUnderDirectory(entry.out, rel))
157
+ continue;
158
+ const rest = rel.slice(entry.out.length + 1);
159
+ for (const source of entry.sources) {
160
+ const computed = swapToSourceExtensions(rest).map((name) => posixJoin(source, name));
161
+ const existing = computed.filter((candidate) => (0, fs_1.isFile)(fs, (0, node_path_1.join)(ctx.rootDir, candidate)));
162
+ for (const candidate of entry.inferred ? existing : computed) {
163
+ if (!candidates.includes(candidate))
164
+ candidates.push(candidate);
165
+ }
166
+ if (existing.length > 0)
167
+ break;
168
+ }
169
+ }
170
+ return candidates;
171
+ }
172
+ const SOURCE_SWAPS = [
173
+ { from: '.d.mts', to: ['.mts'] },
174
+ { from: '.d.cts', to: ['.cts'] },
175
+ { from: '.d.ts', to: ['.ts', '.tsx'] },
176
+ { from: '.mjs', to: ['.mts', '.mjs'] },
177
+ { from: '.cjs', to: ['.cts', '.cjs'] },
178
+ { from: '.js', to: ['.ts', '.tsx', '.js', '.jsx'] },
179
+ ];
180
+ function swapToSourceExtensions(rest) {
181
+ for (const swap of SOURCE_SWAPS) {
182
+ if (rest.endsWith(swap.from)) {
183
+ const head = rest.slice(0, rest.length - swap.from.length);
184
+ return swap.to.map((extension) => `${head}${extension}`);
185
+ }
186
+ }
187
+ return [];
188
+ }
189
+ function createWorkspaceHost(ctx, fs) {
190
+ const isVirtualNodeModulesDirectory = (path) => {
191
+ const posix = (0, fs_1.toPosix)(path);
192
+ return /(?:^|\/)node_modules$/.test(posix) || /\/node_modules\/@[^/]+$/.test(posix);
193
+ };
194
+ return {
195
+ fileExists: (path) => {
196
+ const real = redirectWorkspacePath(path, ctx);
197
+ if ((0, fs_1.isFile)(fs, real))
198
+ return true;
199
+ return outputSourceCandidates(real, ctx, fs).some((candidate) => (0, fs_1.isFile)(fs, (0, node_path_1.join)(ctx.rootDir, candidate)));
200
+ },
201
+ readFile: (path) => {
202
+ const real = redirectWorkspacePath(path, ctx);
203
+ return (0, fs_1.tryRead)(fs, real) ?? undefined;
204
+ },
205
+ directoryExists: (path) => {
206
+ const real = redirectWorkspacePath(path, ctx);
207
+ if ((0, fs_1.isDir)(fs, real))
208
+ return true;
209
+ return isVirtualNodeModulesDirectory(path) || isOutputPath(real, ctx);
210
+ },
211
+ getCurrentDirectory: () => ctx.rootDir,
212
+ getDirectories: (path) => {
213
+ const real = redirectWorkspacePath(path, ctx);
214
+ try {
215
+ return fs.readdir(real).filter((name) => (0, fs_1.isDir)(fs, (0, node_path_1.join)(real, name)));
216
+ }
217
+ catch {
218
+ return [];
219
+ }
220
+ },
221
+ realpath: (path) => {
222
+ const real = redirectWorkspacePath(path, ctx);
223
+ try {
224
+ return fs.realpath(real);
225
+ }
226
+ catch {
227
+ return real;
228
+ }
229
+ },
230
+ useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
231
+ };
232
+ }
233
+ function rootRelative(fs, rootDir, path) {
234
+ let real;
235
+ try {
236
+ real = fs.realpath(path);
237
+ }
238
+ catch {
239
+ real = path;
240
+ }
241
+ const root = (0, fs_1.toPosix)(rootDir);
242
+ const posix = (0, fs_1.toPosix)(real);
243
+ if (posix === root)
244
+ return '';
245
+ if (!posix.startsWith(`${root}/`))
246
+ return null;
247
+ return posix.slice(root.length + 1);
248
+ }
249
+ function relativeTo(fromPath, toPath) {
250
+ const rel = (0, fs_1.toPosix)((0, node_path_1.relative)((0, node_path_1.dirname)(fromPath), toPath));
251
+ return rel.startsWith('.') ? rel : `./${rel}`;
252
+ }
253
+ //# sourceMappingURL=workspaceHost.js.map