From 8c310219aa8c7b4ff3c8c1179893c98bea3e7edc Mon Sep 17 00:00:00 2001 From: William Wong Date: Wed, 9 Oct 2024 10:06:26 +0000 Subject: [PATCH 1/4] Update barrel files --- packages/api/decorator.js | 2 +- packages/api/internal.js | 2 +- packages/base/utils.js | 2 +- packages/component/decorator.js | 2 +- packages/component/internal.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/api/decorator.js b/packages/api/decorator.js index 8506fc240b..f9f042815f 100644 --- a/packages/api/decorator.js +++ b/packages/api/decorator.js @@ -1,3 +1,3 @@ // This is required for Webpack 4 which does not support named exports. // eslint-disable-next-line no-undef -module.exports = require('./dist/botframework-webchat-api.decorator'); +module.exports = require('./dist/botframework-webchat-api.decorator.js'); diff --git a/packages/api/internal.js b/packages/api/internal.js index ea85579df0..9805b0706c 100644 --- a/packages/api/internal.js +++ b/packages/api/internal.js @@ -1,3 +1,3 @@ // This is required for Webpack 4 which does not support named exports. // eslint-disable-next-line no-undef -module.exports = require('./dist/botframework-webchat-api.internal'); +module.exports = require('./dist/botframework-webchat-api.internal.js'); diff --git a/packages/base/utils.js b/packages/base/utils.js index be22dd8b5f..534ba435dd 100644 --- a/packages/base/utils.js +++ b/packages/base/utils.js @@ -1,3 +1,3 @@ // This is required for Webpack 4 which does not support named exports. // eslint-disable-next-line no-undef -module.exports = require('./dist/botframework-webchat-base.utils'); +module.exports = require('./dist/botframework-webchat-base.utils.js'); diff --git a/packages/component/decorator.js b/packages/component/decorator.js index 16dcf52fc7..71f2d1c453 100644 --- a/packages/component/decorator.js +++ b/packages/component/decorator.js @@ -1,3 +1,3 @@ // This is required for Webpack 4 which does not support named exports. // eslint-disable-next-line no-undef -module.exports = require('./lib/decorator/index'); +module.exports = require('./dist/botframework-webchat-component.decorator.js'); diff --git a/packages/component/internal.js b/packages/component/internal.js index 2a05a7c53f..f2e97c9b8d 100644 --- a/packages/component/internal.js +++ b/packages/component/internal.js @@ -1,3 +1,3 @@ // This is required for Webpack 4 which does not support named exports. // eslint-disable-next-line no-undef -module.exports = require('./lib/internal'); +module.exports = require('./dist/botframework-webchat-component.internal.js'); From 317e0262c33cda98549814f214669fbc35e657ce Mon Sep 17 00:00:00 2001 From: William Wong Date: Wed, 9 Oct 2024 10:07:54 +0000 Subject: [PATCH 2/4] Emit CJS as ES2019 --- packages/api/tsup.config.ts | 19 +++++++++++++++---- packages/base/tsup.config.ts | 17 ++++++++++++++--- packages/bundle/tsup.config.ts | 19 +++++++++++++++---- packages/component/tsup.config.ts | 19 +++++++++++++++---- packages/core/tsup.config.ts | 17 ++++++++++++++--- packages/directlinespeech/tsup.config.ts | 16 ++++++++++++++-- packages/fluent-theme/tsup.config.ts | 3 ++- packages/styles/tsup.config.ts | 17 ++++++++++++++--- tsup.base.config.ts | 12 ++++++++---- 9 files changed, 111 insertions(+), 28 deletions(-) diff --git a/packages/api/tsup.config.ts b/packages/api/tsup.config.ts index 423f6dfe2e..b9ff3588e6 100644 --- a/packages/api/tsup.config.ts +++ b/packages/api/tsup.config.ts @@ -1,13 +1,24 @@ import { defineConfig } from 'tsup'; import baseConfig from '../../tsup.base.config'; -export default defineConfig({ +const config: typeof baseConfig = { ...baseConfig, entry: { 'botframework-webchat-api': './src/index.ts', 'botframework-webchat-api.internal': './src/internal.ts', 'botframework-webchat-api.decorator': './src/decorator/index.ts' + } +}; + +export default defineConfig([ + { + ...config, + format: 'esm', + noExternal: ['globalize'] }, - noExternal: ['globalize'], - format: ['esm', 'cjs'] -}); + { + ...config, + format: 'cjs', + target: [...config.target, 'es2019'] + } +]); diff --git a/packages/base/tsup.config.ts b/packages/base/tsup.config.ts index 4c25ec196d..0021615804 100644 --- a/packages/base/tsup.config.ts +++ b/packages/base/tsup.config.ts @@ -1,11 +1,22 @@ import { defineConfig } from 'tsup'; import baseConfig from '../../tsup.base.config'; -export default defineConfig({ +const config: typeof baseConfig = { ...baseConfig, entry: { 'botframework-webchat-base': './src/index.ts', 'botframework-webchat-base.utils': './src/utils/index.ts' + } +}; + +export default defineConfig([ + { + ...config, + format: 'esm' }, - format: ['esm', 'cjs'] -}); + { + ...config, + format: 'cjs', + target: [...config.target, 'es2019'] + } +]); diff --git a/packages/bundle/tsup.config.ts b/packages/bundle/tsup.config.ts index 1b2201ca35..ad95fd81c7 100644 --- a/packages/bundle/tsup.config.ts +++ b/packages/bundle/tsup.config.ts @@ -13,7 +13,7 @@ const resolveCognitiveServicesToES2015 = { } }; -export default defineConfig({ +const config: typeof baseConfig = { ...baseConfig, entry: { 'botframework-webchat': './src/index.ts', @@ -34,6 +34,17 @@ export default defineConfig({ 'memoize-one', 'microsoft-cognitiveservices-speech-sdk', 'web-speech-cognitive-services' - ], - format: ['esm', 'cjs'] -}); + ] +}; + +export default defineConfig([ + { + ...config, + format: 'esm' + }, + { + ...config, + format: 'cjs', + target: [...config.target, 'es2019'] + } +]); diff --git a/packages/component/tsup.config.ts b/packages/component/tsup.config.ts index d3afbefcba..7df5a259f5 100644 --- a/packages/component/tsup.config.ts +++ b/packages/component/tsup.config.ts @@ -1,10 +1,10 @@ +import { injectCSSPlugin } from 'botframework-webchat-styles/build'; import { defineConfig } from 'tsup'; import baseConfig from '../../tsup.base.config'; import { componentStyleContent as componentStyleContentPlaceholder } from './src/Styles/createStyles'; import { decoratorStyleContent as decoratorStyleContentPlaceholder } from './src/decorator/private/createStyles'; -import { injectCSSPlugin } from 'botframework-webchat-styles/build'; -export default defineConfig({ +const config: typeof baseConfig = { ...baseConfig, loader: { ...baseConfig.loader, @@ -18,6 +18,17 @@ export default defineConfig({ 'botframework-webchat-component': './src/index.ts', 'botframework-webchat-component.internal': './src/internal.ts', 'botframework-webchat-component.decorator': './src/decorator/index.ts' + } +}; + +export default defineConfig([ + { + ...config, + format: 'esm' }, - format: ['esm', 'cjs'] -}); + { + ...config, + format: 'cjs', + target: [...config.target, 'es2019'] + } +]); diff --git a/packages/core/tsup.config.ts b/packages/core/tsup.config.ts index 50741e1df5..a7638de4bf 100644 --- a/packages/core/tsup.config.ts +++ b/packages/core/tsup.config.ts @@ -1,10 +1,21 @@ import { defineConfig } from 'tsup'; import baseConfig from '../../tsup.base.config'; -export default defineConfig({ +const config: typeof baseConfig = { ...baseConfig, entry: { 'botframework-webchat-core': './src/index.ts' + } +}; + +export default defineConfig([ + { + ...config, + format: 'esm' }, - format: ['esm', 'cjs'] -}); + { + ...config, + format: 'cjs', + target: [...config.target, 'es2019'] + } +]); diff --git a/packages/directlinespeech/tsup.config.ts b/packages/directlinespeech/tsup.config.ts index e715a24b09..f4de4f27a8 100644 --- a/packages/directlinespeech/tsup.config.ts +++ b/packages/directlinespeech/tsup.config.ts @@ -13,7 +13,7 @@ const resolveCognitiveServicesToES2015 = { } }; -export default defineConfig({ +const config: typeof baseConfig = { ...baseConfig, entry: { 'botframework-directlinespeech-sdk': './src/index.js' @@ -29,4 +29,16 @@ export default defineConfig({ esbuildPlugins: [resolveCognitiveServicesToES2015], // We need to internalize event-target-shim because it appear as transient packages with a different version. noExternal: ['event-target-shim'] -}); +}; + +export default defineConfig([ + { + ...config, + format: 'esm' + }, + { + ...config, + format: 'cjs', + target: [...config.target, 'es2019'] + } +]); diff --git a/packages/fluent-theme/tsup.config.ts b/packages/fluent-theme/tsup.config.ts index 39963d95dc..d890eef93d 100644 --- a/packages/fluent-theme/tsup.config.ts +++ b/packages/fluent-theme/tsup.config.ts @@ -44,7 +44,8 @@ export default defineConfig([ '.css': 'local-css' }, esbuildPlugins: [...(baseConfig.esbuildPlugins || []), injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })], - format: ['cjs'] + format: ['cjs'], + target: [...baseConfig.target, 'es2019'] }, { ...baseConfig, diff --git a/packages/styles/tsup.config.ts b/packages/styles/tsup.config.ts index a0796ae4c3..d49c9aef7a 100644 --- a/packages/styles/tsup.config.ts +++ b/packages/styles/tsup.config.ts @@ -1,12 +1,23 @@ import { defineConfig } from 'tsup'; import baseConfig from '../../tsup.base.config'; -export default defineConfig({ +const config: typeof baseConfig = { ...baseConfig, entry: { 'botframework-webchat-styles': './src/index.ts', 'botframework-webchat-styles.build': './src/build/index.ts', 'botframework-webchat-styles.react': './src/react/index.ts' + } +}; + +export default defineConfig([ + { + ...config, + format: 'esm' }, - format: ['esm', 'cjs'] -}); + { + ...config, + format: 'cjs', + target: [...config.target, 'es2019'] + } +]); diff --git a/tsup.base.config.ts b/tsup.base.config.ts index 04b003fb6a..0c9afec711 100644 --- a/tsup.base.config.ts +++ b/tsup.base.config.ts @@ -1,11 +1,13 @@ -import { defineConfig, type Options } from 'tsup'; +import { type Options } from 'tsup'; import { babelPlugin, defaultPredicate, type Predicate } from './esbuildBabelPluginIstanbul'; +type Target = Exclude | undefined>; + const env = process.env.NODE_ENV || 'development'; const { npm_package_version } = process.env; const istanbulPredicate: Predicate = args => defaultPredicate(args) && !/\.worker\.[cm]?[jt]s$/u.test(args.path); -export default defineConfig({ +const baseConfig: Options & { target: Target[] } = { dts: true, env: { build_tool: 'tsup', @@ -52,5 +54,7 @@ export default defineConfig({ minify: env === 'production', platform: 'browser', sourcemap: true, - target: ['chrome100', 'firefox100', 'safari15'] -}) as Options; + target: ['chrome100', 'firefox100', 'safari15'] satisfies Target[] +}; + +export default baseConfig; From 815bf732c48c819a7ddbc05a35231d53e5d0aa19 Mon Sep 17 00:00:00 2001 From: William Wong Date: Wed, 9 Oct 2024 11:06:43 +0000 Subject: [PATCH 3/4] Force code splitting in CJS --- tsup.base.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tsup.base.config.ts b/tsup.base.config.ts index 0c9afec711..be937b21c6 100644 --- a/tsup.base.config.ts +++ b/tsup.base.config.ts @@ -54,6 +54,7 @@ const baseConfig: Options & { target: Target[] } = { minify: env === 'production', platform: 'browser', sourcemap: true, + splitting: true, target: ['chrome100', 'firefox100', 'safari15'] satisfies Target[] }; From 6796b5bcc555c6c6f9fe9837c9da013c2f7c2dbd Mon Sep 17 00:00:00 2001 From: William Wong Date: Wed, 9 Oct 2024 11:13:07 +0000 Subject: [PATCH 4/4] Add entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fff789f3e..896f165af9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -808,6 +808,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/ - Fixed typings of `useFocus` and `useLocalizer` - Fixes [#3165](https://github.com/microsoft/BotFramework-WebChat/issues/3165) and [#4094](https://github.com/microsoft/BotFramework-WebChat/issues/4094). Allowlist `aria-label` for links in Markdown and skip unrecognized attributes or invalid curly brackets, by [@compulim](https://github.com/compulim), in PR [#4095](https://github.com/microsoft/BotFramework-WebChat/pull/4095) - Fixes [#4190](https://github.com/microsoft/BotFramework-WebChat/issues/4190). Recent Markdown curly bracket fix should not break IE11 due to unsupported "u" flag in `RegExp`, by [@compulim](https://github.com/compulim), in PR [#4191](https://github.com/microsoft/BotFramework-WebChat/pull/4191) +- Improved importability in vanilla Webpack 4 without `babel-loader`, by [@compulim](https://github.com/compulim), in PR [#5322](https://github.com/microsoft/BotFramework-WebChat/pull/5322) ### Changed