From 67e5f2e8a4189216a168cd4d78b4f8cc98883b47 Mon Sep 17 00:00:00 2001 From: Kai Nguyen Date: Fri, 8 Nov 2024 12:04:14 +1100 Subject: [PATCH 1/4] MI-39: Convert to Typescript & support CJS --- .github/workflows/publish.yml | 3 + .gitignore | 1 + package.json | 13 +- pnpm-lock.yaml | 248 ++++++++++++++++++++++++++-------- rollup.config.js | 16 +++ src/{index.js => index.ts} | 4 +- tsconfig.json | 2 +- 7 files changed, 224 insertions(+), 63 deletions(-) create mode 100644 rollup.config.js rename src/{index.js => index.ts} (95%) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9cb7dcf..7f09f39 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -26,6 +26,9 @@ jobs: - name: Install run: pnpm install + - name: Build + run: pnpm build + - name: Preparing environment for release run: | VERSION=$(echo $GITHUB_REF_NAME | sed 's/^.*[A-Za-z]-//g') diff --git a/.gitignore b/.gitignore index 441dadb..379500c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode node_modules .pnpm-store +dist diff --git a/package.json b/package.json index 114429d..0809e7c 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,17 @@ { "name": "@aligent/ts-code-standards", - "main": "src/index.js", "type": "module", + "exports": { + ".": { + "require": "./dist/index.cjs", + "import": "./dist/index.mjs" + }, + "./tsconfigs-base": "./tsconfigs/base.json", + "./tsconfigs-react": "./tsconfigs/react.json" + }, "scripts": { "test": "tsc && eslint .", + "build": "npx rollup -c", "format": "prettier --ignore-path .prettierignore --check \"**/*.+(js|ts|json)\"", "format:check": "pnpm run format", "format:fix": "prettier --ignore-path .prettierignore --write \"**/*.+(js|ts|json)\"" @@ -13,17 +21,18 @@ "@eslint/js": "^9.14.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-jsx-a11y": "^6.10.2", - "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-react": "^7.37.2", "eslint-plugin-react-hooks": "^5.0.0", "prettier-plugin-tailwindcss": "^0.6.8", "typescript-eslint": "^8.13.0" }, "devDependencies": { + "@types/eslint-config-prettier": "^6.11.3", "@types/eslint-plugin-jsx-a11y": "^6.9.0", "@types/eslint__js": "^8.42.3", "eslint": "^9.14.0", "prettier": "^3.3.3", + "rollup": "^4.24.4", "typescript": "^5.6.3" }, "packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0e35783..9a0fe7a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,9 +20,6 @@ importers: eslint-plugin-jsx-a11y: specifier: ^6.10.2 version: 6.10.2(eslint@9.14.0) - eslint-plugin-prettier: - specifier: ^5.2.1 - version: 5.2.1(@types/eslint@9.6.1)(eslint-config-prettier@9.1.0(eslint@9.14.0))(eslint@9.14.0)(prettier@3.3.3) eslint-plugin-react: specifier: ^7.37.2 version: 7.37.2(eslint@9.14.0) @@ -36,6 +33,9 @@ importers: specifier: ^8.13.0 version: 8.13.0(eslint@9.14.0)(typescript@5.6.3) devDependencies: + '@types/eslint-config-prettier': + specifier: ^6.11.3 + version: 6.11.3 '@types/eslint-plugin-jsx-a11y': specifier: ^6.9.0 version: 6.9.0 @@ -48,6 +48,9 @@ importers: prettier: specifier: ^3.3.3 version: 3.3.3 + rollup: + specifier: ^4.24.4 + version: 4.24.4 typescript: specifier: ^5.6.3 version: 5.6.3 @@ -129,9 +132,98 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} - '@pkgr/core@0.1.1': - resolution: {integrity: sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==} - engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} + '@rollup/rollup-android-arm-eabi@4.24.4': + resolution: {integrity: sha512-jfUJrFct/hTA0XDM5p/htWKoNNTbDLY0KRwEt6pyOA6k2fmk0WVwl65PdUdJZgzGEHWx+49LilkcSaumQRyNQw==} + cpu: [arm] + os: [android] + + '@rollup/rollup-android-arm64@4.24.4': + resolution: {integrity: sha512-j4nrEO6nHU1nZUuCfRKoCcvh7PIywQPUCBa2UsootTHvTHIoIu2BzueInGJhhvQO/2FTRdNYpf63xsgEqH9IhA==} + cpu: [arm64] + os: [android] + + '@rollup/rollup-darwin-arm64@4.24.4': + resolution: {integrity: sha512-GmU/QgGtBTeraKyldC7cDVVvAJEOr3dFLKneez/n7BvX57UdhOqDsVwzU7UOnYA7AAOt+Xb26lk79PldDHgMIQ==} + cpu: [arm64] + os: [darwin] + + '@rollup/rollup-darwin-x64@4.24.4': + resolution: {integrity: sha512-N6oDBiZCBKlwYcsEPXGDE4g9RoxZLK6vT98M8111cW7VsVJFpNEqvJeIPfsCzbf0XEakPslh72X0gnlMi4Ddgg==} + cpu: [x64] + os: [darwin] + + '@rollup/rollup-freebsd-arm64@4.24.4': + resolution: {integrity: sha512-py5oNShCCjCyjWXCZNrRGRpjWsF0ic8f4ieBNra5buQz0O/U6mMXCpC1LvrHuhJsNPgRt36tSYMidGzZiJF6mw==} + cpu: [arm64] + os: [freebsd] + + '@rollup/rollup-freebsd-x64@4.24.4': + resolution: {integrity: sha512-L7VVVW9FCnTTp4i7KrmHeDsDvjB4++KOBENYtNYAiYl96jeBThFfhP6HVxL74v4SiZEVDH/1ILscR5U9S4ms4g==} + cpu: [x64] + os: [freebsd] + + '@rollup/rollup-linux-arm-gnueabihf@4.24.4': + resolution: {integrity: sha512-10ICosOwYChROdQoQo589N5idQIisxjaFE/PAnX2i0Zr84mY0k9zul1ArH0rnJ/fpgiqfu13TFZR5A5YJLOYZA==} + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm-musleabihf@4.24.4': + resolution: {integrity: sha512-ySAfWs69LYC7QhRDZNKqNhz2UKN8LDfbKSMAEtoEI0jitwfAG2iZwVqGACJT+kfYvvz3/JgsLlcBP+WWoKCLcw==} + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm64-gnu@4.24.4': + resolution: {integrity: sha512-uHYJ0HNOI6pGEeZ/5mgm5arNVTI0nLlmrbdph+pGXpC9tFHFDQmDMOEqkmUObRfosJqpU8RliYoGz06qSdtcjg==} + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-arm64-musl@4.24.4': + resolution: {integrity: sha512-38yiWLemQf7aLHDgTg85fh3hW9stJ0Muk7+s6tIkSUOMmi4Xbv5pH/5Bofnsb6spIwD5FJiR+jg71f0CH5OzoA==} + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-powerpc64le-gnu@4.24.4': + resolution: {integrity: sha512-q73XUPnkwt9ZNF2xRS4fvneSuaHw2BXuV5rI4cw0fWYVIWIBeDZX7c7FWhFQPNTnE24172K30I+dViWRVD9TwA==} + cpu: [ppc64] + os: [linux] + + '@rollup/rollup-linux-riscv64-gnu@4.24.4': + resolution: {integrity: sha512-Aie/TbmQi6UXokJqDZdmTJuZBCU3QBDA8oTKRGtd4ABi/nHgXICulfg1KI6n9/koDsiDbvHAiQO3YAUNa/7BCw==} + cpu: [riscv64] + os: [linux] + + '@rollup/rollup-linux-s390x-gnu@4.24.4': + resolution: {integrity: sha512-P8MPErVO/y8ohWSP9JY7lLQ8+YMHfTI4bAdtCi3pC2hTeqFJco2jYspzOzTUB8hwUWIIu1xwOrJE11nP+0JFAQ==} + cpu: [s390x] + os: [linux] + + '@rollup/rollup-linux-x64-gnu@4.24.4': + resolution: {integrity: sha512-K03TljaaoPK5FOyNMZAAEmhlyO49LaE4qCsr0lYHUKyb6QacTNF9pnfPpXnFlFD3TXuFbFbz7tJ51FujUXkXYA==} + cpu: [x64] + os: [linux] + + '@rollup/rollup-linux-x64-musl@4.24.4': + resolution: {integrity: sha512-VJYl4xSl/wqG2D5xTYncVWW+26ICV4wubwN9Gs5NrqhJtayikwCXzPL8GDsLnaLU3WwhQ8W02IinYSFJfyo34Q==} + cpu: [x64] + os: [linux] + + '@rollup/rollup-win32-arm64-msvc@4.24.4': + resolution: {integrity: sha512-ku2GvtPwQfCqoPFIJCqZ8o7bJcj+Y54cZSr43hHca6jLwAiCbZdBUOrqE6y29QFajNAzzpIOwsckaTFmN6/8TA==} + cpu: [arm64] + os: [win32] + + '@rollup/rollup-win32-ia32-msvc@4.24.4': + resolution: {integrity: sha512-V3nCe+eTt/W6UYNr/wGvO1fLpHUrnlirlypZfKCT1fG6hWfqhPgQV/K/mRBXBpxc0eKLIF18pIOFVPh0mqHjlg==} + cpu: [ia32] + os: [win32] + + '@rollup/rollup-win32-x64-msvc@4.24.4': + resolution: {integrity: sha512-LTw1Dfd0mBIEqUVCxbvTE/LLo+9ZxVC9k99v1v4ahg9Aak6FpqOfNu5kRkeTAn0wphoC4JU7No1/rL+bBCEwhg==} + cpu: [x64] + os: [win32] + + '@types/eslint-config-prettier@6.11.3': + resolution: {integrity: sha512-3wXCiM8croUnhg9LdtZUJQwNcQYGWxxdOWDjPe1ykCqJFPVpzAKfs/2dgSoCtAvdPeaponcWPI7mPcGGp9dkKQ==} '@types/eslint-plugin-jsx-a11y@6.9.0': resolution: {integrity: sha512-5nw0sPyYGCsFibwjOXftxends8Nrh/JLgDtBWj6aJVcN14kHwy1yIy0o1MGLKfCcR27pvUFGgYG+hX2HSX16uA==} @@ -400,20 +492,6 @@ packages: peerDependencies: eslint: ^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9 - eslint-plugin-prettier@5.2.1: - resolution: {integrity: sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==} - engines: {node: ^14.18.0 || >=16.0.0} - peerDependencies: - '@types/eslint': '>=8.0.0' - eslint: '>=8.0.0' - eslint-config-prettier: '*' - prettier: '>=3.0.0' - peerDependenciesMeta: - '@types/eslint': - optional: true - eslint-config-prettier: - optional: true - eslint-plugin-react-hooks@5.0.0: resolution: {integrity: sha512-hIOwI+5hYGpJEc4uPRmz2ulCjAGD/N13Lukkh8cLV0i2IRk/bdZDYjgLVHj+U9Z704kLIdIO6iueGvxNur0sgw==} engines: {node: '>=10'} @@ -471,9 +549,6 @@ packages: fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} - fast-diff@1.3.0: - resolution: {integrity: sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==} - fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} @@ -509,6 +584,11 @@ packages: for-each@0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} + fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} @@ -831,10 +911,6 @@ packages: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} - prettier-linter-helpers@1.0.0: - resolution: {integrity: sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==} - engines: {node: '>=6.0.0'} - prettier-plugin-tailwindcss@0.6.8: resolution: {integrity: sha512-dGu3kdm7SXPkiW4nzeWKCl3uoImdd5CTZEJGxyypEPL37Wj0HT2pLqjrvSei1nTeuQfO4PUfjeW5cTUNRLZ4sA==} engines: {node: '>=14.21.3'} @@ -928,6 +1004,11 @@ packages: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} + rollup@4.24.4: + resolution: {integrity: sha512-vGorVWIsWfX3xbcyAS+I047kFKapHYivmkaT63Smj77XwvLSJos6M1xGqZnBPFQFBRZDOcG1QnYEIxAvTr/HjA==} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -1002,10 +1083,6 @@ packages: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} - synckit@0.9.2: - resolution: {integrity: sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==} - engines: {node: ^14.18.0 || >=16.0.0} - text-table@0.2.0: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} @@ -1019,9 +1096,6 @@ packages: peerDependencies: typescript: '>=4.2.0' - tslib@2.8.0: - resolution: {integrity: sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==} - type-check@0.4.0: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} @@ -1160,7 +1234,61 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 - '@pkgr/core@0.1.1': {} + '@rollup/rollup-android-arm-eabi@4.24.4': + optional: true + + '@rollup/rollup-android-arm64@4.24.4': + optional: true + + '@rollup/rollup-darwin-arm64@4.24.4': + optional: true + + '@rollup/rollup-darwin-x64@4.24.4': + optional: true + + '@rollup/rollup-freebsd-arm64@4.24.4': + optional: true + + '@rollup/rollup-freebsd-x64@4.24.4': + optional: true + + '@rollup/rollup-linux-arm-gnueabihf@4.24.4': + optional: true + + '@rollup/rollup-linux-arm-musleabihf@4.24.4': + optional: true + + '@rollup/rollup-linux-arm64-gnu@4.24.4': + optional: true + + '@rollup/rollup-linux-arm64-musl@4.24.4': + optional: true + + '@rollup/rollup-linux-powerpc64le-gnu@4.24.4': + optional: true + + '@rollup/rollup-linux-riscv64-gnu@4.24.4': + optional: true + + '@rollup/rollup-linux-s390x-gnu@4.24.4': + optional: true + + '@rollup/rollup-linux-x64-gnu@4.24.4': + optional: true + + '@rollup/rollup-linux-x64-musl@4.24.4': + optional: true + + '@rollup/rollup-win32-arm64-msvc@4.24.4': + optional: true + + '@rollup/rollup-win32-ia32-msvc@4.24.4': + optional: true + + '@rollup/rollup-win32-x64-msvc@4.24.4': + optional: true + + '@types/eslint-config-prettier@6.11.3': {} '@types/eslint-plugin-jsx-a11y@6.9.0': dependencies: @@ -1552,16 +1680,6 @@ snapshots: safe-regex-test: 1.0.3 string.prototype.includes: 2.0.1 - eslint-plugin-prettier@5.2.1(@types/eslint@9.6.1)(eslint-config-prettier@9.1.0(eslint@9.14.0))(eslint@9.14.0)(prettier@3.3.3): - dependencies: - eslint: 9.14.0 - prettier: 3.3.3 - prettier-linter-helpers: 1.0.0 - synckit: 0.9.2 - optionalDependencies: - '@types/eslint': 9.6.1 - eslint-config-prettier: 9.1.0(eslint@9.14.0) - eslint-plugin-react-hooks@5.0.0(eslint@9.14.0): dependencies: eslint: 9.14.0 @@ -1657,8 +1775,6 @@ snapshots: fast-deep-equal@3.1.3: {} - fast-diff@1.3.0: {} - fast-glob@3.3.2: dependencies: '@nodelib/fs.stat': 2.0.5 @@ -1699,6 +1815,9 @@ snapshots: dependencies: is-callable: 1.2.7 + fsevents@2.3.3: + optional: true + function-bind@1.1.2: {} function.prototype.name@1.1.6: @@ -2010,10 +2129,6 @@ snapshots: prelude-ls@1.2.1: {} - prettier-linter-helpers@1.0.0: - dependencies: - fast-diff: 1.3.0 - prettier-plugin-tailwindcss@0.6.8(prettier@3.3.3): dependencies: prettier: 3.3.3 @@ -2059,6 +2174,30 @@ snapshots: reusify@1.0.4: {} + rollup@4.24.4: + dependencies: + '@types/estree': 1.0.6 + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.24.4 + '@rollup/rollup-android-arm64': 4.24.4 + '@rollup/rollup-darwin-arm64': 4.24.4 + '@rollup/rollup-darwin-x64': 4.24.4 + '@rollup/rollup-freebsd-arm64': 4.24.4 + '@rollup/rollup-freebsd-x64': 4.24.4 + '@rollup/rollup-linux-arm-gnueabihf': 4.24.4 + '@rollup/rollup-linux-arm-musleabihf': 4.24.4 + '@rollup/rollup-linux-arm64-gnu': 4.24.4 + '@rollup/rollup-linux-arm64-musl': 4.24.4 + '@rollup/rollup-linux-powerpc64le-gnu': 4.24.4 + '@rollup/rollup-linux-riscv64-gnu': 4.24.4 + '@rollup/rollup-linux-s390x-gnu': 4.24.4 + '@rollup/rollup-linux-x64-gnu': 4.24.4 + '@rollup/rollup-linux-x64-musl': 4.24.4 + '@rollup/rollup-win32-arm64-msvc': 4.24.4 + '@rollup/rollup-win32-ia32-msvc': 4.24.4 + '@rollup/rollup-win32-x64-msvc': 4.24.4 + fsevents: 2.3.3 + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -2162,11 +2301,6 @@ snapshots: supports-preserve-symlinks-flag@1.0.0: {} - synckit@0.9.2: - dependencies: - '@pkgr/core': 0.1.1 - tslib: 2.8.0 - text-table@0.2.0: {} to-regex-range@5.0.1: @@ -2177,8 +2311,6 @@ snapshots: dependencies: typescript: 5.6.3 - tslib@2.8.0: {} - type-check@0.4.0: dependencies: prelude-ls: 1.2.1 diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..f3d9bc9 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,16 @@ + +const OUT_DIR = 'dist'; + +export default { + input: 'src/index.ts', + output: [ + { + file: `${OUT_DIR}/index.cjs`, + format: 'cjs', + }, + { + file: `${OUT_DIR}/index.mjs`, + format: 'es', + }, + ], +}; diff --git a/src/index.js b/src/index.ts similarity index 95% rename from src/index.js rename to src/index.ts index 0382ac9..7cd1492 100644 --- a/src/index.js +++ b/src/index.ts @@ -1,5 +1,5 @@ import eslint from '@eslint/js'; -import eslintPluginPrettier from 'eslint-plugin-prettier/recommended'; +import eslintConfigPrettier from 'eslint-config-prettier'; import { fixupPluginRules } from '@eslint/compat'; import hooksPlugin from 'eslint-plugin-react-hooks'; import jsxA11yPlugin from 'eslint-plugin-jsx-a11y'; @@ -9,7 +9,7 @@ import tsEslint from 'typescript-eslint'; const core = [ eslint.configs.recommended, ...tsEslint.configs.recommended, - eslintPluginPrettier, + eslintConfigPrettier, { rules: { 'no-restricted-syntax': [ diff --git a/tsconfig.json b/tsconfig.json index b94115c..dc559a0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,4 @@ { "extends": "./tsconfigs/react.json", - "include": ["**/*.tsx", "**/*.ts", "**/*.js", "src/declarations.d.ts"] + "include": ["**/*.tsx", "**/*.ts", "**/*.js", "src/declarations.d.ts", "src/index.ts"] } From 2e5888e2b00242f2d1a8baad1366c9d3494914a4 Mon Sep 17 00:00:00 2001 From: Kai Nguyen Date: Fri, 8 Nov 2024 13:44:50 +1100 Subject: [PATCH 2/4] MI-39: Update ReadMe --- README.md | 105 ++++++++++++++++++++++++------------- package.json | 4 ++ rollup.config.js | 2 +- src/{index.ts => index.js} | 0 tsconfig.json | 2 +- 5 files changed, 75 insertions(+), 38 deletions(-) rename src/{index.ts => index.js} (100%) diff --git a/README.md b/README.md index 236596a..3148ec2 100644 --- a/README.md +++ b/README.md @@ -4,64 +4,97 @@ Standard code quality tooling for projects written in TypeScript. ## Usage -Install this module: +### Install this package: + +```bash + # NPM + npm install -D @aligent/ts-code-standards + # Yarn + yarn add -D @aligent/ts-code-standards + # PNPM + pnpm add -D @aligent/ts-code-standards +``` - # NPM - npm install -D @aligent/ts-code-standards - # Yarn - yarn add -D @aligent/ts-code-standards - # PNPM - pnpm add -D @aligent/ts-code-standards +### Copy the `.editorconfig` from this package into your own project: -Copy the `.editorconfig` from this repo into your own. +```bash + # Assuming your package is installed in `node_modules` folder + cp node_modules/@aligent/ts-code-standards/.editorconfig ./.editorconfig +``` -Add the following to your `prettier.config.js`: +### Add the following to your `prettier.config.js`: -```javascript -import { prettierConfig } from '@aligent/ts-code-standards'; +- For ES modules project: -export default prettierConfig; -``` + ```javascript + import { prettierConfig } from '@aligent/ts-code-standards'; -Then install the ESLint and TypeScript configs depending on what type of project you are setting up: + export default prettierConfig; + ``` -### General Projects +- For CommonJS project: -Add the following to your `eslint.config.js`: + ```javascript + const { prettierConfig } = require('@aligent/ts-code-standards'); -```javascript -import { eslintConfigs } from '@aligent/ts-code-standards'; + module.exports = prettierConfig; + ``` -export default [...eslintConfigs.base]; -``` +### Install the ESLint and TypeScript configs: + +#### General Projects + +##### Add the following to your `eslint.config.js`: + +- For ES modules project: + + ```javascript + import { eslintConfigs } from '@aligent/ts-code-standards'; + + export default [...eslintConfigs.base]; + ``` -Add the following to your `tsconfig.json`: +- For CommonJS project: + + ```javascript + const { eslintConfigs } = require('@aligent/ts-code-standards'); + + module.exports = [...eslintConfigs.base]; + ``` + +##### Add the following to your `tsconfig.json`: ```json -{ - "extends": "@aligent/ts-code-standards/tsconfigs/base.json" -} +{ "extends": "@aligent/ts-code-standards/tsconfigs-base" } ``` -### React Projects +#### React Projects -Add the following to your `eslint.config.js`: +##### Add the following to your `eslint.config.js`: -```javascript -import { eslintConfigs } from '@aligent/ts-code-standards'; +- For ES modules project: -export default [...eslintConfigs.react]; -``` + ```javascript + import { eslintConfigs } from '@aligent/ts-code-standards'; + + export default [...eslintConfigs.react]; + ``` + +- For CommonJS project: + + ```javascript + const { eslintConfigs } = require('@aligent/ts-code-standards'); + + module.exports = [...eslintConfigs.react]; + ``` -Add the following to your `tsconfig.json`: +##### Add the following to your `tsconfig.json`: ```json -{ - "extends": "@aligent/ts-code-standards/tsconfigs/react.json" -} +{ "extends": "@aligent/ts-code-standards/tsconfigs-react" } ``` ## Notes -- You'll need to add `include`, `exclude`, `paths` etc. to your `tsconfig` file. These settings will - be project specific. +- You'll need to add `include`, `exclude`, `paths` etc. to your `tsconfig` file. These settings will be project specific. +- Your project is considered as `ES modules` project if the `type` option in the nearest `package.json` is set to `module`. Otherwise, it's a CommonJS project. For more information on this, please check [CommonJS vs. ES modules in Node.js](https://blog.logrocket.com/commonjs-vs-es-modules-node-js/). diff --git a/package.json b/package.json index 0809e7c..02d5590 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,10 @@ "./tsconfigs-base": "./tsconfigs/base.json", "./tsconfigs-react": "./tsconfigs/react.json" }, + "files": [ + "dist", + "tsconfigs" + ], "scripts": { "test": "tsc && eslint .", "build": "npx rollup -c", diff --git a/rollup.config.js b/rollup.config.js index f3d9bc9..70c62b9 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,7 +2,7 @@ const OUT_DIR = 'dist'; export default { - input: 'src/index.ts', + input: 'src/index.js', output: [ { file: `${OUT_DIR}/index.cjs`, diff --git a/src/index.ts b/src/index.js similarity index 100% rename from src/index.ts rename to src/index.js diff --git a/tsconfig.json b/tsconfig.json index dc559a0..a4dc6ad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,4 @@ { "extends": "./tsconfigs/react.json", - "include": ["**/*.tsx", "**/*.ts", "**/*.js", "src/declarations.d.ts", "src/index.ts"] + "include": ["**/*.tsx", "**/*.ts", "**/*.js", "src/declarations.d.ts", "src/index.js"] } From 11dccb8bc711bb2480462d326ce2179408dfaef1 Mon Sep 17 00:00:00 2001 From: Kai Nguyen Date: Fri, 8 Nov 2024 13:47:29 +1100 Subject: [PATCH 3/4] MI-39: Fix formatting --- rollup.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index 70c62b9..ea8448c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,3 @@ - const OUT_DIR = 'dist'; export default { From 99a951920f015e750ba1a24487d82d03369ab285 Mon Sep 17 00:00:00 2001 From: Kai Nguyen Date: Mon, 11 Nov 2024 12:04:55 +1100 Subject: [PATCH 4/4] MI-39: Update exports for backward compatibility --- README.md | 1 + package.json | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3148ec2..cfa9a0c 100644 --- a/README.md +++ b/README.md @@ -98,3 +98,4 @@ Standard code quality tooling for projects written in TypeScript. - You'll need to add `include`, `exclude`, `paths` etc. to your `tsconfig` file. These settings will be project specific. - Your project is considered as `ES modules` project if the `type` option in the nearest `package.json` is set to `module`. Otherwise, it's a CommonJS project. For more information on this, please check [CommonJS vs. ES modules in Node.js](https://blog.logrocket.com/commonjs-vs-es-modules-node-js/). +- For backward compatibility, we also export `./tsconfigs/base.json` and `./tsconfigs/react.json`. However, you should update to the new syntax when configuring your `tsconfig.json` when possible. diff --git a/package.json b/package.json index 02d5590..26b4d1c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "import": "./dist/index.mjs" }, "./tsconfigs-base": "./tsconfigs/base.json", - "./tsconfigs-react": "./tsconfigs/react.json" + "./tsconfigs-react": "./tsconfigs/react.json", + "./tsconfigs/base.json": "./tsconfigs/base.json", + "./tsconfigs/react.json": "./tsconfigs/react.json" }, "files": [ "dist", @@ -15,7 +17,7 @@ ], "scripts": { "test": "tsc && eslint .", - "build": "npx rollup -c", + "build": "rollup -c", "format": "prettier --ignore-path .prettierignore --check \"**/*.+(js|ts|json)\"", "format:check": "pnpm run format", "format:fix": "prettier --ignore-path .prettierignore --write \"**/*.+(js|ts|json)\""