easy-devops 1.4.0 → 1.4.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.
@@ -54,6 +54,25 @@ export const WINSW_BYTES = 18_243_033;
54
54
  /** Service identity. The display name is what appears in services.msc. */
55
55
  export const SERVICE_ID = 'EasyDevOps';
56
56
  export const SERVICE_DISPLAY_NAME = 'Easy DevOps';
57
+
58
+ /**
59
+ * The names the wrapper and its definition are stored under.
60
+ *
61
+ * WinSW v2 finds its configuration ONLY as `<its own base name>.xml` in its
62
+ * own directory; a path passed on the command line is ignored. Storing the
63
+ * downloaded `WinSW-x64.exe` under its release name beside `EasyDevOps.xml`
64
+ * is exactly what made 1.4.0's Server-mode install fail with "Unable to
65
+ * locate WinSW-x64.[xml|yml]". Both names are derived from SERVICE_ID here,
66
+ * and nowhere else, so they cannot drift apart again.
67
+ *
68
+ * WINSW_ASSET stays the RELEASE asset name: it is what is downloaded and what
69
+ * the hash pins, not what the file is called once it is installed.
70
+ */
71
+ export const WINSW_EXE_NAME = `${SERVICE_ID}.exe`;
72
+ export const WINSW_XML_NAME = `${SERVICE_ID}.xml`;
73
+
74
+ /** The name 1.4.0 stored the wrapper under. Found and removed on install. */
75
+ export const LEGACY_WINSW_NAME = WINSW_ASSET;
57
76
  export const SERVICE_DESCRIPTION =
58
77
  'Monitors nginx, domains and certificates, sends notifications, and runs the Easy DevOps Hub agent.';
59
78
 
@@ -125,10 +144,10 @@ export async function verifyWinsw(file) {
125
144
  * @param {typeof fetch} [opts.fetchImpl] Injectable, for tests
126
145
  * @returns {Promise<{ ok: boolean, path?: string, reason?: string, sha256?: string }>}
127
146
  */
128
- export async function downloadWinsw({ dest, log = () => {}, fetchImpl = fetch } = {}) {
147
+ export async function downloadWinsw({ dest, log = () => {}, fetchImpl = fetch, verify = verifyWinsw } = {}) {
129
148
  // Already there and correct: do not download 18MB again.
130
149
  if (fs.existsSync(dest)) {
131
- const existing = await verifyWinsw(dest);
150
+ const existing = await verify(dest);
132
151
  if (existing.ok) {
133
152
  log(`${WINSW_ASSET} ${WINSW_VERSION} already present and verified.`);
134
153
  return { ok: true, path: dest, sha256: existing.sha256 };
@@ -136,6 +155,28 @@ export async function downloadWinsw({ dest, log = () => {}, fetchImpl = fetch }
136
155
  log(`An existing ${path.basename(dest)} did not verify (${existing.reason.split('\n')[0]}); re-downloading.`);
137
156
  }
138
157
 
158
+ // 1.4.0 left the wrapper beside `dest` under its release name. A copy that
159
+ // still verifies is the same pinned binary, so it is moved into place
160
+ // instead of downloading 18MB again; one that does not verify is removed.
161
+ // Either way the old name does not survive, because a second WinSW binary
162
+ // in the directory is only ever a source of confusion.
163
+ const legacy = path.join(path.dirname(dest), LEGACY_WINSW_NAME);
164
+ if (legacy !== dest && fs.existsSync(legacy)) {
165
+ const old = await verify(legacy);
166
+ try {
167
+ if (old.ok) {
168
+ fs.rmSync(dest, { force: true });
169
+ fs.renameSync(legacy, dest);
170
+ log(`Renamed the verified ${LEGACY_WINSW_NAME} to ${path.basename(dest)}.`);
171
+ return { ok: true, path: dest, sha256: old.sha256 };
172
+ }
173
+ fs.rmSync(legacy, { force: true });
174
+ log(`Removed an unverified ${LEGACY_WINSW_NAME} left by an earlier install.`);
175
+ } catch (err) {
176
+ log(`Could not tidy up ${legacy}: ${err.message}. Downloading a fresh copy instead.`);
177
+ }
178
+ }
179
+
139
180
  fs.mkdirSync(path.dirname(dest), { recursive: true });
140
181
 
141
182
  // Downloaded to a temporary name and renamed only after verification, so an
@@ -157,7 +198,7 @@ export async function downloadWinsw({ dest, log = () => {}, fetchImpl = fetch }
157
198
  return { ok: false, reason: `download failed: ${err.message}` };
158
199
  }
159
200
 
160
- const verified = await verifyWinsw(temp);
201
+ const verified = await verify(temp);
161
202
  if (!verified.ok) {
162
203
  try { fs.rmSync(temp, { force: true }); } catch { /* nothing to clean */ }
163
204
  return { ok: false, reason: verified.reason };