Skip to content

Commit bbc5e7f

Browse files
bors[bot]bidoubiwa
andauthored
Merge #504
504: Fix umd build having no node interop r=bidoubiwa a=bidoubiwa The bug was caused by changing the rollup typescript from the non-official [`rollup-plugin-typescript2`](https://www.npmjs.com/package/rollup-plugin-typescript2) to the official one [`@rollup/rollup-typescript](https://github.com/rollup/plugins/tree/master/packages/typescript/#readme).` Multiple libraries suggesting multiple bundles outputs (umd, cjs, ...) are using rollup-plugin-typescript2. Since some of the issues why we initially used this one were resolved, I made the change to go back to the official one. Unfortunately do a lack of tests on the builds themselves I did not realise a new issue was introduced. By rollbacking to the initial plugin we used, the problem seems to be fixed. Tests are added to ensure this. Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents d6038d1 + f7ebc67 commit bbc5e7f

File tree

5 files changed

+149
-280
lines changed

5 files changed

+149
-280
lines changed

jest.config.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
const ignoreFiles = ['<rootDir>/playgrounds', '<rootDir>/tests/assets']
2+
13
module.exports = {
24
verbose: true,
35
watchPlugins: [
46
'jest-watch-typeahead/filename',
57
'jest-watch-typeahead/testname',
68
],
79
projects: [
10+
{
11+
displayName: 'build',
12+
testEnvironment: 'node',
13+
testPathIgnorePatterns: [...ignoreFiles, '<rootDir>/tests/*.ts'],
14+
testMatch: ['**/*.tests.js', '/tests/**/*.js'],
15+
},
816
{
917
globals: {
1018
'ts-jest': {
@@ -13,14 +21,7 @@ module.exports = {
1321
},
1422
preset: 'ts-jest',
1523
displayName: 'dom',
16-
// We are using jest-environment-jsdom 25 until we stop supporting node 10
17-
// jest-environment-jsdom 25 uses jsdom 15 which still supports node 10
18-
testEnvironment: 'jest-environment-jsdom',
19-
testPathIgnorePatterns: [
20-
'<rootDir>/tests/env',
21-
'<rootDir>/playgrounds',
22-
'<rootDir>/tests/assets',
23-
],
24+
testPathIgnorePatterns: [...ignoreFiles, '<rootDir>/tests/build*'],
2425
testMatch: ['**/*.tests.ts', '/tests/**/*.ts'],
2526
},
2627
{
@@ -32,11 +33,7 @@ module.exports = {
3233
preset: 'ts-jest',
3334
displayName: 'node',
3435
testEnvironment: 'node',
35-
testPathIgnorePatterns: [
36-
'<rootDir>/tests/env',
37-
'<rootDir>/playgrounds',
38-
'<rootDir>/tests/assets',
39-
],
36+
testPathIgnorePatterns: [...ignoreFiles],
4037
testMatch: ['**/*.tests.ts', '/tests/**/*.ts'],
4138
},
4239
],

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"scripts": {
77
"cleanup": "shx rm -rf dist/",
88
"test:watch": "yarn test --watch",
9-
"test": "jest --runInBand",
9+
"test": "jest --runInBand --selectProjects dom --selectProjects node",
10+
"test:build": "yarn build && jest --runInBand --selectProjects build",
1011
"test:e2e": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:javascript\" \"cypress run --env playground=javascript\"",
1112
"test:e2e:all": "sh scripts/e2e.sh",
1213
"test:e2e:watch": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:javascript\" \"cypress open --env playground=javascript\"",
13-
"test:all": "yarn test:e2e:all && yarn test",
14+
"test:all": "yarn test:e2e:all && yarn test && test:build",
1415
"playground:vue": "yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue serve",
1516
"playground:react": "yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react start",
1617
"playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start",
@@ -59,7 +60,6 @@
5960
"@babel/preset-env": "^7.15.0",
6061
"@rollup/plugin-commonjs": "^17.1.0",
6162
"@rollup/plugin-node-resolve": "^11.2.0",
62-
"@rollup/plugin-typescript": "^8.2.5",
6363
"@typescript-eslint/eslint-plugin": "^4.16.1",
6464
"@typescript-eslint/parser": "^4.16.1",
6565
"@vue/eslint-config-typescript": "^7.0.0",
@@ -86,13 +86,14 @@
8686
"eslint-plugin-vue": "^7.7.0",
8787
"instantsearch.js": "^4.16.1",
8888
"jest": "^26.6.3",
89-
"jest-environment-jsdom": "25.5",
9089
"jest-watch-typeahead": "^0.6.3",
9190
"prettier": "^2.0.0",
9291
"regenerator-runtime": "^0.13.7",
9392
"rollup": "^2.40.0",
9493
"rollup-plugin-babel": "^4.4.0",
94+
"rollup-plugin-node-polyfills": "^0.2.1",
9595
"rollup-plugin-terser": "^7.0.0",
96+
"rollup-plugin-typescript2": "^0.30.0",
9697
"shx": "^0.3.3",
9798
"ts-jest": "^26.5.2",
9899
"tslib": "^2.3.1",

rollup.config.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import nodeResolve from '@rollup/plugin-node-resolve'
33
import { resolve } from 'path'
44
import babel from 'rollup-plugin-babel'
55
import { terser } from 'rollup-plugin-terser'
6-
import typescript from '@rollup/plugin-typescript'
7-
6+
import typescript from 'rollup-plugin-typescript2'
87
import pkg from './package.json'
98

109
function getOutputFileName(fileName, isProd = false) {
@@ -17,8 +16,12 @@ const INPUT = 'src/index.ts'
1716

1817
const PLUGINS = [
1918
typescript({
20-
tsconfig: 'tsconfig.json',
21-
exclude: ['tests', '*.js', 'scripts', '**/__tests__/*.ts'],
19+
useTsconfigDeclarationDir: true,
20+
tsconfigOverride: {
21+
includes: ['src'],
22+
exclude: ['tests', '*.js', 'scripts', '**/__tests__/*.ts'],
23+
esModuleInterop: true,
24+
},
2225
}),
2326
]
2427
module.exports = [

tests/build.tests.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const {
2+
instantMeiliSearch: UMDinstantMeiliSearch,
3+
} = require('../dist/instant-meilisearch.umd')
4+
const {
5+
instantMeiliSearch: CJSinstantMeiliSearch,
6+
} = require('../dist/instant-meilisearch.cjs')
7+
8+
const UMDclient = UMDinstantMeiliSearch('http://localhost:7700', 'masterKey')
9+
const CJSclient = CJSinstantMeiliSearch('http://localhost:7700', 'masterKey')
10+
const instantsearch = require('instantsearch.js')
11+
12+
test('UMD client should correctly created', () => {
13+
expect(UMDclient.MeiliSearchClient.config.apiKey).toBe('masterKey')
14+
})
15+
16+
test('CJS client should correctly created', () => {
17+
expect(CJSclient.MeiliSearchClient.config.apiKey).toBe('masterKey')
18+
})
19+
20+
test('CJS instantsearch client should correctly created', () => {
21+
const CJSInstantSearch = instantsearch.default({
22+
indexName: 'cjs_index',
23+
searchClient: CJSclient,
24+
})
25+
expect(CJSInstantSearch.indexName).toBe('cjs_index')
26+
expect(CJSInstantSearch.client.MeiliSearchClient.config.apiKey).toBe(
27+
'masterKey'
28+
)
29+
})
30+
31+
test('UMD instantsearch client should correctly created', () => {
32+
const UMDInstantSearch = instantsearch.default({
33+
indexName: 'umd_index',
34+
searchClient: UMDclient,
35+
})
36+
expect(UMDInstantSearch.indexName).toBe('umd_index')
37+
expect(UMDInstantSearch.client.MeiliSearchClient.config.apiKey).toBe(
38+
'masterKey'
39+
)
40+
})

0 commit comments

Comments
 (0)