Skip to content

Commit cc91f39

Browse files
committed
Reduce boot coed
1 parent e661cee commit cc91f39

13 files changed

Lines changed: 97 additions & 116 deletions

File tree

__tests__/html2/boot/bundle.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333

3434
const { WebChat } = window;
3535

36+
// THEN: `window.WebChat` should be a plain object.
37+
expect(typeof WebChat).toBe('object');
38+
39+
// THEN: It should have "ReactWebChat".
40+
expect(WebChat).toHaveProperty('ReactWebChat', expect.any(Function));
41+
3642
// THEN: It should have bits from "core" package.
3743
expect(WebChat).toHaveProperty('Constants', expect.any(Object));
3844

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import defaultCreateDirectLine from '../../createDirectLine';
22
import defaultCreateDirectLineAppServiceExtension from '../../createDirectLineAppServiceExtension';
3-
import ReactWebChat from './full';
4-
import { buildInfo as minimalBuildInfo, version } from './minimal';
3+
import ReactWebChat, { buildInfo as fullBuildInfo } from './full';
54

6-
const buildInfo = Object.freeze({ ...minimalBuildInfo, variant: 'full-es5' });
5+
const buildInfo = Object.freeze({ ...fullBuildInfo, variant: 'full-es5' });
76

87
const createDirectLine = (options: Omit<Parameters<typeof defaultCreateDirectLine>[0], 'botAgent'>) => {
98
(options as any).botAgent &&
109
console.warn(
1110
'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
1211
);
1312

14-
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${version} (ES5)` });
13+
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${buildInfo.version} (ES5)` });
1514
};
1615

1716
const createDirectLineAppServiceExtension = (
@@ -22,9 +21,15 @@ const createDirectLineAppServiceExtension = (
2221
'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
2322
);
2423

25-
return defaultCreateDirectLineAppServiceExtension({ ...options, botAgent: `WebChat/${version} (ES5)` });
24+
return defaultCreateDirectLineAppServiceExtension({ ...options, botAgent: `WebChat/${buildInfo.version} (ES5)` });
2625
};
2726

27+
// #region Re-exports
2828
export * from './full';
29-
export { buildInfo, createDirectLine, createDirectLineAppServiceExtension };
29+
// #endregion
30+
31+
// #region Local exports
3032
export default ReactWebChat;
33+
34+
export { buildInfo, createDirectLine, createDirectLineAppServiceExtension };
35+
// #endregion

packages/bundle/src/boot/actual/full.ts

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@ import ReceiptCardContent from '../../adaptiveCards/Attachment/ReceiptCardConten
99
import SignInCardContent from '../../adaptiveCards/Attachment/SignInCardContent';
1010
import ThumbnailCardContent from '../../adaptiveCards/Attachment/ThumbnailCardContent';
1111
import VideoCardContent from '../../adaptiveCards/Attachment/VideoCardContent';
12-
import createAdaptiveCardsAttachmentForScreenReaderMiddleware from '../../adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware';
13-
import createAdaptiveCardsAttachmentMiddleware from '../../adaptiveCards/createAdaptiveCardsAttachmentMiddleware';
1412
import useAdaptiveCardsHostConfig from '../../adaptiveCards/hooks/useAdaptiveCardsHostConfig';
1513
import useAdaptiveCardsPackage from '../../adaptiveCards/hooks/useAdaptiveCardsPackage';
16-
import createCognitiveServicesSpeechServicesPonyfillFactory from '../../createCognitiveServicesSpeechServicesPonyfillFactory';
1714
import defaultCreateDirectLine from '../../createDirectLine';
1815
import defaultCreateDirectLineAppServiceExtension from '../../createDirectLineAppServiceExtension';
19-
import createDirectLineSpeechAdapters from '../../createDirectLineSpeechAdapters';
20-
import createStyleSet from '../../createFullStyleSet';
2116
import useStyleOptions from '../../hooks/useStyleOptions';
2217
import useStyleSet from '../../hooks/useStyleSet';
23-
import renderMarkdown from '../../markdown/renderMarkdown';
2418
import coreRenderWebChat from '../../renderWebChat';
25-
import { type AdaptiveCardsPackage } from '../../types/AdaptiveCardsPackage';
26-
import FullBundleStyleOptions, { StrictFullBundleStyleOptions } from '../../types/FullBundleStyleOptions';
27-
import { Components as MinimalComponents, hooks, buildInfo as minimalBuildInfo, version, withEmoji } from './minimal';
19+
import { buildInfo as minimalBuildInfo, Components as minimalComponents, hooks as minimalHooks } from './minimal';
2820

