dsh-code-server-app 0.1.38 → 0.1.40

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/lib/index.js CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  vendoredVersion,
49
49
  vendorReady,
50
50
  } from './vendor.js';
51
- import { resolveRuntime, runtimePackageName, verifyNatives } from './native.js';
51
+ import { aliasNodePathDirs, resolveNativeDir, resolveRuntime, runtimePackageName, verifyNatives } from './native.js';
52
52
 
53
53
  // schemastery 由 DSH 部署自带(官方核心依赖),仿 auto-open-web 的解析策略:
54
54
  // 常规 import 优先,不可用时回退到全局 npm 布局的 DSH 部署副本。
@@ -242,7 +242,9 @@ function checkInnerDeps() {
242
242
  function envCheck() {
243
243
  const entry = bundledRuntimeEntry();
244
244
  const csRoot = entry ? path.dirname(path.dirname(path.dirname(entry))) : null; // .../code-server
245
- const argon2 = csRoot !== null ? path.join(csRoot, 'node_modules', 'argon2') : null;
245
+ // argon2 不在 code-server 本体包里(平台包 @<scope>/dshcs-argon2-<平台>-<架构> 提供,经聚合包用
246
+ // npm: 别名装回原名);pnpm 会把带 os/cpu 限定的包嵌套装在聚合包下,所以按多锚点解析。
247
+ const argon2 = resolveNativeDir('argon2');
246
248
  // 必须按当前平台判定:argon2 的 prebuilds 目录存在不代表本平台有二进制(win32-arm64 就缺)。
247
249
  const nativeOk = argon2 !== null && (
248
250
  fs.existsSync(path.join(argon2, 'build', 'Release', 'argon2.node')) ||
@@ -632,6 +634,14 @@ export async function apply(ctx, config) {
632
634
  if (auth === 'password') env.PASSWORD = cfg.passwordToken;
633
635
  // 内置扩展信号文件路径(host → 扩展 打开文件)
634
636
  env.DSHCS_OPEN_FILE_SIGNAL = openFileSignalPath(userDataDir);
637
+ // pnpm 会把带 os/cpu 限定的原生包(os 限定/平台专属)嵌套装在平台聚合包下
638
+ // (如 <profile>/node_modules/@<scope>/dsh-code-server-runtime-<平台>-<架构>/node_modules/argon2),
639
+ // 那些目录不在 code-server 树的向上查找链里 → 用 NODE_PATH 让子进程的 require 找得到。
640
+ const nodePathDirs = aliasNodePathDirs();
641
+ if (nodePathDirs.length > 0) {
642
+ const existing = typeof env.NODE_PATH === 'string' && env.NODE_PATH !== '' ? env.NODE_PATH.split(path.delimiter) : [];
643
+ env.NODE_PATH = [...new Set([...nodePathDirs, ...existing])].join(path.delimiter);
644
+ }
635
645
 
636
646
  let proc;
637
647
  try {
package/lib/native.js CHANGED
@@ -59,27 +59,57 @@ export function resolveRuntime() {
59
59
  return null;
60
60
  }
61
61
 
62
- /** 从 code-server 运行位置校验原生模块能否解析(与运行时同一套向上查找规则)。
62
+ /** 解析原生/别名模块时的锚点目录:
63
+ * ① code-server 运行根(树自带 node_modules);
64
+ * ② 平台聚合包目录 —— pnpm 会把带 os/cpu 限定的包**嵌套装在聚合包下**
65
+ * (`<profile>/node_modules/@<scope>/dsh-code-server-runtime-<平台>-<架构>/node_modules/<别名>`),
66
+ * 既不在 profile 根也不在 code-server 树里,所以要单独作为锚点(运行时用 NODE_PATH 覆盖同一批目录)。
67
+ * @returns {string[]} */
68
+ export function nativeSearchRoots() {
69
+ const roots = [];
70
+ const cs = codeServerRoot();
71
+ if (cs !== null) roots.push(cs);
72
+ const runtime = resolveRuntime();
73
+ if (runtime !== null) roots.push(runtime.root);
74
+ return roots;
75
+ }
76
+
77
+ /** 运行时需要加进 NODE_PATH 的目录(平台聚合包下嵌套的别名包)。
78
+ * @returns {string[]} */
79
+ export function aliasNodePathDirs() {
80
+ const runtime = resolveRuntime();
81
+ if (runtime === null) return [];
82
+ const dir = join(runtime.root, 'node_modules');
83
+ return existsSync(dir) ? [dir] : [];
84
+ }
85
+
86
+ /** 解析某个模块的包目录(依次尝试各锚点;先 `<name>/package.json`,再模块入口)。
87
+ * @returns {string|null} */
88
+ export function resolveNativeDir(name) {
89
+ for (const root of nativeSearchRoots()) {
90
+ let from;
91
+ try {
92
+ from = createRequire(join(root, 'package.json'));
93
+ } catch { continue; }
94
+ for (const spec of [`${name}/package.json`, name]) {
95
+ try {
96
+ return dirname(from.resolve(spec));
97
+ } catch { /* 试下一个 */ }
98
+ }
99
+ }
100
+ return null;
101
+ }
102
+
103
+ /** 从 code-server 运行位置(与聚合包目录)校验原生模块能否解析。
63
104
  * 先试 `<name>/package.json`(ESM-only 包没有 require 入口,如 @microsoft/mxc-sdk),
64
105
  * 再退回 `<name>` 本身。
65
106
  * @param {string[]} modules 期望的原生模块名(通常来自聚合包依赖清单)
66
107
  * @returns {{resolved:string[], missing:string[]}} */
67
108
  export function verifyNatives(modules) {
68
- // 锚点 = code-server 运行根(平台子包内的 code-server/ 或包内 vendor);
69
- // 从它向上:自带 node_modules → 插件 node_modules → <profile>/node_modules。
70
- const from = createRequire(join(codeServerRoot() ?? PACKAGE_ROOT, 'package.json'));
71
109
  const resolved = [];
72
110
  const missing = [];
73
111
  for (const name of modules) {
74
- let ok = false;
75
- for (const spec of [`${name}/package.json`, name]) {
76
- try {
77
- from.resolve(spec);
78
- ok = true;
79
- break;
80
- } catch { /* 试下一个 */ }
81
- }
82
- if (ok) resolved.push(name);
112
+ if (resolveNativeDir(name) !== null) resolved.push(name);
83
113
  else missing.push(name);
84
114
  }
85
115
  return { resolved, missing };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-code-server-app",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "Integrate code-server (VS Code in the browser) into DSH Web and Desktop: right-sidebar tab (DSH >= 0.1.5-alpha.1) with a floating-ball fallback for older hosts, over the Connection /api channel (ctx.connection.fetch; no webServer dependency) with host-side process lifecycle.",
5
5
  "homepage": "https://github.com/jinsiyu/dsh-code-server-app",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "codeServerVersion": "4.136.2",
3
- "preparedAt": "2026-09-10T05:56:02.654Z",
3
+ "preparedAt": "2026-09-10T06:32:05.257Z",
4
4
  "source": "registry",
5
5
  "node": "v24.13.1",
6
6
  "platform": "win32",