diff --git a/.node-version b/.node-version deleted file mode 100644 index 99cdd800..00000000 --- a/.node-version +++ /dev/null @@ -1 +0,0 @@ -16.15.0 diff --git a/jest.config.base.ts b/jest.config.base.ts deleted file mode 100644 index 8b6a5e8d..00000000 --- a/jest.config.base.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Config } from '@jest/types' -import glob from 'glob' - -const packages = glob.sync(`./src`).map(p => p.replace(/^\./, ``)) - -const ignoreDirs = [ - 'build/', - 'dist/', - 'node_modules/', - `\\.cache`, - 'scripts/', - 'public/', - 'generators/', - 'generated/', - 'site/', -] - -const config: Config.InitialOptions = { - roots: packages, - transform: { - '^.+\\.[jt]sx?$': `/jest-preprocess.js`, - }, - moduleNameMapper: { - '.+\\.(css|styl|less|sass|scss)$': `identity-obj-proxy`, - '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': `/__mocks__/file-mock.js`, - }, - testPathIgnorePatterns: ignoreDirs, - transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`], - coveragePathIgnorePatterns: ignoreDirs, - coverageDirectory: '/coverage/', - globals: { - __PATH_PREFIX__: ``, - }, - testURL: `http://localhost`, - setupFiles: [`/loadershim.js`], - testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$', - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], -} - -export default config diff --git a/jest.config.node.ts b/jest.config.node.ts deleted file mode 100644 index 9bd26051..00000000 --- a/jest.config.node.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { Config } from '@jest/types' - -import base from './jest.config.base' - -const config: Config.InitialOptions = { - ...base, - testEnvironment: 'node', -} - -export default config diff --git a/jest.config.ts b/jest.config.ts index 8b2ca7a7..b7f7bce7 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,10 +1,41 @@ import type { Config } from '@jest/types' +import glob from 'glob' -import base from './jest.config.base' +const packages = glob.sync(`./src`).map(p => p.replace(/^\./, ``)) + +const ignoreDirs = [ + 'build/', + 'dist/', + 'node_modules/', + `\\.cache`, + 'scripts/', + 'public/', + 'generators/', + 'generated/', + 'site/', +] const config: Config.InitialOptions = { - ...base, testEnvironment: 'jsdom', + roots: packages, + transform: { + '^.+\\.[jt]sx?$': `/jest-preprocess.js`, + }, + moduleNameMapper: { + '.+\\.(css|styl|less|sass|scss)$': `identity-obj-proxy`, + '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': `/__mocks__/file-mock.js`, + }, + testPathIgnorePatterns: ignoreDirs, + transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`], + coveragePathIgnorePatterns: ignoreDirs, + coverageDirectory: '/coverage/', + globals: { + __PATH_PREFIX__: ``, + }, + testURL: `http://localhost`, + setupFiles: [`/loadershim.js`], + testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], } export default config diff --git a/package.json b/package.json index 7f76de8c..24434e50 100644 --- a/package.json +++ b/package.json @@ -20,41 +20,24 @@ "./site" ], "scripts": { - "prebuild": "npm run clean", - "start": "chokidar \"src/**/*.ts\" -c \"npm run build\"", + "start": "echo 'TODO: chokidar \"src/**/*.ts\" -c \"npm run build\" || npm run test:watch'", + "prebuild": "npm run clean && npm run types-check", "build": "npm run build:cjs && npm run build:esm", - "build:cjs": "tsc -p tsconfig.build.json --module commonjs --outDir dist/cjs", - "build:esm": "tsc -p tsconfig.build.json --module esNext --outDir dist/esm", + "postbuild": "npm run copy:hooks && npm run update:readme", + "build:cjs": "tsc --module commonjs --outDir dist/cjs", + "build:esm": "tsc --module esNext --outDir dist/esm", "test": "jest", + "test:watch": "npm run test -- --watch --silent", + "test:coverage": "ts-node ./scripts/coverage.ts", "clean": "rimraf -rf ./dist", - "types-check": "tsc -p tsconfig.json", - "legacy-clean": "lerna run clean && lerna clean -y", - "legacy-bootstrap": "npm ci && lerna exec npm ci && npm run copy:hooks && npm run build:lib", - "legacy-types-check": "lerna run types-check", - "legacy-lint": "npm-run-all --continue-on-error -p lint:*", - "legacy-lint:code": "eslint '**/*.{js,jsx,ts,tsx}'", - "legacy-lint:other": "prettier --check \"**/*.{json,md,mdx,css,scss,yaml,yml}\"", - "legacy-format": "run-p format:*", - "legacy-format:code": "npm run lint:code -- --fix", - "legacy-format:other": "npm run lint:other -- --write", - "legacy-pretest": "npm run types-check && npm run format", - "legacy-test": "jest", - "legacy-test:ssr": "jest --config ./jest.config.node.ts", - "legacy-test:watch": "npm run test -- --watch --silent", - "legacy-test:coverage": "ts-node ./scripts/coverage.ts", - "legacy-prebuilt": "npm run format && npm run copy:hooks", - "legacy-build": "lerna run build --stream", - "legacy-build:site": "lerna run --scope site build", - "legacy-build:lib": "lerna run --scope usehooks-ts build && npm run copy:hooks", - "legacy-predeploy": "npm run build", - "legacy-deploy": "netlify deploy --dir=site/public --prod", - "legacy-dev:site": "npm run build:lib && cd site && npm run start", - "legacy-dev:lib": "npm run test:watch", - "legacy-serve:site": "cd site && npm run serve", - "legacy-publish": "npm run build:lib && npm run test && lerna publish --no-git-reset", - "legacy-update:readme": "ts-node ./scripts/updateReadme.ts", - "legacy-copy:hooks": "rimraf -rf ./site/generated && ts-node ./scripts/copyHooks.ts", - "legacy-plop": "plop && npm run update:readme && npm run format" + "format": "prettier --check \"**/*.{json,md,mdx,css,scss,yaml,yml}\"", + "lint": "eslint '**/*.{js,jsx,ts,tsx}'", + "types-check": "tsc --noEmit", + "publish": "echo 'TODO: Publish npm package on npm.com'", + "update:readme": "ts-node ./scripts/updateReadme.ts", + "copy:hooks": "rimraf -rf ./site/generated && ts-node ./scripts/copyHooks.ts", + "plop": "plop && npm run update:readme && npm run format", + "deploy-site": "echo 'TODO: deploy: netlify deploy --dir=site/public --prod'" }, "devDependencies": { "@testing-library/react": "^12.1.2", @@ -93,6 +76,10 @@ "peerDependencies": { "react": "^16.9.0 || ^17.0.0 || ^18.0.0" }, + "engines": { + "node": ">=16.15.0", + "npm": ">=8" + }, "repository": { "type": "git", "url": "https://github.com/juliencrn/usehooks-ts" diff --git a/plopfile.js b/plopfile.js index f0b15af3..03f0877f 100644 --- a/plopfile.js +++ b/plopfile.js @@ -21,22 +21,22 @@ module.exports = function (plop) { */ { type: 'add', - path: 'lib/src/{{camelCase name}}/index.ts', + path: 'src/{{camelCase name}}/index.ts', templateFile: 'templates/plop/hooks/lib/index.ts.hbs', }, { type: 'add', - path: 'lib/src/{{camelCase name}}/{{camelCase name}}.ts', + path: 'src/{{camelCase name}}/{{camelCase name}}.ts', templateFile: 'templates/plop/hooks/lib/hook.ts.hbs', }, { type: 'add', - path: 'lib/src/{{camelCase name}}/{{camelCase name}}.test.ts', + path: 'src/{{camelCase name}}/{{camelCase name}}.test.ts', templateFile: 'templates/plop/hooks/lib/hook.test.ts.hbs', }, { type: 'append', - path: 'lib/src/index.ts', + path: 'src/index.ts', templateFile: 'templates/plop/hooks/index.ts.hbs', }, diff --git a/scripts/copyHooks.ts b/scripts/copyHooks.ts index 47f12fbb..10bfa807 100644 --- a/scripts/copyHooks.ts +++ b/scripts/copyHooks.ts @@ -3,7 +3,7 @@ import path from 'path' import { isHookFile, toQueryParams } from './utils' -const hooksDir = path.resolve('./lib/src') +const hooksDir = path.resolve('./src') const demosDir = path.resolve('./site/src/hooks-doc') const outputDir = path.resolve('./site/generated') const sandboxTemplatePath = path.resolve('./templates/codesandbox') diff --git a/scripts/coverage.ts b/scripts/coverage.ts index 643aff1b..9fe5b3fe 100644 --- a/scripts/coverage.ts +++ b/scripts/coverage.ts @@ -3,7 +3,7 @@ import path from 'path' import { isHookFile } from './utils' -const hookDir = path.resolve('./lib/src') +const hookDir = path.resolve('./src') const hooks = fs.readdirSync(hookDir).filter(isHookFile) const testFileRegex = new RegExp(`\.test\.ts$`) let hasTestCount = 0 diff --git a/scripts/updateReadme.ts b/scripts/updateReadme.ts index 5a44fa66..9ef57f1e 100644 --- a/scripts/updateReadme.ts +++ b/scripts/updateReadme.ts @@ -10,14 +10,13 @@ import { camelToKebabCase, isHookFile } from './utils' const demos = fs.readdirSync(path.resolve(path.resolve('./site/src/hooks-doc'))) const hooks = fs - .readdirSync(path.resolve(path.resolve('./lib/src'))) + .readdirSync(path.resolve(path.resolve('./src'))) .filter(isHookFile) .map(name => formatHook(name, demos)) const markdown = createMarkdownList(hooks) insertIn(markdown, path.resolve('./README.md')) -insertIn(markdown, path.resolve('./lib/README.md')) //////////////////////////////////////////////////////////////////////// // 2. Utility functions diff --git a/tsconfig.base.json b/tsconfig.base.json deleted file mode 100644 index 59b7c944..00000000 --- a/tsconfig.base.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "compilerOptions": { - "sourceMap": true, - "declaration": true, - "declarationMap": true, - "noEmitOnError": true, - "skipLibCheck": true, - "removeComments": true, - "esModuleInterop": true, - "jsx": "react", - "strict": true, - "isolatedModules": true, - "lib": ["ESNEXT", "DOM"] - }, - - "exclude": ["node_modules", "dist"] -} diff --git a/tsconfig.build.json b/tsconfig.build.json deleted file mode 100644 index 72c7d352..00000000 --- a/tsconfig.build.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extends": "./tsconfig.base.json", - - "compilerOptions": { - "rootDir": "./src", - "outDir": "./dist", - "target": "esnext", - "moduleResolution": "node", - // Needed for CommonJS modules - "allowSyntheticDefaultImports": true - }, - - "include": ["./src/**/*"], - "exclude": ["./src/**/*.test.ts"] -} diff --git a/tsconfig.json b/tsconfig.json index e53e79b5..231a59bf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,24 @@ { - "extends": "./tsconfig.base.json", - "compilerOptions": { "baseUrl": ".", - "paths": { - "lib": ["src"], - "site": ["site/src"] - }, - "noEmit": true + "rootDir": "./src", + "target": "esnext", + "moduleResolution": "node", + // Needed for CommonJS modules + "allowSyntheticDefaultImports": true, + "sourceMap": true, + "declaration": true, + "declarationMap": true, + "noEmitOnError": true, + "skipLibCheck": true, + "removeComments": true, + "esModuleInterop": true, + "jsx": "react", + "strict": true, + "isolatedModules": true, + "lib": ["ESNEXT", "DOM"] }, - "include": ["src/**/*"] + "include": ["./src/**/*"], + "exclude": ["node_modules", "dist", "./src/**/*.test.ts", "site", "scripts"] }