Skip to content

Commit b319cc6

Browse files
Merge #1488
1488: Add conditional loading for cross-fetch/polyfill - favour native fetch r=bidoubiwa a=icyJoseph # Pull Request ## Related issue Fixes #1487 ## What does this PR do? Load `cross-fetch/polyfill` only if `fetch` is `undefined`. ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? #1487 was opened by me though... - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Joseph Chamochumbi <[email protected]>
2 parents 7950449 + f457cd8 commit b319cc6

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"test:ci": "yarn test --ci",
4545
"test:env": "yarn build && yarn test:env:nodejs && yarn test:env:esm && yarn test:env:node-ts",
4646
"test:env:node-ts": "yarn --cwd tests/env/typescript-node start",
47-
"test:env:nodejs": "node tests/env/node/index.js",
47+
"test:env:nodejs": "yarn build && node tests/env/node/index.js && node tests/env/node/getting_started.js",
4848
"test:env:esm": "yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start",
4949
"size": "node scripts/file-size ./dist/bundles/meilisearch.esm.min.js ./dist/bundles/meilisearch.umd.min.js",
5050
"style": "yarn lint",

src/errors/meilisearch-communication-error.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'cross-fetch/polyfill'
21
import { FetchError } from '../types'
32

43
class MeiliSearchCommunicationError extends Error {

src/http-requests.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'cross-fetch/polyfill'
2-
31
import { Config, EnqueuedTaskObject } from './types'
42
import { PACKAGE_VERSION } from './package-version'
53

@@ -120,6 +118,10 @@ class HttpRequests {
120118
body?: any
121119
config?: Record<string, any>
122120
}) {
121+
if (typeof fetch === 'undefined') {
122+
require('cross-fetch/dist/node-polyfill')
123+
}
124+
123125
const constructURL = new URL(url, this.url)
124126
if (params) {
125127
const queryParams = new URLSearchParams()

tests/env/node/getting_started.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const { MeiliSearch } = require('../../../dist/bundles/meilisearch.umd.js')
2121
// If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
2222
await index.updateFilterableAttributes([
2323
'director',
24-
'genres'
24+
'genres',
25+
'id'
2526
])
2627

2728
let response = await index.addDocuments(dataset)

0 commit comments

Comments
 (0)