dsh-code-server-app 0.1.42 → 0.1.43
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/native.js +44 -12
- package/package.json +1 -1
- package/vendor/VENDOR.json +1 -1
package/lib/native.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// 2. 从 code-server 运行位置出发校验这些模块是否真的能 require 到;
|
|
14
14
|
// 3. 必要时在 code-server 树里补齐别名 junction(ESM import 不认 NODE_PATH,只能靠目录链)。
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
|
-
import { existsSync, readFileSync, mkdirSync, symlinkSync } from 'node:fs';
|
|
16
|
+
import { existsSync, readFileSync, mkdirSync, symlinkSync, lstatSync, rmSync } from 'node:fs';
|
|
17
17
|
import { dirname, join } from 'node:path';
|
|
18
18
|
import { PACKAGE_ROOT, codeServerRoot, profileRootOf } from './vendor.js';
|
|
19
19
|
|
|
@@ -163,21 +163,44 @@ export function ensureAliasLinks() {
|
|
|
163
163
|
return { created, failed };
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
/** 从**插件依赖图**解析(插件 node_modules → <profile>/node_modules)
|
|
166
|
+
/** 从**插件依赖图**解析(插件 node_modules → <profile>/node_modules),返回**真正的包根目录**
|
|
167
|
+
* (有些包 `exports` 不暴露 `./package.json`,只能从入口文件往上找 name 匹配的目录)。
|
|
167
168
|
* 与 `resolveNativeDir` 的区别:不走 code-server 树(树里可能有别的同名版本,例如 code-server 自带的
|
|
168
|
-
* typescript 5.9.3,而 VS Code 要的是 inner deps 里那份
|
|
169
|
-
function
|
|
169
|
+
* typescript 5.9.3,而 VS Code 要的是 inner deps 里那份)。 */
|
|
170
|
+
function packageRootFromPlugin(name) {
|
|
171
|
+
let from;
|
|
170
172
|
try {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
from = createRequire(join(PACKAGE_ROOT, 'package.json'));
|
|
174
|
+
} catch { return null; }
|
|
175
|
+
try {
|
|
176
|
+
return dirname(from.resolve(`${name}/package.json`));
|
|
177
|
+
} catch { /* exports 未暴露 package.json → 退回入口文件 */ }
|
|
178
|
+
try {
|
|
179
|
+
let dir = dirname(from.resolve(name));
|
|
180
|
+
for (let i = 0; i < 8; i += 1) {
|
|
173
181
|
try {
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
183
|
+
if (manifest.name === name) return dir;
|
|
184
|
+
} catch { /* 继续往上 */ }
|
|
185
|
+
const parent = dirname(dir);
|
|
186
|
+
if (parent === dir) break;
|
|
187
|
+
dir = parent;
|
|
176
188
|
}
|
|
177
|
-
} catch { /*
|
|
189
|
+
} catch { /* 解析不了 */ }
|
|
178
190
|
return null;
|
|
179
191
|
}
|
|
180
192
|
|
|
193
|
+
/** 路径上是否已有东西(**包括断链的 junction**:code-server 树被 pnpm 重装后旧链接会变成断链,
|
|
194
|
+
* `existsSync` 对断链返回 false,直接再建会 EPERM)。 */
|
|
195
|
+
function pathEntryExists(target) {
|
|
196
|
+
try {
|
|
197
|
+
lstatSync(target);
|
|
198
|
+
return true;
|
|
199
|
+
} catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
181
204
|
/** 把 VS Code 的「内部依赖目录」用 junction 补回老布局。
|
|
182
205
|
*
|
|
183
206
|
* 为什么需要:老模型里 `lib/vscode/node_modules` 与 `lib/vscode/extensions/node_modules` 是 npm 在树里
|
|
@@ -204,15 +227,24 @@ export function ensureInnerModuleLinks() {
|
|
|
204
227
|
} catch { continue; }
|
|
205
228
|
for (const name of Object.keys(deps)) {
|
|
206
229
|
const link = join(dir, name);
|
|
207
|
-
if (existsSync(join(link, 'package.json'))) continue; //
|
|
208
|
-
|
|
230
|
+
if (existsSync(join(link, 'package.json'))) continue; // 链接有效(真实目录或有效 junction)
|
|
231
|
+
if (pathEntryExists(link)) {
|
|
232
|
+
// 断链(树被重装过)→ 清掉重建
|
|
233
|
+
try {
|
|
234
|
+
rmSync(link, { recursive: true, force: true });
|
|
235
|
+
} catch (error) {
|
|
236
|
+
failed.push(`${name}: 旧链接清理失败 ${error && error.code ? error.code : error}`);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const target = packageRootFromPlugin(name);
|
|
209
241
|
if (target === null) continue; // 该依赖没装(envCheck 会另行报告)
|
|
210
242
|
try {
|
|
211
243
|
mkdirSync(dirname(link), { recursive: true });
|
|
212
244
|
symlinkSync(target, link, process.platform === 'win32' ? 'junction' : 'dir');
|
|
213
245
|
created.push(name);
|
|
214
246
|
} catch (error) {
|
|
215
|
-
failed.push(`${name}: ${error && error.
|
|
247
|
+
failed.push(`${name}: ${error && error.code ? error.code : error}`);
|
|
216
248
|
}
|
|
217
249
|
}
|
|
218
250
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-code-server-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.43",
|
|
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": {
|