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

@nyce/config

v4.1.3

Published

Common configuration files used across projects.

Downloads

427

Readme

@nyce/config

https://www.npmjs.com/package/@nyce/config

Common and very opinionated configuration files for use across various projects. Import only what you need, extend to fill any gaps and keep some of that valuable time to focus on your code.

If you prefer a vanilla JavaScript/TypeScript experience, this probably isn't for you.

Installation

npm install @nyce/config

Requirements

The configuration files assume the following is enabled:

Add the following entry to (the top of) your package.json file to use the Ecmascript Module Loader on your project files:

{
    "type": "module"
}

Optional but recommended: Run NodeJS with the --experimental-specifier-resolution=node flag forimports without specific file extensions:

node --experimental-specifier-resolution=node dist/<YOUR-FILE-NAME-HERE>.js

Make sure to replace <YOUR-FILE-NAME-HERE>.js with the file you want to run.

Usage

TSconfig

Create a file in your project root called tsconfig.json and extend from the NYCE config.

{
    "extends": "@nyce/config/tsconfig.json",
    "compilerOptions": {
        "baseUrl": "src"
    },
    "include": ["src"]
}

SWC compiler

Unlike TSC, SWC doesn't support config extension yet. ~~For now, you can load the config file with an absolute path to node_modules~~.

~~Alternatively you could (automatically) copy the file over to your project.~~

UPDATE: In latest versions of SWC loading to an absolute NODE_MODULES path breaks the base url.

...Updated the section below to provide a working solution until SWC supports extending configuration files.

SHX is now a peerdependency, so make sure to install that with bash

Add the following NPM scripts to copy the config post-install

Replace pnpm with npm in the postinstall script if you use npm instead of pnpm.

{
    "postinstall": "pnpm copy-swc-config",
    "copy-swc-config": "shx cp node_modules/@nyce/config/.swcrc .swcrc",
    "build": "npx swc --config-file .swcrc ./src -d dist"
}

NPM build script:

{
    "build": "npx swc --config-file node_modules/@nyce/config/.swcrc ./src -d dist"
}

NPM start script:

{
    "start": "node --experimental-specifier-resolution=node dist/<YOUR-FILE-NAME-HERE>.js"
}

Make sure to replace <YOUR-FILE-NAME-HERE>.js with the file you want to run.

jest

Create a file in your project root called jest.config.ts with the following contents:

import type { Config } from "@jest/types";
import { pathsToModuleNameMapper } from "ts-jest";

export default async (): Promise<Config.InitialOptions> => {
    const { compilerOptions } = await require("@nyce/config/tsconfig.json");
    const nyceBaseOptions: Config.InitialOptions = await require("@nyce/config/jest.cjs");

    return {
        ...nyceBaseOptions,
        moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/src/" }) ?? {},
    };
};

NPM test script:

{
    "test": "NODE_OPTIONS=--experimental-vm-modules npx jest --coverage"
}

Prettier and ESlint (package.json)

ESLINT forces you to use a prefix on your WHOLE DAMN NPM PACKAGE (seriously?!).

We serve multiple configuration files in this package so prefixing it with eslint-config- would be confusing. The ESlint configuration can be imported by using an absolute path.

{
    "prettier": "@nyce/config/prettier",
    "eslintConfig": {
        "extends": "./node_modules/@nyce/config/eslint"
    }
}

NPM lint and format scripts:

{
    "lint": "eslint './src/**/*.ts' --ext .ts",
    "lint:fix": "eslint './src/**/*.ts' --ext .ts --fix",
    "format": "prettier --loglevel=warn --write src"
}

Nodemon (package.json)

Run Nodemon with a --config parameter pointing to this packages' nodemon.json file and specify a file to watch:

npx nodemon --config node_modules/@nyce/config/nodemon.json src/<YOUR-FILE-NAME-HERE>.ts"

Make sure to replace <YOUR-FILE-NAME-HERE>.ts with the file you want to watch.

NPM watch script:

{
    "watch": "npx nodemon --config node_modules/@nyce/config/nodemon.json src/<YOUR-FILE-NAME-HERE>.ts"
}

Make sure to replace <YOUR-FILE-NAME-HERE>.ts with the file you want to watch.