@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/CHANGELOG.md +6 -0
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/safe-node-fetch.ts +12 -3
package/package.json
CHANGED
package/src/safe-node-fetch.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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 {
|