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

@wrhs/extract-config

v1.0.0

Published

Extract warehouse.ai configuration from a given unpacked directory

Downloads

5

Readme

@wrhs/extract-config

Version npm npm Downloads Build Status Dependencies

Extracts warehouse.ai configuration from a given unpacked directory

Installation

npm install --save @wrhs/extract-config

Usage

const extract = require('@wrhs/extract-config');
const path = require('path');
const unpackedRepo = path.join('path', 'to', 'repo');

const config = await extract(unpackedRepo);

What is in config?

At most, the config will provide the following information:

{
  pkg: {
    // the entire contents of the repo's package.json
  },
  wrhs: {
    // Whether or not to perform a webpack build for this package, or if
    // we can just use the source of this directory as-is.
    //
    // Optional (default: none)
    build: 'webpack',

    // Different locales in which to build the package, this is helpful for
    // parallelizing builds for any number of locales.
    //
    // Optional (default: [])
    locales: [
      'en-US',
      'es-CO',
      'de-DE',
      'zh-CN'
    ],

    // What recommended files to use in each environment
    files: {
      dev: [
        'dist/output.css',
        'dist/output.js'
      ],
      test: [
        'dist/output.min.css',
        'dist/output.min.js'
      ],
      prod: [
        'dist/output.min.css',
        'dist/output.min.js'
      ]
    },

    // Minification options to apply to the output code
    minify: {
      compress: {
        unsafe: true,
        dead_code: true,
        collapse_vars: true,
        drop_console: true,
        conditionals: true,
        booleans: true,
        unused: true,
        if_return: true,
        join_vars: true
      }
    }
  }
}

Allowed files

@wrhs/extract-config will recognize the following configuration files and formats.

.wrhsrc

This is a simple json file that contains information in the above format

{
  "build": "webpack",
  "locales": [
    "C",
    "C++",
    "ArnoldC"
  ]
}

package.json

Similar to .wrhsrc you can place these values into either the base level of your package.json, or into a wrhs object (we will merge the base level into the wrhs object if any)

{
  "name": "my-cool-package",
  "version": "1.2.3",
  "wrhs": {
    "build": "webpack",
    "locales": [
      "en-US",
      "es-CO",
      "de-DE"
    ],
    "files": {
      "test": ["dist/output.js", "dist/output.css"],
      "prod": ["dist/output.min.js", "dist/output.min.css"]
    }
  }
}

wrhs.toml

[files]
dev = ['output.js', 'output.css']
test = ['output.min.js', 'output.min.css']
prod = ['output.min.js', 'output.min.css']

build = 'webpack'

locales = [
  'English',
  'Sindarin',
  'Klingon',
  'Dothraki'
]

[minify]
[minify.compress]
unsafe = true
dead_code = true
unsafe = true
dead_code = true
collapse_vars = true
drop_console = true
conditionals = true
booleans = true
unused = true
if_return = true
join_vars = true

Order of configuration precedence

They are listed in order above, but we will resolve potentially conflicting information based on this precedence:

  1. .wrhsrc
  2. package.json
  3. wrhs.toml

Any configuration from earlier in the list will override identically named configuration later in the list. For example, I have these 2 files present:

.wrhsrc

{
  "build" :"webpack",
  "locales": [
    "Earth", "Mars"
  ]
}

wrhs.toml

locales=['Krypton', 'Oa']

[files]
test = ['output.css']
prod = ['output.min.css']

The final configuration object will be:

{
  build: 'webpack',
  locales: [
    'Earth', 'Mars'
  ],
  files: {
    test: ['output.css']
    prod: ['output.min.css']
  }
}

It's important to note that nested lists and objects will not be merged, just overridden.

We highly recommended keeping all of your configuration in one single location, but to support legacy formats, we allow multiple points of entry.

Testing

npm test