@ttoss/read-config-file 2.0.1 → 2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/read-config-file",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Read a configuration file",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -33,7 +33,7 @@
33
33
  "@types/react": "^18.3.7",
34
34
  "jest": "^29.7.0",
35
35
  "tsup": "^8.3.0",
36
- "@ttoss/config": "^1.32.10",
36
+ "@ttoss/config": "^1.33.0",
37
37
  "@ttoss/read-config-file-test": "^1.0.1"
38
38
  },
39
39
  "keywords": [
package/dist/esm/index.js DELETED
@@ -1,91 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- var __require = /* @__PURE__ */(x => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function (x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/loadConfig.ts
10
- import * as esbuild from "esbuild";
11
- import importSync from "import-sync";
12
- import path from "node:path";
13
- var loadConfig = entryPoint => {
14
- const lastEntryPointName = entryPoint.split("/").pop();
15
- const filename = lastEntryPointName?.split(".")[0];
16
- const outfile = path.resolve(process.cwd(), "out", filename + ".js");
17
- const result = esbuild.buildSync({
18
- bundle: true,
19
- entryPoints: [entryPoint],
20
- /**
21
- * ttoss packages cannot be market as external because it'd break the CI.
22
- * On CI, ttoss packages point to the TS main file, not the compiled
23
- * ones. See more details here https://github.com/ttoss/ttoss/issues/541.
24
- */
25
- external: [],
26
- format: "cjs",
27
- outfile,
28
- platform: "node",
29
- target: "ES2021",
30
- treeShaking: true
31
- });
32
- if (result.errors.length > 0) {
33
- console.error("Error building config file: ", filename);
34
- throw result.errors;
35
- }
36
- try {
37
- const config = importSync(outfile);
38
- return config.default || config.config;
39
- } catch (error) {
40
- console.error("Failed importing build config file: ", filename);
41
- throw error;
42
- }
43
- };
44
-
45
- // src/index.ts
46
- import fs from "fs";
47
- import yaml from "js-yaml";
48
- var readConfigFileSync = ({
49
- configFilePath,
50
- options
51
- }) => {
52
- const extension = configFilePath.split(".").pop();
53
- if (extension === "yaml" || extension === "yml") {
54
- const file = fs.readFileSync(configFilePath, "utf8");
55
- return yaml.load(file);
56
- }
57
- if (extension === "json") {
58
- const file = fs.readFileSync(configFilePath, "utf8");
59
- return JSON.parse(file);
60
- }
61
- if (extension === "js") {
62
- return __require(configFilePath);
63
- }
64
- if (extension === "ts") {
65
- let result = loadConfig(configFilePath);
66
- if (typeof result === "function") {
67
- result = result(options);
68
- }
69
- return result;
70
- }
71
- throw new Error("Unsupported config file extension: " + extension);
72
- };
73
- var readConfigFile = async ({
74
- configFilePath,
75
- options
76
- }) => {
77
- const extension = configFilePath.split(".").pop();
78
- if (extension === "ts") {
79
- let result = loadConfig(configFilePath);
80
- if (typeof result === "function") {
81
- result = result(options);
82
- }
83
- result = await Promise.resolve(result);
84
- return result;
85
- }
86
- return readConfigFileSync({
87
- configFilePath,
88
- options
89
- });
90
- };
91
- export { readConfigFile, readConfigFileSync };
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- type ConfigInput = {
2
- configFilePath: string;
3
- options?: any;
4
- };
5
- declare const readConfigFileSync: <ConfigFile = unknown>({ configFilePath, options, }: ConfigInput) => ConfigFile;
6
- declare const readConfigFile: <ConfigFile = unknown>({ configFilePath, options, }: ConfigInput) => Promise<ConfigFile>;
7
-
8
- export { readConfigFile, readConfigFileSync };