amaprice 1.0.13 → 1.0.14

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amaprice",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "CLI tool to scrape and track Amazon product prices",
5
5
  "main": "src/scraper.js",
6
6
  "type": "commonjs",
@@ -263,6 +263,7 @@ async function enableLaunchdService({
263
263
  const plistPath = getLaunchdPlistPath(label);
264
264
  const logPath = getDaemonLogPath();
265
265
  const daemonEntry = getDaemonEntryPath();
266
+ const target = buildServiceTarget(label);
266
267
 
267
268
  await fs.mkdir(path.dirname(plistPath), { recursive: true });
268
269
  await fs.mkdir(path.dirname(logPath), { recursive: true });
@@ -283,13 +284,22 @@ async function enableLaunchdService({
283
284
  });
284
285
  await fs.writeFile(plistPath, plist, 'utf8');
285
286
 
286
- const bootstrap = await runLaunchctl(['bootstrap', getLaunchdDomain(), plistPath], { allowFailure: true });
287
+ // If service was previously disabled via `background off`, re-enable first.
288
+ await runLaunchctl(['enable', target], { allowFailure: true });
289
+
290
+ let bootstrap = await runLaunchctl(['bootstrap', getLaunchdDomain(), plistPath], { allowFailure: true });
291
+ if (!bootstrap.ok && !isAlreadyLoadedError(bootstrap)) {
292
+ // Recover from stale loaded/disabled state by clearing then bootstrapping once more.
293
+ await runLaunchctl(['bootout', target], { allowFailure: true });
294
+ await runLaunchctl(['enable', target], { allowFailure: true });
295
+ bootstrap = await runLaunchctl(['bootstrap', getLaunchdDomain(), plistPath], { allowFailure: true });
296
+ }
287
297
  if (!bootstrap.ok && !isAlreadyLoadedError(bootstrap)) {
288
298
  throw new Error(`Could not bootstrap launchd service: ${bootstrap.stderr || bootstrap.stdout || 'unknown error'}`);
289
299
  }
290
300
 
291
- await runLaunchctl(['enable', buildServiceTarget(label)], { allowFailure: true });
292
- const kick = await runLaunchctl(['kickstart', '-k', buildServiceTarget(label)], { allowFailure: true });
301
+ await runLaunchctl(['enable', target], { allowFailure: true });
302
+ const kick = await runLaunchctl(['kickstart', '-k', target], { allowFailure: true });
293
303
  if (!kick.ok) {
294
304
  await runLaunchctl(['start', label], { allowFailure: true });
295
305
  }