@teqfw/di 0.20.0 → 0.20.1
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 +7 -1
- package/dist/di.cjs.js +3 -3
- package/dist/di.esm.js +3 -3
- package/package.json +3 -1
- package/src/PreProcessor/Replace.js +1 -1
- package/src/Resolver.js +2 -1
- package/src/SpecAnalyser.js +4 -4
- package/teqfw.json +9 -0
package/RELEASE.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @teqfw/di releases
|
|
2
2
|
|
|
3
|
+
## 0.20.1
|
|
4
|
+
|
|
5
|
+
* Changed regex for parameter extraction in the Spec Analyzer.
|
|
6
|
+
* Removed leading namespace separator in the Resolver.
|
|
7
|
+
* Added `teqfw.json` descriptor to add npm-package to DI container as a sources root in `teqfw/web`.
|
|
8
|
+
|
|
3
9
|
## 0.20.0
|
|
4
10
|
|
|
5
11
|
* Fully redesigned package with simplified composition of objects in the container. Spec Analyzer is used instead of a
|
|
@@ -34,4 +40,4 @@
|
|
|
34
40
|
* docs for plugin's teq-descriptor (see in `main` branch);
|
|
35
41
|
* use object notation instead of array notation in namespace replacement statements of
|
|
36
42
|
teq-descriptor (`@teqfw/di.replace` node format is changed in `./teqfw.json`);
|
|
37
|
-
* array is used as a container for upline dependencies in
|
|
43
|
+
* array is used as a container for upline dependencies in the 'SpecProxy' (object was);
|
package/dist/di.cjs.js
CHANGED
|
@@ -113,7 +113,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
113
113
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
114
114
|
|
|
115
115
|
"use strict";
|
|
116
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/**\n * Pre-processor handler to replace one object key with another.\n */\n\n/**\n * Factory function to create pre-processor handler.\n * @return {function(*): *}\n */\n/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {\n // VARS\n /**\n * Storage for ES modules replacements (interface => implementation).\n * Sample: {['Vnd_Plug_Interface']:'Vnd_Plug_Impl', ...}\n * @type {Object<string, string>}\n */\n const replacements = {};\n\n // FUNCS\n /**\n * @param {TeqFw_Di_Api_ObjectKey} objectKey\n * @param {TeqFw_Di_Api_ObjectKey} originalKey\n * @return {TeqFw_Di_Api_ObjectKey}\n
|
|
116
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/**\n * Pre-processor handler to replace one object key with another.\n * @namespace TeqFw_Di_PreProcessor_Replace\n */\n\n/**\n * Factory function to create pre-processor handler.\n * @return {function(*): *}\n */\n/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {\n // VARS\n /**\n * Storage for ES modules replacements (interface => implementation).\n * Sample: {['Vnd_Plug_Interface']:'Vnd_Plug_Impl', ...}\n * @type {Object<string, string>}\n */\n const replacements = {};\n\n // FUNCS\n /**\n * @param {TeqFw_Di_Api_ObjectKey} objectKey\n * @param {TeqFw_Di_Api_ObjectKey} originalKey\n * @return {TeqFw_Di_Api_ObjectKey}\n */\n function TeqFw_Di_PreProcessor_Replace(objectKey, originalKey) {\n let module = objectKey.moduleName;\n while (replacements[module]) module = replacements[module];\n if (module !== objectKey.moduleName) {\n const res = Object.assign({}, objectKey);\n res.moduleName = module;\n return res;\n } else\n return objectKey;\n }\n\n /**\n * Add replacement for ES6 modules.\n *\n * @param {string} orig ('Vnd_Plug_Interface')\n * @param {string} alter ('Vnd_Plug_Impl')\n */\n TeqFw_Di_PreProcessor_Replace.add = function (orig, alter) {\n replacements[orig] = alter;\n };\n\n // MAIN\n return TeqFw_Di_PreProcessor_Replace;\n}\n\n//# sourceURL=webpack://@teqfw/di/./src/PreProcessor/Replace.js?");
|
|
117
117
|
|
|
118
118
|
/***/ }),
|
|
119
119
|
|
|
@@ -124,7 +124,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
124
124
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
125
125
|
|
|
126
126
|
"use strict";
|
|
127
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ TeqFw_Di_Resolver)\n/* harmony export */ });\n/* harmony import */ var _Defs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Defs.js */ \"./src/Defs.js\");\n/**\n * The Resolver should convert ES6 module name into the path to the sources (file path or URL).\n *\n * This is a base resolver that considers that:\n * - module name is Zend1-compatible ('Vendor_Package_Module')\n * - every namespace is bound to some real path ('Vendor_Package_' => '.../node_modules/@vendor/package/src/...)\n * - every package has sources with the same extensions (*.js, *.mjs, *.es6, ...)\n * - namespaces can be nested (App_Web_ => ./@app/web/..., App_Web_Api_ => ./@app/web_api/...)\n */\n\n\n// VARS\nconst KEY_EXT = 'ext';\nconst KEY_NS = 'ns';\nconst KEY_PATH = 'root';\n/**\n * Namespace parts separator.\n *\n * @type {string}\n */\nconst NSS = '_';\n\n// MAIN\nclass TeqFw_Di_Resolver {\n\n constructor() {\n // VARS\n const _regNs = {};\n let _namespaces = [];\n let _ps = '/'; // web & unix path separator\n\n // INSTANCE METHODS\n\n this.addNamespaceRoot = function (ns, path, ext) {\n _regNs[ns] = {\n [KEY_EXT]: ext ?? _Defs_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"].EXT,\n [KEY_NS]: ns,\n [KEY_PATH]: path,\n };\n _namespaces = Object.keys(_regNs).sort((a, b) => b.localeCompare(a));\n };\n\n /**\n * Convert the module name to the path of the source files .\n * @param {string} moduleName 'Vendor_Package_Module'\n * @return {string} '/home/user/app/node_modules/@vendor/package/src/Module.js'\n */\n this.resolve = function (moduleName) {\n let root, ext, ns;\n for (ns of _namespaces) {\n if (moduleName.startsWith(ns)) {\n root = _regNs[ns][KEY_PATH];\n ext = _regNs[ns][KEY_EXT];\n break;\n }\n }\n if (root && ext) {\n
|
|
127
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ TeqFw_Di_Resolver)\n/* harmony export */ });\n/* harmony import */ var _Defs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Defs.js */ \"./src/Defs.js\");\n/**\n * The Resolver should convert ES6 module name into the path to the sources (file path or URL).\n *\n * This is a base resolver that considers that:\n * - module name is Zend1-compatible ('Vendor_Package_Module')\n * - every namespace is bound to some real path ('Vendor_Package_' => '.../node_modules/@vendor/package/src/...)\n * - every package has sources with the same extensions (*.js, *.mjs, *.es6, ...)\n * - namespaces can be nested (App_Web_ => ./@app/web/..., App_Web_Api_ => ./@app/web_api/...)\n */\n\n\n// VARS\nconst KEY_EXT = 'ext';\nconst KEY_NS = 'ns';\nconst KEY_PATH = 'root';\n/**\n * Namespace parts separator.\n *\n * @type {string}\n */\nconst NSS = '_';\n\n// MAIN\nclass TeqFw_Di_Resolver {\n\n constructor() {\n // VARS\n const _regNs = {};\n let _namespaces = [];\n let _ps = '/'; // web & unix path separator\n\n // INSTANCE METHODS\n\n this.addNamespaceRoot = function (ns, path, ext) {\n _regNs[ns] = {\n [KEY_EXT]: ext ?? _Defs_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"].EXT,\n [KEY_NS]: ns,\n [KEY_PATH]: path,\n };\n _namespaces = Object.keys(_regNs).sort((a, b) => b.localeCompare(a));\n };\n\n /**\n * Convert the module name to the path of the source files .\n * @param {string} moduleName 'Vendor_Package_Module'\n * @return {string} '/home/user/app/node_modules/@vendor/package/src/Module.js'\n */\n this.resolve = function (moduleName) {\n let root, ext, ns;\n for (ns of _namespaces) {\n if (moduleName.startsWith(ns)) {\n root = _regNs[ns][KEY_PATH];\n ext = _regNs[ns][KEY_EXT];\n break;\n }\n }\n if (root && ext) {\n let tail = moduleName.replace(ns, '');\n if (tail.indexOf(NSS) === 0) tail = tail.replace(NSS, '');\n const file = tail.replaceAll(NSS, _ps);\n return `${root}${_ps}${file}.${ext}`;\n } else return moduleName;\n };\n }\n};\n\n//# sourceURL=webpack://@teqfw/di/./src/Resolver.js?");
|
|
128
128
|
|
|
129
129
|
/***/ }),
|
|
130
130
|
|
|
@@ -135,7 +135,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
135
135
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
136
136
|
|
|
137
137
|
"use strict";
|
|
138
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _Defs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Defs.js */ \"./src/Defs.js\");\n/**\n * This function analyzes specification of dependencies extracted from the text definition of the function itself.\n */\n\n\n// VARS\nconst FUNC = /function\\s*\\w*\\s*\\(
|
|
138
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _Defs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Defs.js */ \"./src/Defs.js\");\n/**\n * This function analyzes specification of dependencies extracted from the text definition of the function itself.\n */\n\n\n// VARS\nconst FUNC = /function\\s*\\w*\\s*\\(\\s*\\{([^\\}]*)\\}/s;\nconst CLASS = /constructor\\s*\\(\\s*\\{([^\\}]*)\\}/s;\n\n// FUNCS\n\n/**\n * Internal function to analyze extracted parameters.\n *\n * @param {string} params\n * @return {string[]}\n * @private\n */\nfunction _analyze(params) {\n const res = [];\n // create wrapper for arguments and collect dependencies using Proxy\n try {\n const fn = new Function(`{${params}}`, 'return');\n const spec = new Proxy({}, {\n get: (target, prop) => res.push(prop),\n });\n // run wrapper and return dependencies\n fn(spec);\n } catch (e) {\n const msg = `Cannot analyze the deps specification:${params}\\n`\n + `\\nPlease, be sure that spec does not contain extra ')' in a comments.`\n + `\\n\\nError: ${e}`;\n throw new Error(msg);\n }\n return res;\n}\n\n/**\n * @param {Function|Object} exp\n * @return {string[]}\n */\nfunction _analyzeClass(exp) {\n const res = [];\n // extract arguments from constructor\n const def = exp.toString();\n const parts = CLASS.exec(def);\n if (parts) {\n res.push(..._analyze(parts[1]));\n } // else: constructor does not have arguments\n return res;\n}\n\n/**\n * @param {Function|Object} exp\n * @return {string[]}\n */\nfunction _analyzeFunc(exp) {\n const res = [];\n // extract arguments from factory function\n const def = exp.toString();\n const parts = FUNC.exec(def);\n if (parts) {\n res.push(..._analyze(parts[1]));\n } // else: constructor does not have arguments\n return res;\n}\n\n// MAIN\n/**\n * @param {Function|Object} exp\n * @return {string[]}\n */\n/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__(exp) {\n if (typeof exp === 'function') {\n if (_Defs_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"].isClass(exp)) {\n return _analyzeClass(exp);\n } else {\n return _analyzeFunc(exp);\n }\n } else\n return [];\n}\n\n//# sourceURL=webpack://@teqfw/di/./src/SpecAnalyser.js?");
|
|
139
139
|
|
|
140
140
|
/***/ })
|
|
141
141
|
|
package/dist/di.esm.js
CHANGED
|
@@ -114,7 +114,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
114
114
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
115
115
|
|
|
116
116
|
"use strict";
|
|
117
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/**\n * Pre-processor handler to replace one object key with another.\n */\n\n/**\n * Factory function to create pre-processor handler.\n * @return {function(*): *}\n */\n/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {\n // VARS\n /**\n * Storage for ES modules replacements (interface => implementation).\n * Sample: {['Vnd_Plug_Interface']:'Vnd_Plug_Impl', ...}\n * @type {Object<string, string>}\n */\n const replacements = {};\n\n // FUNCS\n /**\n * @param {TeqFw_Di_Api_ObjectKey} objectKey\n * @param {TeqFw_Di_Api_ObjectKey} originalKey\n * @return {TeqFw_Di_Api_ObjectKey}\n
|
|
117
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/**\n * Pre-processor handler to replace one object key with another.\n * @namespace TeqFw_Di_PreProcessor_Replace\n */\n\n/**\n * Factory function to create pre-processor handler.\n * @return {function(*): *}\n */\n/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {\n // VARS\n /**\n * Storage for ES modules replacements (interface => implementation).\n * Sample: {['Vnd_Plug_Interface']:'Vnd_Plug_Impl', ...}\n * @type {Object<string, string>}\n */\n const replacements = {};\n\n // FUNCS\n /**\n * @param {TeqFw_Di_Api_ObjectKey} objectKey\n * @param {TeqFw_Di_Api_ObjectKey} originalKey\n * @return {TeqFw_Di_Api_ObjectKey}\n */\n function TeqFw_Di_PreProcessor_Replace(objectKey, originalKey) {\n let module = objectKey.moduleName;\n while (replacements[module]) module = replacements[module];\n if (module !== objectKey.moduleName) {\n const res = Object.assign({}, objectKey);\n res.moduleName = module;\n return res;\n } else\n return objectKey;\n }\n\n /**\n * Add replacement for ES6 modules.\n *\n * @param {string} orig ('Vnd_Plug_Interface')\n * @param {string} alter ('Vnd_Plug_Impl')\n */\n TeqFw_Di_PreProcessor_Replace.add = function (orig, alter) {\n replacements[orig] = alter;\n };\n\n // MAIN\n return TeqFw_Di_PreProcessor_Replace;\n}\n\n//# sourceURL=webpack://@teqfw/di/./src/PreProcessor/Replace.js?");
|
|
118
118
|
|
|
119
119
|
/***/ }),
|
|
120
120
|
|
|
@@ -125,7 +125,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
125
125
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
126
126
|
|
|
127
127
|
"use strict";
|
|
128
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ TeqFw_Di_Resolver)\n/* harmony export */ });\n/* harmony import */ var _Defs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Defs.js */ \"./src/Defs.js\");\n/**\n * The Resolver should convert ES6 module name into the path to the sources (file path or URL).\n *\n * This is a base resolver that considers that:\n * - module name is Zend1-compatible ('Vendor_Package_Module')\n * - every namespace is bound to some real path ('Vendor_Package_' => '.../node_modules/@vendor/package/src/...)\n * - every package has sources with the same extensions (*.js, *.mjs, *.es6, ...)\n * - namespaces can be nested (App_Web_ => ./@app/web/..., App_Web_Api_ => ./@app/web_api/...)\n */\n\n\n// VARS\nconst KEY_EXT = 'ext';\nconst KEY_NS = 'ns';\nconst KEY_PATH = 'root';\n/**\n * Namespace parts separator.\n *\n * @type {string}\n */\nconst NSS = '_';\n\n// MAIN\nclass TeqFw_Di_Resolver {\n\n constructor() {\n // VARS\n const _regNs = {};\n let _namespaces = [];\n let _ps = '/'; // web & unix path separator\n\n // INSTANCE METHODS\n\n this.addNamespaceRoot = function (ns, path, ext) {\n _regNs[ns] = {\n [KEY_EXT]: ext ?? _Defs_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"].EXT,\n [KEY_NS]: ns,\n [KEY_PATH]: path,\n };\n _namespaces = Object.keys(_regNs).sort((a, b) => b.localeCompare(a));\n };\n\n /**\n * Convert the module name to the path of the source files .\n * @param {string} moduleName 'Vendor_Package_Module'\n * @return {string} '/home/user/app/node_modules/@vendor/package/src/Module.js'\n */\n this.resolve = function (moduleName) {\n let root, ext, ns;\n for (ns of _namespaces) {\n if (moduleName.startsWith(ns)) {\n root = _regNs[ns][KEY_PATH];\n ext = _regNs[ns][KEY_EXT];\n break;\n }\n }\n if (root && ext) {\n
|
|
128
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ TeqFw_Di_Resolver)\n/* harmony export */ });\n/* harmony import */ var _Defs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Defs.js */ \"./src/Defs.js\");\n/**\n * The Resolver should convert ES6 module name into the path to the sources (file path or URL).\n *\n * This is a base resolver that considers that:\n * - module name is Zend1-compatible ('Vendor_Package_Module')\n * - every namespace is bound to some real path ('Vendor_Package_' => '.../node_modules/@vendor/package/src/...)\n * - every package has sources with the same extensions (*.js, *.mjs, *.es6, ...)\n * - namespaces can be nested (App_Web_ => ./@app/web/..., App_Web_Api_ => ./@app/web_api/...)\n */\n\n\n// VARS\nconst KEY_EXT = 'ext';\nconst KEY_NS = 'ns';\nconst KEY_PATH = 'root';\n/**\n * Namespace parts separator.\n *\n * @type {string}\n */\nconst NSS = '_';\n\n// MAIN\nclass TeqFw_Di_Resolver {\n\n constructor() {\n // VARS\n const _regNs = {};\n let _namespaces = [];\n let _ps = '/'; // web & unix path separator\n\n // INSTANCE METHODS\n\n this.addNamespaceRoot = function (ns, path, ext) {\n _regNs[ns] = {\n [KEY_EXT]: ext ?? _Defs_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"].EXT,\n [KEY_NS]: ns,\n [KEY_PATH]: path,\n };\n _namespaces = Object.keys(_regNs).sort((a, b) => b.localeCompare(a));\n };\n\n /**\n * Convert the module name to the path of the source files .\n * @param {string} moduleName 'Vendor_Package_Module'\n * @return {string} '/home/user/app/node_modules/@vendor/package/src/Module.js'\n */\n this.resolve = function (moduleName) {\n let root, ext, ns;\n for (ns of _namespaces) {\n if (moduleName.startsWith(ns)) {\n root = _regNs[ns][KEY_PATH];\n ext = _regNs[ns][KEY_EXT];\n break;\n }\n }\n if (root && ext) {\n let tail = moduleName.replace(ns, '');\n if (tail.indexOf(NSS) === 0) tail = tail.replace(NSS, '');\n const file = tail.replaceAll(NSS, _ps);\n return `${root}${_ps}${file}.${ext}`;\n } else return moduleName;\n };\n }\n};\n\n//# sourceURL=webpack://@teqfw/di/./src/Resolver.js?");
|
|
129
129
|
|
|
130
130
|
/***/ }),
|
|
131
131
|
|
|
@@ -136,7 +136,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
136
136
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
137
137
|
|
|
138
138
|
"use strict";
|
|
139
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _Defs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Defs.js */ \"./src/Defs.js\");\n/**\n * This function analyzes specification of dependencies extracted from the text definition of the function itself.\n */\n\n\n// VARS\nconst FUNC = /function\\s*\\w*\\s*\\(
|
|
139
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _Defs_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Defs.js */ \"./src/Defs.js\");\n/**\n * This function analyzes specification of dependencies extracted from the text definition of the function itself.\n */\n\n\n// VARS\nconst FUNC = /function\\s*\\w*\\s*\\(\\s*\\{([^\\}]*)\\}/s;\nconst CLASS = /constructor\\s*\\(\\s*\\{([^\\}]*)\\}/s;\n\n// FUNCS\n\n/**\n * Internal function to analyze extracted parameters.\n *\n * @param {string} params\n * @return {string[]}\n * @private\n */\nfunction _analyze(params) {\n const res = [];\n // create wrapper for arguments and collect dependencies using Proxy\n try {\n const fn = new Function(`{${params}}`, 'return');\n const spec = new Proxy({}, {\n get: (target, prop) => res.push(prop),\n });\n // run wrapper and return dependencies\n fn(spec);\n } catch (e) {\n const msg = `Cannot analyze the deps specification:${params}\\n`\n + `\\nPlease, be sure that spec does not contain extra ')' in a comments.`\n + `\\n\\nError: ${e}`;\n throw new Error(msg);\n }\n return res;\n}\n\n/**\n * @param {Function|Object} exp\n * @return {string[]}\n */\nfunction _analyzeClass(exp) {\n const res = [];\n // extract arguments from constructor\n const def = exp.toString();\n const parts = CLASS.exec(def);\n if (parts) {\n res.push(..._analyze(parts[1]));\n } // else: constructor does not have arguments\n return res;\n}\n\n/**\n * @param {Function|Object} exp\n * @return {string[]}\n */\nfunction _analyzeFunc(exp) {\n const res = [];\n // extract arguments from factory function\n const def = exp.toString();\n const parts = FUNC.exec(def);\n if (parts) {\n res.push(..._analyze(parts[1]));\n } // else: constructor does not have arguments\n return res;\n}\n\n// MAIN\n/**\n * @param {Function|Object} exp\n * @return {string[]}\n */\n/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__(exp) {\n if (typeof exp === 'function') {\n if (_Defs_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"].isClass(exp)) {\n return _analyzeClass(exp);\n } else {\n return _analyzeFunc(exp);\n }\n } else\n return [];\n}\n\n//# sourceURL=webpack://@teqfw/di/./src/SpecAnalyser.js?");
|
|
140
140
|
|
|
141
141
|
/***/ })
|
|
142
142
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teqfw/di",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Dependency Injection container based on logical namespaces for ES6 modules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dependency injection",
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
"build": "rm -fr ./dist/ && webpack build"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"babel-eslint": "*",
|
|
34
|
+
"eslint": "*",
|
|
33
35
|
"esm": "*",
|
|
34
36
|
"mocha": "*",
|
|
35
37
|
"webpack": "^5.88.1",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pre-processor handler to replace one object key with another.
|
|
3
|
+
* @namespace TeqFw_Di_PreProcessor_Replace
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -20,7 +21,6 @@ export default function () {
|
|
|
20
21
|
* @param {TeqFw_Di_Api_ObjectKey} objectKey
|
|
21
22
|
* @param {TeqFw_Di_Api_ObjectKey} originalKey
|
|
22
23
|
* @return {TeqFw_Di_Api_ObjectKey}
|
|
23
|
-
* @namespace
|
|
24
24
|
*/
|
|
25
25
|
function TeqFw_Di_PreProcessor_Replace(objectKey, originalKey) {
|
|
26
26
|
let module = objectKey.moduleName;
|
package/src/Resolver.js
CHANGED
|
@@ -55,7 +55,8 @@ export default class TeqFw_Di_Resolver {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
if (root && ext) {
|
|
58
|
-
|
|
58
|
+
let tail = moduleName.replace(ns, '');
|
|
59
|
+
if (tail.indexOf(NSS) === 0) tail = tail.replace(NSS, '');
|
|
59
60
|
const file = tail.replaceAll(NSS, _ps);
|
|
60
61
|
return `${root}${_ps}${file}.${ext}`;
|
|
61
62
|
} else return moduleName;
|
package/src/SpecAnalyser.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import Defs from './Defs.js';
|
|
5
5
|
|
|
6
6
|
// VARS
|
|
7
|
-
const FUNC = /function\s*\w*\s*\(
|
|
8
|
-
const CLASS = /constructor\s*\(
|
|
7
|
+
const FUNC = /function\s*\w*\s*\(\s*\{([^\}]*)\}/s;
|
|
8
|
+
const CLASS = /constructor\s*\(\s*\{([^\}]*)\}/s;
|
|
9
9
|
|
|
10
10
|
// FUNCS
|
|
11
11
|
|
|
@@ -20,14 +20,14 @@ function _analyze(params) {
|
|
|
20
20
|
const res = [];
|
|
21
21
|
// create wrapper for arguments and collect dependencies using Proxy
|
|
22
22
|
try {
|
|
23
|
-
const fn = new Function(params
|
|
23
|
+
const fn = new Function(`{${params}}`, 'return');
|
|
24
24
|
const spec = new Proxy({}, {
|
|
25
25
|
get: (target, prop) => res.push(prop),
|
|
26
26
|
});
|
|
27
27
|
// run wrapper and return dependencies
|
|
28
28
|
fn(spec);
|
|
29
29
|
} catch (e) {
|
|
30
|
-
const msg = `Cannot analyze the deps specification:${
|
|
30
|
+
const msg = `Cannot analyze the deps specification:${params}\n`
|
|
31
31
|
+ `\nPlease, be sure that spec does not contain extra ')' in a comments.`
|
|
32
32
|
+ `\n\nError: ${e}`;
|
|
33
33
|
throw new Error(msg);
|