foresthouse 1.0.1-dev.1 → 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-
|
|
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-
|
|
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) =>
|
|
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 = {}) {
|
|
@@ -1499,6 +1565,7 @@ function unwrapExpression(expression) {
|
|
|
1499
1565
|
}
|
|
1500
1566
|
//#endregion
|
|
1501
1567
|
//#region src/analyzers/react/entries.ts
|
|
1568
|
+
const lineStartOffsetsCache = /* @__PURE__ */ new Map();
|
|
1502
1569
|
function collectEntryUsages(program, filePath, sourceText, includeBuiltins) {
|
|
1503
1570
|
const entries = /* @__PURE__ */ new Map();
|
|
1504
1571
|
program.body.forEach((statement) => {
|
|
@@ -1565,24 +1632,43 @@ function createReactUsageLocation(filePath, sourceText, offset) {
|
|
|
1565
1632
|
};
|
|
1566
1633
|
}
|
|
1567
1634
|
function offsetToLineAndColumn(sourceText, offset) {
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
line += 1;
|
|
1573
|
-
column = 1;
|
|
1574
|
-
continue;
|
|
1575
|
-
}
|
|
1576
|
-
column += 1;
|
|
1577
|
-
}
|
|
1635
|
+
const lineStartOffsets = getLineStartOffsets(sourceText);
|
|
1636
|
+
const boundedOffset = Math.max(0, Math.min(offset, sourceText.length));
|
|
1637
|
+
const lineIndex = findLineIndex(lineStartOffsets, boundedOffset);
|
|
1638
|
+
const lineStartOffset = lineStartOffsets[lineIndex] ?? 0;
|
|
1578
1639
|
return {
|
|
1579
|
-
line,
|
|
1580
|
-
column
|
|
1640
|
+
line: lineIndex + 1,
|
|
1641
|
+
column: boundedOffset - lineStartOffset + 1
|
|
1581
1642
|
};
|
|
1582
1643
|
}
|
|
1583
1644
|
function comparePendingReactUsageEntries(left, right) {
|
|
1584
1645
|
return left.location.filePath.localeCompare(right.location.filePath) || left.location.line - right.location.line || left.location.column - right.location.column || left.kind.localeCompare(right.kind) || left.referenceName.localeCompare(right.referenceName);
|
|
1585
1646
|
}
|
|
1647
|
+
function getLineStartOffsets(sourceText) {
|
|
1648
|
+
const cached = lineStartOffsetsCache.get(sourceText);
|
|
1649
|
+
if (cached !== void 0) return cached;
|
|
1650
|
+
const lineStartOffsets = [0];
|
|
1651
|
+
for (let index = 0; index < sourceText.length; index += 1) if (sourceText[index] === "\n") lineStartOffsets.push(index + 1);
|
|
1652
|
+
lineStartOffsetsCache.set(sourceText, lineStartOffsets);
|
|
1653
|
+
return lineStartOffsets;
|
|
1654
|
+
}
|
|
1655
|
+
function findLineIndex(lineStartOffsets, offset) {
|
|
1656
|
+
let lowerBound = 0;
|
|
1657
|
+
let upperBound = lineStartOffsets.length - 1;
|
|
1658
|
+
while (lowerBound <= upperBound) {
|
|
1659
|
+
const middleIndex = Math.floor((lowerBound + upperBound) / 2);
|
|
1660
|
+
const middleOffset = lineStartOffsets[middleIndex];
|
|
1661
|
+
const nextOffset = lineStartOffsets[middleIndex + 1];
|
|
1662
|
+
if (middleOffset === void 0) return 0;
|
|
1663
|
+
if (offset < middleOffset) {
|
|
1664
|
+
upperBound = middleIndex - 1;
|
|
1665
|
+
continue;
|
|
1666
|
+
}
|
|
1667
|
+
if (nextOffset === void 0 || offset < nextOffset) return middleIndex;
|
|
1668
|
+
lowerBound = middleIndex + 1;
|
|
1669
|
+
}
|
|
1670
|
+
return Math.max(0, lineStartOffsets.length - 1);
|
|
1671
|
+
}
|
|
1586
1672
|
//#endregion
|
|
1587
1673
|
//#region src/analyzers/react/symbols.ts
|
|
1588
1674
|
function collectTopLevelReactSymbols(statement, filePath, symbolsByName) {
|
|
@@ -2520,4 +2606,4 @@ function formatReactNodeFilePath(filePath, kind, cwd) {
|
|
|
2520
2606
|
//#endregion
|
|
2521
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 };
|
|
2522
2608
|
|
|
2523
|
-
//# sourceMappingURL=react-
|
|
2609
|
+
//# sourceMappingURL=react-Bk6iOz9n.mjs.map
|