Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #80 from ably-labs/fix-imports
Browse files Browse the repository at this point in the history
fix: use fully qualified imports with `.js` extension for ESM build
  • Loading branch information
stmoreau authored Aug 18, 2023
2 parents 17e083c + ec82536 commit c589f46
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 57 deletions.
23 changes: 19 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,30 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "react", "react-hooks"],
"plugins": ["@typescript-eslint", "react", "react-hooks", "import"],
"rules": {
// we should remove these at some point
"@typescript-eslint/no-explicit-any": 0,
"prefer-spread": 0
"@typescript-eslint/no-explicit-any": 0
},
"settings": {
"react": {
"version": "detect"
}
}
},
"overrides": [
{
"files": ["**/*.{ts,tsx}"],
"rules": {
// see:
// https://github.com/microsoft/TypeScript/issues/16577#issuecomment-703190339
"import/extensions": [
"error",
"always",
{
"ignorePackages": true
}
]
}
}
]
}
302 changes: 282 additions & 20 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
"devDependencies": {
"@testing-library/react": "^13.3.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"@typescript-eslint/parser": "^6.4.0",
"@vitejs/plugin-react": "^1.3.2",
"eslint": "^8.45.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"jsdom": "^20.0.0",
Expand Down
9 changes: 3 additions & 6 deletions sample-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Types } from 'ably';
import React, { useState } from 'react';
import {
AblyProvider,
useChannel,
usePresence,
useConnectionStateListener,
useChannelStateListener,
useAbly,
} from '../../src/index';
} from '../../src/index.js';
import './App.css';

function App() {
Expand All @@ -24,9 +23,7 @@ function App() {
}
);

const [connectionState, setConnectionState] = useState(
ably.connection.state
);
const [, setConnectionState] = useState(ably.connection.state);

useConnectionStateListener((stateChange) => {
setConnectionState(stateChange.current);
Expand Down Expand Up @@ -82,7 +79,7 @@ function App() {
<div style={{ position: 'fixed', width: '250px' }}>
<ConnectionState />
</div>
<div style={{marginLeft: '250px'}}>
<div style={{ marginLeft: '250px' }}>
<h2>Channel detach</h2>
<button onClick={() => channel.detach()}>Detach</button>
<button onClick={() => ably.close()}>Close</button>
Expand Down
4 changes: 2 additions & 2 deletions sample-app/src/script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import * as Ably from 'ably';

import App from './App';
import { AblyProvider } from '../../src/index';
import App from './App.js';
import { AblyProvider } from '../../src/index.js';

const container = document.getElementById('root')!;

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAbly.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Types } from 'ably';
import React from 'react';
import { getContext } from '../AblyProvider';
import { getContext } from '../AblyProvider.js';

export function useAbly(id: string = 'default'): Types.RealtimePromise {
const client = React.useContext(getContext(id)) as Types.RealtimePromise;
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useChannel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useEffect, useState } from 'react';
import { it, beforeEach, describe, expect, vi } from 'vitest';
import { useChannel } from './useChannel';
import { useChannel } from './useChannel.js';
import { render, screen, waitFor } from '@testing-library/react';
import { FakeAblySdk, FakeAblyChannels } from '../fakes/ably';
import { FakeAblySdk, FakeAblyChannels } from '../fakes/ably.js';
import { Types } from 'ably';
import { act } from 'react-dom/test-utils';
import { AblyProvider } from '../AblyProvider';
import { AblyProvider } from '../AblyProvider.js';

function renderInCtxProvider(
client: FakeAblySdk,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useChannel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Types } from 'ably';
import { useEffect, useMemo, useRef } from 'react';
import { ChannelParameters } from '../AblyReactHooks.js';
import { useAbly } from './useAbly';
import { useStateErrors } from './useStateErrors';
import { useAbly } from './useAbly.js';
import { useStateErrors } from './useStateErrors.js';

export type AblyMessageCallback = Types.messageCallback<Types.Message>;

Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useChannelStateListener.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { it, beforeEach, describe, expect } from 'vitest';
import { useChannelStateListener } from './useChannelStateListener';
import { useChannelStateListener } from './useChannelStateListener.js';
import { useState } from 'react';
import { render, screen } from '@testing-library/react';
import { FakeAblySdk, FakeAblyChannels } from '../fakes/ably';
import { FakeAblySdk, FakeAblyChannels } from '../fakes/ably.js';
import { Types } from 'ably';
import { act } from 'react-dom/test-utils';
import { AblyProvider } from '../AblyProvider';
import { AblyProvider } from '../AblyProvider.js';

function renderInCtxProvider(
client: FakeAblySdk,
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useChannelStateListener.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Types } from 'ably';
import { ChannelNameAndId } from '../AblyReactHooks';
import { useAbly } from './useAbly';
import { useEventListener } from './useEventListener';
import { ChannelNameAndId } from '../AblyReactHooks.js';
import { useAbly } from './useAbly.js';
import { useEventListener } from './useEventListener.js';

type ChannelStateListener = (stateChange: Types.ChannelStateChange) => any;

Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useConnectionStateListener.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import { it, beforeEach, describe, expect } from 'vitest';
import { useState } from 'react';
import { render, screen } from '@testing-library/react';
import { FakeAblySdk } from '../fakes/ably';
import { FakeAblySdk } from '../fakes/ably.js';
import { Types } from 'ably';
import { act } from 'react-dom/test-utils';
import { AblyProvider } from '../AblyProvider';
import { useConnectionStateListener } from './useConnectionStateListener';
import { AblyProvider } from '../AblyProvider.js';
import { useConnectionStateListener } from './useConnectionStateListener.js';

function renderInCtxProvider(
client: FakeAblySdk,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useConnectionStateListener.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Types } from 'ably';
import { useAbly } from './useAbly';
import { useEventListener } from './useEventListener';
import { useAbly } from './useAbly.js';
import { useEventListener } from './useEventListener.js';

type ConnectionStateListener = (
stateChange: Types.ConnectionStateChange
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/usePresence.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { it, beforeEach, describe, expect, vi } from 'vitest';
import { usePresence } from './usePresence';
import { usePresence } from './usePresence.js';
import { render, screen, act } from '@testing-library/react';
import { FakeAblySdk, FakeAblyChannels } from '../fakes/ably';
import { AblyProvider } from '../AblyProvider';
import { FakeAblySdk, FakeAblyChannels } from '../fakes/ably.js';
import { AblyProvider } from '../AblyProvider.js';
import { Types } from 'ably';

function renderInCtxProvider(
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Types } from 'ably';
import { useCallback, useEffect, useState } from 'react';
import { ChannelParameters } from '../AblyReactHooks.js';
import { useAbly } from './useAbly.js';
import { useStateErrors } from './useStateErrors';
import { useStateErrors } from './useStateErrors.js';

export interface PresenceResult<T> {
presenceData: PresenceMessage<T>[];
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useStateErrors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Types } from 'ably';
import { useState } from 'react';
import { useConnectionStateListener } from './useConnectionStateListener';
import { useChannelStateListener } from './useChannelStateListener';
import { ChannelNameAndOptions } from '../AblyReactHooks';
import { useConnectionStateListener } from './useConnectionStateListener.js';
import { useChannelStateListener } from './useChannelStateListener.js';
import { ChannelNameAndOptions } from '../AblyReactHooks.js';

export function useStateErrors(params: ChannelNameAndOptions) {
const [connectionError, setConnectionError] =
Expand Down

0 comments on commit c589f46

Please sign in to comment.