@jsnw/srv-utils 1.0.8 → 1.0.10

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.
@@ -7,7 +7,7 @@ const zod_1 = require("zod");
7
7
  const yaml_1 = require("yaml");
8
8
  const file_exists_1 = require("../file-exists");
9
9
  const getRootPackageDirname_1 = require("../getRootPackageDirname");
10
- const PKG_ROOT_REGEX = /^%pkgroot[\/\\]/i;
10
+ const PKG_ROOT_REGEX = /^%pkgroot(?:[\/\\]|$)/i;
11
11
  class ConfigLoader {
12
12
  static _instance;
13
13
  /**
@@ -110,15 +110,25 @@ class ConfigLoader {
110
110
  const node = nodesToVisit[i];
111
111
  if (typeof node !== 'object' || Array.isArray(node))
112
112
  continue;
113
- if (node['$include'] && typeof node['$include'] === 'string') {
114
- const [loadedYaml, loadError] = this.loadYamlFile(this.resolveIncludePath(mainYamlDirname, node['$include']));
115
- delete node['$include'];
116
- if (loadError) {
117
- errors.push(loadError);
113
+ if (node['$include']) {
114
+ const $includePaths = [];
115
+ if (typeof node['$include'] === 'string') {
116
+ $includePaths.push(node['$include']);
117
+ }
118
+ else if (Array.isArray(node['$include'])) {
119
+ $includePaths.push(...(node['$include']
120
+ .filter(v => v && typeof v === 'string' && v.trim() !== '')));
118
121
  }
119
- else {
120
- for (const [k, v] of Object.entries(loadedYaml))
121
- node[k] = v;
122
+ delete node['$include'];
123
+ for (const path of $includePaths) {
124
+ const [loadedYaml, loadError] = this.loadYamlFile(this.resolveIncludePath(mainYamlDirname, path));
125
+ if (loadError) {
126
+ errors.push(loadError);
127
+ }
128
+ else {
129
+ for (const [k, v] of Object.entries(loadedYaml))
130
+ node[k] = v;
131
+ }
122
132
  }
123
133
  }
124
134
  for (const k of Object.keys(node)) {
@@ -134,7 +144,7 @@ class ConfigLoader {
134
144
  resolvePkgRootPath(path) {
135
145
  if (PKG_ROOT_REGEX.test(path))
136
146
  path = path.replace(PKG_ROOT_REGEX, (0, getRootPackageDirname_1.getRootPackageDirnameSync)() + node_path_1.sep);
137
- return path;
147
+ return (0, node_path_1.resolve)(path);
138
148
  }
139
149
  /**
140
150
  * @param {string} fromDirname
@@ -143,7 +153,7 @@ class ConfigLoader {
143
153
  * @private
144
154
  */
145
155
  resolveIncludePath(fromDirname, toPath) {
146
- return (0, node_path_1.resolve)(fromDirname, toPath);
156
+ return (0, node_path_1.resolve)(this.resolvePkgRootPath(fromDirname), toPath);
147
157
  }
148
158
  }
149
159
  exports.ConfigLoader = ConfigLoader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsnw/srv-utils",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Server-side utilities for Node.js/TypeScript: tsconfig paths, Nest helpers, and config loading.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",