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

Progress TypeScript migration #671

Merged
merged 27 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
26fff40
Initial commit for converting emoji-mart to typescript
Scalahansolo Apr 27, 2022
cbf7f66
WIP Typescript conversion
Scalahansolo Apr 27, 2022
0023000
Remove nested workspaces
zhouzi May 17, 2022
3d9f7a4
Minimal setup
zhouzi May 17, 2022
a974c19
Move devDependencies to root
jwhitham-ds Aug 10, 2022
8c6318f
Remove .parcelrc
jwhitham-ds Aug 10, 2022
afe2ab4
Change import to address known issue with @parcel/transformer-typescr…
jwhitham-ds Aug 10, 2022
d5fc41b
Rename files for TS and React
jwhitham-ds Aug 10, 2022
edea267
Remove filetype from import
jwhitham-ds Aug 10, 2022
38fb3f1
Change tsconfig jsx option to 'react-jsx'
jwhitham-ds Aug 12, 2022
e52a572
Remove strict type checking to allow repo to pass as is
jwhitham-ds Aug 12, 2022
4a4a1a5
Remove more type checking to allow repo to pass as is
jwhitham-ds Aug 12, 2022
63b26d7
Remove .postcssrc
jwhitham-ds Aug 12, 2022
0e07e78
Run prettier
jwhitham-ds Aug 12, 2022
b7d6756
Add ts-jest package and bump jest
jwhitham-ds Aug 23, 2022
ba65731
Add ts-jest transformers to config
jwhitham-ds Aug 23, 2022
f2d8477
Remove --experimental-vm-modules option when running jest.
jwhitham-ds Aug 23, 2022
2350056
Don’t mount component when HTMLElement has been disconnected
EtienneLem Oct 9, 2022
3ba20fa
Move dev dependencies back into package
EtienneLem Oct 9, 2022
427f577
Update Jest config
EtienneLem Oct 9, 2022
e227c4f
Update TS config
EtienneLem Oct 9, 2022
1fa5ae0
Move TS config to root
EtienneLem Oct 9, 2022
4172c84
Add `check:types` to CI integrity job
EtienneLem Oct 10, 2022
2fb18be
Merge branch 'main' into first-pr
EtienneLem Oct 28, 2022
c928dba
Fix TS check
EtienneLem Oct 28, 2022
6c22d2a
Move global dev dependencies back to root + upgrade Parcel
EtienneLem Oct 30, 2022
ded2d42
Fix `yarn dev`
EtienneLem Oct 30, 2022
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
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/env", ["@babel/typescript", { "jsxPragma": "h" }]],
"plugins": [["@babel/transform-react-jsx", { "pragma": "h" }]]
}
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:

- run: yarn install
- run: yarn prettier
- run: yarn check:types

tests:
runs-on: ubuntu-latest
Expand Down
5 changes: 0 additions & 5 deletions .postcssrc

This file was deleted.

1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ module.exports = {
// A map from regular expressions to paths to transformers
transform: {
'.js$': './jest/esm-transformer.js',
'\\.tsx?$': 'ts-jest',
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@
"build:data": "yarn workspace @emoji-mart/data build",
"build:react": "yarn workspace @emoji-mart/react build",
"build:website": "yarn workspace @emoji-mart/website build",
"check:types": "tsc",
"prettier": "prettier --check .",
"prettier:fix": "prettier --write .",
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
"test": "jest"
EtienneLem marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@babel/core": "7.18.9",
"@babel/plugin-transform-modules-commonjs": "7.18.6",
"jest": "28.0.0",
"@parcel/packager-ts": "2.7.0",
"@parcel/transformer-inline-string": "2.7.0",
"@parcel/transformer-sass": "2.7.0",
"@parcel/transformer-typescript-types": "2.7.0",
"jest-environment-jsdom": "28.0.0",
"prettier": "2.5.1"
"jest": "^28.1.3",
"parcel": "2.7.0",
"prettier": "2.5.1",
"ts-jest": "^28.0.7",
"typescript": "4.6.4"
},
"prettier": {
"semi": false,
Expand Down
7 changes: 2 additions & 5 deletions packages/emoji-mart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"url": "/~https://github.com/missive/emoji-mart",
"directory": "packages/emoji-mart"
},
"source": "src/index.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"main": "dist/main.js",
"module": "dist/module.js",
"global": "dist/browser.js",
Expand Down Expand Up @@ -38,10 +39,6 @@
"prepublishOnly": "yarn build"
},
"devDependencies": {
"@parcel/transformer-inline-string": "2.3.2",
"@parcel/transformer-sass": "2.3.2",
"autoprefixer": "10.4.4",
"parcel": "2.3.2",
"preact": "10.6.4"
},
"alias": {
Expand Down
2 changes: 1 addition & 1 deletion packages/emoji-mart/src/browser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import * as EmojiMart from './index.js'
import * as EmojiMart from './index'
EtienneLem marked this conversation as resolved.
Show resolved Hide resolved
window.EmojiMart = EmojiMart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { render } from 'preact'

import { init, getProps } from '../../config'
import { HTMLElement } from '../HTMLElement'
import { Emoji } from '.'
import EmojiProps from './EmojiProps'

export default class EmojiElement extends HTMLElement {
Expand All @@ -20,6 +19,8 @@ export default class EmojiElement extends HTMLElement {
}

await init()
if (this.disconnected) return

render(<Emoji {...props} />, this)
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/emoji-mart/src/components/Emoji/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/emoji-mart/src/components/Emoji/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Emoji } from './Emoji'
export { default as EmojiElement } from './EmojiElement'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as PureInlineComponent } from './PureInlineComponent.js'
export { default as PureInlineComponent } from './PureInlineComponent'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { getProp } from '../../config'

