foresthouse 1.0.1-dev.2 → 1.0.1-dev.3

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.
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as printReactUsageTree, c as printPackageDependencyTree, f as analyzeReactUsage, g as analyzePackageDependencies, h as analyzePackageDependencyDiff, i as graphToSerializablePackageTree, m as isSourceCodeFile, n as graphToSerializableTree, o as printDependencyTree, p as analyzeDependencies, r as diffGraphToSerializablePackageTree, s as printPackageDependencyDiffTree, t as graphToSerializableReactTree } from "./react-DxWukhfX.mjs";
2
+ import { a as printReactUsageTree, c as printPackageDependencyTree, f as analyzeReactUsage, g as analyzePackageDependencies, h as analyzePackageDependencyDiff, i as graphToSerializablePackageTree, m as isSourceCodeFile, n as graphToSerializableTree, o as printDependencyTree, p as analyzeDependencies, r as diffGraphToSerializablePackageTree, s as printPackageDependencyDiffTree, t as graphToSerializableReactTree } from "./react-Bk6iOz9n.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import fs from "node:fs";
5
5
  import path from "node:path";
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as printReactUsageTree, c as printPackageDependencyTree, d as getReactUsageRoots, f as analyzeReactUsage, g as analyzePackageDependencies, h as analyzePackageDependencyDiff, i as graphToSerializablePackageTree, l as getFilteredUsages, n as graphToSerializableTree, o as printDependencyTree, p as analyzeDependencies, r as diffGraphToSerializablePackageTree, s as printPackageDependencyDiffTree, t as graphToSerializableReactTree, u as getReactUsageEntries } from "./react-DxWukhfX.mjs";
1
+ import { a as printReactUsageTree, c as printPackageDependencyTree, d as getReactUsageRoots, f as analyzeReactUsage, g as analyzePackageDependencies, h as analyzePackageDependencyDiff, i as graphToSerializablePackageTree, l as getFilteredUsages, n as graphToSerializableTree, o as printDependencyTree, p as analyzeDependencies, r as diffGraphToSerializablePackageTree, s as printPackageDependencyDiffTree, t as graphToSerializableReactTree, u as getReactUsageEntries } from "./react-Bk6iOz9n.mjs";
2
2
  export { analyzeDependencies, analyzePackageDependencies, analyzePackageDependencyDiff, analyzeReactUsage, diffGraphToSerializablePackageTree, getFilteredUsages, getReactUsageEntries, getReactUsageRoots, graphToSerializablePackageTree, graphToSerializableReactTree, graphToSerializableTree, printDependencyTree, printPackageDependencyDiffTree, printPackageDependencyTree, printReactUsageTree };
