gadicc:package-json

v1.0.4Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

meteor-package-json

A helper for Meteor build plugin authors (for now) who need info from the apps package.json. Watches the file and has a callback for your package to accept changes to it's relevant section, otherwise quits Meteor asking for the user to restart.

Quick Start

For the examples below, assume we are developing john:doe and have the following package.json:

1{
2  "john:doe": {
3    "experimental": false
4  }
5}

Simple Fetch

1const config = packageJson.getPackageConfig('john:doe');
2expect(config).to.deep.equal({ experimental: true });

If the john:doe section is modified, Meteor will exit. If any other part of the file is modified, nothing happens. But it's even better if you can accept the changes to avoid a restart.

Accepting Changes

1// The callback below is only ever called if prev does not deep equal next
2const config = packageJson.getPackageConfig('john:doe', (prev, next) => {
3  if (prev.experimental !== next.experiemnetal) {
4    enableExperimentalFeatures(next.experimental);
5  }
6
7  // We can accept this change; no need to restart Meteor.
8  return true;
9});
10
11// On initial load
12if (config.experimental)
13  enableExperimentalFeatures(true);

API

  • packageJson.getPackageConfig('sectionName', [acceptHandler]);

    • Returns the sectionName property from package.json.
    • If the properties in sectionName have changed (are not deeply equal), then, Meteor will quite if no acceptHandler is given, or if acceptHandler(prevSection, newSection) does not return true.
    • For both the initial return and acceptHandler, if the section is undefined, an empty object ({}) will be returned, so no need to test for this in your code.

Development && testing

npm test or with Wallaby.js.