Skip to content
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

chore!: convert library to typescript #37

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

chore!: convert library to typescript #37

wants to merge 4 commits into from

Conversation

westeezy
Copy link
Contributor

  • Codebase is migrated to TypeScript by using https://github.com/Khan/flow-to-ts
  • Dist folder now outputs esm folder
  • Package.json update for types & modules
  • Flowgen is used to generate flow types from dist/*.d.ts

@westeezy westeezy requested review from gregjopa and wsbrunson June 29, 2022 03:28
package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@westeezy westeezy marked this pull request as ready for review June 29, 2022 15:44
@westeezy westeezy requested a review from a team as a code owner June 29, 2022 15:44
Copy link
Contributor

@gregjopa gregjopa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 🥇 👍

@westeezy westeezy force-pushed the typescript2 branch 4 times, most recently from 74e861f to 72e0c04 Compare November 22, 2022 21:27
@westeezy
Copy link
Contributor Author

Published alpha @krakenjs/[email protected]

dist
├── cross-domain-utils.js
├── cross-domain-utils.js.map
├── cross-domain-utils.min.js
├── cross-domain-utils.min.js.map
├── esm
│   ├── constants.d.ts
│   ├── constants.js
│   ├── constants.js.flow
│   ├── index.d.ts
│   ├── index.js
│   ├── index.js.flow
│   ├── types.d.ts
│   ├── types.js
│   ├── types.js.flow
│   ├── util.d.ts
│   ├── util.js
│   ├── util.js.flow
│   ├── utils.d.ts
│   ├── utils.js
│   └── utils.js.flow

// pass
}
}
}

export function getUserAgent(win: ?SameDomainWindowType): string {
export function getUserAgent(
win: SameDomainWindowType | undefined | undefined
Copy link
Contributor

@dtjones404 dtjones404 Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does undefined | undefined serve some purpose, or is this just a weird artifact from the flow-to-ts tool? Looks like it's present in a few places in src/utils.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @dtjones404! I assume we should only have one undefined

westeezy added 4 commits March 7, 2023 12:08
- Codebase is migrated to TypeScript by using https://github.com/Khan/flow-to-ts
- Dist folder now outputs esm folder
- Package.json update for types & modules
- Flowgen is used to generate flow types from dist/*.d.ts
CrossDomainWindowType,
SameDomainWindowType,
DomainMatcher,
import {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should we use this syntax instead since they are all types?

import type { CrossDomainWindowType, SameDomainWindowType, DomainMatcher } from "./types";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly prefer the syntax Greg is suggesting. If we wanted to, I think we could enforce this with an eslint rule:

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/consistent-type-imports.md#fixstyle

win?: CrossDomainWindowType = window
): ?CrossDomainWindowType {
win: CrossDomainWindowType = window
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

win?: CrossDomainWindowType = window
): ?CrossDomainWindowType {
win: CrossDomainWindowType = window
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

win?: CrossDomainWindowType = window
): ?CrossDomainWindowType {
win: CrossDomainWindowType = window
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

win?: CrossDomainWindowType = window
): ?CrossDomainWindowType {
win: CrossDomainWindowType = window
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

// pass
}
}
}

export function getUserAgent(win: ?SameDomainWindowType): string {
export function getUserAgent(
win: SameDomainWindowType | undefined | undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
win: SameDomainWindowType | undefined | undefined
win: SameDomainWindowType | undefined

}

export function getFrameByName(
win: CrossDomainWindowType,
name: string
): ?CrossDomainWindowType {
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

// pass
}
}

export function findChildFrameByName(
win: CrossDomainWindowType,
name: string
): ?CrossDomainWindowType {
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

@@ -673,15 +678,14 @@ export function findChildFrameByName(
export function findFrameByName(
win: CrossDomainWindowType,
name: string
): ?CrossDomainWindowType {
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

win?: CrossDomainWindowType = window
): ?CrossDomainWindowType {
win: CrossDomainWindowType = window
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

n: number = 1
): ?CrossDomainWindowType {
n = 1
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

n: number = 1
): ?CrossDomainWindowType {
n = 1
): CrossDomainWindowType | undefined | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
): CrossDomainWindowType | undefined | undefined {
): CrossDomainWindowType | undefined {

export type DomainMatcher =
| string
| readonly string[]
| readonly string[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| readonly string[]

@@ -0,0 +1,12 @@
export const PROTOCOL = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super minor, but is this syntax the same?

export const PROTOCOL = {
  MOCK: "mock:",
  FILE: "file:" ,
  ABOUT: "about:",
}  as const

"babel": "cross-env NODE_ENV=production babel src/ --out-dir dist/module",
"karma": "cross-env NODE_ENV=test babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/karma start",
"babel": "cross-env NODE_ENV=production babel src/ --out-dir ./dist/esm/ --extensions .ts,.tsx",
"tsc": "tsc",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to follow the convention of having a typecheck script here, like we have in other repositories?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants