core
core copied to clipboard
[BUG] Windows 下 URI 在 Node.js 和 Web 环境的行为不一致问题
描述你的问题(Describe the bug)
对于 URI.file 在创建本地路径时, Web 环境创建的路径全是错的。
复现路径(To Reproduce)
const u = URI.file('d:\\repo\\ide-electron\\node_modules\\vscode-oniguruma\\release\\onig.wasm');
console.log(u.toString());
// Node.js
// file:///d%3A/repo/ide-electron/node_modules/vscode-oniguruma/release/onig.wasm
// Web
// file:///d%3A%5Crepo%5Cide-electron%5Cnode_modules%5Cvscode-oniguruma%5Crelease%5Conig.wasm
预期表现(Expected behavior) 预期是 Node.js 的行为
问题截图(Screenshots)
Node.js 表现

Electron Renderer 表现

环境信息(Environment)
- OS: windows 10
- Electron
- OpenSumi Version 2.13.4
补充信息(Additional context)
vscode-uri 包的行为:

URI.file('d:\repo\ide-electron\node_modules\vscode-oniguruma\release\onig.wasm');
| Node.js | Web | |
|---|---|---|
| URI.file | scheme: file path: /d:/repo/ide-electron/node_modules/vscode-oniguruma/release/onig.wasm |
same |
| uri.toString() | file:///d%3A/repo/ide-electron/node_modules/vscode-oniguruma/release/onig.wasm | file:///d%3A%5Crepo%5Cide-electron%5Cnode_modules%5Cvscode-oniguruma%5Crelease%5Conig.wasm |
看起来是使用了 vscode-uri 中的 isWindows 判断逻辑: https://github.com/microsoft/vscode-uri/blob/main/src/platform.ts#L16
简单来讲,如果没有在 OpenSumi 中配置 browserNodeIntegrated 为 true,就会出现这种问题。
这块,感觉要改一下 electronEnv 这块的架构:纯粹的具有 Node.js 环境或者纯粹的 Web 环境。之后单独提一个来处理这些。
@yantze 这块后续看一下
问题
- 目前本身是 vscode-uri 内部用了 process.platfrom === 'win32' 做了判断
- 目前 OpenSumi 用了 webpack 4,会 mock 一个 browser-process,里面的 process.platfrom 是 browser process mock and browser
- 导致 vscode-uri 识别到的不是 windows 环境
- 目前 webpack 4 里面的 mock 似乎很难被修改,因为 process 是后续覆盖的,而 vscode-uri 是在解析代码时就识别并固定了,这也是为啥 webpack 5 会单独剥离出来 node 模块的 mock
解决方案
升级 webpack 5,剔除 process 进程的 mock。而 process 对象被 stream-browser 强依赖,可能还要看看这个问题的影响