Skip to content
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

Document technique for manually managing NPM dependencies #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Check out some cool examples below! Try them on Gitpod! Click the Open in Gitpod

Unlike other bridges, you may notice you're not just writing Python code in JavaScript, or vice-versa. You can operate on objects
on the other side of the bridge as if the objects existed on your side. This is achieved through real interop support: you can call
callbacks, and do loss-less function calls with any arguments you like (with the exception of floating points percision of course).
callbacks, and do loss-less function calls with any arguments you like (with the exception of floating points precision of course).

| | python(ia) bridge | javascript bridge | [npm:python-bridge](https://www.npmjs.com/package/python-bridge) |
|---|---|---|---|
Expand Down Expand Up @@ -118,7 +118,7 @@ or location of the file to import. Internally, this calls the ES6 dynamic `impor
supports both CommonJS and ES6 modules.

If you are passing a module name (does not start with / or include a .) such as 'chalk', it will search
for the dependency in the internal node_module folder and if not found, install it automatically.
for the dependency in the internal node_modules folder and if not found, install it automatically.
This install will only happen once, it won't impact startup afterwards.

The second paramater to the built-in require function is the version of the package you want, for
Expand All @@ -127,6 +127,18 @@ if you were using `npm install`. It's reccomended to only use the major version
will be internally treated as a unique package, for example 'chalk--^3'. If you leave this empty,
we will install `latest` version instead, or use the version that may already be installed globally.

If you prefer to not use automatic dependency management, and instead use your own `package.json`/`package-lock.json`/`node_modules`, you can use Node.js's `require` function directly. This will use the packages already installed in a `node_modules` directory of your choice:

```py
import os
# assuming 'node_modules' in same directory as script,
# and has 'chalk' installed
os.environ["NODE_PATH"] = os.path.join(os.path.dirname(__file__), "node_modules")
from javascript import eval_js
require = eval_js("require")
chalk = require("chalk")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a supported feature; it's more of a hack. In which it should not be documented as if it were an intentional and supported feature.

Instead, would need to look at how to properly support this functionality.

```

### Usage

* All function calls to JavaScript are thread synchronous
Expand Down