Repository navigation
[TS migration] Setup typescript in expensify-common & Migrate CONST, fastMerge, Device, Logger to Typescript #699
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
Merged
roryabraham
merged 28 commits into
Expensify:main
from
blazejkustra:ts/configure-typescript
May 27, 2024
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
91d752f
Install deps, change configuration, add scripts to package.json
blazejkustra 3d910ce
Ignore dist
blazejkustra ddfc91e
Adjust prettier and eslint ignore files
blazejkustra b981ab4
Prepare eslint config
blazejkustra 479c9cf
Prepare tsconfigs
blazejkustra 243308a
Add prettier and typecheks workflows
blazejkustra e85751d
Migrate CONST
blazejkustra 3914542
Add endlines
blazejkustra 1334540
Fix basic eslint errors
blazejkustra d31f093
Fix rest of the eslint issues
blazejkustra eb6f98b
Run prettier
blazejkustra a5b8bb7
Add babel to tests to enable Typescript
blazejkustra 1df5b90
Migrate Logger to TS
blazejkustra 78b719e
Migrate Device to TS
blazejkustra d12063c
Remove Logger.d.ts
blazejkustra 55933f5
Migrate fastMerge to TS
blazejkustra 35b4683
Fix fastMerge types
blazejkustra 2c983a1
Create missing index.ts file
blazejkustra cfc6b0a
Adjust after review
blazejkustra 8516cd9
Merge branch 'main' into ts/configure-typescript
blazejkustra 4bbd354
Add Error to Logger parameters type
blazejkustra fda1a9b
Merge branch 'main' into ts/configure-typescript
blazejkustra aab8898
Fix es/no-nullish-coalescing eslint rule
blazejkustra 229b2f3
Remove return from a Logger constructor
blazejkustra a19fc65
Configure you-dont-need-lodash-underscore eslint plugin
blazejkustra 5ad4e37
Add publish workflow from react-native-onyx
blazejkustra 163f4e6
Ignore gpg and .tgz files
blazejkustra cfaa9f2
Update readme
blazejkustra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| *.d.ts | ||
| dist | ||
| node_modules | ||
| *.config.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,80 @@ | ||
| module.exports = { | ||
| extends: ['expensify', 'prettier'], | ||
| rules: { | ||
| // Allow JSX to be written in any file ignoring the extension type | ||
| 'react/jsx-filename-extension': 'off' | ||
| }, | ||
| plugins: ['jest'], | ||
| env: { | ||
| "jest/globals": true | ||
| } | ||
| parser: '@typescript-eslint/parser', | ||
| overrides: [ | ||
| { | ||
| files: ['*.js', '*.jsx'], | ||
| settings: { | ||
| 'import/resolver': { | ||
| node: { | ||
| extensions: ['.js', '.jsx', '.ts', '.tsx'], | ||
| }, | ||
| }, | ||
| }, | ||
| rules: { | ||
| // Allow JSX to be written in any file ignoring the extension type | ||
| 'react/jsx-filename-extension': 'off', | ||
| 'rulesdir/no-api-in-views': 'off', | ||
| 'rulesdir/no-multiple-api-calls': 'off', | ||
| 'rulesdir/prefer-import-module-contents': 'off', | ||
| 'no-constructor-return': 'off', | ||
| 'import/extensions': [ | ||
| 'error', | ||
| 'ignorePackages', | ||
| { | ||
| js: 'never', | ||
| jsx: 'never', | ||
| ts: 'never', | ||
| tsx: 'never', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| files: ['*.ts', '*.tsx'], | ||
| extends: [ | ||
| 'expensify', | ||
| 'plugin:@typescript-eslint/recommended', | ||
| 'plugin:@typescript-eslint/stylistic', | ||
| 'plugin:import/typescript', | ||
| 'plugin:you-dont-need-lodash-underscore/all', | ||
| 'prettier', | ||
| 'plugin:prettier/recommended', | ||
| ], | ||
| plugins: ['react', 'import', '@typescript-eslint'], | ||
| parserOptions: { | ||
| project: './tsconfig.json', | ||
| }, | ||
| rules: { | ||
| 'prefer-regex-literals': 'off', | ||
| 'rulesdir/prefer-underscore-method': 'off', | ||
| 'react/jsx-props-no-spreading': 'off', | ||
| 'react/require-default-props': 'off', | ||
| 'valid-jsdoc': 'off', | ||
| 'es/no-optional-chaining': 'off', | ||
| 'es/no-nullish-coalescing-operators': 'off', | ||
|
blazejkustra marked this conversation as resolved.
|
||
| 'react/jsx-filename-extension': ['error', {extensions: ['.tsx', '.jsx']}], | ||
| 'import/no-unresolved': 'error', | ||
| 'import/consistent-type-specifier-style': ['error', 'prefer-top-level'], | ||
| 'no-use-before-define': 'off', | ||
| '@typescript-eslint/no-use-before-define': 'off', | ||
| '@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}], | ||
| '@typescript-eslint/consistent-type-imports': ['error', {prefer: 'type-imports'}], | ||
| '@typescript-eslint/consistent-type-exports': ['error', {fixMixedExportsWithInlineTypeSpecifier: false}], | ||
| '@typescript-eslint/no-non-null-assertion': 'off', | ||
| '@typescript-eslint/array-type': ['error', {default: 'array-simple'}], | ||
| '@typescript-eslint/consistent-type-definitions': 'off', | ||
| 'import/extensions': [ | ||
| 'error', | ||
| 'ignorePackages', | ||
| { | ||
| js: 'never', | ||
| jsx: 'never', | ||
| ts: 'never', | ||
| tsx: 'never', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| name: Publish package to npmjs | ||
|
|
||
| # This workflow runs when code is pushed to `main` (i.e: when a pull request is merged) | ||
| on: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| # Ensure that only once instance of this workflow executes at a time. | ||
| # If multiple PRs are merged in quick succession, there will only ever be one publish workflow running and one pending. | ||
| concurrency: ${{ github.workflow }} | ||
|
|
||
| jobs: | ||
| version: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| # OSBotify will update the version on `main`, so this check is important to prevent an infinite loop | ||
| if: ${{ github.actor != 'OSBotify' }} | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
| # The OS_BOTIFY_COMMIT_TOKEN is a personal access token tied to osbotify, which allows him to push to protected branches | ||
| token: ${{ secrets.OS_BOTIFY_COMMIT_TOKEN }} | ||
|
|
||
| - name: Decrypt & Import OSBotify GPG key | ||
| run: | | ||
| cd .github | ||
| gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output OSBotify-private-key.asc OSBotify-private-key.asc.gpg | ||
| gpg --import OSBotify-private-key.asc | ||
| env: | ||
| LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }} | ||
|
|
||
| - name: Set up git for OSBotify | ||
| run: | | ||
| git config --global user.signingkey 367811D53E34168C | ||
| git config --global commit.gpgsign true | ||
| git config --global user.name OSBotify | ||
| git config --global user.email infra+osbotify@expensify.com | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Install npm packages | ||
| run: npm ci | ||
|
|
||
| - name: Update npm version | ||
| run: npm version patch | ||
|
|
||
| - name: Set new version in GitHub ENV | ||
| run: echo "NEW_VERSION=$(jq '.version' package.json)" >> $GITHUB_ENV | ||
|
|
||
| - name: Push branch and publish tags | ||
| run: git push origin main && git push --tags | ||
|
|
||
| - name: Build package | ||
| run: npm run build | ||
|
|
||
| - name: Publish to npm | ||
| run: npm publish | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
||
| - name: Get merged pull request | ||
| id: getMergedPullRequest | ||
| run: | | ||
| read -r number < <(gh pr list --search ${{ github.sha }} --state merged --json 'number' | jq -r '.[0] | [.number] | join(" ")') | ||
| echo "number=$number" >> "$GITHUB_OUTPUT" | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
|
|
||
| - name: Comment on merged pull request | ||
| run: gh pr comment ${{ steps.getMergedPullRequest.outputs.number }} --body "🚀Published to npm in v${{ env.NEW_VERSION }}" | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: TypeScript Checks | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize] | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| cache: npm | ||
| cache-dependency-path: package-lock.json | ||
|
|
||
| - run: npm ci | ||
|
|
||
| - name: Type check with TypeScript | ||
| run: npm run typecheck | ||
| env: | ||
| CI: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 20.13.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| dist | ||
| package.json | ||
| package-lock.json | ||
| *.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,3 @@ | ||
| module.exports = { | ||
| presets: [ | ||
| [ | ||
| '@babel/preset-env', | ||
| { | ||
| targets: { | ||
| node: 'current', | ||
| }, | ||
| }, | ||
| ], | ||
| ], | ||
| presets: [['@babel/preset-env', {targets: {node: 'current'}}], '@babel/preset-typescript'], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.