Skip to content

Commit

Permalink
Revert "Build examples by running yarn build in each example (#448)" (#…
Browse files Browse the repository at this point in the history
…456)

This reverts #448, which caused builds to fail on release PRs because running `yarn install` in a individual examples attempted to pull unpublished monorepo packages from the npm registry.
  • Loading branch information
rekmarks authored May 14, 2022
1 parent eb27474 commit 2d84b43
Show file tree
Hide file tree
Showing 16 changed files with 381 additions and 27,883 deletions.
4 changes: 1 addition & 3 deletions packages/examples/examples/bls-signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
"snap.manifest.json"
],
"scripts": {
"test": "echo 'Error: no test specified' && exit 1",
"build": "mm-snap build"
"test": "echo 'Error: no test specified' && exit 1"
},
"dependencies": {
"eth-json-rpc-errors": "^1.1.0",
"mm-snap": "file:../../../cli",
"noble-bls12-381": "^0.2.3"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/bls-signer/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": "OU2yp0gPLBuPKznOIjG3Oz0N47213xHmUsC08nl09BE=",
"shasum": "n5/s5K66duQVo/8Rz+ajmeqx8+y9pRKezjZXG9K4xd4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
5,578 changes: 12 additions & 5,566 deletions packages/examples/examples/bls-signer/yarn.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions packages/examples/examples/ethers-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
"snap.manifest.json"
],
"scripts": {
"test": "echo 'Error: no test specified' && exit 1",
"build": "mm-snap build"
"test": "echo 'Error: no test specified' && exit 1"
},
"dependencies": {
"ethers": "^5.4.6",
"mm-snap": "file:../../../cli"
"ethers": "^5.4.6"
},
"engines": {
"node": ">=14.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/ethers-js/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": "XrWHHxhRL7jbQ2p2iJQ2i3QxWfo8FL99lHAZ8j6ce1c=",
"shasum": "h3V7LGvxmyPPdbQDoB4JA2aEqejW9B0saUNwIsGAr4w=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
5,632 changes: 79 additions & 5,553 deletions packages/examples/examples/ethers-js/yarn.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions packages/examples/examples/ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
"snap.manifest.json"
],
"scripts": {
"test": "echo 'Error: no test specified' && exit 1",
"build": "mm-snap build"
"test": "echo 'Error: no test specified' && exit 1"
},
"dependencies": {
"eth-json-rpc-errors": "^1.1.0",
"mm-snap": "file:../../../cli",
"uuid": "^8.3.2"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/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": "tR2vu2otHZd9KrdEhl5kqYqLFxNdYZl/TURFMi+qTgE=",
"shasum": "vQsxeddY3CaV9cbdFd9PXI9NgKhVSUWs0mR133rc15Q=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
5,565 changes: 8 additions & 5,557 deletions packages/examples/examples/ipfs/yarn.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions packages/examples/examples/notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:changelog": "yarn auto-changelog validate"
},
"dependencies": {
"mm-snap": "file:../../../cli"
},
"engines": {
"node": ">=14.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snap-template.git"
},
"source": {
"shasum": "fq/XEzLmIId2mKFGvQfusaGe77gq7qs9nNR6ClE0Kx4=",
"shasum": "qw0jI3Eutkzwd1Z8QPKG2YVPEgJjlyGqKSpEK/P2VBM=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
5,553 changes: 0 additions & 5,553 deletions packages/examples/examples/notifications/yarn.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/examples/examples/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"test": "echo 'Error: no test specified' && exit 1"
},
"dependencies": {
"eth-rpc-errors": "^4.0.3",
"mm-snap": "file:../../../cli"
"eth-rpc-errors": "^4.0.3"
},
"devDependencies": {
"assemblyscript": "^0.19.23",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/wasm/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": "l8hGjAv8a60vw57+aCKBtlgIhDwyY87yBWCLX3sWgQQ=",
"shasum": "VLp0VAJsonEmZvjoaxa3F+n0VwBbBgYPxm2aQos3rIU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
5,791 changes: 214 additions & 5,577 deletions packages/examples/examples/wasm/yarn.lock

Large diffs are not rendered by default.

115 changes: 58 additions & 57 deletions packages/examples/scripts/buildExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,78 @@ const { resolve: pathResolve } = require('path');

const execa = require('execa');

const SNAPS_CLI_BIN_PATH = '../../../cli/dist/main.js';

const EXAMPLES_PATH = 'examples';

buildExamples();

async function buildExamples() {
const examplesDir = await fs.readdir(EXAMPLES_PATH);

// Check all examples and install dependencies sequentially
const examples = await examplesDir.reduce(async (promise, exampleFile) => {
const array = await promise;

const exampleFilePath = pathResolve(EXAMPLES_PATH, exampleFile);
const exampleFileStat = await fs.stat(exampleFilePath);

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

if (!pkgStat.isFile() || !srcStat.isDirectory()) {
throw new Error(
`Invalid example directory "${exampleFile}". Ensure it has valid 'package.json' and 'index.js' files.`,
);
}
await Promise.all(
examplesDir.map(async (exampleFile) => {
const exampleFilePath = pathResolve(EXAMPLES_PATH, exampleFile);
const exampleFileStat = await fs.stat(exampleFilePath);

try {
// install dependencies
await execa('yarn', ['install'], {
cwd: exampleFilePath,
});
} catch (depsInstallError) {
console.error(
`Unexpected error when installing dependencies in "${exampleFilePath}.`,
);
throw depsInstallError;
}
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);

return [...array, exampleFilePath];
}
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;
}

return array;
}, Promise.resolve([]));
// Some examples needs certain operations to run before it can be built
try {
await execa('yarn', ['prebuild'], {
cwd: exampleFilePath,
});
} catch (err) {
if (!err.message.includes('Command "prebuild" not found')) {
console.error(
`Unexpected error when running prebuild in "${exampleFilePath}.`,
);
throw err;
}
}

// Build examples concurrently
await Promise.all(
examples.map(async (exampleFilePath) => {
// Some examples needs certain operations to run before it can be built
try {
await execa('yarn', ['prebuild'], {
cwd: exampleFilePath,
});
} catch (err) {
if (!err.message.includes('Command "prebuild" not found')) {
console.error(
`Unexpected error when running prebuild in "${exampleFilePath}.`,
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 err;
}
}

try {
await execa('yarn', ['build'], {
cwd: exampleFilePath,
});
} catch (bundleError) {
console.error(
`Unexpected error while creating bundle in "${exampleFilePath}.`,
);
throw bundleError;
}
}),
);
}

0 comments on commit 2d84b43

Please sign in to comment.