Skip to content

Commit 639f367

Browse files
authored
Polyfill Promise as needed (#911)
* Polyfill Promise as needed * Add bluebird on Webpack only * Separate polyfill build * Use ES5 version for mock_dl
1 parent d21da13 commit 639f367

10 files changed

+64
-71
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ webpacked
2020
built
2121
botchat.js
2222
botchat.js.map
23+
botchat-es5.js
24+
botchat-es5.js.map
2325
CognitiveServices.js
2426
CognitiveServices.js.map
2527
*.css

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1717
- `nl-nl`, by [Mick Vleeshouwer](https://github.com/iMicknl) in [PR #821](https://github.com/Microsoft/BotFramework-WebChat/pull/821)
1818
- `pl-pl`, by [Peter Blazejewicz](https://github.com/peterblazejewicz) in [PR #813](https://github.com/Microsoft/BotFramework-WebChat/pull/813)
1919
- `zh-hans`, by [@Antimoney](https://github.com/Antimoney) in [PR #822](https://github.com/Microsoft/BotFramework-WebChat/pull/822) and [PR #823](https://github.com/Microsoft/BotFramework-WebChat/pull/823)
20+
- Promise polyfill with [bluebird](https://www.npmjs.com/package/bluebird) if needed in [#XXX](https://github.com/Microsoft/BotFramework-WebChat/pull/XXX)
2021

2122
### Changed
2223
- Update dependencies

package-lock.json

+11-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"license": "MIT",
3030
"dependencies": {
3131
"adaptivecards": "1.0.0",
32+
"bluebird": "^3.5.1",
3233
"botframework-directlinejs": "0.9.13",
3334
"core-js": "2.4.1",
3435
"markdown-it": "8.3.1",
@@ -65,6 +66,8 @@
6566
"botchat.css",
6667
"botchat.js",
6768
"botchat.js.map",
69+
"botchat-es5.js",
70+
"botchat-es5.js.map",
6871
"CognitiveServices.js",
6972
"CognitiveServices.js.map"
7073
]

src/BotChat.ts

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@ export * from 'botframework-directlinejs';
44
export { queryParams } from './Attachment';
55
export { SpeechOptions } from './SpeechOptions'
66
export { Speech } from './SpeechModule'
7-
// below are shims for compatibility with old browsers (IE 10 being the main culprit)
8-
import 'core-js/modules/es6.string.starts-with';
9-
import 'core-js/modules/es6.array.find';
10-
import 'core-js/modules/es6.array.find-index';

src/BotChatWithPolyfill.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export * from './BotChat';
2+
3+
// below are shims for compatibility with old browsers (IE 10 being the main culprit)
4+
import 'core-js/modules/es6.string.starts-with';
5+
import 'core-js/modules/es6.array.find';
6+
import 'core-js/modules/es6.array.find-index';
7+
8+
// Polyfill Promise if needed
9+
if (typeof (window as any).Promise === 'undefined') {
10+
(window as any).Promise = require('bluebird');
11+
}

test/mock_dl/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ app.get('/botchat.js', function (req, res) {
361361
app.get('/botchat.js.map', function (req, res) {
362362
res.sendFile(path.join(__dirname + "/../../botchat.js.map"));
363363
});
364+
app.get('/botchat-es5.js', function (req, res) {
365+
res.sendFile(path.join(__dirname + "/../../botchat-es5.js"));
366+
});
367+
app.get('/botchat-es5.js.map', function (req, res) {
368+
res.sendFile(path.join(__dirname + "/../../botchat-es5.js.map"));
369+
});
364370
app.get('/CognitiveServices.js', function (req, res) {
365371
res.sendFile(path.join(__dirname + "/../../CognitiveServices.js"));
366372
});

test/test.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<body>
5151
<div id="BotChatGoesHere"></div>
5252

53-
<script src="botchat.js"></script>
53+
<script src="botchat-es5.js"></script>
5454
<script src="mock_speech.js"></script>
5555
<script src="CognitiveServices.js"></script>
5656

webpack.config.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
var webpack = require('webpack');
1+
const webpack = require('webpack');
2+
23
require("expose-loader");
34

4-
var coreConfig = {
5+
const coreConfig = {
56
devtool: "source-map",
67

78
resolve: {
@@ -12,7 +13,10 @@ var coreConfig = {
1213
module: {
1314
rules: [
1415
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
15-
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
16+
{
17+
test: /\.tsx?$/,
18+
loader: "awesome-typescript-loader"
19+
},
1620
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
1721
{
1822
enforce: "pre",
@@ -28,7 +32,7 @@ var coreConfig = {
2832
}
2933
};
3034

31-
var chatConfig = {
35+
const chatConfig = {
3236
entry: "./src/BotChat.ts",
3337
output: {
3438
libraryTarget: "umd",
@@ -37,8 +41,17 @@ var chatConfig = {
3741
}
3842
}
3943

44+
const chatWithPolyfillConfig = {
45+
entry: "./src/BotChatWithPolyfill.ts",
46+
output: {
47+
libraryTarget: "umd",
48+
library: "BotChat",
49+
filename: "./botchat-es5.js"
50+
}
51+
}
52+
4053
// Config for addon features
41-
var featureConfig = {
54+
const featureConfig = {
4255
entry: {
4356
CognitiveServices: "./src/CognitiveServices/lib.ts"
4457
},
@@ -49,4 +62,8 @@ var featureConfig = {
4962
}
5063
}
5164

52-
module.exports = [Object.assign(chatConfig, coreConfig), Object.assign(featureConfig, coreConfig)];
65+
module.exports = [
66+
Object.assign(chatConfig, coreConfig),
67+
Object.assign(chatWithPolyfillConfig, coreConfig),
68+
Object.assign(featureConfig, coreConfig)
69+
];

webpack.production.config.js

+6-56
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
var webpack = require('webpack');
2-
require("expose-loader");
3-
4-
var coreConfig = {
5-
devtool: "source-map",
6-
7-
resolve: {
8-
// Add '.ts' and '.tsx' as resolvable extensions.
9-
extensions: [".ts", ".tsx", ".js", ".json"]
10-
},
1+
const webpack = require('webpack');
2+
const webpackDevConfig = require('./webpack.config');
113

4+
module.exports = webpackDevConfig.map(config => ({
5+
...config,
126
plugins: [
137
new webpack.DefinePlugin({
148
'process.env': {
@@ -22,49 +16,5 @@ var coreConfig = {
2216
sourceMap: true
2317
}),
2418
new webpack.optimize.OccurrenceOrderPlugin(),
25-
],
26-
27-
module: {
28-
rules: [
29-
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
30-
{
31-
test: /\.tsx?$/,
32-
loader: "awesome-typescript-loader"
33-
},
34-
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
35-
{
36-
enforce: "pre",
37-
test: /\.js$/,
38-
loader: "source-map-loader",
39-
exclude: [/node_modules/]
40-
},
41-
{
42-
test: require.resolve('adaptivecards'),
43-
use: [{ loader: 'expose-loader', options: 'AdaptiveCards' }]
44-
}
45-
]
46-
}
47-
};
48-
49-
var chatConfig = {
50-
entry: "./src/BotChat.ts",
51-
output: {
52-
libraryTarget: "umd",
53-
library: "BotChat",
54-
filename: "./botchat.js"
55-
}
56-
}
57-
58-
// Config for addon features
59-
var featureConfig = {
60-
entry: {
61-
CognitiveServices: "./src/CognitiveServices/lib.ts"
62-
},
63-
output: {
64-
libraryTarget: "umd",
65-
library: "[name]",
66-
filename: "./[name].js",
67-
}
68-
}
69-
70-
module.exports = [Object.assign(chatConfig, coreConfig), Object.assign(featureConfig, coreConfig)];
19+
]
20+
}));

0 commit comments

Comments
 (0)