Skip to content

Commit ab071ea

Browse files
authored
Standardise repo per module template as of July 2023 (#115)
* Standardise repo per module template as of July 2023 * Fix some package-specific configs * Remove pull request template * Add pull request template again * Formatting
1 parent 68384c6 commit ab071ea

File tree

13 files changed

+1237
-565
lines changed

13 files changed

+1237
-565
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,3 @@ Are there any issues or other links reviewers should consult to understand this
99
* Fixes #12345
1010
* See: #67890
1111
-->
12-
13-
## Examples
14-
15-
<!--
16-
Are there any examples of this change being used in another repository?
17-
18-
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.
19-
-->

.github/workflows/build-lint-test.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
- name: Install Yarn dependencies
1818
run: yarn --immutable
1919

20-
build:
21-
name: Build
20+
build-source:
21+
name: Build source
2222
runs-on: ubuntu-latest
2323
needs:
2424
- prepare
@@ -33,8 +33,34 @@ jobs:
3333
node-version: ${{ matrix.node-version }}
3434
cache: 'yarn'
3535
- run: yarn --immutable --immutable-cache
36-
- run: yarn build
37-
# This step is dependent on the build output, so it's run here, rather than in the test job.
36+
- run: yarn build:source
37+
- name: Require clean working directory
38+
shell: bash
39+
run: |
40+
if ! git diff --exit-code; then
41+
echo "Working tree dirty at end of job"
42+
exit 1
43+
fi
44+
45+
build-types:
46+
name: Build types
47+
runs-on: ubuntu-latest
48+
needs:
49+
- prepare
50+
strategy:
51+
matrix:
52+
node-version: [16.x, 18.x, 20.x]
53+
steps:
54+
- uses: actions/checkout@v3
55+
- name: Use Node.js ${{ matrix.node-version }}
56+
uses: actions/setup-node@v3
57+
with:
58+
node-version: ${{ matrix.node-version }}
59+
cache: 'yarn'
60+
- run: yarn --immutable --immutable-cache
61+
- run: yarn build:types
62+
# This step is dependent on the TypeScript build output, so it's run
63+
# here, rather than in the test job.
3864
- run: yarn test:types
3965
- name: Require clean working directory
4066
shell: bash

.github/workflows/create-release-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: actions/setup-node@v3
3434
with:
3535
node-version-file: '.nvmrc'
36-
- uses: MetaMask/action-create-release-pr@v1
36+
- uses: MetaMask/action-create-release-pr@v2
3737
env:
3838
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3939
with:

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ jobs:
7474
secrets:
7575
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
7676
PUBLISH_DOCS_TOKEN: ${{ secrets.PUBLISH_DOCS_TOKEN }}
77+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/publish-release.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
secrets:
66
NPM_TOKEN:
77
required: true
8+
SLACK_WEBHOOK_URL:
9+
required: true
810
PUBLISH_DOCS_TOKEN:
911
required: true
1012

@@ -21,7 +23,7 @@ jobs:
2123
uses: actions/setup-node@v3
2224
with:
2325
node-version-file: '.nvmrc'
24-
- uses: MetaMask/action-publish-release@v2
26+
- uses: MetaMask/action-publish-release@v3
2527
env:
2628
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2729
- name: Install
@@ -52,7 +54,10 @@ jobs:
5254
key: ${{ github.sha }}
5355
- name: Dry Run Publish
5456
# omit npm-token token to perform dry run publish
55-
uses: MetaMask/action-npm-publish@v2
57+
uses: MetaMask/action-npm-publish@v4
58+
with:
59+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
60+
subteam: S042S7RE4AE # @metamask-npm-publishers
5661
env:
5762
SKIP_PREPACK: true
5863

.swcrc.build.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://json.schemastore.org/swcrc",
3+
"jsc": {
4+
"parser": {
5+
"syntax": "typescript"
6+
},
7+
"target": "es2020"
8+
},
9+
"sourceMaps": true,
10+
"exclude": [
11+
".*__fixtures__.*",
12+
".*__mocks__.*",
13+
".*__snapshots__.*",
14+
".*__tests?__.*",
15+
".*\\.test\\.?.*\\.tsx?",
16+
".*\\.d\\.tsx?"
17+
]
18+
}

.yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module.exports = {
44
name: "@yarnpkg/plugin-allow-scripts",
55
factory: function (require) {
6-
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;})();
6+
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);})();
77
return plugin;
88
}
99
};

constraints.pro

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,18 @@ gen_enforced_field(WorkspaceCwd, 'repository.url', 'https://github.com/MetaMask/
6565
% The license for the package must be specified.
6666
gen_enforced_field(WorkspaceCwd, 'license').
6767

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

71-
% The type definitions entrypoint the package must be `./dist/index.d.ts`.
72-
gen_enforced_field(WorkspaceCwd, 'types', './dist/index.d.ts').
71+
% The entrypoint for the package must be `./dist/cjs/index.js`.
72+
gen_enforced_field(WorkspaceCwd, 'main', './dist/cjs/index.js').
73+
74+
% The module entrypoint for the package must be `./dist/esm/index.js`.
75+
gen_enforced_field(WorkspaceCwd, 'module', './dist/esm/index.js').
7376

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

7881
% If a dependency is listed under "dependencies", it should not be listed under
7982
% "devDependencies".

package.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,28 @@
1111
"url": "https://github.com/MetaMask/utils.git"
1212
},
1313
"license": "ISC",
14-
"main": "./dist/index.js",
15-
"types": "./dist/index.d.ts",
14+
"main": "./dist/cjs/index.js",
15+
"module": "./dist/esm/index.js",
16+
"types": "./dist/types/index.d.ts",
1617
"files": [
17-
"dist/"
18+
"dist/cjs/**",
19+
"dist/esm/**",
20+
"dist/types/**"
1821
],
1922
"scripts": {
20-
"build": "tsc --project tsconfig.build.json",
23+
"build": "yarn build:source && yarn build:types",
24+
"build:cjs": "swc src --out-dir dist/cjs --config-file .swcrc.build.json --config module.type=commonjs",
2125
"build:clean": "rimraf dist && yarn build",
2226
"build:docs": "typedoc",
23-
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog && yarn lint:constraints",
27+
"build:esm": "swc src --out-dir dist/esm --config-file .swcrc.build.json --config module.type=es6",
28+
"build:source": "yarn build:esm && yarn build:cjs",
29+
"build:types": "tsc --project tsconfig.build.json",
30+
"lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog",
2431
"lint:changelog": "auto-changelog validate",
2532
"lint:constraints": "yarn constraints",
2633
"lint:dependencies": "depcheck && yarn dedupe",
2734
"lint:eslint": "eslint . --cache --ext js,ts",
28-
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog && yarn lint:constraints --fix",
35+
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
2936
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
3037
"prepack": "./scripts/prepack.sh",
3138
"test": "yarn test:source && yarn test:types",
@@ -45,13 +52,15 @@
4552
"superstruct": "^1.0.3"
4653
},
4754
"devDependencies": {
48-
"@lavamoat/allow-scripts": "^2.0.3",
55+
"@lavamoat/allow-scripts": "^2.3.1",
4956
"@lavamoat/preinstall-always-fail": "^1.0.0",
5057
"@metamask/auto-changelog": "^3.1.0",
5158
"@metamask/eslint-config": "^11.0.1",
5259
"@metamask/eslint-config-jest": "^11.0.0",
5360
"@metamask/eslint-config-nodejs": "^11.0.1",
5461
"@metamask/eslint-config-typescript": "^11.0.0",
62+
"@swc/cli": "^0.1.62",
63+
"@swc/core": "^1.3.66",
5564
"@types/jest": "^28.1.7",
5665
"@types/node": "^17.0.23",
5766
"@typescript-eslint/eslint-plugin": "^5.43.0",
@@ -86,7 +95,8 @@
8695
},
8796
"lavamoat": {
8897
"allowScripts": {
89-
"@lavamoat/preinstall-always-fail": false
98+
"@lavamoat/preinstall-always-fail": false,
99+
"@swc/core": true
90100
}
91101
},
92102
"tsd": {

scripts/get.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env bash
22

3-
set -x
43
set -e
54
set -u
65
set -o pipefail
76

7+
if [[ ${RUNNER_DEBUG:-0} == 1 ]]; then
8+
set -x
9+
fi
10+
811
KEY="${1}"
912
OUTPUT="${2}"
1013

0 commit comments

Comments
 (0)