mirror of
https://github.com/hansjone/mind-map.git
synced 2026-10-09 03:20:49 +08:00
fix(dsh-plugin): resolve host peers via ESM import
Linked plugins under dsh.cmd break createRequire from import.meta.url; use dynamic import with profile node_modules fallbacks. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
4bffec1d81
commit
23ff27122f
1 changed files with 28 additions and 18 deletions
|
|
@ -3,11 +3,11 @@
|
||||||
* Canvas Web is local; chat IS a DSH Session (mirror only on the Web).
|
* Canvas Web is local; chat IS a DSH Session (mirror only on the Web).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createRequire } from 'node:module'
|
|
||||||
import { randomBytes } from 'node:crypto'
|
import { randomBytes } from 'node:crypto'
|
||||||
import { homedir } from 'node:os'
|
import { homedir } from 'node:os'
|
||||||
import { join, dirname } from 'node:path'
|
import { join } from 'node:path'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { pathToFileURL } from 'node:url'
|
||||||
|
import { existsSync } from 'node:fs'
|
||||||
import { createRuntime } from './runtime.js'
|
import { createRuntime } from './runtime.js'
|
||||||
import { createSessionBridge } from './session-bridge.js'
|
import { createSessionBridge } from './session-bridge.js'
|
||||||
import { makeMindmapSkill, registerMindmapTools } from './tools.js'
|
import { makeMindmapSkill, registerMindmapTools } from './tools.js'
|
||||||
|
|
@ -23,27 +23,37 @@ const DEFAULTS = {
|
||||||
autoStart: true,
|
autoStart: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadPkg(id) {
|
/**
|
||||||
const homes = [
|
* Resolve a host peer package via ESM import (not createRequire).
|
||||||
fileURLToPath(import.meta.url),
|
* Linked plugins + dsh.cmd chdir break CJS resolution from import.meta.url;
|
||||||
join(process.cwd(), 'package.json'),
|
* parallel loader import also races require() against cosmokit's ESM graph.
|
||||||
join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'profiles', 'web', 'package.json'),
|
*/
|
||||||
|
async function importHostPkg(id) {
|
||||||
|
const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
|
||||||
|
const scoped = id.startsWith('@')
|
||||||
|
const parts = scoped ? id.split('/') : [id]
|
||||||
|
const candidates = [
|
||||||
|
join(dshHome, 'profiles', 'web', 'node_modules', ...parts, 'lib', 'index.mjs'),
|
||||||
|
join(dshHome, 'profiles', 'web', 'node_modules', ...parts, 'lib', 'index.js'),
|
||||||
]
|
]
|
||||||
const errors = []
|
// Bare import works when the package is installed next to this plugin.
|
||||||
for (const from of homes) {
|
|
||||||
try {
|
try {
|
||||||
const require = createRequire(from)
|
return await import(id)
|
||||||
return require(id)
|
} catch {
|
||||||
} catch (e) {
|
// fall through to profile paths
|
||||||
errors.push(e)
|
}
|
||||||
|
for (const file of candidates) {
|
||||||
|
if (!existsSync(file)) continue
|
||||||
|
try {
|
||||||
|
return await import(pathToFileURL(file).href)
|
||||||
|
} catch {
|
||||||
|
// try next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const err = new Error(`cannot resolve ${id}`)
|
throw new Error(`cannot resolve ${id}`)
|
||||||
err.cause = errors[0]
|
|
||||||
throw err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchemaMod = loadPkg('@deepseek-ai/schemastery')
|
const SchemaMod = await importHostPkg('@deepseek-ai/schemastery')
|
||||||
const Schema = SchemaMod.default || SchemaMod
|
const Schema = SchemaMod.default || SchemaMod
|
||||||
|
|
||||||
export const Config = Schema.object({
|
export const Config = Schema.object({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue