Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Typescript migration + standardization #140

Merged
merged 14 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 10 additions & 0 deletions .depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ignores": [
"@lavamoat/allow-scripts",
"@metamask/auto-changelog",
"@types/*",
"prettier-plugin-packagejson",
"ts-node",
"typedoc"
]
}
35 changes: 25 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
module.exports = {
HowardBraham marked this conversation as resolved.
Show resolved Hide resolved
root: true,
parser: '@typescript-eslint/parser',
HowardBraham marked this conversation as resolved.
Show resolved Hide resolved
extends: ['@metamask/eslint-config', '@metamask/eslint-config-nodejs'],
env: {
commonjs: true,
},

overrides: [
{
mikesposito marked this conversation as resolved.
Show resolved Hide resolved
files: ['test/**/*.js'],
files: ['**/*.test.ts'],
extends: ['@metamask/eslint-config-jest'],
rules: {
'node/no-unpublished-require': 0,
mcmire marked this conversation as resolved.
Show resolved Hide resolved
},
},
],
rules: {
camelcase: [
'error',
{
allow: ['signTypedData_v1', 'signTypedData_v3', 'signTypedData_v4'],

settings: {
HowardBraham marked this conversation as resolved.
Show resolved Hide resolved
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
],
},
node: {
tryExtensions: ['.js', '.json', '.node', '.ts'],
},
},

// This is necessary to run eslint on Windows and not get a thousand CRLF errors
mcmire marked this conversation as resolved.
Show resolved Hide resolved
rules: { 'prettier/prettier': ['error', { endOfLine: 'auto' }] },
mcmire marked this conversation as resolved.
Show resolved Hide resolved

ignorePatterns: [
'!.eslintrc.js',
'!.prettierrc.js',
'dist/**/*',
'jest.config.ts',
],
};
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ yarn.lock linguist-generated=false
# yarn v3
# See: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
/.yarn/releases/** binary
/.yarn/plugins/** binary
/.yarn/plugins/** binary
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?

Are there any issues or other links reviewers should consult to understand this pull request better? For instance:

* Fixes #12345
* See: #67890
-->

## Examples
HowardBraham marked this conversation as resolved.
Show resolved Hide resolved

<!--
Are there any examples of this change being used in another repository?

When considering changes to the MetaMask module template, it's strongly preferred that the change be experimented with in another repository first. This gives reviewers a better sense of how the change works, making it less likely the change will need to be reverted or adjusted later.
-->
25 changes: 25 additions & 0 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ jobs:
- name: Install Yarn dependencies
run: yarn --immutable

build:
name: Build
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 19.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn build
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi

lint:
name: Lint
runs-on: ubuntu-latest
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ jobs:
fi

is-release:
# release merge commits come from github-actions
if: startsWith(github.event.commits[0].author.name, 'github-actions')
# Filtering by `push` events ensures that we only release from the `main` branch, which is a
# requirement for our npm publishing environment.
# The commit author should always be 'github-actions' for releases created by the
# 'create-release-pr' workflow, so we filter by that as well to prevent accidentally
# triggering a release.
if: github.event_name == 'push' && startsWith(github.event.head_commit.author.name, 'github-actions')
needs: all-jobs-pass
outputs:
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish docs to GitHub Pages

on:
workflow_call:
inputs:
destination_dir:
required: true
type: string

jobs:
publish-docs-to-gh-pages:
name: Publish docs to GitHub Pages
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Ensure `destination_dir` is not empty
if: ${{ inputs.destination_dir == '' }}
run: exit 1
- name: Checkout the repository
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install npm dependencies
run: yarn --immutable
- name: Run build script
run: yarn build:docs
- name: Deploy to `${{ inputs.destination_dir }}` directory of `gh-pages` branch
uses: peaceiris/actions-gh-pages@de7ea6f8efb354206b205ef54722213d99067935
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
destination_dir: ${{ inputs.destination_dir }}
14 changes: 14 additions & 0 deletions .github/workflows/publish-main-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Publish main branch docs to GitHub Pages

on:
push:
branches: main

jobs:
publish-to-gh-pages:
name: Publish docs to `staging` directory of `gh-pages` branch
permissions:
contents: write
uses: ./.github/workflows/publish-docs.yml
with:
destination_dir: staging
26 changes: 26 additions & 0 deletions .github/workflows/publish-rc-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish release candidate docs to GitHub Pages

on:
push:
branches: 'release/**'

jobs:
get-release-version:
name: Get release version
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.release-name.outputs.RELEASE_VERSION }}
steps:
- name: Extract release version from branch name
id: release-name
run: |
BRANCH_NAME='${{ github.ref_name }}'
echo "RELEASE_VERSION=v${BRANCH_NAME#release/}" >> "$GITHUB_OUTPUT"
publish-to-gh-pages:
name: Publish docs to `rc-${{ needs.get-release-version.outputs.release-version }}` directory of `gh-pages` branch
permissions:
contents: write
uses: ./.github/workflows/publish-docs.yml
needs: get-release-version
with:
destination_dir: rc-${{ needs.get-release-version.outputs.release-version }}
56 changes: 56 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ jobs:
- uses: MetaMask/action-publish-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install
run: |
yarn install
yarn build
- uses: actions/cache@v3
id: restore-build
with:
path: |
./dist
./node_modules/.yarn-state.yml
key: ${{ github.sha }}

publish-npm-dry-run:
runs-on: ubuntu-latest
Expand All @@ -30,6 +41,13 @@ jobs:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- uses: actions/cache@v3
id: restore-build
with:
path: |
./dist
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Dry Run Publish
# omit npm-token token to perform dry run publish
uses: MetaMask/action-npm-publish@v2
Expand All @@ -44,6 +62,13 @@ jobs:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- uses: actions/cache@v3
id: restore-build
with:
path: |
./dist
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Publish
uses: MetaMask/action-npm-publish@v2
with:
Expand All @@ -52,3 +77,34 @@ jobs:
npm-token: ${{ secrets.NPM_TOKEN }}
env:
SKIP_PREPACK: true

get-release-version:
runs-on: ubuntu-latest
needs: publish-npm
outputs:
RELEASE_VERSION: ${{ steps.get-release-version.outputs.RELEASE_VERSION }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- id: get-release-version
shell: bash
run: ./scripts/get.sh ".version" "RELEASE_VERSION"

publish-release-to-gh-pages:
needs: get-release-version
name: Publish docs to `${{ needs.get-release-version.outputs.RELEASE_VERSION }}` directory of `gh-pages` branch
permissions:
contents: write
uses: ./.github/workflows/publish-docs.yml
with:
destination_dir: ${{ needs.get-release-version.outputs.RELEASE_VERSION }}

publish-release-to-latest-gh-pages:
needs: publish-npm
name: Publish docs to `latest` directory of `gh-pages` branch
permissions:
contents: write
uses: ./.github/workflows/publish-docs.yml
with:
destination_dir: latest
68 changes: 57 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,71 @@
# Dependency directories
node_modules/
.DS_Store
dist/
coverage/
docs/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# ESLint
.eslintcache
# Yarn Integrity file
.yarn-integrity

# Jest
/coverage
# dotenv environment variables file
.env
.env.test

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v3 (w/o zero-install)
# See: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v12
v16
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
mikesposito marked this conversation as resolved.
Show resolved Hide resolved
"recommendations": ["rvest.vs-code-prettier-eslint"]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint",
"editor.tabSize": 2,
"files.trimTrailingWhitespace": true,
"javascript.preferences.importModuleSpecifier": "relative"
}
Loading