Skip to content

Commit

Permalink
refactor: update build process, refactor codebase, update eslint rules
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rules have been updated
  • Loading branch information
RebeccaStevens committed Dec 21, 2020
1 parent e487a7d commit 7b5947e
Show file tree
Hide file tree
Showing 36 changed files with 1,207 additions and 929 deletions.
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 100,
"quoteProps": "consistent"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ yarn add -D \
eslint-import-resolver-typescript \
eslint-plugin-jsdoc \
eslint-plugin-markdown \
eslint-plugin-node \
eslint-plugin-optimize-regex \
eslint-plugin-promise \
eslint-plugin-simple-import-sort \
Expand Down
28 changes: 9 additions & 19 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ module.exports = {

// An array of glob patterns indicating a set of files for which coverage
// information should be collected
collectCoverageFrom: ['src/**/*.ts'],
collectCoverageFrom: ["src/**/*.ts"],

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
coverageDirectory: "coverage",

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// '/node_modules/'
// ],

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: [
'text',
'lcov'
],
coverageReporters: ["text", "lcov"],

// An object that configures minimum threshold enforcement for coverage
// results
Expand All @@ -66,9 +63,9 @@ module.exports = {
// A set of global variables that need to be available in all test
// environments
globals: {
'ts-jest': {
tsConfig: 'tsconfig.tests.json'
}
"ts-jest": {
tsConfig: "tsconfig.tests.json",
},
},

// An array of directory names to be searched recursively up from the
Expand All @@ -78,14 +75,7 @@ module.exports = {
// ],

// An array of file extensions your modules use
moduleFileExtensions: [
'js',
'json',
'jsx',
'ts',
'tsx',
'node'
],
moduleFileExtensions: ["js", "json", "jsx", "ts", "tsx", "node"],

// A map from regular expressions to module names that allow to stub out
// resources with a single module
Expand Down Expand Up @@ -146,7 +136,7 @@ module.exports = {
// snapshotSerializers: [],

// The test environment that will be used for testing
testEnvironment: 'node',
testEnvironment: "node",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
Expand Down Expand Up @@ -185,7 +175,7 @@ module.exports = {

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.ts$': 'ts-jest'
"^.+\\.ts$": "ts-jest",
},

// An array of regexp pattern strings that are matched against all source file
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"prebuild": "rimraf dist",
"build": "rollup -c",
"commit": "cz",
"generate-eslintrc": "ts-node -P tsconfig.tools.json scripts/generate-eslintrc.ts",
"generate-eslintrc": "ts-node -P tsconfig.tools.json -r tsconfig-paths/register scripts/generate-eslintrc.ts",
"prelint": "yarn generate-eslintrc",
"lint": "eslint .",
"report-coverage": "codecov -f coverage/lcov.info",
Expand Down Expand Up @@ -63,14 +63,17 @@
"commitizen": "^4.2.2",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.16.0",
"eslint-config-prettier": "^7.1.0",
"eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-jsdoc": "^30.7.9",
"eslint-plugin-markdown": "^1.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-optimize-regex": "^1.2.0",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sonarjs": "^0.5.0",
Expand All @@ -82,9 +85,11 @@
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"rollup": "^2.35.1",
"rollup-plugin-auto-external": "^2.0.0",
"semantic-release": "^17.3.0",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.3"
},
"peerDependencies": {
Expand All @@ -102,5 +107,8 @@
"eslint-plugin-simple-import-sort": "*",
"eslint-plugin-sonarjs": "*",
"eslint-plugin-unicorn": "*"
},
"engines": {
"node": ">=12.0.0"
}
}
7 changes: 7 additions & 0 deletions rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require("ts-node").register({
compilerOptions: {
module: "CommonJS",
},
});

module.exports = require("./rollup.config.ts");
7 changes: 0 additions & 7 deletions rollup.config.js

This file was deleted.

46 changes: 15 additions & 31 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,22 @@
* Rollup Config.
*/

import {
basename,
isAbsolute as isAbsolutePath,
join as joinPaths,
normalize as normalizePath,
} from "path";

import type { RollupOptions } from "rollup";
import rollupPluginCommonjs from "@rollup/plugin-commonjs";
import rollupPluginNodeResolve from "@rollup/plugin-node-resolve";
import rollupPluginTypescript from "@rollup/plugin-typescript";
import path from "path";
import type { RollupOptions } from "rollup";
import rollupPluginAutoExternal from "rollup-plugin-auto-external";

import * as pkg from "./package.json";

const common: Partial<RollupOptions> = {
input: "src/index.ts",

external: (id: string) => {
const localPaths = [".", process.cwd()];
const excludedPaths = ["node_modules"];
const normalId = isAbsolutePath(id) ? normalizePath(id) : id;

return !localPaths.some(
(localPath) =>
// Local file?
normalId.startsWith(localPath) &&
// Not excluded?
!excludedPaths.some((excludePath) =>
normalId.startsWith(joinPaths(localPath, excludePath))
)
);
output: {
dir: "./dist",
sourcemap: false,
exports: "default",
},

treeshake: {
Expand All @@ -41,11 +26,12 @@ const common: Partial<RollupOptions> = {
},
};

const dir = "./dist";
const sourcemap = false;

/**
* Get new instances of all the common plugins.
*/
function getPlugins() {
return [
rollupPluginAutoExternal(),
rollupPluginNodeResolve(),
rollupPluginCommonjs(),
rollupPluginTypescript(),
Expand All @@ -56,10 +42,9 @@ const cjs: RollupOptions = {
...common,

output: {
dir,
entryFileNames: basename(pkg.main),
...common.output,
entryFileNames: path.basename(pkg.main),
format: "cjs",
sourcemap,
},

plugins: getPlugins(),
Expand All @@ -69,10 +54,9 @@ const esm: RollupOptions = {
...common,

output: {
dir,
entryFileNames: basename(pkg.module),
...common.output,
entryFileNames: path.basename(pkg.module),
format: "esm",
sourcemap,
},

plugins: getPlugins(),
Expand Down
5 changes: 0 additions & 5 deletions scripts/.eslintrc

This file was deleted.

45 changes: 35 additions & 10 deletions scripts/generate-eslintrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,52 @@
import { all as deepMerge } from "deepmerge";
import { promises as fs } from "fs";

import libConfig from "../src";
import libConfig from "~";

// Project specific config.
const projectConfig = {
root: true,
parserOptions: {
project: "tsconfig.json",
project: ["tsconfig.json", "tsconfig.eslint.json"],
},
env: {
node: true,
},
rules: {
"no-magic-numbers": "off",
"sonarjs/no-duplicate-string": "off",
"unicorn/prevent-abbreviations": "off",
},
plugins: ["prettier"],
extends: ["plugin:prettier/recommended", "prettier", "prettier/@typescript-eslint"],
overrides: [
{
files: ["*.ts", "*.js"],
files: ["*.{ts,js}"],
rules: {
"functional/immutable-data": "off",
"functional/functional-parameters": "off",
"functional/no-expression-statement": "off",
},
},
{
files: ["scripts/**/*.{ts,js}"],
rules: {
"functional/no-expression-statemen": "off",
"functional/no-throw-statement": "off",
},
},
{
files: ["src/**/*.{ts,js}"],
rules: {
"sonarjs/no-duplicate-string": "off",
},
},
{
files: ["tests/**/*.{ts,js}"],
env: {
jest: true,
},
plugins: ["jest"],
extends: ["plugin:jest/recommended"],
rules: {
"functional/functional-parameters": "off",
"functional/no-expression-statement": "off",
"comma-dangle": "off",
"node/no-sync": "off",
},
},
],
Expand All @@ -34,4 +57,6 @@ const projectConfig = {
const config = deepMerge([libConfig, projectConfig]);

// Write the file.
fs.writeFile(".eslintrc", JSON.stringify(config, undefined, 2));
fs.writeFile(".eslintrc", JSON.stringify(config, undefined, 2)).catch((error) => {
throw error;
});
Loading

0 comments on commit 7b5947e

Please sign in to comment.