diff --git a/entrypoints/main.d.cts b/entrypoints/main.d.cts index 94d834ba..d4fcdc16 100644 --- a/entrypoints/main.d.cts +++ b/entrypoints/main.d.cts @@ -1,2 +1,12 @@ -export {default} from './main.js'; -export * from './main.js'; +import type {TestFn} from '../types/test-fn.cjs'; + +export * from '../types/assertions.cjs'; +export * from '../types/try-fn.cjs'; +export * from '../types/test-fn.cjs'; +export * from '../types/subscribable.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 default test; diff --git a/entrypoints/main.d.ts b/entrypoints/main.d.ts index f12fc65b..6120bb89 100644 --- a/entrypoints/main.d.ts +++ b/entrypoints/main.d.ts @@ -1,12 +1,2 @@ -import type {TestFn} from '../types/test-fn.js'; - -export * from '../types/assertions.js'; -export * from '../types/try-fn.js'; -export * from '../types/test-fn.js'; -export * from '../types/subscribable.js'; - -/** 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; +export * from './main.cjs'; +export {default} from './main.cjs'; diff --git a/entrypoints/plugin.d.cts b/entrypoints/plugin.d.cts index 83723514..24319ce2 100644 --- a/entrypoints/plugin.d.cts +++ b/entrypoints/plugin.d.cts @@ -1 +1,77 @@ -export * from './plugin.js' +import type {URL} from 'node:url'; + +export namespace SharedWorker { + export type ProtocolIdentifier = 'ava-4'; + + export type FactoryOptions = { + negotiateProtocol (supported: readonly ['ava-4']): Protocol; + // Add overloads for additional protocols. + }; + + export type Factory = (options: FactoryOptions) => void; + + export type Protocol = { + readonly initialData: Data; + readonly protocol: 'ava-4'; + broadcast: (data: Data) => BroadcastMessage; + ready: () => Protocol; + subscribe: () => AsyncIterableIterator>; + testWorkers: () => AsyncIterableIterator>; + }; + + export type BroadcastMessage = { + readonly id: string; + replies: () => AsyncIterableIterator>; + }; + + export type PublishedMessage = { + readonly id: string; + replies: () => AsyncIterableIterator>; + }; + + export type ReceivedMessage = { + readonly data: Data; + readonly id: string; + readonly testWorker: TestWorker; + reply: (data: Data) => PublishedMessage; + }; + + export type TestWorker = { + readonly id: string; + readonly file: string; + publish: (data: Data) => PublishedMessage; + subscribe: () => AsyncIterableIterator>; + teardown: (fn: (() => Promise) | (() => void)) => () => Promise; + }; + + export namespace Plugin { + export type RegistrationOptions = { + readonly filename: string | URL; + readonly initialData?: Data; + readonly supportedProtocols: readonly Identifier[]; + readonly teardown?: () => void; + }; + + export type Protocol = { + readonly available: Promise; + readonly currentlyAvailable: boolean; + readonly protocol: 'ava-4'; + publish: (data: Data) => PublishedMessage; + subscribe: () => AsyncIterableIterator>; + }; + + export type PublishedMessage = { + readonly id: string; + replies: () => AsyncIterableIterator>; + }; + + export type ReceivedMessage = { + readonly data: Data; + readonly id: string; + reply: (data: Data) => PublishedMessage; + }; + } +} + +export function registerSharedWorker(options: SharedWorker.Plugin.RegistrationOptions<'ava-4', Data>): SharedWorker.Plugin.Protocol; +// Add overloads for additional protocols. diff --git a/entrypoints/plugin.d.ts b/entrypoints/plugin.d.ts index 24319ce2..e84a6643 100644 --- a/entrypoints/plugin.d.ts +++ b/entrypoints/plugin.d.ts @@ -1,77 +1 @@ -import type {URL} from 'node:url'; - -export namespace SharedWorker { - export type ProtocolIdentifier = 'ava-4'; - - export type FactoryOptions = { - negotiateProtocol (supported: readonly ['ava-4']): Protocol; - // Add overloads for additional protocols. - }; - - export type Factory = (options: FactoryOptions) => void; - - export type Protocol = { - readonly initialData: Data; - readonly protocol: 'ava-4'; - broadcast: (data: Data) => BroadcastMessage; - ready: () => Protocol; - subscribe: () => AsyncIterableIterator>; - testWorkers: () => AsyncIterableIterator>; - }; - - export type BroadcastMessage = { - readonly id: string; - replies: () => AsyncIterableIterator>; - }; - - export type PublishedMessage = { - readonly id: string; - replies: () => AsyncIterableIterator>; - }; - - export type ReceivedMessage = { - readonly data: Data; - readonly id: string; - readonly testWorker: TestWorker; - reply: (data: Data) => PublishedMessage; - }; - - export type TestWorker = { - readonly id: string; - readonly file: string; - publish: (data: Data) => PublishedMessage; - subscribe: () => AsyncIterableIterator>; - teardown: (fn: (() => Promise) | (() => void)) => () => Promise; - }; - - export namespace Plugin { - export type RegistrationOptions = { - readonly filename: string | URL; - readonly initialData?: Data; - readonly supportedProtocols: readonly Identifier[]; - readonly teardown?: () => void; - }; - - export type Protocol = { - readonly available: Promise; - readonly currentlyAvailable: boolean; - readonly protocol: 'ava-4'; - publish: (data: Data) => PublishedMessage; - subscribe: () => AsyncIterableIterator>; - }; - - export type PublishedMessage = { - readonly id: string; - replies: () => AsyncIterableIterator>; - }; - - export type ReceivedMessage = { - readonly data: Data; - readonly id: string; - reply: (data: Data) => PublishedMessage; - }; - } -} - -export function registerSharedWorker(options: SharedWorker.Plugin.RegistrationOptions<'ava-4', Data>): SharedWorker.Plugin.Protocol; -// Add overloads for additional protocols. +export type * from './plugin.cjs'; diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..66c0e85d --- /dev/null +++ b/index.d.ts @@ -0,0 +1,4 @@ +// For compatibility with resolution algorithms other than Node16. + +export * from './entrypoints/main.cjs'; +export {default} from './entrypoints/main.cjs'; diff --git a/package.json b/package.json index 5f40bd5d..eea1e896 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "files": [ "entrypoints", "lib", - "types" + "types", + "*.d.ts" ], "keywords": [ "🦄", diff --git a/plugin.d.ts b/plugin.d.ts new file mode 100644 index 00000000..a1524f2c --- /dev/null +++ b/plugin.d.ts @@ -0,0 +1,3 @@ +// For compatibility with resolution algorithms other than Node16. + +export * from './entrypoints/plugin.cjs'; diff --git a/types/assertions.d.ts b/types/assertions.d.cts similarity index 100% rename from types/assertions.d.ts rename to types/assertions.d.cts diff --git a/types/subscribable.d.ts b/types/subscribable.d.cts similarity index 100% rename from types/subscribable.d.ts rename to types/subscribable.d.cts diff --git a/types/test-fn.d.ts b/types/test-fn.d.cts similarity index 98% rename from types/test-fn.d.ts rename to types/test-fn.d.cts index f58a5d2c..8eb16785 100644 --- a/types/test-fn.d.ts +++ b/types/test-fn.d.cts @@ -1,6 +1,6 @@ -import type {Assertions} from './assertions.js'; -import type {Subscribable} from './subscribable.js'; -import type {TryFn} from './try-fn.js'; +import type {Assertions} from './assertions.cjs'; +import type {Subscribable} from './subscribable.cjs'; +import type {TryFn} from './try-fn.cjs'; /** The `t` value passed to test & hook implementations. */ export type ExecutionContext = { diff --git a/types/try-fn.d.ts b/types/try-fn.d.cts similarity index 96% rename from types/try-fn.d.ts rename to types/try-fn.d.cts index f1381d82..802c834d 100644 --- a/types/try-fn.d.ts +++ b/types/try-fn.d.cts @@ -1,4 +1,4 @@ -import type {Implementation} from './test-fn.js'; +import type {Implementation} from './test-fn.cjs'; export type CommitDiscardOptions = { /**