Skip to content

Commit

Permalink
Updated fetch exists check
Browse files Browse the repository at this point in the history
  • Loading branch information
theothirteen committed Jan 1, 2024
1 parent 34afa8d commit f431250
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/goods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { createInterface } from 'node:readline'
import { $, within, ProcessOutput } from './core.js'
import {
Duration,
isNodeEighteenOrGreaterThanEighteen,
isNativeFetchExists,
isString,
parseDuration,
} from './util.js'
Expand Down Expand Up @@ -57,7 +57,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)
}
Expand Down
3 changes: 1 addition & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions test/utils/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit f431250

Please sign in to comment.