Skip to content

Commit 13b9768

Browse files
author
Forest Hoffman
committed
Fix vscode-textmate dependency
1 parent 277c6cb commit 13b9768

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

build/tasks.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
8686
const webOutputPath = path.join(pkgsPath, "web", "out");
8787
const browserAppOutputPath = path.join(pkgsPath, "app", "browser", "out");
8888
const nodePtyModule = path.join(pkgsPath, "protocol", "node_modules", "node-pty-prebuilt", "build", "Release", "pty.node");
89+
const onigModule = path.join(pkgsPath, "..", "lib", "vscode", "node_modules", "oniguruma", "build", "Release", "onig_scanner.node");
8990
const spdlogModule = path.join(pkgsPath, "protocol", "node_modules", "spdlog", "build", "Release", "spdlog.node");
9091
let ripgrepPath = path.join(pkgsPath, "..", "lib", "vscode", "node_modules", "vscode-ripgrep", "bin", "rg");
9192
if (isWin) {
@@ -95,6 +96,9 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
9596
if (!fs.existsSync(nodePtyModule)) {
9697
throw new Error("Could not find pty.node. Ensure all packages have been installed");
9798
}
99+
if (!fs.existsSync(onigModule)) {
100+
throw new Error("Could not find onig_scanner.node. Ensure all packages have been installed");
101+
}
98102
if (!fs.existsSync(spdlogModule)) {
99103
throw new Error("Could not find spdlog.node. Ensure all packages have been installed");
100104
}
@@ -129,6 +133,7 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
129133
cpDir(browserAppOutputPath, "unauth", browserAppOutputPath);
130134
fse.mkdirpSync(path.join(cliBuildPath, "dependencies"));
131135
fse.copySync(nodePtyModule, path.join(cliBuildPath, "dependencies", "pty.node"));
136+
fse.copySync(onigModule, path.join(cliBuildPath, "dependencies", "onig_scanner.node"));
132137
fse.copySync(spdlogModule, path.join(cliBuildPath, "dependencies", "spdlog.node"));
133138
fse.copySync(ripgrepPath, path.join(cliBuildPath, "dependencies", "rg"));
134139
});

packages/server/src/modules.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ export const setup = (dataDirectory: string): void => {
3939
unpackModule("pty.node");
4040
unpackModule("spdlog.node");
4141
unpackModule("rg", true);
42+
unpackModule("onig_scanner.node");
4243
// const nodePtyUtils = require("../../protocol/node_modules/node-pty-prebuilt/lib/utils") as typeof import("../../protocol/node_modules/node-pty-prebuilt/src/utils");
4344
// tslint:disable-next-line:no-any
4445
// nodePtyUtils.loadNative = (modName: string): any => {
4546
// return (typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require)(path.join(dataDirectory, "dependencies", modName + ".node"));
4647
// };
4748
(<any>global).RIPGREP_LOCATION = path.join(dataDirectory, "dependencies", "rg");
49+
// tslint:disable-next-line:no-any
4850
(<any>global).NODEPTY_LOCATION = path.join(dataDirectory, "dependencies", "pty.node");
4951
// tslint:disable-next-line:no-any
5052
(<any>global).SPDLOG_LOCATION = path.join(dataDirectory, "dependencies", "spdlog.node");
53+
// tslint:disable-next-line:no-any
54+
(<any>global).ONIG_LOCATION = path.join(dataDirectory, "dependencies", "onig_scanner.node");
5155
// tslint:disable-next-line:no-unused-expression
5256
require("../../protocol/node_modules/node-pty-prebuilt/lib/index") as typeof import("../../protocol/node_modules/node-pty-prebuilt/src/index");
5357
};

packages/server/src/vscode/bootstrapFork.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,34 @@ export const requireModule = (modulePath: string, dataDir: string, builtInExtens
7979
(global as any).XMLHttpRequest = xml.XMLHttpRequest;
8080

8181
const mod = require("module") as typeof import("module");
82+
83+
/**
84+
* A list of native packages that could be expected to
85+
* exist in the unpacked version of VS Code. This list may
86+
* grow in the future.
87+
*/
88+
// tslint:disable-next-line:no-any
89+
const nativeModules: ReadonlyArray<{ id: string, module: any }> = [
90+
{ id: "vscode-textmate", module: require("../../../../lib/vscode/node_modules/vscode-textmate") as typeof import("../../../../lib/vscode/node_modules/vscode-textmate") },
91+
];
92+
const oldRequire = mod.prototype.require;
93+
// tslint:disable-next-line:no-any
94+
mod.prototype.require = function (id: string): any {
95+
if (id.slice(0, 3) === "/./") {
96+
for (let i = 0; i < nativeModules.length; i++) {
97+
if (id.slice(-1 * (nativeModules[i].id.length + 1)) !== `/${nativeModules[i].id}`) {
98+
continue;
99+
}
100+
101+
return nativeModules[i].module;
102+
}
103+
throw new Error(`Module '${id}' undefined. If you need this native module, file an issue on GitHub.`);
104+
}
105+
106+
// tslint:disable-next-line:no-any
107+
return oldRequire.call(this, id as any);
108+
};
109+
82110
const promiseFinally = require("promise.prototype.finally") as { shim: () => void };
83111
promiseFinally.shim();
84112
/**

packages/server/webpack.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ module.exports = merge(
88
require(path.join(root, "scripts/webpack.node.config.js"))({
99
// Config options.
1010
}), {
11+
module: {
12+
rules: [{
13+
test: /oniguruma(\\|\/)src(\\|\/).*\.js/,
14+
loader: "string-replace-loader",
15+
options: {
16+
multiple: [{
17+
search: "const Onig(.*) = .*onig_scanner\.node.*\.(.*)",
18+
replace: "const Onig$1 = __non_webpack_require__(global.ONIG_LOCATION).$2;",
19+
flags: "g",
20+
}],
21+
},
22+
}],
23+
},
1124
output: {
1225
filename: "cli.js",
1326
path: path.join(__dirname, "out"),

0 commit comments

Comments
 (0)