Skip to content

Commit

Permalink
feat(javascript): add worker exports (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3680

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Clément Vannicatte <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Sep 10, 2024
1 parent 57295d4 commit 8051cca
Show file tree
Hide file tree
Showing 47 changed files with 1,742 additions and 788 deletions.
31 changes: 22 additions & 9 deletions base.tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ type PKG = {
name: string;
};

const requesters = {
fetch: '@algolia/requester-fetch',
http: '@algolia/requester-node-http',
xhr: '@algolia/requester-browser-xhr',
};

type Requester = keyof typeof requesters;

export function getBaseConfig(cwd: string): Options {
return {
clean: true,
Expand All @@ -16,35 +24,40 @@ export function getBaseConfig(cwd: string): Options {
};
}

export function getDependencies(pkg: PKG, env: 'browser' | 'node'): string[] {
export function getDependencies(pkg: PKG, requester: Requester): 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');
switch (requester) {
case 'http':
return deps.filter((dep) => dep !== requesters.fetch && dep !== requesters.xhr);
case 'xhr':
return deps.filter((dep) => dep !== requesters.fetch && dep !== requesters.http);
case 'fetch':
return deps.filter((dep) => dep !== requesters.xhr && dep !== requesters.http);
default:
throw new Error('unknown requester', requester);
}

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

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

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

0 comments on commit 8051cca

Please sign in to comment.