n-riesco / ijavascript

IJavascript is a javascript kernel for the Jupyter notebook
Other
2.18k stars 187 forks source link

Add missing main file to package.json #92

Closed lgeiger closed 7 years ago

lgeiger commented 7 years ago

We want to ship a bundled version of ijavascript with nteract using Node.js from Electron: https://github.com/nteract/nteract/pull/1339

This 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.

n-riesco commented 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);
n-riesco commented 7 years ago

@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
});
lgeiger commented 7 years ago

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.