@emeryld/rrroutes-export 1.0.8 → 1.0.10
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/README.md +20 -0
- package/dist/exportFinalizedLeaves.changelog.cli.d.ts +2 -0
- package/dist/exportFinalizedLeaves.changelog.d.ts +34 -1
- package/dist/index.cjs +320 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +320 -84
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1394,9 +1394,11 @@ async function runExportFinalizedLeavesCli(argv) {
|
|
|
1394
1394
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
1395
1395
|
var import_node_os = __toESM(require("os"), 1);
|
|
1396
1396
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
1397
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
1397
1398
|
var import_node_child_process2 = require("child_process");
|
|
1398
1399
|
var import_node_util = require("util");
|
|
1399
1400
|
var import_node_url2 = require("url");
|
|
1401
|
+
var import_typescript2 = __toESM(require("typescript"), 1);
|
|
1400
1402
|
var execFile = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
1401
1403
|
var CHANGESET_CFG_FIELDS = [
|
|
1402
1404
|
"summary",
|
|
@@ -1409,6 +1411,7 @@ var CHANGESET_CFG_FIELDS = [
|
|
|
1409
1411
|
"feed"
|
|
1410
1412
|
];
|
|
1411
1413
|
var SCHEMA_SECTIONS = ["params", "query", "body", "output"];
|
|
1414
|
+
var MODULE_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs"];
|
|
1412
1415
|
var SOURCE_KEY_BY_SECTION = {
|
|
1413
1416
|
params: "paramsSchema",
|
|
1414
1417
|
query: "querySchema",
|
|
@@ -1523,6 +1526,65 @@ async function resolveCommitPath(cwd, fromCommit, toCommit) {
|
|
|
1523
1526
|
const commits = pathRaw.split("\n").map((item) => item.trim()).filter(Boolean);
|
|
1524
1527
|
return [fromCommit, ...commits];
|
|
1525
1528
|
}
|
|
1529
|
+
function modulePathStem(modulePath) {
|
|
1530
|
+
const normalized = normalizePath(modulePath).replace(/^\/+/, "");
|
|
1531
|
+
for (const ext of MODULE_EXTENSIONS) {
|
|
1532
|
+
if (normalized.endsWith(ext)) {
|
|
1533
|
+
return normalized.slice(0, -ext.length);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
return normalized;
|
|
1537
|
+
}
|
|
1538
|
+
function extensionVariants(pathLike) {
|
|
1539
|
+
const stem = modulePathStem(pathLike);
|
|
1540
|
+
return MODULE_EXTENSIONS.map((ext) => `${stem}${ext}`);
|
|
1541
|
+
}
|
|
1542
|
+
async function buildModulePathCandidates(repoRoot, toCommit, requestedModuleRel) {
|
|
1543
|
+
const requested = normalizePath(requestedModuleRel).replace(/^\/+/, "");
|
|
1544
|
+
const out = [];
|
|
1545
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1546
|
+
const pushCandidate = (value) => {
|
|
1547
|
+
const normalized = normalizePath(value).replace(/^\/+/, "");
|
|
1548
|
+
if (!normalized) return;
|
|
1549
|
+
if (seen.has(normalized)) return;
|
|
1550
|
+
seen.add(normalized);
|
|
1551
|
+
out.push(normalized);
|
|
1552
|
+
};
|
|
1553
|
+
pushCandidate(requested);
|
|
1554
|
+
extensionVariants(requested).forEach(pushCandidate);
|
|
1555
|
+
const history = await runGit(repoRoot, [
|
|
1556
|
+
"log",
|
|
1557
|
+
"--follow",
|
|
1558
|
+
"--name-only",
|
|
1559
|
+
"--format=",
|
|
1560
|
+
toCommit,
|
|
1561
|
+
"--",
|
|
1562
|
+
requested
|
|
1563
|
+
]);
|
|
1564
|
+
history.split("\n").map((item) => item.trim()).filter(Boolean).forEach((candidate) => {
|
|
1565
|
+
pushCandidate(candidate);
|
|
1566
|
+
extensionVariants(candidate).forEach(pushCandidate);
|
|
1567
|
+
});
|
|
1568
|
+
return out;
|
|
1569
|
+
}
|
|
1570
|
+
async function commitHasPath(repoRoot, commitSha, candidatePath) {
|
|
1571
|
+
try {
|
|
1572
|
+
await execFile("git", ["cat-file", "-e", `${commitSha}:${candidatePath}`], {
|
|
1573
|
+
cwd: repoRoot
|
|
1574
|
+
});
|
|
1575
|
+
return true;
|
|
1576
|
+
} catch {
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
async function resolveModulePathForCommit(repoRoot, commitSha, candidates) {
|
|
1581
|
+
for (const candidate of candidates) {
|
|
1582
|
+
if (await commitHasPath(repoRoot, commitSha, candidate)) {
|
|
1583
|
+
return candidate;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
return void 0;
|
|
1587
|
+
}
|
|
1526
1588
|
function parentDirectories(relativePath) {
|
|
1527
1589
|
const clean = normalizePath(relativePath).replace(/^\/+/, "");
|
|
1528
1590
|
const dir = import_node_path4.default.posix.dirname(clean);
|
|
@@ -1534,8 +1596,11 @@ function parentDirectories(relativePath) {
|
|
|
1534
1596
|
}
|
|
1535
1597
|
return out;
|
|
1536
1598
|
}
|
|
1537
|
-
function buildRelevantConfigFiles(
|
|
1538
|
-
const dirs = new Set(
|
|
1599
|
+
function buildRelevantConfigFiles(moduleCandidates, tsconfigRel) {
|
|
1600
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
1601
|
+
for (const moduleRel of moduleCandidates) {
|
|
1602
|
+
parentDirectories(moduleRel).forEach((item) => dirs.add(item));
|
|
1603
|
+
}
|
|
1539
1604
|
if (tsconfigRel) {
|
|
1540
1605
|
parentDirectories(tsconfigRel).forEach((item) => dirs.add(item));
|
|
1541
1606
|
dirs.add(import_node_path4.default.posix.dirname(normalizePath(tsconfigRel)));
|
|
@@ -1548,7 +1613,7 @@ function buildRelevantConfigFiles(moduleRel, tsconfigRel) {
|
|
|
1548
1613
|
}
|
|
1549
1614
|
return files;
|
|
1550
1615
|
}
|
|
1551
|
-
async function commitTouchedRelevantPaths(cwd, commit,
|
|
1616
|
+
async function commitTouchedRelevantPaths(cwd, commit, moduleCandidates, tsconfigRel) {
|
|
1552
1617
|
const changed = await runGit(cwd, [
|
|
1553
1618
|
"show",
|
|
1554
1619
|
"--pretty=format:",
|
|
@@ -1557,27 +1622,35 @@ async function commitTouchedRelevantPaths(cwd, commit, moduleRel, tsconfigRel) {
|
|
|
1557
1622
|
commit
|
|
1558
1623
|
]);
|
|
1559
1624
|
const changedFiles = changed.split("\n").map((item) => normalizePath(item.trim()).replace(/^\/+/, "")).filter(Boolean);
|
|
1560
|
-
const
|
|
1561
|
-
|
|
1625
|
+
const moduleFiles = Array.from(
|
|
1626
|
+
new Set(moduleCandidates.map((item) => normalizePath(item).replace(/^\/+/, "")))
|
|
1627
|
+
);
|
|
1628
|
+
const moduleDirs = Array.from(
|
|
1629
|
+
new Set(
|
|
1630
|
+
moduleFiles.map((item) => normalizePath(import_node_path4.default.posix.dirname(item)).replace(/^\/+/, "")).filter((item) => item && item !== ".")
|
|
1631
|
+
)
|
|
1632
|
+
);
|
|
1562
1633
|
const tsconfigFile = tsconfigRel ? normalizePath(tsconfigRel).replace(/^\/+/, "") : void 0;
|
|
1563
|
-
const configFiles = buildRelevantConfigFiles(
|
|
1634
|
+
const configFiles = buildRelevantConfigFiles(moduleFiles, tsconfigFile);
|
|
1564
1635
|
return changedFiles.some((file) => {
|
|
1565
|
-
if (file
|
|
1566
|
-
|
|
1567
|
-
|
|
1636
|
+
if (moduleFiles.includes(file)) return true;
|
|
1637
|
+
for (const moduleDir of moduleDirs) {
|
|
1638
|
+
if (file === moduleDir || file.startsWith(`${moduleDir}/`)) {
|
|
1639
|
+
return true;
|
|
1640
|
+
}
|
|
1568
1641
|
}
|
|
1569
1642
|
if (tsconfigFile && file === tsconfigFile) return true;
|
|
1570
1643
|
return configFiles.has(file);
|
|
1571
1644
|
});
|
|
1572
1645
|
}
|
|
1573
|
-
async function filterCommits(cwd, commits,
|
|
1646
|
+
async function filterCommits(cwd, commits, moduleCandidates, tsconfigRel) {
|
|
1574
1647
|
if (commits.length <= 1) {
|
|
1575
1648
|
return commits;
|
|
1576
1649
|
}
|
|
1577
1650
|
const keep = [commits[0]];
|
|
1578
1651
|
for (let i = 1; i < commits.length; i += 1) {
|
|
1579
1652
|
const commit = commits[i];
|
|
1580
|
-
if (await commitTouchedRelevantPaths(cwd, commit,
|
|
1653
|
+
if (await commitTouchedRelevantPaths(cwd, commit, moduleCandidates, tsconfigRel)) {
|
|
1581
1654
|
keep.push(commit);
|
|
1582
1655
|
}
|
|
1583
1656
|
}
|
|
@@ -1879,96 +1952,232 @@ async function pathExists(filePath) {
|
|
|
1879
1952
|
return false;
|
|
1880
1953
|
}
|
|
1881
1954
|
}
|
|
1882
|
-
|
|
1883
|
-
const
|
|
1884
|
-
|
|
1885
|
-
|
|
1955
|
+
function isTypeScriptModule(modulePath) {
|
|
1956
|
+
const ext = import_node_path4.default.extname(modulePath).toLowerCase();
|
|
1957
|
+
return ext === ".ts" || ext === ".tsx" || ext === ".mts" || ext === ".cts";
|
|
1958
|
+
}
|
|
1959
|
+
function isJavaScriptModule(modulePath) {
|
|
1960
|
+
const ext = import_node_path4.default.extname(modulePath).toLowerCase();
|
|
1961
|
+
return ext === ".js" || ext === ".mjs" || ext === ".cjs";
|
|
1962
|
+
}
|
|
1963
|
+
async function resolveSnapshotTsconfig(worktreeDir, modulePath, tsconfigOverride) {
|
|
1964
|
+
if (tsconfigOverride) {
|
|
1965
|
+
const resolved = import_node_path4.default.resolve(worktreeDir, tsconfigOverride);
|
|
1966
|
+
if (!await pathExists(resolved)) {
|
|
1967
|
+
throw new Error(`tsconfig not found: ${resolved}`);
|
|
1968
|
+
}
|
|
1969
|
+
return resolved;
|
|
1970
|
+
}
|
|
1971
|
+
let current = import_node_path4.default.dirname(modulePath);
|
|
1972
|
+
const normalizedRoot = normalizePath(import_node_path4.default.resolve(worktreeDir));
|
|
1973
|
+
while (true) {
|
|
1974
|
+
const candidate = import_node_path4.default.join(current, "tsconfig.json");
|
|
1975
|
+
if (await pathExists(candidate)) {
|
|
1976
|
+
return candidate;
|
|
1977
|
+
}
|
|
1978
|
+
const parent = import_node_path4.default.dirname(current);
|
|
1979
|
+
if (parent === current) break;
|
|
1980
|
+
if (!normalizePath(parent).startsWith(normalizedRoot)) break;
|
|
1981
|
+
current = parent;
|
|
1982
|
+
}
|
|
1983
|
+
throw new Error(
|
|
1984
|
+
`Unable to resolve tsconfig for TypeScript module: ${modulePath}. Pass --tsconfig to override.`
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
function toEmittedModulePath(moduleRel) {
|
|
1988
|
+
const normalized = normalizePath(moduleRel);
|
|
1989
|
+
if (normalized.endsWith(".mts")) return normalized.slice(0, -4) + ".mjs";
|
|
1990
|
+
if (normalized.endsWith(".cts")) return normalized.slice(0, -4) + ".cjs";
|
|
1991
|
+
if (normalized.endsWith(".tsx")) return normalized.slice(0, -4) + ".js";
|
|
1992
|
+
if (normalized.endsWith(".ts")) return normalized.slice(0, -3) + ".js";
|
|
1993
|
+
return normalized;
|
|
1994
|
+
}
|
|
1995
|
+
function buildCompileCacheKey(commitSha, moduleRel, tsconfigPath, tsconfigStat) {
|
|
1996
|
+
return import_node_crypto.default.createHash("sha1").update(commitSha).update("\n").update(normalizePath(moduleRel)).update("\n").update(normalizePath(tsconfigPath)).update("\n").update(String(tsconfigStat.mtimeMs)).update("\n").update(String(tsconfigStat.size)).digest("hex");
|
|
1997
|
+
}
|
|
1998
|
+
async function collectFilesRecursive(rootDir) {
|
|
1999
|
+
const files = [];
|
|
1886
2000
|
const walk = async (dir) => {
|
|
1887
2001
|
const entries = await import_promises2.default.readdir(dir, { withFileTypes: true });
|
|
1888
2002
|
for (const entry of entries) {
|
|
2003
|
+
const target = import_node_path4.default.join(dir, entry.name);
|
|
1889
2004
|
if (entry.isDirectory()) {
|
|
1890
|
-
|
|
1891
|
-
await walk(import_node_path4.default.join(dir, entry.name));
|
|
2005
|
+
await walk(target);
|
|
1892
2006
|
continue;
|
|
1893
2007
|
}
|
|
1894
|
-
if (
|
|
1895
|
-
|
|
1896
|
-
filesToScan.push(import_node_path4.default.join(dir, entry.name));
|
|
1897
|
-
}
|
|
1898
|
-
};
|
|
1899
|
-
await walk(worktreeDir);
|
|
1900
|
-
const importRegexes = [
|
|
1901
|
-
/\\bfrom\\s+['\"](\\.[^'\"]+\\.js)['\"]/g,
|
|
1902
|
-
/\\bimport\\(\\s*['\"](\\.[^'\"]+\\.js)['\"]\\s*\\)/g,
|
|
1903
|
-
/\\brequire\\(\\s*['\"](\\.[^'\"]+\\.js)['\"]\\s*\\)/g
|
|
1904
|
-
];
|
|
1905
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1906
|
-
for (const filePath of filesToScan) {
|
|
1907
|
-
const content = await import_promises2.default.readFile(filePath, "utf8");
|
|
1908
|
-
for (const regex of importRegexes) {
|
|
1909
|
-
regex.lastIndex = 0;
|
|
1910
|
-
let match = regex.exec(content);
|
|
1911
|
-
while (match) {
|
|
1912
|
-
const specifier = match[1];
|
|
1913
|
-
const resolvedJs = import_node_path4.default.resolve(import_node_path4.default.dirname(filePath), specifier);
|
|
1914
|
-
if (seen.has(resolvedJs)) {
|
|
1915
|
-
match = regex.exec(content);
|
|
1916
|
-
continue;
|
|
1917
|
-
}
|
|
1918
|
-
seen.add(resolvedJs);
|
|
1919
|
-
if (await pathExists(resolvedJs)) {
|
|
1920
|
-
match = regex.exec(content);
|
|
1921
|
-
continue;
|
|
1922
|
-
}
|
|
1923
|
-
const tsCandidates = [
|
|
1924
|
-
resolvedJs.replace(/\\.js$/, ".ts"),
|
|
1925
|
-
resolvedJs.replace(/\\.js$/, ".mts"),
|
|
1926
|
-
resolvedJs.replace(/\\.js$/, ".tsx")
|
|
1927
|
-
];
|
|
1928
|
-
let targetTs;
|
|
1929
|
-
for (const candidate of tsCandidates) {
|
|
1930
|
-
if (await pathExists(candidate)) {
|
|
1931
|
-
targetTs = candidate;
|
|
1932
|
-
break;
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
if (targetTs) {
|
|
1936
|
-
const relImport = normalizePath(import_node_path4.default.relative(import_node_path4.default.dirname(resolvedJs), targetTs));
|
|
1937
|
-
const importPath = relImport.startsWith(".") ? relImport : `./${relImport}`;
|
|
1938
|
-
const shim = `export * from '${importPath}'
|
|
1939
|
-
import * as __all from '${importPath}'
|
|
1940
|
-
export default ('default' in __all ? __all.default : __all)
|
|
1941
|
-
`;
|
|
1942
|
-
await import_promises2.default.mkdir(import_node_path4.default.dirname(resolvedJs), { recursive: true });
|
|
1943
|
-
await import_promises2.default.writeFile(resolvedJs, shim, "utf8");
|
|
1944
|
-
shimWrites.push(resolvedJs);
|
|
1945
|
-
}
|
|
1946
|
-
match = regex.exec(content);
|
|
2008
|
+
if (entry.isFile()) {
|
|
2009
|
+
files.push(target);
|
|
1947
2010
|
}
|
|
1948
2011
|
}
|
|
2012
|
+
};
|
|
2013
|
+
if (await pathExists(rootDir)) {
|
|
2014
|
+
await walk(rootDir);
|
|
2015
|
+
}
|
|
2016
|
+
return files;
|
|
2017
|
+
}
|
|
2018
|
+
function suffixMatchScore(candidate, wanted) {
|
|
2019
|
+
const left = normalizePath(candidate).split("/");
|
|
2020
|
+
const right = normalizePath(wanted).split("/");
|
|
2021
|
+
let score = 0;
|
|
2022
|
+
while (score < left.length && score < right.length) {
|
|
2023
|
+
const a = left[left.length - 1 - score];
|
|
2024
|
+
const b = right[right.length - 1 - score];
|
|
2025
|
+
if (a !== b) break;
|
|
2026
|
+
score += 1;
|
|
2027
|
+
}
|
|
2028
|
+
return score;
|
|
2029
|
+
}
|
|
2030
|
+
async function resolveEmittedEntryPath(emitRoot, moduleRel) {
|
|
2031
|
+
const expected = import_node_path4.default.resolve(emitRoot, toEmittedModulePath(moduleRel));
|
|
2032
|
+
if (await pathExists(expected)) {
|
|
2033
|
+
return expected;
|
|
2034
|
+
}
|
|
2035
|
+
const wantedRel = toEmittedModulePath(moduleRel);
|
|
2036
|
+
const wantedBase = import_node_path4.default.posix.basename(normalizePath(wantedRel));
|
|
2037
|
+
const files = await collectFilesRecursive(emitRoot);
|
|
2038
|
+
const candidates = files.filter(
|
|
2039
|
+
(file) => import_node_path4.default.posix.basename(normalizePath(file)) === wantedBase
|
|
2040
|
+
);
|
|
2041
|
+
if (candidates.length === 0) {
|
|
2042
|
+
return void 0;
|
|
1949
2043
|
}
|
|
1950
|
-
|
|
2044
|
+
candidates.sort(
|
|
2045
|
+
(a, b) => suffixMatchScore(b, wantedRel) - suffixMatchScore(a, wantedRel)
|
|
2046
|
+
);
|
|
2047
|
+
return candidates[0];
|
|
1951
2048
|
}
|
|
1952
|
-
async function
|
|
2049
|
+
async function compileSnapshotEntry(options) {
|
|
2050
|
+
const log = options.log ?? (() => void 0);
|
|
2051
|
+
const tsconfigStat = await import_promises2.default.stat(options.tsconfigPath);
|
|
2052
|
+
const cacheKey = buildCompileCacheKey(
|
|
2053
|
+
options.commitSha,
|
|
2054
|
+
options.moduleRel,
|
|
2055
|
+
options.tsconfigPath,
|
|
2056
|
+
{ mtimeMs: tsconfigStat.mtimeMs, size: tsconfigStat.size }
|
|
2057
|
+
);
|
|
2058
|
+
const emitRoot = import_node_path4.default.join(options.cacheRoot, cacheKey, "dist");
|
|
2059
|
+
let emittedEntry = import_node_path4.default.resolve(emitRoot, toEmittedModulePath(options.moduleRel));
|
|
2060
|
+
if (!options.noCache && await pathExists(emittedEntry)) {
|
|
2061
|
+
log(`[changelog] compile cache hit: ${options.commitSha.slice(0, 12)}`);
|
|
2062
|
+
return emittedEntry;
|
|
2063
|
+
}
|
|
2064
|
+
log(
|
|
2065
|
+
`[changelog] compile cache ${options.noCache ? "disabled" : "miss"}: ${options.commitSha.slice(0, 12)}`
|
|
2066
|
+
);
|
|
2067
|
+
await import_promises2.default.rm(import_node_path4.default.join(options.cacheRoot, cacheKey), { recursive: true, force: true }).catch(
|
|
2068
|
+
() => void 0
|
|
2069
|
+
);
|
|
2070
|
+
await import_promises2.default.mkdir(emitRoot, { recursive: true });
|
|
2071
|
+
const readResult = import_typescript2.default.readConfigFile(options.tsconfigPath, import_typescript2.default.sys.readFile);
|
|
2072
|
+
if (readResult.error) {
|
|
2073
|
+
throw new Error(import_typescript2.default.flattenDiagnosticMessageText(readResult.error.messageText, "\n"));
|
|
2074
|
+
}
|
|
2075
|
+
const parsed = import_typescript2.default.parseJsonConfigFileContent(
|
|
2076
|
+
readResult.config,
|
|
2077
|
+
import_typescript2.default.sys,
|
|
2078
|
+
import_node_path4.default.dirname(options.tsconfigPath)
|
|
2079
|
+
);
|
|
2080
|
+
const compilerOptions = {
|
|
2081
|
+
...parsed.options,
|
|
2082
|
+
noEmit: false,
|
|
2083
|
+
declaration: false,
|
|
2084
|
+
declarationMap: false,
|
|
2085
|
+
sourceMap: false,
|
|
2086
|
+
inlineSourceMap: false,
|
|
2087
|
+
composite: false,
|
|
2088
|
+
incremental: false,
|
|
2089
|
+
tsBuildInfoFile: void 0,
|
|
2090
|
+
outDir: emitRoot
|
|
2091
|
+
};
|
|
2092
|
+
const program = import_typescript2.default.createProgram([options.modulePath], compilerOptions);
|
|
2093
|
+
const emitResult = program.emit();
|
|
2094
|
+
const diagnostics = import_typescript2.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).filter((diagnostic) => diagnostic.category === import_typescript2.default.DiagnosticCategory.Error);
|
|
2095
|
+
if (diagnostics.length > 0) {
|
|
2096
|
+
const host = {
|
|
2097
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
2098
|
+
getCurrentDirectory: () => options.worktreeDir,
|
|
2099
|
+
getNewLine: () => "\n"
|
|
2100
|
+
};
|
|
2101
|
+
const message = import_typescript2.default.formatDiagnosticsWithColorAndContext(diagnostics.slice(0, 20), host);
|
|
2102
|
+
throw new Error(
|
|
2103
|
+
`TypeScript snapshot compile failed for ${options.moduleRel} at ${options.commitSha.slice(0, 12)}:
|
|
2104
|
+
${message}`
|
|
2105
|
+
);
|
|
2106
|
+
}
|
|
2107
|
+
emittedEntry = await resolveEmittedEntryPath(emitRoot, options.moduleRel) ?? emittedEntry;
|
|
2108
|
+
if (!await pathExists(emittedEntry)) {
|
|
2109
|
+
throw new Error(
|
|
2110
|
+
`Compiled snapshot entry was not emitted: ${emittedEntry}. Check module/tsconfig compatibility.`
|
|
2111
|
+
);
|
|
2112
|
+
}
|
|
2113
|
+
log(`[changelog] compiled snapshot entry: ${emittedEntry}`);
|
|
2114
|
+
return emittedEntry;
|
|
2115
|
+
}
|
|
2116
|
+
async function loadSnapshotExport(options) {
|
|
2117
|
+
return loadChangelogInput(options.entryPath, options.exportName);
|
|
2118
|
+
}
|
|
2119
|
+
async function createSnapshot(repoRoot, moduleCandidates, exportName, commit, tempRoot, tsconfigRel, exportOptions, log) {
|
|
1953
2120
|
const worktreeDir = import_node_path4.default.join(tempRoot, `wt-${commit.sha.slice(0, 12)}`);
|
|
1954
2121
|
await runGit(repoRoot, ["worktree", "add", "--detach", worktreeDir, commit.sha]);
|
|
1955
2122
|
try {
|
|
1956
2123
|
await ensureWorktreeDependencies(repoRoot, worktreeDir);
|
|
1957
|
-
const
|
|
1958
|
-
|
|
2124
|
+
const resolvedModuleRel = await resolveModulePathForCommit(
|
|
2125
|
+
repoRoot,
|
|
2126
|
+
commit.sha,
|
|
2127
|
+
moduleCandidates
|
|
2128
|
+
);
|
|
2129
|
+
if (!resolvedModuleRel) {
|
|
1959
2130
|
log?.(
|
|
1960
|
-
`[changelog]
|
|
2131
|
+
`[changelog] unresolved module for commit ${commit.sha.slice(0, 12)}; using empty snapshot`
|
|
1961
2132
|
);
|
|
2133
|
+
return {
|
|
2134
|
+
commit,
|
|
2135
|
+
routesByKey: {},
|
|
2136
|
+
sourceObjectsById: {},
|
|
2137
|
+
unresolvedModule: true
|
|
2138
|
+
};
|
|
1962
2139
|
}
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
2140
|
+
log?.(
|
|
2141
|
+
`[changelog] resolved module for commit ${commit.sha.slice(0, 12)}: ${resolvedModuleRel}`
|
|
2142
|
+
);
|
|
2143
|
+
const modulePath = import_node_path4.default.resolve(worktreeDir, resolvedModuleRel);
|
|
2144
|
+
let snapshotRuntimePath = modulePath;
|
|
2145
|
+
let resolvedTsconfigPath;
|
|
2146
|
+
if (isTypeScriptModule(modulePath)) {
|
|
2147
|
+
resolvedTsconfigPath = await resolveSnapshotTsconfig(
|
|
2148
|
+
worktreeDir,
|
|
2149
|
+
modulePath,
|
|
2150
|
+
tsconfigRel
|
|
2151
|
+
);
|
|
2152
|
+
log?.(`[changelog] using tsconfig: ${resolvedTsconfigPath}`);
|
|
2153
|
+
const compileCacheRoot = import_node_path4.default.resolve(
|
|
2154
|
+
exportOptions?.cacheDir ?? import_node_path4.default.join(import_node_os.default.tmpdir(), "rrroutes-export-changelog-cache")
|
|
2155
|
+
);
|
|
2156
|
+
snapshotRuntimePath = await compileSnapshotEntry({
|
|
2157
|
+
worktreeDir,
|
|
2158
|
+
moduleRel: resolvedModuleRel,
|
|
2159
|
+
modulePath,
|
|
2160
|
+
tsconfigPath: resolvedTsconfigPath,
|
|
2161
|
+
commitSha: commit.sha,
|
|
2162
|
+
cacheRoot: compileCacheRoot,
|
|
2163
|
+
noCache: exportOptions?.noCache,
|
|
2164
|
+
log
|
|
2165
|
+
});
|
|
2166
|
+
} else if (!isJavaScriptModule(modulePath)) {
|
|
2167
|
+
throw new Error(
|
|
2168
|
+
`Unsupported module extension for changelog snapshots: ${modulePath}`
|
|
2169
|
+
);
|
|
2170
|
+
}
|
|
2171
|
+
const input = await loadSnapshotExport({
|
|
2172
|
+
entryPath: snapshotRuntimePath,
|
|
2173
|
+
exportName
|
|
2174
|
+
});
|
|
1966
2175
|
const payload = await exportFinalizedLeaves(input, {
|
|
1967
2176
|
includeSource: true,
|
|
1968
2177
|
sourceModulePath: modulePath,
|
|
1969
2178
|
sourceExportName: exportName,
|
|
1970
|
-
tsconfigPath,
|
|
1971
|
-
|
|
2179
|
+
tsconfigPath: resolvedTsconfigPath ?? (tsconfigRel ? import_node_path4.default.resolve(worktreeDir, tsconfigRel) : void 0),
|
|
2180
|
+
handlers: exportOptions?.handlers
|
|
1972
2181
|
});
|
|
1973
2182
|
const routesByKey = toRouteSnapshots(payload);
|
|
1974
2183
|
const sourceObjectsById = toSourceObjectSnapshots(routesByKey);
|
|
@@ -2203,12 +2412,18 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2203
2412
|
log("[changelog] resolving commit window");
|
|
2204
2413
|
const window = await resolveCommitWindow(repoRoot, options.from, options.to);
|
|
2205
2414
|
log(`[changelog] window: ${window.from.slice(0, 12)}..${window.to.slice(0, 12)}`);
|
|
2415
|
+
const moduleCandidates = await buildModulePathCandidates(
|
|
2416
|
+
repoRoot,
|
|
2417
|
+
window.to,
|
|
2418
|
+
modulePathRelative
|
|
2419
|
+
);
|
|
2420
|
+
log(`[changelog] module candidates discovered: ${moduleCandidates.length}`);
|
|
2206
2421
|
const allCommits = await resolveCommitPath(repoRoot, window.from, window.to);
|
|
2207
2422
|
log(`[changelog] commits in ancestry path: ${allCommits.length}`);
|
|
2208
2423
|
const selectedCommitShas = await filterCommits(
|
|
2209
2424
|
repoRoot,
|
|
2210
2425
|
allCommits,
|
|
2211
|
-
|
|
2426
|
+
moduleCandidates,
|
|
2212
2427
|
tsconfigRelative
|
|
2213
2428
|
);
|
|
2214
2429
|
log(`[changelog] commits after path filter: ${selectedCommitShas.length}`);
|
|
@@ -2225,6 +2440,7 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2225
2440
|
log(`[changelog] temp workspace: ${tempRoot}`);
|
|
2226
2441
|
try {
|
|
2227
2442
|
const snapshots = [];
|
|
2443
|
+
const unresolvedModuleCommits = [];
|
|
2228
2444
|
for (let index = 0; index < commits.length; index += 1) {
|
|
2229
2445
|
const commit = commits[index];
|
|
2230
2446
|
log(
|
|
@@ -2233,7 +2449,7 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2233
2449
|
snapshots.push(
|
|
2234
2450
|
await createSnapshot(
|
|
2235
2451
|
repoRoot,
|
|
2236
|
-
|
|
2452
|
+
moduleCandidates,
|
|
2237
2453
|
exportName,
|
|
2238
2454
|
commit,
|
|
2239
2455
|
tempRoot,
|
|
@@ -2242,6 +2458,9 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2242
2458
|
log
|
|
2243
2459
|
)
|
|
2244
2460
|
);
|
|
2461
|
+
if (snapshots[snapshots.length - 1]?.unresolvedModule) {
|
|
2462
|
+
unresolvedModuleCommits.push(commit.sha);
|
|
2463
|
+
}
|
|
2245
2464
|
}
|
|
2246
2465
|
const routeEvents = [];
|
|
2247
2466
|
const sourceEvents = [];
|
|
@@ -2266,7 +2485,8 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2266
2485
|
exportName,
|
|
2267
2486
|
from: window.from,
|
|
2268
2487
|
to: window.to,
|
|
2269
|
-
selectedCommitCount: commits.length
|
|
2488
|
+
selectedCommitCount: commits.length,
|
|
2489
|
+
unresolvedModuleCommits: unresolvedModuleCommits.length > 0 ? unresolvedModuleCommits : void 0
|
|
2270
2490
|
},
|
|
2271
2491
|
commits,
|
|
2272
2492
|
byRoute: routeRecordByKey(routeEvents),
|
|
@@ -2293,6 +2513,13 @@ var __private = {
|
|
|
2293
2513
|
resolveCommitWindow,
|
|
2294
2514
|
resolveCommitPath,
|
|
2295
2515
|
filterCommits,
|
|
2516
|
+
buildModulePathCandidates,
|
|
2517
|
+
resolveModulePathForCommit,
|
|
2518
|
+
resolveSnapshotTsconfig,
|
|
2519
|
+
toEmittedModulePath,
|
|
2520
|
+
buildCompileCacheKey,
|
|
2521
|
+
compileSnapshotEntry,
|
|
2522
|
+
loadSnapshotExport,
|
|
2296
2523
|
toRouteSnapshots,
|
|
2297
2524
|
toSourceObjectSnapshots,
|
|
2298
2525
|
diffSnapshots,
|
|
@@ -2303,6 +2530,7 @@ var __private = {
|
|
|
2303
2530
|
var import_node_path5 = __toESM(require("path"), 1);
|
|
2304
2531
|
function parseFinalizedLeavesChangelogCliArgs(argv) {
|
|
2305
2532
|
const args = /* @__PURE__ */ new Map();
|
|
2533
|
+
let noCache = false;
|
|
2306
2534
|
for (let i = 0; i < argv.length; i += 1) {
|
|
2307
2535
|
const key = argv[i];
|
|
2308
2536
|
if (key === "--") continue;
|
|
@@ -2310,6 +2538,10 @@ function parseFinalizedLeavesChangelogCliArgs(argv) {
|
|
|
2310
2538
|
if (key === "--with-source") {
|
|
2311
2539
|
continue;
|
|
2312
2540
|
}
|
|
2541
|
+
if (key === "--no-cache") {
|
|
2542
|
+
noCache = true;
|
|
2543
|
+
continue;
|
|
2544
|
+
}
|
|
2313
2545
|
const value = argv[i + 1];
|
|
2314
2546
|
if (!value || value.startsWith("--")) {
|
|
2315
2547
|
throw new Error(`Missing value for ${key}`);
|
|
@@ -2328,7 +2560,9 @@ function parseFinalizedLeavesChangelogCliArgs(argv) {
|
|
|
2328
2560
|
htmlFile: args.get("--html") ?? void 0,
|
|
2329
2561
|
tsconfigPath: args.get("--tsconfig") ?? void 0,
|
|
2330
2562
|
from: args.get("--from") ?? void 0,
|
|
2331
|
-
to: args.get("--to") ?? void 0
|
|
2563
|
+
to: args.get("--to") ?? void 0,
|
|
2564
|
+
cacheDir: args.get("--cache-dir") ?? void 0,
|
|
2565
|
+
noCache
|
|
2332
2566
|
};
|
|
2333
2567
|
}
|
|
2334
2568
|
async function runExportFinalizedLeavesChangelogCli(argv) {
|
|
@@ -2346,6 +2580,8 @@ async function runExportFinalizedLeavesChangelogCli(argv) {
|
|
|
2346
2580
|
from: args.from,
|
|
2347
2581
|
to: args.to,
|
|
2348
2582
|
includeSource: true,
|
|
2583
|
+
cacheDir: args.cacheDir,
|
|
2584
|
+
noCache: args.noCache,
|
|
2349
2585
|
log
|
|
2350
2586
|
};
|
|
2351
2587
|
log("[changelog-cli] starting changelog export");
|