From 2721a7e31d6ede55a3ae143289fd2bad89bee84b Mon Sep 17 00:00:00 2001 From: Gabriel Grant Date: Tue, 14 Jan 2025 17:34:57 -0800 Subject: [PATCH 1/2] feat: add support for --watch flag (default on) --- README.md | 1 + package.json | 5 ++++ src/config.ts | 9 +++++++ src/services/server-manager.ts | 1 + src/utils/__tests__/cmd.test.ts | 44 ++++++++++++++++++++++++++++----- src/utils/cmd.ts | 7 ++++++ 6 files changed, 61 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 29e0dd8..f440064 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ You can configure the extension using the following settings: - `marimo.browserType`: Browser to open marimo app (`system` or `embedded`, default: `embedded`) - `marimo.port`: Default port for marimo server (default: `2818`) - `marimo.sandbox`: Always start marimo in a sandbox, e.g. `marimo edit --sandbox` (default: `false`). Requires [`uv`](https://docs.astral.sh/uv/) to be installed. +- `marimo.watch`: Always start marimo with the `--watch` flag (default: `true`). - `marimo.host`: Hostname for marimo server (default: `localhost`) - `marimo.https`: Enable HTTPS for marimo server (default: `false`) - `marimo.enableToken`: Enable token authentication (default: `false`) diff --git a/package.json b/package.json index 6cd0f5d..9c3ec48 100644 --- a/package.json +++ b/package.json @@ -336,6 +336,11 @@ "default": false, "description": "Whether to always start marimo in a sandbox. Requires `uv` to be installed." }, + "marimo.watch": { + "type": "boolean", + "default": true, + "description": "Whether to always start marimo with the --watch flag." + }, "marimo.https": { "type": "boolean", "default": false, diff --git a/src/config.ts b/src/config.ts index f2ab301..48e8a39 100644 --- a/src/config.ts +++ b/src/config.ts @@ -21,6 +21,7 @@ export interface Config { readonly tokenPassword: string | undefined; readonly https: boolean; readonly sandbox: boolean; + readonly watch: boolean; } /** @@ -131,6 +132,14 @@ export const Config = { get sandbox(): boolean { return getConfig("sandbox", false); }, + + /** + * Whether to always start marimo with the --watch flag. + * @default true + */ + get watch(): boolean { + return getConfig("watch", true); + }, }; export async function composeUrl(port: number): Promise { diff --git a/src/services/server-manager.ts b/src/services/server-manager.ts index 00a1291..545a0a6 100644 --- a/src/services/server-manager.ts +++ b/src/services/server-manager.ts @@ -283,6 +283,7 @@ export class ServerManager implements IServerManager { .enableToken(this.config.enableToken) .tokenPassword(this.config.tokenPassword) .sandbox(this.config.sandbox) + .watch(this.config.watch) .build(); } diff --git a/src/utils/__tests__/cmd.test.ts b/src/utils/__tests__/cmd.test.ts index dc6ee98..047eab1 100644 --- a/src/utils/__tests__/cmd.test.ts +++ b/src/utils/__tests__/cmd.test.ts @@ -20,7 +20,7 @@ describe("MarimoCmdBuilder", () => { .tokenPassword("") .build(); expect(cmd).toMatchInlineSnapshot( - `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token"`, + `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --watch"`, ); }); @@ -36,7 +36,7 @@ describe("MarimoCmdBuilder", () => { .tokenPassword("secret") .build(); expect(cmd).toMatchInlineSnapshot( - `"marimo --yes -d edit path/to/file --host=localhost --port=2718 --headless --token-password=secret"`, + `"marimo --yes -d edit path/to/file --host=localhost --port=2718 --headless --token-password=secret --watch"`, ); }); @@ -52,7 +52,7 @@ describe("MarimoCmdBuilder", () => { .tokenPassword("") .build(); expect(cmd).toMatchInlineSnapshot( - `"marimo --yes run path/to/file --host=localhost --port=2718 --headless --no-token"`, + `"marimo --yes run path/to/file --host=localhost --port=2718 --headless --no-token --watch"`, ); }); @@ -69,7 +69,7 @@ describe("MarimoCmdBuilder", () => { .build(); expect(b).toMatchInlineSnapshot( - `"marimo --yes edit "path/to/some file" --host=localhost --port=2718 --headless --no-token"`, + `"marimo --yes edit "path/to/some file" --host=localhost --port=2718 --headless --no-token --watch"`, ); }); @@ -86,7 +86,7 @@ describe("MarimoCmdBuilder", () => { .build(); expect(b).toMatchInlineSnapshot( - `"marimo --yes edit path/to/file --host=0.0.0.0 --port=2718 --headless --no-token"`, + `"marimo --yes edit path/to/file --host=0.0.0.0 --port=2718 --headless --no-token --watch"`, ); }); @@ -102,7 +102,39 @@ describe("MarimoCmdBuilder", () => { .sandbox(true) .build(); expect(cmd).toMatchInlineSnapshot( - `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --sandbox"`, + `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --sandbox --watch"`, + ); + }); + + it("should support watch mode", () => { + const cmd = new MarimoCmdBuilder() + .debug(false) + .mode("edit") + .fileOrDir("path/to/file") + .host("localhost") + .port(2718) + .headless(true) + .enableToken(false) + .watch(true) + .build(); + expect(cmd).toMatchInlineSnapshot( + `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --watch"`, + ); + }); + + it("should support disabling watch mode", () => { + const cmd = new MarimoCmdBuilder() + .debug(false) + .mode("edit") + .fileOrDir("path/to/file") + .host("localhost") + .port(2718) + .headless(true) + .enableToken(false) + .watch(false) + .build(); + expect(cmd).toMatchInlineSnapshot( + `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token"`, ); }); }); diff --git a/src/utils/cmd.ts b/src/utils/cmd.ts index 8aab156..010ad07 100644 --- a/src/utils/cmd.ts +++ b/src/utils/cmd.ts @@ -64,6 +64,13 @@ export class MarimoCmdBuilder { return this; } + watch(value: boolean) { + if (value) { + this.cmd.push("--watch"); + } + return this; + } + build() { return this.cmd.join(" "); } From 65d650630f2654b3e9a19bf481363c05f754f3c7 Mon Sep 17 00:00:00 2001 From: Gabriel Grant Date: Tue, 14 Jan 2025 18:06:35 -0800 Subject: [PATCH 2/2] don't expect --watch flag in cmd builder tests tests don't use the default config, so shouldn't expect the --watch flag unless explicitly set --- src/utils/__tests__/cmd.test.ts | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/utils/__tests__/cmd.test.ts b/src/utils/__tests__/cmd.test.ts index 047eab1..eb35196 100644 --- a/src/utils/__tests__/cmd.test.ts +++ b/src/utils/__tests__/cmd.test.ts @@ -20,7 +20,7 @@ describe("MarimoCmdBuilder", () => { .tokenPassword("") .build(); expect(cmd).toMatchInlineSnapshot( - `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --watch"`, + `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token"`, ); }); @@ -36,7 +36,7 @@ describe("MarimoCmdBuilder", () => { .tokenPassword("secret") .build(); expect(cmd).toMatchInlineSnapshot( - `"marimo --yes -d edit path/to/file --host=localhost --port=2718 --headless --token-password=secret --watch"`, + `"marimo --yes -d edit path/to/file --host=localhost --port=2718 --headless --token-password=secret"`, ); }); @@ -52,7 +52,7 @@ describe("MarimoCmdBuilder", () => { .tokenPassword("") .build(); expect(cmd).toMatchInlineSnapshot( - `"marimo --yes run path/to/file --host=localhost --port=2718 --headless --no-token --watch"`, + `"marimo --yes run path/to/file --host=localhost --port=2718 --headless --no-token"`, ); }); @@ -69,7 +69,7 @@ describe("MarimoCmdBuilder", () => { .build(); expect(b).toMatchInlineSnapshot( - `"marimo --yes edit "path/to/some file" --host=localhost --port=2718 --headless --no-token --watch"`, + `"marimo --yes edit "path/to/some file" --host=localhost --port=2718 --headless --no-token"`, ); }); @@ -86,7 +86,7 @@ describe("MarimoCmdBuilder", () => { .build(); expect(b).toMatchInlineSnapshot( - `"marimo --yes edit path/to/file --host=0.0.0.0 --port=2718 --headless --no-token --watch"`, + `"marimo --yes edit path/to/file --host=0.0.0.0 --port=2718 --headless --no-token"`, ); }); @@ -102,7 +102,7 @@ describe("MarimoCmdBuilder", () => { .sandbox(true) .build(); expect(cmd).toMatchInlineSnapshot( - `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --sandbox --watch"`, + `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --sandbox"`, ); }); @@ -121,20 +121,4 @@ describe("MarimoCmdBuilder", () => { `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --watch"`, ); }); - - it("should support disabling watch mode", () => { - const cmd = new MarimoCmdBuilder() - .debug(false) - .mode("edit") - .fileOrDir("path/to/file") - .host("localhost") - .port(2718) - .headless(true) - .enableToken(false) - .watch(false) - .build(); - expect(cmd).toMatchInlineSnapshot( - `"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token"`, - ); - }); });