Skip to content

Commit 2823c40

Browse files
sarahdayanHaroenvdhayab
committed
refactor: introduce instantsearch-core (#6371)
* feat: introduce `instantsearch-core` package * Apply suggestions from code review Co-authored-by: Dhaya <154633+dhayab@users.noreply.github.com> --------- Co-authored-by: Haroen Viaene <hello@haroen.me> Co-authored-by: Dhaya <154633+dhayab@users.noreply.github.com>
1 parent a8b4c8c commit 2823c40

28 files changed

+190
-36
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ jobs:
178178
- packages/vue-instantsearch/vue2
179179
- packages/vue-instantsearch/vue3
180180
- packages/instantsearch-ui-components/dist
181+
- packages/instantsearch-core/dist
181182

182183
test metadata:
183184
<<: *defaults

.codesandbox/ci.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"packages/react-instantsearch-nextjs",
1616
"packages/vue-instantsearch",
1717
"packages/instantsearch.css",
18-
"packages/instantsearch-ui-components"
18+
"packages/instantsearch-ui-components",
19+
"packages/instantsearch-core"
1920
],
2021
"node": "16"
2122
}

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ const config = {
168168
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
169169
'@typescript-eslint/method-signature-style': 'error',
170170
'@typescript-eslint/unbound-method': 'error',
171+
'import/no-unresolved': [
172+
'error',
173+
{ ignore: ['instantsearch-core/types'] },
174+
],
171175
},
172176
},
173177
{

babel.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ module.exports = (api) => {
146146
],
147147
],
148148
},
149+
{
150+
test: 'packages/instantsearch-core',
151+
plugins: [
152+
[
153+
'@babel/plugin-transform-runtime',
154+
{
155+
corejs: false,
156+
helpers: true,
157+
regenerator: false,
158+
},
159+
],
160+
],
161+
},
149162
],
150163
// jsx is transpiled, so the comment should no longer be present in the final files
151164
shouldPrintComment: (value) => !value.startsWith('* @jsx'),

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const config = {
5454
'^instantsearch.js/(.*)$': '<rootDir>/packages/instantsearch.js/$1',
5555
'^instantsearch-ui-components/(.*)$':
5656
'<rootDir>/packages/instantsearch-ui-components/$1',
57+
'^instantsearch-core/(.*)$': '<rootDir>/packages/instantsearch-core/$1',
5758
},
5859
modulePathIgnorePatterns: [
5960
'<rootDir>/packages/create-instantsearch-app/src/templates',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Change Log

packages/instantsearch-core/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3+
4+
- [instantsearch-core](#instantsearch-core)
5+
- [Contributing](#contributing)
6+
- [License](#license)
7+
8+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
9+
10+
# instantsearch-core
11+
12+
InstantSearch Core is an open-source UI library used by InstantSearch for common utilities and types.
13+
14+
> Note: `instantsearch-core` exists for internal usage and isn't designed for public consumption.
15+
16+
## Contributing
17+
18+
We welcome all contributors, from casual to regular 💙
19+
20+
- **Bug report**. Is something not working as expected? [Send a bug report][contributing-bugreport].
21+
- **Feature request**. Would you like to add something to the library? [Send a feature request][contributing-featurerequest].
22+
- **Documentation**. Did you find a typo in the doc? [Open an issue][contributing-newissue] and we'll take care of it.
23+
- **Development**. If you don't know where to start, you can check the open issues that are [tagged easy][contributing-label-easy], the [bugs][contributing-label-bug] or [chores][contributing-label-chore].
24+
25+
To start contributing to code, you need to:
26+
27+
1. [Fork the project](https://help.github.com/articles/fork-a-repo/)
28+
1. [Clone the repository](https://help.github.com/articles/cloning-a-repository/)
29+
1. Install the dependencies: `yarn`
30+
31+
Please read [our contribution process](https://github.com/algolia/instantsearch/blob/master/CONTRIBUTING.md) to learn more.
32+
33+
## License
34+
35+
InstantSearch Core is [MIT licensed](../../LICENSE).
36+
37+
<!-- Links -->
38+
39+
[contributing-bugreport]: https://github.com/algolia/instantsearch/issues/new?template=BUG_REPORT.yml&labels=triage,Library%3A%20InstantSearch+Core
40+
[contributing-featurerequest]: https://github.com/algolia/instantsearch/discussions/new?category=ideas&labels=triage,Library%3A%20InstantSearch+Core&title=Feature%20request%3A%20
41+
[contributing-newissue]: https://github.com/algolia/instantsearch/issues/new?labels=triage,Library%3A%20InstantSearch+Core
42+
[contributing-label-easy]: https://github.com/algolia/instantsearch/issues?q=is%3Aopen+is%3Aissue+label%3A%22Difficulty%3A+Easy%22+label%3A%22Library%3A%20InstantSearch+Core%22
43+
[contributing-label-bug]: https://github.com/algolia/instantsearch/issues?q=is%3Aissue+is%3Aopen+label%3A%22Type%3A+Bug%22+label%3A%22Library%3A%20InstantSearch+Core%22
44+
[contributing-label-chore]: https://github.com/algolia/instantsearch/issues?q=is%3Aissue+is%3Aopen+label%3A%22Type%3A+Chore%22+label%3A%22Library%3A%20InstantSearch+Core%22
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "instantsearch-core",
3+
"version": "0.1.0",
4+
"description": "Common utilities and types for InstantSearch.",
5+
"types": "dist/es/index.d.ts",
6+
"main": "dist/cjs/index.js",
7+
"module": "dist/es/index.js",
8+
"type": "module",
9+
"exports": {
10+
".": {
11+
"types": "./dist/es/index.d.ts",
12+
"require": "./dist/cjs/index.js",
13+
"default": "./dist/es/index.js"
14+
},
15+
"./types": {
16+
"types": "./types/index.d.ts",
17+
"require": "./types/index.cjs",
18+
"default": "./types/index.mjs"
19+
}
20+
},
21+
"sideEffects": false,
22+
"license": "MIT",
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/algolia/instantsearch"
26+
},
27+
"author": {
28+
"name": "Algolia, Inc.",
29+
"url": "https://www.algolia.com"
30+
},
31+
"keywords": [
32+
"algolia",
33+
"components",
34+
"fast",
35+
"instantsearch",
36+
"react",
37+
"search"
38+
],
39+
"files": [
40+
"README.md",
41+
"dist"
42+
],
43+
"scripts": {
44+
"clean": "rm -rf dist",
45+
"build": "yarn build:cjs && yarn build:es && yarn build:types",
46+
"build:es:base": "BABEL_ENV=es,disableHoisting babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/es --ignore '**/__tests__/**/*','**/__mocks__/**/*'",
47+
"build:es": "yarn build:es:base --quiet",
48+
"build:cjs": "BABEL_ENV=cjs,disableHoisting babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/cjs --ignore '**/__tests__/**/*','**/__mocks__/**/*' --quiet && ../../scripts/prepare-cjs.sh",
49+
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/es",
50+
"version": "./scripts/version.cjs",
51+
"watch:es": "yarn --silent build:es:base --watch"
52+
},
53+
"dependencies": {
54+
"@babel/runtime": "^7.1.2",
55+
"algoliasearch-helper": "3.22.5"
56+
}
57+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const version = require('../package.json').version;
7+
8+
fs.writeFileSync(
9+
path.resolve(__dirname, '../src/version.ts'),
10+
`export default '${version}';\n`
11+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import version from './version';
2+
3+
export { version };
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default '0.1.0';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../tsconfig.declaration"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type * from 'algoliasearch-helper/types/algoliasearch.d.ts';
2+
3+
export {};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file exists to ensure when someone imports `instantsearch-core/types`,
2+
// a file exists to be resolved. Normally, this will never be used.
3+
module.exports = {};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type * from './algoliasearch.d.ts';
2+
export type * from './insights.d.ts';
3+
export type * from './results.d.ts';
4+
export type * from './utils.d.ts';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file exists to ensure when someone imports `instantsearch-core/types`,
2+
// a file exists to be resolved. Normally, this will never be used.
3+
export {};

packages/instantsearch.js/src/types/insights.ts renamed to packages/instantsearch-core/types/insights.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Hit } from './results';
1+
import type { Hit } from './results.d.ts';
22
import type {
33
InsightsMethodMap as _InsightsMethodMap,
44
InsightsClient as _InsightsClient,

packages/instantsearch.js/src/types/results.ts renamed to packages/instantsearch-core/types/results.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SearchOptions } from './algoliasearch';
1+
import type { SearchOptions } from './algoliasearch.d.ts';
22
import type {
33
PlainSearchParameters,
44
RecommendParametersOptions,

packages/instantsearch.js/src/types/utils.ts renamed to packages/instantsearch-core/types/utils.d.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ export type HighlightedParts = {
33
isHighlighted: boolean;
44
};
55

6-
// https://stackoverflow.com/questions/48230773/how-to-create-a-partial-like-that-requires-a-single-property-to-be-set/48244432#48244432
6+
/**
7+
* Makes at least one of an object property required.
8+
* https://stackoverflow.com/questions/48230773/how-to-create-a-partial-like-that-requires-a-single-property-to-be-set/48244432#48244432
9+
*/
710
export type AtLeastOne<
811
TTarget,
912
TMapped = { [Key in keyof TTarget]: Pick<TTarget, Key> }
1013
> = Partial<TTarget> & TMapped[keyof TMapped];
1114

12-
// removes intermediary composed types in IntelliSense
15+
/**
16+
* Removes intermediary composed types in IntelliSense
17+
*/
1318
export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
1419

15-
// Make certain keys in an object required
20+
/**
21+
* Make certain keys in an object required.
22+
*/
1623
export type RequiredKeys<TObject, TKeys extends keyof TObject> = Expand<
1724
Required<Pick<TObject, TKeys>> & Omit<TObject, TKeys>
1825
>;

packages/instantsearch.js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@types/qs": "^6.5.3",
3232
"algoliasearch-helper": "3.22.5",
3333
"htm": "^3.0.0",
34+
"instantsearch-core": "0.1.0",
3435
"instantsearch-ui-components": "0.9.0",
3536
"preact": "^10.10.0",
3637
"qs": "^6.5.1 < 6.10",

packages/instantsearch.js/src/connectors/dynamic-widgets/__tests__/connectDynamicWidgets-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { index } from '../../../widgets';
2020
import connectHierarchicalMenu from '../../hierarchical-menu/connectHierarchicalMenu';
2121
import connectRefinementList from '../../refinement-list/connectRefinementList';
2222

23-
import type { SearchResponse } from '../../../types/algoliasearch';
2423
import type { DynamicWidgetsConnectorParams } from '../connectDynamicWidgets';
24+
import type { SearchResponse } from 'instantsearch-core/types';
2525

2626
expect.addSnapshotSerializer(widgetSnapshotSerializer);
2727

packages/instantsearch.js/src/index.es.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ import { carousel } from 'instantsearch.js/es/templates'`
6969

7070
export default instantsearch;
7171

72-
export * from './types';
72+
export type * from './types';

packages/instantsearch.js/src/types/algoliasearch.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/instantsearch.js/src/types/connector.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { InsightsClient } from './insights';
21
import type { InstantSearch } from './instantsearch';
3-
import type { Hit } from './results';
42
import type { UnknownWidgetParams, Widget, WidgetDescription } from './widget';
53
import type { SearchResults } from 'algoliasearch-helper';
4+
import type { Hit, InsightsClient } from 'instantsearch-core/types';
65

76
/**
87
* The base renderer options. All render functions receive
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
// internal
2-
export * from './utils';
3-
4-
// Algolia-related
5-
// eslint-disable-next-line import/export
6-
export * from './algoliasearch';
7-
export * from './results';
1+
export type * from 'instantsearch-core/types';
82

93
// component-related
10-
export * from './component';
4+
export type * from './component';
115

126
// instantsearch-related
13-
export * from './instantsearch';
14-
export * from './middleware';
15-
export * from './router';
16-
export * from './insights';
7+
export type * from './instantsearch';
8+
export type * from './middleware';
9+
export type * from './router';
1710

1811
// widget-related
19-
export * from './connector';
20-
export * from './widget-factory';
21-
export * from './widget';
22-
export * from './ui-state';
23-
export * from './render-state';
24-
export * from './templates';
12+
export type * from './connector';
13+
export type * from './widget-factory';
14+
export type * from './widget';
15+
export type * from './ui-state';
16+
export type * from './render-state';
17+
export type * from './templates';
18+
19+
export {};

packages/instantsearch.js/src/types/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type InstantSearch from '../lib/InstantSearch';
22
import type { UiState } from './ui-state';
3-
import type { AtLeastOne } from './utils';
3+
import type { AtLeastOne } from 'instantsearch-core/types';
44

55
export type MiddlewareDefinition<TUiState extends UiState = UiState> = {
66
/**

packages/instantsearch.js/src/types/widget.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import type { IndexWidget } from '../widgets';
2-
import type { RecommendResponse } from './algoliasearch';
32
import type { InstantSearch } from './instantsearch';
43
import type { IndexRenderState, WidgetRenderState } from './render-state';
54
import type { IndexUiState, UiState } from './ui-state';
6-
import type { Expand, RequiredKeys } from './utils';
75
import type {
86
AlgoliaSearchHelper as Helper,
97
SearchParameters,
108
SearchResults,
119
RecommendParameters,
1210
} from 'algoliasearch-helper';
11+
import type {
12+
RecommendResponse,
13+
Expand,
14+
RequiredKeys,
15+
} from 'instantsearch-core/types';
1316

1417
export type ScopedResult = {
1518
indexId: string;

packages/instantsearch.js/src/widgets/dynamic-widgets/__tests__/dynamic-widgets-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '../../../../test/createWidget';
2020
import refinementList from '../../refinement-list/refinement-list';
2121

22-
import type { SearchResponse } from '../../../types/algoliasearch';
22+
import type { SearchResponse } from 'instantsearch-core/types';
2323

2424
expect.addSnapshotSerializer(widgetSnapshotSerializer);
2525

0 commit comments

Comments
 (0)