Skip to content

Commit

Permalink
[web pub sub] update express to ESM (#29862)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR

- @azure/web-pubsub-express

### Issues associated with this PR


### Describe the problem that is addressed by this PR

Updates to ESM via `tshy` and moves from Mocha/Chai/Sinon to `vitest`

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
mpodwysocki authored Jun 3, 2024
1 parent 55d0676 commit 6cb2dd4
Show file tree
Hide file tree
Showing 21 changed files with 251 additions and 159 deletions.
23 changes: 18 additions & 5 deletions common/config/rush/pnpm-lock.yaml

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

7 changes: 6 additions & 1 deletion sdk/web-pubsub/web-pubsub-express/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"plugins": ["@azure/azure-sdk"],
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"]
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
"rules": {
"@azure/azure-sdk/ts-package-json-module": "off",
"@azure/azure-sdk/ts-package-json-types": "off",
"@azure/azure-sdk/ts-package-json-files-required": "off"
}
}
8 changes: 8 additions & 0 deletions sdk/web-pubsub/web-pubsub-express/.tshy/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"module": "nodenext",
"moduleResolution": "nodenext"
}
}
14 changes: 14 additions & 0 deletions sdk/web-pubsub/web-pubsub-express/.tshy/commonjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.cts",
"../src/**/*.tsx"
],
"exclude": [
"../src/**/*.mts"
],
"compilerOptions": {
"outDir": "../.tshy-build/commonjs"
}
}
12 changes: 12 additions & 0 deletions sdk/web-pubsub/web-pubsub-express/.tshy/esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx"
],
"exclude": [],
"compilerOptions": {
"outDir": "../.tshy-build/esm"
}
}
4 changes: 2 additions & 2 deletions sdk/web-pubsub/web-pubsub-express/api-extractor.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "types/src/index.d.ts",
"mainEntryPointFilePath": "dist/esm/index.d.ts",
"docModel": {
"enabled": true
},
Expand All @@ -11,7 +11,7 @@
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./types/web-pubsub-express.d.ts"
"publicTrimmedFilePath": "./dist/web-pubsub-express.d.ts"
},
"messages": {
"tsdocMessageReporting": {
Expand Down
64 changes: 39 additions & 25 deletions sdk/web-pubsub/web-pubsub-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
"version": "1.0.6",
"description": "Azure Web PubSub CloudEvents handlers",
"sdk-type": "client",
"main": "dist/index.js",
"module": "dist-esm/src/index.js",
"types": "types/web-pubsub-express.d.ts",
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "echo \"Browser is not supported.\" && exit 0",
"build:node": "tsc -p . && dev-tool run bundle --browser-test=false",
"build:node": "tshy",
"build:samples": "echo Obsolete.",
"build:test": "tsc -p . && dev-tool run bundle --browser-test=false",
"build": "npm run clean && tsc -p . && dev-tool run bundle --browser-test=false && dev-tool run extract-api",
"build:test": "tshy",
"build": "npm run clean && tshy && dev-tool run bundle --browser-test=false && dev-tool run extract-api",
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf --glob dist dist-esm test-dist temp types *.tgz *.log",
"execute:samples": "dev-tool samples run samples-dev",
"extract-api": "tsc -p . && dev-tool run extract-api",
"extract-api": "tshy && dev-tool run extract-api",
"integration-test:browser": "echo \"Browser is not supported.\" && exit 0",
"integration-test:node": "echo skipped",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
Expand All @@ -28,14 +25,11 @@
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
"test": "npm run build:test && npm run unit-test && npm run integration-test",
"unit-test:browser": "echo \"Browser is not supported.\" && exit 0",
"unit-test:node": "dev-tool run test:node-ts-input --no-test-proxy",
"unit-test:node": "dev-tool run test:vitest --no-test-proxy",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
"files": [
"dist/",
"dist-esm/",
"types/web-pubsub-express.d.ts",
"types/web-pubsub-express.d.ts.map",
"README.md",
"LICENSE"
],
Expand All @@ -55,38 +49,58 @@
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-express/README.md",
"sideEffects": false,
"dependencies": {
"tslib": "^2.2.0",
"@azure/logger": "^1.0.0"
"@azure/logger": "^1.1.2",
"tslib": "^2.6.2"
},
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@microsoft/api-extractor": "^7.31.1",
"@types/chai": "^4.1.6",
"@types/express": "^4.16.0",
"@types/express-serve-static-core": "^4.17.19",
"@types/jsonwebtoken": "^9.0.0",
"@types/mocha": "^10.0.0",
"@types/node": "^18.0.0",
"@types/sinon": "^17.0.0",
"chai": "^4.2.0",
"cross-env": "^7.0.2",
"@vitest/browser": "^1.6.0",
"@vitest/coverage-istanbul": "^1.6.0",
"dotenv": "^16.0.0",
"eslint": "^8.0.0",
"express": "^4.16.3",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"puppeteer": "^22.2.0",
"rimraf": "^5.0.5",
"sinon": "^17.0.0",
"source-map-support": "^0.5.9",
"tshy": "^1.14.0",
"typescript": "~5.4.5",
"ts-node": "^10.0.0"
"vitest": "^1.6.0"
},
"//sampleConfiguration": {
"productName": "Azure Web PubSub CloudEvents Handlers for Express",
"productSlugs": [
"azure"
]
}
},
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
},
"dialects": [
"esm",
"commonjs"
],
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "dist/index.js",
"types": "./dist/commonjs/index.d.ts",
"type": "module"
}
4 changes: 2 additions & 2 deletions sdk/web-pubsub/web-pubsub-express/samples-dev/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// Licensed under the MIT license.

