@metamask/snaps-cli 1.0.1 → 2.0.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/.browserslistrc +3 -0
- package/CHANGELOG.md +32 -372
- package/README.md +548 -69
- package/dist/cjs/builders.js +148 -0
- package/dist/cjs/builders.js.map +1 -0
- package/dist/cjs/cli.js +35 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/commands/build/build.js +54 -0
- package/dist/cjs/commands/build/build.js.map +1 -0
- package/dist/cjs/commands/build/implementation.js +31 -0
- package/dist/cjs/commands/build/implementation.js.map +1 -0
- package/dist/cjs/commands/build/index.js +45 -0
- package/dist/cjs/commands/build/index.js.map +1 -0
- package/dist/cjs/commands/eval/eval.js +57 -0
- package/dist/cjs/commands/eval/eval.js.map +1 -0
- package/dist/cjs/commands/eval/implementation.js +27 -0
- package/dist/cjs/commands/eval/implementation.js.map +1 -0
- package/dist/cjs/commands/eval/index.js +50 -0
- package/dist/cjs/commands/eval/index.js.map +1 -0
- package/dist/cjs/commands/index.js +30 -0
- package/dist/cjs/commands/index.js.map +1 -0
- package/dist/cjs/commands/manifest/implementation.js +34 -0
- package/dist/cjs/commands/manifest/implementation.js.map +1 -0
- package/dist/cjs/commands/manifest/index.js +50 -0
- package/dist/cjs/commands/manifest/index.js.map +1 -0
- package/dist/cjs/commands/manifest/manifest.js +55 -0
- package/dist/cjs/commands/manifest/manifest.js.map +1 -0
- package/dist/cjs/commands/serve/index.js +33 -0
- package/dist/cjs/commands/serve/index.js.map +1 -0
- package/dist/cjs/commands/serve/serve.js +21 -0
- package/dist/cjs/commands/serve/serve.js.map +1 -0
- package/dist/cjs/commands/watch/implementation.js +35 -0
- package/dist/cjs/commands/watch/implementation.js.map +1 -0
- package/dist/cjs/commands/watch/index.js +47 -0
- package/dist/cjs/commands/watch/index.js.map +1 -0
- package/dist/cjs/commands/watch/watch.js +51 -0
- package/dist/cjs/commands/watch/watch.js.map +1 -0
- package/dist/cjs/config.js +323 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/errors.js +37 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +77 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/main.js +19 -0
- package/dist/cjs/main.js.map +1 -0
- package/dist/cjs/utils/cli.js +61 -0
- package/dist/cjs/utils/cli.js.map +1 -0
- package/dist/cjs/utils/errors.js +42 -0
- package/dist/cjs/utils/errors.js.map +1 -0
- package/dist/cjs/utils/index.js +25 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/legacy.js +48 -0
- package/dist/cjs/utils/legacy.js.map +1 -0
- package/dist/cjs/utils/logging.js +46 -0
- package/dist/cjs/utils/logging.js.map +1 -0
- package/dist/cjs/utils/path.js +16 -0
- package/dist/cjs/utils/path.js.map +1 -0
- package/dist/cjs/utils/steps.js +52 -0
- package/dist/cjs/utils/steps.js.map +1 -0
- package/dist/cjs/webpack/compiler.js +96 -0
- package/dist/cjs/webpack/compiler.js.map +1 -0
- package/dist/cjs/webpack/config.js +239 -0
- package/dist/cjs/webpack/config.js.map +1 -0
- package/dist/cjs/webpack/index.js +22 -0
- package/dist/cjs/webpack/index.js.map +1 -0
- package/dist/cjs/webpack/loaders/browserify.js +97 -0
- package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
- package/dist/cjs/webpack/loaders/wasm.js +36 -0
- package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
- package/dist/cjs/webpack/plugins.js +340 -0
- package/dist/cjs/webpack/plugins.js.map +1 -0
- package/dist/cjs/webpack/utils.js +181 -0
- package/dist/cjs/webpack/utils.js.map +1 -0
- package/dist/{builders.js → esm/builders.js} +48 -51
- package/dist/esm/builders.js.map +1 -0
- package/dist/esm/cli.js +26 -0
- package/dist/esm/cli.js.map +1 -0
- package/dist/esm/commands/build/build.js +51 -0
- package/dist/esm/commands/build/build.js.map +1 -0
- package/dist/esm/commands/build/implementation.js +27 -0
- package/dist/esm/commands/build/implementation.js.map +1 -0
- package/dist/esm/commands/build/index.js +17 -0
- package/dist/esm/commands/build/index.js.map +1 -0
- package/dist/esm/commands/eval/eval.js +54 -0
- package/dist/esm/commands/eval/eval.js.map +1 -0
- package/dist/esm/commands/eval/implementation.js +24 -0
- package/dist/esm/commands/eval/implementation.js.map +1 -0
- package/dist/esm/commands/eval/index.js +22 -0
- package/dist/esm/commands/eval/index.js.map +1 -0
- package/dist/esm/commands/index.js +15 -0
- package/dist/esm/commands/index.js.map +1 -0
- package/dist/esm/commands/manifest/implementation.js +33 -0
- package/dist/esm/commands/manifest/implementation.js.map +1 -0
- package/dist/esm/commands/manifest/index.js +22 -0
- package/dist/esm/commands/manifest/index.js.map +1 -0
- package/dist/esm/commands/manifest/manifest.js +52 -0
- package/dist/esm/commands/manifest/manifest.js.map +1 -0
- package/dist/esm/commands/serve/index.js +18 -0
- package/dist/esm/commands/serve/index.js.map +1 -0
- package/dist/esm/commands/serve/serve.js +17 -0
- package/dist/esm/commands/serve/serve.js.map +1 -0
- package/dist/esm/commands/watch/implementation.js +34 -0
- package/dist/esm/commands/watch/implementation.js.map +1 -0
- package/dist/esm/commands/watch/index.js +19 -0
- package/dist/esm/commands/watch/index.js.map +1 -0
- package/dist/esm/commands/watch/watch.js +50 -0
- package/dist/esm/commands/watch/watch.js.map +1 -0
- package/dist/esm/config.js +327 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/errors.js +30 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/main.js +10 -0
- package/dist/esm/main.js.map +1 -0
- package/dist/esm/utils/cli.js +43 -0
- package/dist/esm/utils/cli.js.map +1 -0
- package/dist/esm/utils/errors.js +43 -0
- package/dist/esm/utils/errors.js.map +1 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/legacy.js +47 -0
- package/dist/esm/utils/legacy.js.map +1 -0
- package/dist/esm/utils/logging.js +40 -0
- package/dist/esm/utils/logging.js.map +1 -0
- package/dist/esm/utils/path.js +13 -0
- package/dist/esm/utils/path.js.map +1 -0
- package/dist/esm/utils/steps.js +43 -0
- package/dist/esm/utils/steps.js.map +1 -0
- package/dist/esm/webpack/compiler.js +89 -0
- package/dist/esm/webpack/compiler.js.map +1 -0
- package/dist/esm/webpack/config.js +241 -0
- package/dist/esm/webpack/config.js.map +1 -0
- package/dist/esm/webpack/index.js +5 -0
- package/dist/esm/webpack/index.js.map +1 -0
- package/dist/esm/webpack/loaders/browserify.js +82 -0
- package/dist/esm/webpack/loaders/browserify.js.map +1 -0
- package/dist/esm/webpack/loaders/wasm.js +26 -0
- package/dist/esm/webpack/loaders/wasm.js.map +1 -0
- package/dist/esm/webpack/plugins.js +343 -0
- package/dist/esm/webpack/plugins.js.map +1 -0
- package/dist/esm/webpack/utils.js +208 -0
- package/dist/esm/webpack/utils.js.map +1 -0
- package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
- package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
- package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
- package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
- package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
- package/dist/types/builders.d.ts +8 -0
- package/dist/{cli.d.ts → types/cli.d.ts} +1 -1
- package/dist/types/commands/build/build.d.ts +10 -0
- package/dist/types/commands/build/implementation.d.ts +10 -0
- package/dist/types/commands/build/index.d.ts +10 -0
- package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/eval.d.ts +14 -0
- package/dist/types/commands/eval/implementation.d.ts +9 -0
- package/dist/types/commands/eval/index.d.ts +10 -0
- package/dist/types/commands/manifest/implementation.d.ts +12 -0
- package/dist/types/commands/manifest/index.d.ts +10 -0
- package/dist/types/commands/manifest/manifest.d.ts +14 -0
- package/dist/{cmds/build → types/commands/serve}/index.d.ts +4 -4
- package/dist/types/commands/serve/serve.d.ts +16 -0
- package/dist/types/commands/watch/implementation.d.ts +14 -0
- package/dist/types/commands/watch/index.d.ts +10 -0
- package/dist/types/commands/watch/watch.d.ts +19 -0
- package/dist/types/config.d.ts +792 -0
- package/dist/types/errors.d.ts +25 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/utils/cli.d.ts +17 -0
- package/dist/types/utils/errors.d.ts +23 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/legacy.d.ts +27 -0
- package/dist/types/utils/logging.d.ts +22 -0
- package/dist/types/utils/path.d.ts +9 -0
- package/dist/types/utils/steps.d.ts +17 -0
- package/dist/types/webpack/compiler.d.ts +29 -0
- package/dist/types/webpack/config.d.ts +37 -0
- package/dist/types/webpack/index.d.ts +3 -0
- package/dist/types/webpack/loaders/browserify.d.ts +16 -0
- package/dist/types/webpack/loaders/wasm.d.ts +20 -0
- package/dist/types/webpack/plugins.d.ts +147 -0
- package/dist/types/webpack/utils.d.ts +188 -0
- package/package.json +83 -43
- package/dist/builders.d.ts +0 -27
- package/dist/builders.js.map +0 -1
- package/dist/cli.js +0 -51
- package/dist/cli.js.map +0 -1
- package/dist/cmds/build/buildHandler.d.ts +0 -13
- package/dist/cmds/build/buildHandler.js +0 -37
- package/dist/cmds/build/buildHandler.js.map +0 -1
- package/dist/cmds/build/bundle.d.ts +0 -15
- package/dist/cmds/build/bundle.js +0 -80
- package/dist/cmds/build/bundle.js.map +0 -1
- package/dist/cmds/build/index.js +0 -29
- package/dist/cmds/build/index.js.map +0 -1
- package/dist/cmds/build/utils.d.ts +0 -56
- package/dist/cmds/build/utils.js +0 -100
- package/dist/cmds/build/utils.js.map +0 -1
- package/dist/cmds/eval/evalHandler.d.ts +0 -9
- package/dist/cmds/eval/evalHandler.js +0 -25
- package/dist/cmds/eval/evalHandler.js.map +0 -1
- package/dist/cmds/eval/index.d.ts +0 -9
- package/dist/cmds/eval/index.js +0 -15
- package/dist/cmds/eval/index.js.map +0 -1
- package/dist/cmds/index.js +0 -14
- package/dist/cmds/index.js.map +0 -1
- package/dist/cmds/init/index.d.ts +0 -9
- package/dist/cmds/init/index.js +0 -34
- package/dist/cmds/init/index.js.map +0 -1
- package/dist/cmds/init/initHandler.d.ts +0 -26
- package/dist/cmds/init/initHandler.js +0 -69
- package/dist/cmds/init/initHandler.js.map +0 -1
- package/dist/cmds/init/initUtils.d.ts +0 -39
- package/dist/cmds/init/initUtils.js +0 -122
- package/dist/cmds/init/initUtils.js.map +0 -1
- package/dist/cmds/manifest/index.d.ts +0 -9
- package/dist/cmds/manifest/index.js +0 -24
- package/dist/cmds/manifest/index.js.map +0 -1
- package/dist/cmds/manifest/manifestHandler.d.ts +0 -10
- package/dist/cmds/manifest/manifestHandler.js +0 -50
- package/dist/cmds/manifest/manifestHandler.js.map +0 -1
- package/dist/cmds/serve/index.d.ts +0 -9
- package/dist/cmds/serve/index.js +0 -15
- package/dist/cmds/serve/index.js.map +0 -1
- package/dist/cmds/serve/serveHandler.d.ts +0 -10
- package/dist/cmds/serve/serveHandler.js +0 -59
- package/dist/cmds/serve/serveHandler.js.map +0 -1
- package/dist/cmds/serve/serveUtils.d.ts +0 -22
- package/dist/cmds/serve/serveUtils.js +0 -39
- package/dist/cmds/serve/serveUtils.js.map +0 -1
- package/dist/cmds/watch/index.d.ts +0 -9
- package/dist/cmds/watch/index.js +0 -32
- package/dist/cmds/watch/index.js.map +0 -1
- package/dist/cmds/watch/watchHandler.d.ts +0 -14
- package/dist/cmds/watch/watchHandler.js +0 -100
- package/dist/cmds/watch/watchHandler.js.map +0 -1
- package/dist/main.js +0 -15
- package/dist/main.js.map +0 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -19
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/misc.d.ts +0 -53
- package/dist/utils/misc.js +0 -156
- package/dist/utils/misc.js.map +0 -1
- package/dist/utils/snap-config.d.ts +0 -48
- package/dist/utils/snap-config.js +0 -117
- package/dist/utils/snap-config.js.map +0 -1
- /package/dist/{cmds → types/commands}/index.d.ts +0 -0
- /package/dist/{main.d.ts → types/main.d.ts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../../src/cmds/manifest/manifestHandler.ts"],"names":[],"mappings":";;;AAAA,uDAA4E;AAI5E,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CAAC,EAAE,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,2BAAa,EAC9C,OAAO,CAAC,GAAG,EAAE,EACb,OAAO,CAAC,aAAa,CAAC,CACvB,CAAC;QAEF,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,IAAA,sBAAQ,EAAC,GAAG,YAAY,0BAA0B,CAAC,CAAC;YACpD,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;YAEjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,IAAA,wBAAU,EACR,6EAA6E,CAC9E,CAAC;YACF,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;SACtC;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,GAAG,KAAK,EAAE,CAAC,CAAC;KAC5C;AACH,CAAC;AAvBD,0CAuBC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,OAAe;IACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE;QAClC,IAAA,wBAAU,EAAC,qBAAqB,OAAO,EAAE,CAAC,CAAC;KAC5C;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,OAAe;IACvC,IAAA,sBAAQ,EAAC,GAAG,YAAY,GAAG,OAAO,EAAE,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { checkManifest, logError, logWarning } from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\n\nconst ERROR_PREFIX = 'Manifest Error: ';\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param argv - The Yargs `argv` object.\n * @param argv.writeManifest - Whether to write the fixed manifest to disk.\n */\nexport async function manifestHandler({ writeManifest }: YargsArgs) {\n try {\n const { warnings, errors } = await checkManifest(\n process.cwd(),\n Boolean(writeManifest),\n );\n\n if (!writeManifest && errors.length > 0) {\n logError(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n logWarning(\n 'Manifest Warning: Validation of snap.manifest.json completed with warnings.',\n );\n warnings.forEach(logManifestWarning);\n }\n } catch (error) {\n throw new Error(`${ERROR_PREFIX}${error}`);\n }\n}\n\n/**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\nfunction logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n logWarning(`Manifest Warning: ${message}`);\n }\n}\n\n/**\n * Logs a manifest error.\n *\n * @param message - The message to log.\n */\nfunction logManifestError(message: string) {\n logError(`${ERROR_PREFIX}${message}`);\n}\n"]}
|
package/dist/cmds/serve/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
const builders_1 = __importDefault(require("../../builders"));
|
|
6
|
-
const serveHandler_1 = require("./serveHandler");
|
|
7
|
-
module.exports = {
|
|
8
|
-
command: ['serve', 's'],
|
|
9
|
-
desc: 'Locally serve Snap file(s) for testing',
|
|
10
|
-
builder: (yarg) => {
|
|
11
|
-
yarg.option('root', builders_1.default.root).option('port', builders_1.default.port);
|
|
12
|
-
},
|
|
13
|
-
handler: async (argv) => (0, serveHandler_1.serve)(argv),
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/serve/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,iDAAuC;AAEvC,iBAAS;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,wCAAwC;IAC9C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAA,oBAAK,EAAC,IAAI,CAAC;CAChD,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { serve } from './serveHandler';\n\nexport = {\n command: ['serve', 's'],\n desc: 'Locally serve Snap file(s) for testing',\n builder: (yarg: yargs.Argv) => {\n yarg.option('root', builders.root).option('port', builders.port);\n },\n handler: async (argv: YargsArgs) => serve(argv),\n};\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { YargsArgs } from '../../types/yargs';
|
|
2
|
-
/**
|
|
3
|
-
* Starts a local, static HTTP server on the given port with the given root
|
|
4
|
-
* directory.
|
|
5
|
-
*
|
|
6
|
-
* @param argv - Arguments as an object generated by Yargs.
|
|
7
|
-
* @param argv.root - The root directory path string.
|
|
8
|
-
* @param argv.port - The server port.
|
|
9
|
-
*/
|
|
10
|
-
export declare function serve(argv: YargsArgs): Promise<void>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.serve = void 0;
|
|
7
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
-
const http_1 = __importDefault(require("http"));
|
|
9
|
-
const serve_handler_1 = __importDefault(require("serve-handler"));
|
|
10
|
-
const serveUtils_1 = require("./serveUtils");
|
|
11
|
-
/**
|
|
12
|
-
* Starts a local, static HTTP server on the given port with the given root
|
|
13
|
-
* directory.
|
|
14
|
-
*
|
|
15
|
-
* @param argv - Arguments as an object generated by Yargs.
|
|
16
|
-
* @param argv.root - The root directory path string.
|
|
17
|
-
* @param argv.port - The server port.
|
|
18
|
-
*/
|
|
19
|
-
async function serve(argv) {
|
|
20
|
-
const { port, root: rootDir } = argv;
|
|
21
|
-
await (0, snaps_utils_1.validateDirPath)(rootDir, true);
|
|
22
|
-
(0, snaps_utils_1.logInfo)(`\nStarting server...`);
|
|
23
|
-
const server = http_1.default.createServer((req, res) => {
|
|
24
|
-
(0, serve_handler_1.default)(req, res, {
|
|
25
|
-
public: rootDir,
|
|
26
|
-
headers: [
|
|
27
|
-
{
|
|
28
|
-
source: '**/*',
|
|
29
|
-
headers: [
|
|
30
|
-
{
|
|
31
|
-
key: 'Cache-Control',
|
|
32
|
-
value: 'no-cache',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
key: 'Access-Control-Allow-Origin',
|
|
36
|
-
value: '*',
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
})?.catch((error) => {
|
|
42
|
-
(0, serveUtils_1.logServerError)(error, argv.port);
|
|
43
|
-
res.statusCode = 500;
|
|
44
|
-
res.end();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
server.listen({ port }, () => (0, serveUtils_1.logServerListening)(port));
|
|
48
|
-
server.on('request', (request) => (0, serveUtils_1.logRequest)(request));
|
|
49
|
-
server.on('error', (error) => {
|
|
50
|
-
(0, serveUtils_1.logServerError)(error, argv.port);
|
|
51
|
-
process.exitCode = 1;
|
|
52
|
-
});
|
|
53
|
-
server.on('close', () => {
|
|
54
|
-
(0, snaps_utils_1.logInfo)('Server closed');
|
|
55
|
-
process.exitCode = 1;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
exports.serve = serve;
|
|
59
|
-
//# sourceMappingURL=serveHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serveHandler.js","sourceRoot":"","sources":["../../../src/cmds/serve/serveHandler.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAiE;AACjE,gDAAwB;AACxB,kEAAyC;AAGzC,6CAA8E;AAE9E;;;;;;;GAOG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAErC,MAAM,IAAA,6BAAe,EAAC,OAAiB,EAAE,IAAI,CAAC,CAAC;IAE/C,IAAA,qBAAO,EAAC,sBAAsB,CAAC,CAAC;IAEhC,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC5C,IAAA,uBAAY,EAAC,GAAG,EAAE,GAAG,EAAE;YACrB,MAAM,EAAE,OAAiB;YACzB,OAAO,EAAE;gBACP;oBACE,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE;wBACP;4BACE,GAAG,EAAE,eAAe;4BACpB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,GAAG,EAAE,6BAA6B;4BAClC,KAAK,EAAE,GAAG;yBACX;qBACF;iBACF;aACF;SACF,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAClB,IAAA,2BAAc,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,IAAA,+BAAkB,EAAC,IAAI,CAAC,CAAC,CAAC;IAExD,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,uBAAU,EAAC,OAAO,CAAC,CAAC,CAAC;IAEvD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3B,IAAA,2BAAc,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACtB,IAAA,qBAAO,EAAC,eAAe,CAAC,CAAC;QACzB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC;AA7CD,sBA6CC","sourcesContent":["import { logInfo, validateDirPath } from '@metamask/snaps-utils';\nimport http from 'http';\nimport serveHandler from 'serve-handler';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { logRequest, logServerError, logServerListening } from './serveUtils';\n\n/**\n * Starts a local, static HTTP server on the given port with the given root\n * directory.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.root - The root directory path string.\n * @param argv.port - The server port.\n */\nexport async function serve(argv: YargsArgs): Promise<void> {\n const { port, root: rootDir } = argv;\n\n await validateDirPath(rootDir as string, true);\n\n logInfo(`\\nStarting server...`);\n\n const server = http.createServer((req, res) => {\n serveHandler(req, res, {\n public: rootDir as string,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n })?.catch((error) => {\n logServerError(error, argv.port);\n res.statusCode = 500;\n res.end();\n });\n });\n\n server.listen({ port }, () => logServerListening(port));\n\n server.on('request', (request) => logRequest(request));\n\n server.on('error', (error) => {\n logServerError(error, argv.port);\n process.exitCode = 1;\n });\n\n server.on('close', () => {\n logInfo('Server closed');\n process.exitCode = 1;\n });\n}\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Log a message with the URL and port of the server.
|
|
3
|
-
*
|
|
4
|
-
* @param port - The port that the server is running on.
|
|
5
|
-
*/
|
|
6
|
-
export declare function logServerListening(port: number): void;
|
|
7
|
-
/**
|
|
8
|
-
* Log a message with the request URL.
|
|
9
|
-
*
|
|
10
|
-
* @param request - The request object.
|
|
11
|
-
* @param request.url - The URL of the request.
|
|
12
|
-
*/
|
|
13
|
-
export declare function logRequest(request: {
|
|
14
|
-
url?: string;
|
|
15
|
-
}): void;
|
|
16
|
-
/**
|
|
17
|
-
* Log an error message.
|
|
18
|
-
*
|
|
19
|
-
* @param error - The error to log.
|
|
20
|
-
* @param port - The port that the server is running on.
|
|
21
|
-
*/
|
|
22
|
-
export declare function logServerError(error: Error, port: number): void;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logServerError = exports.logRequest = exports.logServerListening = void 0;
|
|
4
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
|
-
/**
|
|
6
|
-
* Log a message with the URL and port of the server.
|
|
7
|
-
*
|
|
8
|
-
* @param port - The port that the server is running on.
|
|
9
|
-
*/
|
|
10
|
-
function logServerListening(port) {
|
|
11
|
-
(0, snaps_utils_1.logInfo)(`Server listening on: http://localhost:${port}`);
|
|
12
|
-
}
|
|
13
|
-
exports.logServerListening = logServerListening;
|
|
14
|
-
/**
|
|
15
|
-
* Log a message with the request URL.
|
|
16
|
-
*
|
|
17
|
-
* @param request - The request object.
|
|
18
|
-
* @param request.url - The URL of the request.
|
|
19
|
-
*/
|
|
20
|
-
function logRequest(request) {
|
|
21
|
-
(0, snaps_utils_1.logInfo)(`Handling incoming request for: ${request.url ?? 'unknown'}`);
|
|
22
|
-
}
|
|
23
|
-
exports.logRequest = logRequest;
|
|
24
|
-
/**
|
|
25
|
-
* Log an error message.
|
|
26
|
-
*
|
|
27
|
-
* @param error - The error to log.
|
|
28
|
-
* @param port - The port that the server is running on.
|
|
29
|
-
*/
|
|
30
|
-
function logServerError(error, port) {
|
|
31
|
-
if (error.code === 'EADDRINUSE') {
|
|
32
|
-
(0, snaps_utils_1.logError)(`Server error: Port ${port} already in use.`);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
(0, snaps_utils_1.logError)(`Server error: ${error.message}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.logServerError = logServerError;
|
|
39
|
-
//# sourceMappingURL=serveUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serveUtils.js","sourceRoot":"","sources":["../../../src/cmds/serve/serveUtils.ts"],"names":[],"mappings":";;;AAAA,uDAA0D;AAE1D;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,IAAA,qBAAO,EAAC,yCAAyC,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAFD,gDAEC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,OAAyB;IAClD,IAAA,qBAAO,EAAC,kCAAkC,OAAO,CAAC,GAAG,IAAI,SAAS,EAAE,CAAC,CAAC;AACxE,CAAC;AAFD,gCAEC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAY,EAAE,IAAY;IACvD,IAAK,KAAa,CAAC,IAAI,KAAK,YAAY,EAAE;QACxC,IAAA,sBAAQ,EAAC,sBAAsB,IAAI,kBAAkB,CAAC,CAAC;KACxD;SAAM;QACL,IAAA,sBAAQ,EAAC,iBAAiB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5C;AACH,CAAC;AAND,wCAMC","sourcesContent":["import { logError, logInfo } from '@metamask/snaps-utils';\n\n/**\n * Log a message with the URL and port of the server.\n *\n * @param port - The port that the server is running on.\n */\nexport function logServerListening(port: number) {\n logInfo(`Server listening on: http://localhost:${port}`);\n}\n\n/**\n * Log a message with the request URL.\n *\n * @param request - The request object.\n * @param request.url - The URL of the request.\n */\nexport function logRequest(request: { url?: string }) {\n logInfo(`Handling incoming request for: ${request.url ?? 'unknown'}`);\n}\n\n/**\n * Log an error message.\n *\n * @param error - The error to log.\n * @param port - The port that the server is running on.\n */\nexport function logServerError(error: Error, port: number) {\n if ((error as any).code === 'EADDRINUSE') {\n logError(`Server error: Port ${port} already in use.`);\n } else {\n logError(`Server error: ${error.message}`);\n }\n}\n"]}
|
package/dist/cmds/watch/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
const builders_1 = __importDefault(require("../../builders"));
|
|
6
|
-
const utils_1 = require("../build/utils");
|
|
7
|
-
const watchHandler_1 = require("./watchHandler");
|
|
8
|
-
module.exports = {
|
|
9
|
-
command: ['watch', 'w'],
|
|
10
|
-
desc: 'Build Snap on change',
|
|
11
|
-
builder: (yarg) => {
|
|
12
|
-
yarg
|
|
13
|
-
.option('src', builders_1.default.src)
|
|
14
|
-
.option('eval', builders_1.default.eval)
|
|
15
|
-
.option('dist', builders_1.default.dist)
|
|
16
|
-
.option('outfileName', builders_1.default.outfileName)
|
|
17
|
-
.option('sourceMaps', builders_1.default.sourceMaps)
|
|
18
|
-
.option('stripComments', builders_1.default.stripComments)
|
|
19
|
-
.option('transpilationMode', builders_1.default.transpilationMode)
|
|
20
|
-
.option('depsToTranspile', builders_1.default.depsToTranspile)
|
|
21
|
-
.option('manifest', builders_1.default.manifest)
|
|
22
|
-
.option('writeManifest', builders_1.default.writeManifest)
|
|
23
|
-
.option('serve', builders_1.default.serve)
|
|
24
|
-
.option('root', builders_1.default.root)
|
|
25
|
-
.option('port', builders_1.default.port)
|
|
26
|
-
.implies('writeManifest', 'manifest')
|
|
27
|
-
.implies('depsToTranspile', 'transpilationMode')
|
|
28
|
-
.middleware((argv) => (0, utils_1.processInvalidTranspilation)(argv));
|
|
29
|
-
},
|
|
30
|
-
handler: async (argv) => (0, watchHandler_1.watch)(argv),
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/watch/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,0CAA6D;AAC7D,iDAAuC;AAEvC,iBAAS;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,sBAAsB;IAC5B,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,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,kBAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,mBAAmB,EAAE,kBAAQ,CAAC,iBAAiB,CAAC;aACvD,MAAM,CAAC,iBAAiB,EAAE,kBAAQ,CAAC,eAAe,CAAC;aACnD,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,OAAO,EAAE,kBAAQ,CAAC,KAAK,CAAC;aAC/B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC;aACpC,OAAO,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;aAC/C,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,mCAA2B,EAAC,IAAW,CAAC,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAA,oBAAK,EAAC,IAAI,CAAC;CAChD,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { processInvalidTranspilation } from '../build/utils';\nimport { watch } from './watchHandler';\n\nexport = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => watch(argv),\n};\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { YargsArgs } from '../../types/yargs';
|
|
2
|
-
/**
|
|
3
|
-
* Watch a directory and its subdirectories for changes, and build when files
|
|
4
|
-
* are added or changed.
|
|
5
|
-
*
|
|
6
|
-
* Ignores 'node_modules' and dotfiles.
|
|
7
|
-
* Creates destination directory if it doesn't exist.
|
|
8
|
-
*
|
|
9
|
-
* @param argv - Arguments as an object generated by Yargs.
|
|
10
|
-
* @param argv.src - The source file path.
|
|
11
|
-
* @param argv.dist - The output directory path.
|
|
12
|
-
* @param argv.'outfileName' - The output file name.
|
|
13
|
-
*/
|
|
14
|
-
export declare function watch(argv: YargsArgs): Promise<void>;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.watch = void 0;
|
|
7
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
-
const chokidar_1 = __importDefault(require("chokidar"));
|
|
9
|
-
const utils_1 = require("../../utils");
|
|
10
|
-
const bundle_1 = require("../build/bundle");
|
|
11
|
-
const evalHandler_1 = require("../eval/evalHandler");
|
|
12
|
-
const manifestHandler_1 = require("../manifest/manifestHandler");
|
|
13
|
-
const serveHandler_1 = require("../serve/serveHandler");
|
|
14
|
-
/**
|
|
15
|
-
* Watch a directory and its subdirectories for changes, and build when files
|
|
16
|
-
* are added or changed.
|
|
17
|
-
*
|
|
18
|
-
* Ignores 'node_modules' and dotfiles.
|
|
19
|
-
* Creates destination directory if it doesn't exist.
|
|
20
|
-
*
|
|
21
|
-
* @param argv - Arguments as an object generated by Yargs.
|
|
22
|
-
* @param argv.src - The source file path.
|
|
23
|
-
* @param argv.dist - The output directory path.
|
|
24
|
-
* @param argv.'outfileName' - The output file name.
|
|
25
|
-
*/
|
|
26
|
-
async function watch(argv) {
|
|
27
|
-
const { dist, eval: shouldEval, manifest, outfileName, src, serve: shouldServe, } = argv;
|
|
28
|
-
if (outfileName) {
|
|
29
|
-
(0, snaps_utils_1.validateOutfileName)(outfileName);
|
|
30
|
-
}
|
|
31
|
-
await (0, snaps_utils_1.validateFilePath)(src);
|
|
32
|
-
await (0, snaps_utils_1.validateDirPath)(dist, true);
|
|
33
|
-
const rootDir = src.includes('/')
|
|
34
|
-
? src.substring(0, src.lastIndexOf('/') + 1)
|
|
35
|
-
: '.';
|
|
36
|
-
const outfilePath = (0, snaps_utils_1.getOutfilePath)(dist, outfileName);
|
|
37
|
-
const buildSnap = async (path, logMessage) => {
|
|
38
|
-
if (logMessage !== undefined) {
|
|
39
|
-
(0, snaps_utils_1.logInfo)(logMessage);
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
await (0, bundle_1.bundle)(src, outfilePath, argv, (0, utils_1.loadConfig)().bundlerCustomizer);
|
|
43
|
-
if (manifest) {
|
|
44
|
-
await (0, manifestHandler_1.manifestHandler)(argv);
|
|
45
|
-
}
|
|
46
|
-
if (shouldEval) {
|
|
47
|
-
await (0, evalHandler_1.evalHandler)({ ...argv, bundle: outfilePath });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
(0, snaps_utils_1.logError)(`Error ${path === undefined
|
|
52
|
-
? 'during initial build'
|
|
53
|
-
: `while processing "${path}"`}.`, error);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
chokidar_1.default
|
|
57
|
-
.watch(rootDir, {
|
|
58
|
-
ignoreInitial: true,
|
|
59
|
-
ignored: [
|
|
60
|
-
'**/node_modules/**',
|
|
61
|
-
`**/${dist}/**`,
|
|
62
|
-
`**/test/**`,
|
|
63
|
-
`**/tests/**`,
|
|
64
|
-
`**/*.test.js`,
|
|
65
|
-
`**/*.test.ts`,
|
|
66
|
-
/* istanbul ignore next */
|
|
67
|
-
(str) => str !== '.' && str.startsWith('.'),
|
|
68
|
-
],
|
|
69
|
-
})
|
|
70
|
-
.on('ready', () => {
|
|
71
|
-
buildSnap()
|
|
72
|
-
.then(() => {
|
|
73
|
-
if (shouldServe) {
|
|
74
|
-
return (0, serveHandler_1.serve)(argv);
|
|
75
|
-
}
|
|
76
|
-
return undefined;
|
|
77
|
-
})
|
|
78
|
-
.catch((error) => {
|
|
79
|
-
(0, snaps_utils_1.logError)('Error during initial build.', error);
|
|
80
|
-
});
|
|
81
|
-
})
|
|
82
|
-
.on('add', (path) => {
|
|
83
|
-
buildSnap(path, `File added: ${path}`).catch((error) => {
|
|
84
|
-
(0, snaps_utils_1.logError)(`Error while processing "${path}".`, error);
|
|
85
|
-
});
|
|
86
|
-
})
|
|
87
|
-
.on('change', (path) => {
|
|
88
|
-
buildSnap(path, `File changed: ${path}`).catch((error) => {
|
|
89
|
-
(0, snaps_utils_1.logError)(`Error while processing "${path}".`, error);
|
|
90
|
-
});
|
|
91
|
-
})
|
|
92
|
-
.on('unlink', (path) => (0, snaps_utils_1.logInfo)(`File removed: ${path}`))
|
|
93
|
-
.on('error', (error) => {
|
|
94
|
-
(0, snaps_utils_1.logError)(`Watcher error: ${error.message}`, error);
|
|
95
|
-
})
|
|
96
|
-
.add(rootDir);
|
|
97
|
-
(0, snaps_utils_1.logInfo)(`Watching '${rootDir}' for changes...`);
|
|
98
|
-
}
|
|
99
|
-
exports.watch = watch;
|
|
100
|
-
//# sourceMappingURL=watchHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"watchHandler.js","sourceRoot":"","sources":["../../../src/cmds/watch/watchHandler.ts"],"names":[],"mappings":";;;;;;AAAA,uDAO+B;AAC/B,wDAAgC;A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BAAQ,EAAC,2BAA2B,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;SACD,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,qBAAO,EAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;SACxD,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;QAC5B,IAAA,sBAAQ,EAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC;SAED,GAAG,CAAC,OAAO,CAAC,CAAC;IAEhB,IAAA,qBAAO,EAAC,aAAa,OAAO,kBAAkB,CAAC,CAAC;AAClD,CAAC;AA5FD,sBA4FC","sourcesContent":["import {\n getOutfilePath,\n logError,\n logInfo,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\nimport chokidar from 'chokidar';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { bundle } from '../build/bundle';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { serve } from '../serve/serveHandler';\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.'outfileName' - The output file name.\n */\nexport async function watch(argv: YargsArgs): Promise<void> {\n const {\n dist,\n eval: shouldEval,\n manifest,\n outfileName,\n src,\n serve: shouldServe,\n } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n const rootDir = src.includes('/')\n ? src.substring(0, src.lastIndexOf('/') + 1)\n : '.';\n const outfilePath = getOutfilePath(dist, outfileName);\n\n const buildSnap = async (path?: string, logMessage?: string) => {\n if (logMessage !== undefined) {\n logInfo(logMessage);\n }\n\n try {\n await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);\n\n if (manifest) {\n await manifestHandler(argv);\n }\n\n if (shouldEval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n } catch (error) {\n logError(\n `Error ${\n path === undefined\n ? 'during initial build'\n : `while processing \"${path}\"`\n }.`,\n error,\n );\n }\n };\n\n chokidar\n .watch(rootDir, {\n ignoreInitial: true,\n ignored: [\n '**/node_modules/**',\n `**/${dist}/**`,\n `**/test/**`,\n `**/tests/**`,\n `**/*.test.js`,\n `**/*.test.ts`,\n /* istanbul ignore next */\n (str: string) => str !== '.' && str.startsWith('.'),\n ],\n })\n\n .on('ready', () => {\n buildSnap()\n .then(() => {\n if (shouldServe) {\n return serve(argv);\n }\n\n return undefined;\n })\n .catch((error) => {\n logError('Error during initial build.', error);\n });\n })\n .on('add', (path) => {\n buildSnap(path, `File added: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('change', (path) => {\n buildSnap(path, `File changed: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('unlink', (path) => logInfo(`File removed: ${path}`))\n .on('error', (error: Error) => {\n logError(`Watcher error: ${error.message}`, error);\n })\n\n .add(rootDir);\n\n logInfo(`Watching '${rootDir}' for changes...`);\n}\n"]}
|
package/dist/main.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const cli_1 = require("./cli");
|
|
8
|
-
const cmds_1 = __importDefault(require("./cmds"));
|
|
9
|
-
global.snaps = {
|
|
10
|
-
verboseErrors: false,
|
|
11
|
-
suppressWarnings: false,
|
|
12
|
-
isWatching: false,
|
|
13
|
-
};
|
|
14
|
-
(0, cli_1.cli)(process.argv, cmds_1.default);
|
|
15
|
-
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;AAEA,+BAA4B;AAC5B,kDAA8B;AAE9B,MAAM,CAAC,KAAK,GAAG;IACb,aAAa,EAAE,KAAK;IACpB,gBAAgB,EAAE,KAAK;IACvB,UAAU,EAAE,KAAK;CAClB,CAAC;AAEF,IAAA,SAAG,EAAC,OAAO,CAAC,IAAI,EAAE,cAAQ,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { cli } from './cli';\nimport commands from './cmds';\n\nglobal.snaps = {\n verboseErrors: false,\n suppressWarnings: false,\n isWatching: false,\n};\n\ncli(process.argv, commands);\n"]}
|
package/dist/utils/index.d.ts
DELETED
package/dist/utils/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./misc"), exports);
|
|
18
|
-
__exportStar(require("./snap-config"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,gDAA8B","sourcesContent":["export * from './misc';\nexport * from './snap-config';\n"]}
|
package/dist/utils/misc.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Arguments } from 'yargs';
|
|
2
|
-
export declare const permRequestKeys: string[];
|
|
3
|
-
export declare const CONFIG_FILE = "snap.config.js";
|
|
4
|
-
/**
|
|
5
|
-
* Sets global variable snaps which tracks user settings:
|
|
6
|
-
* watch mode activation, verbose errors messages, and whether to suppress
|
|
7
|
-
* warnings.
|
|
8
|
-
*
|
|
9
|
-
* @param argv - Arguments as an object generated by `yargs`.
|
|
10
|
-
*/
|
|
11
|
-
export declare function setSnapGlobals(argv: Arguments): void;
|
|
12
|
-
/**
|
|
13
|
-
* Attempts to convert a string to a boolean and throws if the value is invalid.
|
|
14
|
-
*
|
|
15
|
-
* @param value - The value to convert to a boolean.
|
|
16
|
-
* @returns `true` if the value is the string `"true"`, `false` if it is the
|
|
17
|
-
* string `"false"`, the value if it is already a boolean, or an error
|
|
18
|
-
* otherwise.
|
|
19
|
-
*/
|
|
20
|
-
export declare function booleanStringToBoolean(value: unknown): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Sanitizes inputs. Currently normalizes "./" paths to ".".
|
|
23
|
-
* Yargs handles other path normalization as specified in builders.
|
|
24
|
-
*
|
|
25
|
-
* @param argv - Arguments as an object generated by yargs.
|
|
26
|
-
*/
|
|
27
|
-
export declare function sanitizeInputs(argv: Arguments): void;
|
|
28
|
-
/**
|
|
29
|
-
* Logs an error message to console. Logs original error if it exists and
|
|
30
|
-
* the verboseErrors global is true.
|
|
31
|
-
*
|
|
32
|
-
* @param message - The error message.
|
|
33
|
-
* @param error - The original error.
|
|
34
|
-
*/
|
|
35
|
-
export declare function logError(message: string | null, error?: Error): void;
|
|
36
|
-
/**
|
|
37
|
-
* Logs an error, attempts to unlink the destination file, and kills the
|
|
38
|
-
* process.
|
|
39
|
-
*
|
|
40
|
-
* @param prefix - The message prefix.
|
|
41
|
-
* @param message - The error message.
|
|
42
|
-
* @param error - The original error.
|
|
43
|
-
* @param destFilePath - The output file path.
|
|
44
|
-
*/
|
|
45
|
-
export declare function writeError(prefix: string, message: string, error: Error, destFilePath?: string): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Trims leading and trailing periods "." and forward slashes "/" from the
|
|
48
|
-
* given path string.
|
|
49
|
-
*
|
|
50
|
-
* @param pathString - The path string to trim.
|
|
51
|
-
* @returns The trimmed path string.
|
|
52
|
-
*/
|
|
53
|
-
export declare function trimPathString(pathString: string): string;
|
package/dist/utils/misc.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.trimPathString = exports.writeError = exports.logError = exports.sanitizeInputs = exports.booleanStringToBoolean = exports.setSnapGlobals = exports.CONFIG_FILE = exports.permRequestKeys = void 0;
|
|
7
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
-
const utils_1 = require("@metamask/utils");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
exports.permRequestKeys = [
|
|
12
|
-
'@context',
|
|
13
|
-
'id',
|
|
14
|
-
'parentCapability',
|
|
15
|
-
'invoker',
|
|
16
|
-
'date',
|
|
17
|
-
'caveats',
|
|
18
|
-
'proof',
|
|
19
|
-
];
|
|
20
|
-
exports.CONFIG_FILE = 'snap.config.js';
|
|
21
|
-
// CLI arguments whose values are file paths
|
|
22
|
-
const pathArguments = new Set([
|
|
23
|
-
'src',
|
|
24
|
-
's',
|
|
25
|
-
'dist',
|
|
26
|
-
'd',
|
|
27
|
-
'bundle',
|
|
28
|
-
'b',
|
|
29
|
-
'root',
|
|
30
|
-
'r',
|
|
31
|
-
]);
|
|
32
|
-
/**
|
|
33
|
-
* Sets global variable snaps which tracks user settings:
|
|
34
|
-
* watch mode activation, verbose errors messages, and whether to suppress
|
|
35
|
-
* warnings.
|
|
36
|
-
*
|
|
37
|
-
* @param argv - Arguments as an object generated by `yargs`.
|
|
38
|
-
*/
|
|
39
|
-
function setSnapGlobals(argv) {
|
|
40
|
-
if (['w', 'watch'].includes(argv._[0])) {
|
|
41
|
-
global.snaps.isWatching = true;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
global.snaps.isWatching = false;
|
|
45
|
-
}
|
|
46
|
-
if ((0, utils_1.hasProperty)(argv, 'verboseErrors')) {
|
|
47
|
-
global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);
|
|
48
|
-
}
|
|
49
|
-
if ((0, utils_1.hasProperty)(argv, 'suppressWarnings')) {
|
|
50
|
-
global.snaps.suppressWarnings = booleanStringToBoolean(argv.suppressWarnings);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.setSnapGlobals = setSnapGlobals;
|
|
54
|
-
/**
|
|
55
|
-
* Attempts to convert a string to a boolean and throws if the value is invalid.
|
|
56
|
-
*
|
|
57
|
-
* @param value - The value to convert to a boolean.
|
|
58
|
-
* @returns `true` if the value is the string `"true"`, `false` if it is the
|
|
59
|
-
* string `"false"`, the value if it is already a boolean, or an error
|
|
60
|
-
* otherwise.
|
|
61
|
-
*/
|
|
62
|
-
function booleanStringToBoolean(value) {
|
|
63
|
-
if (typeof value === 'boolean') {
|
|
64
|
-
return value;
|
|
65
|
-
}
|
|
66
|
-
else if (value === 'true') {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
else if (value === 'false') {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
throw new Error(`Expected a boolean or the strings "true" or "false". Received: "${String(value)}"`);
|
|
73
|
-
}
|
|
74
|
-
exports.booleanStringToBoolean = booleanStringToBoolean;
|
|
75
|
-
/**
|
|
76
|
-
* Sanitizes inputs. Currently normalizes "./" paths to ".".
|
|
77
|
-
* Yargs handles other path normalization as specified in builders.
|
|
78
|
-
*
|
|
79
|
-
* @param argv - Arguments as an object generated by yargs.
|
|
80
|
-
*/
|
|
81
|
-
function sanitizeInputs(argv) {
|
|
82
|
-
Object.keys(argv).forEach((key) => {
|
|
83
|
-
if (typeof argv[key] === 'string') {
|
|
84
|
-
// Node's path.normalize() does not do this
|
|
85
|
-
if (argv[key] === './') {
|
|
86
|
-
argv[key] = '.';
|
|
87
|
-
}
|
|
88
|
-
if (pathArguments.has(key)) {
|
|
89
|
-
argv[key] = path_1.default.normalize(argv[key]);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
exports.sanitizeInputs = sanitizeInputs;
|
|
95
|
-
/**
|
|
96
|
-
* Logs an error message to console. Logs original error if it exists and
|
|
97
|
-
* the verboseErrors global is true.
|
|
98
|
-
*
|
|
99
|
-
* @param message - The error message.
|
|
100
|
-
* @param error - The original error.
|
|
101
|
-
*/
|
|
102
|
-
function logError(message, error) {
|
|
103
|
-
if (message !== null) {
|
|
104
|
-
(0, snaps_utils_1.logError)(message);
|
|
105
|
-
}
|
|
106
|
-
if (error && global.snaps.verboseErrors) {
|
|
107
|
-
(0, snaps_utils_1.logError)(error);
|
|
108
|
-
}
|
|
109
|
-
if (message === null && (!error || (error && !global.snaps.verboseErrors))) {
|
|
110
|
-
(0, snaps_utils_1.logError)('Unknown error.');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.logError = logError;
|
|
114
|
-
/**
|
|
115
|
-
* Logs an error, attempts to unlink the destination file, and kills the
|
|
116
|
-
* process.
|
|
117
|
-
*
|
|
118
|
-
* @param prefix - The message prefix.
|
|
119
|
-
* @param message - The error message.
|
|
120
|
-
* @param error - The original error.
|
|
121
|
-
* @param destFilePath - The output file path.
|
|
122
|
-
*/
|
|
123
|
-
async function writeError(prefix, message, error, destFilePath) {
|
|
124
|
-
let processedPrefix = prefix;
|
|
125
|
-
if (!prefix.endsWith(' ')) {
|
|
126
|
-
processedPrefix += ' ';
|
|
127
|
-
}
|
|
128
|
-
logError(processedPrefix + message, error);
|
|
129
|
-
try {
|
|
130
|
-
if (destFilePath) {
|
|
131
|
-
await fs_1.promises.unlink(destFilePath);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
catch (unlinkError) {
|
|
135
|
-
logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);
|
|
136
|
-
}
|
|
137
|
-
// unless the watcher is active, exit
|
|
138
|
-
if (!global.snaps.isWatching) {
|
|
139
|
-
// TODO(ritave): Remove process exit and change into collapse of functions
|
|
140
|
-
// https://github.com/MetaMask/snaps-monorepo/issues/81
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
exports.writeError = writeError;
|
|
145
|
-
/**
|
|
146
|
-
* Trims leading and trailing periods "." and forward slashes "/" from the
|
|
147
|
-
* given path string.
|
|
148
|
-
*
|
|
149
|
-
* @param pathString - The path string to trim.
|
|
150
|
-
* @returns The trimmed path string.
|
|
151
|
-
*/
|
|
152
|
-
function trimPathString(pathString) {
|
|
153
|
-
return pathString.replace(/^[./]+|[./]+$/gu, '');
|
|
154
|
-
}
|
|
155
|
-
exports.trimPathString = trimPathString;
|
|
156
|
-
//# sourceMappingURL=misc.js.map
|
package/dist/utils/misc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[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IAAI,eAAe,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACzB,eAAe,IAAI,GAAG,CAAC;KACxB;IAED,QAAQ,CAAC,eAAe,GAAG,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,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,0EAA0E;QAC1E,qEAAqE;QACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AA1BD,gCA0BC;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 { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { 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_FILE = 'snap.config.js';\n\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\n * warnings.\n *\n * @param 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 (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param 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 message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\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 // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\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"]}
|