Skip to content

fix(javascript): export types for algoliasearch #706

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

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.5
0.0.6
18 changes: 14 additions & 4 deletions clients/algoliasearch-client-javascript/base.rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import fs from 'fs';
const NPM_ORG = '@experimental-api-clients-automation/';

// Output formats
const BROWSER_FORMATS = ['umd-browser', 'esm-browser', 'cjs-browser'];
const NODE_FORMATS = ['cjs-node', 'esm-node'];
const BROWSER_FORMATS = ['esm-browser', 'cjs-browser', 'umd-browser'];
const NODE_FORMATS = ['esm-node', 'cjs-node'];

// Utils package with default options
const UTILS = {
Expand Down Expand Up @@ -125,7 +125,7 @@ export function getPackageConfigs() {
external: ['dom'],
dependencies: [
...commonConfig.dependencies,
`${NPM_ORG}/requester-browser-xhr`,
`${NPM_ORG}requester-browser-xhr`,
],
globals: {
[packageName]: packageName,
Expand All @@ -138,7 +138,7 @@ export function getPackageConfigs() {
formats: NODE_FORMATS,
dependencies: [
...commonConfig.dependencies,
`${NPM_ORG}/requester-node-http`,
`${NPM_ORG}requester-node-http`,
],
},
];
Expand All @@ -161,24 +161,34 @@ export function createLicense(name, version) {
* Bundlers with their output format and file name for the given client.
*/
export function createBundlers({ output, clientPath }) {
const commonOptions = {
exports: 'named',
};

return {
'esm-node': {
...commonOptions,
file: `${clientPath}/dist/${output}.esm.node.js`,
format: 'es',
},
'esm-browser': {
...commonOptions,
file: `${clientPath}/dist/${output}.esm.browser.js`,
format: 'es',
},
'umd-browser': {
...commonOptions,
file: `${clientPath}/dist/${output}.umd.browser.js`,
format: 'umd',
esModule: false,
},
'cjs-node': {
...commonOptions,
file: `${clientPath}/dist/${output}.cjs.node.js`,
format: 'cjs',
},
'cjs-browser': {
...commonOptions,
file: `${clientPath}/dist/${output}.cjs.browser.js`,
format: 'cjs',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
} from '@experimental-api-clients-automation/client-search/src/searchClient';
import { createXhrRequester } from '@experimental-api-clients-automation/requester-browser-xhr';

export * from './models';

export const apiClientVersion = searchClientVersion;

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
ErrorBase,
PutProps,
PostProps,
DelProps,
GetProps,
} from '@experimental-api-clients-automation/client-search/model';

export * from '@experimental-api-clients-automation/client-search/model';
export * from '@experimental-api-clients-automation/client-personalization/model';
export * from '@experimental-api-clients-automation/client-analytics/model';

export { ErrorBase, PutProps, PostProps, DelProps, GetProps };
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
} from '@experimental-api-clients-automation/client-search/src/searchClient';
import { createHttpRequester } from '@experimental-api-clients-automation/requester-node-http';

export * from './models';

export const apiClientVersion = searchClientVersion;

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line import/no-unresolved
export * from './dist/algoliasearch/builds/node';
export * from './dist/node';
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"types": ["node", "jest"],
"outDir": "dist"
},
"include": ["builds/node.ts", "builds/browser.ts"],
"include": ["builds/node.ts", "builds/browser.ts", "builds/models.ts"],
"exclude": ["dist", "node_modules", "__tests__"]
}
27 changes: 12 additions & 15 deletions clients/algoliasearch-client-javascript/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const packageConfigs = getPackageConfigs();
const rollupConfig = [];

packageConfigs.forEach((packageConfig) => {
let checkForTypes = true;
const clientPath = path.resolve('packages', packageConfig.package);
const clientPackageJson = JSON.parse(
fs.readFileSync(path.resolve(clientPath, 'package.json'))
Expand All @@ -32,19 +33,8 @@ packageConfigs.forEach((packageConfig) => {
});

packageConfig.formats.forEach((format) => {
// Avoid generating types multiple times.
let areTypesGenerated = false;
const isUmdBuild = format === 'umd-browser';
const isEsmBrowserBuild = format === 'esm-browser';

if (isUmdBuild) {
bundlers[format].name = packageConfig.name;
bundlers[format].banner = createLicense(
packageConfig.package,
clientPackageJson.version
);
}

const umdConfig = {
compressorPlugins: [],
transpilerPlugins: [],
Expand All @@ -56,6 +46,12 @@ packageConfigs.forEach((packageConfig) => {
}

if (isUmdBuild) {
bundlers[format].name = packageConfig.name;
bundlers[format].banner = createLicense(
packageConfig.package,
clientPackageJson.version
);

umdConfig.compressorPlugins = [terser()];
umdConfig.transpilerPlugins = [
babel({
Expand Down Expand Up @@ -87,12 +83,13 @@ packageConfigs.forEach((packageConfig) => {
}),
nodeResolve(),
ts({
check: !areTypesGenerated,
check: checkForTypes,
tsconfig: path.resolve(clientPath, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
declaration: !areTypesGenerated,
declarationMap: !areTypesGenerated,
declaration: checkForTypes,
declarationMap: checkForTypes,
noEmit: !checkForTypes,
},
},
}),
Expand All @@ -107,7 +104,7 @@ packageConfigs.forEach((packageConfig) => {
},
});

areTypesGenerated = true;
checkForTypes = false;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ set -e

yarn build utils

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

for CLIENT in $PACKAGES_EXCEPT_FOR_UTILS
do
SKIP_UTILS=true yarn build $CLIENT
done

SKIP_UTILS=true yarn build algoliasearch
2 changes: 1 addition & 1 deletion playground/javascript/node/algoliasearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { algoliasearch } from '@experimental-api-clients-automation/algoliasearc
import { ApiError } from '@experimental-api-clients-automation/client-common';
import dotenv from 'dotenv';

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

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

Expand Down