From f826d620b4f753c7fc8dc902cf57c1b9fadbb756 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 4 Nov 2021 19:28:04 -0500 Subject: [PATCH 1/6] Start adding Typescript support --- .lintstagedrc.json | 1 + app/soapbox/utils/accounts.js | Bin 1883 -> 0 bytes app/soapbox/utils/accounts.ts | 73 +++++++++++++++++++++++ package.json | 6 +- tsconfig.json | 13 ++++ webpack/configuration.js | Bin 766 -> 789 bytes webpack/rules/babel.js | Bin 527 -> 693 bytes webpack/rules/index.js | Bin 544 -> 494 bytes webpack/shared.js | Bin 3493 -> 3609 bytes yarn.lock | 108 ++++++++++++++++++++++++++++++++-- 10 files changed, 193 insertions(+), 8 deletions(-) delete mode 100644 app/soapbox/utils/accounts.js create mode 100644 app/soapbox/utils/accounts.ts create mode 100644 tsconfig.json diff --git a/.lintstagedrc.json b/.lintstagedrc.json index 4e9b31be58..5dcd5926ae 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,4 +1,5 @@ { "*.js": "eslint --cache", + "*.ts": "eslint --cache", "app/styles/**/*.scss": "stylelint" } diff --git a/app/soapbox/utils/accounts.js b/app/soapbox/utils/accounts.js deleted file mode 100644 index 6970f005046c2a23a7b0665b57cc786c8381b2dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1883 zcmcIkO>f&U488kTu)qM>K;~}O7U{=O1Srs6T5OjfXjPj|HP})r$^BTG|2|5V;yB4R z48u-wB=WsSK8m7QC~aX0*L(roz-804mOs?!{;#0YssSeAAv;b)Ot=!p4l?|~zLca; zl49p*FI2;YoDk^On=2RtFACL43*!@5CID8y`Cou8qt$gElv94n=!j*<6bqoywpxP3 z7a+8hZnFGQ8S8FWP;gs32DA{#NIqR9tK%fWS6}y*vYstU>HM#9tG@KAN31qPM4@4J?O+_ zQDlJG_GYbYmVZ}5`sy}H3%WPC_LYG43pec!TUSRgIVjgC1mLkk~(}&sANsmP`)Kg*3%SOl%2y?AU z)Z8jP%Z+L{GditnsFQrH6Co-0{(Yi~SPT8VHS_GVpXu+5}?x@*})P%D46|@-): string => { + try { + const url = account.get('url'); + return new URL(url).host; + } catch { + return ''; + } +}; + +export const getDomain = (account: ImmutableMap): string => { + const domain = account.get('acct').split('@')[1]; + return domain ? domain : getDomainFromURL(account); +}; + +export const guessFqn = (account: ImmutableMap): string => { + const [user, domain] = account.get('acct').split('@'); + if (!domain) return [user, getDomainFromURL(account)].join('@'); + return account.get('acct'); +}; + +export const getBaseURL = (account: ImmutableMap): string => { + try { + const url = account.get('url'); + return new URL(url).origin; + } catch { + return ''; + } +}; + +// user@domain even for local users +export const acctFull = (account: ImmutableMap): string => ( + account.get('fqn') || guessFqn(account) +); + +export const getAcct = (account: ImmutableMap, displayFqn: boolean) :string => ( + displayFqn === true ? acctFull(account) : account.get('acct') +); + +export const isStaff = (account: ImmutableMap = ImmutableMap()): boolean => ( + [isAdmin, isModerator].some(f => f(account) === true) +); + +export const isAdmin = (account: ImmutableMap): boolean => ( + account.getIn(['pleroma', 'is_admin']) === true +); + +export const isModerator = (account: ImmutableMap): boolean => ( + account.getIn(['pleroma', 'is_moderator']) === true +); + +export const getFollowDifference = (state: ImmutableMap, accountId: string, type: string): number => { + const items: any = state.getIn(['user_lists', type, accountId, 'items'], ImmutableOrderedSet()); + const counter: number = Number(state.getIn(['accounts_counters', accountId, `${type}_count`], 0)); + return Math.max(counter - items.size, 0); +}; + +export const isLocal = (account: ImmutableMap): boolean => { + const domain: string = account.get('acct').split('@')[1]; + return domain === undefined ? true : false; +}; + +export const isRemote = (account: ImmutableMap): boolean => !isLocal(account); + +export const isVerified = (account: ImmutableMap): boolean => { + const tags: any = account.getIn(['pleroma', 'tags'], ImmutableList()); + return tags.includes('verified'); +}; diff --git a/package.json b/package.json index 5f45298400..dcb0fd4148 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "manage:translations": "node ./webpack/translationRunner.js", "test": "${npm_execpath} run test:lint && ${npm_execpath} run test:jest", "test:lint": "${npm_execpath} run test:lint:js && ${npm_execpath} run test:lint:sass", - "test:lint:js": "npx eslint --ext=js . --cache", + "test:lint:js": "npx eslint --ext .js,.jsx,.ts,.tsx . --cache", "test:lint:sass": "npx stylelint app/styles/**/*.scss", "test:jest": "npx jest --coverage", "prepare": "husky install" @@ -85,6 +85,7 @@ "escape-html": "^1.0.3", "exif-js": "^2.3.0", "feather-icons": "^4.28.0", + "fork-ts-checker-webpack-plugin": "^6.4.0", "html-webpack-harddisk-plugin": "^2.0.0", "html-webpack-plugin": "^5.3.2", "http-link-header": "^1.0.2", @@ -151,9 +152,10 @@ "terser-webpack-plugin": "^5.2.3", "tiny-queue": "^0.2.1", "ts-jest": "^27.0.5", + "ts-loader": "^9.2.6", "tslib": "^2.3.1", "twemoji": "https://github.com/twitter/twemoji#v13.0.2", - "typescript": "^4.0.3", + "typescript": "^4.4.4", "util": "^0.12.4", "uuid": "^8.3.2", "webpack": "^5.52.0", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..41f113e86c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "sourceMap": true, + "noImplicitAny": true, + "module": "es6", + "target": "es5", + "jsx": "react", + "allowJs": true, + "moduleResolution": "node", + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true + } +} diff --git a/webpack/configuration.js b/webpack/configuration.js index 960e25e60c64e6d268e42af2433b44c93c176d79..f2cc0c7fb736f385daa9563508300ffc5c3d9737 100644 GIT binary patch delta 31 hcmeyzI+blh1EWw@afP~$g1TNwF_fyFt+_RME0DV}V=s9dkFuaJ^ioS2l8s!&o{kgAZJk(!*HTBM+> zP@bw#o|%)QP+FX-kXfRTnWvDJUzDv-kW-qTna8C71tmp^dBp{pIjR16Ih9rlB}JvF gI#9`42m?x0Lq&7)6H`))tQ6Ff5|dJMfNr=C025R&umAu6 delta 13 VcmdnW+RrkfXX51flP@wp0RSmr26g}d diff --git a/webpack/rules/index.js b/webpack/rules/index.js index d3290659e816b9b03cc69aa38fd1122f406faa31..4c4fa6872fdbebeb6023b383d3bbc408156f9551 100644 GIT binary patch delta 11 ScmZ3$@{V~!2jk>jjA;NIa0G(@ delta 61 zcmaFIyntmx2cx0BzJgC;aY;_4jzU3EesXGYu|jc4Vo7GQLRw}{YOz9Tab{jRn5~eL NpO}(bG`XEI9RQ}o7CZm| diff --git a/webpack/shared.js b/webpack/shared.js index c7343f005178927c91728cbef6ddd727718fbaf1..a5d40711154ae5b4e4321d5987a2a85d89d65aa2 100644 GIT binary patch delta 99 zcmZ1~JyT}G9Y#~P{G#lTV&{z1=3.0.0 <4.0.0", chokidar@^3.5.1: +"chokidar@>=3.0.0 <4.0.0", chokidar@^3.4.2, chokidar@^3.5.1: version "3.5.2" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ== @@ -3631,6 +3652,14 @@ encodeurl@~1.0.2: resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= +enhanced-resolve@^5.0.0: + version "5.8.3" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.8.3.tgz#6d552d465cce0423f5b3d718511ea53826a7b2f0" + integrity sha512-EGAbGvH7j7Xt2nc0E7D99La1OiEs8LnyimkRgwExpUMScN6O+3x9tIWs7PLQZVNx4YD+00skHXPXi1yQHpAmZA== + dependencies: + graceful-fs "^4.2.4" + tapable "^2.2.0" + enhanced-resolve@^5.8.0: version "5.8.2" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz#15ddc779345cbb73e97c611cd00c01c1e7bf4d8b" @@ -4296,6 +4325,25 @@ foreach@^2.0.5: resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" integrity sha1-C+4AUBiusmDQo6865ljdATbsG5k= +fork-ts-checker-webpack-plugin@^6.4.0: + version "6.4.0" + resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-6.4.0.tgz#057e477cf1d8b013b2ed2669437f818680289c4c" + integrity sha512-3I3wFkc4DbzaUDPWEi96wdYGu4EKtxBafhZYm0o4mX51d9bphAY4P3mBl8K5mFXFJqVzHfmdbm9kLGnm7vwwBg== + dependencies: + "@babel/code-frame" "^7.8.3" + "@types/json-schema" "^7.0.5" + chalk "^4.1.0" + chokidar "^3.4.2" + cosmiconfig "^6.0.0" + deepmerge "^4.2.2" + fs-extra "^9.0.0" + glob "^7.1.6" + memfs "^3.1.2" + minimatch "^3.0.4" + schema-utils "2.7.0" + semver "^7.3.2" + tapable "^1.0.0" + form-data@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f" @@ -4457,6 +4505,18 @@ glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.1.6: + version "7.2.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" + integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + global-modules@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-2.0.0.tgz#997605ad2345f27f51539bea26574421215c7780" @@ -6424,6 +6484,13 @@ media-typer@0.3.0: resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= +memfs@^3.1.2: + version "3.3.0" + resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.3.0.tgz#4da2d1fc40a04b170a56622c7164c6be2c4cbef2" + integrity sha512-BEE62uMfKOavX3iG7GYX43QJ+hAeeWnwIAuJ/R6q96jaMtiLzhsxHJC8B1L7fK7Pt/vXDRwb3SG/yBpNGDPqzg== + dependencies: + fs-monkey "1.0.3" + memfs@^3.2.2: version "3.2.4" resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.2.4.tgz#1108c28d2e9137daf5a5586af856c3e18c1c64b2" @@ -6477,7 +6544,7 @@ micromark@~2.11.0: debug "^4.0.0" parse-entities "^2.0.0" -micromatch@^4.0.2, micromatch@^4.0.4: +micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4: version "4.0.4" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9" integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg== @@ -8519,6 +8586,15 @@ schema-utils@*, schema-utils@^3.0, schema-utils@^3.0.0, schema-utils@^3.1.0, sch ajv "^6.12.5" ajv-keywords "^3.5.2" +schema-utils@2.7.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.0.tgz#17151f76d8eae67fbbf77960c33c676ad9f4efc7" + integrity sha512-0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A== + dependencies: + "@types/json-schema" "^7.0.4" + ajv "^6.12.2" + ajv-keywords "^3.4.1" + schema-utils@^2.6.5, schema-utils@^2.6.6: version "2.7.1" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7" @@ -9195,6 +9271,11 @@ taffydb@2.6.2: resolved "https://registry.yarnpkg.com/taffydb/-/taffydb-2.6.2.tgz#7cbcb64b5a141b6a2efc2c5d2c67b4e150b2a268" integrity sha1-fLy2S1oUG2ou/CxdLGe04VCyomg= +tapable@^1.0.0: + version "1.1.3" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2" + integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA== + tapable@^2.0, tapable@^2.0.0, tapable@^2.1.1, tapable@^2.2.0: version "2.2.1" resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" @@ -9369,6 +9450,16 @@ ts-jest@^27.0.5: semver "7.x" yargs-parser "20.x" +ts-loader@^9.2.6: + version "9.2.6" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.2.6.tgz#9937c4dd0a1e3dbbb5e433f8102a6601c6615d74" + integrity sha512-QMTC4UFzHmu9wU2VHZEmWWE9cUajjfcdcws+Gh7FhiO+Dy0RnR1bNz0YCHqhI0yRowCE9arVnNxYHqELOy9Hjw== + dependencies: + chalk "^4.1.0" + enhanced-resolve "^5.0.0" + micromatch "^4.0.0" + semver "^7.3.4" + tsconfig-paths@^3.11.0: version "3.11.0" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.11.0.tgz#954c1fe973da6339c78e06b03ce2e48810b65f36" @@ -9472,11 +9563,16 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@^4.0, typescript@^4.0.3: +typescript@^4.0: version "4.4.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324" integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA== +typescript@^4.4.4: + version "4.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" + integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== + uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac" From f42754ad58b0a029457a856eeb73fe48e900829e Mon Sep 17 00:00:00 2001 From: Justin <867411-licatajustin@users.noreply.gitlab.com> Date: Thu, 27 Jan 2022 19:56:16 +0000 Subject: [PATCH 2/6] Apply 1 suggestion(s) to 1 file(s) --- app/soapbox/utils/accounts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/utils/accounts.ts b/app/soapbox/utils/accounts.ts index e3b7a7a560..361ecbc25e 100644 --- a/app/soapbox/utils/accounts.ts +++ b/app/soapbox/utils/accounts.ts @@ -38,7 +38,7 @@ export const acctFull = (account: ImmutableMap): string => ( account.get('fqn') || guessFqn(account) ); -export const getAcct = (account: ImmutableMap, displayFqn: boolean) :string => ( +export const getAcct = (account: ImmutableMap, displayFqn: boolean): string => ( displayFqn === true ? acctFull(account) : account.get('acct') ); From 134d92d83e266e264e8cd9e0e065533f985487d8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 19 Feb 2022 01:46:57 -0500 Subject: [PATCH 3/6] eslint: typescript --- .eslintrc.js | Bin 5723 -> 5831 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c12341232ef550d68f0bdcbbc66dbb75fded1b00..7ff1ba47871913384f005932c1691e52424380b3 100644 GIT binary patch delta 145 zcmcbub6j_Vu6;C@0uZRD7UyK Date: Sat, 19 Feb 2022 15:53:52 -0500 Subject: [PATCH 4/6] Typescript: IT WORKS --- babel.config.js | Bin 1383 -> 1410 bytes package.json | 1 + yarn.lock | 166 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 166 insertions(+), 1 deletion(-) diff --git a/babel.config.js b/babel.config.js index 1e167ead62d9d7978a94bd7d0eaa0096013f56f1..b9f7954d16bec2bfc98baea11afc821ba23b6644 100644 GIT binary patch delta 28 jcmaFP)x Date: Wed, 23 Feb 2022 14:56:16 -0500 Subject: [PATCH 5/6] Fix typescript imports --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index 41f113e86c..cead8687c1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "baseUrl": "app/", "sourceMap": true, "noImplicitAny": true, "module": "es6", From a6a87f6702de3ac25344d739dd60e82800ea84e9 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 23 Feb 2022 15:29:03 -0500 Subject: [PATCH 6/6] Convert Badge component to typescript --- app/soapbox/components/{badge.js => badge.tsx} | Bin 286 -> 291 bytes 1 file changed, 0 insertions(+), 0 deletions(-) rename app/soapbox/components/{badge.js => badge.tsx} (89%) diff --git a/app/soapbox/components/badge.js b/app/soapbox/components/badge.tsx similarity index 89% rename from app/soapbox/components/badge.js rename to app/soapbox/components/badge.tsx index 6185af97a30f7a50ac9b1bab58972e2ff4b51fee..b12ed768f5e0ed66d291e96d8e6eb50eff21fa9a 100644 GIT binary patch delta 15 WcmbQow3ul^2&>UQ$i&D~01<%$-T(jq