-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to require("bokehjs") in node.js #5129
Changes from 6 commits
7ac6020
e8576ae
c145921
0c23b32
06defe8
8f10ccf
ff02e0a
35e8f13
1ff935d
4c5c3ec
af8150d
d5c327a
5475770
cca8f21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
path = require "path" | ||
assert = require "assert" | ||
rootRequire = require("root-require") | ||
|
||
root = rootRequire.packpath.parent() | ||
pkg = rootRequire("./package.json") | ||
|
||
module.constructor.prototype.require = (modulePath) -> | ||
assert(modulePath, 'missing path') | ||
assert(typeof modulePath == 'string', 'path must be a string') | ||
|
||
load = (modulePath) => | ||
this.constructor._load(modulePath, this) | ||
|
||
overridePath = pkg.browser[modulePath] | ||
|
||
if overridePath? | ||
modulePath = path.join(root, overridePath) | ||
|
||
return load(modulePath) | ||
|
||
if not (global.window? and global.document?) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to make this work in environments that provide their own web browser-like environment. Note that bokehjs requires |
||
jsdom = require('jsdom').jsdom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Later, if/when someone tries to webpack bokeh (hint: jupyterlab, other web contexts), they're going to have this annoyingly dynamic require to deal with, when they're not reliant on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattpap any comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rgbkrk, to me, being able to repackage bokehjs with webpack and run bokehjs in node.js, are two different targets. There are two reasons bokehjs doesn't work out of the box in node.js. One are module aliases (to Also, trying to repackage bokehjs in a custom way may not be as trivial as just including it in a thridparty webpack build, because some of bokehjs' functionality, like custom models, requires specific javascript bundle's encoding and additional code to be present at runtime. Note that at this point we don't use stock browserify to build bokehjs (we use a custom module labeler), and it's likely we will be using a custom approach to unify bokehjs' and custom model build, and allow for building custom, per plot, bokehjs bundles. However, if you just want to include core bokehjs' functionality, that should be easy though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rgbkrk, do you have a test case on which I could experiment? In the end our build may be too complicated and there might be room for improvement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After initial investigation, this seems to be a lot of work for little gains. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to webpack's documentation, it should be possible to avoid this custom There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, it looks like the only problem I can see right now, is that there there is one |
||
|
||
global.document = jsdom() | ||
global.window = document.defaultView | ||
|
||
for own name, object of global.window | ||
if not global[name]? | ||
global[name] = object | ||
|
||
Bokeh = require './main' | ||
_ = Bokeh._ | ||
|
||
APIs = require './api' | ||
_.extend(Bokeh, _.omit(APIs, "models")) | ||
|
||
Bokeh.require_widgets = () -> | ||
Widgets = require './models/widgets/main' | ||
_.extend(Bokeh, _.omit(Widgets, "models")) | ||
Bokeh.Models.register_locations(Widgets.models) | ||
|
||
module.exports = Bokeh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been done in PR #4946.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I wondered about this when I was installing too.