Skip to content

Commit

Permalink
fix: 配置文件支持 cjs、js、mjs 后缀类型,以解决 ESM 模块项目下加载配置文件异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed Jun 5, 2024
1 parent 1d179d1 commit fd4a667
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 40 deletions.
23 changes: 10 additions & 13 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
- `jira` 自定义关联 jira 的检测逻辑(TODO: 方案说明)
- more...


![](./assets/img/flh.png)

<p style="text-align: center">方案流程图</p>
Expand All @@ -53,7 +52,7 @@ npm i -D @lzwme/fed-lint-helper
```bash
flh --help

# 在当前目录下生成默认的配置文件 .flh.config.js
# 在当前目录下生成默认的配置文件 .flh.config.cjs
flh init --config

# typescript check
Expand Down Expand Up @@ -110,20 +109,19 @@ import { TsCheck, ESLintCheck } from '@lzwme/fed-lint-helper';

// typescript check
const tsCheck = new TsCheck({
exitOnError: false,
src: ['src'],
// checkOnInit: false,
// debug: true,
// toWhiteList: true,
// cache: true,
// removeCache: false,
// tsConfigFileName: 'tsconfig.eslint.json',
// silent: false,
exitOnError: false,
src: ['src'],
// checkOnInit: false,
// debug: true,
// toWhiteList: true,
// cache: true,
// removeCache: false,
// tsConfigFileName: 'tsconfig.eslint.json',
// silent: false,
});
const res = await tsCheck.start();
console.log(res);


// eslint check
const eslintCheck = new ESLintCheck({
exitOnError: false,
Expand Down Expand Up @@ -177,7 +175,6 @@ pnpm dev

该插件由[志文工作室](https://lzw.me)开发和维护。


[stars-badge]: https://img.shields.io/github/stars/lzwme/fed-lint-helper.svg
[stars-url]: https://github.com/lzwme/fed-lint-helper/stargazers
[forks-badge]: https://img.shields.io/github/forks/lzwme/fed-lint-helper.svg
Expand Down
11 changes: 11 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
/*
* @Author: renxia
* @Date: 2024-04-10 10:10:45
* @LastEditors: renxia
* @LastEditTime: 2024-06-05 14:36:13
* @Description:
*/
// module.exports = [
// ...require('./preset/eslint'),
// ];
const path = require('path');
const eslint = require('@eslint/js');
const tseslint = require('typescript-eslint');
const globals = require('globals');

module.exports = [
...tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
globals: {
...globals.node,
},
parserOptions: {
tsconfigRootDir: path.resolve(__dirname),
project: path.resolve('./tsconfig.eslint.json'),
Expand Down
41 changes: 20 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,41 @@
"bin"
],
"dependencies": {
"@lzwme/fe-utils": "^1.7.2",
"commander": "^12.0.0",
"console-log-colors": "^0.4.0",
"@lzwme/fe-utils": "^1.7.3",
"commander": "^12.1.0",
"console-log-colors": "^0.5.0",
"enquirer": "^2.4.1",
"fast-glob": "^3.3.2",
"micromatch": "^4.0.5"
"micromatch": "^4.0.7"
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@eslint/js": "^9.4.0",
"@jest/core": "^29.7.0",
"@jest/test-result": "^29.7.0",
"@jest/types": "^29.6.3",
"@node-rs/deno-lint": "^1.20.1",
"@types/eslint": "^8.56.7",
"@node-rs/deno-lint": "^1.20.4",
"@types/eslint": "^8.56.10",
"@types/jest": "^29.5.12",
"@types/micromatch": "^4.0.6",
"@types/node": "^20.12.6",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"eslint": "^9.0.0",
"@types/micromatch": "^4.0.7",
"@types/node": "^20.14.1",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"eslint": "^9.4.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.2.0",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^52.0.0",
"eslint-plugin-unicorn": "^53.0.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"prettier": "^3.3.0",
"standard-version": "^9.5.0",
"stylelint": "^16.3.1",
"ts-jest": "^29.1.2",
"stylelint": "^16.6.1",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typescript": "^5.4.4",
"typescript-eslint": "^7.6.0"
"typescript": "^5.4.5",
"typescript-eslint": "^7.12.0"
},
"peerDependencies": {
"@jest/core": "*"
Expand All @@ -110,6 +110,5 @@
"@jest/core": {
"optional": true
}
},
"packageManager": "[email protected]"
}
}
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ program
// .aliases(['flh'])
.version(FlhPkgInfo.version, '-v, --version')
.description(cyanBright(FlhPkgInfo.description))
.option('-c, --config-path <filepath>', `配置文件 ${yellowBright('.flh.config.js')} 的路径`)
.option('-c, --config-path <filepath>', `配置文件 ${yellowBright('.flh.config.cjs')} 的路径`)
.option('--silent', `开启静默模式。`)
.option('--debug', `开启调试模式。`)
.option('--ci', `Whether to run task in continuous integration (CI) mode.`)
Expand Down
12 changes: 7 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* @Author: lzw
* @Date: 2021-09-25 16:15:03
* @LastEditors: renxia
* @LastEditTime: 2024-01-18 14:57:23
* @LastEditTime: 2024-06-05 14:34:26
* @Description:
*/

import { existsSync, mkdirSync } from 'node:fs';
import { resolve, dirname } from 'node:path';
import { resolve, dirname, extname } from 'node:path';
import { homedir } from 'node:os';
import { env } from 'node:process';
// import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const commConfig: CommConfig = {

export const config: FlhConfig = {
...commConfig,
configPath: '.flh.config.js',
configPath: '.flh.config.cjs',
packages: {},
ci: Boolean(env.CI || env.GITLAB_CI || env.JENKINS_HOME || env.FLH_CI),
logValidityDays: 7,
Expand Down Expand Up @@ -125,8 +125,10 @@ export function getConfig(options?: FlhConfig, useCache = true) {

// 配置文件只处理一次
if (!isInited) {
const configPath = resolve(config.configPath);
if (existsSync(configPath)) {
const ext = extname(config.configPath);
const extList = ['.cjs', '.js', '.mjs', ext];
const configPath = extList.find(d => existsSync(resolve(config.configPath.replace(ext, d))));
if (configPath) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const d = require(configPath);
Expand Down

0 comments on commit fd4a667

Please sign in to comment.