@emeryld/rrroutes-export 1.0.7 → 1.0.8
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/index.cjs +87 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +87 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1817,11 +1817,95 @@ async function ensureWorktreeDependencies(repoRoot, worktreeDir) {
|
|
|
1817
1817
|
}
|
|
1818
1818
|
await fs2.symlink(rootNodeModules, worktreeNodeModules, "junction");
|
|
1819
1819
|
}
|
|
1820
|
-
async function
|
|
1820
|
+
async function pathExists(filePath) {
|
|
1821
|
+
try {
|
|
1822
|
+
await fs2.access(filePath);
|
|
1823
|
+
return true;
|
|
1824
|
+
} catch {
|
|
1825
|
+
return false;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
async function createMissingJsImportShims(worktreeDir) {
|
|
1829
|
+
const shimWrites = [];
|
|
1830
|
+
const filesToScan = [];
|
|
1831
|
+
const skipNames = /* @__PURE__ */ new Set([".git", "node_modules", "dist", "build"]);
|
|
1832
|
+
const walk = async (dir) => {
|
|
1833
|
+
const entries = await fs2.readdir(dir, { withFileTypes: true });
|
|
1834
|
+
for (const entry of entries) {
|
|
1835
|
+
if (entry.isDirectory()) {
|
|
1836
|
+
if (skipNames.has(entry.name)) continue;
|
|
1837
|
+
await walk(path4.join(dir, entry.name));
|
|
1838
|
+
continue;
|
|
1839
|
+
}
|
|
1840
|
+
if (!entry.isFile()) continue;
|
|
1841
|
+
if (!/\\.(ts|tsx|mts)$/.test(entry.name)) continue;
|
|
1842
|
+
filesToScan.push(path4.join(dir, entry.name));
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
await walk(worktreeDir);
|
|
1846
|
+
const importRegexes = [
|
|
1847
|
+
/\\bfrom\\s+['\"](\\.[^'\"]+\\.js)['\"]/g,
|
|
1848
|
+
/\\bimport\\(\\s*['\"](\\.[^'\"]+\\.js)['\"]\\s*\\)/g,
|
|
1849
|
+
/\\brequire\\(\\s*['\"](\\.[^'\"]+\\.js)['\"]\\s*\\)/g
|
|
1850
|
+
];
|
|
1851
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1852
|
+
for (const filePath of filesToScan) {
|
|
1853
|
+
const content = await fs2.readFile(filePath, "utf8");
|
|
1854
|
+
for (const regex of importRegexes) {
|
|
1855
|
+
regex.lastIndex = 0;
|
|
1856
|
+
let match = regex.exec(content);
|
|
1857
|
+
while (match) {
|
|
1858
|
+
const specifier = match[1];
|
|
1859
|
+
const resolvedJs = path4.resolve(path4.dirname(filePath), specifier);
|
|
1860
|
+
if (seen.has(resolvedJs)) {
|
|
1861
|
+
match = regex.exec(content);
|
|
1862
|
+
continue;
|
|
1863
|
+
}
|
|
1864
|
+
seen.add(resolvedJs);
|
|
1865
|
+
if (await pathExists(resolvedJs)) {
|
|
1866
|
+
match = regex.exec(content);
|
|
1867
|
+
continue;
|
|
1868
|
+
}
|
|
1869
|
+
const tsCandidates = [
|
|
1870
|
+
resolvedJs.replace(/\\.js$/, ".ts"),
|
|
1871
|
+
resolvedJs.replace(/\\.js$/, ".mts"),
|
|
1872
|
+
resolvedJs.replace(/\\.js$/, ".tsx")
|
|
1873
|
+
];
|
|
1874
|
+
let targetTs;
|
|
1875
|
+
for (const candidate of tsCandidates) {
|
|
1876
|
+
if (await pathExists(candidate)) {
|
|
1877
|
+
targetTs = candidate;
|
|
1878
|
+
break;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
if (targetTs) {
|
|
1882
|
+
const relImport = normalizePath(path4.relative(path4.dirname(resolvedJs), targetTs));
|
|
1883
|
+
const importPath = relImport.startsWith(".") ? relImport : `./${relImport}`;
|
|
1884
|
+
const shim = `export * from '${importPath}'
|
|
1885
|
+
import * as __all from '${importPath}'
|
|
1886
|
+
export default ('default' in __all ? __all.default : __all)
|
|
1887
|
+
`;
|
|
1888
|
+
await fs2.mkdir(path4.dirname(resolvedJs), { recursive: true });
|
|
1889
|
+
await fs2.writeFile(resolvedJs, shim, "utf8");
|
|
1890
|
+
shimWrites.push(resolvedJs);
|
|
1891
|
+
}
|
|
1892
|
+
match = regex.exec(content);
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
return shimWrites;
|
|
1897
|
+
}
|
|
1898
|
+
async function createSnapshot(repoRoot, moduleRel, exportName, commit, tempRoot, tsconfigRel, exportOptions, log) {
|
|
1821
1899
|
const worktreeDir = path4.join(tempRoot, `wt-${commit.sha.slice(0, 12)}`);
|
|
1822
1900
|
await runGit(repoRoot, ["worktree", "add", "--detach", worktreeDir, commit.sha]);
|
|
1823
1901
|
try {
|
|
1824
1902
|
await ensureWorktreeDependencies(repoRoot, worktreeDir);
|
|
1903
|
+
const shimmedFiles = await createMissingJsImportShims(worktreeDir);
|
|
1904
|
+
if (shimmedFiles.length > 0) {
|
|
1905
|
+
log?.(
|
|
1906
|
+
`[changelog] created ${shimmedFiles.length} missing .js import shim(s) in ${commit.sha.slice(0, 12)}`
|
|
1907
|
+
);
|
|
1908
|
+
}
|
|
1825
1909
|
const modulePath = path4.resolve(worktreeDir, moduleRel);
|
|
1826
1910
|
const tsconfigPath = tsconfigRel ? path4.resolve(worktreeDir, tsconfigRel) : void 0;
|
|
1827
1911
|
const input = await loadChangelogInput(modulePath, exportName);
|
|
@@ -2100,7 +2184,8 @@ async function exportFinalizedLeavesChangelog(options) {
|
|
|
2100
2184
|
commit,
|
|
2101
2185
|
tempRoot,
|
|
2102
2186
|
tsconfigRelative,
|
|
2103
|
-
options
|
|
2187
|
+
options,
|
|
2188
|
+
log
|
|
2104
2189
|
)
|
|
2105
2190
|
);
|
|
2106
2191
|
}
|