Skip to content

Commit

Permalink
chore(javascript): use tsup bundler (#3640)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Sep 3, 2024
1 parent 0790e3b commit ff0c996
Show file tree
Hide file tree
Showing 32 changed files with 1,393 additions and 490 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ jobs:
if: ${{ startsWith(env.head_ref, 'chore/prepare-release-') }}
run: cd clients/algoliasearch-client-javascript && yarn test:size

- name: Test JavaScript bundle and types
if: ${{ startsWith(env.head_ref, 'chore/prepare-release-') }}
run: cd clients/algoliasearch-client-javascript && yarn test:bundle

- name: Remove previous CTS output
run: rm -rf ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).testsToDelete }}

Expand Down
303 changes: 0 additions & 303 deletions clients/algoliasearch-client-javascript/base.rollup.config.js

This file was deleted.

50 changes: 50 additions & 0 deletions clients/algoliasearch-client-javascript/base.tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from 'path';

import type { Options } from 'tsup';

type PKG = {
dependencies?: Record<string, string>;
name: string;
};

export function getBaseConfig(cwd: string): Options {
return {
clean: true,
sourcemap: true,
splitting: false,
tsconfig: path.resolve(cwd, 'tsconfig.json'),
};
}

export function getDependencies(pkg: PKG, env: 'node' | 'browser'): string[] {
const deps = Object.keys(pkg.dependencies || {}) || [];

if (pkg.name !== "algoliasearch") {
return deps
}

if (env === 'node') {
return deps.filter(dep => dep !== '@algolia/requester-browser-xhr')
}

return deps.filter(dep => dep !== '@algolia/requester-node-http')
}

export function getBaseNodeOptions(pkg: PKG, cwd: string): Options {
return {
...getBaseConfig(cwd),
platform: 'node',
target: 'node14',
external: [...getDependencies(pkg, 'node'), 'node:crypto'],
};
}

export function getBaseBrowserOptions(pkg: PKG, cwd: string): Options {
return {
...getBaseConfig(cwd),
platform: 'browser',
format: ['esm'],
target: ['chrome109', 'safari15.6', 'firefox115', 'edge126'],
external: [...getDependencies(pkg, 'browser'), 'dom'],
};
}
Loading

0 comments on commit ff0c996

Please sign in to comment.