@teqfw/di 0.21.1 → 0.22.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.
package/RELEASE.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @teqfw/di releases
2
2
 
3
+ ## 0.22.0
4
+
5
+ * Add Windows paths to the Resolver.
6
+
3
7
  ## 0.21.1
4
8
 
5
9
  * Fix the dependency key signature in `TeqFw_Di_Container_A_Parser_Chunk_Def`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teqfw/di",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "description": "Dependency Injection container for ES6 modules that works in both browser and Node.js apps.",
5
5
  "keywords": [
6
6
  "dependency injection",
@@ -26,16 +26,20 @@ export default class TeqFw_Di_Container_Resolver {
26
26
  constructor() {
27
27
  // VARS
28
28
  const _regNs = {};
29
+ let _isWindows = false; // flag of the runtime env - win or *nix/web
29
30
  let _namespaces = [];
30
31
  let _ps = '/'; // web & unix path separator
31
32
 
32
33
  // INSTANCE METHODS
33
34
 
34
35
  this.addNamespaceRoot = function (ns, path, ext) {
36
+ const lead = (_isWindows) ? path.replace(/^\\/, '') : path; // remove leading backslash for Win
37
+ const norm = lead.replace(/\\/g, '/'); // replace all windows path separators
38
+ const root = (_isWindows) ? `file://${norm}` : norm;
35
39
  _regNs[ns] = {
36
40
  [KEY_EXT]: ext ?? Defs.EXT,
37
41
  [KEY_NS]: ns,
38
- [KEY_PATH]: path,
42
+ [KEY_PATH]: root,
39
43
  };
40
44
  _namespaces = Object.keys(_regNs).sort((a, b) => b.localeCompare(a));
41
45
  };
@@ -61,5 +65,14 @@ export default class TeqFw_Di_Container_Resolver {
61
65
  return `${root}${_ps}${file}.${ext}`;
62
66
  } else return moduleName;
63
67
  };
68
+
69
+ /**
70
+ * 'true' - to use '\' as path separator to resolve paths.
71
+ * @param {boolean} isWindows
72
+ */
73
+ this.setWindowsEnv = function (isWindows = true) {
74
+ _isWindows = isWindows;
75
+ _ps = (isWindows) ? '\\' : '/';
76
+ };
64
77
  }
65
78
  };