Skip to content

Commit

Permalink
fix: use both .d.cts and .d.mts extensions for all type files
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed May 30, 2022
1 parent fdb302a commit b513102
Show file tree
Hide file tree
Showing 14 changed files with 740 additions and 20 deletions.
7 changes: 7 additions & 0 deletions index.d.cts
@@ -0,0 +1,7 @@
import type {TestFn} from './types/test-fn.cjs';

/** Call to declare a test, or chain to declare hooks or test modifiers */
declare const test: TestFn;

/** Call to declare a test, or chain to declare hooks or test modifiers */
export = test;
12 changes: 12 additions & 0 deletions index.d.mts
@@ -0,0 +1,12 @@
import type {TestFn} from './types/test-fn.mjs';

export * from './types/assertions.mjs';
export * from './types/try-fn.mjs';
export * from './types/test-fn.mjs';
export * from './types/subscribable.mjs';

/** Call to declare a test, or chain to declare hooks or test modifiers */
declare const test: TestFn;

/** Call to declare a test, or chain to declare hooks or test modifiers */
export default test;
12 changes: 0 additions & 12 deletions index.d.ts

This file was deleted.

10 changes: 6 additions & 4 deletions package.json
Expand Up @@ -11,7 +11,7 @@
"exports": {
".": {
"import": {
"types": "./index.d.ts",
"types": "./index.d.mts",
"default": "./entrypoints/main.mjs"
},
"require": {
Expand All @@ -22,7 +22,7 @@
"./eslint-plugin-helper": "./entrypoints/eslint-plugin-helper.cjs",
"./plugin": {
"import": {
"types": "./plugin.d.ts",
"types": "./plugin.d.mts",
"default": "./entrypoints/plugin.mjs"
},
"require": {
Expand All @@ -43,8 +43,10 @@
"entrypoints",
"lib",
"types",
"index.d.ts",
"plugin.d.ts"
"index.d.cts",
"index.d.mts",
"plugin.d.cts",
"plugin.d.mts"
],
"keywords": [
"🦄",
Expand Down
File renamed without changes.
77 changes: 77 additions & 0 deletions plugin.d.mts
@@ -0,0 +1,77 @@
import {URL} from 'node:url';

export namespace SharedWorker {
export type ProtocolIdentifier = 'ava-4';

export type FactoryOptions = {
negotiateProtocol <Data = unknown>(supported: readonly ['ava-4']): Protocol<Data>;
// Add overloads for additional protocols.
};

export type Factory = (options: FactoryOptions) => void;

export type Protocol<Data = unknown> = {
readonly initialData: Data;
readonly protocol: 'ava-4';
broadcast: (data: Data) => BroadcastMessage<Data>;
ready: () => Protocol<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
testWorkers: () => AsyncIterableIterator<TestWorker<Data>>;
};

export type BroadcastMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};

export type PublishedMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};

export type ReceivedMessage<Data = unknown> = {
readonly data: Data;
readonly id: string;
readonly testWorker: TestWorker;
reply: (data: Data) => PublishedMessage<Data>;
};

export type TestWorker<Data = unknown> = {
readonly id: string;
readonly file: string;
publish: (data: Data) => PublishedMessage<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
teardown: (fn: (() => Promise<void>) | (() => void)) => () => Promise<void>;
};

export namespace Plugin {
export type RegistrationOptions<Identifier extends ProtocolIdentifier, Data = unknown> = {
readonly filename: string | URL;
readonly initialData?: Data;
readonly supportedProtocols: readonly Identifier[];
readonly teardown?: () => void;
};

export type Protocol<Data = unknown> = {
readonly available: Promise<void>;
readonly currentlyAvailable: boolean;
readonly protocol: 'ava-4';
publish: (data: Data) => PublishedMessage<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};

export type PublishedMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};

export type ReceivedMessage<Data = unknown> = {
readonly data: Data;
readonly id: string;
reply: (data: Data) => PublishedMessage<Data>;
};
}
}

export function registerSharedWorker<Data = unknown>(options: SharedWorker.Plugin.RegistrationOptions<'ava-4', Data>): SharedWorker.Plugin.Protocol<Data>;
// Add overloads for additional protocols.
File renamed without changes.

0 comments on commit b513102

Please sign in to comment.