@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 CHANGED
@@ -1871,11 +1871,95 @@ async function ensureWorktreeDependencies(repoRoot, worktreeDir) {
1871
1871
  }
1872
1872
  await import_promises2.default.symlink(rootNodeModules, worktreeNodeModules, "junction");
1873
1873
  }
1874
- async function createSnapshot(repoRoot, moduleRel, exportName, commit, tempRoot, tsconfigRel, exportOptions) {
1874
+ async function pathExists(filePath) {
1875
+ try {
1876
+ await import_promises2.default.access(filePath);
1877
+ return true;
1878
+ } catch {
1879
+ return false;
1880
+ }
1881
+ }
1882
+ async function createMissingJsImportShims(worktreeDir) {
1883
+ const shimWrites = [];
1884
+ const filesToScan = [];
1885
+ const skipNames = /* @__PURE__ */ new Set([".git", "node_modules", "dist", "build"]);
1886
+ const walk = async (dir) => {
1887
+ const entries = await import_promises2.default.readdir(dir, { withFileTypes: true });
1888
+ for (const entry of entries) {
1889
+ if (entry.isDirectory()) {
1890
+ if (skipNames.has(entry.name)) continue;
1891
+ await walk(import_node_path4.default.join(dir, entry.name));
1892
+ continue;
1893
+ }
1894
+ if (!entry.isFile()) continue;
1895
+ if (!/\\.(ts|tsx|mts)$/.test(entry.name)) continue;
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);
1947
+ }
1948
+ }
1949
+ }
1950
+ return shimWrites;
1951
+ }
1952
+ async function createSnapshot(repoRoot, moduleRel, exportName, commit, tempRoot, tsconfigRel, exportOptions, log) {
1875
1953
  const worktreeDir = import_node_path4.default.join(tempRoot, `wt-${commit.sha.slice(0, 12)}`);
1876
1954
  await runGit(repoRoot, ["worktree", "add", "--detach", worktreeDir, commit.sha]);
1877
1955
  try {
1878
1956
  await ensureWorktreeDependencies(repoRoot, worktreeDir);
1957
+ const shimmedFiles = await createMissingJsImportShims(worktreeDir);
1958
+ if (shimmedFiles.length > 0) {
1959
+ log?.(
1960
+ `[changelog] created ${shimmedFiles.length} missing .js import shim(s) in ${commit.sha.slice(0, 12)}`
1961
+ );
1962
+ }
1879
1963
  const modulePath = import_node_path4.default.resolve(worktreeDir, moduleRel);
1880
1964
  const tsconfigPath = tsconfigRel ? import_node_path4.default.resolve(worktreeDir, tsconfigRel) : void 0;
1881
1965
  const input = await loadChangelogInput(modulePath, exportName);
@@ -2154,7 +2238,8 @@ async function exportFinalizedLeavesChangelog(options) {
2154
2238
  commit,
2155
2239
  tempRoot,
2156
2240
  tsconfigRelative,
2157
- options
2241
+ options,
2242
+ log
2158
2243
  )
2159
2244
  );
2160
2245
  }