@metamask/snaps-cli 0.24.1 → 0.26.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/dist/builders.d.ts +3 -3
- package/dist/builders.js +5 -5
- package/dist/builders.js.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/cmds/build/buildHandler.js +1 -1
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/bundle.js +4 -4
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/build/index.js +1 -1
- package/dist/cmds/build/index.js.map +1 -1
- package/dist/cmds/build/utils.js +5 -4
- package/dist/cmds/build/utils.js.map +1 -1
- package/dist/cmds/eval/evalHandler.js +2 -0
- package/dist/cmds/eval/evalHandler.js.map +1 -1
- package/dist/cmds/eval/index.js +1 -1
- package/dist/cmds/eval/index.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/initHandler.js +7 -7
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +3 -3
- package/dist/cmds/init/initUtils.js +12 -12
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/index.js +3 -3
- package/dist/cmds/manifest/index.js.map +1 -1
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/serve/index.js +1 -1
- package/dist/cmds/serve/index.js.map +1 -1
- package/dist/cmds/serve/serveHandler.js +8 -3
- package/dist/cmds/serve/serveHandler.js.map +1 -1
- package/dist/cmds/watch/index.js +1 -1
- package/dist/cmds/watch/index.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +25 -9
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/utils/misc.d.ts +8 -8
- package/dist/utils/misc.js +18 -18
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/snap-config.d.ts +1 -1
- package/dist/utils/snap-config.js +10 -9
- package/dist/utils/snap-config.js.map +1 -1
- package/package.json +18 -18
package/dist/builders.d.ts
CHANGED
|
@@ -19,9 +19,9 @@ export declare type SnapsCliBuilders = {
|
|
|
19
19
|
readonly directory: Readonly<PositionalOptions>;
|
|
20
20
|
};
|
|
21
21
|
export declare enum TranspilationModes {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
LocalAndDeps = "localAndDeps",
|
|
23
|
+
LocalOnly = "localOnly",
|
|
24
|
+
None = "none"
|
|
25
25
|
}
|
|
26
26
|
declare const builders: SnapsCliBuilders;
|
|
27
27
|
export default builders;
|
package/dist/builders.js
CHANGED
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TranspilationModes = void 0;
|
|
4
4
|
var TranspilationModes;
|
|
5
5
|
(function (TranspilationModes) {
|
|
6
|
-
TranspilationModes["
|
|
7
|
-
TranspilationModes["
|
|
8
|
-
TranspilationModes["
|
|
6
|
+
TranspilationModes["LocalAndDeps"] = "localAndDeps";
|
|
7
|
+
TranspilationModes["LocalOnly"] = "localOnly";
|
|
8
|
+
TranspilationModes["None"] = "none";
|
|
9
9
|
})(TranspilationModes = exports.TranspilationModes || (exports.TranspilationModes = {}));
|
|
10
10
|
const builders = {
|
|
11
11
|
bundle: {
|
|
@@ -47,7 +47,7 @@ const builders = {
|
|
|
47
47
|
coerce: (arg) => {
|
|
48
48
|
const port = Number.parseInt(String(arg), 10);
|
|
49
49
|
if (Number.isNaN(port)) {
|
|
50
|
-
throw new Error(`Invalid port: ${arg}`);
|
|
50
|
+
throw new Error(`Invalid port: ${String(arg)}`);
|
|
51
51
|
}
|
|
52
52
|
return port;
|
|
53
53
|
},
|
|
@@ -98,7 +98,7 @@ const builders = {
|
|
|
98
98
|
type: 'string',
|
|
99
99
|
describe: 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',
|
|
100
100
|
demandOption: false,
|
|
101
|
-
default: TranspilationModes.
|
|
101
|
+
default: TranspilationModes.LocalOnly,
|
|
102
102
|
choices: Object.values(TranspilationModes),
|
|
103
103
|
},
|
|
104
104
|
depsToTranspile: {
|
package/dist/builders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;AAsBA,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,mDAA6B,CAAA;IAC7B,6CAAuB,CAAA;IACvB,mCAAa,CAAA;AACf,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B;AAED,MAAM,QAAQ,GAAqB;IACjC,MAAM,EAAE;QACN,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,gBAAgB;KAC1B;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,MAAM;KAChB;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,wCAAwC;QAClD,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,QAAQ,EAAE;QACR,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,6BAA6B;QACvC,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,+BAA+B;QACzC,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,CAAC,GAAY,EAAE,EAAE;YACvB,MAAM,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Q;QACd,QAAQ,EACN,iHAAiH;QACnH,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,kBAAkB,CAAC,SAAS;QACrC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC;KAC3C;IAED,eAAe,EAAE;QACf,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,yCAAyC;QACnD,YAAY,EAAE,KAAK;KACpB;IAED,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,yBAAyB;QACnC,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,aAAa,EAAE;QACb,QAAQ,EAAE,kDAAkD;QAC5D,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,KAAK,EAAE;QACL,QAAQ,EAAE,wCAAwC;QAClD,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,SAAS,EAAE;QACT,QAAQ,EAAE,sBAAsB;QAChC,IAAI,EAAE,QAAQ;KACf;CACF,CAAC;AAEF,kBAAe,QAAQ,CAAC","sourcesContent":["import { Options, PositionalOptions } from 'yargs';\n\nexport type SnapsCliBuilders = {\n readonly bundle: Readonly<Options>;\n readonly dist: Readonly<Options>;\n readonly eval: Readonly<Options>;\n readonly manifest: Readonly<Options>;\n readonly outfileName: Readonly<Options>;\n readonly port: Readonly<Options>;\n readonly root: Readonly<Options>;\n readonly sourceMaps: Readonly<Options>;\n readonly src: Readonly<Options>;\n readonly stripComments: Readonly<Options>;\n readonly suppressWarnings: Readonly<Options>;\n readonly transpilationMode: Readonly<Options>;\n readonly depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly directory: Readonly<PositionalOptions>;\n};\n\nexport enum TranspilationModes {\n LocalAndDeps = 'localAndDeps',\n LocalOnly = 'localOnly',\n None = 'none',\n}\n\nconst builders: SnapsCliBuilders = {\n bundle: {\n alias: 'b',\n describe: 'Snap bundle file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist/bundle.js',\n },\n\n dist: {\n alias: 'd',\n describe: 'Output directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist',\n },\n\n eval: {\n alias: 'e',\n describe: 'Attempt to evaluate Snap bundle in SES',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n manifest: {\n alias: 'm',\n describe: 'Validate snap.manifest.json',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n port: {\n alias: 'p',\n describe: 'Local server port for testing',\n type: 'number',\n demandOption: true,\n default: 8081,\n coerce: (arg: unknown) => {\n const port = Number.parseInt(String(arg), 10);\n if (Number.isNaN(port)) {\n throw new Error(`Invalid port: ${String(arg)}`);\n }\n return port;\n },\n },\n\n outfileName: {\n alias: 'n',\n describe: 'Output file name',\n type: 'string',\n demandOption: false,\n default: 'bundle.js',\n },\n\n root: {\n alias: 'r',\n describe: 'Server root directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: '.',\n },\n\n sourceMaps: {\n describe: 'Whether builds include sourcemaps',\n type: 'boolean',\n demandOption: false,\n default: false,\n },\n\n src: {\n alias: 's',\n describe: 'Source file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'src/index.js',\n },\n\n stripComments: {\n alias: 'strip',\n describe: 'Whether to remove code comments from the build output',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n suppressWarnings: {\n type: 'boolean',\n describe: 'Whether to suppress warnings',\n demandOption: false,\n default: false,\n },\n\n transpilationMode: {\n type: 'string',\n describe:\n 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',\n demandOption: false,\n default: TranspilationModes.LocalOnly,\n choices: Object.values(TranspilationModes),\n },\n\n depsToTranspile: {\n type: 'array',\n describe: 'Transpile only the listed dependencies.',\n demandOption: false,\n },\n\n verboseErrors: {\n type: 'boolean',\n describe: 'Display original errors',\n demandOption: false,\n default: true,\n },\n\n writeManifest: {\n describe: 'Make necessary changes to the Snap manifest file',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n serve: {\n describe: 'Serve Snap file(s) locally for testing',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n directory: {\n describe: 'the directory to use',\n type: 'string',\n },\n};\n\nexport default builders;\n"]}
|
package/dist/cli.js
CHANGED
|
@@ -39,8 +39,8 @@ function cli(argv, commands) {
|
|
|
39
39
|
(0, utils_1.setSnapGlobals)(yargsArgv);
|
|
40
40
|
(0, utils_1.sanitizeInputs)(yargsArgv);
|
|
41
41
|
}), true)
|
|
42
|
-
.fail((
|
|
43
|
-
(0, utils_1.logError)(
|
|
42
|
+
.fail((message, error, _yargs) => {
|
|
43
|
+
(0, utils_1.logError)(message, error);
|
|
44
44
|
process.exitCode = 1;
|
|
45
45
|
})
|
|
46
46
|
.demandCommand(1, 'You must specify at least one command.')
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAGzC,0DAAkC;AAClC,mCAMiB;AAEjB;;;;;;GAMG;AACH,SAAgB,GAAG,CAAC,IAAc,EAAE,QAAa;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,oEAAoE;IACpE,IAAA,eAAK,EAAC,OAAO,CAAC;SACX,UAAU,CAAC,SAAS,CAAC;SACrB,KAAK,CAAC,+BAA+B,CAAC;SAEtC,OAAO,CAAC,SAAS,EAAE,sDAAsD,CAAC;SAC1E,OAAO,CACN,+BAA+B,EAC/B,iEAAiE,CAClE;SACA,OAAO,CACN,iCAAiC,EACjC,6CAA6C,CAC9C;SACA,OAAO,CACN,4CAA4C,EAC5C,2CAA2C,CAC5C;SACA,OAAO,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;SACnE,OAAO,CAAC,yBAAyB,EAAE,uCAAuC,CAAC;SAC3E,OAAO,CACN,iCAAiC,EACjC,gGAAgG,CACjG;SAEA,OAAO,CAAC,QAAQ,CAAC;SAEjB,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;SAE/C,MAAM,CAAC,kBAAkB,EAAE,kBAAQ,CAAC,gBAAgB,CAAC;SAErD,MAAM,EAAE;QAET,gEAAgE;QAChE,+EAA+E;QAC/E,0FAA0F;SACzF,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE,aAA+B,EAAE,EAAE;QACzD,IAAA,mBAAW,EAAC,IAAA,kBAAU,GAAE,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC7D,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;QAC1B,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAQ,EACT,IAAI,CACL;SAEA,IAAI,CAAC,CAAC,OAAe,EAAE,KAAY,EAAE,MAAM,EAAE,EAAE;QAC9C,IAAA,gBAAQ,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC;SAED,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAE1D,IAAI,EAAE;SACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAxDD,kBAwDC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\n\nimport builders from './builders';\nimport {\n applyConfig,\n loadConfig,\n sanitizeInputs,\n setSnapGlobals,\n logError,\n} from './utils';\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport function cli(argv: string[], commands: any): void {\n const rawArgv = argv.slice(2);\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n yargs(rawArgv)\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize a snap project in the current directory`)\n .example(\n '$0 init --template javascript',\n `\\tInitialize a snap JavaScript project in the current directory`,\n )\n .example(\n '$0 build -s src/index.js -d out',\n `\\tBuild 'src/index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s src/index.js -d out -n snap.js',\n `\\tBuild 'src/index.js' as './out/snap.js'`,\n )\n .example('$0 serve -r out', `\\tServe files in './out' on port 8080`)\n .example('$0 serve -r out -p 9000', `\\tServe files in './out' on port 9000`)\n .example(\n '$0 watch -s src/index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`,\n )\n\n .command(commands)\n\n .option('verboseErrors', builders.verboseErrors)\n\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n // Typecast: The @types/yargs type for .middleware is incorrect.\n // yargs middleware functions receive the yargs instance as a second parameter.\n // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation\n .middleware(\n ((yargsArgv: Arguments, yargsInstance: typeof yargsType) => {\n applyConfig(loadConfig(), rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((message: string, error: Error, _yargs) => {\n logError(message, error);\n process.exitCode = 1;\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.build = void 0;
|
|
4
4
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
-
const manifestHandler_1 = require("../manifest/manifestHandler");
|
|
7
6
|
const evalHandler_1 = require("../eval/evalHandler");
|
|
7
|
+
const manifestHandler_1 = require("../manifest/manifestHandler");
|
|
8
8
|
const bundle_1 = require("./bundle");
|
|
9
9
|
/**
|
|
10
10
|
* Builds all files in the given source directory to the given destination
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;
|
|
1
|
+
{"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAG/B,uCAAyC;AACzC,qDAAkD;AAClD,iEAA8D;AAC9D,qCAAkC;AAElC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACxC,IAAI,WAAW,EAAE;QACf,IAAA,iCAAmB,EAAC,WAAW,CAAC,CAAC;KAClC;IACD,MAAM,IAAA,8BAAgB,EAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAA,6BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,IAAA,4BAAc,EAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,MAAM,IAAA,eAAM,EACzB,GAAG,EACH,WAAW,EACX,IAAI,EACJ,IAAA,kBAAU,GAAE,CAAC,iBAAiB,CAC/B,CAAC;IACF,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;QACvB,MAAM,IAAA,yBAAW,kCAAM,IAAI,KAAE,MAAM,EAAE,WAAW,IAAG,CAAC;KACrD;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,sBAsBC","sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Argv from 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 build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"]}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.bundle = void 0;
|
|
7
|
-
const browserify_1 = __importDefault(require("browserify"));
|
|
8
7
|
const snaps_browserify_plugin_1 = __importDefault(require("@metamask/snaps-browserify-plugin"));
|
|
8
|
+
const browserify_1 = __importDefault(require("browserify"));
|
|
9
9
|
const builders_1 = require("../../builders");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
// We need to statically import all Browserify transforms and all Babel presets
|
|
@@ -23,7 +23,7 @@ const utils_1 = require("./utils");
|
|
|
23
23
|
* @param bundlerTransform - An optional function which can be used to transform
|
|
24
24
|
* the Browserify instance, e.g., adding a custom transform or plugin.
|
|
25
25
|
*/
|
|
26
|
-
function bundle(src, dest, argv, bundlerTransform) {
|
|
26
|
+
async function bundle(src, dest, argv, bundlerTransform) {
|
|
27
27
|
const { sourceMaps: debug, transpilationMode } = argv;
|
|
28
28
|
const babelifyOptions = (0, utils_1.processDependencies)(argv);
|
|
29
29
|
return new Promise((resolve, _reject) => {
|
|
@@ -33,8 +33,8 @@ function bundle(src, dest, argv, bundlerTransform) {
|
|
|
33
33
|
// Standalone is required to properly support Snaps using module.exports
|
|
34
34
|
standalone: '<snap>',
|
|
35
35
|
});
|
|
36
|
-
if (transpilationMode !== builders_1.TranspilationModes.
|
|
37
|
-
bundler.transform(require('babelify'), Object.assign({ global: transpilationMode === builders_1.TranspilationModes.
|
|
36
|
+
if (transpilationMode !== builders_1.TranspilationModes.None) {
|
|
37
|
+
bundler.transform(require('babelify'), Object.assign({ global: transpilationMode === builders_1.TranspilationModes.LocalAndDeps, extensions: ['.js', '.ts'], presets: [
|
|
38
38
|
require('@babel/preset-typescript'),
|
|
39
39
|
[
|
|
40
40
|
require('@babel/preset-env'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,gGAAoE;AACpE,4DAA0D;AAE1D,6CAAoD;AAEpD,mCAA+D;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,mHAAmH;AAEnH;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,MAAM,CAC1B,GAAW,EACX,IAAY,EACZ,IAAe,EACf,gBAAsD;IAEtD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IACtD,MAAM,eAAe,GAAG,IAAA,2BAAmB,EAAC,IAAW,CAAC,CAAC;IACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,MAAM,OAAO,GAA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R,CAAC,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAhED,wBAgEC","sourcesContent":["import plugin, { Options } from '@metamask/snaps-browserify-plugin';\nimport browserify, { BrowserifyObject } from 'browserify';\n\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { processDependencies, writeBundleFile } from './utils';\n\n// We need to statically import all Browserify transforms and all Babel presets\n// and plugins, and calling `require` is the sanest way to do that.\n/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */\n\n/**\n * Builds a Snap bundle JS file from its JavaScript source.\n *\n * @param src - The source file path.\n * @param dest - The destination file path.\n * @param argv - Arguments as an object generated by `yargs`.\n * @param argv.sourceMaps - Whether to output sourcemaps.\n * @param argv.stripComments - Whether to remove comments from code.\n * @param argv.transpilationMode - The Babel transpilation mode.\n * @param bundlerTransform - An optional function which can be used to transform\n * the Browserify instance, e.g., adding a custom transform or plugin.\n */\nexport async function bundle(\n src: string,\n dest: string,\n argv: YargsArgs,\n bundlerTransform?: (bundler: BrowserifyObject) => void,\n): Promise<boolean> {\n const { sourceMaps: debug, transpilationMode } = argv;\n const babelifyOptions = processDependencies(argv as any);\n return new Promise((resolve, _reject) => {\n const bundler = browserify(src, {\n debug,\n extensions: ['.js', '.ts'],\n // Standalone is required to properly support Snaps using module.exports\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: ['chrome >= 66', 'firefox >= 68'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-object-rest-spread'),\n require('@babel/plugin-proposal-optional-chaining'),\n require('@babel/plugin-proposal-nullish-coalescing-operator'),\n ],\n parserOpts: {\n attachComment: !argv.stripComments,\n },\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin<Options>(plugin, {\n stripComments: argv.stripComments,\n manifestPath: undefined,\n eval: false,\n });\n\n bundler.bundle(\n async (bundleError, bundleBuffer: Buffer) =>\n await writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n }),\n );\n });\n}\n"]}
|
package/dist/cmds/build/index.js
CHANGED
|
@@ -24,6 +24,6 @@ module.exports = {
|
|
|
24
24
|
.implies('depsToTranspile', 'transpilationMode')
|
|
25
25
|
.middleware((argv) => (0, utils_1.processInvalidTranspilation)(argv));
|
|
26
26
|
},
|
|
27
|
-
handler: (argv) => (0, buildHandler_1.build)(argv),
|
|
27
|
+
handler: async (argv) => (0, buildHandler_1.build)(argv),
|
|
28
28
|
};
|
|
29
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,iDAAuC;AACvC,mCAAsD;AAEtD,iBAAS;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,wBAAwB;IAC9B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,kBAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,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,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,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 { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nexport = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('dist', builders.dist)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('src', builders.src)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => build(argv),\n};\n"]}
|
package/dist/cmds/build/utils.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processInvalidTranspilation = exports.sanitizeDependencyPaths = exports.getDependencyRegExp = exports.processDependencies = exports.writeBundleFile = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
|
-
const misc_1 = require("../../utils/misc");
|
|
6
5
|
const builders_1 = require("../../builders");
|
|
6
|
+
const misc_1 = require("../../utils/misc");
|
|
7
7
|
/**
|
|
8
8
|
* Performs postprocessing on the bundle contents and writes them to disk.
|
|
9
9
|
* Intended to be used in the callback passed to the Browserify `.bundle()`
|
|
@@ -41,7 +41,7 @@ exports.writeBundleFile = writeBundleFile;
|
|
|
41
41
|
function processDependencies(argv) {
|
|
42
42
|
const { depsToTranspile, transpilationMode } = argv;
|
|
43
43
|
const babelifyOptions = {};
|
|
44
|
-
if (transpilationMode === builders_1.TranspilationModes.
|
|
44
|
+
if (transpilationMode === builders_1.TranspilationModes.LocalAndDeps) {
|
|
45
45
|
const regexpStr = getDependencyRegExp(depsToTranspile);
|
|
46
46
|
if (regexpStr !== null) {
|
|
47
47
|
babelifyOptions.ignore = [regexpStr];
|
|
@@ -57,12 +57,13 @@ exports.processDependencies = processDependencies;
|
|
|
57
57
|
* @returns A RegExp object.
|
|
58
58
|
*/
|
|
59
59
|
function getDependencyRegExp(dependencies) {
|
|
60
|
+
var _a;
|
|
60
61
|
let regexp = null;
|
|
61
62
|
if (!dependencies || dependencies.includes('.') || !dependencies.length) {
|
|
62
63
|
return regexp;
|
|
63
64
|
}
|
|
64
65
|
const paths = sanitizeDependencyPaths(dependencies);
|
|
65
|
-
regexp = `/node_modules/(?!${paths.shift()}`;
|
|
66
|
+
regexp = `/node_modules/(?!${(_a = paths.shift()) !== null && _a !== void 0 ? _a : ''}`;
|
|
66
67
|
paths.forEach((path) => (regexp += `|${path}`));
|
|
67
68
|
regexp += '/)';
|
|
68
69
|
return RegExp(regexp, 'u');
|
|
@@ -91,7 +92,7 @@ exports.sanitizeDependencyPaths = sanitizeDependencyPaths;
|
|
|
91
92
|
*/
|
|
92
93
|
function processInvalidTranspilation(argv) {
|
|
93
94
|
if (argv.depsToTranspile &&
|
|
94
|
-
argv.transpilationMode !== builders_1.TranspilationModes.
|
|
95
|
+
argv.transpilationMode !== builders_1.TranspilationModes.LocalAndDeps) {
|
|
95
96
|
throw new Error('"depsToTranspile" can only be specified if "transpilationMode" is set to "localAndDeps" .');
|
|
96
97
|
}
|
|
97
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/cmds/build/utils.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/cmds/build/utils.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AAEpC,6CAAoD;AAEpD,2CAA8C;AAU9C;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,eAAe,CAAC,EACpC,WAAW,EACX,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,OAAO,GACa;IACpB,IAAI,WAAW,EAAE;QACf,MAAM,IAAA,iBAAU,EAAC,cAAc,EAAE,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;KACpE;IAED,IAAI;QACF,MAAM,aAAE,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,QAAQ,EAAE,CAAC,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,iBAAiB,IAAI,IAAI,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,CAAC;KACf;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAA,iBAAU,EAAC,cAAc,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;KAC9D;AACH,CAAC;AAlBD,0CAkBC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,IAAe;IACjD,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IACpD,MAAM,eAAe,GAAwB,EAAE,C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kB,CAAC,YAAY,EAC1D;QACA,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;AACH,CAAC;AATD,kEASC","sourcesContent":["import { promises as fs } from 'fs';\n\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { writeError } from '../../utils/misc';\n\ntype WriteBundleFileArgs = {\n bundleError: Error;\n bundleBuffer: Buffer;\n src: string;\n dest: string;\n resolve: (value: boolean) => void;\n};\n\n/**\n * Performs postprocessing on the bundle contents and writes them to disk.\n * Intended to be used in the callback passed to the Browserify `.bundle()`\n * call.\n *\n * @param options - Options bag.\n * @param options.bundleError - Any error received from Browserify.\n * @param options.bundleBuffer - The {@link Buffer} with the bundle contents\n * from Browserify.\n * @param options.src - The source file path.\n * @param options.dest - The destination file path.\n * @param options.resolve - A {@link Promise} resolution function, so that we\n * can use promises and `async`/`await` even though Browserify uses callbacks.\n */\nexport async function writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n}: WriteBundleFileArgs) {\n if (bundleError) {\n await writeError('Build error:', bundleError.message, bundleError);\n }\n\n try {\n await fs.writeFile(dest, bundleBuffer?.toString());\n console.log(`Build success: '${src}' bundled as '${dest}'!`);\n resolve(true);\n } catch (error) {\n await writeError('Write error:', error.message, error, dest);\n }\n}\n\n/**\n * Processes dependencies and updates `argv` with an options object.\n *\n * @param argv - The Yargs arguments object.\n * @returns An object with options that can be passed to Babelify.\n */\nexport function processDependencies(argv: YargsArgs) {\n const { depsToTranspile, transpilationMode } = argv;\n const babelifyOptions: Record<string, any> = {};\n if (transpilationMode === TranspilationModes.LocalAndDeps) {\n const regexpStr = getDependencyRegExp(depsToTranspile as string[]);\n if (regexpStr !== null) {\n babelifyOptions.ignore = [regexpStr];\n }\n }\n return babelifyOptions;\n}\n\n/**\n * Processes a string of space delimited dependencies into one RegExp string.\n *\n * @param dependencies - An array of dependencies to add to the RegExp.\n * @returns A RegExp object.\n */\nexport function getDependencyRegExp(dependencies: string[]): RegExp | null {\n let regexp: string | null = null;\n if (!dependencies || dependencies.includes('.') || !dependencies.length) {\n return regexp;\n }\n const paths: string[] = sanitizeDependencyPaths(dependencies);\n regexp = `/node_modules/(?!${paths.shift() ?? ''}`;\n paths.forEach((path) => (regexp += `|${path}`));\n regexp += '/)';\n return RegExp(regexp, 'u');\n}\n\n/**\n * Helper function remove any leading and trailing slashes from dependency list.\n *\n * @param dependencies - An array of dependencies to sanitize.\n * @returns An array of sanitized paths.\n */\nexport function sanitizeDependencyPaths(dependencies: string[]): string[] {\n return dependencies.map((dependency) => {\n return dependency.replace(/^[/\\\\]+/u, '').replace(/[/\\\\]+$/u, '');\n });\n}\n\n/**\n * Check the Yargs argv object, to see if the provided options are valid. The\n * options are invalid if both `depsToTranspile` are provided, and\n * `transpilationMode` is not set to `localAndDeps`.\n *\n * @param argv - The Yargs arguments object.\n * @throws If the `depsToTranspile` is set, and `transpilationMode` is not set\n * to `localAndDeps`.\n */\nexport function processInvalidTranspilation(argv: YargsArgs) {\n if (\n argv.depsToTranspile &&\n argv.transpilationMode !== TranspilationModes.LocalAndDeps\n ) {\n throw new Error(\n '\"depsToTranspile\" can only be specified if \"transpilationMode\" is set to \"localAndDeps\" .',\n );\n }\n}\n"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.evalHandler = void 0;
|
|
4
4
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
5
6
|
/**
|
|
6
7
|
* Runs the snap in a worker, to ensure SES compatibility.
|
|
7
8
|
*
|
|
@@ -11,6 +12,7 @@ const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
|
11
12
|
*/
|
|
12
13
|
async function evalHandler(argv) {
|
|
13
14
|
const { bundle: bundlePath } = argv;
|
|
15
|
+
(0, utils_1.assert)(typeof bundlePath === 'string');
|
|
14
16
|
try {
|
|
15
17
|
await (0, snaps_utils_1.evalBundle)(bundlePath);
|
|
16
18
|
console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;
|
|
1
|
+
{"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AACnD,2CAAyC;AAIzC;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAEpC,IAAA,cAAM,EAAC,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC;IAEvC,IAAI;QACF,MAAM,IAAA,wBAAU,EAAC,UAAU,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,4BAA4B,UAAU,WAAW,CAAC,CAAC;KAChE;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5D;AACH,CAAC;AAXD,kCAWC","sourcesContent":["import { evalBundle } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport { YargsArgs } from '../../types/yargs';\n\n/**\n * Runs the snap in a worker, to ensure SES compatibility.\n *\n * @param argv - The Yargs arguments object.\n * @returns A promise that resolves once the eval has finished.\n * @throws If the eval failed.\n */\nexport async function evalHandler(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n\n assert(typeof bundlePath === 'string');\n\n try {\n await evalBundle(bundlePath);\n console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"]}
|
package/dist/cmds/eval/index.js
CHANGED
|
@@ -10,6 +10,6 @@ module.exports = {
|
|
|
10
10
|
builder: (yarg) => {
|
|
11
11
|
yarg.option('bundle', builders_1.default.bundle);
|
|
12
12
|
},
|
|
13
|
-
handler: (argv) => (0, evalHandler_1.evalHandler)(argv),
|
|
13
|
+
handler: async (argv) => (0, evalHandler_1.evalHandler)(argv),
|
|
14
14
|
};
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/eval/index.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/eval/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,+CAA4C;AAE5C,iBAAS;IACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC;IACtB,IAAI,EAAE,wCAAwC;IAC9C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,kBAAQ,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAA,yBAAW,EAAC,IAAI,CAAC;CACtD,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { evalHandler } from './evalHandler';\n\nexport = {\n command: ['eval', 'e'],\n desc: 'Attempt to evaluate Snap bundle in SES',\n builder: (yarg: yargs.Argv) => {\n yarg.option('bundle', builders.bundle);\n },\n handler: async (argv: YargsArgs) => evalHandler(argv),\n};\n"]}
|
package/dist/cmds/init/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAW5C;;;;;;GAMG;AACH,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC;IAExC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEpC,MAAM,IAAA,oBAAK,kCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,CAAC;AA5BD,iBAAS;IACP,OAAO,EAAE,CAAC,kBAAkB,EAAE,eAAe,CAAC;IAC9C,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,kBAAQ,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CAC/C,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler } from './initHandler';\n\nexport = {\n command: ['init [directory]', 'i [directory]'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg.positional('directory', builders.directory);\n },\n handler: async (argv: YargsArgs) => init(argv),\n};\n\n/**\n * The main entrypoint for the init command. This calls the init handler to\n * initialize the snap package, builds the snap, and then updates the manifest\n * with the shasum of the built snap.\n *\n * @param argv - The Yargs arguments object.\n */\nasync function init(argv: YargsArgs): Promise<void> {\n const newArgs = await initHandler(argv);\n\n process.chdir(newArgs.snapLocation);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n console.log('\\nSnap project successfully initiated!');\n}\n"]}
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.initHandler = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
7
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const initUtils_1 = require("./initUtils");
|
|
11
11
|
const SATISFIED_VERSION = '>=16';
|
|
12
12
|
/**
|
|
@@ -36,20 +36,20 @@ async function initHandler(argv) {
|
|
|
36
36
|
await (0, initUtils_1.prepareWorkingDirectory)(directoryToUse);
|
|
37
37
|
try {
|
|
38
38
|
console.log(`Cloning template...`);
|
|
39
|
-
|
|
40
|
-
fs_1.promises.rm(path_1.default.join(directoryToUse, '.git'), {
|
|
39
|
+
(0, initUtils_1.cloneTemplate)(directoryToUse);
|
|
40
|
+
await fs_1.promises.rm(path_1.default.join(directoryToUse, '.git'), {
|
|
41
41
|
force: true,
|
|
42
42
|
recursive: true,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
catch (
|
|
45
|
+
catch (error) {
|
|
46
46
|
throw new Error('Init Error: Failed to create template.');
|
|
47
47
|
}
|
|
48
48
|
console.log('Installing dependencies...');
|
|
49
|
-
|
|
49
|
+
(0, initUtils_1.yarnInstall)(directoryToUse);
|
|
50
50
|
if (!(0, initUtils_1.isInGitRepository)(directoryToUse)) {
|
|
51
51
|
console.log('Initializing git repository...');
|
|
52
|
-
|
|
52
|
+
(0, initUtils_1.gitInit)(directoryToUse);
|
|
53
53
|
}
|
|
54
54
|
const snapLocation = path_1.default.join(directoryToUse, initUtils_1.SNAP_LOCATION);
|
|
55
55
|
const manifest = await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.Manifest));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,uDAQ+B;AAC/B,2BAAoC;AACpC,gDAA6B;AAG7B,2CAQqB;AAErB,MAAM,iBAAiB,GAAG,MAAqB,CAAC;AAEhD;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAE3B,MAAM,kBAAkB,GAAG,IAAA,mCAAqB,EAC9C,OAAO,CAAC,OAAwB,EAChC,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE;QACvB,MAAM,IAAI,KAAK,CACb,0DAA0D,OAAO,CAAC,OAAO,4BAA4B,iBAAiB,GAAG,CAC1H,CAAC;KACH;IAED,MAAM,SAAS,GAAG,IAAA,0BAAc,GAAE,CAAC;IACnC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;KACH;IAED,MAAM,cAAc,GAAG,SAAS;QAC9B,CAAC,CAAC,cAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC;QAC1C,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAElB,OAAO,CAAC,GAAG,CAAC,aAAa,cAAc,KAAK,CAAC,CAAC;IAE9C,MAAM,IAAA,mCAAuB,EAAC,cAAc,CAAC,CAAC;IAE9C,IAAI;QACF,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,IAAA,yBAAa,EAAC,cAAc,CAAC,CAAC;QAE9B,MAAM,aAAE,CAAC,EAAE,CAAC,cAAS,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE;YAClD,KAAK,EAAE,IAAI;YACX,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAC1C,IAAA,uBAAW,EAAC,cAAc,CAAC,CAAC;IAE5B,IAAI,CAAC,IAAA,6BAAiB,EAAC,cAAc,CAAC,EAAE;QACtC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAC9C,IAAA,mBAAO,EAAC,cAAc,CAAC,CAAC;KACzB;IAED,MAAM,YAAY,GAAG,cAAS,CAAC,IAAI,CAAC,cAAc,EAAE,yBAAa,CAAC,CAAC;IAEnE,MAAM,QAAQ,GAAiB,MAAM,IAAA,0BAAY,EAC/C,cAAS,CAAC,IAAI,CAAC,YAAY,EAAE,8BAAgB,CAAC,QAAQ,CAAC,CACxD,CAAC;IACF,MAAM,WAAW,GAAuB,MAAM,IAAA,0BAAY,EACxD,cAAS,CAAC,IAAI,CAAC,YAAY,EAAE,8BAAgB,CAAC,WAAW,CAAC,CAC3D,CAAC;IAEF,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAElE,uCACK,IAAI,KACP,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,EACxB,GAAG,EAAE,WAAW,CAAC,IAAI,IAAI,cAAc,EACvC,YAAY,IACZ;AACJ,CAAC;AAnED,kCAmEC","sourcesContent":["import {\n NpmSnapFileNames,\n SnapManifest,\n readJsonFile,\n satisfiesVersionRange,\n NpmSnapPackageJson,\n SemVerVersion,\n SemVerRange,\n} from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { YargsArgs } from '../../types/yargs';\nimport {\n cloneTemplate,\n gitInit,\n isGitInstalled,\n isInGitRepository,\n prepareWorkingDirectory,\n SNAP_LOCATION,\n yarnInstall,\n} from './initUtils';\n\nconst SATISFIED_VERSION = '>=16' as SemVerRange;\n\n/**\n * Creates a new snap package, based on one of the provided templates. This\n * creates all the necessary files, like `package.json`, `snap.config.js`, etc.\n * to start developing a snap.\n *\n * @param argv - The Yargs arguments object.\n * @returns The Yargs arguments augmented with the new `dist`, `outfileName` and\n * `src` properties.\n * @throws If initialization of the snap package failed.\n */\nexport async function initHandler(argv: YargsArgs) {\n const { directory } = argv;\n\n const isVersionSupported = satisfiesVersionRange(\n process.version as SemVerVersion,\n SATISFIED_VERSION,\n );\n\n if (!isVersionSupported) {\n throw new Error(\n `Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`,\n );\n }\n\n const gitExists = isGitInstalled();\n if (!gitExists) {\n throw new Error(\n `Init Error: git is not installed. Please install git to continue.`,\n );\n }\n\n const directoryToUse = directory\n ? pathUtils.join(process.cwd(), directory)\n : process.cwd();\n\n console.log(`Preparing ${directoryToUse}...`);\n\n await prepareWorkingDirectory(directoryToUse);\n\n try {\n console.log(`Cloning template...`);\n cloneTemplate(directoryToUse);\n\n await fs.rm(pathUtils.join(directoryToUse, '.git'), {\n force: true,\n recursive: true,\n });\n } catch (error) {\n throw new Error('Init Error: Failed to create template.');\n }\n\n console.log('Installing dependencies...');\n yarnInstall(directoryToUse);\n\n if (!isInGitRepository(directoryToUse)) {\n console.log('Initializing git repository...');\n gitInit(directoryToUse);\n }\n\n const snapLocation = pathUtils.join(directoryToUse, SNAP_LOCATION);\n\n const manifest: SnapManifest = await readJsonFile(\n pathUtils.join(snapLocation, NpmSnapFileNames.Manifest),\n );\n const packageJson: NpmSnapPackageJson = await readJsonFile(\n pathUtils.join(snapLocation, NpmSnapFileNames.PackageJson),\n );\n\n const distPath = manifest.source.location.npm.filePath.split('/');\n\n return {\n ...argv,\n dist: distPath[0],\n outfileName: distPath[1],\n src: packageJson.main || 'src/index.js',\n snapLocation,\n };\n}\n"]}
|
|
@@ -11,7 +11,7 @@ export declare function prepareWorkingDirectory(directory: string): Promise<void
|
|
|
11
11
|
*
|
|
12
12
|
* @param directory - The directory to clone the template in.
|
|
13
13
|
*/
|
|
14
|
-
export declare function cloneTemplate(directory: string):
|
|
14
|
+
export declare function cloneTemplate(directory: string): void;
|
|
15
15
|
/**
|
|
16
16
|
* Check if git is installed.
|
|
17
17
|
*
|
|
@@ -30,10 +30,10 @@ export declare function isInGitRepository(directory: string): boolean;
|
|
|
30
30
|
*
|
|
31
31
|
* @param directory - The directory to init.
|
|
32
32
|
*/
|
|
33
|
-
export declare function gitInit(directory: string):
|
|
33
|
+
export declare function gitInit(directory: string): void;
|
|
34
34
|
/**
|
|
35
35
|
* Install dependencies in a yarn project.
|
|
36
36
|
*
|
|
37
37
|
* @param directory - The directory containing the project.
|
|
38
38
|
*/
|
|
39
|
-
export declare function yarnInstall(directory: string):
|
|
39
|
+
export declare function yarnInstall(directory: string): void;
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.yarnInstall = exports.gitInit = exports.isInGitRepository = exports.isGitInstalled = exports.cloneTemplate = exports.prepareWorkingDirectory = exports.SNAP_LOCATION = exports.TEMPLATE_GIT_URL = void 0;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
7
|
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
exports.TEMPLATE_GIT_URL = 'https://github.com/MetaMask/template-snap-monorepo.git';
|
|
11
11
|
exports.SNAP_LOCATION = 'packages/snap/';
|
|
@@ -21,7 +21,7 @@ async function prepareWorkingDirectory(directory) {
|
|
|
21
21
|
try {
|
|
22
22
|
await fs_1.promises.mkdir(directory, { recursive: true });
|
|
23
23
|
}
|
|
24
|
-
catch (
|
|
24
|
+
catch (error) {
|
|
25
25
|
throw new Error('Init Error: Failed to create new directory.');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -30,8 +30,8 @@ async function prepareWorkingDirectory(directory) {
|
|
|
30
30
|
throw new Error(`Directory ${directory} not empty.`);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
catch (
|
|
34
|
-
throw new Error(`Init Error: Failed to prepare working directory with message: ${
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error(`Init Error: Failed to prepare working directory with message: ${error.message}`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
exports.prepareWorkingDirectory = prepareWorkingDirectory;
|
|
@@ -40,13 +40,13 @@ exports.prepareWorkingDirectory = prepareWorkingDirectory;
|
|
|
40
40
|
*
|
|
41
41
|
* @param directory - The directory to clone the template in.
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
function cloneTemplate(directory) {
|
|
44
44
|
try {
|
|
45
45
|
(0, child_process_1.execSync)(`git clone --depth=1 ${exports.TEMPLATE_GIT_URL} ${directory}`, {
|
|
46
46
|
stdio: [2],
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
catch (
|
|
49
|
+
catch (error) {
|
|
50
50
|
throw new Error('Init Error: Failed to clone the template.');
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -61,7 +61,7 @@ function isGitInstalled() {
|
|
|
61
61
|
(0, child_process_1.execSync)('git --version', { stdio: 'ignore' });
|
|
62
62
|
return true;
|
|
63
63
|
}
|
|
64
|
-
catch (
|
|
64
|
+
catch (error) {
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -80,7 +80,7 @@ function isInGitRepository(directory) {
|
|
|
80
80
|
});
|
|
81
81
|
return true;
|
|
82
82
|
}
|
|
83
|
-
catch (
|
|
83
|
+
catch (error) {
|
|
84
84
|
return false;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -90,14 +90,14 @@ exports.isInGitRepository = isInGitRepository;
|
|
|
90
90
|
*
|
|
91
91
|
* @param directory - The directory to init.
|
|
92
92
|
*/
|
|
93
|
-
|
|
93
|
+
function gitInit(directory) {
|
|
94
94
|
try {
|
|
95
95
|
(0, child_process_1.execSync)('git init', {
|
|
96
96
|
stdio: 'ignore',
|
|
97
97
|
cwd: path_1.default.resolve(__dirname, directory),
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
catch (
|
|
100
|
+
catch (error) {
|
|
101
101
|
throw new Error('Init Error: Failed to init a new git repository.');
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -107,14 +107,14 @@ exports.gitInit = gitInit;
|
|
|
107
107
|
*
|
|
108
108
|
* @param directory - The directory containing the project.
|
|
109
109
|
*/
|
|
110
|
-
|
|
110
|
+
function yarnInstall(directory) {
|
|
111
111
|
try {
|
|
112
112
|
(0, child_process_1.execSync)('yarn install', {
|
|
113
113
|
stdio: [0, 1, 2],
|
|
114
114
|
cwd: path_1.default.resolve(__dirname, directory),
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
catch (
|
|
117
|
+
catch (error) {
|
|
118
118
|
throw new Error('Init Error: Failed to install dependencies.');
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initUtils.js","sourceRoot":"","sources":["../../../src/cmds/init/initUtils.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"initUtils.js","sourceRoot":"","sources":["../../../src/cmds/init/initUtils.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAyC;AACzC,2BAAoC;AACpC,gDAA6B;AAEhB,QAAA,gBAAgB,GAC3B,wDAAwD,CAAC;AAE9C,QAAA,aAAa,GAAG,gBAAgB,CAAC;AAE9C;;;;GAIG;AACI,KAAK,UAAU,uBAAuB,CAC3C,SAAiB;IAEjB,IAAI;QACF,MAAM,kBAAkB,GAAG,SAAS,KAAK,OAAO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AAE,cAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7C,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAVD,8CAUC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,SAAiB;IACvC,IAAI;QACF,IAAA,wBAAQ,EAAC,UAAU,EAAE;YACnB,KAAK,EAAE,QAAQ;YACf,GAAG,EAAE,cAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7C,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;KACrE;AACH,CAAC;AATD,0BASC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAC,SAAiB;IAC3C,IAAI;QACF,IAAA,wBAAQ,EAAC,cAAc,EAAE;YACvB,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAChB,GAAG,EAAE,cAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7C,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAChE;AACH,CAAC;AATD,kCASC","sourcesContent":["import { execSync } from 'child_process';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nexport const TEMPLATE_GIT_URL =\n 'https://github.com/MetaMask/template-snap-monorepo.git';\n\nexport const SNAP_LOCATION = 'packages/snap/';\n\n/**\n * Checks if the destination folder exists and if it's empty. Otherwise create it.\n *\n * @param directory - The desination folder.\n */\nexport async function prepareWorkingDirectory(\n directory: string,\n): Promise<void> {\n try {\n const isCurrentDirectory = directory === process.cwd();\n\n if (!isCurrentDirectory) {\n try {\n await fs.mkdir(directory, { recursive: true });\n } catch (error) {\n throw new Error('Init Error: Failed to create new directory.');\n }\n }\n\n const existingFiles = await fs.readdir(directory);\n\n if (existingFiles.length > 0) {\n throw new Error(`Directory ${directory} not empty.`);\n }\n } catch (error) {\n throw new Error(\n `Init Error: Failed to prepare working directory with message: ${error.message}`,\n );\n }\n}\n\n/**\n * Clones the template in a directory.\n *\n * @param directory - The directory to clone the template in.\n */\nexport function cloneTemplate(directory: string) {\n try {\n execSync(`git clone --depth=1 ${TEMPLATE_GIT_URL} ${directory}`, {\n stdio: [2],\n });\n } catch (error) {\n throw new Error('Init Error: Failed to clone the template.');\n }\n}\n\n/**\n * Check if git is installed.\n *\n * @returns True if git is installed, or false otherwise.\n */\nexport function isGitInstalled() {\n try {\n execSync('git --version', { stdio: 'ignore' });\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Check if the actual working dir is a git repository.\n *\n * @param directory - The directory to check.\n * @returns True if it's a git repository otherwise false.\n */\nexport function isInGitRepository(directory: string) {\n try {\n execSync('git rev-parse --is-inside-work-tree', {\n stdio: 'ignore',\n cwd: pathUtils.resolve(__dirname, directory),\n });\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Init a git repository.\n *\n * @param directory - The directory to init.\n */\nexport function gitInit(directory: string) {\n try {\n execSync('git init', {\n stdio: 'ignore',\n cwd: pathUtils.resolve(__dirname, directory),\n });\n } catch (error) {\n throw new Error('Init Error: Failed to init a new git repository.');\n }\n}\n\n/**\n * Install dependencies in a yarn project.\n *\n * @param directory - The directory containing the project.\n */\nexport function yarnInstall(directory: string) {\n try {\n execSync('yarn install', {\n stdio: [0, 1, 2],\n cwd: pathUtils.resolve(__dirname, directory),\n });\n } catch (error) {\n throw new Error('Init Error: Failed to install dependencies.');\n }\n}\n"]}
|
|
@@ -15,9 +15,9 @@ module.exports = {
|
|
|
15
15
|
try {
|
|
16
16
|
await (0, manifestHandler_1.manifestHandler)(argv);
|
|
17
17
|
}
|
|
18
|
-
catch (
|
|
19
|
-
(0, utils_1.logError)(
|
|
20
|
-
throw
|
|
18
|
+
catch (error) {
|
|
19
|
+
(0, utils_1.logError)(error.message, error);
|
|
20
|
+
throw error;
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/manifest/index.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/manifest/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,uCAAuC;AACvC,uDAAoD;AAEpD,iBAAS;IACP,OAAO,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC;IAC1B,IAAI,EAAE,sCAAsC;IAC5C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,eAAe,kCAAO,kBAAQ,CAAC,aAAa,KAAE,KAAK,EAAE,CAAC,KAAK,CAAC,IAAG,CAAC;IAC9E,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE;QACjC,IAAI;YACF,MAAM,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;SAC7B;QAAC,OAAO,KAAK,EAAE;YACd,IAAA,gBAAQ,EAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC/B,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CACF,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\nimport { manifestHandler } from './manifestHandler';\n\nexport = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('writeManifest', { ...builders.writeManifest, alias: ['fix'] });\n },\n handler: async (argv: YargsArgs) => {\n try {\n await manifestHandler(argv);\n } catch (error) {\n logError(error.message, error);\n throw error;\n }\n },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../../src/cmds/manifest/manifestHandler.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;
|
|
1
|
+
{"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../../src/cmds/manifest/manifestHandler.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AAItD,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,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,0BAA0B,CAAC,CAAC;YACzD,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,OAAO,CAAC,GAAG,CACT,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,OAAO,CAAC,GAAG,CAAC,qBAAqB,OAAO,EAAE,CAAC,CAAC;KAC7C;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,OAAe;IACvC,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,GAAG,OAAO,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import { checkManifest } 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 console.error(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n console.log(\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 console.log(`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 console.error(`${ERROR_PREFIX}${message}`);\n}\n"]}
|
package/dist/cmds/serve/index.js
CHANGED
|
@@ -10,6 +10,6 @@ module.exports = {
|
|
|
10
10
|
builder: (yarg) => {
|
|
11
11
|
yarg.option('root', builders_1.default.root).option('port', builders_1.default.port);
|
|
12
12
|
},
|
|
13
|
-
handler: (argv) => (0, serveHandler_1.serve)(argv),
|
|
13
|
+
handler: async (argv) => (0, serveHandler_1.serve)(argv),
|
|
14
14
|
};
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/serve/index.ts"],"names":[],"mappings":";;;;
|
|
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"]}
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.serve = void 0;
|
|
7
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
8
|
const http_1 = __importDefault(require("http"));
|
|
8
9
|
const serve_handler_1 = __importDefault(require("serve-handler"));
|
|
9
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
10
10
|
const serveUtils_1 = require("./serveUtils");
|
|
11
11
|
/**
|
|
12
12
|
* Starts a local, static HTTP server on the given port with the given root
|
|
@@ -20,8 +20,9 @@ async function serve(argv) {
|
|
|
20
20
|
const { port, root: rootDir } = argv;
|
|
21
21
|
await (0, snaps_utils_1.validateDirPath)(rootDir, true);
|
|
22
22
|
console.log(`\nStarting server...`);
|
|
23
|
-
const server = http_1.default.createServer(
|
|
24
|
-
|
|
23
|
+
const server = http_1.default.createServer((req, res) => {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = (0, serve_handler_1.default)(req, res, {
|
|
25
26
|
public: rootDir,
|
|
26
27
|
headers: [
|
|
27
28
|
{
|
|
@@ -38,6 +39,10 @@ async function serve(argv) {
|
|
|
38
39
|
],
|
|
39
40
|
},
|
|
40
41
|
],
|
|
42
|
+
})) === null || _a === void 0 ? void 0 : _a.catch((error) => {
|
|
43
|
+
(0, serveUtils_1.logServerError)(error, argv.port);
|
|
44
|
+
res.statusCode = 500;
|
|
45
|
+
res.end();
|
|
41
46
|
});
|
|
42
47
|
});
|
|
43
48
|
server.listen({ port }, () => (0, serveUtils_1.logServerListening)(port));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serveHandler.js","sourceRoot":"","sources":["../../../src/cmds/serve/serveHandler.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,kEAAyC;
|
|
1
|
+
{"version":3,"file":"serveHandler.js","sourceRoot":"","sources":["../../../src/cmds/serve/serveHandler.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAwD;AACxD,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,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAEpC,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;;QAC5C,MAAA,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,0CAAE,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,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC;AA7CD,sBA6CC","sourcesContent":["import { 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 console.log(`\\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 console.log('Server closed');\n process.exitCode = 1;\n });\n}\n"]}
|
package/dist/cmds/watch/index.js
CHANGED
|
@@ -27,6 +27,6 @@ module.exports = {
|
|
|
27
27
|
.implies('depsToTranspile', 'transpilationMode')
|
|
28
28
|
.middleware((argv) => (0, utils_1.processInvalidTranspilation)(argv));
|
|
29
29
|
},
|
|
30
|
-
handler: (argv) => (0, watchHandler_1.watch)(argv),
|
|
30
|
+
handler: async (argv) => (0, watchHandler_1.watch)(argv),
|
|
31
31
|
};
|
|
32
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/watch/index.ts"],"names":[],"mappings":";;;;
|
|
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"]}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.watch = void 0;
|
|
7
|
-
const chokidar_1 = __importDefault(require("chokidar"));
|
|
8
7
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
+
const chokidar_1 = __importDefault(require("chokidar"));
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
10
|
const bundle_1 = require("../build/bundle");
|
|
11
11
|
const evalHandler_1 = require("../eval/evalHandler");
|
|
@@ -30,7 +30,9 @@ async function watch(argv) {
|
|
|
30
30
|
}
|
|
31
31
|
await (0, snaps_utils_1.validateFilePath)(src);
|
|
32
32
|
await (0, snaps_utils_1.validateDirPath)(dist, true);
|
|
33
|
-
const rootDir = src.
|
|
33
|
+
const rootDir = src.includes('/')
|
|
34
|
+
? src.substring(0, src.lastIndexOf('/') + 1)
|
|
35
|
+
: '.';
|
|
34
36
|
const outfilePath = (0, snaps_utils_1.getOutfilePath)(dist, outfileName);
|
|
35
37
|
const buildSnap = async (path, logMessage) => {
|
|
36
38
|
if (logMessage !== undefined) {
|
|
@@ -65,14 +67,28 @@ async function watch(argv) {
|
|
|
65
67
|
(str) => str !== '.' && str.startsWith('.'),
|
|
66
68
|
],
|
|
67
69
|
})
|
|
68
|
-
.on('ready',
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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, utils_1.logError)('Error during initial build.', error);
|
|
80
|
+
});
|
|
81
|
+
})
|
|
82
|
+
.on('add', (path) => {
|
|
83
|
+
buildSnap(path, `File added: ${path}`).catch((error) => {
|
|
84
|
+
(0, utils_1.logError)(`Error while processing "${path}".`, error);
|
|
85
|
+
});
|
|
86
|
+
})
|
|
87
|
+
.on('change', (path) => {
|
|
88
|
+
buildSnap(path, `File changed: ${path}`).catch((error) => {
|
|
89
|
+
(0, utils_1.logError)(`Error while processing "${path}".`, error);
|
|
90
|
+
});
|
|
73
91
|
})
|
|
74
|
-
.on('add', (path) => buildSnap(path, `File added: ${path}`))
|
|
75
|
-
.on('change', (path) => buildSnap(path, `File changed: ${path}`))
|
|
76
92
|
.on('unlink', (path) => console.log(`File removed: ${path}`))
|
|
77
93
|
.on('error', (error) => {
|
|
78
94
|
(0, utils_1.logError)(`Watcher error: ${error.message}`, error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watchHandler.js","sourceRoot":"","sources":["../../../src/cmds/watch/watchHandler.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"watchHandler.js","sourceRoot":"","sources":["../../../src/cmds/watch/watchHandler.ts"],"names":[],"mappings":";;;;;;AAAA,uDAK+B;AAC/B,wDAAgC;AAGhC,uCAAmD;AACnD,4CAAyC;AACzC,qDAAkD;AAClD,iEAA8D;AAC9D,wDAA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IACL,CAAC,CAAC;SACD,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;SAC5D,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;QAC5B,IAAA,gBAAQ,EAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC;SAED,GAAG,CAAC,OAAO,CAAC,CAAC;IAEhB,OAAO,CAAC,GAAG,CAAC,aAAa,OAAO,kBAAkB,CAAC,CAAC;AACtD,CAAC;AA5FD,sBA4FC","sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\nimport chokidar from 'chokidar';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig, logError } 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 console.log(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) => console.log(`File removed: ${path}`))\n .on('error', (error: Error) => {\n logError(`Watcher error: ${error.message}`, error);\n })\n\n .add(rootDir);\n\n console.log(`Watching '${rootDir}' for changes...`);\n}\n"]}
|
package/dist/utils/misc.d.ts
CHANGED
|
@@ -29,27 +29,27 @@ export declare function sanitizeInputs(argv: Arguments): void;
|
|
|
29
29
|
* Logs an error message to console. Logs original error if it exists and
|
|
30
30
|
* the verboseErrors global is true.
|
|
31
31
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
32
|
+
* @param message - The error message.
|
|
33
|
+
* @param error - The original error.
|
|
34
34
|
*/
|
|
35
|
-
export declare function logError(
|
|
35
|
+
export declare function logError(message: string | null, error?: Error): void;
|
|
36
36
|
/**
|
|
37
37
|
* Logs a warning message to console.
|
|
38
38
|
*
|
|
39
|
-
* @param
|
|
39
|
+
* @param message - The warning message.
|
|
40
40
|
* @param error - The original error.
|
|
41
41
|
*/
|
|
42
|
-
export declare function logWarning(
|
|
42
|
+
export declare function logWarning(message: string, error?: Error): void;
|
|
43
43
|
/**
|
|
44
44
|
* Logs an error, attempts to unlink the destination file, and kills the
|
|
45
45
|
* process.
|
|
46
46
|
*
|
|
47
47
|
* @param prefix - The message prefix.
|
|
48
|
-
* @param
|
|
49
|
-
* @param
|
|
48
|
+
* @param message - The error message.
|
|
49
|
+
* @param error - The original error.
|
|
50
50
|
* @param destFilePath - The output file path.
|
|
51
51
|
*/
|
|
52
|
-
export declare function writeError(prefix: string,
|
|
52
|
+
export declare function writeError(prefix: string, message: string, error: Error, destFilePath?: string): Promise<void>;
|
|
53
53
|
/**
|
|
54
54
|
* Trims leading and trailing periods "." and forward slashes "/" from the
|
|
55
55
|
* given path string.
|
package/dist/utils/misc.js
CHANGED
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.trimPathString = exports.writeError = exports.logWarning = exports.logError = exports.sanitizeInputs = exports.booleanStringToBoolean = exports.setSnapGlobals = exports.CONFIG_FILE = exports.permRequestKeys = void 0;
|
|
7
|
+
const utils_1 = require("@metamask/utils");
|
|
7
8
|
const fs_1 = require("fs");
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const utils_1 = require("@metamask/utils");
|
|
10
10
|
exports.permRequestKeys = [
|
|
11
11
|
'@context',
|
|
12
12
|
'id',
|
|
@@ -68,7 +68,7 @@ function booleanStringToBoolean(value) {
|
|
|
68
68
|
else if (value === 'false') {
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
71
|
-
throw new Error(`Expected a boolean or the strings "true" or "false". Received: "${value}"`);
|
|
71
|
+
throw new Error(`Expected a boolean or the strings "true" or "false". Received: "${String(value)}"`);
|
|
72
72
|
}
|
|
73
73
|
exports.booleanStringToBoolean = booleanStringToBoolean;
|
|
74
74
|
/**
|
|
@@ -95,17 +95,17 @@ exports.sanitizeInputs = sanitizeInputs;
|
|
|
95
95
|
* Logs an error message to console. Logs original error if it exists and
|
|
96
96
|
* the verboseErrors global is true.
|
|
97
97
|
*
|
|
98
|
-
* @param
|
|
99
|
-
* @param
|
|
98
|
+
* @param message - The error message.
|
|
99
|
+
* @param error - The original error.
|
|
100
100
|
*/
|
|
101
|
-
function logError(
|
|
102
|
-
if (
|
|
103
|
-
console.error(
|
|
101
|
+
function logError(message, error) {
|
|
102
|
+
if (message !== null) {
|
|
103
|
+
console.error(message);
|
|
104
104
|
}
|
|
105
|
-
if (
|
|
106
|
-
console.error(
|
|
105
|
+
if (error && global.snaps.verboseErrors) {
|
|
106
|
+
console.error(error);
|
|
107
107
|
}
|
|
108
|
-
if (
|
|
108
|
+
if (message === null && (!error || (error && !global.snaps.verboseErrors))) {
|
|
109
109
|
console.error('Unknown error.');
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -113,12 +113,12 @@ exports.logError = logError;
|
|
|
113
113
|
/**
|
|
114
114
|
* Logs a warning message to console.
|
|
115
115
|
*
|
|
116
|
-
* @param
|
|
116
|
+
* @param message - The warning message.
|
|
117
117
|
* @param error - The original error.
|
|
118
118
|
*/
|
|
119
|
-
function logWarning(
|
|
120
|
-
if (
|
|
121
|
-
console.warn(
|
|
119
|
+
function logWarning(message, error) {
|
|
120
|
+
if (message && !global.snaps.suppressWarnings) {
|
|
121
|
+
console.warn(message);
|
|
122
122
|
if (error && global.snaps.verboseErrors) {
|
|
123
123
|
console.error(error);
|
|
124
124
|
}
|
|
@@ -130,16 +130,16 @@ exports.logWarning = logWarning;
|
|
|
130
130
|
* process.
|
|
131
131
|
*
|
|
132
132
|
* @param prefix - The message prefix.
|
|
133
|
-
* @param
|
|
134
|
-
* @param
|
|
133
|
+
* @param message - The error message.
|
|
134
|
+
* @param error - The original error.
|
|
135
135
|
* @param destFilePath - The output file path.
|
|
136
136
|
*/
|
|
137
|
-
async function writeError(prefix,
|
|
137
|
+
async function writeError(prefix, message, error, destFilePath) {
|
|
138
138
|
let processedPrefix = prefix;
|
|
139
139
|
if (!prefix.endsWith(' ')) {
|
|
140
140
|
processedPrefix += ' ';
|
|
141
141
|
}
|
|
142
|
-
logError(processedPrefix +
|
|
142
|
+
logError(processedPrefix + message, error);
|
|
143
143
|
try {
|
|
144
144
|
if (destFilePath) {
|
|
145
145
|
await fs_1.promises.unlink(destFilePath);
|
package/dist/utils/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA8C;AAC9C,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,WAAW,GAAG,gBAAgB,CAAC;AAE5C,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;;;;;;GAMG;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,IAAA,mBAAW,EAAC,IAAI,EAAE,eAAe,CAAC,EAAE;QACtC,MAAM,CAA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AC,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 { 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 console.error(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n console.error('Unknown error.');\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param message - The warning message.\n * @param error - The original error.\n */\nexport function logWarning(message: string, error?: Error): void {\n if (message && !global.snaps.suppressWarnings) {\n console.warn(message);\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 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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="watchify" />
|
|
2
2
|
import type browserify from 'browserify';
|
|
3
|
+
import { Infer } from 'superstruct';
|
|
3
4
|
import { Arguments } from 'yargs';
|
|
4
5
|
import yargs from 'yargs/yargs';
|
|
5
|
-
import { Infer } from 'superstruct';
|
|
6
6
|
export declare type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;
|
|
7
7
|
export declare const SnapConfigStruct: import("superstruct").Struct<{
|
|
8
8
|
cliOptions?: Record<string, unknown> | undefined;
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.applyConfig = exports.loadConfig = exports.isSnapConfig = exports.SnapConfigStruct = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
7
|
const utils_1 = require("@metamask/utils");
|
|
9
|
-
const
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
10
9
|
const superstruct_1 = require("superstruct");
|
|
10
|
+
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
11
11
|
const builders_1 = __importDefault(require("../builders"));
|
|
12
12
|
const misc_1 = require("./misc");
|
|
13
13
|
exports.SnapConfigStruct = (0, superstruct_1.object)({
|
|
@@ -38,7 +38,7 @@ let snapConfigCache;
|
|
|
38
38
|
* @returns The snap config.
|
|
39
39
|
*/
|
|
40
40
|
function loadConfig(cached = true) {
|
|
41
|
-
if (snapConfigCache !== undefined && cached
|
|
41
|
+
if (snapConfigCache !== undefined && cached) {
|
|
42
42
|
return snapConfigCache;
|
|
43
43
|
}
|
|
44
44
|
let config;
|
|
@@ -46,12 +46,12 @@ function loadConfig(cached = true) {
|
|
|
46
46
|
// eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
|
|
47
47
|
config = require(path_1.default.resolve(process.cwd(), misc_1.CONFIG_FILE));
|
|
48
48
|
}
|
|
49
|
-
catch (
|
|
50
|
-
if (
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
51
51
|
snapConfigCache = {};
|
|
52
52
|
return snapConfigCache;
|
|
53
53
|
}
|
|
54
|
-
(0, misc_1.logError)(`Error during parsing of ${misc_1.CONFIG_FILE}`,
|
|
54
|
+
(0, misc_1.logError)(`Error during parsing of ${misc_1.CONFIG_FILE}`, error);
|
|
55
55
|
return process.exit(1);
|
|
56
56
|
}
|
|
57
57
|
if (!isSnapConfig(config)) {
|
|
@@ -80,6 +80,7 @@ exports.loadConfig = loadConfig;
|
|
|
80
80
|
* @param yargsInstance - An instance of `yargs`.
|
|
81
81
|
*/
|
|
82
82
|
function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
|
|
83
|
+
var _a;
|
|
83
84
|
// Instances of yargs has a number of undocumented functions, including
|
|
84
85
|
// getOptions. This function returns an object with properties "key" and
|
|
85
86
|
// "alias", which specify the options associated with the current command and
|
|
@@ -100,11 +101,11 @@ function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
|
|
|
100
101
|
const shouldSetArg = (key) => {
|
|
101
102
|
return commandOptions.has(key) && !(0, utils_1.hasProperty)(parsedProcessArgv, key);
|
|
102
103
|
};
|
|
103
|
-
const
|
|
104
|
-
for (const key of Object.keys(
|
|
104
|
+
const config = (_a = snapConfig.cliOptions) !== null && _a !== void 0 ? _a : {};
|
|
105
|
+
for (const key of Object.keys(config)) {
|
|
105
106
|
if ((0, utils_1.hasProperty)(builders_1.default, key)) {
|
|
106
107
|
if (shouldSetArg(key)) {
|
|
107
|
-
yargsArgv[key] =
|
|
108
|
+
yargsArgv[key] = config[key];
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA8C;AAE9C,gDAAwB;AACxB,6CAAgE;AAEhE,gEAAsC;AAGtC,2DAAmC;AACnC,iCAA+C;AAIlC,QAAA,gBAAgB,GAAG,IAAA,oBAAM,EAAC;IACrC,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC9B,iBAAiB,EAAE,IAAA,sBAAQ,EAAC,IAAA,kBAAI,GAAE,CAAC;CACpC,CAAC,CAAC;AASH;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,wBAAgB,CAAC,CAAC;AACrC,CAAC;AAFD,oCAEC;AAED,IAAI,eAAuC,CAAC;AAE5C;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAC,MAAM,GAAG,IAAI;IACtC,IAAI,eAAe,KAAK,SAAS,IAAI,MAAM,EAAE;QAC3C,OAAO,eAAe,CAAC;KACxB;IAED,IAAI,MAAW,CAAC;IAChB,IAAI;QACF,iHAAiH;QACjH,MAAM,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,kBAAW,CAAC,CAAC,CAAC;KAC5D;IAAC,OAAO,KAAU,EAAE;QACnB,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACrC,eAAe,GAAG,EAAE,CAAC;YACrB,OAAO,eAAe,CAAC;SACxB;QACD,IAAA,eAAQ,EAAC,2BAA2B,kBAAW,EAAE,EAAE,KAAK,CAAC,CAAC;Q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,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACrC,IAAI,IAAA,mBAAW,EAAC,kBAAQ,EAAE,GAAG,CAAC,EAAE;YAC9B,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE;gBACrB,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;aAC9B;SACF;aAAM;YACL,IAAA,eAAQ,EACN,4DAA4D,GAAG,qBAAqB,kBAAW,uCAAuC,CACvI,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;KACF;AACH,CAAC;AAhDD,kCAgDC","sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport { object, optional, func, Infer, is } from 'superstruct';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n process.exit(1);\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
44
44
|
"@babel/preset-env": "^7.16.7",
|
|
45
45
|
"@babel/preset-typescript": "^7.16.7",
|
|
46
|
-
"@metamask/snaps-browserify-plugin": "^0.
|
|
47
|
-
"@metamask/snaps-utils": "^0.
|
|
46
|
+
"@metamask/snaps-browserify-plugin": "^0.26.0",
|
|
47
|
+
"@metamask/snaps-utils": "^0.26.0",
|
|
48
48
|
"@metamask/utils": "^3.3.1",
|
|
49
49
|
"babelify": "^10.0.0",
|
|
50
50
|
"browserify": "^17.0.0",
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@lavamoat/allow-scripts": "^2.0.3",
|
|
61
|
-
"@metamask/auto-changelog": "^
|
|
62
|
-
"@metamask/eslint-config": "^
|
|
63
|
-
"@metamask/eslint-config-jest": "^
|
|
64
|
-
"@metamask/eslint-config-nodejs": "^
|
|
65
|
-
"@metamask/eslint-config-typescript": "^
|
|
61
|
+
"@metamask/auto-changelog": "^3.1.0",
|
|
62
|
+
"@metamask/eslint-config": "^11.0.0",
|
|
63
|
+
"@metamask/eslint-config-jest": "^11.0.0",
|
|
64
|
+
"@metamask/eslint-config-nodejs": "^11.0.1",
|
|
65
|
+
"@metamask/eslint-config-typescript": "^11.0.0",
|
|
66
66
|
"@types/browserify": "^12.0.36",
|
|
67
67
|
"@types/is-url": "^1.2.28",
|
|
68
68
|
"@types/jest": "^27.5.1",
|
|
@@ -70,28 +70,28 @@
|
|
|
70
70
|
"@types/rimraf": "^3.0.0",
|
|
71
71
|
"@types/serve-handler": "^6.1.0",
|
|
72
72
|
"@types/yargs": "^15.0.12",
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
74
|
-
"@typescript-eslint/parser": "^5.
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
74
|
+
"@typescript-eslint/parser": "^5.42.1",
|
|
75
75
|
"clipboardy": "^2.3.0",
|
|
76
76
|
"deepmerge": "^4.2.2",
|
|
77
|
-
"eslint": "^
|
|
78
|
-
"eslint-config-prettier": "^8.
|
|
79
|
-
"eslint-plugin-import": "^2.
|
|
80
|
-
"eslint-plugin-jest": "^
|
|
81
|
-
"eslint-plugin-jsdoc": "^
|
|
77
|
+
"eslint": "^8.27.0",
|
|
78
|
+
"eslint-config-prettier": "^8.5.0",
|
|
79
|
+
"eslint-plugin-import": "^2.26.0",
|
|
80
|
+
"eslint-plugin-jest": "^27.1.5",
|
|
81
|
+
"eslint-plugin-jsdoc": "^39.6.2",
|
|
82
82
|
"eslint-plugin-node": "^11.1.0",
|
|
83
|
-
"eslint-plugin-prettier": "^
|
|
83
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
84
84
|
"execa": "^5.1.1",
|
|
85
85
|
"jest": "^29.0.2",
|
|
86
86
|
"jest-it-up": "^2.0.0",
|
|
87
87
|
"memfs": "^3.4.10",
|
|
88
|
-
"prettier": "^2.
|
|
88
|
+
"prettier": "^2.7.1",
|
|
89
89
|
"prettier-plugin-packagejson": "^2.2.11",
|
|
90
90
|
"rimraf": "^3.0.2",
|
|
91
91
|
"ts-jest": "^29.0.0",
|
|
92
92
|
"ts-node": "^10.7.0",
|
|
93
93
|
"tsc-watch": "^4.5.0",
|
|
94
|
-
"typescript": "
|
|
94
|
+
"typescript": "~4.8.4"
|
|
95
95
|
},
|
|
96
96
|
"engines": {
|
|
97
97
|
"node": ">=16.0.0"
|