@metamask/snaps-cli 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/dist/cmds/eval/eval-worker.js +2 -2
- package/dist/cmds/eval/eval-worker.js.map +1 -1
- package/dist/cmds/eval/workerEval.js +1 -1
- package/dist/cmds/eval/workerEval.js.map +1 -1
- package/dist/cmds/init/index.js +1 -1
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/init-template.json +1 -1
- package/dist/utils/misc.js +18 -0
- package/dist/utils/misc.js.map +1 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.4.0]
|
|
10
|
+
### Fixed
|
|
11
|
+
- Make Windows-compatible ([#131](https://github.com/MetaMask/snaps-skunkworks/pull/131))
|
|
12
|
+
|
|
13
|
+
## [0.3.1]
|
|
14
|
+
### Changed
|
|
15
|
+
- No changes this release.
|
|
16
|
+
|
|
17
|
+
## [0.3.0]
|
|
18
|
+
### Changed
|
|
19
|
+
- **BREAKING:** Enforce consistent naming for Snaps-related functionality ([#119](https://github.com/MetaMask/snaps-skunkworks/pull/119))
|
|
20
|
+
|
|
21
|
+
## [0.2.2]
|
|
22
|
+
### Fixed
|
|
23
|
+
- Package script issues ([#97](https://github.com/MetaMask/snaps-skunkworks/pull/97), [#98](https://github.com/MetaMask/snaps-skunkworks/pull/98))
|
|
24
|
+
|
|
9
25
|
## [0.2.1]
|
|
10
26
|
### Fixed
|
|
11
27
|
- Snap produced by `mm-snap init` ([#94](https://github.com/MetaMask/snaps-skunkworks/pull/94))
|
|
@@ -29,7 +45,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
29
45
|
- Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
|
|
30
46
|
- The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
|
|
31
47
|
|
|
32
|
-
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.
|
|
48
|
+
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.4.0...HEAD
|
|
49
|
+
[0.4.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.3.1...v0.4.0
|
|
50
|
+
[0.3.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.3.0...v0.3.1
|
|
51
|
+
[0.3.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.2.2...v0.3.0
|
|
52
|
+
[0.2.2]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.2.1...v0.2.2
|
|
33
53
|
[0.2.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.2.0...v0.2.1
|
|
34
54
|
[0.2.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.1.1...v0.2.0
|
|
35
55
|
[0.1.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.1.0...v0.1.1
|
|
@@ -15,8 +15,8 @@ lockdown({
|
|
|
15
15
|
});
|
|
16
16
|
if (worker_threads_1.parentPort !== null) {
|
|
17
17
|
worker_threads_1.parentPort.on('message', (message) => {
|
|
18
|
-
const {
|
|
19
|
-
new Compartment(getMockEndowments()).evaluate(fs_1.readFileSync(
|
|
18
|
+
const { snapFilePath } = message;
|
|
19
|
+
new Compartment(getMockEndowments()).evaluate(fs_1.readFileSync(snapFilePath, 'utf8'));
|
|
20
20
|
setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;;;;AAAA,mCAAsC;AACtC,mDAA4C;AAC5C,2BA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AN,gBAAM;QACN,IAAI;QACJ,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;QACjB,IAAI;QACJ,MAAM,EAAE,mBAAmB,EAAE;QAC7B,UAAU;QACV,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;QAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;QACrB,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;KAC3B,CAAC;IAEF,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,IAClB;AACJ,CAAC","sourcesContent":["import { EventEmitter } from 'events';\nimport { parentPort } from 'worker_threads';\nimport { readFileSync } from 'fs';\nimport crypto from 'crypto';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\ndeclare let lockdown: any, Compartment: any;\n\ntype MockSnapProvider = EventEmitter & {\n registerRpcMessageHandler: () => any;\n request: () => Promise<any>;\n};\n\nlockdown({\n mathTaming: 'unsafe',\n errorTaming: 'unsafe',\n});\n\nif (parentPort !== null) {\n parentPort.on('message', (message: { snapFilePath: string }) => {\n const { snapFilePath } = message;\n\n new Compartment(getMockEndowments()).evaluate(\n readFileSync(snapFilePath, 'utf8'),\n );\n setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n });\n}\n\nfunction getMockSnapProvider(): MockSnapProvider {\n const mockProvider = new EventEmitter() as Partial<MockSnapProvider>;\n mockProvider.registerRpcMessageHandler = () => true;\n mockProvider.request = async () => true;\n return mockProvider as MockSnapProvider;\n}\n\nfunction getMockEndowments() {\n const endowments = {\n BigInt,\n Buffer,\n console,\n crypto,\n Date,\n fetch: () => true,\n Math,\n wallet: getMockSnapProvider(),\n setTimeout,\n SubtleCrypto: () => undefined,\n WebSocket: () => true,\n XMLHttpRequest: () => true,\n };\n\n return {\n ...endowments,\n window: endowments,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerEval.js","sourceRoot":"","sources":["../../../src/cmds/eval/workerEval.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAwC;AACxC,gDAA6B;AAE7B,SAAgB,UAAU,CAAC,UAAkB;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,uBAAM,CAAC,iBAAiB,EAAE,CAAC;aAC5B,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YAC/B,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,CAAC,IAAI,CAAC,CAAC;aACf;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;aAChE;QACH,CAAC,CAAC;aACD,WAAW,CAAC;YACX,
|
|
1
|
+
{"version":3,"file":"workerEval.js","sourceRoot":"","sources":["../../../src/cmds/eval/workerEval.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAwC;AACxC,gDAA6B;AAE7B,SAAgB,UAAU,CAAC,UAAkB;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,uBAAM,CAAC,iBAAiB,EAAE,CAAC;aAC5B,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YAC/B,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,CAAC,IAAI,CAAC,CAAC;aACf;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;aAChE;QACH,CAAC,CAAC;aACD,WAAW,CAAC;YACX,YAAY,EAAE,UAAU;SACzB,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AAdD,gCAcC;AAED;;GAEG;AACH,SAAS,iBAAiB;IACxB,OAAO,cAAS,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { Worker } from 'worker_threads';\nimport pathUtils from 'path';\n\nexport function workerEval(bundlePath: string): Promise<null> {\n return new Promise((resolve) => {\n new Worker(getEvalWorkerPath())\n .on('exit', (exitCode: number) => {\n if (exitCode === 0) {\n resolve(null);\n } else {\n throw new Error(`Worker exited abnormally! Code: ${exitCode}`);\n }\n })\n .postMessage({\n snapFilePath: bundlePath,\n });\n });\n}\n\n/**\n * @returns The path to the eval worker file.\n */\nfunction getEvalWorkerPath(): string {\n return pathUtils.join(__dirname, 'eval-worker.js');\n}\n"]}
|
package/dist/cmds/init/index.js
CHANGED
|
@@ -9,7 +9,7 @@ async function init(argv) {
|
|
|
9
9
|
console.log();
|
|
10
10
|
const newArgs = await initHandler_1.initHandler(argv);
|
|
11
11
|
await buildHandler_1.build(Object.assign(Object.assign({}, newArgs), { manifest: false, eval: true }));
|
|
12
|
-
console.log('\
|
|
12
|
+
console.log('\nSnap project successfully initiated!');
|
|
13
13
|
}
|
|
14
14
|
module.exports = {
|
|
15
15
|
command: ['init', 'i'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAe5C,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,MAAM,OAAO,GAAG,MAAM,yBAAW,CAAC,IAAI,CAAC,CAAC;IAExC,MAAM,oBAAK,iCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAe5C,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,MAAM,OAAO,GAAG,MAAM,yBAAW,CAAC,IAAI,CAAC,CAAC;IAExC,MAAM,oBAAK,iCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,CAAC;AAxBD,iBAAS;IACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC;IACtB,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC","sourcesContent":["import yargs from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler } from './initHandler';\n\nexport = {\n command: ['init', 'i'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('port', builders.port);\n },\n handler: (argv: YargsArgs) => init(argv),\n};\n\nasync function init(argv: YargsArgs): Promise<void> {\n console.log();\n const newArgs = await initHandler(argv);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n console.log('\\nSnap project successfully initiated!');\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"html": "<!doctype html>\n\n<html>\n\n </head>\n <title>Hello Snaps!</title>\n </head>\n\n <body>\n <h1>Hello Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The Snap <b>package.json</b> must be located in located in the server root directory\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by <b>package.json:web3Wallet.bundle.url</b>\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n\n // we identify the Snap by the location of its package.json file\n const snapId = new URL('package.json', window.location.href).toString()\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the
|
|
2
|
+
"html": "<!doctype html>\n\n<html>\n\n </head>\n <title>Hello Snaps!</title>\n </head>\n\n <body>\n <h1>Hello Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The Snap <b>package.json</b> must be located in located in the server root directory\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by <b>package.json:web3Wallet.bundle.url</b>\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n\n // we identify the Snap by the location of its package.json file\n const snapId = new URL('package.json', window.location.href).toString()\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the snap\n async function connect () {\n await ethereum.request({\n method: 'wallet_enable',\n params: [{\n wallet_snap: { [snapId]: {} },\n }]\n })\n }\n\n // here we call the snap's \"hello\" method\n async function send () {\n try {\n const response = await ethereum.request({\n method: 'wallet_invokeSnap',\n params: [snapId, {\n method: 'hello'\n }]\n })\n } catch (err) {\n console.error(err)\n alert('Problem happened: ' + err.message || err)\n }\n }\n\n </script>\n\n</html>\n",
|
|
3
3
|
"js": "wallet.registerRpcMessageHandler(async (originString, requestObject) => {\n switch (requestObject.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [`Hello, ${originString}!`],\n });\n default:\n throw new Error('Method not found.');\n }\n});\n"
|
|
4
4
|
}
|
package/dist/utils/misc.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.trimPathString = exports.writeError = exports.logWarning = exports.logError = exports.sanitizeInputs = exports.setSnapGlobals = exports.CONFIG_PATHS = exports.permRequestKeys = void 0;
|
|
4
7
|
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
5
9
|
exports.permRequestKeys = [
|
|
6
10
|
'@context',
|
|
7
11
|
'id',
|
|
@@ -12,6 +16,17 @@ exports.permRequestKeys = [
|
|
|
12
16
|
'proof',
|
|
13
17
|
];
|
|
14
18
|
exports.CONFIG_PATHS = ['snap.config.json'];
|
|
19
|
+
// CLI arguments whose values are file paths
|
|
20
|
+
const pathArguments = new Set([
|
|
21
|
+
'src',
|
|
22
|
+
's',
|
|
23
|
+
'dist',
|
|
24
|
+
'd',
|
|
25
|
+
'bundle',
|
|
26
|
+
'b',
|
|
27
|
+
'root',
|
|
28
|
+
'r',
|
|
29
|
+
]);
|
|
15
30
|
/**
|
|
16
31
|
* Sets global variable snaps which tracks user settings:
|
|
17
32
|
* watch mode activation, verbose errors messages, and whether to suppress warnings.
|
|
@@ -46,6 +61,9 @@ function sanitizeInputs(argv) {
|
|
|
46
61
|
if (argv[key] === './') {
|
|
47
62
|
argv[key] = '.';
|
|
48
63
|
}
|
|
64
|
+
if (pathArguments.has(key)) {
|
|
65
|
+
argv[key] = path_1.default.normalize(argv[key]);
|
|
66
|
+
}
|
|
49
67
|
}
|
|
50
68
|
});
|
|
51
69
|
}
|
package/dist/utils/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AAGX,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,YAAY,GAAG,CAAC,kBAAkB,CAAC,CAAC;AACjD,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,KAAK;IACL,GAAG;IACH,MAAM;IACN,GAAG;IACH,QAAQ;IACR,GAAG;IACH,MAAM;IACN,GAAG;CACJ,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,IAAe;IAC5C,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAW,CAAC,EAAE;QAChD,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;KAChC;SAAM;QACL,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;KACjC;IAED,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE;QAC/D,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KAC1D;IAED,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,EAAE;QAClE,MAAM,CAAC,KAAK,CAAC,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,gBAAgB,C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AAe,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACzB,eAAe,IAAI,GAAG,CAAC;KACxB;IAED,QAAQ,CAAC,eAAe,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IACrC,IAAI;QACF,IAAI,YAAY,EAAE;YAChB,MAAM,aAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;SACvC;KACF;IAAC,OAAO,WAAW,EAAE;QACpB,QAAQ,CAAC,GAAG,eAAe,gCAAgC,EAAE,WAAW,CAAC,CAAC;KAC3E;IAED,qCAAqC;IACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE;QAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AAxBD,gCAwBC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,UAAkB;IAC/C,OAAO,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import { promises as filesystem } from 'fs';\nimport path from 'path';\nimport { Arguments } from 'yargs';\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_PATHS = ['snap.config.json'];\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress warnings.\n *\n * @param {Argument} argv - arguments as an object generated by yargs\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (Object.prototype.hasOwnProperty.call(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = Boolean(argv.verboseErrors);\n }\n\n if (Object.prototype.hasOwnProperty.call(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = Boolean(argv.suppressWarnings);\n }\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param {Argument} argv - arguments as an object generated by yargs\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param msg - The error message\n * @param err - The original error\n */\nexport function logError(msg: string, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and exits.\n *\n * @param prefix - The message prefix\n * @param msg - The error message\n * @param err - The original error\n * @param destFilePath - The output file path\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns - The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,9 +19,11 @@
|
|
|
19
19
|
"build:typescript": "tsc --project ./tsconfig.local.json",
|
|
20
20
|
"build:chmod": "chmod +x ./dist/main.js",
|
|
21
21
|
"build": "yarn build:init-template && yarn build:typescript && yarn build:chmod",
|
|
22
|
-
"build:clean": "yarn
|
|
22
|
+
"build:clean": "yarn clean && yarn build",
|
|
23
|
+
"clean": "rimraf dist/*",
|
|
23
24
|
"test": "jest",
|
|
24
25
|
"test:watch": "jest --watch",
|
|
26
|
+
"test:ci": "yarn test",
|
|
25
27
|
"lint:changelog": "yarn auto-changelog validate",
|
|
26
28
|
"lint:eslint": "eslint . --cache --ext js,ts",
|
|
27
29
|
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
|