@ai-sdk/provider-utils 4.0.41 → 4.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/provider-utils",
3
- "version": "4.0.41",
3
+ "version": "4.0.42",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -141,8 +141,7 @@ function isNodeDefaultFetch(fetch: FetchFunction): boolean {
141
141
 
142
142
  async function createSafeNodeFetch(): Promise<FetchFunction> {
143
143
  // Node 20.16+ exposes getBuiltinModule; older supported Node versions use an
144
- // indirect dynamic import. Keeping the specifier non-literal prevents browser
145
- // bundlers from pulling Node built-ins into the provider-utils entry point.
144
+ // indirect dynamic import that is hidden from browser bundle parsers.
146
145
  const [{ createRequire }, { lookup }] = await Promise.all([
147
146
  loadNodeModule<NodeModule>('node:module'),
148
147
  loadNodeModule<NodeDns>('node:dns'),
@@ -180,8 +179,18 @@ async function loadNodeModule<T>(id: string): Promise<T> {
180
179
  : (builtinModule as T);
181
180
  }
182
181
 
182
+ let dynamicImport: ((specifier: string) => Promise<unknown>) | undefined;
183
+
183
184
  function importNodeModule(id: string): Promise<unknown> {
184
- return import(id);
185
+ // Metro rejects non-static dynamic imports while parsing, even though this
186
+ // Node-only fallback is never executed in React Native. Construct the import
187
+ // function lazily so the distributed module contains no import expression for
188
+ // Metro to analyze and runtimes with process.getBuiltinModule avoid it.
189
+ dynamicImport ??= Function('specifier', 'return import(specifier)') as (
190
+ specifier: string,
191
+ ) => Promise<unknown>;
192
+
193
+ return dynamicImport(id);
185
194
  }
186
195
 
187
196
  function getCurrentModulePath(): string {