Skip to content

Commit 05ba27f

Browse files
Johennesrichvdh
andauthored
Change imports for Node.js compatibility (#4377)
* Change imports for Node.js compatibility Fixes: #4287 Signed-off-by: Johannes Marbach <[email protected]> * Run prettier * Run prettier (again) * Add comment * Update babel.config.cjs --------- Signed-off-by: Johannes Marbach <[email protected]> Co-authored-by: Richard van der Hoff <[email protected]>
1 parent e6acfdf commit 05ba27f

File tree

192 files changed

+1445
-1387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+1445
-1387
lines changed

babel.config.cjs

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ module.exports = {
1414
modules: process.env.NODE_ENV === "test" ? "commonjs" : false,
1515
},
1616
],
17-
"@babel/preset-typescript",
17+
[
18+
"@babel/preset-typescript",
19+
{
20+
// When using the transpiled javascript in `lib`, Node.js requires `.js` extensions on any `import`
21+
// specifiers. However, Jest uses the TS source (via babel) and fails to resolve the `.js` names.
22+
// To resolve this,we use the `.ts` names in the source, and rewrite the `import` specifiers to use
23+
// `.js` during transpilation, *except* when we are targetting Jest.
24+
rewriteImportExtensions: process.env.NODE_ENV !== "test",
25+
},
26+
],
1827
],
1928
plugins: [
2029
"@babel/plugin-transform-numeric-separator",

src/@types/auth.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { UnstableValue } from "../NamespacedValue";
18-
import { IClientWellKnown } from "../client";
17+
import { UnstableValue } from "../NamespacedValue.ts";
18+
import { IClientWellKnown } from "../client.ts";
1919

2020
// disable lint because these are wire responses
2121
/* eslint-disable camelcase */

src/@types/beacon.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { RelatesToRelationship, REFERENCE_RELATION } from "./extensible_events";
18-
import { UnstableValue } from "../NamespacedValue";
19-
import { MAssetEvent, MLocationEvent, MTimestampEvent } from "./location";
17+
import { RelatesToRelationship, REFERENCE_RELATION } from "./extensible_events.ts";
18+
import { UnstableValue } from "../NamespacedValue.ts";
19+
import { MAssetEvent, MLocationEvent, MTimestampEvent } from "./location.ts";
2020

2121
/**
2222
* Beacon info and beacon event types as described in MSC3672

src/@types/crypto.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import type { ISignatures } from "./signed";
17+
import type { ISignatures } from "./signed.ts";
1818

1919
export type OlmGroupSessionExtraData = {
2020
untrusted?: boolean;
2121
sharedHistory?: boolean;
2222
};
2323

2424
// Backwards compatible re-export
25-
export type { EventDecryptionResult as IEventDecryptionResult } from "../common-crypto/CryptoBackend";
25+
export type { EventDecryptionResult as IEventDecryptionResult } from "../common-crypto/CryptoBackend.ts";
2626

2727
interface Extensible {
2828
[key: string]: any;

src/@types/event.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { NamespacedValue, UnstableValue } from "../NamespacedValue";
17+
import { NamespacedValue, UnstableValue } from "../NamespacedValue.ts";
1818
import {
1919
PolicyRuleEventContent,
2020
RoomAvatarEventContent,
@@ -34,16 +34,16 @@ import {
3434
RoomTopicEventContent,
3535
SpaceChildEventContent,
3636
SpaceParentEventContent,
37-
} from "./state_events";
37+
} from "./state_events.ts";
3838
import {
3939
ExperimentalGroupCallRoomMemberState,
4040
IGroupCallRoomMemberState,
4141
IGroupCallRoomState,
42-
} from "../webrtc/groupCall";
43-
import { MSC3089EventContent } from "../models/MSC3089Branch";
44-
import { M_BEACON, M_BEACON_INFO, MBeaconEventContent, MBeaconInfoEventContent } from "./beacon";
45-
import { XOR } from "./common";
46-
import { ReactionEventContent, RoomMessageEventContent, StickerEventContent } from "./events";
42+
} from "../webrtc/groupCall.ts";
43+
import { MSC3089EventContent } from "../models/MSC3089Branch.ts";
44+
import { M_BEACON, M_BEACON_INFO, MBeaconEventContent, MBeaconInfoEventContent } from "./beacon.ts";
45+
import { XOR } from "./common.ts";
46+
import { ReactionEventContent, RoomMessageEventContent, StickerEventContent } from "./events.ts";
4747
import {
4848
MCallAnswer,
4949
MCallBase,
@@ -54,10 +54,10 @@ import {
5454
MCallSelectAnswer,
5555
SDPStreamMetadata,
5656
SDPStreamMetadataKey,
57-
} from "../webrtc/callEventTypes";
58-
import { EncryptionKeysEventContent, ICallNotifyContent } from "../matrixrtc/types";
59-
import { M_POLL_END, M_POLL_START, PollEndEventContent, PollStartEventContent } from "./polls";
60-
import { SessionMembershipData } from "../matrixrtc/CallMembership";
57+
} from "../webrtc/callEventTypes.ts";
58+
import { EncryptionKeysEventContent, ICallNotifyContent } from "../matrixrtc/types.ts";
59+
import { M_POLL_END, M_POLL_START, PollEndEventContent, PollStartEventContent } from "./polls.ts";
60+
import { SessionMembershipData } from "../matrixrtc/CallMembership.ts";
6161

6262
export enum EventType {
6363
// Room state events

src/@types/events.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { MsgType, RelationType } from "./event";
18-
import { FileInfo, ImageInfo, MediaEventContent } from "./media";
19-
import { XOR } from "./common";
17+
import { MsgType, RelationType } from "./event.ts";
18+
import { FileInfo, ImageInfo, MediaEventContent } from "./media.ts";
19+
import { XOR } from "./common.ts";
2020

2121
interface BaseTimelineEvent {
2222
"body": string;

src/@types/extensible_events.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
import { EitherAnd, NamespacedValue, Optional, UnstableValue } from "matrix-events-sdk";
1818

19-
import { isProvided } from "../extensible_events_v1/utilities";
19+
import { isProvided } from "../extensible_events_v1/utilities.ts";
2020

2121
// Types and utilities for MSC1767: Extensible events (version 1) in Matrix
2222

src/@types/location.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ limitations under the License.
1717
// Types for MSC3488 - m.location: Extending events with location data
1818
import { EitherAnd } from "matrix-events-sdk";
1919

20-
import { UnstableValue } from "../NamespacedValue";
21-
import { M_TEXT } from "./extensible_events";
20+
import { UnstableValue } from "../NamespacedValue.ts";
21+
import { M_TEXT } from "./extensible_events.ts";
2222

2323
export enum LocationAssetType {
2424
Self = "m.self",

src/@types/media.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { MsgType } from "../@types/event";
17+
import { MsgType } from "../@types/event.ts";
1818

1919
/**
2020
* Information on encrypted media attachments.

src/@types/polls.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
REFERENCE_RELATION,
2222
RelatesToRelationship,
2323
TSNamespace,
24-
} from "./extensible_events";
24+
} from "./extensible_events.ts";
2525

2626
/**
2727
* Identifier for a disclosed poll.

src/@types/registration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { AuthDict } from "../interactive-auth";
17+
import { AuthDict } from "../interactive-auth.ts";
1818

1919
/**
2020
* The request body of a call to `POST /_matrix/client/v3/register`.

src/@types/requests.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { IContent, IEvent } from "../models/event";
18-
import { Preset, Visibility } from "./partials";
19-
import { IEventWithRoomId, SearchKey } from "./search";
20-
import { IRoomEventFilter } from "../filter";
21-
import { Direction } from "../models/event-timeline";
22-
import { PushRuleAction } from "./PushRules";
23-
import { IRoomEvent } from "../sync-accumulator";
24-
import { EventType, RelationType, RoomType } from "./event";
17+
import { IContent, IEvent } from "../models/event.ts";
18+
import { Preset, Visibility } from "./partials.ts";
19+
import { IEventWithRoomId, SearchKey } from "./search.ts";
20+
import { IRoomEventFilter } from "../filter.ts";
21+
import { Direction } from "../models/event-timeline.ts";
22+
import { PushRuleAction } from "./PushRules.ts";
23+
import { IRoomEvent } from "../sync-accumulator.ts";
24+
import { EventType, RelationType, RoomType } from "./event.ts";
2525

2626
// allow camelcase as these are things that go onto the wire
2727
/* eslint-disable camelcase */

src/@types/search.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ limitations under the License.
1616

1717
// Types relating to the /search API
1818

19-
import { IRoomEvent, IStateEvent } from "../sync-accumulator";
20-
import { IRoomEventFilter } from "../filter";
21-
import { SearchResult } from "../models/search-result";
19+
import { IRoomEvent, IStateEvent } from "../sync-accumulator.ts";
20+
import { IRoomEventFilter } from "../filter.ts";
21+
import { SearchResult } from "../models/search-result.ts";
2222

2323
/* eslint-disable camelcase */
2424
export interface IEventWithRoomId extends IRoomEvent {

src/@types/spaces.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { IPublicRoomsChunkRoom } from "../client";
18-
import { RoomType } from "./event";
19-
import { IStrippedState } from "../sync-accumulator";
17+
import { IPublicRoomsChunkRoom } from "../client.ts";
18+
import { RoomType } from "./event.ts";
19+
import { IStrippedState } from "../sync-accumulator.ts";
2020

2121
// Types relating to Rooms of type `m.space` and related APIs
2222

src/@types/state_events.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { RoomType } from "./event";
18-
import { GuestAccess, HistoryVisibility, JoinRule, RestrictedAllowType } from "./partials";
19-
import { ImageInfo } from "./media";
20-
import { PolicyRecommendation } from "../models/invites-ignorer";
17+
import { RoomType } from "./event.ts";
18+
import { GuestAccess, HistoryVisibility, JoinRule, RestrictedAllowType } from "./partials.ts";
19+
import { ImageInfo } from "./media.ts";
20+
import { PolicyRecommendation } from "../models/invites-ignorer.ts";
2121

2222
export interface RoomCanonicalAliasEventContent {
2323
alias?: string;

src/@types/synapse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { IdServerUnbindResult } from "./partials";
17+
import { IdServerUnbindResult } from "./partials.ts";
1818

1919
// Types relating to Synapse Admin APIs
2020

src/@types/sync.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { ServerControlledNamespacedValue } from "../NamespacedValue";
17+
import { ServerControlledNamespacedValue } from "../NamespacedValue.ts";
1818

1919
/**
2020
* https://github.com/matrix-org/matrix-doc/pull/3773

src/@types/topic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ limitations under the License.
1616

1717
import { EitherAnd } from "matrix-events-sdk";
1818

19-
import { UnstableValue } from "../NamespacedValue";
20-
import { IMessageRendering } from "./extensible_events";
19+
import { UnstableValue } from "../NamespacedValue.ts";
20+
import { IMessageRendering } from "./extensible_events.ts";
2121

2222
/**
2323
* Extensible topic event type based on MSC3765

src/@types/uia.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { AuthDict, IAuthData } from "../interactive-auth";
17+
import { AuthDict, IAuthData } from "../interactive-auth.ts";
1818

1919
/**
2020
* Helper type to represent HTTP request body for a UIA enabled endpoint

src/ReEmitter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
// eslint-disable-next-line no-restricted-imports
2020
import { EventEmitter } from "events";
2121

22-
import { ListenerMap, TypedEventEmitter } from "./models/typed-event-emitter";
22+
import { ListenerMap, TypedEventEmitter } from "./models/typed-event-emitter.ts";
2323

2424
export class ReEmitter {
2525
public constructor(private readonly target: EventEmitter) {}

src/ToDeviceMessageQueue.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { ToDeviceMessageId } from "./@types/event";
18-
import { logger } from "./logger";
19-
import { MatrixClient, ClientEvent } from "./client";
20-
import { MatrixError } from "./http-api";
21-
import { IndexedToDeviceBatch, ToDeviceBatch, ToDeviceBatchWithTxnId, ToDevicePayload } from "./models/ToDeviceMessage";
22-
import { MatrixScheduler } from "./scheduler";
23-
import { SyncState } from "./sync";
24-
import { MapWithDefault } from "./utils";
17+
import { ToDeviceMessageId } from "./@types/event.ts";
18+
import { logger } from "./logger.ts";
19+
import { MatrixClient, ClientEvent } from "./client.ts";
20+
import { MatrixError } from "./http-api/index.ts";
21+
import {
22+
IndexedToDeviceBatch,
23+
ToDeviceBatch,
24+
ToDeviceBatchWithTxnId,
25+
ToDevicePayload,
26+
} from "./models/ToDeviceMessage.ts";
27+
import { MatrixScheduler } from "./scheduler.ts";
28+
import { SyncState } from "./sync.ts";
29+
import { MapWithDefault } from "./utils.ts";
2530

2631
const MAX_BATCH_SIZE = 20;
2732

src/autodiscovery.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
import { IClientWellKnown, IWellKnownConfig, IServerVersions } from "./client";
19-
import { logger } from "./logger";
20-
import { MatrixError, Method, timeoutSignal } from "./http-api";
21-
import { SUPPORTED_MATRIX_VERSIONS } from "./version-support";
18+
import { IClientWellKnown, IWellKnownConfig, IServerVersions } from "./client.ts";
19+
import { logger } from "./logger.ts";
20+
import { MatrixError, Method, timeoutSignal } from "./http-api/index.ts";
21+
import { SUPPORTED_MATRIX_VERSIONS } from "./version-support.ts";
2222

2323
// Dev note: Auto discovery is part of the spec.
2424
// See: https://matrix.org/docs/spec/client_server/r0.4.0.html#server-discovery

src/browser-index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import * as matrixcs from "./matrix";
17+
import * as matrixcs from "./matrix.ts";
1818

1919
type BrowserMatrix = typeof matrixcs;
2020
declare global {
@@ -40,5 +40,5 @@ if (indexedDB) {
4040
matrixcs.setCryptoStoreFactory(() => new matrixcs.IndexedDBCryptoStore(indexedDB!, "matrix-js-sdk:crypto"));
4141
}
4242

43-
export * from "./matrix";
43+
export * from "./matrix.ts";
4444
globalThis.matrixcs = matrixcs;

0 commit comments

Comments
 (0)