Re-organize types for maximum compatibility
Add shims for TypeScript's 'node' module resolution algorithm. The exports map is only used with the `node16` algorithm. Write types in CommonJS, so they can be exported from ESM files. The other way around is prone to, at the very least, confusing warnings.
This commit is contained in:
parent
2d3f39404d
commit
3ebe65cbeb
11 changed files with 105 additions and 97 deletions
|
|
@ -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;
|
||||
|
|
|
|||
14
entrypoints/main.d.ts
vendored
14
entrypoints/main.d.ts
vendored
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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 <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.
|
||||
|
|
|
|||
78
entrypoints/plugin.d.ts
vendored
78
entrypoints/plugin.d.ts
vendored
|
|
@ -1,77 +1 @@
|
|||
import type {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.
|
||||
export type * from './plugin.cjs';
|
||||
|
|
|
|||
4
index.d.ts
vendored
Normal file
4
index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// For compatibility with resolution algorithms other than Node16.
|
||||
|
||||
export * from './entrypoints/main.cjs';
|
||||
export {default} from './entrypoints/main.cjs';
|
||||
|
|
@ -42,7 +42,8 @@
|
|||
"files": [
|
||||
"entrypoints",
|
||||
"lib",
|
||||
"types"
|
||||
"types",
|
||||
"*.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"🦄",
|
||||
|
|
|
|||
3
plugin.d.ts
vendored
Normal file
3
plugin.d.ts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// For compatibility with resolution algorithms other than Node16.
|
||||
|
||||
export * from './entrypoints/plugin.cjs';
|
||||
|
|
@ -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<Context = unknown> = {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import type {Implementation} from './test-fn.js';
|
||||
import type {Implementation} from './test-fn.cjs';
|
||||
|
||||
export type CommitDiscardOptions = {
|
||||
/**
|
||||
Loading…
Reference in a new issue