New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types(jest-haste-map): Expose a minimal public API to TypeScript #13023
Changes from 2 commits
ee77bcc
92cd981
4ca08fd
cc936d4
b8c4a69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ import type { | |
FileMetaData, | ||
HasteMapStatic, | ||
HasteRegExp, | ||
IHasteMap, | ||
IModuleMap, | ||
InternalHasteMap, | ||
HasteMap as InternalHasteMapObject, | ||
MockData, | ||
|
@@ -109,11 +111,12 @@ type Watcher = { | |
|
||
type HasteWorker = typeof import('./worker'); | ||
|
||
export type {default as FS} from './HasteFS'; | ||
export {default as ModuleMap} from './ModuleMap'; | ||
export const ModuleMap = HasteModuleMap as { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to cast? |
||
create: (rootPath: string) => IModuleMap; | ||
}; | ||
export type { | ||
ChangeEvent, | ||
HasteMap as HasteMapObject, | ||
Comment on lines
-115
to
-116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing these exports is a breaking change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. specifically But maybe not - since we bundle our TS types, lots of internal types are never present in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think this is safe, because as you say it's not referenced by the built declaration files there should be no observable change to consumers of (It's type-breaking to users of |
||
IHasteFS, | ||
IHasteMap, | ||
IModuleMap, | ||
SerializableModuleMap, | ||
} from './types'; | ||
|
@@ -210,7 +213,7 @@ function invariant(condition: unknown, message?: string): asserts condition { | |
* Worker processes can directly access the cache through `HasteMap.read()`. | ||
* | ||
*/ | ||
export default class HasteMap extends EventEmitter { | ||
class HasteMap extends EventEmitter implements IHasteMap { | ||
private _buildPromise: Promise<InternalHasteMapObject> | null = null; | ||
private _cachePath = ''; | ||
private _changeInterval?: ReturnType<typeof setInterval>; | ||
|
@@ -227,7 +230,7 @@ export default class HasteMap extends EventEmitter { | |
return HasteMap; | ||
} | ||
|
||
static async create(options: Options): Promise<HasteMap> { | ||
static async create(options: Options): Promise<IHasteMap> { | ||
if (options.hasteMapModulePath) { | ||
const CustomHasteMap = require(options.hasteMapModulePath); | ||
return new CustomHasteMap(options); | ||
|
@@ -1143,3 +1146,8 @@ function copy<T extends Record<string, unknown>>(object: T): T { | |
function copyMap<K, V>(input: Map<K, V>): Map<K, V> { | ||
return new Map(input); | ||
} | ||
|
||
export default HasteMap as HasteMapStatic & { | ||
SimenB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
create(options: Options): Promise<IHasteMap>; | ||
getStatic(config: Config.ProjectConfig): HasteMapStatic; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have an inline type here instead of using a named one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly meant, why is this
HasteMapObject
thing not exported fromjest-haste-map
?