Skip to content

Commit

Permalink
Standardise repo per module template as of April 2023 (#102)
Browse files Browse the repository at this point in the history
* Standardise repo per module template as of April 2023

* Fix test script

* Fix test workflow

* Add further standardisation
  • Loading branch information
Mrtenz authored Apr 26, 2023
1 parent b217ca1 commit d4a9d2e
Show file tree
Hide file tree
Showing 17 changed files with 1,360 additions and 310 deletions.
11 changes: 11 additions & 0 deletions .depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ignores": [
"@lavamoat/allow-scripts",
"@lavamoat/preinstall-always-fail",
"@metamask/auto-changelog",
"@types/*",
"prettier-plugin-packagejson",
"ts-node",
"typedoc"
]
}
3 changes: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ module.exports = {
{
files: ['*.ts'],
extends: ['@metamask/eslint-config-typescript'],
rules: {
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
},
},

{
Expand Down
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* text=auto

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
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

<!--
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.
-->
8 changes: 4 additions & 4 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- prepare
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 19.x]
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -34,7 +34,7 @@ jobs:
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.
# This step is dependent on the 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 All @@ -51,7 +51,7 @@ jobs:
- prepare
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 19.x]
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
- prepare
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 19.x]
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
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 @@ -8,7 +8,7 @@ on:
default: 'main'
required: true
release-type:
description: 'A SemVer version diff, i.e. major, minor, patch, prerelease etc. Mutually exclusive with "release-version".'
description: 'A SemVer version diff, i.e. major, minor, or patch. Mutually exclusive with "release-version".'
required: false
release-version:
description: 'A specific version to bump to. Mutually exclusive with "release-type".'
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14
v16
52 changes: 52 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-constraints.cjs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
enableScripts: false

enableTelemetry: 0

logFilters:
- code: YN0004
level: discard
Expand All @@ -8,6 +10,8 @@ nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js'
spec: "https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js"
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
spec: "@yarnpkg/plugin-constraints"

yarnPath: .yarn/releases/yarn-3.2.3.cjs
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ The full API documentation for the latest published version of this library is [

### Setup

- Install [Node.js](https://nodejs.org) version 12
- Install [Node.js](https://nodejs.org) version 16
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
- Install [Yarn v1](https://yarnpkg.com/en/docs/install)
- Run `yarn setup` to install dependencies and run any required post-install scripts
- **Warning:** Do not use the `yarn` / `yarn install` command directly. Use `yarn setup` instead. The normal install command will skip required post-install scripts, leaving your development environment in an invalid state.
- Install [Yarn v3](https://yarnpkg.com/getting-started/install)
- Run `yarn install` to install dependencies and run any required post-install scripts

### Testing and Linting

Expand Down
91 changes: 91 additions & 0 deletions constraints.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
%===============================================================================
% Utility predicates
%===============================================================================

% True if RepoName can be unified with the repository name part of RepoUrl, a
% complete URL for a repository on GitHub. This URL must include the ".git"
% extension.
repo_name(RepoUrl, RepoName) :-
Prefix = 'https://github.com/MetaMask/',
atom_length(Prefix, PrefixLength),
Suffix = '.git',
atom_length(Suffix, SuffixLength),
atom_length(RepoUrl, RepoUrlLength),
sub_atom(RepoUrl, 0, PrefixLength, After, Prefix),
sub_atom(RepoUrl, Before, SuffixLength, 0, Suffix),
Start is RepoUrlLength - After + 1,
End is Before + 1,
RepoNameLength is End - Start,
sub_atom(RepoUrl, PrefixLength, RepoNameLength, SuffixLength, RepoName).

%===============================================================================
% Constraints
%===============================================================================

% The package must have a name.
\+ gen_enforced_field(WorkspaceCwd, 'name', null).

% The package must have a description.
\+ gen_enforced_field(WorkspaceCwd, 'description', null).
% The description cannot end with a period.
gen_enforced_field(WorkspaceCwd, 'description', DescriptionWithoutTrailingPeriod) :-
workspace_field(WorkspaceCwd, 'description', Description),
atom_length(Description, Length),
LengthLessOne is Length - 1,
sub_atom(Description, LengthLessOne, 1, 0, LastCharacter),
sub_atom(Description, 0, LengthLessOne, 1, DescriptionWithoutPossibleTrailingPeriod),
(
LastCharacter == '.' ->
DescriptionWithoutTrailingPeriod = DescriptionWithoutPossibleTrailingPeriod ;
DescriptionWithoutTrailingPeriod = Description
).

% The homepage of the package must match its name (which is in turn based on its
% workspace directory name).
gen_enforced_field(WorkspaceCwd, 'homepage', CorrectHomepageUrl) :-
workspace_field(WorkspaceCwd, 'repository.url', RepoUrl),
repo_name(RepoUrl, RepoName),
atomic_list_concat(['https://github.com/MetaMask/', RepoName, '#readme'], CorrectHomepageUrl).

% The bugs URL of the package must point to the Issues page for the repository.
gen_enforced_field(WorkspaceCwd, 'bugs.url', CorrectBugsUrl) :-
\+ workspace_field(WorkspaceCwd, 'private', true),
workspace_field(WorkspaceCwd, 'repository.url', RepoUrl),
repo_name(RepoUrl, RepoName),
atomic_list_concat(['https://github.com/MetaMask/', RepoName, '/issues'], CorrectBugsUrl).

% The package must specify Git as the repository type.
gen_enforced_field(WorkspaceCwd, 'repository.type', 'git').

% The package must match the URL of a repo within the MetaMask organization.
gen_enforced_field(WorkspaceCwd, 'repository.url', 'https://github.com/MetaMask/<insert repo name here>.git') :-
workspace_field(WorkspaceCwd, 'repository.url', RepoUrl),
\+ repo_name(RepoUrl, _).

% 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/index.d.ts`.
gen_enforced_field(WorkspaceCwd, 'types', './dist/index.d.ts').

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

% If a dependency is listed under "dependencies", it should not be listed under
% "devDependencies".
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, DependencyType) :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, 'dependencies'),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
DependencyType == 'devDependencies'.

% The package must specify a minimum Node version of 16.
gen_enforced_field(WorkspaceCwd, 'engines.node', '>=16.0.0').

% The package is public.
gen_enforced_field(WorkspaceCwd, 'publishConfig.access', 'public').
% The package is available on the NPM registry.
gen_enforced_field(WorkspaceCwd, 'publishConfig.registry', 'https://registry.npmjs.org/').
Loading

0 comments on commit d4a9d2e

Please sign in to comment.