Skip to content

Commit

Permalink
Fix exports types for esm (#302)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ryanio authored Aug 14, 2023
1 parent a7ea7a8 commit 6093a62
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 37 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,11 @@ name: Node.js Package

on:
release:
types: [created]
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
- run: npm ci
- run: npm test
- run: npm run build

publish-npm:
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -31,6 +18,7 @@ jobs:
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
- run: npm test
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
8 changes: 6 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ const config: Config.InitialOptions = {
displayName: pack.name,
id: pack.name,
modulePaths: ['<rootDir>/src'],
preset: 'ts-jest',
testEnvironment: 'jsdom'
preset: 'ts-jest/presets/default-esm',
extensionsToTreatAsEsm: ['.ts'],
testEnvironment: 'jsdom',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1'
}
};

export default config;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"type": "module",
"exports": {
"require": "./dist/index.cjs",
"default": "./dist/index.modern.js"
"default": "./dist/index.modern.js",
"types": "./dist/index.d.ts"
},
"main": "./dist/index.cjs",
"module": "./dist/index.module.js",
Expand Down
6 changes: 3 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Socket, Channel } from 'phoenix';
import { collectionTopic } from './helpers';
import { collectionTopic } from './helpers.js';
import {
ClientConfig,
BaseStreamMessage,
Expand All @@ -18,8 +18,8 @@ import {
Network,
OnClientEvent,
OrderValidationEvent
} from './types';
import { ENDPOINTS } from './constants';
} from './types.js';
import { ENDPOINTS } from './constants.js';

export class OpenSeaStreamClient {
private socket: Socket;
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Network } from './types';
import { Network } from './types.js';

export const ENDPOINTS = {
[Network.MAINNET]: 'wss://stream.openseabeta.com/socket',
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './client';
export * from './types';
export * from './client.js';
export * from './types.js';
31 changes: 19 additions & 12 deletions tests/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { EventType, LogLevel, OpenSeaStreamClient } from '../src';
import WS from 'jest-websocket-mock';
import { getSocket, getChannels, encode, mockEvent } from './helpers';
import { collectionTopic } from '../src/helpers';
import { jest } from '@jest/globals';
import { WS } from 'jest-websocket-mock';
import { getSocket, getChannels, encode, mockEvent } from './helpers.js';
import {
EventType,
LogLevel,
OnClientEvent,
OpenSeaStreamClient
} from '../src/index.js';
import { collectionTopic } from '../src/helpers.js';

let server: WS;
let streamClient: OpenSeaStreamClient;
Expand Down Expand Up @@ -131,7 +137,9 @@ describe('middleware', () => {
test('single', () => {
const collectionSlug = 'c1';

const onClientEvent = jest.fn().mockImplementation(() => true);
const onClientEvent = jest
.fn()
.mockImplementation(() => true) as OnClientEvent;

streamClient = new OpenSeaStreamClient({
...clientOpts,
Expand Down Expand Up @@ -194,11 +202,10 @@ describe('middleware', () => {
test('filter out events', () => {
const collectionSlug = 'c1';

const onClientEvent = jest
.fn()
.mockImplementation(
(_c, _e, event) => event.payload.chain === 'ethereum'
);
const onClientEvent = jest.fn().mockImplementation(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(_c, _e, event: any) => event.payload.chain.name === 'ethereum'
) as OnClientEvent;

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

const ethereumListing = mockEvent(EventType.ITEM_LISTED, {
chain: 'ethereum'
chain: { name: 'ethereum' }
});
const polygonListing = mockEvent(EventType.ITEM_LISTED, {
chain: 'polygon'
chain: { name: 'polygon' }
});

streamClient.onEvents(
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"outDir": "./dist",
"strict": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"baseUrl": "."
}
Expand Down

0 comments on commit 6093a62

Please sign in to comment.