2921
const renderWebChat = coreRenderWebChat.bind(null, ReactWebChat);
3022

@@ -36,7 +28,7 @@ const createDirectLine = (options: Omit<Parameters<typeof defaultCreateDirectLin
3628
'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
3729
);
3830

39-
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${version} (Full)` });
31+
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${buildInfo.version} (Full)` });
4032
};
4133

4234
const createDirectLineAppServiceExtension = (
@@ -47,18 +39,19 @@ const createDirectLineAppServiceExtension = (
4739
'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
4840
);
4941

50-
return defaultCreateDirectLineAppServiceExtension({ ...options, botAgent: `WebChat/${version} (Full)` });
42+
return defaultCreateDirectLineAppServiceExtension({ ...options, botAgent: `WebChat/${buildInfo.version} (Full)` });
5143
};
5244

53-
const patchedHooks = Object.freeze({
54-
...hooks,
45+
const hooks = Object.freeze({
46+
...minimalHooks,
5547
useAdaptiveCardsHostConfig,
5648
useAdaptiveCardsPackage,
5749
useStyleOptions,
5850
useStyleSet
5951
});
6052

61-
const AdditionalComponents = Object.freeze({
53+
const Components = Object.freeze({
54+
...minimalComponents,
6255
AdaptiveCardContent,
6356
AnimationCardContent,
6457
AudioCardContent,
@@ -70,45 +63,45 @@ const AdditionalComponents = Object.freeze({
7063
SignInCardContent,
7164
ThumbnailCardContent,
7265
VideoCardContent
73-
});
74-
75-
const Components: Readonly<typeof MinimalComponents & typeof AdditionalComponents> = Object.freeze({
76-
...MinimalComponents,
77-
...AdditionalComponents
78-
});
79-
80-
type StyleOptions = FullBundleStyleOptions;
81-
type StrictStyleOptions = StrictFullBundleStyleOptions;
66+
} as const);
8267

83-
export default ReactWebChat;
68+
// #region Re-exports
69+
export { default as createAdaptiveCardsAttachmentForScreenReaderMiddleware } from '../../adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware';
70+
export { default as createAdaptiveCardsAttachmentMiddleware } from '../../adaptiveCards/createAdaptiveCardsAttachmentMiddleware';
71+
export { default as createCognitiveServicesSpeechServicesPonyfillFactory } from '../../createCognitiveServicesSpeechServicesPonyfillFactory';
72+
export { default as createDirectLineSpeechAdapters } from '../../createDirectLineSpeechAdapters';
73+
export { default as createStyleSet } from '../../createFullStyleSet';
74+
export { default as renderMarkdown } from '../../markdown/renderMarkdown';
75+
export { type AdaptiveCardsPackage } from '../../types/AdaptiveCardsPackage';
76+
export {
77+
type StrictFullBundleStyleOptions as StrictStyleOptions,
78+
type default as StyleOptions
79+
} from '../../types/FullBundleStyleOptions';
8480
export {
85-
Constants,
8681
concatMiddleware,
82+
Constants,
8783
createBrowserWebSpeechPonyfillFactory,
8884
createStore,
8985
createStoreWithDevTools,
9086
createStoreWithOptions,
9187
decorator,
9288
internal,
9389
testIds,
94-
version
90+
version,
91+
withEmoji
9592
} from './minimal';
93+
// #endregion
94+
95+
// #region Local exports
96+
export default ReactWebChat;
97+
9698
export {
97-
Components,
98-
ReactWebChat,
9999
buildInfo,
100-
createAdaptiveCardsAttachmentForScreenReaderMiddleware,
101-
createAdaptiveCardsAttachmentMiddleware,
102-
createCognitiveServicesSpeechServicesPonyfillFactory,
100+
Components,
103101
createDirectLine,
104102
createDirectLineAppServiceExtension,
105-
createDirectLineSpeechAdapters,
106-
createStyleSet,
107-
patchedHooks as hooks,
108-
renderMarkdown,
109-
renderWebChat,
110-
withEmoji,
111-
type AdaptiveCardsPackage,
112-
type StrictStyleOptions,
113-
type StyleOptions
103+
hooks,
104+
ReactWebChat,
105+
renderWebChat
114106
};
107+
// #endregion

packages/bundle/src/boot/actual/middleware.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
// TODO: [P1] Unsure why export * will not export anything for /__tests__/html2/samples.
2-
3-
// ```
4-
// ▲ [WARNING] Import "activityComponent" will always be undefined because the file "../../../packages/bundle/dist/botframework-webchat.middleware.mjs" has no exports [import-is-undefined]
5-
// ```
6-
7-
// export * from 'botframework-webchat-api/middleware';
8-
91
export {
102
activityComponent,
113
ActivityPolymiddlewareProxy,
Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,23 @@
1-
import { type StrictStyleOptions, type StyleOptions } from 'botframework-webchat-api';
21
import * as apiDecorator from 'botframework-webchat-api/decorator';
2+
import ReactWebChat from 'botframework-webchat-component';
33
import * as componentDecorator from 'botframework-webchat-component/decorator';
44
import * as internal from 'botframework-webchat-component/internal';
5-
import { Constants, createStore, createStoreWithDevTools, createStoreWithOptions } from 'botframework-webchat-core';
65

7-
import ReactWebChat, {
8-
Components,
9-
concatMiddleware,
10-
createStyleSet,
11-
hooks,
12-
testIds,
13-
withEmoji
14-
} from 'botframework-webchat-component';
15-
16-
import createBrowserWebSpeechPonyfillFactory from '../../createBrowserWebSpeechPonyfillFactory';
176
import defaultCreateDirectLine from '../../createDirectLine';
187
import defaultCreateDirectLineAppServiceExtension from '../../createDirectLineAppServiceExtension';
198
import coreRenderWebChat from '../../renderWebChat';
209

2110
const renderWebChat = coreRenderWebChat.bind(null, ReactWebChat);
2211

23-
const buildTool = process.env.build_tool;
24-
const moduleFormat = process.env.module_format;
25-
const version = process.env.npm_package_version;
26-
2712
const buildInfo = Object.freeze({
28-
buildTool,
29-
moduleFormat,
13+
buildTool: process.env.build_tool,
14+
moduleFormat: 'unknown',
3015
variant: 'minimal',
31-
version
16+
version: process.env.npm_package_version
3217
});
3318

19+
const { version } = buildInfo;
20+
3421
const createDirectLine = (options: Omit<Parameters<typeof defaultCreateDirectLine>[0], 'botAgent'>) => {
3522
(options as any).botAgent &&
3623
console.warn(
@@ -56,27 +43,31 @@ const decorator = Object.freeze({
5643
...componentDecorator
5744
});
5845

59-
export default ReactWebChat;
46+
// #region Re-exports
47+
export { type StrictStyleOptions, type StyleOptions } from 'botframework-webchat-api';
6048
export {
61-
buildInfo,
6249
Components,
6350
concatMiddleware,
64-
Constants,
65-
createBrowserWebSpeechPonyfillFactory,
51+
createStyleSet,
52+
hooks,
53+
testIds,
54+
withEmoji
55+
} from 'botframework-webchat-component';
56+
export { Constants, createStore, createStoreWithDevTools, createStoreWithOptions } from 'botframework-webchat-core';
57+
export { default as createBrowserWebSpeechPonyfillFactory } from '../../createBrowserWebSpeechPonyfillFactory';
58+
// #endregion
59+
60+
// #region Local exports
61+
export default ReactWebChat;
62+
63+
export {
64+
buildInfo,
6665
createDirectLine,
6766
createDirectLineAppServiceExtension,
68-
createStore,
69-
createStoreWithDevTools,
70-
createStoreWithOptions,
71-
createStyleSet,
7267
decorator,
73-
hooks,
7468
internal,
7569
ReactWebChat,
7670
renderWebChat,
77-
testIds,
78-
version,
79-
withEmoji,
80-
type StrictStyleOptions,
81-
type StyleOptions
71+
version
8272
};
73+
// #endregion

packages/bundle/src/boot/bundle/full-es5.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
// Importing polyfills required for IE11/ES5.
2-
import './polyfill';
2+
import './polyfill/es5';
33

4-
import * as es5 from '../actual/full-es5';
4+
import * as actual from '../actual/full-es5';
55
import * as middleware from '../actual/middleware';
66
import addVersion from '../addVersion';
77

8-
const buildInfo = Object.freeze({
9-
...es5.buildInfo,
10-
buildTool: process.env.build_tool,
11-
moduleFormat: process.env.module_format
12-
});
8+
const buildInfo = Object.freeze({ ...actual.buildInfo, moduleFormat: process.env.module_format });
139

1410
// Until we have a development-specific bundle, we are not shipping createStoreWithDevTools in bundle.
15-
const { createStoreWithDevTools: _createStoreWithDevTools, ...finalES5 } = es5;
11+
const { createStoreWithDevTools: _createStoreWithDevTools, ...exports } = actual;
1612

1713
window['WebChat'] = Object.freeze({
1814
...window['WebChat'],
19-
...finalES5,
15+
...exports,
2016
buildInfo,
2117
middleware
2218
});

packages/bundle/src/boot/bundle/full.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import './modern-polyfill';
1+
import './polyfill/modern';
22

3-
import * as full from '../actual/full';
3+
import * as actual from '../actual/full';
44
import * as middleware from '../actual/middleware';
55
import addVersion from '../addVersion';
66

7-
const buildInfo = Object.freeze({
8-
...full.buildInfo,
9-
buildTool: process.env.build_tool,
10-
moduleFormat: process.env.module_format
11-
});
7+
const buildInfo = Object.freeze({ ...actual.buildInfo, moduleFormat: process.env.module_format });
128

139
// Until we have a development-specific bundle, we are not shipping createStoreWithDevTools in bundle.
14-
const { createStoreWithDevTools: _createStoreWithDevTools, ...finalFull } = full;
10+
const { createStoreWithDevTools: _createStoreWithDevTools, ...exports } = actual;
1511

1612
window['WebChat'] = Object.freeze({
1713
...window['WebChat'],
18-
...finalFull,
14+
...exports,
1915
buildInfo,
2016
middleware
2117
});

packages/bundle/src/boot/bundle/minimal.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import * as middleware from '../actual/middleware';
2-
import * as minimal from '../actual/minimal.js';
2+
import * as actual from '../actual/minimal.js';
33
import addVersion from '../addVersion';
44

5-
const buildInfo = Object.freeze({
6-
...minimal.buildInfo,
7-
buildTool: process.env.build_tool,
8-
moduleFormat: process.env.module_format
9-
});
5+
const buildInfo = Object.freeze({ ...actual.buildInfo, moduleFormat: process.env.module_format });
106

117
// Until we have a development-specific bundle, we are not shipping createStoreWithDevTools in bundle.
12-
const { createStoreWithDevTools: _createStoreWithDevTools, ...finalMinimal } = minimal;
8+
const { createStoreWithDevTools: _createStoreWithDevTools, ...exports } = actual;
139

1410
window['WebChat'] = Object.freeze({
1511
...window['WebChat'],
16-
...finalMinimal,
12+
...exports,
1713
buildInfo,
1814
middleware
1915
});
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)