n-riesco / ijavascript

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

Add option to search for package.json and start kernel from that folder #171

Closed slavaGanzin closed 6 years ago

slavaGanzin commented 6 years ago

Hello Nicolas.

I had trouble with relative paths in js using Hydrogen. By default it works well: you almost always have package.json in your atom project folder, so you can use Hydrogen's option to start kernel from there. But if you have nested projects(wich starts from theirs folders) in one project it becomes a harder.

So I write a little bit of a hack:

(function f() {try { require('fs').readFileSync('package.json') } catch(e) {process.chdir('..'); f()}})()

And I think it can be integrated in ijavascript as an option. What do you think?

n-riesco commented 6 years ago

Hi @slavaGanzin (sorry about the late reply).

I feel this kind of functionality belongs to Hydrogen. I've opened issue https://github.com/nteract/hydrogen/issues/1419 to discuss a more general solution that would let users select a working directory when they start a kernel.

n-riesco commented 6 years ago

@slavaGanzin a quick question: at the moment, how do you run your hack? do you use the setting startupCode?

slavaGanzin commented 6 years ago

Yes. You are right:

    startupCode: '''
      {"Python 3": "%matplotlib inline", "Javascript (Node.js)": "(function f() {try { require('fs').readFileSync('package.json') } catch(e) {process.chdir('..'); f()}})()"}      
    '''