-
Notifications
You must be signed in to change notification settings - Fork 80
Modules
anode contains basic support for modules, whereby modules of different flavours can be installed and uninstalled via an intent API.
Note that the functionality provided, at present, is not comparable to npm
. Module packages are not processed by npm
, and therefore install-time scripts are not run, and any binaries included in a module are not processed. Furthermore, there is no version awareness or dependency awareness. In short, the functionality provided does not amount to a package manager, but is simply a convenience to be able to simply add and remove module packages in various formats, and allow them to be installed into anode's private filesystem area without root privileges.
A port of npm
is being investigated, and will hopefully appear in a forthcoming version of anode. However, even when this does happen, there will inevitably be limitations in functionality - local module repositories would be unlikely to be supported, for example.
anode currently supports the following module types:
-
pure JS, presented in a package or as a single standalone script with a
.js
extension; -
native addons with a
.node
extension.
anode supports installation via a few different package formats:
-
a directory containing a tree of files (eg on the storage card);
-
zip archives with a
.zip
extension; -
compressed tar archives with a
.tar.gz
or.tgz
extension.
anode installs packages into the /data/data/org.meshpoint.anode/node_modules/
directory. Inside this directory, each module is installed either as a standalone file with appropriate extension (if presented as a standalone addon or js file) or as a directory, with the module contents unpacked beneath that directory. This matches the layout expected by node itself.
On a rooted device it is possible to copy files and directories into this location to manage this space by hand; however, on a non-rooted phone this isn't possible so it is necessary to use anode's API.
An intent-based API is provided, with two actions:
-
org.meshpoint.anode.INSTALL
with extraspath
(mandatory, path to the module resource or package) andmodule
(optional, module name to use to install). If the module name is not specified, it is guessed from thepath
. Thepath
specifier may be a fully qualified path to a file or directory, or may be anhttp
orhttps
URI. If it is a URI, anode will download a standalone module file (JS or addon) or a module package from that location. Direct download of a directory tree from a remote location is not supported; use a supported package type instead. -
org.meshpoint.anode.UNINSTALL
with extramodule
argument to specify the module to be removed. The module argument must be the module identifier, and not the filename - eghello
instead ofhello.js
orhello.node
.
So, to install the addon that is in the file /data/tmp/hello.node
, use the command:
adb shell am broadcast -a org.meshpoint.anode.INSTALL -e path /data/tmp/hello.node
To install the packaged module that is online at http://mymodules.com/hello.tgz
use the command:
adb shell am broadcast -a org.meshpoint.anode.INSTALL -e path http://mymodules.com/hello.tgz
To uninstall either of these modules, use the command:
adb shell am broadcast -a org.meshpoint.anode.UNINSTALL -e module hello