@tsed/config 8.40.2 → 8.41.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.
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import JsYaml from "js-yaml";
|
|
2
|
-
import { existsSync, watch } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync, watch } from "node:fs";
|
|
3
3
|
import { logger } from "@tsed/di";
|
|
4
4
|
export class YamlConfigSource {
|
|
5
5
|
async getAll() {
|
|
6
|
-
const { path, ...opts } = this.options;
|
|
6
|
+
const { path, encoding = "utf8", ...opts } = this.options;
|
|
7
7
|
// Check if the file exists
|
|
8
8
|
if (!existsSync(path)) {
|
|
9
9
|
logger().warn(`Configuration file not found: ${path}`);
|
|
10
10
|
return {};
|
|
11
11
|
}
|
|
12
12
|
// Read the file
|
|
13
|
-
|
|
13
|
+
const fileContent = readFileSync(path, encoding);
|
|
14
|
+
return ((await JsYaml.load(fileContent, opts)) || {});
|
|
14
15
|
}
|
|
15
16
|
watch(onChange) {
|
|
16
17
|
const { path } = this.options;
|
|
@@ -2,9 +2,14 @@ import type { ConfigSource, ConfigSourceOnChangeCB } from "../../interfaces/Conf
|
|
|
2
2
|
import { type LoadOptions } from "js-yaml";
|
|
3
3
|
export interface YamlConfigSourceOptions extends LoadOptions {
|
|
4
4
|
/**
|
|
5
|
-
* The path to the
|
|
5
|
+
* The path to the YAML file.
|
|
6
6
|
*/
|
|
7
7
|
path: string;
|
|
8
|
+
/**
|
|
9
|
+
* The encoding to use when reading the file.
|
|
10
|
+
* @default "utf8"
|
|
11
|
+
*/
|
|
12
|
+
encoding?: BufferEncoding;
|
|
8
13
|
}
|
|
9
14
|
export declare class YamlConfigSource implements ConfigSource<YamlConfigSourceOptions> {
|
|
10
15
|
options: YamlConfigSourceOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/config",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.41.0",
|
|
4
4
|
"description": "Configuration management for Ts.ED",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Config",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"tslib": ">=2.7.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@tsed/barrels": "8.
|
|
74
|
-
"@tsed/core": "8.
|
|
75
|
-
"@tsed/di": "8.
|
|
76
|
-
"@tsed/typescript": "8.
|
|
73
|
+
"@tsed/barrels": "8.41.0",
|
|
74
|
+
"@tsed/core": "8.41.0",
|
|
75
|
+
"@tsed/di": "8.41.0",
|
|
76
|
+
"@tsed/typescript": "8.41.0",
|
|
77
77
|
"@types/js-yaml": "4.0.9",
|
|
78
78
|
"dotenv": "^16.5.0",
|
|
79
79
|
"dotenv-expand": "^12.0.2",
|