@jsnw/srv-utils 1.0.6 → 1.0.8
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.
|
@@ -34,7 +34,7 @@ class ConfigLoader {
|
|
|
34
34
|
console.error(loadError.message);
|
|
35
35
|
process.exit(1);
|
|
36
36
|
}
|
|
37
|
-
const [processedYaml, includeErrors] = loader.processIncludes(yaml);
|
|
37
|
+
const [processedYaml, includeErrors] = loader.processIncludes((0, node_path_1.dirname)(path), yaml);
|
|
38
38
|
if (includeErrors && includeErrors.length > 0) {
|
|
39
39
|
for (const err of includeErrors)
|
|
40
40
|
console.error(`$include error: ${err.message}`);
|
|
@@ -97,11 +97,12 @@ class ConfigLoader {
|
|
|
97
97
|
return [parsed, null];
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
+
* @param {string} mainYamlDirname
|
|
100
101
|
* @param yaml
|
|
101
102
|
* @returns {ErrorResult<any, Error[]>}
|
|
102
103
|
* @protected
|
|
103
104
|
*/
|
|
104
|
-
processIncludes(yaml) {
|
|
105
|
+
processIncludes(mainYamlDirname, yaml) {
|
|
105
106
|
if (typeof yaml !== 'object')
|
|
106
107
|
return yaml;
|
|
107
108
|
const nodesToVisit = [yaml], errors = [];
|
|
@@ -110,7 +111,7 @@ class ConfigLoader {
|
|
|
110
111
|
if (typeof node !== 'object' || Array.isArray(node))
|
|
111
112
|
continue;
|
|
112
113
|
if (node['$include'] && typeof node['$include'] === 'string') {
|
|
113
|
-
const [loadedYaml, loadError] = this.loadYamlFile((
|
|
114
|
+
const [loadedYaml, loadError] = this.loadYamlFile(this.resolveIncludePath(mainYamlDirname, node['$include']));
|
|
114
115
|
delete node['$include'];
|
|
115
116
|
if (loadError) {
|
|
116
117
|
errors.push(loadError);
|
|
@@ -135,5 +136,14 @@ class ConfigLoader {
|
|
|
135
136
|
path = path.replace(PKG_ROOT_REGEX, (0, getRootPackageDirname_1.getRootPackageDirnameSync)() + node_path_1.sep);
|
|
136
137
|
return path;
|
|
137
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* @param {string} fromDirname
|
|
141
|
+
* @param {string} toPath
|
|
142
|
+
* @returns {string}
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
resolveIncludePath(fromDirname, toPath) {
|
|
146
|
+
return (0, node_path_1.resolve)(fromDirname, toPath);
|
|
147
|
+
}
|
|
138
148
|
}
|
|
139
149
|
exports.ConfigLoader = ConfigLoader;
|
|
@@ -33,10 +33,18 @@ export declare class ConfigLoader {
|
|
|
33
33
|
*/
|
|
34
34
|
protected validateYaml<T extends z.ZodTypeAny>(data: any, schema: T): ErrorResult<z.infer<T>, Error>;
|
|
35
35
|
/**
|
|
36
|
+
* @param {string} mainYamlDirname
|
|
36
37
|
* @param yaml
|
|
37
38
|
* @returns {ErrorResult<any, Error[]>}
|
|
38
39
|
* @protected
|
|
39
40
|
*/
|
|
40
|
-
protected processIncludes(yaml: any): ErrorResult<any, Error[]>;
|
|
41
|
+
protected processIncludes(mainYamlDirname: string, yaml: any): ErrorResult<any, Error[]>;
|
|
41
42
|
private resolvePkgRootPath;
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} fromDirname
|
|
45
|
+
* @param {string} toPath
|
|
46
|
+
* @returns {string}
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
private resolveIncludePath;
|
|
42
50
|
}
|
package/package.json
CHANGED