From ed02186f627fd3f499c29b6abd9a16ccf8edf3b9 Mon Sep 17 00:00:00 2001
From: Mantra <87142457+mantrakp04@users.noreply.github.com>
Date: Mon, 15 Jun 2026 16:32:09 -0700
Subject: [PATCH] Fix/npm-pkg-shared-backend (#1598)
---
## Summary by cubic
Prepares `@hexclave/shared-backend` for npm publishing with a proper
build, dual ESM/CJS exports, and bundled types. Also simplifies an
import parsing helper for safer matching.
- New Features
- Configure build with `tsdown`; output CJS/ESM and `.d.ts` to `dist/`
and `dist/esm/`.
- Add export map for `.` and `./config-agent` with `require` and
`default` entries plus types.
- Update publish settings: set `main`/`types` to built files, include
only `dist`, exclude tests, and add `build`, `dev`, `clean` scripts.
- Add repository field and `tsdown.config.ts`.
- Bug Fixes
- Simplified import specifier parsing in `src/index.ts` to push matches
directly and remove unnecessary error throwing.
Written for commit 9f18bc019ae452099b719241dd0d4051cad92d09.
Summary will update on new commits.
---
packages/shared-backend/package.json | 32 +++++++++++++++++++-----
packages/shared-backend/src/index.ts | 6 +----
packages/shared-backend/tsdown.config.ts | 3 +++
3 files changed, 30 insertions(+), 11 deletions(-)
create mode 100644 packages/shared-backend/tsdown.config.ts
diff --git a/packages/shared-backend/package.json b/packages/shared-backend/package.json
index 3fd9096d8..307aa5b23 100644
--- a/packages/shared-backend/package.json
+++ b/packages/shared-backend/package.json
@@ -1,19 +1,39 @@
{
"name": "@hexclave/shared-backend",
"version": "1.0.17",
- "private": true,
- "type": "module",
- "main": "./src/index.ts",
- "types": "./src/index.ts",
+ "repository": "https://github.com/hexclave/hexclave",
+ "main": "./dist/index.js",
+ "types": "./dist/index.d.ts",
"exports": {
- ".": "./src/index.ts",
- "./config-agent": "./src/config-agent.ts"
+ ".": {
+ "types": "./dist/index.d.ts",
+ "require": {
+ "default": "./dist/index.js"
+ },
+ "default": "./dist/esm/index.js"
+ },
+ "./config-agent": {
+ "types": "./dist/config-agent.d.ts",
+ "require": {
+ "default": "./dist/config-agent.js"
+ },
+ "default": "./dist/esm/config-agent.js"
+ }
},
"scripts": {
+ "build": "rimraf dist && tsdown",
+ "clean": "rimraf dist && rimraf node_modules",
+ "dev": "tsdown --watch",
"lint": "eslint --ext .tsx,.ts .",
"typecheck": "tsc --noEmit",
"test": "vitest run"
},
+ "files": [
+ "dist",
+ "!dist/**/*.test.*",
+ "CHANGELOG.md",
+ "LICENSE"
+ ],
"dependencies": {
"@anthropic-ai/claude-agent-sdk": "^0.2.73",
"@hexclave/shared": "workspace:*",
diff --git a/packages/shared-backend/src/index.ts b/packages/shared-backend/src/index.ts
index f3f04003a..044ab1edf 100644
--- a/packages/shared-backend/src/index.ts
+++ b/packages/shared-backend/src/index.ts
@@ -330,11 +330,7 @@ function getRelativeImportSpecifiers(content: string): string[] {
const importPattern = /\bimport\b(?:[^'"]*?\bfrom\s*)?["'](\.{1,2}\/[^"']+)["']/g;
let match: RegExpExecArray | null;
while ((match = importPattern.exec(content)) !== null) {
- const specifier = match[1];
- if (specifier == null) {
- throw new Error("Import specifier regex matched without a capture group.");
- }
- specifiers.push(specifier);
+ specifiers.push(match[1]);
}
return specifiers;
}
diff --git a/packages/shared-backend/tsdown.config.ts b/packages/shared-backend/tsdown.config.ts
new file mode 100644
index 000000000..d112d04a0
--- /dev/null
+++ b/packages/shared-backend/tsdown.config.ts
@@ -0,0 +1,3 @@
+import createJsLibraryTsupConfig from '../../configs/tsdown/js-library.ts';
+
+export default createJsLibraryTsupConfig({});