@clawchatsai/connector 0.1.13 → 0.1.14
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.js +35 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -102,18 +102,42 @@ function getPrebuildKey() {
|
|
|
102
102
|
return `linuxmusl-${arch}`;
|
|
103
103
|
return `${platform}-${arch}`;
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Resolve a package's install root without relying on subpath access to its
|
|
107
|
+
* package.json. Node treats an "exports" map as an allowlist, so
|
|
108
|
+
* require.resolve('<pkg>/package.json') throws for any package that does not
|
|
109
|
+
* explicitly export it. Resolving the main entry is always permitted, so walk
|
|
110
|
+
* up from there to the directory named after the package.
|
|
111
|
+
*/
|
|
112
|
+
function resolvePackageRoot(require, pkgName) {
|
|
113
|
+
let entry;
|
|
114
|
+
try {
|
|
115
|
+
entry = require.resolve(pkgName);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const marker = `${path.sep}${pkgName}${path.sep}`;
|
|
121
|
+
const idx = entry.lastIndexOf(marker);
|
|
122
|
+
if (idx === -1)
|
|
123
|
+
return undefined;
|
|
124
|
+
return entry.slice(0, idx + marker.length - 1);
|
|
125
|
+
}
|
|
105
126
|
async function ensureNativeModules(ctx) {
|
|
106
127
|
const pluginDir = path.resolve(__dirname, '..');
|
|
107
128
|
// Resolve node-datachannel's actual install root (handles npm hoisting).
|
|
108
129
|
// Writing to <pluginDir>/node_modules/node-datachannel/ would create a
|
|
109
130
|
// package-shaped directory that lacks package.json + JS, shadowing the
|
|
110
131
|
// hoisted copy and breaking subpath imports like 'node-datachannel/polyfill'.
|
|
132
|
+
//
|
|
133
|
+
// Resolve via the package's main entry, NOT 'node-datachannel/package.json':
|
|
134
|
+
// node-datachannel's exports map declares only "." and "./polyfill", so asking
|
|
135
|
+
// for the package.json subpath always throws ERR_PACKAGE_PATH_NOT_EXPORTED.
|
|
136
|
+
// That made this function bail out before copying anything on every install;
|
|
137
|
+
// it only appeared to work where a binary already existed from a source build.
|
|
111
138
|
const require = createRequire(import.meta.url);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
ndcRoot = path.dirname(require.resolve('node-datachannel/package.json'));
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
139
|
+
const ndcRoot = resolvePackageRoot(require, 'node-datachannel');
|
|
140
|
+
if (!ndcRoot) {
|
|
117
141
|
ctx.logger.error('[clawchats] node-datachannel package not resolvable; WebRTC unavailable.');
|
|
118
142
|
return;
|
|
119
143
|
}
|
|
@@ -137,7 +161,12 @@ async function ensureNativeModules(ctx) {
|
|
|
137
161
|
ctx.logger.info('[clawchats] node-datachannel ready.');
|
|
138
162
|
}
|
|
139
163
|
catch (e) {
|
|
140
|
-
|
|
164
|
+
// Surface the manual remedy: the service import fails moments later with an
|
|
165
|
+
// opaque "Cannot find module '../../../build/Release/node_datachannel.node'",
|
|
166
|
+
// which says nothing about what to actually do.
|
|
167
|
+
ctx.logger.error(`[clawchats] Failed to install prebuilt: ${e.message}\n` +
|
|
168
|
+
` To fix manually:\n mkdir -p ${path.dirname(targetPath)}\n` +
|
|
169
|
+
` cp ${prebuiltPath} ${targetPath}`);
|
|
141
170
|
}
|
|
142
171
|
}
|
|
143
172
|
const CLAWCHATS_MD_CONTENT = `# ClawChats — Inline File Delivery
|