Skip to content

Commit

Permalink
feat: add cjs projects support
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Aug 4, 2023
1 parent 25c1051 commit 9ed6129
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
30 changes: 30 additions & 0 deletions lib/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @fileoverview eslint ignore files automatically(cjs projects).
* @author 唯然<[email protected]>
*/
const process = require("process");
const fs = require("fs");
const path = require("path");

/**
* @param {object} [opts]
* @param {string} [opts.cwd]
* @param {string} [opts.filename]
* @param {string[]?} [opts.extraIgnores]
* @returns {{ignores: string[]}} the list of ignored files
*/
module.exports.ignores = function ignores(opts = {}) {
const ignoreFile = path.join(
opts.cwd || process.cwd(),
opts.filename || ".gitignore"
);
const text = fs.readFileSync(ignoreFile, "utf-8");
const lines = text
.split(/(\r\n|\n)+/)
.map((line) => line.trim())
.filter((line) => line && !line.startsWith("#"));

return {
ignores: [...lines, ...(opts.extraIgnores || [])],
};
}
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview eslint ignore files automatically.
* @fileoverview eslint ignore files automatically(esm projects).
* @author 唯然<[email protected]>
*/
import process from "process";
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
"author": "唯然<[email protected]",
"type": "module",
"main": "./lib/index.js",
"exports": "./lib/index.js",
"exports": {
".": {
"require": "./lib/index.js",
"import": "./lib/index.js",
"typings": "./lib/index.d.ts"
}
},
"typings": "./lib/index.d.ts",
"files": [
"LICENSE",
Expand Down

0 comments on commit 9ed6129

Please sign in to comment.