-
Notifications
You must be signed in to change notification settings - Fork 2
CokeCodes Package System
One of the charming thing of node.js is the package system. To extend system capabilities, CokeCodes also have a package system but there is some differences between CokeCodes and node.js package system:
CokeCodes has a package management command-line tool: pkg. In terminal, use pkg tool to install/uninstall, import/unimport, update and publish packages. In terminal type help pkg to see detailed information.
Some Examples
#install the "rollup" package:
$> pkg install rollup
#import the "nodeshim" package:
$> pkg import nodeshim
#update the "rollup" package:
$> pkg update rollup
In browser, import module path string must starts with "./", "../" or "/". So we can't use package import like:
import path from "path";//ERROR: module path must starts with "./", "../" or "/"In CokeCodes, to import a package, you should use path: "/@[PKGName]":
import CodeMirror from "/@codemirror";//import "codemirror" package's main entry.
import cokeNT from "/@disk/utils.js";//import the "utils.js" in "disk" package.HTML file can also import package files:
...
<script src="/@codemirror/mode/javascript.js"></script>
...The mechanism behind the package path is implemented in the CokeCodes Service-Worker.
node.js has a complex install location system for package. In CokeCodes, to simple and speed up the package search process, we use static install location. CokeCodes packages have two install location option: as a disk or in system lib:
- When a package is installed as a disk it will create a new disk-dir at root path [-PkgName]. This install options is for applications.
- When a package is installed in system lib, it will be installed at `/coke/lib/[PkgName]/' dir
While developing, packages can have a lot of versions, node.js version system cloud be kinda mess when your project depends on several packages and they depends on a same package but with different versions. All these versions will be load into memory. To avoid package overload, CokeCodes package published with tag.
- Several package versions can use same tag if they share exactly same features and APIs.
- When package upgrades with new feature and APIs, it should use a new tag
- If new tag can declare that it is compatible with old tag. So we may redirect the usage of old tag to new compatible tag
- Project imports packages can also include the tag information