Skip to content

Commit 7089dc6

Browse files
bors[bot]curquizabidoubiwa
authored
Merge #238
238: Changed to named export instead of default export r=bidoubiwa a=bidoubiwa Following the decision taken in `meilisearch-js`: meilisearch/meilisearch-js#756 # Named exports MeiliSearch Js decided to go in the direction of new best practices in JS libraries by changing from default export to named export. ## New usage ES: ```javascript import {instantMeiliSearch } from '@meilisearch/instant-meilisearch' // ES const searchClient = instantMeiliSearch(...); ``` Node ```javascript const { instantMeiliSearch } = require('@meilisearch/instant-meilisearch') // Node const searchClient = instantMeiliSearch(...); ``` ```javascript instantMeiliSearch // browser window.instantMeiliSearch // browser const searchClient = instantMeiliSearch(...); const searchClient2 = window.instantMeiliSearch(...); ``` Co-authored-by: Clémentine Urquizar <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com> Co-authored-by: cvermand <[email protected]>
2 parents 0381429 + 2a5adea commit 7089dc6

File tree

9 files changed

+47
-45
lines changed

9 files changed

+47
-45
lines changed

playgrounds/html/public/index.html

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,37 @@
2020
<script src="../../../src/index.js"></script>
2121
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
2222
<script>
23-
console.log(instantMeiliSearch)
24-
instantMeiliSearch = instantMeiliSearch.default
25-
const search = instantsearch({
26-
indexName: "steam-video-games",
27-
searchClient: instantMeiliSearch(
28-
"https://demos.meilisearch.com",
29-
"dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25",
30-
)
31-
});
32-
search.addWidgets([
33-
instantsearch.widgets.searchBox({
34-
container: "#searchbox",
35-
placeholder: "Search..",
36-
}),
37-
instantsearch.widgets.configure({
38-
hitsPerPage: 8,
39-
}),
40-
instantsearch.widgets.hits({
41-
container: "#hits",
42-
templates: {
43-
item: `
44-
<div>
45-
<div class="hit-name">
46-
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
47-
</div>
48-
</div>
49-
`
50-
}
51-
})
52-
]);
53-
54-
search.start();
23+
// This is due to parcel not accepting globals on html files.
24+
instantMeiliSearch = instantMeiliSearch.instantMeiliSearch;
25+
const search = instantsearch({
26+
indexName: "steam-video-games",
27+
searchClient: instantMeiliSearch(
28+
"https://demos.meilisearch.com",
29+
"dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25",
30+
)
31+
});
32+
search.addWidgets([
33+
instantsearch.widgets.searchBox({
34+
container: "#searchbox",
35+
placeholder: "Search..",
36+
}),
37+
instantsearch.widgets.configure({
38+
hitsPerPage: 8,
39+
}),
40+
instantsearch.widgets.hits({
41+
container: "#hits",
42+
templates: {
43+
item: `
44+
<div>
45+
<div class="hit-name">
46+
{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
47+
</div>
48+
</div>
49+
`
50+
}
51+
})
52+
]);
53+
search.start();
5554
</script>
5655
</body>
5756
</html>
58-

playgrounds/javascript/src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import instantMeiliSearch from '../../../src/index'
1+
import { instantMeiliSearch } from '../../../src/index'
22

33
const search = instantsearch({
44
indexName: 'steam-video-games',

playgrounds/react/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Configure
1212
} from "react-instantsearch-dom";
1313
import "./App.css";
14-
import instantMeiliSearch from "./instant-meilisearch.js";
14+
import { instantMeiliSearch } from "./instant-meilisearch.js";
1515

1616
const searchClient = instantMeiliSearch(
1717
"https://demos.meilisearch.com",

playgrounds/vue/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
<script>
6060
import "instantsearch.css/themes/algolia-min.css";
61-
import instantMeiliSearch from "../../../src/index.js";
61+
import { instantMeiliSearch } from "../../../src/index.js";
6262
6363
export default {
6464
data() {

rollup.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ function getOutputFileName(fileName, isProd = false) {
1010
}
1111

1212
const env = process.env.NODE_ENV || 'development'
13-
const LIB_NAME = 'instantMeiliSearch'
1413
const ROOT = resolve(__dirname, '.')
1514

1615
module.exports = [
1716
// browser-friendly IIFE build
1817
{
1918
input: 'src/index.js', // directory to transpilation of typescript
2019
output: {
21-
name: LIB_NAME,
20+
name: 'window',
21+
extend: true,
2222
file: getOutputFileName(
2323
// will add .min. in filename if in production env
2424
resolve(ROOT, pkg.browser),
@@ -52,7 +52,7 @@ module.exports = [
5252
resolve(ROOT, pkg.cjs),
5353
env === 'production'
5454
),
55-
exports: 'default',
55+
exports: 'named',
5656
format: 'cjs',
5757
sourcemap: env === 'production', // create sourcemap for error reporting in production mode
5858
},
@@ -61,7 +61,7 @@ module.exports = [
6161
resolve(ROOT, pkg.module),
6262
env === 'production'
6363
),
64-
exports: 'default',
64+
exports: 'named',
6565
format: 'es',
6666
sourcemap: env === 'production', // create sourcemap for error reporting in production mode
6767
},

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MeiliSearch } from 'meilisearch'
22
import { removeUndefinedFromObject } from './utils.js'
33
import { createHighlighResult, createSnippetResult } from './format.js'
44

5-
export default function instantMeiliSearch(hostUrl, apiKey, options = {}) {
5+
export function instantMeiliSearch(hostUrl, apiKey, options = {}) {
66
return {
77
client: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
88
attributesToHighlight: ['*'],

tests/base.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import instantMeiliSearch from '../src/index'
1+
import { instantMeiliSearch } from '../src/index'
22

33
test('Should test if instantMeiliSearch Client is created correctly', () => {
44
const client = instantMeiliSearch('http://localhost:7700', 'masterKey')

tests/env/esm/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import instantMeiliSearch from '../../../../dist/instant-meilisearch.esm'
1+
import { instantMeiliSearch } from '../../../../dist/instant-meilisearch.esm'
22

33
console.log(instantMeiliSearch)
44
const client = instantMeiliSearch('http://localhost:7700', 'masterKey')

tests/env/node/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
const UMDinstantMeiliSearch = require('../../../dist/instant-meilisearch.umd')
2-
const CJSinstantMeiliSearch = require('../../../dist/instant-meilisearch.cjs')
1+
const {
2+
instantMeiliSearch: UMDinstantMeiliSearch,
3+
} = require('../../../dist/instant-meilisearch.umd')
4+
const {
5+
instantMeiliSearch: CJSinstantMeiliSearch,
6+
} = require('../../../dist/instant-meilisearch.cjs')
37

48
const UMDtest = UMDinstantMeiliSearch('http://localhost:7700', 'masterKey')
59
const CJStest = CJSinstantMeiliSearch('http://localhost:7700', 'masterKey')

0 commit comments

Comments
 (0)