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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/* @flow */

module.exports = {
extends: "./node_modules/@krakenjs/eslint-config-grumbler",
extends:
"./node_modules/@krakenjs/eslint-config-grumbler/eslintrc-typescript",

rules: {
"keyword-spacing": "off",
"@typescript-eslint/keyword-spacing": "off",

globals: {
__TEST__: true,
// off for initial ts conversion
// Implicit any in catch clause
"@typescript-eslint/no-implicit-any-catch": "off",
// Prefer using an optional chain expression instead, as it's more concise and easier to read
"@typescript-eslint/prefer-optional-chain": "off",
// Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
"@typescript-eslint/prefer-nullish-coalescing": "off",
// Generic Object Injection Sink
"security/detect-object-injection": "off",
},
};
3 changes: 0 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ jobs:
- name: 👕 Lint commit messages
uses: wagoid/commitlint-github-action@v4

- name: ▶️ Run flow-typed script
run: npm run flow-typed

- name: ▶️ Run build script
run: npm run build

Expand Down
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,7 @@ Returns true if the specified domain matches the pattern. The pattern can be one

All of the tasks are listed in the package.json file under the scripts section

| Command | Description |
| ------------- | :--------------------------------------: |
| npm run build | Builds the dist files |
| npm test | Runs the test suite. Lint + Type + Karma |

# Debugging

Run the debug task and pass the next tasks as argument.

```
npm run debug -- npm run build
npm run debug -- npm test
npm run debug -- npm run karma -- --browsers=Chrome
```
| Command | Description |
| ------------- | :-------------------: |
| npm run build | Builds the dist files |
| npm test | Runs full test suite. |
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: "@krakenjs/babel-config-grumbler/babelrc-browser",
presets: ["@krakenjs/babel-config-grumbler/flow-ts-babel-preset"],
};
3 changes: 0 additions & 3 deletions babel.config.json

This file was deleted.

14 changes: 0 additions & 14 deletions karma.conf.js

This file was deleted.

51 changes: 31 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
"version": "3.0.2",
"description": "Utilities for dealing with cross-domain windows.",
"main": "dist/cross-domain-utils.js",
"module": "dist/module/index.js",
"module": "dist/index.js",
"types": "dist/esm/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "npm run test && npm run babel && npm run webpack",
"build": "npm run test && npm run babel && npm run webpack && npm run build:types",
"build:flow": "find ./dist -type f -not -path './node_modules/*' -name '*.d.ts' -exec sh -c 'flowgen --add-flow-header $1 -o ${1%.*.*}.js.flow' _ '{}' \\;",
"build:tsc": "tsc src/* --outDir ./dist/esm --declaration --emitDeclarationOnly --strict",
"build:types": "npm run build:tsc && npm run build:flow",
"webpack": "cross-env NODE_ENV=production babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress --output-path dist",
"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?

"format": "prettier --write --ignore-unknown .",
"format:check": "prettier --check .",
"test": "npm run format:check && npm run lint && npm run flow-typed && npm run flow && npm run karma",
"lint": "eslint src/ test/",
"flow": "flow",
"flow-typed": "rm -rf ./flow-typed && flow-typed install",
"test": "npm run format:check && npm run lint && npm run tsc --no-emit && npm run vitest",
westeezy marked this conversation as resolved.
Show resolved Hide resolved
"lint": "eslint --ext ts,tsx,js,jsx src/ test/",
"clean": "rimraf dist coverage",
"reinstall": "rimraf flow-typed && rimraf node_modules && npm install && flow-typed install",
"prerelease": "npm run clean && npm run build && git add dist && git commit -m 'ci: check in dist folder' || echo 'Nothing to distribute'",
"release": "standard-version",
"postrelease": "git push && git push --follow-tags && npm publish",
"debug": "cross-env NODE_ENV=debug",
"prepare": "husky install"
"prepare": "husky install",
"vitest": "vitest run --dom --coverage",
"vitest:watch": "vitest watch --dom --coverage --ui"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -72,23 +76,30 @@
],
"license": "Apache-2.0",
"files": [
"src/",
"dist/"
],
"readmeFilename": "README.md",
"devDependencies": {
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@krakenjs/grumbler-scripts": "^8.0.5",
"chai": "^4.2.0",
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@krakenjs/babel-config-grumbler": "^8.0.7",
"@krakenjs/eslint-config-grumbler": "^8.0.7",
"@krakenjs/typescript-config-grumbler": "^8.0.7",
"@krakenjs/webpack-config-grumbler": "^8.1.0-alpha.1",
"@vitest/coverage-c8": "^0.25.3",
"@vitest/ui": "^0.25.3",
"chai": "^4.3.7",
"cross-env": "^7.0.3",
"flow-bin": "0.155.0",
"flow-typed": "^3.8.0",
"husky": "^7.0.4",
"flowgen": "^1.20.1",
"happy-dom": "^7.7.0",
"husky": "^8.0.2",
"lint-staged": "^13.0.3",
"mocha": "^4",
"prettier": "2.7.1",
"standard-version": "^9.3.2"
"standard-version": "^9.5.0",
"ts-node": "^10.9.1",
"typescript": "4.9.3",
"vite": "^3.2.4",
"vitest": "0.25.3"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
Expand Down
14 changes: 0 additions & 14 deletions src/constants.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -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

MOCK: "mock:" as const,
FILE: "file:" as const,
ABOUT: "about:" as const,
};

export const WILDCARD = "*";

export const WINDOW_TYPE = {
IFRAME: "iframe" as const,
POPUP: "popup" as const,
};
2 changes: 0 additions & 2 deletions src/index.flow.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* @flow */

export * from "./utils";
export * from "./types";
export * from "./constants";
42 changes: 0 additions & 42 deletions src/types.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type CrossDomainWindowType = Window;

export type SameDomainWindowType = Omit<
Window,
"frames" | "parent" | "focus" | "top" | "opener" | "postMessage"
>;

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[]

| RegExp;
11 changes: 0 additions & 11 deletions src/util.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function isRegex(item: unknown): boolean {
return Object.prototype.toString.call(item) === "[object RegExp]";
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function noop(...args: readonly unknown[]): void {
// pass
}
Loading