@@ -1075,6 +1075,8 @@ var DependencyGraphBuilder = class {
1075
1075
  programCache = /* @__PURE__ */ new Map();
1076
1076
  checkerCache = /* @__PURE__ */ new Map();
1077
1077
  resolverCache = /* @__PURE__ */ new Map();
1078
+ resolutionCache = /* @__PURE__ */ new Map();
1079
+ packageRootCache = /* @__PURE__ */ new Map();
1078
1080
  constructor(entryConfigs, options) {
1079
1081
  this.entryConfigs = entryConfigs;
1080
1082
  this.options = options;
@@ -1097,14 +1099,7 @@ var DependencyGraphBuilder = class {
1097
1099
  const config = this.getConfigForFile(normalizedPath);
1098
1100
  const program = this.getProgramForFile(normalizedPath, config);
1099
1101
  const checker = this.getCheckerForFile(normalizedPath, config);
1100
- const dependencies = collectModuleReferences(program.getSourceFile(normalizedPath) ?? createSourceFile(normalizedPath), checker).map((reference) => resolveDependency(reference, normalizedPath, {
1101
- cwd: this.options.cwd,
1102
- expandWorkspaces: this.options.expandWorkspaces,
1103
- projectOnly: this.options.projectOnly,
1104
- getConfigForFile: (targetPath) => this.getConfigForFile(targetPath),
1105
- getResolverForFile: (targetPath) => this.getResolverForFile(targetPath),
1106
- ...entryConfigPath === void 0 ? {} : { entryConfigPath }
1107
- }));
1102
+ const dependencies = collectModuleReferences(program.getSourceFile(normalizedPath) ?? createSourceFile(normalizedPath), checker).map((reference) => this.resolveDependencyWithCache(reference, normalizedPath, config, entryConfigPath));
1108
1103
  this.nodes.set(normalizedPath, {
1109
1104
  id: normalizedPath,
1110
1105
  dependencies
@@ -1172,7 +1167,78 @@ var DependencyGraphBuilder = class {
1172
1167
  this.resolverCache.set(cacheKey, resolver);
1173
1168
  return resolver;
1174
1169
  }
1170
+ resolveDependencyWithCache(reference, containingFile, config, entryConfigPath) {
1171
+ const cacheKey = this.getResolutionCacheKey(reference.specifier, containingFile, config, entryConfigPath);
1172
+ const cachedResolution = this.resolutionCache.get(cacheKey);
1173
+ if (cachedResolution !== void 0) return toDependencyEdge(reference, cachedResolution);
1174
+ const resolved = resolveDependency(reference, containingFile, {
1175
+ cwd: this.options.cwd,
1176
+ expandWorkspaces: this.options.expandWorkspaces,
1177
+ projectOnly: this.options.projectOnly,
1178
+ getConfigForFile: (targetPath) => this.getConfigForFile(targetPath),
1179
+ getResolverForFile: (targetPath) => this.getResolverForFile(targetPath),
1180
+ ...entryConfigPath === void 0 ? {} : { entryConfigPath }
1181
+ });
1182
+ this.resolutionCache.set(cacheKey, {
1183
+ kind: resolved.kind,
1184
+ target: resolved.target,
1185
+ ...resolved.boundary === void 0 ? {} : { boundary: resolved.boundary }
1186
+ });
1187
+ return resolved;
1188
+ }
1189
+ getResolutionCacheKey(specifier, containingFile, config, entryConfigPath) {
1190
+ const scopeKey = entryConfigPath ?? "";
1191
+ if (isPackageLikeImport(specifier)) {
1192
+ const packageRoot = this.getPackageRoot(containingFile) ?? path.dirname(containingFile);
1193
+ return `package:${this.getProgramCacheKey(containingFile, config)}:${packageRoot}:${specifier}:${scopeKey}`;
1194
+ }
1195
+ return `path:${path.dirname(containingFile)}:${specifier}:${scopeKey}`;
1196
+ }
1197
+ getPackageRoot(filePath) {
1198
+ const startDirectory = path.dirname(filePath);
1199
+ if (this.packageRootCache.has(startDirectory)) return this.packageRootCache.get(startDirectory);
1200
+ const traversedDirectories = [];
1201
+ let currentDirectory = startDirectory;
1202
+ while (true) {
1203
+ if (this.packageRootCache.has(currentDirectory)) {
1204
+ const cached = this.packageRootCache.get(currentDirectory);
1205
+ traversedDirectories.forEach((directory) => {
1206
+ this.packageRootCache.set(directory, cached);
1207
+ });
1208
+ return cached;
1209
+ }
1210
+ traversedDirectories.push(currentDirectory);
1211
+ if (fs.existsSync(path.join(currentDirectory, "package.json"))) {
1212
+ traversedDirectories.forEach((directory) => {
1213
+ this.packageRootCache.set(directory, currentDirectory);
1214
+ });
1215
+ return currentDirectory;
1216
+ }
1217
+ const parentDirectory = path.dirname(currentDirectory);
1218
+ if (parentDirectory === currentDirectory) {
1219
+ traversedDirectories.forEach((directory) => {
1220
+ this.packageRootCache.set(directory, void 0);
1221
+ });
1222
+ return;
1223
+ }
1224
+ currentDirectory = parentDirectory;
1225
+ }
1226
+ }
1175
1227
  };
1228
+ function isPackageLikeImport(specifier) {
1229
+ return !specifier.startsWith(".") && !path.isAbsolute(specifier);
1230
+ }
1231
+ function toDependencyEdge(reference, resolution) {
1232
+ return {
1233
+ specifier: reference.specifier,
1234
+ referenceKind: reference.referenceKind,
1235
+ isTypeOnly: reference.isTypeOnly,
1236
+ unused: reference.unused,
1237
+ kind: resolution.kind,
1238
+ target: resolution.target,
1239
+ ...resolution.boundary === void 0 ? {} : { boundary: resolution.boundary }
1240
+ };
1241
+ }
1176
1242
  //#endregion
1177
1243
  //#region src/analyzers/import/index.ts
1178
1244
  function analyzeDependencies(entryFile, options = {}) {
@@ -2540,4 +2606,4 @@ function formatReactNodeFilePath(filePath, kind, cwd) {
2540
2606
  //#endregion
2541
2607
  export { printReactUsageTree as a, printPackageDependencyTree as c, getReactUsageRoots as d, analyzeReactUsage as f, analyzePackageDependencies as g, analyzePackageDependencyDiff as h, graphToSerializablePackageTree as i, getFilteredUsages as l, isSourceCodeFile as m, graphToSerializableTree as n, printDependencyTree as o, analyzeDependencies as p, diffGraphToSerializablePackageTree as r, printPackageDependencyDiffTree as s, graphToSerializableReactTree as t, getReactUsageEntries as u };
2542
2608
 
2543
- //# sourceMappingURL=react-DxWukhfX.mjs.map
2609
+ //# sourceMappingURL=react-Bk6iOz9n.mjs.map