const WindowHTMLElement =
Expand Down Expand Up @@ -44,4 +45,12 @@ export default class HTMLElement extends WindowHTMLElement {
this.component.forceUpdate()
}
}

disconnectedCallback() {
this.disconnected = true

if (this.component && this.component.unregister) {
this.component.unregister()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { HTMLElement } from '.'

export default class ShadowElement extends HTMLElement {
Expand Down
2 changes: 0 additions & 2 deletions packages/emoji-mart/src/components/HTMLElement/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/emoji-mart/src/components/HTMLElement/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as HTMLElement } from './HTMLElement'
export { default as ShadowElement } from './ShadowElement'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { PureComponent } from 'preact/compat'
import { Data, I18n } from '../../config'
import Icons from '../../icons'
Expand Down
1 change: 0 additions & 1 deletion packages/emoji-mart/src/components/Navigation/index.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/emoji-mart/src/components/Navigation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Navigation } from './Navigation'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { Component, createRef } from 'preact'

import { deepEqual, sleep, getEmojiData } from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { render } from 'preact'

import { init, getProps } from '../../config'
Expand All @@ -20,13 +21,9 @@ export default class PickerElement extends ShadowElement {
}

await init(props)
render(<Picker {...props} />, this.shadowRoot)
}
if (this.disconnected) return

disconnectedCallback() {
if (this.component) {
this.component.unregister()
}
render(<Picker {...props} />, this.shadowRoot)
}
}

Expand Down
3 changes: 0 additions & 3 deletions packages/emoji-mart/src/components/Picker/index.js

This file was deleted.

4 changes: 4 additions & 0 deletions packages/emoji-mart/src/components/Picker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-nocheck
export { default as Picker } from './Picker'
export { default as PickerElement } from './PickerElement'
export { default as PickerStyles } from 'bundle-text:./PickerStyles.scss'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import i18n_en from '@emoji-mart/data/i18n/en.json'
import PickerProps from './components/Picker/PickerProps'
import {
Expand All @@ -23,7 +24,8 @@ async function fetchJSON(src) {
return json
}

let promise = null
let promise: Promise<void> | null = null
let initiated = false
let initCallback = null
let initialized = false

Expand Down
1 change: 1 addition & 0 deletions packages/emoji-mart/src/declaration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '*.scss'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { Store } from '../helpers'

const DEFAULTS = [
Expand All @@ -18,9 +19,9 @@ const DEFAULTS = [
'heart',
]

let Index = null
let Index: any | null = null

function add(emoji) {
function add(emoji: { id: string }) {
Index || (Index = Store.get('frequently') || {})

const emojiId = emoji.id || emoji
Expand Down
16 changes: 0 additions & 16 deletions packages/emoji-mart/src/helpers/index.js

This file was deleted.

16 changes: 16 additions & 0 deletions packages/emoji-mart/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export { default as Store } from './store'

export { default as NativeSupport } from './native-support'
export { default as FrequentlyUsed } from './frequently-used'
export { default as SearchIndex } from './search-index'

export const SafeFlags = [
'checkered_flag',
'crossed_flags',
'pirate_flag',
'rainbow-flag',
'transgender_flag',
'triangular_flag_on_post',
'waving_black_flag',
'waving_white_flag',
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { init, Data } from '../config'

const SHORTCODES_REGEX = /^(?:\:([^\:]+)\:)(?:\:skin-tone-(\d)\:)?$/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function set(key, value) {
function set(key: string, value: string) {
try {
window.localStorage[`emoji-mart.${key}`] = JSON.stringify(value)
} catch (error) {}
}

function get(key) {
function get(key: string): any {
try {
const value = window.localStorage[`emoji-mart.${key}`]

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SearchIndex } from './helpers'

export function deepEqual(a, b) {
export function deepEqual(a: any, b: any): boolean {
return (
Array.isArray(a) &&
Array.isArray(b) &&
Expand All @@ -15,15 +15,15 @@ export async function sleep(frames = 1) {
}
}

export function getEmojiData(emoji, { skinIndex } = {}) {
export function getEmojiData(emoji, { skinIndex = 0 } = {}) {
const skin =
emoji.skins[skinIndex] ||
(() => {
skinIndex = 0
return emoji.skins[skinIndex]
})()

const emojiData = {
const emojiData: any = {
id: emoji.id,
name: emoji.name,
native: skin.native,
Expand Down
18 changes: 18 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"allowJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "preserve",
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment",
"isolatedModules": true,
"strict": false,
"skipLibCheck": true,
"resolveJsonModule": true,
"noEmit": true
},
"exclude": ["node_modules", "dist"]
}
Loading