feat(daemon): Add reset feature
MODIFY
packages/daemon/index.d.ts
packages/daemon/index.d.ts
@@ -8,6 +8,7 @@ export async function stop(locator?: Locator);
export async function restart(locator?: Locator);
export async function terminate(locator?: Locator);
export async function clean(locator?: Locator);
+export async function reset(locator?: Locator);
export async function makeEndoClient<TBootstrap>(
name: string,
sockPath: string,

MODIFY
packages/daemon/index.js
packages/daemon/index.js
@@ -83,14 +83,16 @@ export const start = async (locator = defaultLocator) => {
});
};
-export const clean = async (locator = defaultLocator) => {
- if (process.platform !== 'win32') {
- await fs.promises.unlink(locator.sockPath).catch(error => {
+const enoentOk = error => {
if (error.code === 'ENOENT') {
return;
}
throw error;
- });
+};
+
+export const clean = async (locator = defaultLocator) => {
+ if (process.platform !== 'win32') {
+ await fs.promises.rm(locator.sockPath).catch(enoentOk);
}
};
@@ -105,3 +107,14 @@ export const restart = async (locator = defaultLocator) => {
export const stop = async (locator = defaultLocator) => {
return terminate(locator).catch(() => {});
};
+
+export const reset = async (locator = defaultLocator) => {
+ const cleanedUp = clean(locator);
+ const restated = fs.promises
+ .rm(locator.statePath, { recursive: true })
+ .catch(enoentOk);
+ const cachedOut = fs.promises
+ .rm(locator.cachePath, { recursive: true })
+ .catch(enoentOk);
+ await Promise.all([cleanedUp, restated, cachedOut]);
+};

MODIFY
packages/daemon/test/test-endo.js
packages/daemon/test/test-endo.js
@@ -12,7 +12,14 @@ import url from 'url';
import path from 'path';
import { E } from '@endo/far';
import { makePromiseKit } from '@endo/promise-kit';
-import { start, stop, restart, clean, makeEndoClient } from '../index.js';
+import {
+ start,
+ stop,
+ restart,
+ clean,
+ reset,
+ makeEndoClient,
+} from '../index.js';
const { raw } = String;
@@ -30,6 +37,7 @@ const locator = {
test.serial('lifecycle', async t => {
const { resolve: cancel, promise: cancelled } = makePromiseKit();
+ await reset(locator);
await clean(locator);
await start(locator);
await stop(locator);

feat(daemon): Add reset feature