diff --git a/src/goods.ts b/src/goods.ts index e63f23e11d9..0726da71be0 100644 --- a/src/goods.ts +++ b/src/goods.ts @@ -20,7 +20,7 @@ import { createInterface } from 'node:readline' import { $, within, ProcessOutput } from './core.js' import { Duration, - isNodeEighteenOrGreaterThanEighteen, + isNativeFetchExists, isString, parseDuration, } from './util.js' @@ -56,7 +56,7 @@ export function sleep(duration: Duration) { } export async function globalFetch(url: RequestInfo, init?: RequestInit) { - if (isNodeEighteenOrGreaterThanEighteen) { + if (isNativeFetchExists) { $.log({ kind: 'fetch', url, init }) return (globalThis as any).fetch(url, init) } diff --git a/src/util.ts b/src/util.ts index ade0a7caf0c..74353323f54 100644 --- a/src/util.ts +++ b/src/util.ts @@ -341,8 +341,7 @@ export function formatCmd(cmd?: string): string { return out + '\n' } -export const isNodeEighteenOrGreaterThanEighteen = - process.versions && Number(process.versions.node.split('.')[0]) >= 18 +export const isNativeFetchExists = 'fetch' in globalThis; const reservedWords = [ 'if', diff --git a/test/cli.test.js b/test/cli.test.js index 300b5610d0c..6dfc077ac1a 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -15,7 +15,7 @@ import { suite } from 'uvu' import * as assert from 'uvu/assert' import '../build/globals.js' -import { isNodeEighteenOrGreaterThanEighteen } from './utils/test-utils.js' +import { isNativeFetchExists } from './utils/test-utils.js' const test = suite('cli') @@ -98,7 +98,7 @@ test('supports `--prefix` flag ', async () => { }) test('scripts from https', async () => { - if (!isNodeEighteenOrGreaterThanEighteen) { + if (!isNativeFetchExists) { return true; } $`cat ${path.resolve('test/fixtures/echo.http')} | nc -l 8080` @@ -107,7 +107,7 @@ test('scripts from https', async () => { }) test('scripts from https not ok', async () => { - if (!isNodeEighteenOrGreaterThanEighteen) { + if (!isNativeFetchExists) { return true; } $`echo $'HTTP/1.1 500\n\n' | nc -l 8081` diff --git a/test/goods.test.js b/test/goods.test.js index 77ebbffe083..ed1becb5110 100644 --- a/test/goods.test.js +++ b/test/goods.test.js @@ -16,7 +16,7 @@ import chalk from 'chalk' import { suite } from 'uvu' import * as assert from 'uvu/assert' -import { isNodeEighteenOrGreaterThanEighteen } from './utils/test-utils.js' +import { isNativeFetchExists } from './utils/test-utils.js' import '../build/globals.js' const test = suite('goods') @@ -50,7 +50,7 @@ test('globby available', async () => { }) test('fetch() works', async () => { - if(!isNodeEighteenOrGreaterThanEighteen){ + if(!isNativeFetchExists){ return true; } assert.match( diff --git a/test/utils/test-utils.js b/test/utils/test-utils.js index 7e2a864e229..c75a0321539 100644 --- a/test/utils/test-utils.js +++ b/test/utils/test-utils.js @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -const isNodeEighteenOrGreaterThanEighteen = - process.versions && Number(process.versions.node.split('.')[0]) >= 18 +const isNativeFetchExists = 'fetch' in globalThis; -export { isNodeEighteenOrGreaterThanEighteen } +export { isNativeFetchExists }