Skip to content

Commit 6b6833f

Browse files
committed
runtime: even better exports tracking
After working with claude and closely tracking the docs
1 parent 30db816 commit 6b6833f

File tree

1 file changed

+16
-1
lines changed
  • packages/runtime/src/modules

1 file changed

+16
-1
lines changed

packages/runtime/src/modules/repo.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,22 @@ export const getModuleEntryPoint = async (
232232
);
233233
const pkg = JSON.parse(pkgRaw);
234234

235-
const main = pkg.exports?.['.']?.import ?? pkg.main ?? 'index.js';
235+
// Find the best ESM entrypoint
236+
// https://nodejs.org/api/packages.html#package-entry-points
237+
let esm;
238+
if (typeof pkg.exports === 'string') {
239+
esm = pkg.exports;
240+
} else {
241+
const exportsField = pkg.exports?.['.'];
242+
esm =
243+
typeof exportsField === 'string' ? exportsField : exportsField?.import;
244+
}
245+
246+
// main might point to esm or cjs, but in our adaptors it points to CJS
247+
const cjsProbably = pkg.main;
248+
249+
const main = esm ?? cjsProbably ?? 'index.js';
250+
236251
const p = path.resolve(moduleRoot, main);
237252

238253
return { path: p, version: pkg.version };

0 commit comments

Comments
 (0)