Closed lgeiger closed 7 years ago
Hi Lukas!
Since you're only interested in lib/kernel.js
, there is no need to install IJavascript; jp-kernel
is enough. Something like this should work:
var Kernel = require("jp-kernel");
var config = {
cwd: process.cwd(),
hideUndefined: true,
protocolVersion: "5.0",
connection: JSON.parse(fs.readFileSync("path/to/connnection_file.json")),
startupCallback: function() {
// Callback invoked at session startup.
// This callback can be used to setup a session; e.g. to register a require extensions.
console.log("startupCallback:", this.startupCallback);
},
};
// Start kernel
var kernel = new Kernel(config);
@lgeiger I had I quick look at https://github.com/nteract/nteract/pull/1339 and I understand your need for this PR, but I don't want to hack the path to the kernel launcher as the package.json
main. Becuase, although this would make require.resolve("ijavascript")
, it wouldn't make require("ijavascript")
work.
I think nteract
should distribute a customised launcher for IJavascript (I say customised, because I think for nteract
it makes more sense to hide undefined results). Below is an example of what this launcher could look like:
var Kernel = require("jp-kernel");
var config = {
cwd: process.cwd(),
hideUndefined: true,
protocolVersion: "5.0",
connection: JSON.parse(fs.readFileSync("path/to/connnection_file.json")),
startupCallback: function() {
// Callback invoked at session startup.
// This callback can be used to setup a session; e.g. to register a require extensions.
console.log("startupCallback:", this.startupCallback);
},
};
// Start kernel
var kernel = new Kernel(config);
// Interpret a SIGINT signal as a request to interrupt the kernel
process.on("SIGINT", function() {
log("Interrupting kernel");
kernel.restart(); // TODO(NR) Implement kernel interruption
});
We can make it work with https://github.com/n-riesco/ijavascript/commit/302421dbf3cf36e7e42b54d0ed694a7723239cc7 for now 👍
But you're right, in the long term we should probably use a customized node kernel.
We want to ship a bundled version of
ijavascript
withnteract
using Node.js from Electron: https://github.com/nteract/nteract/pull/1339This will allow us to use
require.resolve('ijavascript')
to obtain the file path. Otherwise the require call will fail because no main file is specified.