This page documents the prerequisites and procedures used during the
development of the xpm
module.
This project is currently written in JavaScript, but a rewrite to TypeScript is planned.
The prerequisites are:
- git
- node >= 14.13.1 (for stable modules)
- npm
The project is hosted on GitHub:
To clone the master
branch, use:
mkdir "${HOME}/Work/node-modules" && cd "${HOME}/Work/node-modules"
git clone https://github.com/xpack/xpm-js.git xpm-js.git
For development, to clone the develop
branch, use:
git clone --branch develop https://github.com/xpack/xpm-js.git xpm-js.git
npm install
To later check for newer dependencies:
npm outdated
Details about dependencies:
- https://www.npmjs.com/package/@ilg/cli-start-options
- https://www.npmjs.com/package/@xpack/xpm-liquid
- https://www.npmjs.com/package/cacache
- https://www.npmjs.com/package/copy-file
- https://www.npmjs.com/package/decompress
- https://www.npmjs.com/package/del
- https://www.npmjs.com/package/is-windows
- https://www.npmjs.com/package/liquidjs
- https://www.npmjs.com/package/mz
- https://www.npmjs.com/package/node-fetch
- https://www.npmjs.com/package/pacote
- https://www.npmjs.com/package/parse-git-config
- https://www.npmjs.com/package/semver
- https://www.npmjs.com/package/tar
- https://www.npmjs.com/package/user-home
The module uses ECMAScript 6 class definitions and modules.
As style, the project uses the JavaScript Standard Style, automatically checked at each commit via CI.
Generally, to fit two editor windows side by side in a screen, all files should limit the line length to 80.
/* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
Known and accepted exceptions:
- none
To manually fix compliance with the style guide (where possible):
$ npm run fix
> [email protected] fix
> standard --fix
The tests use the node-tap
framework
(A Test-Anything-Protocol library for Node.js, written by Isaac Schlueter).
As for any npm
package, the standard way to run the project tests is
via npm test
:
cd xpm-js.git
npm install
npm run test
To run a specific test with more verbose output, use npm run tap
:
npm run tap test/tap/...
Coverage tests are a good indication on how much of the source files is exercised by the tests. Ideally all source files should be covered 100%, for all 4 criteria (statements, branches, functions, lines).
To run the coverage tests, use npm run test-coverage
:
npm run test-coverage
...
Use /* istanbul ignore next <something> */
before the code to be ignored
(https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md).
Fully excluded files:
lib/utils/cmd-shim.js
The continuous integration tests are performed via GitHub Actions.
The tests are currently performed with node 14, 16, 18.
To preserve compatibility with Node 10, use the older version of the documentation:
The documentation metadata follows the JSdoc tags.
To enforce checking at file level, add the following comments right after
the use strict
:
'use strict'
/* eslint valid-jsdoc: "error" */
/* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
Note: be sure C style comments are used, C++ styles are not parsed by ESLint.
There were some problems with cacache & pacote.
- [email protected]: fails to download binaries.
- [email protected]: apparently works, but passing the stream to cacache fails.
The previous known to work versions:
"cacache": "^12.0.2",
"pacote": "^9.4.1",
Note: the cacache version should match the one used inside pacote.
TODO: investigate and update.
xpm is able to create new projects based on templates.
To be accepted as a template, a project must:
- be an xPack (have a
package.json
which includes anxpack
property - have a property called
main
inpackage.json
, pointing to a JavaScript file that can be consumed byawait import()
(formerlyrequire()
) - the main file must export a class called
XpmInitTemplate
- an instances of this class must have a
run()
method. - have all dependencies bundled in (via
bundleDependencies
)
The steps invoked by xpm to initialise a project from a template are:
- call pacote to install the xPack in the global home folder
- identify the
main
property inpackage.json
- import the
XpmInitTemplate
class from the main JavaScript file by invoking require() - instantiate the
XpmInitTemplate
class - execute the
run()
method.
The full code is in init.js
, but a simplified version looks like this:
await pacote.extract(config.template, globalPackagePath,
{ cache: cacheFolderPath })
const mainTemplatePath = path.join(globalPackagePath, globalJson.main)
context.CliError = CliError
context.CliExitCodes = CliExitCodes
const { XpmInitTemplate } = await import(mainTemplatePath)
const xpmInitTemplate = new XpmInitTemplate(context)
const code = await xpmInitTemplate.run()