@ttoss/read-config-file 1.0.2 → 1.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/esm/index.js CHANGED
@@ -8,7 +8,6 @@ var __require = /* @__PURE__ */(x => typeof require !== "undefined" ? require :
8
8
 
9
9
  // src/loadConfig.ts
10
10
  import * as esbuild from "esbuild";
11
- import { typescriptConfig } from "@ttoss/config";
12
11
  import importSync from "import-sync";
13
12
  import path from "path";
14
13
  var loadConfig = entryPoint => {
@@ -27,7 +26,7 @@ var loadConfig = entryPoint => {
27
26
  format: "cjs",
28
27
  outfile,
29
28
  platform: "node",
30
- target: typescriptConfig.target,
29
+ target: "ES2021",
31
30
  treeShaking: true
32
31
  });
33
32
  if (result.errors.length > 0) {
@@ -47,7 +46,8 @@ var loadConfig = entryPoint => {
47
46
  import fs from "fs";
48
47
  import yaml from "js-yaml";
49
48
  var readConfigFileSync = ({
50
- configFilePath
49
+ configFilePath,
50
+ options
51
51
  }) => {
52
52
  const extension = configFilePath.split(".").pop();
53
53
  if (extension === "yaml" || extension === "yml") {
@@ -64,26 +64,28 @@ var readConfigFileSync = ({
64
64
  if (extension === "ts") {
65
65
  let result = loadConfig(configFilePath);
66
66
  if (typeof result === "function") {
67
- result = result();
67
+ result = result(options);
68
68
  }
69
69
  return result;
70
70
  }
71
71
  throw new Error("Unsupported config file extension: " + extension);
72
72
  };
73
73
  var readConfigFile = async ({
74
- configFilePath
74
+ configFilePath,
75
+ options
75
76
  }) => {
76
77
  const extension = configFilePath.split(".").pop();
77
78
  if (extension === "ts") {
78
79
  let result = loadConfig(configFilePath);
79
80
  if (typeof result === "function") {
80
- result = result();
81
+ result = result(options);
81
82
  }
82
83
  result = await Promise.resolve(result);
83
84
  return result;
84
85
  }
85
86
  return readConfigFileSync({
86
- configFilePath
87
+ configFilePath,
88
+ options
87
89
  });
88
90
  };
89
91
  export { readConfigFile, readConfigFileSync };
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  type ConfigInput = {
2
2
  configFilePath: string;
3
+ options?: any;
3
4
  };
4
- declare const readConfigFileSync: <ConfigFile = unknown>({ configFilePath, }: ConfigInput) => ConfigFile;
5
- declare const readConfigFile: <ConfigFile = unknown>({ configFilePath, }: ConfigInput) => Promise<ConfigFile>;
5
+ declare const readConfigFileSync: <ConfigFile = unknown>({ configFilePath, options, }: ConfigInput) => ConfigFile;
6
+ declare const readConfigFile: <ConfigFile = unknown>({ configFilePath, options, }: ConfigInput) => Promise<ConfigFile>;
6
7
 
7
8
  export { readConfigFile, readConfigFileSync };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  type ConfigInput = {
2
2
  configFilePath: string;
3
+ options?: any;
3
4
  };
4
- declare const readConfigFileSync: <ConfigFile = unknown>({ configFilePath, }: ConfigInput) => ConfigFile;
5
- declare const readConfigFile: <ConfigFile = unknown>({ configFilePath, }: ConfigInput) => Promise<ConfigFile>;
5
+ declare const readConfigFileSync: <ConfigFile = unknown>({ configFilePath, options, }: ConfigInput) => ConfigFile;
6
+ declare const readConfigFile: <ConfigFile = unknown>({ configFilePath, options, }: ConfigInput) => Promise<ConfigFile>;
6
7
 
7
8
  export { readConfigFile, readConfigFileSync };
package/dist/index.js CHANGED
@@ -45,7 +45,6 @@ module.exports = __toCommonJS(src_exports);
45
45
 
46
46
  // src/loadConfig.ts
47
47
  var esbuild = __toESM(require("esbuild"), 1);
48
- var import_config = require("@ttoss/config");
49
48
  var import_import_sync = __toESM(require("import-sync"), 1);
50
49
  var import_node_path = __toESM(require("path"), 1);
51
50
  var loadConfig = entryPoint => {
@@ -64,7 +63,7 @@ var loadConfig = entryPoint => {
64
63
  format: "cjs",
65
64
  outfile,
66
65
  platform: "node",
67
- target: import_config.typescriptConfig.target,
66
+ target: "ES2021",
68
67
  treeShaking: true
69
68
  });
70
69
  if (result.errors.length > 0) {
@@ -84,7 +83,8 @@ var loadConfig = entryPoint => {
84
83
  var import_fs = __toESM(require("fs"), 1);
85
84
  var import_js_yaml = __toESM(require("js-yaml"), 1);
86
85
  var readConfigFileSync = ({
87
- configFilePath
86
+ configFilePath,
87
+ options
88
88
  }) => {
89
89
  const extension = configFilePath.split(".").pop();
90
90
  if (extension === "yaml" || extension === "yml") {
@@ -101,26 +101,28 @@ var readConfigFileSync = ({
101
101
  if (extension === "ts") {
102
102
  let result = loadConfig(configFilePath);
103
103
  if (typeof result === "function") {
104
- result = result();
104
+ result = result(options);
105
105
  }
106
106
  return result;
107
107
  }
108
108
  throw new Error("Unsupported config file extension: " + extension);
109
109
  };
110
110
  var readConfigFile = async ({
111
- configFilePath
111
+ configFilePath,
112
+ options
112
113
  }) => {
113
114
  const extension = configFilePath.split(".").pop();
114
115
  if (extension === "ts") {
115
116
  let result = loadConfig(configFilePath);
116
117
  if (typeof result === "function") {
117
- result = result();
118
+ result = result(options);
118
119
  }
119
120
  result = await Promise.resolve(result);
120
121
  return result;
121
122
  }
122
123
  return readConfigFileSync({
123
- configFilePath
124
+ configFilePath,
125
+ options
124
126
  });
125
127
  };
126
128
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/read-config-file",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Read a configuration file",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -23,10 +23,9 @@
23
23
  "src"
24
24
  ],
25
25
  "dependencies": {
26
- "esbuild": "^0.20.2",
26
+ "esbuild": "^0.21.3",
27
27
  "import-sync": "^2.2.2",
28
- "js-yaml": "^4.1.0",
29
- "@ttoss/config": "^1.32.3"
28
+ "js-yaml": "^4.1.0"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@types/jest": "^29.5.12",
@@ -34,6 +33,7 @@
34
33
  "@types/react": "^18.2.79",
35
34
  "jest": "^29.7.0",
36
35
  "tsup": "^8.0.2",
36
+ "@ttoss/config": "^1.32.4",
37
37
  "@ttoss/read-config-file-test": "^1.0.1"
38
38
  },
39
39
  "keywords": [
package/src/index.ts CHANGED
@@ -4,10 +4,13 @@ import yaml from 'js-yaml';
4
4
 
5
5
  type ConfigInput = {
6
6
  configFilePath: string;
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ options?: any;
7
9
  };
8
10
 
9
11
  export const readConfigFileSync = <ConfigFile = unknown>({
10
12
  configFilePath,
13
+ options,
11
14
  }: ConfigInput): ConfigFile => {
12
15
  const extension = configFilePath.split('.').pop();
13
16
 
@@ -28,7 +31,7 @@ export const readConfigFileSync = <ConfigFile = unknown>({
28
31
  if (extension === 'ts') {
29
32
  let result = loadConfig(configFilePath);
30
33
  if (typeof result === 'function') {
31
- result = result();
34
+ result = result(options);
32
35
  }
33
36
  return result as ConfigFile;
34
37
  }
@@ -38,17 +41,18 @@ export const readConfigFileSync = <ConfigFile = unknown>({
38
41
 
39
42
  export const readConfigFile = async <ConfigFile = unknown>({
40
43
  configFilePath,
44
+ options,
41
45
  }: ConfigInput): Promise<ConfigFile> => {
42
46
  const extension = configFilePath.split('.').pop();
43
47
 
44
48
  if (extension === 'ts') {
45
49
  let result = loadConfig(configFilePath);
46
50
  if (typeof result === 'function') {
47
- result = result();
51
+ result = result(options);
48
52
  }
49
53
  result = await Promise.resolve(result);
50
54
  return result as ConfigFile;
51
55
  }
52
56
 
53
- return readConfigFileSync({ configFilePath });
57
+ return readConfigFileSync({ configFilePath, options });
54
58
  };
package/src/loadConfig.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as esbuild from 'esbuild';
2
- import { typescriptConfig } from '@ttoss/config';
3
2
  import importSync from 'import-sync';
4
3
  import path from 'node:path';
5
4
 
@@ -22,7 +21,7 @@ export const loadConfig = <T>(entryPoint: string): T | undefined => {
22
21
  format: 'cjs',
23
22
  outfile,
24
23
  platform: 'node',
25
- target: typescriptConfig.target,
24
+ target: 'ES2021',
26
25
  treeShaking: true,
27
26
  });
28
27