Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): discover compiled default re-export extension mounts (#4956)

roboeve[bot]95571f13dd64
diff --git a/.changeset/compiled-reexport-mount-discovery.md b/.changeset/compiled-reexport-mount-discovery.md
new file mode 100644
index 000000000..a78c3e5ba
--- /dev/null
+++ b/.changeset/compiled-reexport-mount-discovery.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Fix discovery of extension mounts written as `export { default } from "<pkg>"` inside a packaged extension, which `eve extension build` compiles to `import x from "<pkg>"; export { x as default };`.
diff --git a/packages/eve/src/discover/extension-specifier.test.ts b/packages/eve/src/discover/extension-specifier.test.ts
index 21f544320..5a80c26a6 100644
--- a/packages/eve/src/discover/extension-specifier.test.ts
+++ b/packages/eve/src/discover/extension-specifier.test.ts
@@ -56,13 +56,13 @@ describe("parseExtensionMountSpecifier", () => {
});
// https://github.com/vercel/eve/issues/4953
- it.fails("reads a compiled identifier default export", () => {
+ it("reads a compiled identifier default export", () => {
const source = 'import b from "@acme/b";\nvar b_default = b;\nexport { b_default as default };';
expect(parseExtensionMountSpecifier(source)).toBe("@acme/b");
});
// https://github.com/vercel/eve/issues/4953
- it.fails("reads an emitted default re-export", () => {
+ it("reads an emitted default re-export", () => {
const source = 'import b_default from "@acme/b";\nexport { b_default as default };';
expect(parseExtensionMountSpecifier(source)).toBe("@acme/b");
});
diff --git a/packages/eve/src/discover/extension-specifier.ts b/packages/eve/src/discover/extension-specifier.ts
index e1283b1c7..9188de206 100644
--- a/packages/eve/src/discover/extension-specifier.ts
+++ b/packages/eve/src/discover/extension-specifier.ts
@@ -13,6 +13,7 @@ function escapeRegExp(value: string): string {
* - `import { crm } from "@acme/crm"; export default crm({ ... });`
* - `import crm from "@acme/crm"; export default crm();`
* - `import crm from "@acme/crm"; const mount = crm(); export { mount as default };`
+ * - `import crm from "@acme/crm"; export { crm as default };`
*
* Returns the specifier string, or `null` when the file does not match a
* recognized mount shape.
@@ -24,7 +25,7 @@ export function parseExtensionMountSpecifier(source: string): string | null {
}
const factory = source.match(/export\s+default\s+([A-Za-z_$][\w$]*)\s*[(;\n]/);
- const boundName = factory?.[1] ?? emittedMountFactory(source);
+ const boundName = factory?.[1] ?? emittedMountBinding(source);
if (boundName === undefined) {
return null;
}
@@ -53,7 +54,8 @@ export function parseExtensionMountSpecifier(source: string): string | null {
return null;
}
-function emittedMountFactory(source: string): string | undefined {
+/** Resolves `export { x as default }` to the factory call or identifier that initializes `x`, or to `x` itself. */
+function emittedMountBinding(source: string): string | undefined {
const exports = /export\s*\{([^}]*)\}\s*(?:;|$)/g;
for (const match of source.matchAll(exports)) {
for (const entry of (match[1] ?? "").split(",")) {
@@ -61,10 +63,10 @@ function emittedMountFactory(source: string): string | undefined {
if (alias === null) continue;
const declaration = source.match(
new RegExp(
- `\\b(?:const|let|var)\\s+${escapeRegExp(alias[1]!)}\\s*=\\s*([A-Za-z_$][\\w$]*)\\s*\\(`,
+ `\\b(?:const|let|var)\\s+${escapeRegExp(alias[1]!)}\\s*=\\s*([A-Za-z_$][\\w$]*)\\s*[(;]`,
),
);
- return declaration?.[1];
+ return declaration?.[1] ?? alias[1];
}
}
return undefined;