-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 all 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 { | ||
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,11 @@ 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 the smallest API surface required by Jest | ||
type IJestHasteMap = HasteMapStatic & { | ||
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. should this be exported? 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. I'm not sure to be honest. In a way it's exposed via The general idea is to "hide" statics we don't need to be public - such as the bunch that come from extending Happy to go with your judgement anyway. 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. fair enough 👍 If for some reason people want it, I assume they'll send a PR 😀 |
||
create(options: Options): Promise<IHasteMap>; | ||
getStatic(config: Config.ProjectConfig): HasteMapStatic; | ||
}; | ||
const JestHasteMap: IJestHasteMap = HasteMap; | ||
export default JestHasteMap; |
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 need to cast?