@jsnw/srv-utils 1.0.7 → 1.0.9

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
  /**
@@ -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(path, 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,12 +97,12 @@ class ConfigLoader {
97
97
  return [parsed, null];
98
98
  }
99
99
  /**
100
- * @param {string} mainYamlPath
100
+ * @param {string} mainYamlDirname
101
101
  * @param yaml
102
102
  * @returns {ErrorResult<any, Error[]>}
103
103
  * @protected
104
104
  */
105
- processIncludes(mainYamlPath, yaml) {
105
+ processIncludes(mainYamlDirname, yaml) {
106
106
  if (typeof yaml !== 'object')
107
107
  return yaml;
108
108
  const nodesToVisit = [yaml], errors = [];
@@ -111,7 +111,7 @@ class ConfigLoader {
111
111
  if (typeof node !== 'object' || Array.isArray(node))
112
112
  continue;
113
113
  if (node['$include'] && typeof node['$include'] === 'string') {
114
- const [loadedYaml, loadError] = this.loadYamlFile((0, node_path_1.resolve)(mainYamlPath, node['$include']));
114
+ const [loadedYaml, loadError] = this.loadYamlFile(this.resolveIncludePath(mainYamlDirname, node['$include']));
115
115
  delete node['$include'];
116
116
  if (loadError) {
117
117
  errors.push(loadError);
@@ -134,7 +134,16 @@ class ConfigLoader {
134
134
  resolvePkgRootPath(path) {
135
135
  if (PKG_ROOT_REGEX.test(path))
136
136
  path = path.replace(PKG_ROOT_REGEX, (0, getRootPackageDirname_1.getRootPackageDirnameSync)() + node_path_1.sep);
137
- return path;
137
+ return (0, node_path_1.resolve)(path);
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)(this.resolvePkgRootPath(fromDirname), toPath);
138
147
  }
139
148
  }
140
149
  exports.ConfigLoader = ConfigLoader;
@@ -33,11 +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} mainYamlPath
36
+ * @param {string} mainYamlDirname
37
37
  * @param yaml
38
38
  * @returns {ErrorResult<any, Error[]>}
39
39
  * @protected
40
40
  */
41
- protected processIncludes(mainYamlPath: string, yaml: any): ErrorResult<any, Error[]>;
41
+ protected processIncludes(mainYamlDirname: string, yaml: any): ErrorResult<any, Error[]>;
42
42
  private resolvePkgRootPath;
43
+ /**
44
+ * @param {string} fromDirname
45
+ * @param {string} toPath
46
+ * @returns {string}
47
+ * @private
48
+ */
49
+ private resolveIncludePath;
43
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsnw/srv-utils",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
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",