Skip to content

Commit 6093a62

Browse files
authored
Fix exports types for esm (#302)
* fix exports types * simplify npm-publish workflow * add file extensions to index.ts to fix esm imports * remove unneeded tsconfig options * use esm in jest * lint * fix for windows env by not providing cli flag
1 parent a7ea7a8 commit 6093a62

File tree

8 files changed

+35
-37
lines changed

8 files changed

+35
-37
lines changed

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,11 @@ name: Node.js Package
55

66
on:
77
release:
8-
types: [created]
8+
types: [published]
99

1010
jobs:
11-
build:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v3
15-
- uses: actions/setup-node@v3
16-
with:
17-
node-version-file: .nvmrc
18-
- run: npm ci
19-
- run: npm test
20-
- run: npm run build
21-
2211
publish-npm:
23-
needs: build
2412
runs-on: ubuntu-latest
25-
2613
steps:
2714
- uses: actions/checkout@v3
2815
- uses: actions/setup-node@v3
@@ -31,6 +18,7 @@ jobs:
3118
registry-url: https://registry.npmjs.org/
3219
- run: npm ci
3320
- run: npm run build
21+
- run: npm test
3422
- run: npm publish
3523
env:
3624
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

jest.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ const config: Config.InitialOptions = {
77
displayName: pack.name,
88
id: pack.name,
99
modulePaths: ['<rootDir>/src'],
10-
preset: 'ts-jest',
11-
testEnvironment: 'jsdom'
10+
preset: 'ts-jest/presets/default-esm',
11+
extensionsToTreatAsEsm: ['.ts'],
12+
testEnvironment: 'jsdom',
13+
moduleNameMapper: {
14+
'^(\\.{1,2}/.*)\\.js$': '$1'
15+
}
1216
};
1317

1418
export default config;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"type": "module",
1313
"exports": {
1414
"require": "./dist/index.cjs",
15-
"default": "./dist/index.modern.js"
15+
"default": "./dist/index.modern.js",
16+
"types": "./dist/index.d.ts"
1617
},
1718
"main": "./dist/index.cjs",
1819
"module": "./dist/index.module.js",

src/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Socket, Channel } from 'phoenix';
2-
import { collectionTopic } from './helpers';
2+
import { collectionTopic } from './helpers.js';
33
import {
44
ClientConfig,
55
BaseStreamMessage,
@@ -18,8 +18,8 @@ import {
1818
Network,
1919
OnClientEvent,
2020
OrderValidationEvent
21-
} from './types';
22-
import { ENDPOINTS } from './constants';
21+
} from './types.js';
22+
import { ENDPOINTS } from './constants.js';
2323

2424
export class OpenSeaStreamClient {
2525
private socket: Socket;

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Network } from './types';
1+
import { Network } from './types.js';
22

33
export const ENDPOINTS = {
44
[Network.MAINNET]: 'wss://stream.openseabeta.com/socket',

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './client';
2-
export * from './types';
1+
export * from './client.js';
2+
export * from './types.js';

tests/client.spec.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { EventType, LogLevel, OpenSeaStreamClient } from '../src';
2-
import WS from 'jest-websocket-mock';
3-
import { getSocket, getChannels, encode, mockEvent } from './helpers';
4-
import { collectionTopic } from '../src/helpers';
1+
import { jest } from '@jest/globals';
2+
import { WS } from 'jest-websocket-mock';
3+
import { getSocket, getChannels, encode, mockEvent } from './helpers.js';
4+
import {
5+
EventType,
6+
LogLevel,
7+
OnClientEvent,
8+
OpenSeaStreamClient
9+
} from '../src/index.js';
10+
import { collectionTopic } from '../src/helpers.js';
511

612
let server: WS;
713
let streamClient: OpenSeaStreamClient;
@@ -131,7 +137,9 @@ describe('middleware', () => {
131137
test('single', () => {
132138
const collectionSlug = 'c1';
133139

134-
const onClientEvent = jest.fn().mockImplementation(() => true);
140+
const onClientEvent = jest
141+
.fn()
142+
.mockImplementation(() => true) as OnClientEvent;
135143

136144
streamClient = new OpenSeaStreamClient({
137145
...clientOpts,
@@ -194,11 +202,10 @@ describe('middleware', () => {
194202
test('filter out events', () => {
195203
const collectionSlug = 'c1';
196204

197-
const onClientEvent = jest
198-
.fn()
199-
.mockImplementation(
200-
(_c, _e, event) => event.payload.chain === 'ethereum'
201-
);
205+
const onClientEvent = jest.fn().mockImplementation(
206+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
207+
(_c, _e, event: any) => event.payload.chain.name === 'ethereum'
208+
) as OnClientEvent;
202209

203210
streamClient = new OpenSeaStreamClient({
204211
...clientOpts,
@@ -214,10 +221,10 @@ describe('middleware', () => {
214221
const onEvent = jest.fn();
215222

216223
const ethereumListing = mockEvent(EventType.ITEM_LISTED, {
217-
chain: 'ethereum'
224+
chain: { name: 'ethereum' }
218225
});
219226
const polygonListing = mockEvent(EventType.ITEM_LISTED, {
220-
chain: 'polygon'
227+
chain: { name: 'polygon' }
221228
});
222229

223230
streamClient.onEvents(

tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"outDir": "./dist",
88
"strict": true,
99
"declaration": true,
10-
"allowSyntheticDefaultImports": true,
1110
"forceConsistentCasingInFileNames": true,
12-
"esModuleInterop": true,
1311
"resolveJsonModule": true,
1412
"baseUrl": "."
1513
}

0 commit comments

Comments
 (0)