4.1.1 • Published 25 days ago

@nyce/config v4.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
25 days ago

@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.

4.1.1

25 days ago

4.0.15

2 months ago

4.0.13

3 months ago

4.0.11

4 months ago

4.0.10

5 months ago

4.0.9

5 months ago

4.0.7

5 months ago

4.0.6

5 months ago

4.0.5

5 months ago

4.0.4

5 months ago

4.0.3

5 months ago

4.0.1

5 months ago

4.0.2

5 months ago

2.2.1

8 months ago

2.2.0

8 months ago

2.1.1

10 months ago

2.2.3

8 months ago

2.2.2

8 months ago

2.2.5

8 months ago

2.1.0

10 months ago

2.0.1

10 months ago

3.2.2

6 months ago

3.3.0

6 months ago

3.2.1

6 months ago

3.2.0

8 months ago

3.1.0

8 months ago

3.3.3

6 months ago

3.3.2

6 months ago

3.0.0

8 months ago

4.0.0

6 months ago

2.0.0

11 months ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago