Skip to content

Commit

Permalink
feat: add typescript config
Browse files Browse the repository at this point in the history
  • Loading branch information
StanHannebelle committed Jan 21, 2022
1 parent e8b7d42 commit fccecf3
Show file tree
Hide file tree
Showing 5 changed files with 1,615 additions and 1,551 deletions.
112 changes: 91 additions & 21 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,96 @@
module.exports = {
extends: [
"eslint:recommended",
"plugin:import/recommended",
"plugin:prettier/recommended",
],
rules: {
curly: ["error", "all"],
eqeqeq: ["error", "smart"],
"import/no-duplicates": "off",
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: true,
optionalDependencies: false,
peerDependencies: false,
},
],
"no-shadow": [
"error",
{
hoist: "all",
},
],
"prefer-const": "error",
"sort-imports": [
"error",
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
},
],
"padding-line-between-statements": [
"error",
{
blankLine: "always",
prev: "*",
next: "return",
},
],
complexity: ["error", 8],
"max-lines": ["error", 200],
"max-depth": ["error", 3],
"max-params": ["error", 2],
},

root: true,
plugins: ["import"],
env: {
node: true,
es6: true,
node: true,
},
extends: ["airbnb-base", "prettier"],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
},
plugins: ["prettier"],
rules: {
"prettier/prettier": "error",
quotes: ["error", "double"],
"no-console": "off",
"no-plusplus": "off",
"no-param-reassign": "off",
"no-new": "off",
"import/named": "off",
"import/no-cycle": "off",
},
parserOptions: { ecmaVersion: 2021 },
overrides: [
{
files: ["**/*.ts?(x)"],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/typescript",
"plugin:prettier/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
},
rules: {
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/strict-boolean-expressions": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_$", varsIgnorePattern: "^_$" },
],
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-ignore": "allow-with-description",
minimumDescriptionLength: 10,
},
],
},
},
],
};
51 changes: 51 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const defaultPresets = [
["@babel/preset-typescript", { allowNamespaces: true }],
];

const defaultIgnores = [
/.*\/(.*\.|)test\.tsx?/,
/bundle\.ts/,
/node_modules/,
/lib/,
];

const presetsForESM = [
[
"@babel/preset-env",
{
modules: false,
},
],
...defaultPresets,
];
const presetsForCJS = [
[
"@babel/preset-env",
{
modules: "cjs",
},
],
...defaultPresets,
];
const plugins = [
[
"module-resolver",
{
root: ["."],
},
],
"@babel/plugin-transform-runtime",
];

module.exports = {
env: {
cjs: {
presets: presetsForCJS,
},
esm: {
presets: presetsForESM,
},
},
ignore: defaultIgnores,
plugins,
};
40 changes: 28 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "1.0.3",
"description": "Custom Jest Assertions for Serverless Projects",
"main": "lib/index.js",
"module": "lib/esm/index.js",
"types": "lib/types/index.d.ts",
"directories": {
"lib": "lib"
},
Expand All @@ -14,29 +16,43 @@
"author": "Theodo UK",
"license": "MIT",
"scripts": {
"build": "babel ./src --out-dir lib",
"build-maps": "babel ./src --out-dir lib --source-maps",
"dev": "babel ./src --out-dir lib --watch",
"build": "rm -rf lib && yarn package:cjs && yarn package:esm && yarn package:types",
"dev": "rm -rf lib && concurrently 'yarn:package:* --watch'",
"lint": "eslint ./src",
"fix": "yarn lint --fix",
"release": "release-it"
"release": "release-it",
"package:cjs": "NODE_ENV=cjs yarn transpile --out-dir lib/cjs --source-maps",
"package:esm": "NODE_ENV=esm yarn transpile --out-dir lib/esm --source-maps",
"package:types": "ttsc",
"transpile": "babel . --extensions .ts"
},
"dependencies": {
"aws-sdk": "^2.711.0",
"import-all.macro": "^3.1.0"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@zerollup/ts-transform-paths": "^1.7.18",
"babel-plugin-module-resolver": "^4.1.0",
"concurrently": "^6.0.0",
"babel-plugin-macros": "^3.1.0",
"eslint": "^7.25.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.2.1",
"release-it": "^14.6.1"
"release-it": "^14.6.1",
"ts-node": "^10.4.0",
"ttypescript": "^1.5.12",
"typescript": "^4.5.2",
"@typescript-eslint/eslint-plugin": "^5.6.0",
"@typescript-eslint/parser": "^5.6.0",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0"
},
"babel": {
"presets": [
Expand Down
20 changes: 20 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"skipLibCheck": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": true,
"sourceMap": true,
"target": "ES2020",
"strict": true,
"baseUrl": ".",
"composite": true,
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }],
"emitDeclarationOnly": true,
"outDir": "./lib/types",
"rootDir": "./src"
},
"include": ["./src/**/*.ts"]
}
Loading

0 comments on commit fccecf3

Please sign in to comment.