Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use dynamic import for node-specific libraries #820

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/core/src/lib/prepareParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -76,10 +72,15 @@ function merge(src: unknown, target: unknown) {
* into a parameters object for making an API request.
*
*/
function processFile(
async function processFile(
paramName: string | undefined,
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');
if (typeof file === 'string') {
// In order to support relative pathed files, we need to attempt to resolve them.
const resolvedFile = path.resolve(file);
Expand Down