Skip to content

Commit 32602e2

Browse files
committed
refactor: extract client factory entrypoint normalization into a separate function
1 parent ec8172e commit 32602e2

1 file changed

Lines changed: 29 additions & 22 deletions

File tree

packages/tree-shaking-plugin/src/lib/transform/entrypoints.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
ClientEntrypoint,
3+
QraftClientFactoryEntrypointConfig,
34
QraftPrecreatedClientEntrypointConfig,
45
QraftTreeShakeOptions,
56
ServicesTarget,
@@ -12,34 +13,40 @@ export function normalizeEntrypoints(
1213
): ClientEntrypoint[] {
1314
return (options.entrypoints ?? []).map((entrypoint) => {
1415
if (entrypoint.kind === 'clientFactory') {
15-
const services = normalizeServices(
16-
entrypoint.factory.moduleSpecifier,
17-
entrypoint.services
18-
);
19-
const reactContext = normalizeReactContext(
20-
entrypoint.factory.moduleSpecifier,
21-
entrypoint.reactContext
22-
);
23-
24-
return {
25-
kind: 'generatedFactory',
26-
key: composeGeneratedFactoryEntrypointKey(
27-
entrypoint.factory.exportName,
28-
entrypoint.factory.moduleSpecifier,
29-
services.moduleSpecifierBase,
30-
services.directory,
31-
reactContext?.moduleSpecifier ?? ''
32-
),
33-
factory: entrypoint.factory,
34-
services,
35-
reactContext,
36-
};
16+
return normalizeClientFactoryEntrypoint(entrypoint);
3717
}
3818

3919
return normalizePrecreatedEntrypoint(entrypoint);
4020
});
4121
}
4222

23+
function normalizeClientFactoryEntrypoint(
24+
config: QraftClientFactoryEntrypointConfig
25+
): ClientEntrypoint {
26+
const services = normalizeServices(
27+
config.factory.moduleSpecifier,
28+
config.services
29+
);
30+
const reactContext = normalizeReactContext(
31+
config.factory.moduleSpecifier,
32+
config.reactContext
33+
);
34+
35+
return {
36+
kind: 'generatedFactory',
37+
key: composeGeneratedFactoryEntrypointKey(
38+
config.factory.exportName,
39+
config.factory.moduleSpecifier,
40+
services.moduleSpecifierBase,
41+
services.directory,
42+
reactContext?.moduleSpecifier ?? ''
43+
),
44+
factory: config.factory,
45+
services,
46+
reactContext,
47+
};
48+
}
49+
4350
function normalizePrecreatedEntrypoint(
4451
config: QraftPrecreatedClientEntrypointConfig
4552
): ClientEntrypoint {

0 commit comments

Comments
 (0)