Skip to content

brionmario/oss

Repository files navigation

Brion Marios's memoji

Brion Mario's logo 's OSS Configs

Shareable configurations to maintain consistency across
my opensource projects.

License

☢️ Disclaimer: The configurations provided here are tailored to my individual coding style and workflow. They are based on my own experiences, preferences, and opinions about best practices in software development. However, please note that coding standards and best practices evolve over time, and as such, these configurations may be subject to frequent updates and changes. Users are encouraged to review and adapt these configurations according to their own requirements and preferences.

Table of Contents

Creating a GitHub repository

Create a new repository from the GitHub UI or the gh CLI. Make it empty

Tip

Initialize it as an empty repository to make it easier for mono-repo management tools and to make consistent commit messages.

.gitignore

Use the .gitignore files that come with the monorepo management tools or boilerplates, or use one of the relevant ones from .gitignore folder.

Tip

Most .gitignore files generated by boilerplates doesn't exclude some files like MacOS .DS_Store, etc. Hence, I maintain a list of such common cases and append them to the generated ignore files if they doesn't include.

Setup a npm Client

pnpm

I use pnpm as my preferred npm client. It's fast and it saves disk space by using a single storage for all packages across projects.

Refer to the pnpm docs for installation instructions.

Repo Management

Turborepo

These days, I use turborepo as my go-to tool for managing monorepos. It's fast, easy to use, and has a great CLI.

Creating a new monorepo

pnpm dlx create-turbo@latest
  • Answer with . for Where would you like to create your turborepo? . to initialize the repository from the root.

  • Answer with pnpm workspaces for Which package manager do you want to use?.

Important

Refer to the turborepo docs for installation instructions since the above instructions are subject to change.

Code Linting & Formatting

EditorConfig

EditorConfig helps maintain consistent coding styles across various editors and IDEs.

For monorepo root

Use the following .editorconfig file at the root of the mono-repo.

For nested packages

For nested packages, you can use a separate .editorconfig file tailored to the specific requirements of that package or just inherit the root ..editorconfig as shown in the following example configuration:

ESLint

Warning

To use ESLint effectively, ensure you have it installed in your IDE or code editor. You can install ESLint via your editor's extension marketplace or by following the instructions on the ESLint website.

I've written my own ESLint plugin and it's available on npm as @brionmario/eslint-plugin.

Install

Installation can be done using the following command:

pnpm add -D eslint @brionmario/eslint-plugin

Add npm scripts

Add the following npm script to run eslint on common files. (You may skip this if the monorepo management tool or the boilerplate adds their own script.)

"lint": "eslint . --ext .js,.jsx,.ts,.tsx",

Add config file

For monorepo root

Add the following .eslintrc.cjs file at the mono-repo root.

Add Ignore file

For monorepo root

Add the following .eslintignore file at the mono-repo root.

Prettier

Warning

Before using Prettier, make sure to install the Prettier plugin for your code editor. This ensures consistent code formatting across your project and enhances collaboration.

I've a custom prettier config that I use for all my projects. It's available on npm as @brionmario/prettier-config.

Install

Installation can be done using the following command:

pnpm add -D prettier @brionmario/prettier-config

Add npm scripts

Add the following npm script to run prettier. (You may skip this if the monorepo management tool or the boilerplate adds their own script.)

"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css,json,md,mdx}\""

Add config file

For monorepo root

Add the following prettier.config.cjs file at the mono-repo root.

Add Ignore file

For monorepo root

Add the following .prettierignore file at the mono-repo root.

For Node.js

Add the following .prettierignore file at the root of the Node.js based package.

Versioning & Releases

This section provides information on how to manage versioning and releases with my preferred toolchains.

Changesets

I've been loving Changesets for release and versioning recently.

Install

Installation can be done using the following command:

pnpm add -D @changesets/cli

Initialize

To initialize Changesets:

npx changeset init

Configure GitHub flavored changelogs

Install @changesets/changelog-github plugin for GitHub flavored Changelog generation.

pnpm add -D @changesets/changelog-github

Add npm scripts

Add the following two npm scripts.

"publish:packages": "changeset publish",
"version:packages": "changeset version && pnpm install --lockfile-only"

Update the default .changeset/config.json

Replace the default .changeset/config.json file with this config file and adjust the configurations accordingly removing the comments.

Static Analysis

Typescript

To ensure consistent TypeScript configuration across the repository, use the following base configuration file:

Install

Installation can be done using the following command:

pnpm add -D typescript

For monorepo root

For the monorepo root, use the following tsconfig.base.json. This file simplifies configuration by setting up paths for easy navigation to the source code of your packages.

For Node.js

For Node.js based packages, use the following tsconfig.json files.

For React

For React based packages, use the following tsconfig.json files.

Bundling

Rollup

Install

Installation of the main rollup package can be done using the following command:

pnpm add -D rollup

For Node.js

Install
pnpm add -D @rollup/plugin-commonjs @rollup/plugin-node-resolve @rollup/plugin-typescript rollup-plugin-dts rollup-plugin-peer-deps-external rollup-plugin-terser @rollup/plugin-terser rollup-plugin-preserve-directives
Add Rollup Config

Use the following rollup.config.js configuration for bundling Node.js based projects.

rollup.config.js

If you prefer to use JavaScript for the configuration, use the following rollup.config.js configuration.

rollup.config.ts

If you prefer to use TypeScript for the configuration, use the following rollup.config.ts configuration and install the relevant types.

pnpm add -D @types/node

Important

Rollup throws and error when the const declarations have a type in the config file. Hence, I've used suppressed the @typescript-eslint/typedef rule for the config file.

For React

Install
pnpm add -D @rollup/plugin-commonjs @rollup/plugin-node-resolve @rollup/plugin-typescript rollup-plugin-dts rollup-plugin-peer-deps-external rollup-plugin-terser @rollup/plugin-terser rollup-plugin-preserve-directives
Add Rollup Config

Use the following Rollup configurations for bundling React based projects.

rollup.config.ts

If you prefer to use TypeScript for the configuration, use the following rollup.config.ts configuration and install the relevant types.

pnpm add -D @types/node

Important

Rollup throws and error when the const declarations have a type in the config file. Hence, I've used suppressed the @typescript-eslint/typedef rule for the config file.

Testing

Jest

Add Jest Config

Use the following configurations for Jest.

jest.config.ts

If you prefer to use TypeScript for the configuration, use the following jest.config.ts configuration and install the relevant types.

pnpm add -D ts-jest ts-node @jest/types @types/jest @types/node

Install jest to use Jest for unit testing.

pnpm add -D jest

Use the following jest.config.js configuration for unit testing pure JavaScript projects.

jest.config.ts

Install ts-jest and @jest/types to use TypeScript in Jest configuration.

pnpm add -D ts-jest ts-node @jest/types @types/jest @types/node

Use the following jest.config.ts configuration for unit testing pure JavaScript projects.

Add tsconfig.spec.json file

Use the following tsconfig.spec.json configuration for unit testing pure JavaScript projects.

Add npm scripts

Add the following npm script to run tests. (You may skip this if the monorepo management tool or the boilerplate adds their own script.)

    "test": "pnpm jest --passWithNoTests"
Setup test files

Add the following setup-test.ts file to the root directory of the package.

For React projects

Install React Testing Library
pnpm add -D @testing-library/react @testing-library/dom @types/react @types/react-dom jest-environment-jsdom

About

Reusable files/folders that are commonly used in OSS projects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published