Skip to content

Commit

Permalink
Fix build and publish scripts (#169)
Browse files Browse the repository at this point in the history
While publishing `0.6.0`, I discovered a number of issues with the package-wide build and publishing scripts. This PR fixes these issues by adding a `build:pre-tsc` and `build:post-tsc` script to each package, and ensuring that these get executed for each package in the correct order at the time of publishing.
  • Loading branch information
rekmarks authored Dec 17, 2021
1 parent d5cdc91 commit 8d2b219
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 92 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
],
"scripts": {
"setup": "yarn install && yarn allow-scripts",
"publish:all": "yarn setup && yarn workspaces run publish",
"publish:all": "./scripts/publish-all.sh",
"link-packages": "./scripts/link-packages.sh",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
"lint:changelogs": "yarn workspaces run lint:changelog",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"build:tsc": "tsc --build --force tsconfig.json",
"build:pre-tsc": "yarn workspace @metamask/snap-controllers run build:pre-tsc",
"build:post-tsc": "yarn workspace @metamask/snap-workers run build:post-tsc",
"build": "yarn build:pre-tsc && yarn build:tsc && yarn build:post-tsc",
"build:clean": "yarn workspaces run clean && yarn build",
"build": "yarn workspaces run build:pre-tsc && yarn build:tsc && yarn workspaces run build:post-tsc",
"build:clean": "yarn clean && yarn build",
"clean": "yarn workspaces run clean",
"test": "yarn workspaces run test",
"test:ci": "yarn workspaces run test:ci"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"test": "yarn test:prepare && jest",
"test:ci": "yarn test:prepare && ./scripts/test-ci.sh",
"build:pre-tsc": "yarn build:ajv && node scripts/transpileSchemaTypes.js",
"build:post-tsc": "echo 'N/A'",
"build:tsc": "tsc --project tsconfig.local.json",
"ajv-compile": "ajv compile --strict=true --all-errors",
"build:ajv": "./scripts/build-ajv.sh",
Expand All @@ -27,8 +28,7 @@
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:changelog": "yarn auto-changelog validate",
"publish": "../../scripts/publish-package.sh",
"publish:prep": "yarn lint && yarn build:clean"
"publish": "../../scripts/publish-package.sh"
},
"dependencies": {
"@metamask/controllers": "^17.0.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/example-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
"snap.manifest.json"
],
"scripts": {
"build": "mm-snap build",
"build": "node ../snaps-cli/dist/main.js build",
"build:clean": "yarn clean && yarn build",
"build:pre-tsc": "echo 'N/A'",
"build:post-tsc": "yarn build",
"clean": "rimraf dist/*",
"test": "echo \"@metamask/example-snap has no tests.\"",
"test": "echo 'N/A'",
"test:ci": "yarn test",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:changelog": "yarn auto-changelog validate",
"publish": "../../scripts/publish-package.sh",
"publish:prep": "yarn build:clean"
"publish": "../../scripts/publish-package.sh"
},
"devDependencies": {
"@metamask/auto-changelog": "^2.5.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/iframe-execution-environment-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:changelog": "yarn auto-changelog validate",
"build:tsc": "tsc --project tsconfig.json",
"build:post-tsc": "echo 'post-tsc-iframe-execution-env'",
"build": "yarn build:tsc && yarn build:post-tsc",
"build": "yarn build:tsc",
"build:pre-tsc": "echo 'N/A'",
"build:post-tsc": "echo 'N/A'",
"build:clean": "yarn clean && yarn build",
"clean": "rimraf dist/*",
"publish": "../../scripts/publish-package.sh",
"publish:prep": "yarn lint && yarn build:clean"
"publish": "../../scripts/publish-package.sh"
},
"dependencies": {
"@metamask/controllers": "^17.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/rpc-methods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
"dist/"
],
"scripts": {
"test": "echo \"@metamask/rpc-methods has no tests.\"",
"test": "echo 'N/A'",
"test:ci": "yarn test",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:changelog": "yarn auto-changelog validate",
"build:pre-tsc": "echo 'N/A'",
"build:post-tsc": "echo 'N/A'",
"build": "tsc --project tsconfig.local.json",
"build:clean": "yarn clean && yarn build",
"clean": "rimraf dist/*",
"publish": "../../scripts/publish-package.sh",
"publish:prep": "yarn lint && yarn build:clean"
"publish": "../../scripts/publish-package.sh"
},
"dependencies": {
"@metamask/key-tree": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap-examples/examples/bls-signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"snap.manifest.json"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo 'Error: no test specified' && exit 1"
},
"dependencies": {
"eth-json-rpc-errors": "^1.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-skunkworks.git"
},
"source": {
"shasum": "P8wkLLcyTh6qt1HHxYA3WrBvwot3G9QHfYUHJp6VSFk=",
"shasum": "gbEjrhR+Q39xUlngLKJ0w/8q5ucHdKTx7Q8xqmRf8Mk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap-examples/examples/ethers-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"snap.manifest.json"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo 'Error: no test specified' && exit 1"
},
"dependencies": {
"ethers": "^5.4.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-skunkworks.git"
},
"source": {
"shasum": "TYPwBSP8KRqXUWiH0V/rqx9H2HXWhIMOo73F/0jEryY=",
"shasum": "dF1UV3/wsSWbOLorgsTxxMfC5VTCvZV+UawSY9VSZCk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap-examples/examples/ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"snap.manifest.json"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo 'Error: no test specified' && exit 1"
},
"dependencies": {
"eth-json-rpc-errors": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap-examples/examples/ipfs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-skunkworks.git"
},
"source": {
"shasum": "V2AbL1M0/2eZINuZb1pT8AKcxW3VwcefrCxYsWRyWgk=",
"shasum": "MCWDvknLHxnCp5VVXXb5HAONnM76FduHJF+AmC7mrOE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
11 changes: 6 additions & 5 deletions packages/snap-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
],
"scripts": {
"setup": "yarn install && yarn allow-scripts",
"test": "echo \"@metamask/snap-examples has no tests.\"",
"test": "echo 'N/A'",
"test:ci": "yarn test",
"lint:changelog": "yarn auto-changelog validate",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"build": "node ./scripts/buildExamples.js",
"build:clean": "echo \"@metamask/snap-examples has no build:clean command.\"",
"clean": "echo \"@metamask/snap-examples has no clean command.\"",
"publish": "../../scripts/publish-package.sh",
"publish:prep": "yarn lint && yarn build:clean"
"build:pre-tsc": "echo 'N/A'",
"build:post-tsc": "yarn build",
"build:clean": "echo 'N/A'",
"clean": "echo 'N/A'",
"publish": "../../scripts/publish-package.sh"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^1.0.5",
Expand Down
92 changes: 48 additions & 44 deletions packages/snap-examples/scripts/buildExamples.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
const { promises: fs } = require('fs');
const { resolve, join: pathJoin } = require('path');
const { resolve: pathResolve } = require('path');

const execa = require('execa');

const SNAPS_CLI_BIN_PATH = pathJoin(
__dirname,
'../../../node_modules/@metamask/snaps-cli/dist/main.js',
);
const SNAPS_CLI_BIN_PATH = '../../../snaps-cli/dist/main.js';

const EXAMPLES_PATH = 'examples';

Expand All @@ -15,48 +12,55 @@ buildExamples();
async function buildExamples() {
const examplesDir = await fs.readdir(EXAMPLES_PATH);

examplesDir.forEach(async (exampleFile) => {
const exampleFilePath = resolve(EXAMPLES_PATH, exampleFile);
const exampleFileStat = await fs.stat(exampleFilePath);

if (exampleFileStat.isDirectory()) {
const srcPath = resolve(exampleFilePath, 'index.js');
const pkgPath = resolve(exampleFilePath, 'package.json');
const pkgStat = await fs.stat(pkgPath);
const srcStat = await fs.stat(srcPath);

if (pkgStat.isFile() && srcStat.isFile()) {
try {
// install dependencies
await execa('yarn', ['install'], {
cwd: exampleFilePath,
});
} catch (depsInstallError) {
console.error(
`Unexpected error when installing dependencies in "${exampleFilePath}.`,
);
throw depsInstallError;
}
await Promise.all(
examplesDir.map(async (exampleFile) => {
const exampleFilePath = pathResolve(EXAMPLES_PATH, exampleFile);
const exampleFileStat = await fs.stat(exampleFilePath);

if (exampleFileStat.isDirectory()) {
const srcPath = pathResolve(exampleFilePath, 'src/index.js');
const pkgPath = pathResolve(exampleFilePath, 'package.json');
const pkgStat = await fs.stat(pkgPath);
const srcStat = await fs.stat(srcPath);

try {
await execa(
SNAPS_CLI_BIN_PATH,
['build', '--sourceMaps', '--stripComments'],
{
if (pkgStat.isFile() && srcStat.isFile()) {
try {
// install dependencies
await execa('yarn', ['install'], {
cwd: exampleFilePath,
},
);
} catch (bundleError) {
console.error(
`Unexpected error while creating bundle in "${exampleFilePath}.`,
});
} catch (depsInstallError) {
console.error(
`Unexpected error when installing dependencies in "${exampleFilePath}.`,
);
throw depsInstallError;
}

try {
await execa(
'node',
[
pathResolve(exampleFilePath, SNAPS_CLI_BIN_PATH),
'build',
'--sourceMaps',
'--stripComments',
],
{
cwd: exampleFilePath,
},
);
} catch (bundleError) {
console.error(
`Unexpected error while creating bundle in "${exampleFilePath}.`,
);
throw bundleError;
}
} else {
throw new Error(
`Invalid example directory "${exampleFile}". Ensure it has valid 'package.json' and 'index.js' files.`,
);
throw bundleError;
}
} else {
throw new Error(
`Invalid example directory "${exampleFile}". Ensure it has valid 'package.json' and 'index.js' files.`,
);
}
}
});
}),
);
}
11 changes: 6 additions & 5 deletions packages/snaps-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@
"scripts": {
"setup": "yarn install && yarn allow-scripts",
"shasum": "node ./scripts/computeSnapShasum.js",
"build:init-template": "node ./scripts/createInitTemplate.js",
"build:init-template": "node ./scripts/createInitTemplate.js && yarn prettier --check src/cmds/init/init-template.json",
"build:typescript": "tsc --project ./tsconfig.local.json",
"build:chmod": "chmod +x ./dist/main.js",
"build": "yarn build:init-template && yarn build:typescript && yarn build:chmod",
"build:pre-tsc": "echo 'N/A'",
"build:post-tsc": "./scripts/publish-prep.sh",
"build:clean": "yarn clean && yarn build",
"build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
"clean": "rimraf dist/*",
"test": "jest",
"test:watch": "jest --watch",
"test": "yarn build:init-template && jest",
"test:watch": "yarn test --watch",
"test:ci": "yarn test",
"lint:changelog": "yarn auto-changelog validate",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"publish": "../../scripts/publish-package.sh",
"publish:prep": "./scripts/publish-prep.sh"
"publish": "../../scripts/publish-package.sh"
},
"dependencies": {
"@metamask/snap-controllers": "^0.6.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/snaps-cli/scripts/publish-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ set -e
set -u
set -o pipefail

yarn build:clean
yarn build:init-template
yarn build:chmod

if [[ $(git diff --quiet) != '' ]]; then
echo "Working tree dirty after building"
exit 1
fi

yarn lint
13 changes: 7 additions & 6 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
"index.d.ts"
],
"scripts": {
"build": "echo \"@metamask/snap-types has no build command.\"",
"build:clean": "echo \"@metamask/snap-types has no build:clean command.\"",
"clean": "echo \"@metamask/snap-types has no clean command.\"",
"test": "echo \"@metamask/snap-types has no tests.\"",
"build": "echo 'N/A'",
"build:clean": "echo 'N/A'",
"build:pre-tsc": "echo 'N/A'",
"build:post-tsc": "echo 'N/A'",
"clean": "echo 'N/A'",
"test": "echo 'N/A'",
"test:ci": "yarn test",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:changelog": "yarn auto-changelog validate",
"publish": "../../scripts/publish-package.sh",
"publish:prep": "yarn lint"
"publish": "../../scripts/publish-package.sh"
},
"dependencies": {
"@metamask/controllers": "^17.0.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
"dist/"
],
"scripts": {
"test": "echo \"@metamask/snap-workers has no tests.\"",
"test": "echo 'N/A'",
"test:ci": "yarn test",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:changelog": "yarn auto-changelog validate",
"build": "yarn build:tsc && yarn build:post-tsc",
"build:tsc": "tsc --project tsconfig.local.json",
"build:pre-tsc": "echo 'N/A'",
"build:post-tsc": "node bundle.js",
"build": "yarn build:tsc && yarn build:post-tsc",
"build:clean": "yarn clean && yarn build",
"clean": "rimraf dist/*",
"publish": "../../scripts/publish-package.sh",
"publish:prep": "yarn lint && yarn build:clean"
"publish": "../../scripts/publish-package.sh"
},
"devDependencies": {
"@metamask/inpage-provider": "^8.0.3",
Expand Down
Loading

0 comments on commit 8d2b219

Please sign in to comment.