@emeryld/rrroutes-export 1.0.9 → 1.0.11
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 +4 -0
- package/dist/exportFinalizedLeaves.changelog.d.ts +7 -1
- package/dist/index.cjs +121 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +121 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1357,6 +1357,7 @@ var CHANGESET_CFG_FIELDS = [
|
|
|
1357
1357
|
"feed"
|
|
1358
1358
|
];
|
|
1359
1359
|
var SCHEMA_SECTIONS = ["params", "query", "body", "output"];
|
|
1360
|
+
var MODULE_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs"];
|
|
1360
1361
|
var SOURCE_KEY_BY_SECTION = {
|
|
1361
1362
|
params: "paramsSchema",
|
|
1362
1363
|
query: "querySchema",
|
|
@@ -1471,6 +1472,65 @@ async function resolveCommitPath(cwd, fromCommit, toCommit) {
|
|
|
1471
1472
|
const commits = pathRaw.split("\n").map((item) => item.trim()).filter(Boolean);
|
|
1472
1473
|
return [fromCommit, ...commits];
|
|
1473
1474
|
}
|
|
1475
|
+
function modulePathStem(modulePath) {
|
|
1476
|
+
const normalized = normalizePath(modulePath).replace(/^\/+/, "");
|
|
1477
|
+
for (const ext of MODULE_EXTENSIONS) {
|
|
1478
|
+
if (normalized.endsWith(ext)) {
|
|
1479
|
+
return normalized.slice(0, -ext.length);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return normalized;
|
|
1483
|
+
}
|
|
1484
|
+
function extensionVariants(pathLike) {
|
|
1485
|
+
const stem = modulePathStem(pathLike);
|
|
1486
|
+
return MODULE_EXTENSIONS.map((ext) => `${stem}${ext}`);
|
|
1487
|
+
}
|
|
1488
|
+
async function buildModulePathCandidates(repoRoot, toCommit, requestedModuleRel) {
|
|
1489
|
+
const requested = normalizePath(requestedModuleRel).replace(/^\/+/, "");
|
|
1490
|
+
const out = [];
|
|
1491
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1492
|
+
const pushCandidate = (value) => {
|
|
1493
|
+
const normalized = normalizePath(value).replace(/^\/+/, "");
|
|
1494
|
+
if (!normalized) return;
|
|
1495
|
+
if (seen.has(normalized)) return;
|
|
1496
|
+
seen.add(normalized);
|
|
1497
|
+
out.push(normalized);
|
|
1498
|
+
};
|
|
1499
|
+
pushCandidate(requested);
|
|
1500
|
+
extensionVariants(requested).forEach(pushCandidate);
|
|
1501
|
+
const history = await runGit(repoRoot, [
|
|
1502
|
+
"log",
|
|
1503
|
+
"--follow",
|
|
1504
|
+
"--name-only",
|
|
1505
|
+
"--format=",
|
|
1506
|
+
toCommit,
|
|
1507
|
+
"--",
|
|
1508
|
+
requested
|
|
1509
|
+
]);
|
|
1510
|
+
history.split("\n").map((item) => item.trim()).filter(Boolean).forEach((candidate) => {
|
|
1511
|
+
pushCandidate(candidate);
|
|
1512
|
+
extensionVariants(candidate).forEach(pushCandidate);
|
|
1513
|
+
});
|
|
1514
|
+
return out;
|
|
1515
|
+
}
|
|
1516
|
+
async function commitHasPath(repoRoot, commitSha, candidatePath) {
|
|
1517
|
+
try {
|
|
1518
|
+
await execFile("git", ["cat-file", "-e", `${commitSha}:${candidatePath}`], {
|
|
1519
|
+
cwd: repoRoot
|
|
1520
|
+
});
|
|
1521
|
+
return true;
|
|
1522
|
+
} catch {
|
|
1523
|
+
return false;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
async function resolveModulePathForCommit(repoRoot, commitSha, candidates) {
|
|
1527
|
+
for (const candidate of candidates) {
|
|
1528
|
+
if (await commitHasPath(repoRoot, commitSha, candidate)) {
|
|
1529
|
+
return candidate;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
return void 0;
|
|
1533
|
+
}
|
|
1474
1534
|
function parentDirectories(relativePath) {
|
|
1475
1535
|
const clean = normalizePath(relativePath).replace(/^\/+/, "");
|
|
1476
1536
|
const dir = path4.posix.dirname(clean);
|
|
@@ -1482,8 +1542,11 @@ function parentDirectories(relativePath) {
|
|
|
1482
1542
|
}
|
|
1483
1543
|
return out;
|
|
1484
1544
|
}
|
|
1485
|
-
function buildRelevantConfigFiles(
|
|
1486
|
-
const dirs = new Set(
|
|
1545
|
+
function buildRelevantConfigFiles(moduleCandidates, tsconfigRel) {
|
|
1546
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
1547
|
+
for (const moduleRel of moduleCandidates) {
|
|
1548
|
+
parentDirectories(moduleRel).forEach((item) => dirs.add(item));
|
|
1549
|
+
}
|
|
1487
1550
|
if (tsconfigRel) {
|
|
1488
1551
|
parentDirectories(tsconfigRel).forEach((item) => dirs.add(item));
|
|
1489
1552
|
dirs.add(path4.posix.dirname(normalizePath(tsconfigRel)));
|
|
@@ -1496,7 +1559,7 @@ function buildRelevantConfigFiles(moduleRel, tsconfigRel) {
|
|
|
1496
1559
|
}
|
|
1497
1560
|
return files;
|
|
1498
1561
|
}
|
|
1499
|
-
async function commitTouchedRelevantPaths(cwd, commit,
|
|
1562
|
+
async function commitTouchedRelevantPaths(cwd, commit, moduleCandidates, tsconfigRel) {
|
|
1500
1563
|
const changed = await runGit(cwd, [
|
|
1501
1564
|
"show",
|
|
1502
1565
|
"--pretty=format:",
|
|
@@ -1505,27 +1568,35 @@ async function commitTouchedRelevantPaths(cwd, commit, moduleRel, tsconfigRel) {
|
|
|
1505
1568
|
commit
|
|
1506
1569
|
]);
|
|
1507
1570
|
const changedFiles = changed.split("\n").map((item) => normalizePath(item.trim()).replace(/^\/+/, "")).filter(Boolean);
|
|
1508
|
-
const
|
|
1509
|
-
|
|
1571
|
+
const moduleFiles = Array.from(
|
|
1572
|
+
new Set(moduleCandidates.map((item) => normalizePath(item).replace(/^\/+/, "")))
|
|
1573
|
+
);
|
|
1574
|
+
const moduleDirs = Array.from(
|
|
1575
|
+
new Set(
|
|
1576
|
+
moduleFiles.map((item) => normalizePath(path4.posix.dirname(item)).replace(/^\/+/, "")).filter((item) => item && item !== ".")
|
|
1577
|
+
)
|
|
1578
|
+
);
|
|
1510
1579
|
const tsconfigFile = tsconfigRel ? normalizePath(tsconfigRel).replace(/^\/+/, "") : void 0;
|
|
1511
|
-
const configFiles = buildRelevantConfigFiles(
|
|
1580
|
+
const configFiles = buildRelevantConfigFiles(moduleFiles, tsconfigFile);
|
|
1512
1581
|
return changedFiles.some((file) => {
|
|
1513
|
-
if (file
|
|
1514
|
-
|
|
1515
|
-
|
|
1582
|
+
if (moduleFiles.includes(file)) return true;
|
|
1583
|
+
for (const moduleDir of moduleDirs) {
|
|
1584
|
+
if (file === moduleDir || file.startsWith(`${moduleDir}/`)) {
|
|
1585
|
+
return true;
|
|
1586
|
+
}
|
|
1516
1587
|
}
|
|
1517
1588
|
if (tsconfigFile && file === tsconfigFile) return true;
|
|
1518
1589
|
return configFiles.has(file);
|
|
1519
1590
|
});
|
|
1520
1591
|
}
|
|
1521
|
-
async function filterCommits(cwd, commits,
|
|
1592
|
+
async function filterCommits(cwd, commits, moduleCandidates, tsconfigRel) {
|
|
1522
1593
|
if (commits.length <= 1) {
|
|
1523
1594
|
return commits;
|
|
1524
1595
|
}
|
|
1525
1596
|
const keep = [commits[0]];
|
|
1526
1597
|
for (let i = 1; i < commits.length; i += 1) {
|
|
1527
1598
|
const commit = commits[i];
|
|
1528
|
-
if (await commitTouchedRelevantPaths(cwd, commit,
|
|
1599
|
+
if (await commitTouchedRelevantPaths(cwd, commit, moduleCandidates, tsconfigRel)) {
|
|
1529
1600
|
keep.push(commit);
|
|
1530
1601
|
}
|
|
1531
1602
|
}
|
|
@@ -1959,6 +2030,7 @@ async function compileSnapshotEntry(options) {
|
|
|
1959
2030
|
declarationMap: false,
|
|
1960
2031
|
sourceMap: false,
|
|
1961
2032
|
inlineSourceMap: false,
|
|
2033
|
+
inlineSources: false,
|
|
1962
2034
|
composite: false,
|
|
1963
2035
|
incremental: false,
|
|
1964
2036
|
tsBuildInfoFile: void 0,
|
|
@@ -1991,12 +2063,31 @@ ${message}`
|
|
|
1991
2063
|
async function loadSnapshotExport(options) {
|
|
1992
2064
|
return loadChangelogInput(options.entryPath, options.exportName);
|
|
1993
2065
|
}
|
|
1994
|
-
async function createSnapshot(repoRoot,
|
|
2066
|
+
async function createSnapshot(repoRoot, moduleCandidates, exportName, commit, tempRoot, tsconfigRel, exportOptions, log) {
|
|
1995
2067
|
const worktreeDir = path4.join(tempRoot, `wt-${commit.sha.slice(0, 12)}`);
|
|
1996
2068
|
await runGit(repoRoot, ["worktree", "add", "--detach", worktreeDir, commit.sha]);
|
|
1997
2069
|
try {
|
|
1998
2070
|
await ensureWorktreeDependencies(repoRoot, worktreeDir);
|
|
1999
|
-
const
|
|
2071
|
+
const resolvedModuleRel = await resolveModulePathForCommit(
|
|
2072
|
+
repoRoot,
|
|
2073
|
+
commit.sha,
|
|
2074
|
+
moduleCandidates
|
|
2075
|
+
);
|
|
2076
|
+
if (!resolvedModuleRel) {
|
|
2077
|
+
log?.(
|
|
2078
|
+
`[changelog] unresolved module for commit ${commit.sha.slice(0, 12)}; using empty snapshot`
|
|
2079
|
+
);
|
|
2080
|
+
return {
|
|
2081
|
+
commit,
|
|
2082
|
+
routesByKey: {},
|
|
2083
|
+
sourceObjectsById: {},
|
|
2084
|
+
unresolvedModule: true
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
log?.(
|
|
2088
|
+
`[changelog] resolved module for commit ${commit.sha.slice(0, 12)}: ${resolvedModuleRel}`
|
|
2089
|
+
);
|
|
2090
|
+
const modulePath = path4.resolve(worktreeDir, resolvedModuleRel);
|
|
2000
2091
|
let snapshotRuntimePath = modulePath;
|
|
2001
2092
|
let resolvedTsconfigPath;
|
|
2002
2093
|
if (isTypeScriptModule(modulePath)) {
|
|
@@ -2011,7 +2102,7 @@ async function createSnapshot(repoRoot, moduleRel, exportName, commit, tempRoot,
|
|
|
2011
2102
|
);
|
|
2012
2103
|
snapshotRuntimePath = await compileSnapshotEntry({
|
|
2013
2104
|
worktreeDir,
|
|
2014
|
-
moduleRel,
|
|
2105
|
+
moduleRel: resolvedModuleRel,
|
|
2015
2106
|
modulePath,
|
|
2016
2107
|
tsconfigPath: resolvedTsconfigPath,
|
|
2017
2108
|
commitSha: commit.sha,
|
|
@@ -2268,12 +2359,18 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2268
2359
|
log("[changelog] resolving commit window");
|
|
2269
2360
|
const window = await resolveCommitWindow(repoRoot, options.from, options.to);
|
|
2270
2361
|
log(`[changelog] window: ${window.from.slice(0, 12)}..${window.to.slice(0, 12)}`);
|
|
2362
|
+
const moduleCandidates = await buildModulePathCandidates(
|
|
2363
|
+
repoRoot,
|
|
2364
|
+
window.to,
|
|
2365
|
+
modulePathRelative
|
|
2366
|
+
);
|
|
2367
|
+
log(`[changelog] module candidates discovered: ${moduleCandidates.length}`);
|
|
2271
2368
|
const allCommits = await resolveCommitPath(repoRoot, window.from, window.to);
|
|
2272
2369
|
log(`[changelog] commits in ancestry path: ${allCommits.length}`);
|
|
2273
2370
|
const selectedCommitShas = await filterCommits(
|
|
2274
2371
|
repoRoot,
|
|
2275
2372
|
allCommits,
|
|
2276
|
-
|
|
2373
|
+
moduleCandidates,
|
|
2277
2374
|
tsconfigRelative
|
|
2278
2375
|
);
|
|
2279
2376
|
log(`[changelog] commits after path filter: ${selectedCommitShas.length}`);
|
|
@@ -2290,6 +2387,7 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2290
2387
|
log(`[changelog] temp workspace: ${tempRoot}`);
|
|
2291
2388
|
try {
|
|
2292
2389
|
const snapshots = [];
|
|
2390
|
+
const unresolvedModuleCommits = [];
|
|
2293
2391
|
for (let index = 0; index < commits.length; index += 1) {
|
|
2294
2392
|
const commit = commits[index];
|
|
2295
2393
|
log(
|
|
@@ -2298,7 +2396,7 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2298
2396
|
snapshots.push(
|
|
2299
2397
|
await createSnapshot(
|
|
2300
2398
|
repoRoot,
|
|
2301
|
-
|
|
2399
|
+
moduleCandidates,
|
|
2302
2400
|
exportName,
|
|
2303
2401
|
commit,
|
|
2304
2402
|
tempRoot,
|
|
@@ -2307,6 +2405,9 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2307
2405
|
log
|
|
2308
2406
|
)
|
|
2309
2407
|
);
|
|
2408
|
+
if (snapshots[snapshots.length - 1]?.unresolvedModule) {
|
|
2409
|
+
unresolvedModuleCommits.push(commit.sha);
|
|
2410
|
+
}
|
|
2310
2411
|
}
|
|
2311
2412
|
const routeEvents = [];
|
|
2312
2413
|
const sourceEvents = [];
|
|
@@ -2331,7 +2432,8 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2331
2432
|
exportName,
|
|
2332
2433
|
from: window.from,
|
|
2333
2434
|
to: window.to,
|
|
2334
|
-
selectedCommitCount: commits.length
|
|
2435
|
+
selectedCommitCount: commits.length,
|
|
2436
|
+
unresolvedModuleCommits: unresolvedModuleCommits.length > 0 ? unresolvedModuleCommits : void 0
|
|
2335
2437
|
},
|
|
2336
2438
|
commits,
|
|
2337
2439
|
byRoute: routeRecordByKey(routeEvents),
|
|
@@ -2358,6 +2460,8 @@ var __private = {
|
|
|
2358
2460
|
resolveCommitWindow,
|
|
2359
2461
|
resolveCommitPath,
|
|
2360
2462
|
filterCommits,
|
|
2463
|
+
buildModulePathCandidates,
|
|
2464
|
+
resolveModulePathForCommit,
|
|
2361
2465
|
resolveSnapshotTsconfig,
|
|
2362
2466
|
toEmittedModulePath,
|
|
2363
2467
|
buildCompileCacheKey,
|