@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 CHANGED
@@ -8,7 +8,16 @@ interface ESLintConfig {
8
8
  dependencies: string[];
9
9
  payload: Payload;
10
10
  }
11
- declare const readFlatConfig: (root: string) => Promise<ESLintConfig>;
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, readFlatConfig };
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 resolveConfigPath = (root) => {
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 readFlatConfig = async (root) => {
33
- const { basePath, fullPath } = resolveConfigPath(root);
34
- const { dependencies, mod } = await runInDirectory(basePath, async () => {
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 { readFlatConfig };
145
+ export { resolveFlatConfig };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sushichan044/eslint-config-array-resolver",
3
3
  "description": "Resolves flat config module. For internal use only.",
4
- "version": "0.0.1",
4
+ "version": "0.1.0",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "author": {