Skip to content

Commit

Permalink
Add base package (#5176)
Browse files Browse the repository at this point in the history
* Add base package

* Self review

* fix wording

Co-authored-by: William Wong <compulim@users.noreply.github.com>

* Remove babel

* Self-review

* Tweak api package

* Tweak component package

* Tweak more packages

* Fix lock file

* Valid core dts

* Do not emit unused

* Make base a bit useful ⚡️

* Cleanup

---------

Co-authored-by: William Wong <compulim@users.noreply.github.com>
  • Loading branch information
OEvgeny and compulim authored Oct 2, 2024
1 parent 0eed4fb commit 21a4ec1
Show file tree
Hide file tree
Showing 60 changed files with 231 additions and 113 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull-request-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ jobs:
- run: npm run build --if-present

- name: Run tsd under packages/bundle (CJS)
run: ../../node_modules/.bin/tsd -t ./lib/index.d.ts
run: ../../node_modules/.bin/tsd -t ./dist/botframework-webchat.d.ts
working-directory: ./packages/bundle

- name: Run tsd under packages/bundle (ESM)
run: ../../node_modules/.bin/tsd -t ./dist/botframework-webchat.d.mts
working-directory: ./packages/bundle

- name: Run tsd under packages/core (CJS)
run: ../../node_modules/.bin/tsd -t ./lib/index.d.ts
run: ../../node_modules/.bin/tsd -t ./dist/botframework-webchat-core.d.ts
working-directory: ./packages/core

- name: Run tsd under packages/core (ESM)
Expand Down
39 changes: 36 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"keywords": [],
"cldr-data-coverage": "full",
"workspaces": [
"./packages/base",
"./packages/test/dev-server",
"./packages/test/harness",
"./packages/test/web-server",
Expand Down
11 changes: 8 additions & 3 deletions packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

Web Chat consists of the following packages:

- [`base`](#base)
- [`core`](#core)
- [`component`](#component)
- [`bundle`](#bundle)
- [`directlinespeech`](#directlinespeech)
- [`embed`](#embed)
- [`isomorphic-*`](#isomorphic-*)

## `base`

Essentials and utilities used in the project.

## `core`

Stateful data layer as Redux store.
Expand Down Expand Up @@ -69,9 +74,9 @@ We offer 3 build flavors:

| | Instrumented | Minified | Source maps |
| ----------- | ------------ | -------- | ----------- |
| Production || ||
| Test | | ||
| Development ||| |
| Production ||||
| Test ||||
| Development ||||

> Instrumentation code is added by Istanbul via Babel.
> Minification is carried out by Terser via Webpack.
Expand Down
1 change: 0 additions & 1 deletion packages/api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*.tgz
/dist/
/lib/
/node_modules/
/src/external/
2 changes: 1 addition & 1 deletion packages/api/decorator.js
Original file line number Diff line number Diff line change
@@ -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-api.decorator');
2 changes: 1 addition & 1 deletion packages/api/internal.js
Original file line number Diff line number Diff line change
@@ -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-api.internal');
25 changes: 10 additions & 15 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "botframework-webchat-api",
"version": "0.0.0-0",
"description": "React DOM component of botframework-webchat",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"main": "./dist/botframework-webchat-api.js",
"types": "./dist/botframework-webchat-api.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/botframework-webchat-api.d.mts",
"default": "./dist/botframework-webchat-api.mjs"
},
"require": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
"types": "./dist/botframework-webchat-api.d.ts",
"default": "./dist/botframework-webchat-api.js"
}
},
"./internal": {
Expand All @@ -21,8 +21,8 @@
"default": "./dist/botframework-webchat-api.internal.mjs"
},
"require": {
"types": "./lib/internal.d.ts",
"default": "./lib/internal.js"
"types": "./dist/botframework-webchat-api.internal.d.ts",
"default": "./dist/botframework-webchat-api.internal.js"
}
},
"./decorator": {
Expand All @@ -31,8 +31,8 @@
"default": "./dist/botframework-webchat-api.decorator.mjs"
},
"require": {
"types": "./lib/decorator/index.d.ts",
"default": "./lib/decorator/index.js"
"types": "./dist/botframework-webchat-api.decorator.d.ts",
"default": "./dist/botframework-webchat-api.decorator.js"
}
}
},
Expand All @@ -51,16 +51,13 @@
"files": [
"./dist/**/*",
"./*.js",
"./lib/**/*",
"./src/**/*"
],
"homepage": "https://github.com/microsoft/BotFramework-WebChat/tree/main/packages/component#readme",
"scripts": {
"build": "npm run build:globalize && npm run build:tsup && npm run build:typescript && npm run build:babel",
"build:babel": "cross-env build_tool=babel module_format=commonjs babel src --copy-files --extensions .js,.ts,.tsx --ignore **/*.spec.js,**/*.spec.ts,**/*.spec.tsx,**/*.test.js,**/*.test.ts,**/*.test.tsx,__tests__/**/*.js,__tests__/**/*.ts,__tests__/**/*.tsx --no-copy-ignored --out-dir lib --verbose",
"build": "npm run build:globalize && npm run build:tsup",
"build:globalize": "node scripts/createPrecompiledGlobalize.mjs",
"build:tsup": "tsup --config ./tsup.config.ts",
"build:typescript": "tsc --project src/tsconfig.json",
"bump": "npm run bump:prod && npm run bump:dev && (npm audit fix || exit 0)",
"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",
"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",
Expand All @@ -71,9 +68,7 @@
"precommit:typecheck": "tsc --project ./src --emitDeclarationOnly false --esModuleInterop true --noEmit --pretty false",
"preversion": "cat package.json | jq '(.localDependencies // {} | to_entries | map([if .value == \"production\" then \"dependencies\" else \"devDependencies\" end, .key])) as $P | delpaths($P)' > package-temp.json && mv package-temp.json package.json",
"start": "concurrently --kill-others --prefix-colors \"auto\" \"npm:start:*\"",
"start:babel": "npm run build:babel -- --skip-initial-build --watch",
"start:tsup": "npm run build:tsup -- --watch",
"start:typescript": "npm run build:typescript -- --watch"
"start:tsup": "npm run build:tsup -- --watch"
},
"localDependencies": {
"botframework-webchat-cldr-data": "development",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/hooks/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import normalizeLanguage from '../utils/normalizeLanguage';
import { SendBoxMiddlewareProvider, type SendBoxMiddleware } from './internal/SendBoxMiddleware';
import { SendBoxToolbarMiddlewareProvider, type SendBoxToolbarMiddleware } from './internal/SendBoxToolbarMiddleware';
import Tracker from './internal/Tracker';
import { default as WebChatAPIContext } from './internal/WebChatAPIContext';
import WebChatAPIContext, { type WebChatAPIContextType } from './internal/WebChatAPIContext';
import WebChatReduxContext, { useDispatch } from './internal/WebChatReduxContext';
import defaultSelectVoice from './internal/defaultSelectVoice';
import applyMiddleware, {
Expand Down Expand Up @@ -218,7 +218,7 @@ type ComposerCoreProps = Readonly<{
attachmentMiddleware?: OneOrMany<AttachmentMiddleware>;
avatarMiddleware?: OneOrMany<AvatarMiddleware>;
cardActionMiddleware?: OneOrMany<CardActionMiddleware>;
children?: ReactNode | ((context: ContextOf<typeof WebChatAPIContext>) => ReactNode);
children?: ReactNode | ((context: ContextOf<React.Context<WebChatAPIContextType>>) => ReactNode);
dir?: string;
directLine: DirectLineJSBotConnection;
/**
Expand Down Expand Up @@ -543,7 +543,7 @@ const ComposerCore = ({
* This context should consist of members that are not in the Redux store
* i.e. members that are not interested in other types of UIs
*/
const context = useMemo<ContextOf<typeof WebChatAPIContext>>(
const context = useMemo<ContextOf<React.Context<WebChatAPIContextType>>>(
() => ({
...cardActionContext,
...groupActivitiesContext,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/hooks/internal/WebChatAPIContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ScrollToEndButtonComponentFactory } from '../../types/ScrollToEndButton
import TelemetryMeasurementEvent from '../../types/TelemetryMeasurementEvent';
import { RenderToast } from '../../types/ToastMiddleware';

type WebChatAPIContext = {
export type WebChatAPIContextType = {
activityRenderer?: LegacyActivityRenderer;
activityStatusRenderer: RenderActivityStatus;
attachmentForScreenReaderRenderer?: AttachmentForScreenReaderComponentFactory;
Expand Down Expand Up @@ -88,7 +88,7 @@ type WebChatAPIContext = {
username?: string;
};

const context = createContext<WebChatAPIContext>(undefined);
const context = createContext<WebChatAPIContextType>(undefined);

context.displayName = 'WebChatAPIContext';

Expand Down
6 changes: 1 addition & 5 deletions packages/api/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationDir": "../lib",
"declarationMap": true,
"downlevelIteration": true,
"emitDeclarationOnly": true,
"jsx": "react",
"module": "ESNext",
"moduleResolution": "Bundler",
"preserveWatchOutput": true,
"noEmit": true,
"pretty": true,
"resolveJsonModule": true, // Required for localization files
"skipLibCheck": true,
Expand Down
3 changes: 2 additions & 1 deletion packages/api/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default defineConfig({
'botframework-webchat-api.internal': './src/internal.ts',
'botframework-webchat-api.decorator': './src/decorator/index.ts'
},
noExternal: ['globalize']
noExternal: ['globalize'],
format: ['esm', 'cjs']
});
6 changes: 6 additions & 0 deletions packages/base/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends:
- ../../.eslintrc.production.yml

# This package is compatible with web browser.
env:
browser: true
3 changes: 3 additions & 0 deletions packages/base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*.tgz
/dist/
/node_modules/
Empty file added packages/base/README.md
Empty file.
Loading

0 comments on commit 21a4ec1

Please sign in to comment.