From 17e87a5dd79a000ff9f583ca8c64e6221654e3ed Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 16 Nov 2023 10:31:14 -0600 Subject: [PATCH 1/2] fix: use dynamic import for node-specific libraries --- packages/core/src/lib/prepareParams.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/src/lib/prepareParams.ts b/packages/core/src/lib/prepareParams.ts index 1d9cd9fb..cdc0747a 100644 --- a/packages/core/src/lib/prepareParams.ts +++ b/packages/core/src/lib/prepareParams.ts @@ -2,13 +2,9 @@ import type { ReadStream } from 'node:fs'; import type { Operation } from 'oas/operation'; import type { ParameterObject, SchemaObject } from 'oas/types'; -import fs from 'node:fs'; -import path from 'node:path'; import stream from 'node:stream'; import caseless from 'caseless'; -import DatauriParser from 'datauri/parser.js'; -import datauri from 'datauri/sync.js'; // `get-stream` is included in our bundle, see `tsup.config.ts` // eslint-disable-next-line import/no-extraneous-dependencies import { getStreamAsBuffer } from 'get-stream'; @@ -76,10 +72,14 @@ function merge(src: unknown, target: unknown) { * into a parameters object for making an API request. * */ -function processFile( +async function processFile( paramName: string | undefined, file: string | ReadStream, ): Promise<{ base64?: string; buffer?: Buffer; filename: string; paramName?: string } | undefined> { + const fs = await import('node:fs'); + const path = await import('node:path'); + const { default: DatauriParser } = await import('datauri/parser.js'); + const { default: datauri } = await import('datauri/sync.js'); if (typeof file === 'string') { // In order to support relative pathed files, we need to attempt to resolve them. const resolvedFile = path.resolve(file); From 012b2bc1bda04881f0d0c974112e19a2e392b7f3 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 18 Nov 2024 08:42:00 -0600 Subject: [PATCH 2/2] fix: lint --- packages/core/src/lib/prepareParams.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/lib/prepareParams.ts b/packages/core/src/lib/prepareParams.ts index a4381e67..0f02683c 100644 --- a/packages/core/src/lib/prepareParams.ts +++ b/packages/core/src/lib/prepareParams.ts @@ -77,6 +77,7 @@ async function processFile( file: ReadStream | string, ): Promise<{ base64?: string; buffer?: Buffer; filename: string; paramName?: string } | undefined> { const fs = await import('node:fs'); + // eslint-disable-next-line unicorn/import-style const path = await import('node:path'); const { default: DatauriParser } = await import('datauri/parser.js'); const { default: datauri } = await import('datauri/sync.js');