Skip to content

Commit

Permalink
refactor!: move dist/module to lib and export flow types
Browse files Browse the repository at this point in the history
Moving esm files to `lib/` folder gives us a path to stop importing from
`src/` when importing files for treeshaking. We can migrate to importing
from `lib/` and still have flow definitions at the ready

Tasks Completed:
- Remove module folder
- Output transpiled code and flow defs to `lib/`
  • Loading branch information
westeezy committed Feb 15, 2022
1 parent fcb991a commit 25b0c2f
Show file tree
Hide file tree
Showing 16 changed files with 1,181 additions and 68 deletions.
Empty file removed dist/.gitignore
Empty file.
1 change: 0 additions & 1 deletion dist/cross-domain-utils.js.map

This file was deleted.

56 changes: 0 additions & 56 deletions dist/module/index.js.flow

This file was deleted.

5 changes: 0 additions & 5 deletions dist/module/util.js.flow

This file was deleted.

1 change: 0 additions & 1 deletion dist/test.htm

This file was deleted.

File renamed without changes.
14 changes: 14 additions & 0 deletions lib/constants.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* @flow */

export const PROTOCOL = {
MOCK: ('mock:' : 'mock:'),
FILE: ('file:' : 'file:'),
ABOUT: ('about:' : 'about:')
};

export const WILDCARD = '*';

export const WINDOW_TYPE = {
IFRAME: ('iframe' : 'iframe'),
POPUP: ('popup' : 'popup')
};
File renamed without changes.
5 changes: 5 additions & 0 deletions lib/index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* @flow */

export * from './utils';
export * from './types';
export * from './constants';
File renamed without changes.
40 changes: 40 additions & 0 deletions lib/types.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* @flow */

// export something to force webpack to see this as an ES module
export const TYPES = true;

export type CrossDomainLocationType = {|

|};

export type CrossDomainWindowType = {|
location : string | CrossDomainLocationType,
self : CrossDomainWindowType,
closed : boolean,
open : (string, string, string) => CrossDomainWindowType,
close : () => void,
focus : () => void,
top : CrossDomainWindowType,
frames : $ReadOnlyArray<CrossDomainWindowType>,
opener ? : CrossDomainWindowType,
parent : CrossDomainWindowType,
length : number,
postMessage : (string, string) => void
|};

export type SameDomainWindowType = Object & {|
location : string | Object,
self : CrossDomainWindowType,
closed : boolean,
open : (string, string, string) => CrossDomainWindowType,
close : () => void,
focus : () => void,
XMLHttpRequest : typeof XMLHttpRequest,
document : Document,
navigator : {|
userAgent : string,
mockUserAgent? : string
|}
|};

export type DomainMatcher = string | $ReadOnlyArray<string> | $ReadOnlyArray<string> | RegExp;
File renamed without changes.
11 changes: 11 additions & 0 deletions lib/util.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* @flow */

export function isRegex(item : mixed) : boolean {
// $FlowFixMe method-unbinding
return Object.prototype.toString.call(item) === '[object RegExp]';
}

// eslint-disable-next-line no-unused-vars
export function noop(...args : $ReadOnlyArray<mixed>) {
// pass
}
File renamed without changes.
Loading

0 comments on commit 25b0c2f

Please sign in to comment.