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

Switch to type only import & upgrade to prettier 2.0 #911

Merged
merged 6 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ module.exports = {
path.join(__dirname, './scripts/jest-setup.js'),
],
// skip packages other than 'ts-results', 'async-call-rpc' and 'holoflows/kit'
transformIgnorePatterns: ['node_modules((?!(ts-results|async-call-rpc|@holoflows\\/kit)).)*$'],
transformIgnorePatterns: [],
transform: {
'[/\\\\]node_modules[/\\\\].+\\.m?js$': 'jest-esm-transformer',
'node_modules.+(ts-results|async-call-rpc|holoflows).+.js$': 'jest-esm-transformer',
},
moduleNameMapper: {
'^@holoflows/kit.+(?<!sleep)$': require.resolve('@holoflows/kit/umd/index.js'),
'lodash-es': require.resolve('lodash'),
'idb/with-async-ittr': require.resolve('idb/with-async-ittr-cjs.js'),
'idb/with-async-ittr-cjs': require.resolve('idb/with-async-ittr-cjs.js'),
},
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"start:ios": "webpack-dev-server --wk-webview --mode development",
"storybook": "start-storybook -p 9009 -s public --quiet",
"test": "jest --watch",
"test:ci": "jest --ci --collectCoverage=true --reporters=default --reporters=jest-junit -w 1",
"test:ci": "jest --ci --collectCoverage=true --reporters=default --reporters=jest-junit -w 1 --forceExit",
"test:e2e": "jest --runInBand --config=jest-e2e.config.js",
"uninstall": "ts-node scripts/postinstall.ts"
},
Expand Down Expand Up @@ -126,8 +126,8 @@
"@types/jest": "^25.1.4",
"@types/jest-environment-puppeteer": "^4.3.1",
"@types/puppeteer": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.19.2",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"asmcrypto.js": "^2.3.2",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.1.0",
Expand All @@ -136,10 +136,10 @@
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.7.2",
"eslint-config-prettier": "^6.10.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react-hooks": "^2.3.0",
"eslint-plugin-react-hooks": "^2.5.1",
"esm": "^3.2.25",
"expect-puppeteer": "^4.4.0",
"fake-indexeddb": "^3.0.0",
Expand All @@ -154,7 +154,7 @@
"jest-webextension-mock": "^3.5.0",
"lint-staged": "^10.0.7",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"prettier": "^2.0.2",
"puppeteer": "^2.1.1",
"react-devtools": "^4.5.0",
"react-docgen-typescript-loader": "^3.7.1",
Expand Down
6 changes: 3 additions & 3 deletions public/firefoxFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@
const PatchThisOfDescriptorToGlobal = (desc, global) => {
const { get, set, value } = desc
if (get)
desc.get = function() {
desc.get = function () {
if (this === globalThis) return get.apply(window)
return get.apply(this)
}
if (set)
desc.set = function(val) {
desc.set = function (val) {
if (this === globalThis) return set.apply(global, val)
return set.apply(this, val)
}
if (value && typeof value === 'function') {
const desc2 = Object.getOwnPropertyDescriptors(value)
desc.value = function(...args) {
desc.value = function (...args) {
if (new.target) return Reflect.construct(value, args, new.target)
return Reflect.apply(value, this === globalThis ? global : this, args)
}
Expand Down
7 changes: 4 additions & 3 deletions scripts/import-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (diags) {
}

function getChecker(): (path: string) => string | null {
return x => {
return (x) => {
if (x.includes('@material-ui')) {
return `@material-ui appears in the import chain!
To write a cross context file, use safeMUI() inside the function to import them conditionally.
Expand Down Expand Up @@ -55,6 +55,7 @@ function checkReferenceRecursive(
for (const dependency of file.getImportDeclarations()) {
let isTypeOnlyImport = true

if (dependency.compilerNode.importClause?.isTypeOnly) continue
// We consider default import and ns import is not type only import
if (dependency.getDefaultImport() || dependency.getNamespaceImport()) {
isTypeOnlyImport = false
Expand Down Expand Up @@ -97,7 +98,7 @@ function checkReferenceRecursive(
esModuleStyleImport.push(path)
}
const nodeStyleRequires: string[] = []
file.transform(traversal => {
file.transform((traversal) => {
const node = traversal.visitChildren()
// require('...')
if (!ts.ts.isCallExpression(node)) return node
Expand Down Expand Up @@ -125,7 +126,7 @@ function checkReferenceRecursive(
if (diag) {
console.error(`${diag}
Import chain:
${nextRefChain.map(x => ' => ' + x).join('\n')}
${nextRefChain.map((x) => ' => ' + x).join('\n')}
`)
hasDiagnostics = true
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/jest-global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module.exports = async () => {
}

function addAsmCryptoForTest(cb) {
var download = function(url, dest, cb) {
var download = function (url, dest, cb) {
var file = fs.createWriteStream(dest)
var request = http.get(url, function(response) {
var request = http.get(url, function (response) {
response.pipe(file)
file.on('finish', function() {
file.on('finish', function () {
file.close(cb)
})
})
Expand Down
2 changes: 1 addition & 1 deletion scripts/puppeteer-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const pptOpts = {
function findChrome() {
try {
const clBase = path.join(require.resolve('chrome-launcher'), '..')
global.clInt = x => require(path.join(clBase, `${x}.js`))
global.clInt = (x) => require(path.join(clBase, `${x}.js`))
return clInt('chrome-finder')[clInt('utils').getPlatform()]()[0]
} catch (e) {
console.error(e)
Expand Down
12 changes: 6 additions & 6 deletions src/background-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ if (GetContext() === 'background') {
}`
const contentScripts: Array<{ code: string } | { file: string }> = []
const contentScriptReady = fetch('generated__content__script.html')
.then(x => x.text())
.then(html => {
.then((x) => x.text())
.then((html) => {
const parser = new DOMParser()
const root = parser.parseFromString(html, 'text/html')
root.querySelectorAll('script').forEach(script => {
root.querySelectorAll('script').forEach((script) => {
if (script.innerText) contentScripts.push({ code: script.innerText })
else if (script.src)
contentScripts.push({ file: new URL(script.src, browser.runtime.getURL('')).pathname })
})
})
browser.webNavigation.onCommitted.addListener(async arg => {
browser.webNavigation.onCommitted.addListener(async (arg) => {
if (arg.url === 'about:blank') return
await contentScriptReady
/**
Expand Down Expand Up @@ -70,7 +70,7 @@ if (GetContext() === 'background') {
}
})

browser.runtime.onInstalled.addListener(detail => {
browser.runtime.onInstalled.addListener((detail) => {
if (webpackEnv.genericTarget === 'facebookApp') return
if (detail.reason === 'install') {
browser.tabs.create({ url: getWelcomePageURL() })
Expand All @@ -94,7 +94,7 @@ if (GetContext() === 'background') {
})
}
function IgnoreError(arg: unknown): (reason: Error) => void {
return e => {
return (e) => {
if (e.message.includes('non-structured-clonable data')) {
// It's okay we don't need the result, happened on Firefox
} else if (e.message.includes('Frame not found, or missing host permission')) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/DataSource/useActivatedUI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Profile } from '../../database'
import type { Profile } from '../../database'
import { useValueRef } from '../../utils/hooks/useValueRef'
import { getActivatedUI } from '../../social-network/ui'
import { currentSelectedIdentity } from '../../components/shared-settings/settings'
Expand All @@ -24,11 +24,11 @@ export function useMyPersonas() {
export function useCurrentIdentity(noDefault?: boolean): Profile | null {
const all = useMyIdentities()
const current = useValueRef(currentSelectedIdentity[getActivatedUI().networkIdentifier])
return all.find(i => i.identifier.toText() === current) || (noDefault ? null : all[0])
return all.find((i) => i.identifier.toText() === current) || (noDefault ? null : all[0])
}
export function useCurrentGroupsList() {
const groups = useGroupsList()
const currentIdentity = useCurrentIdentity()
if (!currentIdentity) return []
return groups.filter(x => x.identifier.ownerIdentifier?.equals(currentIdentity.identifier))
return groups.filter((x) => x.identifier.ownerIdentifier?.equals(currentIdentity.identifier))
}
2 changes: 1 addition & 1 deletion src/components/DebugModeUI/DebugList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const F = (props: { hint: string; content: string | number }) => (
export function DebugList(props: { items: readonly (readonly [string, string | number | undefined] | JSX.Element)[] }) {
return (
<ul style={{ wordBreak: 'break-all', padding: '0 1em', margin: 0, background: 'black', color: 'white' }}>
{props.items.map(x =>
{props.items.map((x) =>
Array.isArray(x) ? <F hint={x[0]} content={x[1] === undefined ? 'undefined' : x[1]} /> : x,
)}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/components/DebugModeUI/PostHashDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import DialogTitle from '@material-ui/core/DialogTitle'
import { blue } from '@material-ui/core/colors'
import { useFriendsList } from '../DataSource/useActivatedUI'
import { Avatar } from '../../utils/components/Avatar'
import { Profile } from '../../database'
import type { Profile } from '../../database'
Jack-Works marked this conversation as resolved.
Show resolved Hide resolved
import Services from '../../extension/service'
import { PostIVIdentifier } from '../../database/type'
import { deconstructPayload } from '../../utils/type-transform/Payload'
Expand Down Expand Up @@ -57,7 +57,7 @@ function SimpleDialog(props: SimpleDialogProps) {
If MagicCode is not the same, it means at least one of Maskbook calculate the post hash wrong.
</DialogContentText>
<List dense>
{props.friends.map(one => {
{props.friends.map((one) => {
const [magicCode, fingerprint] = map.get(one.identifier.toText()) || ['Unknown', 'Unknown']
return (
<ListItem>
Expand Down
4 changes: 2 additions & 2 deletions src/components/InjectedComponents/AddToKeyStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { AdditionalContent, AdditionalContentProps } from './AdditionalPostContent'
import Services from '../../extension/service'
import { useI18N } from '../../utils/i18n-next-ui'
import { ProfileIdentifier } from '../../database/type'
import type { ProfileIdentifier } from '../../database/type'
import { useAsync } from 'react-use'
import CheckIcon from '@material-ui/icons/Check'
import CloseIcon from '@material-ui/icons/Close'
Expand Down Expand Up @@ -35,7 +35,7 @@ export function AddToKeyStore({ provePost, postBy, ...props }: AddToKeyStoreProp
type SuccessProps = Partial<AdditionalContentProps>
type WaitingProps = Partial<AdditionalContentProps>
type FailedProps = Partial<AdditionalContentProps> & { error: Error }
const useStyle = makeStyles(theme => ({
const useStyle = makeStyles((theme) => ({
root: {
display: 'inline-flex',
lineHeight: '16px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getUrl } from '../../utils/utils'
import { makeStyles, Typography, Card } from '@material-ui/core'
import { useStylesExtends } from '../custom-ui-helper'
import classNames from 'classnames'
import { TypedMessageText, TypedMessage } from '../../extension/background-script/CryptoServices/utils'
import type { TypedMessageText, TypedMessage } from '../../extension/background-script/CryptoServices/utils'
import { TypedMessageRendererProps, DefaultTypedMessageRenderer } from './TypedMessageRenderer'

export interface AdditionalContentProps
Expand Down
4 changes: 2 additions & 2 deletions src/components/InjectedComponents/CommentBox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef } from 'react'
import { useCapturedInput } from '../../utils/hooks/useCapturedEvents'
import { PropsOf } from '@emotion/styled-base/types/helper'
import type { PropsOf } from '@emotion/styled-base/types/helper'
import { useI18N } from '../../utils/i18n-next-ui'
import { makeStyles } from '@material-ui/styles'
import { InputBase } from '@material-ui/core'
Expand Down Expand Up @@ -39,7 +39,7 @@ export function CommentBox(props: CommentBoxProps) {
const [binder, inputRef, node] = useCapturedInput(() => {})
const { t } = useI18N()
useEffect(
binder(['keypress'], e => {
binder(['keypress'], (e) => {
if (!node) return
if (e.key === 'Enter') {
props.onSubmit(node.value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { AdditionalContent, AdditionalContentProps } from '../AdditionalPostContent'
import { useI18N } from '../../../utils/i18n-next-ui'
import { DecryptionProgress } from '../../../extension/background-script/CryptoServices/decryptFrom'
import type { DecryptionProgress } from '../../../extension/background-script/CryptoServices/decryptFrom'
export interface DecryptPostAwaitingProps {
type?: DecryptionProgress
AdditionalContentProps?: Partial<AdditionalContentProps>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { AdditionalContent, AdditionalContentProps } from '../AdditionalPostContent'
import { useI18N } from '../../../utils/i18n-next-ui'
import { NotSetupYetPrompt } from '../../shared/NotSetupYetPrompt'
import { BannerProps } from '../../Welcomes/Banner'
import type { BannerProps } from '../../Welcomes/Banner'
import { DecryptFailedReason } from '../../../utils/constants'
export interface DecryptPostFailedProps {
error: Error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { useMemo, useState, useEffect } from 'react'
import { sleep } from '../../../utils/utils'
import { ServicesWithProgress } from '../../../extension/service'
import { Profile } from '../../../database'
import { ProfileIdentifier, PostIdentifier } from '../../../database/type'
import {
import type { Profile } from '../../../database'
import type { ProfileIdentifier, PostIdentifier } from '../../../database/type'
import type {
DecryptionProgress,
FailureDecryption,
SuccessDecryption,
} from '../../../extension/background-script/CryptoServices/decryptFrom'
import { deconstructPayload } from '../../../utils/type-transform/Payload'
import { TypedMessage } from '../../../extension/background-script/CryptoServices/utils'
import type { TypedMessage } from '../../../extension/background-script/CryptoServices/utils'
import { DecryptPostSuccess, DecryptPostSuccessProps } from './DecryptedPostSuccess'
import { DecryptPostAwaitingProps, DecryptPostAwaiting } from './DecryptPostAwaiting'
import { DecryptPostFailedProps, DecryptPostFailed } from './DecryptPostFailed'
Expand Down Expand Up @@ -85,7 +85,7 @@ export function DecryptPost(props: DecryptPostProps) {
} else setDecryptingStatus(status.value)
}
}
run().catch(e => setDecrypted({ error: e?.message } as FailureDecryption))
run().catch((e) => setDecrypted({ error: e?.message } as FailureDecryption))
return () => signal.abort()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [encryptedText, postBy.toText(), whoAmI.toText(), sharedPublic])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react'
import { Payload } from '../../../utils/type-transform/Payload'
import { ProfileIdentifier } from '../../../database/type'
import { SuccessDecryption, FailureDecryption } from '../../../extension/background-script/CryptoServices/decryptFrom'
import type { Payload } from '../../../utils/type-transform/Payload'
import type { ProfileIdentifier } from '../../../database/type'
import type {
SuccessDecryption,
FailureDecryption,
} from '../../../extension/background-script/CryptoServices/decryptFrom'
import { DebugList } from '../../DebugModeUI/DebugList'
import { DebugModeUI_PostHashDialog } from '../../DebugModeUI/PostHashDialog'
import { useValueRef } from '../../../utils/hooks/useValueRef'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { getUrl } from '../../../utils/utils'
import { useI18N } from '../../../utils/i18n-next-ui'
import { makeStyles } from '@material-ui/styles'
import { Box, Link, useMediaQuery, useTheme, Typography } from '@material-ui/core'
import { Profile } from '../../../database'
import { ProfileIdentifier, PostIdentifier } from '../../../database/type'
import type { Profile } from '../../../database'
import type { ProfileIdentifier, PostIdentifier } from '../../../database/type'
import { useStylesExtends } from '../../custom-ui-helper'
import { TypedMessage } from '../../../extension/background-script/CryptoServices/utils'
import type { TypedMessage } from '../../../extension/background-script/CryptoServices/utils'
import RedPacketInDecryptedPost from '../../../plugins/Wallet/UI/RedPacket/RedPacketInDecryptedPost'
import CheckIcon from '@material-ui/icons/Check'
import ClearIcon from '@material-ui/icons/Clear'
Expand Down Expand Up @@ -41,7 +41,7 @@ export const DecryptPostSuccess = React.memo(function DecryptPostSuccess(props:
return (
<AdditionalContent
metadataRenderer={{
after: props => <RedPacketInDecryptedPost message={props.message} postIdentifier={postIdentifier} />,
after: (props) => <RedPacketInDecryptedPost message={props.message} postIdentifier={postIdentifier} />,
}}
header={<DecryptPostSuccessHeader {...props} shareMenu={shareMenu} />}
message={data.content}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export function ImmersiveSetupStepperUI(props: ImmersiveSetupStepperUIProps) {
required
label={t('username')}
value={props.username}
onChange={e => props.onUsernameChange(e.currentTarget.value)}
onChange={(e) => props.onUsernameChange(e.currentTarget.value)}
innerRef={inputRef}
/>
<br />
Expand Down Expand Up @@ -297,7 +297,7 @@ export function ImmersiveSetupStepper(
next={next}
// ? username & onUsernameChange is a self managed group
username={username}
onUsernameChange={v => {
onUsernameChange={(v) => {
setUsername(v)
touched.current = true
}}
Expand Down
6 changes: 3 additions & 3 deletions src/components/InjectedComponents/PersonKnown.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react'
import { AdditionalContent, AdditionalContentProps } from './AdditionalPostContent'
import { useI18N } from '../../utils/i18n-next-ui'
import { ProfileIdentifier } from '../../database/type'
import type { ProfileIdentifier } from '../../database/type'
import Services from '../../extension/service'
import { ValueRef } from '@holoflows/kit/es'
import type { ValueRef } from '@holoflows/kit/es'
import { useValueRef } from '../../utils/hooks/useValueRef'
import { Typography } from '@material-ui/core'
import { useAsync } from 'react-use'
Expand All @@ -22,7 +22,7 @@ export function PersonKnown(props: PersonKnownProps) {
const state = useAsync(async () => {
if (!owner) return null
const profiles = await Services.Identity.queryMyProfiles(owner.network)
const myProfile = profiles.find(x => x.identifier.equals(owner))
const myProfile = profiles.find((x) => x.identifier.equals(owner))

if (bio && myProfile) {
const prove = await Services.Crypto.getMyProveBio(myProfile.identifier)
Expand Down