Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(version): bump algoliasearch version to v4.11.0 #4939

Merged
merged 5 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,35 @@ To run the test continuously based on what you changed (useful when developing o
yarn test --watch
```

### Type checks

Type checks ensure code is correctly typed both for code quality and compatibility for our TypeScript users.
Haroenv marked this conversation as resolved.
Show resolved Hide resolved

To ensure typing is correct in the latest version of `instantsearch.js`:
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
```sh
yarn type-check
```

Since we still support `instantsearch.js@v3`, types checking should also be done against `v3`.

```sh
sh scripts/tests/algoliasearch-v3-tests.sh
```


### Type check for `algoliasearch` updates
Haroenv marked this conversation as resolved.
Show resolved Hide resolved

Users might update `instantsearch.js` to its latest version but keep older versions of `algoliasearch`. TypeScript users using previous versions of `algoliasearch` import different type definitions. Nonetheless, `instantsearch.js` should support both old and new `instantsearch` types.


Currently, we ensure compatibility of `algoliasearch` **v3** and **v4** in `instantsearch.js`.
In type checks of the previous section, we confirmed type compatibility with algoliasearch **v4**. With the following type-check we also ensure compatibility with `algoliasearch` **v3**.


```sh
sh scripts/tests/algoliasearch-v3.sh
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
```

## Linting

Linters are static checkers for code. They help us maintain a consistent code base. They are used for JavaScript and TypeScript files.
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ npm install instantsearch.js algoliasearch
yarn add instantsearch.js algoliasearch
```

### TypeScript users

To use `instantsearch.js` in a TypeScript environment, depending on your `algoliasearch` versions, different types must be imported:

**`algoliasearch` version 3**

```bash
npm install @types/algoliasearch@3
# or
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
yarn add @types/algoliasearch@3
```

The Algoliasearch client version 3 support is close to an end and thus **deprecated**.
Haroenv marked this conversation as resolved.
Show resolved Hide resolved

**`algoliasearch` version 4**

V4 uses the types provided by both `algoliasearch` and `@algolia/client-search`.

```bash
yarn add algoliasearch@4 @algolia/client-search
```

In case you are not using `algoliasearch` as the search client, it must still be installed in TypeScript environments.

## Documentation

The documentation is available on the [Algolia website](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/).
Expand Down
30 changes: 30 additions & 0 deletions scripts/tests/algoliasearch-v3-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

echo "Cache current version of algoliasearch"
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
current_algoliasearch_version=$(cat package.json | grep -r '"algoliasearch"' | cut -d '"' -f4)
current_client_search_version=$(cat package.json | grep -r '"@algolia/client-search"' | cut -d '"' -f4)

echo "Update algoliasearch to v3 version"
# Remove algoliasearch latest
yarn remove @algolia/client-search >/dev/null

# Install algoliasearch v3
yarn add @types/algoliasearch@3.34.10 algoliasearch@3.35.1 >/dev/null

echo "Run type check on algoliasearch v3"
# Now that instantsearch.js uses algoliasearch v3. Run the related type-check
yarn run type-check:v3

echo "Rollback to previous algoliasearch version"
## Rollback to previous algoliasearch version

# remove obsolete types file
yarn remove @types/algoliasearch algoliasearch >/dev/null

# Install previous algoliasearch packages.
yarn add algoliasearch@$current_algoliasearch_version --dev >/dev/null
yarn add @algolia/client-search@$current_client_search_version --dev >/dev/null

echo "Run type check on algoliasearch v4 to ensure successful execution of the script"
# Run type-check to ensure the execution of the script was successful.
yarn run type-check
6 changes: 6 additions & 0 deletions src/connectors/geo-search/__tests__/connectGeoSearch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
}),
]);

// @ts-ignore
helper.setQueryParameter('insideBoundingBox', '10,12,14,16');

widget.init!(
Expand Down Expand Up @@ -659,6 +660,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
}),
]);

// @ts-ignore
sarahdayan marked this conversation as resolved.
Show resolved Hide resolved
helper.setQueryParameter('insideBoundingBox', '10,12,14,16');

widget.init!(
Expand Down Expand Up @@ -694,6 +696,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
expect(lastRenderArgs(render).hasMapMoveSinceLastRefine()).toBe(true);
expect(lastRenderArgs(render).isRefinedWithMap()).toBe(true);

// @ts-ignore
helper.setQueryParameter('insideBoundingBox', '12,14,16,18');

widget.render!(
Expand All @@ -718,6 +721,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
const helper = createFakeHelper();

// Simulate the configuration or external setter (like URLSync)
// @ts-ignore
helper.setQueryParameter('insideBoundingBox', '10,12,12,14');

widget.init!(
Expand Down Expand Up @@ -1338,6 +1342,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
const widget = customGeoSearch({});
const helper = createFakeHelper();

// @ts-ignore
helper.setQueryParameter('insideBoundingBox', '10,12,12,14');

const expectation = new SearchParameters({ index: '' });
Expand Down Expand Up @@ -1557,6 +1562,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
it('gives all render functions with refinement', () => {
const [widget, helper] = getInitializedWidget();
helper.setQueryParameter('aroundLatLng', '10, 12');
// @ts-ignore
helper.setQueryParameter('insideBoundingBox', '10,12,11,2');

expect(
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/geo-search/__tests__/geo-search-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/geo-search/
// Simulate the current refinement
helper.setQueryParameter(
'insideBoundingBox',
// @ts-expect-error class uses strings
// @ts-ignore
'48.84174222399724, 2.367719162523599, 48.81614630305218, 2.284205902635904'
);

Expand Down