You can expand your plugin’s functionality by installing dependencies from the npm package repository. You can install new dependencies by defining a package.json file[1] in the same directory as your myst.yml[2], and running npm install.
Here’s an example package.json file that includes the js-yaml package, which is a YAML parser.
{
"dependencies": {
"js-yaml": "^4.1.0"
}
}By running npm install, we see:
$ npm install
added 2 packages, and audited 3 packages in 898ms
found 0 vulnerabilitiesYou can then use the js-yaml package in your plugin code by importing it.
For example, the following JavaScript snippet uses the js-yaml package and the fs package (already built into JavaScript) to load YAML data from a file.
import yaml from "js-yaml";
import fs from "fs";
// Read and parse team data
const someData = yaml.load(fs.readFileSync("data.yml", "utf8"));Note that any plugins will be run from the root of the project, so set your file paths accordingly.
¶
For more information about
package.jsonfiles, see the Node.js documentation and the MDN package documentation.In fact, you can define a new
package.jsonfor each custom plugin, by defining your plugins in their own folders. There is little benefit to doing this, though.