Skip to content

Commit 4c7400a

Browse files
authored
Disable AMD in our bundle (#5478)
* Bundle globalize-runtime * Disable ESLint for PrecompiledGlobalize.bundle.js * Add entry * Use undefined * Disable AMD on bundled code * Update entry * Revert globalize changes and remove define from test harness * Revert * Add comment * Remove define.amd * Update entry
1 parent 2986fa9 commit 4c7400a

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
219219
- Fixed [#5452](https://github.com/microsoft/BotFramework-WebChat/issues/5452). With Fluent/Copilot theme, the typing indicator padding should not be squashed, in PR [#5453](https://github.com/microsoft/BotFramework-WebChat/pull/5453), by [@compulim](https://github.com/compulim)
220220
- Fixed [#5461](https://github.com/microsoft/BotFramework-WebChat/issues/5461). On macOS and Fluent skinpack applied, using Japanese IME to input some Japanese text should not send them immediately, in PR [#5462](https://github.com/microsoft/BotFramework-WebChat/pull/5462), by [@compulim](https://github.com/compulim)
221221
- Fixed [#5472](https://github.com/microsoft/BotFramework-WebChat/issues/5472), ensure proper inheritance from the outside of Web Chat for visibility CSS property when hidden, in PR [#5473](https://github.com/microsoft/BotFramework-WebChat/pull/5473), by [@OEvgeny](https://github.com/OEvgeny)
222+
- Fixed [#5474](https://github.com/microsoft/BotFramework-WebChat/issues/5474). Disable AMD glue code in bundle, in PR [#5478](https://github.com/microsoft/BotFramework-WebChat/pull/5478), by [@compulim](https://github.com/compulim)
223+
- Downstreamers who use our CommonJS and ES Modules output with esbuild will need to disable AMD themselves to prevent conflict with RequireJS
222224

223225
# Removed
224226

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="https://requirejs.org/docs/release/2.3.7/minified/require.js"></script>
6+
<script crossorigin="anonymous" src="/test-harness.js"></script>
7+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
8+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
9+
</head>
10+
<body>
11+
<main id="webchat"></main>
12+
<script>
13+
run(async function () {
14+
WebChat.renderWebChat(
15+
{
16+
directLine: WebChat.createDirectLine({ token: await testHelpers.token.fetchDirectLineToken() }),
17+
store: testHelpers.createStore()
18+
},
19+
document.getElementById('webchat')
20+
);
21+
22+
await pageConditions.uiConnected();
23+
});
24+
</script>
25+
</body>
26+
</html>

packages/test/harness/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"scripts": {
1515
"build": "npm run build:babel && npm run build:esbuild",
1616
"build:babel": "babel --config-file ./babel.config.json --out-dir lib src",
17-
"build:esbuild": "esbuild lib/browser/index.js --bundle --define:process.env.CI=undefined --outfile=dist/test-harness.js --sourcemap --target=chrome100",
17+
"build:esbuild": "esbuild lib/browser/index.js --bundle --define:define=undefined --define:process.env.CI=undefined --outfile=dist/test-harness.js --sourcemap --target=chrome100",
1818
"bump": "npm run bump:prod && npm run bump:dev && (npm audit fix || exit 0)",
1919
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localDependencies // {} | keys) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | contains([$K]) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
2020
"bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localDependencies // {} | keys) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | contains([$K]) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install --save-exact $PACKAGES_TO_BUMP || true",

packages/test/page-object/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"build": "npm run build:babel && npm run build:esbuild",
1313
"build:babel": "babel --out-dir lib/ src/",
14-
"build:esbuild": "esbuild lib/index.js --bundle --outfile=dist/test-page-object.js --sourcemap --target=chrome100",
14+
"build:esbuild": "esbuild lib/index.js --bundle --define:define=undefined --outfile=dist/test-page-object.js --sourcemap --target=chrome100",
1515
"bump": "npm run bump:prod && npm run bump:dev && (npm audit fix || exit 0)",
1616
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localDependencies // {} | keys) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | contains([$K]) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
1717
"bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localDependencies // {} | keys) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | contains([$K]) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install --save-exact $PACKAGES_TO_BUMP || true",

tsup.base.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ const baseConfig: Options & { target: Target[] } = {
1717
...(npm_package_version ? { npm_package_version } : {})
1818
},
1919
esbuildOptions: options => {
20+
// esbuild don't touch AMD but it also don't remove AMD glue code.
21+
// Some of our packages prefers AMD over CJS via UMD and it also use anonymous modules.
22+
// This combination conflict with RequireJS if it present in the system.
23+
// We are removing AMD glue code manually, just like how Rollup does.
24+
// Read more at https://github.com/evanw/esbuild/issues/1348.
25+
// Also https://github.com/rollup/plugins/blob/e1a5ef99f1578eb38a8c87563cb9651db228f3bd/packages/commonjs/src/transform-commonjs.js#L328.
26+
// Test case at /__tests__/html2/hosting/requirejs.html.
27+
options.define = options.define || {};
28+
options.define.define = 'undefined';
29+
2030
options.legalComments = 'linked';
2131
},
2232
esbuildPlugins:

0 commit comments

Comments
 (0)