From 9903d385a73dc208631ecb481a1f2d2824096557 Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Sun, 31 May 2026 21:26:37 +0200 Subject: [PATCH] fix: Replace import.meta.env for better compatibility --- packages/jotai-eager/build.config.ts | 9 +++++++++ packages/jotai-eager/src/soon.ts | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 packages/jotai-eager/build.config.ts diff --git a/packages/jotai-eager/build.config.ts b/packages/jotai-eager/build.config.ts new file mode 100644 index 0000000..f8329f4 --- /dev/null +++ b/packages/jotai-eager/build.config.ts @@ -0,0 +1,9 @@ +import { defineBuildConfig } from 'unbuild'; + +export default defineBuildConfig({ + replace: { + // Some consumers complain when import.meta is used, even when it's + // emitted only in the .mjs entrypoint (looking at you CodeSandbox) + 'import.meta.env?.MODE': 'process.env.NODE_ENV', + }, +}); diff --git a/packages/jotai-eager/src/soon.ts b/packages/jotai-eager/src/soon.ts index 6dedef3..4956d81 100644 --- a/packages/jotai-eager/src/soon.ts +++ b/packages/jotai-eager/src/soon.ts @@ -1,11 +1,11 @@ import { getPromiseMeta, setPromiseMeta } from './isPromise.ts'; /** - * Executes `process` with `data` as input synchronously if `data` is known, meaning + * Executes `handler` with `data` as input synchronously if `data` is known, meaning * it is not an unresolved promise of the value. * * @param data The data to process, now or later (soon). - * @param process The processing function that takes the awaited data and returns a result. + * @param handler The processing function that takes the awaited data and returns a result. * @returns The result of processing the data synchronously if available, or a promise of the result if data is pending. * * @example @@ -22,15 +22,15 @@ import { getPromiseMeta, setPromiseMeta } from './isPromise.ts'; */ export function soon( data: TInput, - process: (knownData: Awaited) => TOutput, + handler: (knownData: Awaited) => TOutput, ): TOutput | Promise>; /** - * Executes `process` with `data` as input synchronously if `data` is known, meaning + * Executes `handler` with `data` as input synchronously if `data` is known, meaning * it is not an unresolved promise of the value. * - * @param process The processing function that takes the awaited data and returns a result. - * @returns A function that can be called with `data`, and returns the result (or promise of result) from running `process` on `data`. + * @param handler The processing function that takes the awaited data and returns a result. + * @returns A function that can be called with `data`, and returns the result (or promise of result) from running `handler` on `data`. * * @example * ```ts @@ -42,7 +42,7 @@ export function soon( * ``` */ export function soon( - process: (knownData: NoInfer>) => TOutput, + handler: (knownData: NoInfer>) => TOutput, ): (data: TInput) => TOutput | Promise>; export function soon( @@ -62,14 +62,14 @@ export function soon( function _soonImpl( data: TInput, - process: (knownData: NoInfer>) => TOutput, + handler: (knownData: NoInfer>) => TOutput, ): TOutput | Promise> { const meta = getPromiseMeta>(data); if (meta) { if (meta.status === 'fulfilled') { - // can process the value earlier - return process(meta.value); + // can handle the value earlier + return handler(meta.value); } if (meta.status === 'rejected') { @@ -84,7 +84,7 @@ function _soonImpl( const transformedPromise = promise.then( (value) => { setPromiseMeta(promise, { status: 'fulfilled', value }); - return process(value) as Awaited; + return handler(value) as Awaited; }, (reason) => { setPromiseMeta(promise, { status: 'rejected', reason }); @@ -95,7 +95,7 @@ function _soonImpl( } try { - return process(data as Awaited); + return handler(data as Awaited); } catch (err) { // To keep the error handling behavior consistent, lets // always return a rejected promise, even if the processing