@devopsplaybook.io/common-utils 1.9.0 → 1.10.0-beta.19.2cffff2
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/dist/src/ConfigBase.js +6 -2
- package/package.json +1 -1
- package/src/ConfigBase.spec.ts +33 -0
- package/src/ConfigBase.ts +6 -2
package/dist/src/ConfigBase.js
CHANGED
|
@@ -139,9 +139,13 @@ class ConfigBase {
|
|
|
139
139
|
this._fields = [];
|
|
140
140
|
this.SERVICE_ID = serviceId;
|
|
141
141
|
this.CONFIG_FILE = configFile || process.env.CONFIG_FILE || "config.json";
|
|
142
|
-
// Auto-detect version from
|
|
142
|
+
// Auto-detect the host application version from its package.json.
|
|
143
|
+
// Services run with their project root as the current working
|
|
144
|
+
// directory, so <cwd>/package.json is the host app's manifest. The
|
|
145
|
+
// installed library's own package.json is deliberately not used: it
|
|
146
|
+
// would report the library version, not the service version.
|
|
143
147
|
try {
|
|
144
|
-
const pkg = fse.readJsonSync(path_1.default.resolve(
|
|
148
|
+
const pkg = fse.readJsonSync(path_1.default.resolve(process.cwd(), "package.json"));
|
|
145
149
|
if (pkg && pkg.version) {
|
|
146
150
|
this.VERSION = pkg.version;
|
|
147
151
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devopsplaybook.io/common-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0-beta.19.2cffff2",
|
|
4
4
|
"description": "Shared utility modules for devopsplaybook.io projects (DB, Config, OTel context, auth/users, notifications, LLM, system helpers)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Open Telemetry",
|
package/src/ConfigBase.spec.ts
CHANGED
|
@@ -105,4 +105,37 @@ describe("ConfigBase", () => {
|
|
|
105
105
|
await config.reload();
|
|
106
106
|
expect(config.DATABASE_TYPE).toBe("postgres");
|
|
107
107
|
});
|
|
108
|
+
|
|
109
|
+
describe("VERSION detection", () => {
|
|
110
|
+
let cwdSpy: jest.SpyInstance;
|
|
111
|
+
|
|
112
|
+
afterEach(() => {
|
|
113
|
+
cwdSpy.mockRestore();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should detect VERSION from a package.json in the working directory", () => {
|
|
117
|
+
fse.writeJsonSync(path.join(tmpDir, "package.json"), {
|
|
118
|
+
name: "host-app",
|
|
119
|
+
version: "3.2.1",
|
|
120
|
+
});
|
|
121
|
+
cwdSpy = jest.spyOn(process, "cwd").mockReturnValue(tmpDir);
|
|
122
|
+
const config = new TestConfig(configPath);
|
|
123
|
+
expect(config.VERSION).toBe("3.2.1");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should fall back to VERSION '1' when the working directory has no package.json", () => {
|
|
127
|
+
cwdSpy = jest.spyOn(process, "cwd").mockReturnValue(tmpDir);
|
|
128
|
+
const config = new TestConfig(configPath);
|
|
129
|
+
expect(config.VERSION).toBe("1");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should fall back to VERSION '1' when package.json has no version field", () => {
|
|
133
|
+
fse.writeJsonSync(path.join(tmpDir, "package.json"), {
|
|
134
|
+
name: "host-app",
|
|
135
|
+
});
|
|
136
|
+
cwdSpy = jest.spyOn(process, "cwd").mockReturnValue(tmpDir);
|
|
137
|
+
const config = new TestConfig(configPath);
|
|
138
|
+
expect(config.VERSION).toBe("1");
|
|
139
|
+
});
|
|
140
|
+
});
|
|
108
141
|
});
|
package/src/ConfigBase.ts
CHANGED
|
@@ -167,9 +167,13 @@ export abstract class ConfigBase implements ConfigCommonInterface {
|
|
|
167
167
|
this.SERVICE_ID = serviceId;
|
|
168
168
|
this.CONFIG_FILE = configFile || process.env.CONFIG_FILE || "config.json";
|
|
169
169
|
|
|
170
|
-
// Auto-detect version from
|
|
170
|
+
// Auto-detect the host application version from its package.json.
|
|
171
|
+
// Services run with their project root as the current working
|
|
172
|
+
// directory, so <cwd>/package.json is the host app's manifest. The
|
|
173
|
+
// installed library's own package.json is deliberately not used: it
|
|
174
|
+
// would report the library version, not the service version.
|
|
171
175
|
try {
|
|
172
|
-
const pkg = fse.readJsonSync(path.resolve(
|
|
176
|
+
const pkg = fse.readJsonSync(path.resolve(process.cwd(), "package.json"));
|
|
173
177
|
if (pkg && pkg.version) {
|
|
174
178
|
this.VERSION = pkg.version;
|
|
175
179
|
}
|