Skip to content

Commit

Permalink
[WS-2008] Bundle with tsup to support CJS + ESM (#41)
Browse files Browse the repository at this point in the history
* base tsup setup

* fix exports field

* bump version to 0.10.1
  • Loading branch information
jackyzha0 authored Dec 15, 2023
1 parent c79bb70 commit 192f4f2
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 31 deletions.
40 changes: 26 additions & 14 deletions package-lock.json

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

54 changes: 41 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
{
"name": "@replit/river",
"sideEffects": false,
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
"version": "0.10.0",
"version": "0.10.1",
"type": "module",
"exports": {
".": "./dist/router/index.js",
"./logging": "./dist/logging/index.js",
"./codec": "./dist/codec/index.js",
"./test-util": "./dist/util/testHelpers.js",
"./transport": "./dist/transport/index.js",
"./transport/ws/client": "./dist/transport/impls/ws/client.js",
"./transport/ws/server": "./dist/transport/impls/ws/server.js",
"./transport/stdio": "./dist/transport/impls/stdio/stdio.js"
".": {
"import": "./dist/router/index.js",
"require": "./dist/router/index.cjs"
},
"./logging": {
"import": "./dist/logging/index.js",
"require": "./dist/logging/index.cjs"
},
"./codec": {
"import": "./dist/codec/index.js",
"require": "./dist/codec/index.cjs"
},
"./transport": {
"import": "./dist/transport/index.js",
"require": "./dist/transport/index.cjs"
},
"./transport/ws/client": {
"import": "./dist/transport/impls/ws/client.js",
"require": "./dist/transport/impls/ws/client.cjs"
},
"./transport/ws/server": {
"import": "./dist/transport/impls/ws/server.js",
"require": "./dist/transport/impls/ws/server.cjs"
},
"./transport/stdio": {
"import": "./dist/transport/impls/stdio/stdio.js",
"require": "./dist/transport/impls/stdio/stdio.cjs"
},
"./test-util": {
"import": "./dist/util/testHelpers.js",
"require": "./dist/util/testHelpers.cjs"
}
},
"sideEffects": [
"./dist/logging/index.js"
],
"files": [
"dist"
],
"dependencies": {
"@msgpack/msgpack": "^3.0.0-beta2",
"@sinclair/typebox": "^0.31.8",
"nanoid": "^4.0.2"
},
"peerDependencies": {
"@sinclair/typebox": "^0.31.28",
"isomorphic-ws": "^5.0.0",
"it-pushable": "^3.2.1",
"nanoid": "^4.0.2",
"ws": "^8.13.0"
},
"devDependencies": {
Expand All @@ -36,7 +64,7 @@
"scripts": {
"check": "tsc --noEmit && npx prettier . --check",
"format": "npx prettier . --write",
"build": "rm -rf ./dist && tsc",
"build": "tsup && du -sh dist",
"prepack": "npm run build",
"release": "npm publish --access public",
"test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
Expand Down
6 changes: 3 additions & 3 deletions transport/impls/ws/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Codec, NaiveJsonCodec } from '../../../codec';
import { log } from '../../../logging';
import { TransportClientId } from '../../message';
import { Transport } from '../../transport';
import { Server } from 'ws';
import { WebSocketServer } from 'ws';
import { WebSocket } from 'isomorphic-ws';
import { WebSocketConnection } from './connection';

Expand All @@ -15,11 +15,11 @@ const defaultOptions: Options = {
};

export class WebSocketServerTransport extends Transport<WebSocketConnection> {
wss: Server;
wss: WebSocketServer;
clientId: TransportClientId;

constructor(
wss: Server,
wss: WebSocketServer,
clientId: TransportClientId,
providedOptions?: Partial<Options>,
) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"resolveJsonModule": true,
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"moduleResolution": "bundler" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
Expand Down
18 changes: 18 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: [
'router/index.ts',
'logging/index.ts',
'codec/index.ts',
'util/testHelpers.ts',
'transport/index.ts',
'transport/impls/ws/client.ts',
'transport/impls/ws/server.ts',
'transport/stdio.ts',
],
format: ['esm', 'cjs'],
sourcemap: false,
clean: true,
dts: true,
});

0 comments on commit 192f4f2

Please sign in to comment.