A complementary project to fixturify
When implementing JS build tooling it is common to have complete projects as fixture data. Unfortunately fixtures committed to disk can be somewhat to maintain and augment.
The fixturify library is a great way to co-locate tests and their file system fixture information. This project embraces fixturify, but aims to reduce the verbosity when building graphs of node modules and dependencies.
yarn add fixturify-project
const Project = require('fixturify-project');
const project = new Project('rsvp', '3.1.4');
project.addDependency('mocha', '5.2.0');
project.addDependency('chai', '5.2.0');
project.pkg // => the contents of package.json for the given project
project.files['index.js'] = 'module.exports = "Hello, World!"';
project.writeSync('some/root/');
Which the following files (and most importantly the appropriate file contents:
some/root/rsvp/package.json
some/root/rsvp/index.js
some/root/rsvp/node_modules/mocha/package.json
some/root/rsvp/node_modules/chai/package.json
One can also produce JSON, which can be used directly by fixturify:
// continued from above
const fixturify = require('fixturify');
fixturify.writeSync('some/other/root', project.toJSON());
Obviously nested dependencies are common, and are not only supported but somewhat ergonomic:
const Project = require('fixturify-project');
const project = new Project('rsvp', '3.1.4');
// version 1
project.addDependency('a', '1.2.3', a => a.addDependency('d', '3.2.1'));
// version 2
let b = project.addDependency('b', '3.2.3');
let c = b.addDependency('c', '4.4.4');
// and this works recursively:
let e = c.addDependency('e', '5.4.4');
project.writeSync('some/root/');
Which produces:
some/root/rsvp/package.json
some/root/rsvp/index.js
some/root/rsvp/node_modules/a/package.json
some/root/rsvp/node_modules/a/node_modules/d/package.json
some/root/rsvp/node_modules/b/package.json
some/root/rsvp/node_modules/b/node_modules/c/package.json
some/root/rsvp/node_modules/b/node_modules/c/node_modules/e/package.json
Project.fromJSON(json, name)
consume a given project from JSONProject.fromDir(pathToProject)
consume a given project from disk, infer name and version from the existing package.json`Project.fromDir(root, name)
consume a given project from disk, assuming it has been written to byProject.prototype.writeSync(root)
;Project.prototype.root
the path thatProject.prototype.writeSync
will write to by default, if not specified as constructor argument will default to a temp directoryProject.prototype.pkg
the projectspackage.json
represented as an in-memory POJO.Project.prototype.files
a POJO (in the format offixturify
) representing the files within the project rootProject.prototype.clone()
deep clone a given projectProject.prototype.readSync(root)
assumes the state of the given root (symmetrical toProject.prototype.writeSync(root)
)Project.prototype.writeSync(root)
writes the project to disk atroot
Project.prototype.addDependency(name, version)
add a dependency to the given projectProject.prototype.addDevDependency(name, version)
add a devDependency to the given projectProject.prototype.dispose()
immediately delete the given projects tmp directories. If left not invoked, these files will be deleted when the process exists.