Skip to content

Commit 33cffcb

Browse files
authored
fix(javascript): export types for algoliasearch (#706)
1 parent 600fbee commit 33cffcb

File tree

10 files changed

+50
-24
lines changed

10 files changed

+50
-24
lines changed

.github/.cache_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.5
1+
0.0.6

clients/algoliasearch-client-javascript/base.rollup.config.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import fs from 'fs';
44
const NPM_ORG = '@experimental-api-clients-automation/';
55

66
// Output formats
7-
const BROWSER_FORMATS = ['umd-browser', 'esm-browser', 'cjs-browser'];
8-
const NODE_FORMATS = ['cjs-node', 'esm-node'];
7+
const BROWSER_FORMATS = ['esm-browser', 'cjs-browser', 'umd-browser'];
8+
const NODE_FORMATS = ['esm-node', 'cjs-node'];
99

1010
// Utils package with default options
1111
const UTILS = {
@@ -125,7 +125,7 @@ export function getPackageConfigs() {
125125
external: ['dom'],
126126
dependencies: [
127127
...commonConfig.dependencies,
128-
`${NPM_ORG}/requester-browser-xhr`,
128+
`${NPM_ORG}requester-browser-xhr`,
129129
],
130130
globals: {
131131
[packageName]: packageName,
@@ -138,7 +138,7 @@ export function getPackageConfigs() {
138138
formats: NODE_FORMATS,
139139
dependencies: [
140140
...commonConfig.dependencies,
141-
`${NPM_ORG}/requester-node-http`,
141+
`${NPM_ORG}requester-node-http`,
142142
],
143143
},
144144
];
@@ -161,24 +161,34 @@ export function createLicense(name, version) {
161161
* Bundlers with their output format and file name for the given client.
162162
*/
163163
export function createBundlers({ output, clientPath }) {
164+
const commonOptions = {
165+
exports: 'named',
166+
};
167+
164168
return {
165169
'esm-node': {
170+
...commonOptions,
166171
file: `${clientPath}/dist/${output}.esm.node.js`,
167172
format: 'es',
168173
},
169174
'esm-browser': {
175+
...commonOptions,
170176
file: `${clientPath}/dist/${output}.esm.browser.js`,
171177
format: 'es',
172178
},
173179
'umd-browser': {
180+
...commonOptions,
174181
file: `${clientPath}/dist/${output}.umd.browser.js`,
175182
format: 'umd',
183+
esModule: false,
176184
},
177185
'cjs-node': {
186+
...commonOptions,
178187
file: `${clientPath}/dist/${output}.cjs.node.js`,
179188
format: 'cjs',
180189
},
181190
'cjs-browser': {
191+
...commonOptions,
182192
file: `${clientPath}/dist/${output}.cjs.browser.js`,
183193
format: 'cjs',
184194
},

clients/algoliasearch-client-javascript/packages/algoliasearch/builds/browser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {
2727
} from '@experimental-api-clients-automation/client-search/src/searchClient';
2828
import { createXhrRequester } from '@experimental-api-clients-automation/requester-browser-xhr';
2929

30+
export * from './models';
31+
3032
export const apiClientVersion = searchClientVersion;
3133

3234
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {
2+
ErrorBase,
3+
PutProps,
4+
PostProps,
5+
DelProps,
6+
GetProps,
7+
} from '@experimental-api-clients-automation/client-search/model';
8+
9+
export * from '@experimental-api-clients-automation/client-search/model';
10+
export * from '@experimental-api-clients-automation/client-personalization/model';
11+
export * from '@experimental-api-clients-automation/client-analytics/model';
12+
13+
export { ErrorBase, PutProps, PostProps, DelProps, GetProps };

clients/algoliasearch-client-javascript/packages/algoliasearch/builds/node.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
} from '@experimental-api-clients-automation/client-search/src/searchClient';
2727
import { createHttpRequester } from '@experimental-api-clients-automation/requester-node-http';
2828

29+
export * from './models';
30+
2931
export const apiClientVersion = searchClientVersion;
3032

3133
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// eslint-disable-next-line import/no-unresolved
2-
export * from './dist/algoliasearch/builds/node';
2+
export * from './dist/node';

clients/algoliasearch-client-javascript/packages/algoliasearch/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"types": ["node", "jest"],
55
"outDir": "dist"
66
},
7-
"include": ["builds/node.ts", "builds/browser.ts"],
7+
"include": ["builds/node.ts", "builds/browser.ts", "builds/models.ts"],
88
"exclude": ["dist", "node_modules", "__tests__"]
99
}

clients/algoliasearch-client-javascript/rollup.config.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const packageConfigs = getPackageConfigs();
1717
const rollupConfig = [];
1818

1919
packageConfigs.forEach((packageConfig) => {
20+
let checkForTypes = true;
2021
const clientPath = path.resolve('packages', packageConfig.package);
2122
const clientPackageJson = JSON.parse(
2223
fs.readFileSync(path.resolve(clientPath, 'package.json'))
@@ -32,19 +33,8 @@ packageConfigs.forEach((packageConfig) => {
3233
});
3334

3435
packageConfig.formats.forEach((format) => {
35-
// Avoid generating types multiple times.
36-
let areTypesGenerated = false;
3736
const isUmdBuild = format === 'umd-browser';
3837
const isEsmBrowserBuild = format === 'esm-browser';
39-
40-
if (isUmdBuild) {
41-
bundlers[format].name = packageConfig.name;
42-
bundlers[format].banner = createLicense(
43-
packageConfig.package,
44-
clientPackageJson.version
45-
);
46-
}
47-
4838
const umdConfig = {
4939
compressorPlugins: [],
5040
transpilerPlugins: [],
@@ -56,6 +46,12 @@ packageConfigs.forEach((packageConfig) => {
5646
}
5747

5848
if (isUmdBuild) {
49+
bundlers[format].name = packageConfig.name;
50+
bundlers[format].banner = createLicense(
51+
packageConfig.package,
52+
clientPackageJson.version
53+
);
54+
5955
umdConfig.compressorPlugins = [terser()];
6056
umdConfig.transpilerPlugins = [
6157
babel({
@@ -87,12 +83,13 @@ packageConfigs.forEach((packageConfig) => {
8783
}),
8884
nodeResolve(),
8985
ts({
90-
check: !areTypesGenerated,
86+
check: checkForTypes,
9187
tsconfig: path.resolve(clientPath, 'tsconfig.json'),
9288
tsconfigOverride: {
9389
compilerOptions: {
94-
declaration: !areTypesGenerated,
95-
declarationMap: !areTypesGenerated,
90+
declaration: checkForTypes,
91+
declarationMap: checkForTypes,
92+
noEmit: !checkForTypes,
9693
},
9794
},
9895
}),
@@ -107,7 +104,7 @@ packageConfigs.forEach((packageConfig) => {
107104
},
108105
});
109106

110-
areTypesGenerated = true;
107+
checkForTypes = false;
111108
});
112109
});
113110

clients/algoliasearch-client-javascript/scripts/build_all.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ set -e
33

44
yarn build utils
55

6-
PACKAGES_EXCEPT_FOR_UTILS=$(ls ./packages | grep -v -E "(client-common|requester-)")
6+
PACKAGES_EXCEPT_FOR_UTILS=$(ls ./packages | grep -v -E "(client-common|requester-|algoliasearch$)")
77

88
for CLIENT in $PACKAGES_EXCEPT_FOR_UTILS
99
do
1010
SKIP_UTILS=true yarn build $CLIENT
1111
done
12+
13+
SKIP_UTILS=true yarn build algoliasearch

playground/javascript/node/algoliasearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { algoliasearch } from '@experimental-api-clients-automation/algoliasearc
22
import { ApiError } from '@experimental-api-clients-automation/client-common';
33
import dotenv from 'dotenv';
44

5-
import type { SearchResponses } from '@experimental-api-clients-automation/client-search';
5+
import type { SearchResponses } from '@experimental-api-clients-automation/algoliasearch';
66

77
dotenv.config({ path: '../../.env' });
88

0 commit comments

Comments
 (0)