From 77b8fe75d9b70cacca3555b3b9a6c450708830d8 Mon Sep 17 00:00:00 2001 From: CJ_Clippy Date: Wed, 16 Jul 2025 22:44:15 -0800 Subject: [PATCH] import nanospawn in cjs interop way --- services/our/src/tasks/createHlsPlaylist.ts | 17 ++++------------- services/our/src/utils/nanoSpawn.ts | 7 +++++++ 2 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 services/our/src/utils/nanoSpawn.ts diff --git a/services/our/src/tasks/createHlsPlaylist.ts b/services/our/src/tasks/createHlsPlaylist.ts index f667506..e994605 100644 --- a/services/our/src/tasks/createHlsPlaylist.ts +++ b/services/our/src/tasks/createHlsPlaylist.ts @@ -1,5 +1,4 @@ import type { Task, Helpers } from "graphile-worker"; -import spawn from 'nano-spawn'; import { PrismaClient } from "../../generated/prisma"; import { withAccelerate } from "@prisma/extension-accelerate"; import { getOrDownloadAsset } from "../utils/cache"; @@ -11,6 +10,7 @@ import { basename, join, dirname } from "node:path"; import { mkdirp } from "fs-extra"; import { listFilesRecursive } from "../utils/filesystem"; import { getMimeType } from "../utils/mimetype"; +import { getNanoSpawn } from "../utils/nanoSpawn"; const prisma = new PrismaClient().$extends(withAccelerate()); @@ -47,10 +47,12 @@ interface HlsVariant { + export async function createVariants(helpers: Helpers, inputFilePath: string): Promise { const workdir = join(env.CACHE_ROOT, nanoid()); await mkdirp(workdir); const baseName = basename(inputFilePath, '.mp4'); + const spawn = await getNanoSpawn() const resolutions = [ { width: 1920, height: 1080, bitrate: 4000000, name: '1080p' }, // 4Mbps @@ -99,6 +101,7 @@ export async function packageHls( ): Promise { const args: string[] = []; + const spawn = await getNanoSpawn() // Optional: sort variants by bandwidth descending variants.sort((a, b) => b.bandwidth - a.bandwidth); @@ -123,18 +126,6 @@ export async function packageHls( args.push('--segment_duration=2'); // matches Twitch’s chunk size - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) - helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) helpers.logger.info(`PILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE\nPILLS HERE`) await spawn('packager', args, { diff --git a/services/our/src/utils/nanoSpawn.ts b/services/our/src/utils/nanoSpawn.ts new file mode 100644 index 0000000..4e00c6b --- /dev/null +++ b/services/our/src/utils/nanoSpawn.ts @@ -0,0 +1,7 @@ +// utils/nanoSpawn.ts +// we do this because we need to use dynamic import() when using ESM only module via tsup CJS interop. + +export async function getNanoSpawn() { + const nanoSpawn = (await import('nano-spawn')).default; + return nanoSpawn +} \ No newline at end of file