Skip to content

Commit 8964352

Browse files
authoredSep 10, 2024··
feat(javascript): add worker exports (#3680)
1 parent 24391e3 commit 8964352

File tree

18 files changed

+931
-738
lines changed

18 files changed

+931
-738
lines changed
 

‎clients/algoliasearch-client-javascript/base.tsup.config.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ type PKG = {
77
name: string;
88
};
99

10+
const requesters = {
11+
fetch: '@algolia/requester-fetch',
12+
http: '@algolia/requester-node-http',
13+
xhr: '@algolia/requester-browser-xhr',
14+
};
15+
16+
type Requester = keyof typeof requesters;
17+
1018
export function getBaseConfig(cwd: string): Options {
1119
return {
1220
clean: true,
@@ -16,35 +24,40 @@ export function getBaseConfig(cwd: string): Options {
1624
};
1725
}
1826

19-
export function getDependencies(pkg: PKG, env: 'browser' | 'node'): string[] {
27+
export function getDependencies(pkg: PKG, requester: Requester): string[] {
2028
const deps = Object.keys(pkg.dependencies || {}) || [];
2129

2230
if (pkg.name !== 'algoliasearch') {
2331
return deps;
2432
}
2533

26-
if (env === 'node') {
27-
return deps.filter((dep) => dep !== '@algolia/requester-browser-xhr');
34+
switch (requester) {
35+
case 'http':
36+
return deps.filter((dep) => dep !== requesters.fetch && dep !== requesters.xhr);
37+
case 'xhr':
38+
return deps.filter((dep) => dep !== requesters.fetch && dep !== requesters.http);
39+
case 'fetch':
40+
return deps.filter((dep) => dep !== requesters.xhr && dep !== requesters.http);
41+
default:
42+
throw new Error('unknown requester', requester);
2843
}
29-
30-
return deps.filter((dep) => dep !== '@algolia/requester-node-http');
3144
}
3245

33-
export function getBaseNodeOptions(pkg: PKG, cwd: string): Options {
46+
export function getBaseNodeOptions(pkg: PKG, cwd: string, requester: Requester = 'http'): Options {
3447
return {
3548
...getBaseConfig(cwd),
3649
platform: 'node',
3750
target: 'node14',
38-
external: [...getDependencies(pkg, 'node'), 'node:crypto'],
51+
external: [...getDependencies(pkg, requester), 'node:crypto'],
3952
};
4053
}
4154

42-
export function getBaseBrowserOptions(pkg: PKG, cwd: string): Options {
55+
export function getBaseBrowserOptions(pkg: PKG, cwd: string, requester: Requester = 'xhr'): Options {
4356
return {
4457
...getBaseConfig(cwd),
4558
platform: 'browser',
4659
format: ['esm'],
4760
target: ['chrome109', 'safari15.6', 'firefox115', 'edge126'],
48-
external: [...getDependencies(pkg, 'browser'), 'dom'],
61+
external: [...getDependencies(pkg, requester), 'dom'],
4962
};
5063
}

0 commit comments

Comments
 (0)
Please sign in to comment.