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

@bscotch/config

v1.4.5

Published

A library of helper classes for modeling and managing configuration files, including tsconfig.json and package.json files.

Downloads

259

Readme

Config Utilities

Configuration file management can be a pain. This package contains a collection of helpers to make config management easier.

JSON Config Files

In the JavaScript/Typescript ecosystem, most configuration files are stored as JSON files.

ConfigFile base class

This package provides a base ConfigFile base class to make saving, loading, and typing JSON-based configuration files easier.

  • Uses JSON5 for loading, so that your config files can contain comments and other JSON-incompatible features.
  • Can follow "extends" fields.

The following is a sample for how to create a custom config class using this package's base class.

import { ConfigFile, ConfigFileOptions } from '@bscotch/config';

interface MyConfigOptions {
  someValue: string;
  someOtherValue: { hello: number }[];
}

class MyConfigClass extends ConfigFile<MyConfigOptions> {
  constructor(
    options: Omit<ConfigFileOptions<MyConfigOptions>, 'defaultBaseName'>,
  ) {
    super({ defaultBasename: 'my-config.json', ...options });
  }

  async cumulativeOptions() {
    // Get all parsed config data, following
    // "extends" fields, so that you can apply
    // custom resolution logic.
    const chain = await this.inheritenceChain();
    const options = chain.reduce((cumulative, current) => {
      Object.assign(cumulative, current);
      return cumulative;
    }, {});
    return options;
  }
}

// Load a config file (defaults to searching cwd)
const config = new ConfigFile<MyConfig>();
const options = await config.cumulativeOptions();

PackageJson class

This package provides a PackageJson class for working with package.json files. It extends the ConfigFile base class.

  • Bump versions
  • Check for and change dependencies
  • Discover all files that would be included by npm pack
  • Enforce/check publish-ability
  • Supports monorepos
    • Follows dependencies that use the file: protocol.
    • Checks publish-ability based on local dependencies, e.g. if a local dep is private the package is treated as unpublishable.
import { PackageJson } from '@bscotch/config';

// You can extend the PackageJson type with custom
// fields.
interface CustomFields {
  myField: string;
  myOtherField: { hello: number }[];
}

// Find the nearest package.json and load it
// (starts in cwd by default)
const pkg = await PackageJson.findPackageJson<CustomFields>();

// Check for a dependency
const tsDep = pkg.findDependency('typescript');
// -> {version: '^4.7.3', type: 'devDependencies'}

// Bump the version
await pkg.bumpVersion('minor');

TsConfig class

Typescript configuration options are specified with tsconfig.json files. These files are loaded and used by a wide variety of tools, though any given tool may only support a subset of options or config versions.

The TsConfig helper class provides utilities for various features that are useful for managing a Typescript project, mostly for simplifying the creation of tools that operate on Typescript projects.

  • Get cumulative options by following "extends" fields.
  • Find all source files that would be included, even those included via "references".
  • Check if a given path/module is included by a Typescript project, with alias resolution.
import { TsConfig } from '@bscotch/config';

// Find the nearest tsconfig.json file.
const mainConfig = await TsConfig.resolve();

// Get the cumulative config options, resulting
// from recursively following paths in the "extends" field.
const options = await mainConfig.cumulativeConfig();

// Get a list of all `tsconfig`s that are part of this
// project, by recursively following the paths found in
// the "references" field.
const configs = await mainConfig.resolveProjectReferenceTree();