@onlineapps/service-wrapper 2.1.10 → 2.1.11
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/package.json +1 -1
- package/src/ConfigLoader.js +24 -3
- package/src/index.js +1 -1
package/package.json
CHANGED
package/src/ConfigLoader.js
CHANGED
|
@@ -76,8 +76,26 @@ class ConfigLoader {
|
|
|
76
76
|
return CONFIG_REGISTRY;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Load version from package.json (Single Source of Truth)
|
|
81
|
+
* @param {string} basePath - Base path (defaults to process.cwd())
|
|
82
|
+
* @returns {string} Package version
|
|
83
|
+
*/
|
|
84
|
+
static loadPackageVersion(basePath = process.cwd()) {
|
|
85
|
+
const packagePath = path.join(basePath, 'package.json');
|
|
86
|
+
try {
|
|
87
|
+
const content = fs.readFileSync(packagePath, 'utf8');
|
|
88
|
+
const pkg = JSON.parse(content);
|
|
89
|
+
return pkg.version || '0.0.0';
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.warn(`[ConfigLoader] Could not read package.json version: ${error.message}`);
|
|
92
|
+
return '0.0.0';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
79
96
|
/**
|
|
80
97
|
* Load service configuration from conn-config/config.json
|
|
98
|
+
* Version is always taken from package.json (Single Source of Truth)
|
|
81
99
|
* @param {string} basePath - Base path (defaults to process.cwd())
|
|
82
100
|
* @returns {Object} Service configuration
|
|
83
101
|
* @throws {Error} If config file not found or invalid JSON
|
|
@@ -89,11 +107,14 @@ class ConfigLoader {
|
|
|
89
107
|
const content = fs.readFileSync(configPath, 'utf8');
|
|
90
108
|
const config = JSON.parse(content);
|
|
91
109
|
|
|
92
|
-
// Validate required fields
|
|
93
|
-
if (!config.service || !config.service.name
|
|
94
|
-
throw new Error('Invalid config.json: Missing required
|
|
110
|
+
// Validate required fields (version not required - comes from package.json)
|
|
111
|
+
if (!config.service || !config.service.name) {
|
|
112
|
+
throw new Error('Invalid config.json: Missing required field (service.name)');
|
|
95
113
|
}
|
|
96
114
|
|
|
115
|
+
// Always use version from package.json (Single Source of Truth)
|
|
116
|
+
config.service.version = this.loadPackageVersion(basePath);
|
|
117
|
+
|
|
97
118
|
return config;
|
|
98
119
|
} catch (error) {
|
|
99
120
|
if (error.code === 'ENOENT') {
|
package/src/index.js
CHANGED