npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fixturify-project

v7.1.3

Published

[![npm version](https://badge.fury.io/js/fixturify-project.svg)](https://badge.fury.io/js/fixturify-project) [![CI](https://github.com/stefanpenner/node-fixturify-project/workflows/CI/badge.svg)](https://github.com/stefanpenner/node-fixturify-project/acti

Downloads

1,864,366

Readme

node-fixturify-project

npm version CI

When implementing JS build tooling it is common to have complete projects as fixture data. Unfortunately fixtures committed to disk can be somewhat hard to maintain and augment.

Basic Usage

npm install --save-dev fixturify-project
const { Project } = require('fixturify-project');
const project = new Project('rsvp', '3.1.4', {
  files: {
    'index.js': 'module.exports = "Hello, World!"',
  },
});

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; // => read or write the set of files further

// if you don't set this, a new temp dir will be made for you when you write()
project.baseDir = 'some/base/dir/';

await project.write();

// after write(), you can read project.baseDir even if you didn't set it
expect(fs.existsSync(join(project.baseDir, 'index.js'))).to.eql(true);

The above example produces the following files (and most importantly the appropriate file contents:

some/base/dir/package.json
some/base/dir/index.js
some/base/dir/node_modules/mocha/package.json
some/base/dir/node_modules/chai/package.json

Nesting Dependencies

addDependency returns another Project instance, so you can nest arbitrarily deep:

const { Project } = require('fixturify-project');

let project = new Project('rsvp');
let a = project.addDependency('a');
let b = a.addDependency('b');
let c = b.addDependency('c');

await project.write();

Which produces:

$TMPDIR/xxx/package.json
$TMPDIR/xxx/index.js
$TMPDIR/xxx/node_modules/a/package.json
$TMPDIR/xxx/node_modules/a/node_modules/b/package.json
$TMPDIR/xxx/node_modules/b/node_modules/b/node_modules/c/package.json

Linking to real dependencies

Instead of creating all packages from scratch, you can link to real preexisting packages. This lets you take a real working package and modify it and its dependencies and watch how it behaves.

const { Project } = require('fixturify-project');

let project = new Project();
let a = project.addDependency('a');

// explicit target
project.linkDependency('b', { target: '/example/b' });

// this will follow node resolution rules to lookup "c" from "../elsewhere"
project.linkDependency('c', { baseDir: '/example' });

// this will follow node resolution rules to lookup "my-aliased-name" from "../elsewhere"
project.linkDependency('d', { baseDir: '/example', resolveName: 'my-aliased-name' });

await project.write();

Produces:

$TMPDIR/xxx/package.json
$TMPDIR/xxx/index.js
$TMPDIR/xxx/node_modules/a/package.json
$TMPDIR/xxx/node_modules/a/node_modules/b -> /example/b
$TMPDIR/xxx/node_modules/b/node_modules/c -> /example/node_modules/c
$TMPDIR/xxx/node_modules/b/node_modules/d -> /example/node_modules/my-aliased-name

When constructing a whole Project from a directory, you can choose to link all dependencies instead of copying them in as Projects:

let project = Project.fromDir('./sample-project', { linkDeps: true });
project.files['extra.js'] = '// stuff';
await project.write();

This will generate a new copy of sample-project, with symlinks to all its original dependencies, but with "extra.js" added.

By default, linkDeps will only link up dependencies (which is appropriate for libraries). If you want to also include devDependencies (which is appropriate for apps) you can use linkDevDeps instead.

API

Project

Kind: global class

project.baseDir

Kind: instance property of Project

| Param | Description | | --- | --- | | dir | The directory path. |

project.baseDir

Kind: instance property of Project Read only: true

project.name : string

Kind: instance property of Project

project.name

Kind: instance property of Project

project.version : string

Kind: instance property of Project

project.version

Kind: instance property of Project

project.mergeFiles(dirJSON)

Kind: instance method of Project

| Param | Description | | --- | --- | | dirJSON | An object containing a directory representation to merge. |

project.write(dirJSON?)

Kind: instance method of Project

| Param | Description | | --- | --- | | dirJSON? | An optional object containing a directory representation to write. |

project.addDependency() ⇒

Kind: instance method of Project Returns:

project.addDevDependency() ⇒

Kind: instance method of Project Returns:

project.removeDependency(name)

Kind: instance method of Project

| Param | Description | | --- | --- | | name | The name of the dependency to remove. |

project.removeDevDependency(name)

Kind: instance method of Project

| Param | Description | | --- | --- | | name | The name of the devDependency to remove. |

project.linkDependency(name)

Kind: instance method of Project

| Param | Description | | --- | --- | | name | The name of the dependency to link. |

project.linkDevDependency(name)

Kind: instance method of Project

| Param | Description | | --- | --- | | name | The name of the dependency to link. |

project.dependencyProjects() ⇒

Kind: instance method of Project Returns:

project.devDependencyProjects() ⇒

Kind: instance method of Project Returns:

project.clone() ⇒

Kind: instance method of Project Returns:

project.dispose()

Kind: instance method of Project

Project.fromDir(baseDir, opts) ⇒

Kind: static method of Project Returns:

| Param | Description | | --- | --- | | baseDir | The base directory to read the project from. | | opts | An options object. | | opts.linkDeps | Include linking dependencies from the Project's node_modules. | | opts.linkDevDeps | Include linking devDependencies from the Project's node_modules. |