Skip to content

Commit

Permalink
chore(tsc): update tsconfig, remove @hoishin/tsconfig (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoishin authored Jun 12, 2023
1 parent c505bd8 commit 8d72acc
Show file tree
Hide file tree
Showing 13 changed files with 596 additions and 1,379 deletions.
11 changes: 10 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
],
"overrides": [
{
"files": ["**/__tests__/**/*"],
"files": ["./src/**/*"],
"parserOptions": {
"project": "./src/tsconfig.json"
}
},
{
"files": ["./tests/**/*"],
"parserOptions": {
"project": "./tests/tsconfig.json"
},
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-argument": "off",
Expand Down
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

14 changes: 14 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type {JestConfigWithTsJest} from 'ts-jest';

export default {
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: './tests/tsconfig.json',
},
],
},
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
} satisfies JestConfigWithTsJest;
19 changes: 7 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@
],
"scripts": {
"_prettier": "prettier \"**/*.{js,ts,tsx,md,yml,yaml,json}\"",
"build": "del-cli cjs esm && run-p build:*",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build": "del-cli cjs esm && tsc -b src/tsconfig.json src/tsconfig.cjs.json",
"fmt": "yarn _prettier --write",
"prepare": "yarn build",
"prepublishOnly": "yarn build",
"release": "standard-version",
"test": "run-s test:*",
"test:fmt": "yarn _prettier --check",
"test:jest": "jest",
Expand Down Expand Up @@ -70,9 +66,8 @@
},
"devDependencies": {
"@hoishin/prettierrc": "2.1.1",
"@hoishin/tsconfig": "2.0.0",
"@testing-library/react": "^13.4.0",
"@types/jest": "^28",
"@types/jest": "^29.5.2",
"@types/lodash.clone": "4.5.6",
"@types/node": "12.12.29",
"@types/react": "^18.0.0",
Expand All @@ -84,16 +79,16 @@
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "4.3.0",
"jest": "28.1.3",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"lint-staged": "10.5.1",
"npm-run-all": "4.1.5",
"prettier": "2.0.0",
"prettier": "^2.8.8",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"sort-package-json": "1.46.1",
"standard-version": "^8.0.0",
"ts-jest": "^28",
"typescript": "^4.5.4"
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
}
}
8 changes: 8 additions & 0 deletions src/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node16",
"outDir": "../cjs"
}
}
10 changes: 10 additions & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "ES2022",
"moduleResolution": "bundler",
"types": ["@nodecg/types/augment-window.d.ts"],
"outDir": "../esm"
},
"include": ["./**/*.ts", "./**/*.tsx"]
}
16 changes: 9 additions & 7 deletions src/use-replicant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ export const useReplicant = <T>(
): [T | undefined, (newValue: T) => void] => {
const [value, updateValue] = useState<T | undefined>(initialValue);

const replicantOptions: typeof options = options && {
persistent: options.persistent,
schemaPath: options.schemaPath,
};
const replicantOptions =
options &&
({
persistent: options.persistent,
schemaPath: options.schemaPath,
} satisfies typeof options);

if (options && 'defaultValue' in options) {
(replicantOptions as NodeCG.Replicant.OptionsWithDefault<
T
>).defaultValue = options.defaultValue;
(
replicantOptions as NodeCG.Replicant.OptionsWithDefault<T>
).defaultValue = options.defaultValue;
}

let replicant: NodeCG.ClientReplicant<T>;
Expand Down
7 changes: 7 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"jsx": "react-jsx",
"types": ["ts-jest/globals", "@nodecg/types/augment-window.d.ts"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';
import {render, act, fireEvent} from '@testing-library/react';
import type {RenderResult} from '@testing-library/react';

import {useReplicant} from '..';
import {useReplicant} from '../src';
import type NodeCG from '@nodecg/types';

const replicantHandler = jest.fn();
Expand All @@ -32,12 +32,12 @@ class Replicant extends EventEmitter {
}
}

on(event: string, payload: any): this {
override on(event: string, payload: any): this {
replicantHandler(event, payload);
return super.on(event, payload);
}

removeListener(event: string, listener: () => void): this {
override removeListener(event: string, listener: () => void): this {
replicantRemoveListener();
return super.removeListener(event, listener);
}
Expand Down
14 changes: 0 additions & 14 deletions tsconfig.cjs.json

This file was deleted.

14 changes: 0 additions & 14 deletions tsconfig.esm.json

This file was deleted.

33 changes: 22 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
{
"extends": "@hoishin/tsconfig",
"compilerOptions": {
"target": "ESNext",
"lib": ["esnext", "dom"],
"jsx": "react",
"target": "ES2022",
"lib": ["ES2022", "DOM"],
"module": "Node16",
"moduleResolution": "node16",

"declaration": true,
"moduleResolution": "node",
"sourceMap": true,
"isolatedModules": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": true,

"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,

"skipLibCheck": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"node_modules/@nodecg/types/augment-window.d.ts"
]
}
}
Loading

0 comments on commit 8d72acc

Please sign in to comment.