/**
* @summary Demonstrates handling Web PubSub CloudEvents with Express
Expand All @@ -21,7 +21,7 @@ const handler = new WebPubSubEventHandler("chat", {
console.log(connectedRequest);
},
handleUserEvent(req, res) {
var calledTime = req.context.states.calledTime++;
const calledTime = req.context.states.calledTime++;
console.log(calledTime);
// You can also set the state here
res.setState("calledTime", calledTime);
Expand Down
8 changes: 0 additions & 8 deletions sdk/web-pubsub/web-pubsub-express/samples-dev/tsconfig.json

This file was deleted.

12 changes: 6 additions & 6 deletions sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import * as utils from "./utils";
import { IncomingMessage, ServerResponse } from "http";
import { URL } from "url";
import { logger } from "./logger";
import * as utils from "./utils.js";
import { IncomingMessage, ServerResponse } from "node:http";
import { URL } from "node:url";
import { logger } from "./logger.js";

import {
import type {
ConnectRequest,
ConnectResponse,
ConnectedRequest,
Expand All @@ -16,7 +16,7 @@ import {
UserEventRequest,
UserEventResponseHandler,
WebPubSubEventHandlerOptions,
} from "./cloudEventsProtocols";
} from "./cloudEventsProtocols.js";

enum EventType {
Connect,
Expand Down
4 changes: 2 additions & 2 deletions sdk/web-pubsub/web-pubsub-express/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export { WebPubSubEventHandler } from "./webPubSubEventHandler";
export { WebPubSubEventHandler } from "./webPubSubEventHandler.js";

export * from "./cloudEventsProtocols";
export * from "./cloudEventsProtocols.js";
2 changes: 1 addition & 1 deletion sdk/web-pubsub/web-pubsub-express/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { IncomingMessage } from "http";
import { IncomingMessage } from "node:http";

function isJsonObject(obj: any): boolean {
return obj && typeof obj === "object" && !Array.isArray(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import express from "express-serve-static-core";

import { CloudEventsDispatcher } from "./cloudEventsDispatcher";
import { WebPubSubEventHandlerOptions } from "./cloudEventsProtocols";
import { CloudEventsDispatcher } from "./cloudEventsDispatcher.js";
import { WebPubSubEventHandlerOptions } from "./cloudEventsProtocols.js";

/**
* The handler to handle incoming CloudEvents messages
Expand Down
Loading

0 comments on commit 6cb2dd4

Please sign in to comment.