@storm-software/config-tools 1.35.7 → 1.36.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## 1.36.1 (2024-04-13)
2
+
3
+
4
+ ### 🩹 Fixes
5
+
6
+ - **build-tools:** Update the path provided to include TypeScript declarations ([a1a74b21](https://github.com/storm-software/storm-ops/commit/a1a74b21))
7
+
8
+
9
+ ### ❤️ Thank You
10
+
11
+ - Patrick Sullivan
12
+
13
+ ## 1.36.0 (2024-04-09)
14
+
15
+
16
+ ### 🚀 Features
17
+
18
+ - **config-tools:** Significant improvements to logic to get config files ([0a0ac895](https://github.com/storm-software/storm-ops/commit/0a0ac895))
19
+
20
+
21
+ ### ❤️ Thank You
22
+
23
+ - Patrick Sullivan
24
+
1
25
  ## 1.35.7 (2024-04-08)
2
26
 
3
27
 
package/README.md CHANGED
@@ -16,7 +16,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages
16
16
 
17
17
  <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
18
18
 
19
- [![Version](https://img.shields.io/badge/version-1.35.6-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
19
+ [![Version](https://img.shields.io/badge/version-1.35.7-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
20
20
  [![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://docusaurus.io/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
21
21
 
22
22
  > [!IMPORTANT]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storm-software/config-tools",
3
- "version": "1.35.7",
3
+ "version": "1.36.1",
4
4
  "private": false,
5
5
  "description": "⚡The Storm-Ops monorepo contains utility applications, tools, and various libraries to create modern and scalable web applications.",
6
6
  "repository": {
@@ -11,8 +11,10 @@
11
11
  "main": "./index.js",
12
12
  "types": "declarations.d.ts",
13
13
  "dependencies": {
14
- "chalk": "4.1.2",
14
+ "c12": "^1.10.0",
15
+ "chalk": "5.3.0",
15
16
  "cosmiconfig": "9.0.0",
17
+ "deepmerge": "4.3.1",
16
18
  "zod": "3.22.4"
17
19
  },
18
20
  "publishConfig": {
@@ -1,35 +1,10 @@
1
- import type { CosmiconfigResult, PublicExplorer, Config } from "cosmiconfig";
2
1
  import type { StormConfigInput } from "@storm-software/config";
3
- import { join } from "node:path";
4
2
  import { findWorkspaceRoot } from "../utilities/find-workspace-root";
5
- import { readFile, stat } from "node:fs/promises";
3
+ import { loadConfig } from "c12";
4
+ import merge from "deepmerge";
6
5
 
7
- let _cosmiconfig: any = undefined;
8
- let defaultExplorer: PublicExplorer | undefined;
9
-
10
- /**
11
- * Get the config file for the current Storm workspace
12
- *
13
- * @param fileName - The name of the config file to search for
14
- * @param filePath - The path to search for the config file in
15
- * @returns The config file for the current Storm workspace
16
- */
17
- export const getConfigFileExplorer = async (
18
- fileName: string
19
- ): Promise<PublicExplorer | undefined> => {
20
- if (!_cosmiconfig) {
21
- const mod = await import("cosmiconfig");
22
- if (mod?.cosmiconfig) {
23
- _cosmiconfig = mod.cosmiconfig;
24
- }
25
-
26
- if (!_cosmiconfig) {
27
- return undefined;
28
- }
29
- }
30
-
31
- return _cosmiconfig(fileName, { cache: true });
32
- };
6
+ // let _cosmiconfig: any = undefined;
7
+ // let defaultExplorer: PublicExplorer | undefined;
33
8
 
34
9
  /**
35
10
  * Get the config file for the current Storm workspace
@@ -41,36 +16,13 @@ export const getConfigFileExplorer = async (
41
16
  export const getConfigFileByName = async (
42
17
  fileName: string,
43
18
  filePath?: string
44
- ): Promise<CosmiconfigResult | undefined> => {
45
- return (await getConfigFileExplorer(fileName))?.search(filePath);
46
- };
47
-
48
- /**
49
- * Get the config file for the current Storm workspace
50
- *
51
- * @param fileName - The name of the config file to search for
52
- * @param filePath - The path to search for the config file in
53
- * @returns The config file for the current Storm workspace
54
- */
55
- export const getJsonConfigFile = async (
56
- fileName: string,
57
- filePath?: string
58
- ): Promise<CosmiconfigResult | undefined> => {
59
- // const fse = await import("fs-extra/esm");
60
-
61
- const jsonPath = join(
62
- filePath ?? process.cwd(),
63
- fileName.endsWith(".json") ? fileName : `${fileName}.json`
64
- );
65
- const isEmpty = !!(await stat(jsonPath).catch((_) => false));
19
+ ): Promise<Partial<StormConfigInput> | undefined> => {
20
+ const workspacePath = filePath ? filePath : findWorkspaceRoot(filePath);
66
21
 
67
- return isEmpty
68
- ? {
69
- config: JSON.parse(await readFile(jsonPath, "utf-8")),
70
- filepath: jsonPath,
71
- isEmpty
72
- }
73
- : { config: {} as Config, filepath: jsonPath, isEmpty };
22
+ return loadConfig<Partial<StormConfigInput>>({
23
+ cwd: workspacePath,
24
+ name: fileName
25
+ });
74
26
  };
75
27
 
76
28
  /**
@@ -84,45 +36,33 @@ export const getConfigFile = async (
84
36
  ): Promise<Partial<StormConfigInput> | undefined> => {
85
37
  const workspacePath = filePath ? filePath : findWorkspaceRoot(filePath);
86
38
 
87
- // let cosmiconfigResult = await getJsonConfigFile("storm", workspacePath);
88
- // if (!cosmiconfigResult || cosmiconfigResult.isEmpty) {
89
- if (!defaultExplorer) {
90
- defaultExplorer = await getConfigFileExplorer("storm");
91
- }
92
-
93
- let cosmiconfigResult: any = null;
94
- if (defaultExplorer) {
95
- cosmiconfigResult = await defaultExplorer.search(workspacePath);
96
- }
97
-
98
- if ((!cosmiconfigResult || cosmiconfigResult.isEmpty) && additionalFileNames.length > 0) {
99
- for (const additionalFileName of additionalFileNames) {
100
- cosmiconfigResult = await getJsonConfigFile(additionalFileName, workspacePath);
101
- if (cosmiconfigResult && !cosmiconfigResult.isEmpty) {
102
- break;
103
- }
104
-
105
- cosmiconfigResult = await getConfigFileByName(additionalFileName, workspacePath);
106
- if (cosmiconfigResult && !cosmiconfigResult.isEmpty) {
107
- break;
39
+ let { config, configFile } = await loadConfig<Partial<StormConfigInput>>({
40
+ cwd: workspacePath,
41
+ name: "storm"
42
+ });
43
+
44
+ if (additionalFileNames) {
45
+ const results = await Promise.all(
46
+ additionalFileNames.map(fileName =>
47
+ loadConfig({
48
+ cwd: workspacePath,
49
+ name: fileName
50
+ })
51
+ )
52
+ );
53
+
54
+ for (const result of results) {
55
+ if (result) {
56
+ config = merge(config ?? {}, result.config ?? {});
108
57
  }
109
58
  }
110
59
  }
111
- // }
112
60
 
113
- if (
114
- !cosmiconfigResult ||
115
- Object.keys(cosmiconfigResult).length === 0 ||
116
- cosmiconfigResult.isEmpty ||
117
- !cosmiconfigResult.filepath
118
- ) {
61
+ if (!config) {
119
62
  return undefined;
120
63
  }
121
64
 
122
- const config: Partial<StormConfigInput> = cosmiconfigResult.config ?? {};
123
- if (cosmiconfigResult.filepath) {
124
- config.configFile = cosmiconfigResult.filepath;
125
- }
65
+ config.configFile = configFile;
126
66
  config.runtimeVersion = "0.0.1";
127
67
 
128
68
  return config;
@@ -25,7 +25,8 @@ export const createConfig = (workspaceRoot?: string): StormConfig => {
25
25
  * @returns The config for the current Storm workspace
26
26
  */
27
27
  export const createStormConfig = <
28
- TExtensionName extends keyof StormConfig["extensions"] = keyof StormConfig["extensions"],
28
+ TExtensionName extends
29
+ keyof StormConfig["extensions"] = keyof StormConfig["extensions"],
29
30
  TExtensionConfig = any,
30
31
  TExtensionSchema extends ZodTypeAny = ZodTypeAny
31
32
  >(
@@ -55,10 +56,11 @@ export const createStormConfig = <
55
56
  if (schema && extensionName) {
56
57
  result.extensions = {
57
58
  ...result.extensions,
58
- [extensionName]: createConfigExtension<TExtensionName, TExtensionConfig, TExtensionSchema>(
59
- extensionName,
60
- schema
61
- )
59
+ [extensionName]: createConfigExtension<
60
+ TExtensionName,
61
+ TExtensionConfig,
62
+ TExtensionSchema
63
+ >(extensionName, schema)
62
64
  };
63
65
  }
64
66
 
@@ -74,7 +76,8 @@ export const createStormConfig = <
74
76
  * @returns The config for the specified Storm config extension. If the extension does not exist, `undefined` is returned.
75
77
  */
76
78
  export const createConfigExtension = <
77
- TExtensionName extends keyof StormConfig["extensions"] = keyof StormConfig["extensions"],
79
+ TExtensionName extends
80
+ keyof StormConfig["extensions"] = keyof StormConfig["extensions"],
78
81
  TExtensionConfig = any,
79
82
  TExtensionSchema extends ZodTypeAny = ZodTypeAny
80
83
  >(
@@ -98,7 +101,9 @@ export const createConfigExtension = <
98
101
  /**
99
102
  * Load the config file values for the current Storm workspace into environment variables
100
103
  */
101
- export const loadStormConfig = async (workspaceRoot?: string): Promise<StormConfig> => {
104
+ export const loadStormConfig = async (
105
+ workspaceRoot?: string
106
+ ): Promise<StormConfig> => {
102
107
  let config = {} as StormConfig;
103
108
 
104
109
  let _workspaceRoot = workspaceRoot;
@@ -76,7 +76,7 @@ ${_chalk.bold.hex(config?.colors?.error ? config.colors.error : "#7d1a1a")(">")}
76
76
  `
77
77
  ${_chalk.bold.hex(config?.colors?.warning ? config.colors.warning : "#fcc419")("> ")} ${_chalk.bold
78
78
  .bgHex(config?.colors?.warning ? config.colors.warning : "#fcc419")
79
- .whiteBright(" ⚠ Warn ")} ${_chalk.hex(
79
+ .whiteBright(" ⚠ Warn ")} ${_chalk.hex(
80
80
  config?.colors?.warning ? config.colors.warning : "#fcc419"
81
81
  )(message)}
82
82
  `