From 57b5ee52e462fa5bfc8fcf3cacff000a442e7fc8 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 8 Jul 2025 18:30:43 +0200 Subject: [PATCH 1/3] feat: touch workaround --- cli/src/commands/server.ts | 4 ++++ cli/src/services/touch.services.ts | 35 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 cli/src/services/touch.services.ts diff --git a/cli/src/commands/server.ts b/cli/src/commands/server.ts index b22d100..fdb8d76 100644 --- a/cli/src/commands/server.ts +++ b/cli/src/commands/server.ts @@ -7,6 +7,7 @@ import {buildContext} from '../services/context.services'; import {setController} from '../services/controller.services'; import {collectIdentities} from '../services/identity.services'; import {transfer} from '../services/ledger.services'; +import {touchWatchedFile} from '../services/touch.services'; import type {CliContext} from '../types/context'; import {nextArg} from '../utils/args.utils'; @@ -92,6 +93,9 @@ const buildServer = ({context}: {context: CliContext}): Server => res.end(JSON.stringify(identities)); return; } + case 'touch': { + await touchWatchedFile({searchParams}); + } } error404(); diff --git a/cli/src/services/touch.services.ts b/cli/src/services/touch.services.ts new file mode 100644 index 0000000..a1bf8ad --- /dev/null +++ b/cli/src/services/touch.services.ts @@ -0,0 +1,35 @@ +import {isEmptyString} from '@dfinity/utils'; +import {yellow} from 'kleur'; +import {existsSync} from 'node:fs'; +import {utimes} from 'node:fs/promises'; +import {join} from 'node:path'; +import {DEV_DEPLOY_FOLDER} from '../constants/dev.constants'; + +/** + * Workaround Podman and Apple container issues on macOS: + * - https://github.com/containers/podman/issues/22343 + * - https://github.com/apple/container/issues/141 + */ +export const touchWatchedFile = async ({searchParams}: {searchParams: URLSearchParams}) => { + const file = searchParams.get('file'); + + if (isEmptyString(file)) { + console.log(`ℹ️ Skipped touching file: no file provided.`); + return; + } + + const filename = decodeURIComponent(file); + const filepath = join(DEV_DEPLOY_FOLDER, filename); + + if (!existsSync(filepath)) { + console.log(`ℹ️ Skipped touching file: ${yellow(filepath)} does not exist.`); + return; + } + + await touch(filepath); +}; + +const touch = async (filePath: string) => { + const now = new Date(); + await utimes(filePath, now, now); +}; From a573cfe902bec68e8c2fda27213ad5f98125cfcd Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 8 Jul 2025 18:34:36 +0200 Subject: [PATCH 2/3] fix: kleur import --- cli/src/services/touch.services.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/src/services/touch.services.ts b/cli/src/services/touch.services.ts index a1bf8ad..cd37a00 100644 --- a/cli/src/services/touch.services.ts +++ b/cli/src/services/touch.services.ts @@ -1,10 +1,12 @@ import {isEmptyString} from '@dfinity/utils'; -import {yellow} from 'kleur'; +import kleur from 'kleur'; import {existsSync} from 'node:fs'; import {utimes} from 'node:fs/promises'; import {join} from 'node:path'; import {DEV_DEPLOY_FOLDER} from '../constants/dev.constants'; +const {yellow} = kleur; + /** * Workaround Podman and Apple container issues on macOS: * - https://github.com/containers/podman/issues/22343 From d03bc2b1d448c4d74c43f1f6e33efc4f1b159f58 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 8 Jul 2025 19:12:27 +0200 Subject: [PATCH 3/3] feat: handle error and success response --- cli/src/commands/server.ts | 2 ++ cli/src/services/touch.services.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/src/commands/server.ts b/cli/src/commands/server.ts index fdb8d76..06073b6 100644 --- a/cli/src/commands/server.ts +++ b/cli/src/commands/server.ts @@ -95,6 +95,8 @@ const buildServer = ({context}: {context: CliContext}): Server => } case 'touch': { await touchWatchedFile({searchParams}); + done(); + return; } } diff --git a/cli/src/services/touch.services.ts b/cli/src/services/touch.services.ts index cd37a00..b2a2800 100644 --- a/cli/src/services/touch.services.ts +++ b/cli/src/services/touch.services.ts @@ -5,7 +5,7 @@ import {utimes} from 'node:fs/promises'; import {join} from 'node:path'; import {DEV_DEPLOY_FOLDER} from '../constants/dev.constants'; -const {yellow} = kleur; +const {yellow, red} = kleur; /** * Workaround Podman and Apple container issues on macOS: @@ -28,7 +28,11 @@ export const touchWatchedFile = async ({searchParams}: {searchParams: URLSearchP return; } - await touch(filepath); + try { + await touch(filepath); + } catch (err: unknown) { + console.log(red(`️‼️ Unexpected error while touching ${filepath}`), err); + } }; const touch = async (filePath: string) => {