@way_marks/server 4.4.7 → 4.5.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/dist/services/version.js
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.setProjectRoot = setProjectRoot;
|
|
37
|
+
exports.setCurrentVersionForTest = setCurrentVersionForTest;
|
|
37
38
|
exports.resetState = resetState;
|
|
38
39
|
exports.getVersionInfo = getVersionInfo;
|
|
39
40
|
const fs = __importStar(require("fs"));
|
|
@@ -42,9 +43,14 @@ const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
|
42
43
|
const NPM_TIMEOUT_MS = 5000; // 5 seconds
|
|
43
44
|
const CACHE_FILE_NAME = 'version-cache.json';
|
|
44
45
|
let projectRoot = process.env.WAYMARK_PROJECT_ROOT || process.cwd();
|
|
46
|
+
let currentVersionOverride = null;
|
|
45
47
|
function setProjectRoot(root) {
|
|
46
48
|
projectRoot = root;
|
|
47
49
|
}
|
|
50
|
+
/** For testing only — override the version returned by getCurrentVersion(). */
|
|
51
|
+
function setCurrentVersionForTest(version) {
|
|
52
|
+
currentVersionOverride = version;
|
|
53
|
+
}
|
|
48
54
|
function getCachePath() {
|
|
49
55
|
return path.join(projectRoot, '.waymark', CACHE_FILE_NAME);
|
|
50
56
|
}
|
|
@@ -137,25 +143,56 @@ async function fetchLatestVersionFromNpm() {
|
|
|
137
143
|
return null;
|
|
138
144
|
}
|
|
139
145
|
}
|
|
146
|
+
function isWaymarkPackageJson(packageJson) {
|
|
147
|
+
if (!packageJson.name)
|
|
148
|
+
return false;
|
|
149
|
+
return packageJson.name.includes('way_marks') || packageJson.name.includes('waymark');
|
|
150
|
+
}
|
|
140
151
|
function getCurrentVersion() {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (!fs.existsSync(cliPackageJsonPath)) {
|
|
144
|
-
return '0.0.0';
|
|
145
|
-
}
|
|
146
|
-
const content = fs.readFileSync(cliPackageJsonPath, 'utf-8');
|
|
147
|
-
const packageJson = JSON.parse(content);
|
|
148
|
-
return packageJson.version || '0.0.0';
|
|
152
|
+
if (currentVersionOverride !== null) {
|
|
153
|
+
return currentVersionOverride;
|
|
149
154
|
}
|
|
150
|
-
|
|
151
|
-
|
|
155
|
+
// Search these paths in order; accept the first file that (a) exists and
|
|
156
|
+
// (b) belongs to a waymark package (name contains "way_marks" or "waymark").
|
|
157
|
+
//
|
|
158
|
+
// Candidate 1 — compiled global/local npm install:
|
|
159
|
+
// __dirname = .../node_modules/@way_marks/server/dist/services/
|
|
160
|
+
// Two levels up → .../node_modules/@way_marks/server/package.json ✓
|
|
161
|
+
//
|
|
162
|
+
// Candidate 2 — ts-node inside monorepo (src/ not dist/):
|
|
163
|
+
// __dirname = packages/server/src/services/
|
|
164
|
+
// Three levels up → packages/server → no cli there
|
|
165
|
+
// So explicitly check sibling packages/cli.
|
|
166
|
+
//
|
|
167
|
+
// Candidate 3 — monorepo dev with compiled output (dist/):
|
|
168
|
+
// projectRoot = waymark checkout root → packages/cli/package.json ✓
|
|
169
|
+
const candidates = [
|
|
170
|
+
path.join(__dirname, '..', '..', 'package.json'), // compiled install
|
|
171
|
+
path.join(__dirname, '..', '..', '..', 'packages', 'cli', 'package.json'), // ts-node monorepo
|
|
172
|
+
path.join(projectRoot, 'packages', 'cli', 'package.json'), // monorepo dev
|
|
173
|
+
];
|
|
174
|
+
for (const candidate of candidates) {
|
|
175
|
+
try {
|
|
176
|
+
if (!fs.existsSync(candidate))
|
|
177
|
+
continue;
|
|
178
|
+
const content = fs.readFileSync(candidate, 'utf-8');
|
|
179
|
+
const packageJson = JSON.parse(content);
|
|
180
|
+
if (packageJson.version && isWaymarkPackageJson(packageJson)) {
|
|
181
|
+
return packageJson.version;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
// try next candidate
|
|
186
|
+
}
|
|
152
187
|
}
|
|
188
|
+
return '0.0.0';
|
|
153
189
|
}
|
|
154
190
|
let lastFetchPromise = null;
|
|
155
191
|
let lastFetchTime = 0;
|
|
156
192
|
function resetState() {
|
|
157
193
|
lastFetchPromise = null;
|
|
158
194
|
lastFetchTime = 0;
|
|
195
|
+
currentVersionOverride = null;
|
|
159
196
|
}
|
|
160
197
|
async function getVersionInfo() {
|
|
161
198
|
const currentVersion = getCurrentVersion();
|