From f524668b8238180f383fd6944b64609954a96674 Mon Sep 17 00:00:00 2001 From: tal Date: Thu, 9 Nov 2023 20:22:13 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=94=A5=20allow=20TypeScript=20con?= =?UTF-8?q?figuration=20for=20Inflint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit allow TypeScript configuration for Inflint --- README.md | 4 +- package.json | 3 +- pnpm-lock.yaml | 56 +++++++++++++++---- src/modules/app/utils/merge-configurations.ts | 3 +- src/modules/configuration/index.ts | 2 + 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f97e151d..240610b9 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,7 @@ Configuration can be set in the following files: - a `package.json` property: `"inflint": {...}` - a `.inflintrc` file in JSON or YAML format - a `.inflintrc.json`, `.inflintrc.yaml`, `.inflintrc.yml`, `.inflintrc.js`, `.inflintrc.ts`, or `.inflintrc.cjs` file -- a `inflint.config.js`, or `inflint.config.cjs` CommonJS module exporting an object - -Currently, a TypeScript configuration file is not supported: https://github.com/Codex-/cosmiconfig-typescript-loader/issues/60 +- a `inflint.config.ts`, `inflint.config.js`, or `inflint.config.cjs` CommonJS module exporting an object ### Rules format When applying rules either via the CLI or other configuration, you must follow the rules format. diff --git a/package.json b/package.json index e9d81e65..7d1ef3ce 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,8 @@ "dependencies": { "@expo/spawn-async": "1.7.2", "chalk": "5.3.0", - "cosmiconfig": "8.1.3", + "cosmiconfig": "8.3.6", + "cosmiconfig-typescript-loader": "5.0.0", "fast-glob": "3.3.1", "micromatch": "4.0.5", "minimist": "1.2.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1068d099..2360c1ce 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,11 @@ dependencies: specifier: 5.3.0 version: 5.3.0 cosmiconfig: - specifier: 8.1.3 - version: 8.1.3 + specifier: 8.3.6 + version: 8.3.6(typescript@5.2.2) + cosmiconfig-typescript-loader: + specifier: 5.0.0 + version: 5.0.0(@types/node@20.5.1)(cosmiconfig@8.3.6)(typescript@5.2.2) fast-glob: specifier: 3.3.1 version: 3.3.1 @@ -238,8 +241,8 @@ packages: '@commitlint/types': 18.1.0 '@types/node': 18.18.8 chalk: 4.1.2 - cosmiconfig: 8.1.3 - cosmiconfig-typescript-loader: 5.0.0(@types/node@18.18.8)(cosmiconfig@8.1.3)(typescript@5.2.2) + cosmiconfig: 8.3.6(typescript@5.2.2) + cosmiconfig-typescript-loader: 5.0.0(@types/node@18.18.8)(cosmiconfig@8.3.6)(typescript@5.2.2) lodash.isplainobject: 4.0.6 lodash.merge: 4.6.2 lodash.uniq: 4.5.0 @@ -1032,7 +1035,6 @@ packages: /@types/node@20.5.1: resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==} - dev: true /@types/normalize-package-data@2.4.1: resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} @@ -1849,6 +1851,7 @@ packages: /clone@1.0.4: resolution: {integrity: sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==} engines: {node: '>=0.8'} + requiresBuild: true dev: true /color-convert@1.9.3: @@ -2014,7 +2017,7 @@ packages: - '@swc/wasm' dev: true - /cosmiconfig-typescript-loader@5.0.0(@types/node@18.18.8)(cosmiconfig@8.1.3)(typescript@5.2.2): + /cosmiconfig-typescript-loader@5.0.0(@types/node@18.18.8)(cosmiconfig@8.3.6)(typescript@5.2.2): resolution: {integrity: sha512-+8cK7jRAReYkMwMiG+bxhcNKiHJDM6bR9FD/nGBXOWdMLuYawjF5cGrtLilJ+LGd3ZjCXnJjR5DkfWPoIVlqJA==} engines: {node: '>=v16'} peerDependencies: @@ -2023,11 +2026,25 @@ packages: typescript: '>=4' dependencies: '@types/node': 18.18.8 - cosmiconfig: 8.1.3 + cosmiconfig: 8.3.6(typescript@5.2.2) jiti: 1.21.0 typescript: 5.2.2 dev: true + /cosmiconfig-typescript-loader@5.0.0(@types/node@20.5.1)(cosmiconfig@8.3.6)(typescript@5.2.2): + resolution: {integrity: sha512-+8cK7jRAReYkMwMiG+bxhcNKiHJDM6bR9FD/nGBXOWdMLuYawjF5cGrtLilJ+LGd3ZjCXnJjR5DkfWPoIVlqJA==} + engines: {node: '>=v16'} + peerDependencies: + '@types/node': '*' + cosmiconfig: '>=8.2' + typescript: '>=4' + dependencies: + '@types/node': 20.5.1 + cosmiconfig: 8.3.6(typescript@5.2.2) + jiti: 1.21.0 + typescript: 5.2.2 + dev: false + /cosmiconfig@7.0.1: resolution: {integrity: sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==} engines: {node: '>=10'} @@ -2057,6 +2074,22 @@ packages: js-yaml: 4.1.0 parse-json: 5.2.0 path-type: 4.0.0 + dev: true + + /cosmiconfig@8.3.6(typescript@5.2.2): + resolution: {integrity: sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==} + engines: {node: '>=14'} + peerDependencies: + typescript: '>=4.9.5' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + import-fresh: 3.3.0 + js-yaml: 4.1.0 + parse-json: 5.2.0 + path-type: 4.0.0 + typescript: 5.2.2 /create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} @@ -2296,6 +2329,7 @@ packages: /defaults@1.0.4: resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} + requiresBuild: true dependencies: clone: 1.0.4 dev: true @@ -3142,7 +3176,7 @@ packages: resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==} engines: {node: '>=12'} dependencies: - graceful-fs: 4.2.10 + graceful-fs: 4.2.11 jsonfile: 6.1.0 universalify: 2.0.0 dev: true @@ -3885,7 +3919,6 @@ packages: /jiti@1.21.0: resolution: {integrity: sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==} hasBin: true - dev: true /js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -3957,7 +3990,7 @@ packages: dependencies: universalify: 2.0.0 optionalDependencies: - graceful-fs: 4.2.10 + graceful-fs: 4.2.11 dev: true /jsonparse@1.3.1: @@ -4072,7 +4105,7 @@ packages: resolution: {integrity: sha512-gUD/epcRms75Cw8RT1pUdHugZYM5ce64ucs2GEISABwkRsOQr0q2wm/MV2TKThycIe5e0ytRweW2RZxclogCdQ==} engines: {node: '>=8'} dependencies: - graceful-fs: 4.2.10 + graceful-fs: 4.2.11 parse-json: 5.2.0 strip-bom: 4.0.0 type-fest: 0.6.0 @@ -5765,7 +5798,6 @@ packages: resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} engines: {node: '>=14.17'} hasBin: true - dev: true /unbox-primitive@1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} diff --git a/src/modules/app/utils/merge-configurations.ts b/src/modules/app/utils/merge-configurations.ts index 43b01391..56c030e4 100644 --- a/src/modules/app/utils/merge-configurations.ts +++ b/src/modules/app/utils/merge-configurations.ts @@ -1,6 +1,7 @@ import path from 'node:path'; import { cosmiconfig } from 'cosmiconfig'; +import { TypeScriptLoader } from 'cosmiconfig-typescript-loader'; import type { IBaseConfiguration, ISourceConfiguration } from '@/interfaces/configuration'; import { withCleanObject } from '@/utils/object'; @@ -56,7 +57,7 @@ export const recurseSourceConfiguration = async ( } const extendsFilePath = path.join(configPath, '..', config.extends); - const explorer = cosmiconfig(''); + const explorer = cosmiconfig('', { loaders: { '.ts': TypeScriptLoader() } }); const result = await explorer.load(extendsFilePath).catch(() => null); if (!result) { diff --git a/src/modules/configuration/index.ts b/src/modules/configuration/index.ts index 951b44f4..5d1d0505 100644 --- a/src/modules/configuration/index.ts +++ b/src/modules/configuration/index.ts @@ -2,6 +2,7 @@ import path from 'node:path'; import { cosmiconfig } from 'cosmiconfig'; import type { CosmiconfigResult } from 'cosmiconfig/dist/types'; +import { TypeScriptLoader } from 'cosmiconfig-typescript-loader'; import type { ISourceConfiguration } from '@/interfaces/configuration'; import CLILoggerModule from '@/shared/modules/cli-logger'; @@ -15,6 +16,7 @@ const StartConfiguration = async ( ): Promise<[ISourceConfiguration, string | undefined] | null> => { const explorer = cosmiconfig(CONFIGURATION_MODULE_NAME, { searchPlaces: configFilePath ? [configFilePath] : DEFAULT_SEARCH_PLACES, + loaders: { '.ts': TypeScriptLoader() }, }); let result: CosmiconfigResult | null;