Skip to content

Commit 847e900

Browse files
authored
Show deprecation for legacy imports (#5600)
* Show deprecation for old imports * Add entry * Update message * Rename to deprecateObject * Check for no dupe deprecation notes * Get own properties only * Add denylist * Use warnOnce from base * Add explicit type casting
1 parent fa3f1e1 commit 847e900

File tree

19 files changed

+269
-27
lines changed

19 files changed

+269
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
140140
- (Experimental) Added support for importing via `<script type="module">`, by [@compulim](https://github.com/compulim) in PR [#5592](https://github.com/microsoft/BotFramework-WebChat/pull/5592)
141141
- Added support for `botframework-webchat-fluent-theme` package, by [@compulim](https://github.com/compulim) in PR [#5593](https://github.com/microsoft/BotFramework-WebChat/pull/5593)
142142
- Bundling vendor chunks, by [@compulim](https://github.com/compulim) in PR [#5595](https://github.com/microsoft/BotFramework-WebChat/pull/5595)
143+
- Added deprecation notes for legacy imports, by [@compulim](https://github.com/compulim) in PR [#5600](https://github.com/microsoft/BotFramework-WebChat/pull/5600)
144+
- `import { hooks } from 'botframework-webchat'` should be replaced by `import * as hooks from 'botframework-webchat/hook'`
143145

144146
### Changed
145147

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
</head>
6+
<body>
7+
<main id="webchat"></main>
8+
<script type="importmap">
9+
{
10+
"imports": {
11+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
12+
"jest-mock": "https://esm.sh/jest-mock",
13+
"react": "/__dist__/packages/bundle/static/react.js",
14+
"react-dom": "/__dist__/packages/bundle/static/react-dom.js"
15+
}
16+
}
17+
</script>
18+
<script type="module">
19+
import { fn, spyOn } from 'jest-mock';
20+
21+
spyOn(console, 'warn');
22+
</script>
23+
<script type="module">
24+
import '/test-harness.mjs';
25+
import '/test-page-object.mjs';
26+
27+
import { Components, createDirectLine, createStoreWithOptions, renderWebChat } from 'botframework-webchat';
28+
import { version } from 'react';
29+
30+
run(async function () {
31+
expect(console.warn).toHaveBeenCalledTimes(0);
32+
33+
// WHEN: Touching "Components.BasicWebChat".
34+
expect(Components.BasicWebChat).not.toBeUndefined();
35+
36+
// THEN: Should show deprecation note.
37+
expect(console.warn).toHaveBeenCalledTimes(1);
38+
expect(console.warn).toHaveBeenLastCalledWith(
39+
"botframework-webchat: `import { Components } from 'botframework-webchat'` has been deprecated, use `import { %s } from 'botframework-webchat/component'` instead.",
40+
'BasicWebChat'
41+
);
42+
43+
// WHEN: Touching "Components.BasicTranscript".
44+
expect(Components.BasicWebChat).not.toBeUndefined();
45+
46+
// THEN: Should not show deprecation note again.
47+
expect(console.warn).toHaveBeenCalledTimes(1);
48+
});
49+
</script>
50+
</body>
51+
</html>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
</head>
6+
<body>
7+
<main id="webchat"></main>
8+
<script type="importmap">
9+
{
10+
"imports": {
11+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
12+
"botframework-webchat/component": "/__dist__/packages/bundle/static/botframework-webchat/component.js",
13+
"jest-mock": "https://esm.sh/jest-mock",
14+
"react": "/__dist__/packages/bundle/static/react.js",
15+
"react-dom": "/__dist__/packages/bundle/static/react-dom.js"
16+
}
17+
}
18+
</script>
19+
<script type="module">
20+
import { fn, spyOn } from 'jest-mock';
21+
22+
spyOn(console, 'warn');
23+
</script>
24+
<script type="module">
25+
import '/test-harness.mjs';
26+
import '/test-page-object.mjs';
27+
28+
import { createDirectLine, createStoreWithOptions, renderWebChat } from 'botframework-webchat';
29+
import * as Components from 'botframework-webchat/component';
30+
import { version } from 'react';
31+
32+
run(async function () {
33+
expect(console.warn).toHaveBeenCalledTimes(0);
34+
35+
// WHEN: Touching anything about "hooks".
36+
expect(Components.BasicWebChat).not.toBeUndefined();
37+
38+
expect(console.warn).toHaveBeenCalledTimes(0);
39+
});
40+
</script>
41+
</body>
42+
</html>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
</head>
6+
<body>
7+
<main id="webchat"></main>
8+
<script type="importmap">
9+
{
10+
"imports": {
11+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
12+
"jest-mock": "https://esm.sh/jest-mock",
13+
"react": "/__dist__/packages/bundle/static/react.js",
14+
"react-dom": "/__dist__/packages/bundle/static/react-dom.js"
15+
}
16+
}
17+
</script>
18+
<script type="module">
19+
import { fn, spyOn } from 'jest-mock';
20+
21+
spyOn(console, 'warn');
22+
</script>
23+
<script type="module">
24+
import '/test-harness.mjs';
25+
import '/test-page-object.mjs';
26+
27+
import { createDirectLine, createStoreWithOptions, hooks, renderWebChat } from 'botframework-webchat';
28+
import { version } from 'react';
29+
30+
run(async function () {
31+
expect(console.warn).toHaveBeenCalledTimes(0);
32+
33+
// WHEN: Touching "hooks.useStyleOptions".
34+
expect(hooks.useStyleOptions).not.toBeUndefined();
35+
36+
// THEN: Should show deprecation note.
37+
expect(console.warn).toHaveBeenCalledTimes(1);
38+
expect(console.warn).toHaveBeenLastCalledWith(
39+
"botframework-webchat: `import { hooks } from 'botframework-webchat'` has been deprecated, use `import { %s } from 'botframework-webchat/hook'` instead.",
40+
'useStyleOptions'
41+
);
42+
43+
// WHEN: Touching "hooks.useStyleSet".
44+
expect(hooks.useStyleSet).not.toBeUndefined();
45+
46+
// THEN: Should not show deprecation note again.
47+
expect(console.warn).toHaveBeenCalledTimes(1);
48+
});
49+
</script>
50+
</body>
51+
</html>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
</head>
6+
<body>
7+
<main id="webchat"></main>
8+
<script type="importmap">
9+
{
10+
"imports": {
11+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
12+
"botframework-webchat/hook": "/__dist__/packages/bundle/static/botframework-webchat/hook.js",
13+
"jest-mock": "https://esm.sh/jest-mock",
14+
"react": "/__dist__/packages/bundle/static/react.js",
15+
"react-dom": "/__dist__/packages/bundle/static/react-dom.js"
16+
}
17+
}
18+
</script>
19+
<script type="module">
20+
import { fn, spyOn } from 'jest-mock';
21+
22+
spyOn(console, 'warn');
23+
</script>
24+
<script type="module">
25+
import '/test-harness.mjs';
26+
import '/test-page-object.mjs';
27+
28+
import { createDirectLine, createStoreWithOptions, renderWebChat } from 'botframework-webchat';
29+
import * as hooks from 'botframework-webchat/hook';
30+
import { version } from 'react';
31+
32+
run(async function () {
33+
expect(console.warn).toHaveBeenCalledTimes(0);
34+
35+
// WHEN: Touching anything about "hooks".
36+
expect(hooks.useStyleOptions).not.toBeUndefined();
37+
38+
expect(console.warn).toHaveBeenCalledTimes(0);
39+
});
40+
</script>
41+
</body>
42+
</html>

packages/api-middleware/src/private/templatePolymiddleware.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { warnOnce } from 'botframework-webchat-core';
1+
import { warnOnce } from '@msinternal/botframework-webchat-base/utils';
22
import { type Enhancer } from 'handler-chain';
33
import React, { memo, type ReactNode } from 'react';
44
import {

packages/api/src/hooks/useSendFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint no-magic-numbers: ["error", { "ignore": [0, 1024] }] */
22

3-
import { warnOnce } from 'botframework-webchat-core';
3+
import { warnOnce } from '@msinternal/botframework-webchat-base/utils';
44
import { useCallback } from 'react';
55

66
import useWebChatAPIContext from './internal/useWebChatAPIContext';

packages/api/src/middleware/private/templateMiddleware.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { warnOnce } from 'botframework-webchat-core';
1+
import { warnOnce } from '@msinternal/botframework-webchat-base/utils';
22
import React, { memo, type ReactNode } from 'react';
33
import { createChainOfResponsibility, type ComponentMiddleware } from 'react-chain-of-responsibility';
44
import { array, function_, safeParse, type InferOutput } from 'valibot';

packages/api/src/normalizeStyleOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { warnOnce } from 'botframework-webchat-core';
1+
import { warnOnce } from '@msinternal/botframework-webchat-base/utils';
22

33
import defaultStyleOptions from './defaultStyleOptions';
44
import StyleOptions, { StrictStyleOptions } from './StyleOptions';

packages/api/src/utils/warnOnce.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)