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

Standardise repo per module template as of July 2023 #115

Merged
merged 5 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 0 additions & 8 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ Are there any issues or other links reviewers should consult to understand this
* Fixes #12345
* See: #67890
-->

## Examples
Mrtenz 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.
-->
34 changes: 30 additions & 4 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
- name: Install Yarn dependencies
run: yarn --immutable

build:
name: Build
build-source:
name: Build source
runs-on: ubuntu-latest
needs:
- prepare
Expand All @@ -33,8 +33,34 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn build
# This step is dependent on the build output, so it's run here, rather than in the test job.
- run: yarn build:source
- 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

build-types:
name: Build types
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [16.x, 18.x, 20.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:types
# This step is dependent on the TypeScript build output, so it's run
# here, rather than in the test job.
- run: yarn test:types
- name: Require clean working directory
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- uses: MetaMask/action-create-release-pr@v1
- uses: MetaMask/action-create-release-pr@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ jobs:
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PUBLISH_DOCS_TOKEN: ${{ secrets.PUBLISH_DOCS_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
9 changes: 7 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
secrets:
NPM_TOKEN:
required: true
SLACK_WEBHOOK_URL:
required: true
PUBLISH_DOCS_TOKEN:
required: true

Expand All @@ -21,7 +23,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- uses: MetaMask/action-publish-release@v2
- uses: MetaMask/action-publish-release@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install
Expand Down Expand Up @@ -52,7 +54,10 @@ jobs:
key: ${{ github.sha }}
- name: Dry Run Publish
# omit npm-token token to perform dry run publish
uses: MetaMask/action-npm-publish@v2
uses: MetaMask/action-npm-publish@v4
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
subteam: S042S7RE4AE # @metamask-npm-publishers
env:
SKIP_PREPACK: true

Expand Down
18 changes: 18 additions & 0 deletions .swcrc.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2020"
},
"sourceMaps": true,
"exclude": [
".*__fixtures__.*",
".*__mocks__.*",
".*__snapshots__.*",
".*__tests?__.*",
".*\\.test\\.?.*\\.tsx?",
".*\\.d\\.tsx?"
]
}
2 changes: 1 addition & 1 deletion .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = {
name: "@yarnpkg/plugin-allow-scripts",
factory: function (require) {
var plugin=(()=>{var a=Object.create,l=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty;var u=e=>l(e,"__esModule",{value:!0});var f=e=>{if(typeof require!="undefined")return require(e);throw new Error('Dynamic require of "'+e+'" is not supported')};var g=(e,o)=>{for(var r in o)l(e,r,{get:o[r],enumerable:!0})},m=(e,o,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of s(o))!c.call(e,t)&&t!=="default"&&l(e,t,{get:()=>o[t],enumerable:!(r=i(o,t))||r.enumerable});return e},x=e=>m(u(l(e!=null?a(p(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var k={};g(k,{default:()=>d});var n=x(f("@yarnpkg/shell")),y={hooks:{afterAllInstalled:async()=>{let e=await(0,n.execute)("yarn run allow-scripts");e!==0&&process.exit(e)}}},d=y;return k;})();
var plugin=(()=>{var l=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var p=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(o,e)=>(typeof require<"u"?require:o)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var u=(t,o)=>{for(var e in o)l(t,e,{get:o[e],enumerable:!0})},f=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of a(o))!c.call(t,i)&&i!==e&&l(t,i,{get:()=>o[i],enumerable:!(r=s(o,i))||r.enumerable});return t};var m=t=>f(l({},"__esModule",{value:!0}),t);var g={};u(g,{default:()=>d});var n=p("@yarnpkg/shell"),x={hooks:{afterAllInstalled:async()=>{let t=await(0,n.execute)("yarn run allow-scripts");t!==0&&process.exit(t)}}},d=x;return m(g);})();
return plugin;
}
};
13 changes: 8 additions & 5 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ gen_enforced_field(WorkspaceCwd, 'repository.url', 'https://github.com/MetaMask/
% The license for the package must be specified.
gen_enforced_field(WorkspaceCwd, 'license').

% The entrypoint for the package must be `./dist/index.js`.
gen_enforced_field(WorkspaceCwd, 'main', './dist/index.js').
% The type definitions entrypoint the package must be `./dist/types/index.d.ts`.
gen_enforced_field(WorkspaceCwd, 'types', './dist/types/index.d.ts').

% The type definitions entrypoint the package must be `./dist/index.d.ts`.
gen_enforced_field(WorkspaceCwd, 'types', './dist/index.d.ts').
% The entrypoint for the package must be `./dist/cjs/index.js`.
gen_enforced_field(WorkspaceCwd, 'main', './dist/cjs/index.js').

% The module entrypoint for the package must be `./dist/esm/index.js`.
gen_enforced_field(WorkspaceCwd, 'module', './dist/esm/index.js').

% The list of files included in the package must only include files generated
% during the build step.
gen_enforced_field(WorkspaceCwd, 'files', ['dist/']).
gen_enforced_field(WorkspaceCwd, 'files', ['dist/cjs/**', 'dist/esm/**', 'dist/types/**']).

% If a dependency is listed under "dependencies", it should not be listed under
% "devDependencies".
Expand Down
26 changes: 18 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@
"url": "https://github.com/MetaMask/utils.git"
},
"license": "ISC",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"files": [
"dist/"
"dist/cjs/**",
"dist/esm/**",
"dist/types/**"
],
"scripts": {
"build": "tsc --project tsconfig.build.json",
"build": "yarn build:source && yarn build:types",
"build:cjs": "swc src --out-dir dist/cjs --config-file .swcrc.build.json --config module.type=commonjs",
"build:clean": "rimraf dist && yarn build",
"build:docs": "typedoc",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog && yarn lint:constraints",
"build:esm": "swc src --out-dir dist/esm --config-file .swcrc.build.json --config module.type=es6",
"build:source": "yarn build:esm && yarn build:cjs",
"build:types": "tsc --project tsconfig.build.json",
"lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog",
"lint:changelog": "auto-changelog validate",
"lint:constraints": "yarn constraints",
"lint:dependencies": "depcheck && yarn dedupe",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog && yarn lint:constraints --fix",
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepack": "./scripts/prepack.sh",
"test": "yarn test:source && yarn test:types",
Expand All @@ -45,13 +52,15 @@
"superstruct": "^1.0.3"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.0.3",
"@lavamoat/allow-scripts": "^2.3.1",
"@lavamoat/preinstall-always-fail": "^1.0.0",
"@metamask/auto-changelog": "^3.1.0",
"@metamask/eslint-config": "^11.0.1",
"@metamask/eslint-config-jest": "^11.0.0",
"@metamask/eslint-config-nodejs": "^11.0.1",
"@metamask/eslint-config-typescript": "^11.0.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.66",
"@types/jest": "^28.1.7",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.43.0",
Expand Down Expand Up @@ -86,7 +95,8 @@
},
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false
"@lavamoat/preinstall-always-fail": false,
"@swc/core": true
}
},
"tsd": {
Expand Down
5 changes: 4 additions & 1 deletion scripts/get.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env bash

set -x
set -e
set -u
set -o pipefail

if [[ ${RUNNER_DEBUG:-0} == 1 ]]; then
set -x
fi

KEY="${1}"
OUTPUT="${2}"

Expand Down
1 change: 0 additions & 1 deletion scripts/prepack.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash

set -x
set -e
set -o pipefail

Expand Down
14 changes: 12 additions & 2 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"inlineSources": true,
"noEmit": false,
"outDir": "dist",
"outDir": "dist/types",
"rootDir": "src",
"sourceMap": true
},
"include": ["./src/**/*.ts"],
"exclude": ["./src/**/*.test.ts"]
"exclude": [
"./src/**/__fixtures__/**/*",
"./src/**/__mocks__/**/*",
"./src/**/__test__/**/*",
"./src/**/__tests__/**/*",
"./src/**/__snapshots__/**/*",
"./src/**/*.test.ts",
"./src/**/*.test.*.ts"
]
}
Loading