@sushichan044/eslint-config-array-resolver 0.0.1 → 0.0.2

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,10 @@ interface ESLintConfig {
8
8
  dependencies: string[];
9
9
  payload: Payload;
10
10
  }
11
- declare const readFlatConfig: (root: string) => Promise<ESLintConfig>;
11
+ interface ReadFlatConfigOptions {
12
+ suppressOutput?: boolean;
13
+ }
14
+ declare const readFlatConfig: (root: string, options?: ReadFlatConfigOptions) => Promise<ESLintConfig>;
12
15
  interface FlatConfigItem extends Linter.Config {
13
16
  index: number;
14
17
  }
package/dist/index.js CHANGED
@@ -14,6 +14,37 @@ const runInDirectory = async (directory, function_) => {
14
14
  const isNonEmptyString = (maybeString) => {
15
15
  return typeof maybeString === "string" && maybeString !== "";
16
16
  };
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
+ };
17
48
  const resolveConfigPath = (root) => {
18
49
  const configPath = any([
19
50
  "eslint.config.js",
@@ -29,15 +60,18 @@ const resolveConfigPath = (root) => {
29
60
  fullPath: configPath
30
61
  };
31
62
  };
32
- const readFlatConfig = async (root) => {
63
+ const readFlatConfig = async (root, options = {}) => {
64
+ const { suppressOutput = false } = options;
33
65
  const { basePath, fullPath } = resolveConfigPath(root);
34
- const { dependencies, mod } = await runInDirectory(basePath, async () => {
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({
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.0.2",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "author": {