-
Notifications
You must be signed in to change notification settings - Fork 95
/
postInstall.js
64 lines (61 loc) · 2.12 KB
/
postInstall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copied from https://github.com/microsoft/vscode-jupyter/blob/main/build/ci/postInstall.js
const fs = require("fs");
const { downloadZMQ } = require("@vscode/zeromq");
const path = require("path");
/**
* In order to get raw kernels working, we reuse the default kernel that jupyterlab ships.
* However it expects to be talking to a websocket which is serializing the messages to strings.
* Our raw kernel is not a web socket and needs to do its own serialization. To do so, we make a copy
* of the default kernel with the serialization stripped out. This is simpler than making a copy of the module
* at runtime.
*/
function createJupyterKernelWithoutSerialization() {
var relativePath = path.join(
"node_modules",
"@jupyterlab",
"services",
"lib",
"kernel",
"default.js",
);
var filePath = path.join("", relativePath);
if (!fs.existsSync(filePath)) {
throw new Error(
"Jupyter lab default kernel not found '" +
filePath +
"' (Jupyter Extension post install script)",
);
}
var fileContents = fs.readFileSync(filePath, { encoding: "utf8" });
var replacedContents = fileContents
.replace(
/^const serialize =.*$/gm,
"const serialize = { serialize: (a) => a, deserialize: (a) => a };",
)
.replace(
"const owned = team.session === this.clientId;",
"const owned = parentHeader.session === this.clientId;",
);
if (replacedContents === fileContents) {
throw new Error(
"Jupyter lab default kernel cannot be made non serializing",
);
}
var destPath = path.join(path.dirname(filePath), "nonSerializingKernel.js");
fs.writeFileSync(destPath, replacedContents);
console.log(destPath + " file generated (by Jupyter VSC)");
}
async function downloadZmqBinaries() {
// if (common.getBundleConfiguration() === common.bundleConfiguration.web) {
// // No need to download zmq binaries for web.
// return;
// }
await downloadZMQ();
}
createJupyterKernelWithoutSerialization();
downloadZmqBinaries()
.then(() => process.exit(0))
.catch((ex) => {
console.error("Failed to download ZMQ", ex);
process.exit(1);
});