From dc299d923fa7f460235ae5587d0446fc63dbabd9 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Sat, 11 May 2024 00:33:08 -0400 Subject: [PATCH] fix: no node fs module in runtime closes #840 --- src/layers/2_generator/files.ts | 2 +- src/layers/2_generator/prelude.ts | 13 +++++++++++++ src/lib/prelude.ts | 17 ++--------------- 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 src/layers/2_generator/prelude.ts diff --git a/src/layers/2_generator/files.ts b/src/layers/2_generator/files.ts index 670e2c01d..c27365f6d 100644 --- a/src/layers/2_generator/files.ts +++ b/src/layers/2_generator/files.ts @@ -3,9 +3,9 @@ import { getPath } from '@dprint/typescript' import _ from 'json-bigint' import fs from 'node:fs/promises' import * as Path from 'node:path' -import { fileExists } from '../../lib/prelude.js' import type { OptionsInput } from './generateCode.js' import { generateCode, type Input as GenerateInput } from './generateCode.js' +import { fileExists } from './prelude.js' export interface Input { name?: string diff --git a/src/layers/2_generator/prelude.ts b/src/layers/2_generator/prelude.ts new file mode 100644 index 000000000..0f895429d --- /dev/null +++ b/src/layers/2_generator/prelude.ts @@ -0,0 +1,13 @@ +import fs from 'node:fs/promises' +import { errorFromMaybeError } from '../../lib/prelude.js' + +export const fileExists = async (path: string) => { + return Boolean( + await fs.stat(path).catch((_: unknown) => { + const error = errorFromMaybeError(_) + return `code` in error && typeof error.code === `string` && error.code === `ENOENT` + ? null + : Promise.reject(error) + }), + ) +} diff --git a/src/lib/prelude.ts b/src/lib/prelude.ts index ebdd8f518..4e0b740ea 100644 --- a/src/lib/prelude.ts +++ b/src/lib/prelude.ts @@ -1,3 +1,5 @@ +import type { ConditionalSimplifyDeep } from 'type-fest/source/conditional-simplify.js' + /* eslint-disable */ export type RemoveIndex = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] @@ -180,23 +182,8 @@ export type Values = T[keyof T] export type GetKeyOr = Key extends keyof T ? T[Key] : Or -import type { ConditionalSimplifyDeep } from 'type-fest/source/conditional-simplify.js' - export type SimplifyDeep = ConditionalSimplifyDeep | Date, object> -import fs from 'node:fs/promises' - -export const fileExists = async (path: string) => { - return Boolean( - await fs.stat(path).catch((_: unknown) => { - const error = errorFromMaybeError(_) - return `code` in error && typeof error.code === `string` && error.code === `ENOENT` - ? null - : Promise.reject(error) - }), - ) -} - export type As = U extends T ? U : never export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never