@sushichan044/eslint-config-array-resolver 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +11 -2
- package/dist/index.js +39 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,16 @@ interface ESLintConfig {
|
|
|
8
8
|
dependencies: string[];
|
|
9
9
|
payload: Payload;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Traverse and find the ESLint config file.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
interface ReadFlatConfigOptions {
|
|
18
|
+
suppressOutput?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare const resolveFlatConfig: (root: string, options?: ReadFlatConfigOptions) => Promise<ESLintConfig>;
|
|
12
21
|
interface FlatConfigItem extends Linter.Config {
|
|
13
22
|
index: number;
|
|
14
23
|
}
|
|
@@ -33,4 +42,4 @@ interface RuleInfo extends RuleMetaData<string, unknown> {
|
|
|
33
42
|
plugin: string;
|
|
34
43
|
}
|
|
35
44
|
//#endregion
|
|
36
|
-
export { type ESLintConfig, type RuleInfo,
|
|
45
|
+
export { type ESLintConfig, type RuleInfo, resolveFlatConfig };
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,38 @@ const runInDirectory = async (directory, function_) => {
|
|
|
14
14
|
const isNonEmptyString = (maybeString) => {
|
|
15
15
|
return typeof maybeString === "string" && maybeString !== "";
|
|
16
16
|
};
|
|
17
|
-
const
|
|
17
|
+
const NO_OP_FN = () => {};
|
|
18
|
+
const NO_RESULT = Symbol("NO_RESULT");
|
|
19
|
+
const executeWithSilentLogs = async (function_) => {
|
|
20
|
+
const original = {
|
|
21
|
+
debug: console.debug,
|
|
22
|
+
info: console.info,
|
|
23
|
+
log: console.log
|
|
24
|
+
};
|
|
25
|
+
console.log = NO_OP_FN;
|
|
26
|
+
console.info = NO_OP_FN;
|
|
27
|
+
console.debug = NO_OP_FN;
|
|
28
|
+
let res = {
|
|
29
|
+
data: NO_RESULT,
|
|
30
|
+
err: /* @__PURE__ */ new Error("No result returned from the callback")
|
|
31
|
+
};
|
|
32
|
+
try {
|
|
33
|
+
res = {
|
|
34
|
+
data: await function_(),
|
|
35
|
+
err: null
|
|
36
|
+
};
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof Error) res.err = error;
|
|
39
|
+
else res.err = new Error(String(error));
|
|
40
|
+
} finally {
|
|
41
|
+
console.log = original.log;
|
|
42
|
+
console.info = original.info;
|
|
43
|
+
console.debug = original.debug;
|
|
44
|
+
}
|
|
45
|
+
if (res.err) throw res.err;
|
|
46
|
+
return res.data;
|
|
47
|
+
};
|
|
48
|
+
const findConfigPath = (root) => {
|
|
18
49
|
const configPath = any([
|
|
19
50
|
"eslint.config.js",
|
|
20
51
|
"eslint.config.mjs",
|
|
@@ -29,15 +60,18 @@ const resolveConfigPath = (root) => {
|
|
|
29
60
|
fullPath: configPath
|
|
30
61
|
};
|
|
31
62
|
};
|
|
32
|
-
const
|
|
33
|
-
const {
|
|
34
|
-
const {
|
|
63
|
+
const resolveFlatConfig = async (root, options = {}) => {
|
|
64
|
+
const { suppressOutput = false } = options;
|
|
65
|
+
const { basePath, fullPath } = findConfigPath(root);
|
|
66
|
+
const moduleImportPromise = runInDirectory(basePath, async () => {
|
|
35
67
|
return bundleRequire({
|
|
36
68
|
cwd: basePath,
|
|
37
69
|
filepath: fullPath,
|
|
38
70
|
tsconfig: false
|
|
39
71
|
});
|
|
40
72
|
});
|
|
73
|
+
const importPromise = suppressOutput ? executeWithSilentLogs(async () => moduleImportPromise) : moduleImportPromise;
|
|
74
|
+
const { dependencies, mod } = await importPromise;
|
|
41
75
|
const configModule = await (mod.default ?? mod);
|
|
42
76
|
const rawConfigs = Array.isArray(configModule) ? configModule : [configModule];
|
|
43
77
|
rawConfigs.unshift({
|
|
@@ -108,4 +142,4 @@ const readFlatConfig = async (root) => {
|
|
|
108
142
|
payload
|
|
109
143
|
};
|
|
110
144
|
};
|
|
111
|
-
export {
|
|
145
|
+
export { resolveFlatConfig };
|