@metamask/snaps-cli 0.17.0 → 0.19.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 +0 -1
- package/dist/builders.js +0 -6
- package/dist/builders.js.map +1 -1
- package/dist/cmds/build/buildHandler.js +7 -6
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/bundle.js +6 -11
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/build/index.js +0 -1
- package/dist/cmds/build/index.js.map +1 -1
- package/dist/cmds/build/utils.js +1 -1
- package/dist/cmds/build/utils.js.map +1 -1
- package/dist/cmds/eval/evalHandler.d.ts +1 -1
- package/dist/cmds/eval/evalHandler.js +8 -9
- 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 -5
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/init-template.json +1 -1
- package/dist/cmds/init/initHandler.js +9 -10
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +1 -1
- package/dist/cmds/init/initUtils.js +12 -12
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/index.js +1 -1
- package/dist/cmds/manifest/index.js.map +1 -1
- package/dist/cmds/manifest/manifestHandler.d.ts +1 -10
- package/dist/cmds/manifest/manifestHandler.js +23 -180
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/serve/serveHandler.js +6 -2
- package/dist/cmds/serve/serveHandler.js.map +1 -1
- package/dist/cmds/watch/index.js +0 -1
- package/dist/cmds/watch/index.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +6 -5
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/tsconfig.json +6 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/misc.d.ts +0 -1
- package/dist/utils/misc.js +1 -3
- package/dist/utils/misc.js.map +1 -1
- package/package.json +4 -5
- package/dist/cmds/eval/eval-worker.d.ts +0 -1
- package/dist/cmds/eval/eval-worker.js +0 -40
- package/dist/cmds/eval/eval-worker.js.map +0 -1
- package/dist/cmds/eval/mock.d.ts +0 -14
- package/dist/cmds/eval/mock.js +0 -98
- package/dist/cmds/eval/mock.js.map +0 -1
- package/dist/cmds/eval/workerEval.d.ts +0 -8
- package/dist/cmds/eval/workerEval.js +0 -37
- package/dist/cmds/eval/workerEval.js.map +0 -1
- package/dist/utils/fs.d.ts +0 -24
- package/dist/utils/fs.js +0 -66
- package/dist/utils/fs.js.map +0 -1
- package/dist/utils/snap-config.__GENERATED__.d.ts +0 -2
- package/dist/utils/snap-config.__GENERATED__.js +0 -18
- package/dist/utils/snap-config.__GENERATED__.js.map +0 -1
- package/dist/utils/validate-fs.d.ts +0 -35
- package/dist/utils/validate-fs.js +0 -69
- package/dist/utils/validate-fs.js.map +0 -1
package/dist/builders.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export declare type SnapsCliBuilders = {
|
|
|
12
12
|
readonly stripComments: Readonly<Options>;
|
|
13
13
|
readonly suppressWarnings: Readonly<Options>;
|
|
14
14
|
readonly transpilationMode: Readonly<Options>;
|
|
15
|
-
readonly transformHtmlComments: Readonly<Options>;
|
|
16
15
|
readonly depsToTranspile: Readonly<Options>;
|
|
17
16
|
readonly verboseErrors: Readonly<Options>;
|
|
18
17
|
readonly writeManifest: Readonly<Options>;
|
package/dist/builders.js
CHANGED
|
@@ -106,12 +106,6 @@ const builders = {
|
|
|
106
106
|
default: TranspilationModes.localOnly,
|
|
107
107
|
choices: Object.values(TranspilationModes),
|
|
108
108
|
},
|
|
109
|
-
transformHtmlComments: {
|
|
110
|
-
type: 'boolean',
|
|
111
|
-
describe: 'Whether to break up HTML comment tokens wherever they appear in your source code.',
|
|
112
|
-
demandOption: true,
|
|
113
|
-
default: true,
|
|
114
|
-
},
|
|
115
109
|
depsToTranspile: {
|
|
116
110
|
type: 'array',
|
|
117
111
|
describe: 'Transpile only the listed dependencies.',
|
package/dist/builders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;
|
|
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,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,yCAAyB,CAAA;IACzB,yCAAyB,CAAA;AAC3B,CAAC,EAHW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAGvB;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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AAI,EAAE,SAAS;QACf,QAAQ,EAAE,8BAA8B;QACxC,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;KACf;IAED,iBAAiB,EAAE;QACjB,IAAI,EAAE,QAAQ;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,QAAQ,EAAE;QACR,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,0DAA0D;QACpE,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,YAAY,CAAC,UAAU;QAChC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;KACrC;CACF,CAAC;AAEF,kBAAe,QAAQ,CAAC","sourcesContent":["import { Options } 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 template: Readonly<Options>;\n};\n\nexport enum TranspilationModes {\n localAndDeps = 'localAndDeps',\n localOnly = 'localOnly',\n none = 'none',\n}\n\nexport enum TemplateType {\n TypeScript = 'typescript',\n JavaScript = 'javascript',\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: ${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 template: {\n alias: 't',\n describe: 'Specify which template to use (TypeScript or JavaScript)',\n type: 'string',\n demandOption: false,\n default: TemplateType.TypeScript,\n choices: Object.values(TemplateType),\n },\n};\n\nexport default builders;\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.build = void 0;
|
|
4
|
+
const snap_utils_1 = require("@metamask/snap-utils");
|
|
4
5
|
const utils_1 = require("../../utils");
|
|
5
|
-
const evalHandler_1 = require("../eval/evalHandler");
|
|
6
6
|
const manifestHandler_1 = require("../manifest/manifestHandler");
|
|
7
|
+
const evalHandler_1 = require("../eval/evalHandler");
|
|
7
8
|
const bundle_1 = require("./bundle");
|
|
8
9
|
/**
|
|
9
10
|
* Builds all files in the given source directory to the given destination
|
|
@@ -19,14 +20,14 @@ const bundle_1 = require("./bundle");
|
|
|
19
20
|
async function build(argv) {
|
|
20
21
|
const { src, dist, outfileName } = argv;
|
|
21
22
|
if (outfileName) {
|
|
22
|
-
(0,
|
|
23
|
+
(0, snap_utils_1.validateOutfileName)(outfileName);
|
|
23
24
|
}
|
|
24
|
-
await (0,
|
|
25
|
-
await (0,
|
|
26
|
-
const outfilePath = (0,
|
|
25
|
+
await (0, snap_utils_1.validateFilePath)(src);
|
|
26
|
+
await (0, snap_utils_1.validateDirPath)(dist, true);
|
|
27
|
+
const outfilePath = (0, snap_utils_1.getOutfilePath)(dist, outfileName);
|
|
27
28
|
const result = await (0, bundle_1.bundle)(src, outfilePath, argv, (0, utils_1.loadConfig)().bundlerCustomizer);
|
|
28
29
|
if (result && argv.eval) {
|
|
29
|
-
await (0, evalHandler_1.
|
|
30
|
+
await (0, evalHandler_1.evalHandler)(Object.assign(Object.assign({}, argv), { bundle: outfilePath }));
|
|
30
31
|
}
|
|
31
32
|
if (argv.manifest) {
|
|
32
33
|
await (0, manifestHandler_1.manifestHandler)(argv);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,qDAK8B;AAE9B,uCAAyC;AACzC,iEAA8D;AAC9D,qDAAkD;AAClD,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,gCAAmB,EAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,IAAA,6BAAgB,EAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAA,4BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,IAAA,2BAAc,EAAC,IAAI,EAAE,WAAqB,CAAC,CAAC;IAChE,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/snap-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { evalHandler } from '../eval/evalHandler';\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 as string);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName as string);\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"]}
|
|
@@ -34,10 +34,7 @@ function bundle(src, dest, argv, bundlerTransform) {
|
|
|
34
34
|
standalone: '<snap>',
|
|
35
35
|
});
|
|
36
36
|
if (transpilationMode !== builders_1.TranspilationModes.none) {
|
|
37
|
-
bundler.transform(require('babelify'), {
|
|
38
|
-
global: transpilationMode === builders_1.TranspilationModes.localAndDeps,
|
|
39
|
-
extensions: ['.js', '.ts'],
|
|
40
|
-
presets: [
|
|
37
|
+
bundler.transform(require('babelify'), Object.assign({ global: transpilationMode === builders_1.TranspilationModes.localAndDeps, extensions: ['.js', '.ts'], presets: [
|
|
41
38
|
require('@babel/preset-typescript'),
|
|
42
39
|
[
|
|
43
40
|
require('@babel/preset-env'),
|
|
@@ -47,21 +44,19 @@ function bundle(src, dest, argv, bundlerTransform) {
|
|
|
47
44
|
},
|
|
48
45
|
},
|
|
49
46
|
],
|
|
50
|
-
],
|
|
51
|
-
plugins: [
|
|
47
|
+
], plugins: [
|
|
52
48
|
require('@babel/plugin-transform-runtime'),
|
|
53
49
|
require('@babel/plugin-proposal-class-properties'),
|
|
54
50
|
require('@babel/plugin-proposal-object-rest-spread'),
|
|
55
51
|
require('@babel/plugin-proposal-optional-chaining'),
|
|
56
52
|
require('@babel/plugin-proposal-nullish-coalescing-operator'),
|
|
57
|
-
],
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
], parserOpts: {
|
|
54
|
+
attachComment: !argv.stripComments,
|
|
55
|
+
} }, babelifyOptions));
|
|
60
56
|
}
|
|
61
|
-
bundlerTransform
|
|
57
|
+
bundlerTransform === null || bundlerTransform === void 0 ? void 0 : bundlerTransform(bundler);
|
|
62
58
|
bundler.plugin(snaps_browserify_plugin_1.default, {
|
|
63
59
|
stripComments: argv.stripComments,
|
|
64
|
-
transformHtmlComments: argv.transformHtmlComments,
|
|
65
60
|
});
|
|
66
61
|
bundler.bundle(async (bundleError, bundleBuffer) => await (0, utils_1.writeBundleFile)({
|
|
67
62
|
bundleError,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0D;AAC1D,gGAAuD;AACvD,6CAAoD;AAEpD,mCAA+D;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,mHAAmH;AAEnH;;;;;;;;;;;GAWG;AACH,SAAgB,MAAM,CACpB,GAAW,EACX,IAAY,EACZ,IAAe,EACf,gBAAsD;IAEtD,MAA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AAC,UAAU,CAAC,kBACnC,MAAM,EAAE,iBAAiB,KAAK,6BAAkB,CAAC,YAAY,EAC7D,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAC1B,OAAO,EAAE;oBACP,OAAO,CAAC,0BAA0B,CAAC;oBACnC;wBACE,OAAO,CAAC,mBAAmB,CAAC;wBAC5B;4BACE,OAAO,EAAE;gCACP,QAAQ,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;6BAC5C;yBACF;qBACF;iBACF,EACD,OAAO,EAAE;oBACP,OAAO,CAAC,iCAAiC,CAAC;oBAC1C,OAAO,CAAC,yCAAyC,CAAC;oBAClD,OAAO,CAAC,2CAA2C,CAAC;oBACpD,OAAO,CAAC,0CAA0C,CAAC;oBACnD,OAAO,CAAC,oDAAoD,CAAC;iBAC9D,EACD,UAAU,EAAE;oBACV,aAAa,EAAE,CAAC,IAAI,CAAC,aAAa;iBACnC,IACG,eAAuB,EAC3B,CAAC;SACJ;QAED,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAG,OAAO,CAAC,CAAC;QAE5B,OAAO,CAAC,MAAM,CAAC,iCAAM,EAAE;YACrB,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC,CAAC;QAEH,OAAO,CAAC,MAAM,CACZ,KAAK,EAAE,WAAW,EAAE,YAAoB,EAAE,EAAE,CAC1C,MAAM,IAAA,uBAAe,EAAC;YACpB,WAAW;YACX,YAAY;YACZ,GAAG;YACH,IAAI;YACJ,OAAO;SACR,CAAC,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AA9DD,wBA8DC","sourcesContent":["import browserify, { BrowserifyObject } from 'browserify';\nimport plugin from '@metamask/snaps-browserify-plugin';\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 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(plugin, {\n stripComments: argv.stripComments,\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
|
@@ -19,7 +19,6 @@ module.exports = {
|
|
|
19
19
|
.option('stripComments', builders_1.default.stripComments)
|
|
20
20
|
.option('transpilationMode', builders_1.default.transpilationMode)
|
|
21
21
|
.option('depsToTranspile', builders_1.default.depsToTranspile)
|
|
22
|
-
.option('transformHtmlComments', builders_1.default.transformHtmlComments)
|
|
23
22
|
.option('writeManifest', builders_1.default.writeManifest)
|
|
24
23
|
.implies('writeManifest', 'manifest')
|
|
25
24
|
.implies('depsToTranspile', 'transpilationMode')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;AACA,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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/build/index.ts"],"names":[],"mappings":";;;;AACA,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,CAAC,IAAe,EAAE,EAAE,CAAC,IAAA,oBAAK,EAAC,IAAI,CAAC;CAC1C,CAAC","sourcesContent":["import yargs from 'yargs';\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: (argv: YargsArgs) => build(argv),\n};\n"]}
|
package/dist/cmds/build/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ async function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve,
|
|
|
23
23
|
await (0, misc_1.writeError)('Build error:', bundleError.message, bundleError);
|
|
24
24
|
}
|
|
25
25
|
try {
|
|
26
|
-
await fs_1.promises.writeFile(dest, bundleBuffer
|
|
26
|
+
await fs_1.promises.writeFile(dest, bundleBuffer === null || bundleBuffer === void 0 ? void 0 : bundleBuffer.toString());
|
|
27
27
|
console.log(`Build success: '${src}' bundled as '${dest}'!`);
|
|
28
28
|
resolve(true);
|
|
29
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/cmds/build/utils.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,2CAA8C;AAE9C,6CAAoD;AAUpD;;;;;;;;;;;;;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,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/cmds/build/utils.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,2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CAAC,MAAM,EAAE;QACvE,OAAO,MAAM,CAAC;KACf;IACD,MAAM,KAAK,GAAa,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC9D,MAAM,GAAG,oBAAoB,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;IAC7C,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;IAChD,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC;AAVD,kDAUC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,YAAsB;IAC5D,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QACrC,OAAO,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,0DAIC;AAED;;;;;;;;GAQG;AACH,SAAgB,2BAA2B,CAAC,IAAe;IACzD,IACE,IAAI,CAAC,eAAe;QACpB,IAAI,CAAC,iBAAiB,KAAK,6BAAkB,CAAC,YAAY,EAC1D;QACA,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;AACH,CAAC;AATD,kEASC","sourcesContent":["import { promises as fs } from 'fs';\nimport { writeError } from '../../utils/misc';\nimport { YargsArgs } from '../../types/yargs';\nimport { TranspilationModes } from '../../builders';\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"]}
|
|
@@ -6,4 +6,4 @@ import { YargsArgs } from '../../types/yargs';
|
|
|
6
6
|
* @returns A promise that resolves once the eval has finished.
|
|
7
7
|
* @throws If the eval failed.
|
|
8
8
|
*/
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function evalHandler(argv: YargsArgs): Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.evalHandler = void 0;
|
|
4
|
+
const snap_utils_1 = require("@metamask/snap-utils");
|
|
4
5
|
const utils_1 = require("../../utils");
|
|
5
|
-
const workerEval_1 = require("./workerEval");
|
|
6
6
|
/**
|
|
7
7
|
* Runs the snap in a worker, to ensure SES compatibility.
|
|
8
8
|
*
|
|
@@ -10,17 +10,16 @@ const workerEval_1 = require("./workerEval");
|
|
|
10
10
|
* @returns A promise that resolves once the eval has finished.
|
|
11
11
|
* @throws If the eval failed.
|
|
12
12
|
*/
|
|
13
|
-
async function
|
|
13
|
+
async function evalHandler(argv) {
|
|
14
14
|
const { bundle: bundlePath } = argv;
|
|
15
|
-
await (0, utils_1.validateFilePath)(bundlePath);
|
|
16
15
|
try {
|
|
17
|
-
await (0,
|
|
16
|
+
await (0, snap_utils_1.evalBundle)(bundlePath);
|
|
18
17
|
console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);
|
|
19
18
|
}
|
|
20
|
-
catch (
|
|
21
|
-
(0, utils_1.logError)(`Snap evaluation error: ${
|
|
22
|
-
throw
|
|
19
|
+
catch (error) {
|
|
20
|
+
(0, utils_1.logError)(`Snap evaluation error: ${error.message}`, error);
|
|
21
|
+
throw error;
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
|
-
exports.
|
|
24
|
+
exports.evalHandler = evalHandler;
|
|
26
25
|
//# sourceMappingURL=evalHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAElD,uCAAuC;AAEvC;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAEpC,IAAI;QACF,MAAM,IAAA,uBAAU,EAAC,UAAoB,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,4BAA4B,UAAU,WAAW,CAAC,CAAC;KAChE;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,gBAAQ,EAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAVD,kCAUC","sourcesContent":["import { evalBundle } from '@metamask/snap-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\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 try {\n await evalBundle(bundlePath as string);\n console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n logError(`Snap evaluation error: ${error.message}`, error);\n throw error;\n }\n}\n"]}
|
package/dist/cmds/eval/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/eval/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/eval/index.ts"],"names":[],"mappings":";;;;AACA,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,CAAC,IAAe,EAAE,EAAE,CAAC,IAAA,yBAAW,EAAC,IAAI,CAAC;CAChD,CAAC","sourcesContent":["import yargs from 'yargs';\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: (argv: YargsArgs) => evalHandler(argv),\n};\n"]}
|
package/dist/cmds/init/index.js
CHANGED
|
@@ -16,11 +16,7 @@ const initUtils_1 = require("./initUtils");
|
|
|
16
16
|
async function init(argv) {
|
|
17
17
|
console.log();
|
|
18
18
|
const newArgs = await (0, initHandler_1.initHandler)(argv);
|
|
19
|
-
await (0, buildHandler_1.build)({
|
|
20
|
-
...newArgs,
|
|
21
|
-
manifest: false,
|
|
22
|
-
eval: true,
|
|
23
|
-
});
|
|
19
|
+
await (0, buildHandler_1.build)(Object.assign(Object.assign({}, newArgs), { manifest: false, eval: true }));
|
|
24
20
|
await (0, initHandler_1.updateManifestShasum)();
|
|
25
21
|
console.log('\nSnap project successfully initiated!');
|
|
26
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAAkE;AAClE,2CAAiD;AAsBjD;;;;;;GAMG;AACH,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC;IAExC,MAAM,IAAA,oBAAK,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAAkE;AAClE,2CAAiD;AAsBjD;;;;;;GAMG;AACH,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC;IAExC,MAAM,IAAA,oBAAK,kCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,MAAM,IAAA,kCAAoB,GAAE,CAAC;IAE7B,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,CAAC;AAxCD,iBAAS;IACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC;IACtB,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE,EAAE;YACxB,IAAA,8BAAkB,EAAC,SAAS,CAAC,CAAC;QAChC,CAAC,CAAQ,EACT,IAAI,CACL,CAAC;IACN,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler, updateManifestShasum } from './initHandler';\nimport { correctDefaultArgs } from './initUtils';\n\nexport = {\n command: ['init', 'i'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('dist', builders.dist)\n .option('port', builders.port)\n .option('outfileName', builders.outfileName)\n .option('template', builders.template)\n .middleware(\n ((yargsArgv: Arguments) => {\n correctDefaultArgs(yargsArgv);\n }) as any,\n true,\n );\n },\n handler: (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 console.log();\n const newArgs = await initHandler(argv);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n await updateManifestShasum();\n\n console.log('\\nSnap project successfully initiated!');\n}\n"]}
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
"source": "module.exports.onRpcRequest = async ({ origin, request }) => {\n switch (request.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [\n {\n prompt: `Hello, ${origin}!`,\n description:\n 'This custom confirmation is just for display purposes.',\n textAreaContent:\n 'But you can edit the snap source code to make it do something, if you want to!',\n },\n ],\n });\n default:\n throw new Error('Method not found.');\n }\n};\n",
|
|
4
4
|
"typescriptHtml": "<!doctype html>\n<html>\n </head>\n <title>Hello, Snaps!</title>\n <link rel=\"icon\" type=\"image/svg\" href=\"./images/icon.svg\"/>\n </head>\n\n <body>\n <h1>Hello, Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The <code>snap.manifest.json</code> and <code>package.json</code> must be located in the server root directory...\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by the <code>location</code> field of <code>snap.manifest.json</code>.\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n const snapId = `local:${window.location.href}`;\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the snap\n async function connect () {\n await ethereum.request({\n method: 'wallet_enable',\n params: [{\n wallet_snap: { [snapId]: {} },\n }]\n })\n }\n\n // here we call the snap's \"hello\" method\n async function send () {\n try {\n await ethereum.request({\n method: 'wallet_invokeSnap',\n params: [snapId, {\n method: 'hello'\n }]\n })\n } catch (err) {\n console.error(err)\n alert('Problem happened: ' + err.message || err)\n }\n }\n </script>\n</html>\n",
|
|
5
5
|
"typescriptSource": "import { OnRpcRequestHandler } from '@metamask/snap-types';\n\nexport const onRpcRequest: OnRpcRequestHandler = ({ origin, request }) => {\n switch (request.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [\n {\n prompt: `Hello, ${origin}!`,\n description:\n 'This custom confirmation is just for display purposes.',\n textAreaContent:\n 'But you can edit the snap source code to make it do something, if you want to!',\n },\n ],\n });\n default:\n throw new Error('Method not found.');\n }\n};\n",
|
|
6
|
-
"typescriptConfig": "{\n \"extends\": \"../../../../tsconfig.packages.json\",\n \"compilerOptions\": {\n \"typeRoots\": [\"../../../../node_modules/@types\"]\n },\n \"files\": [\"
|
|
6
|
+
"typescriptConfig": "{\n \"extends\": \"../../../../tsconfig.packages.json\",\n \"compilerOptions\": {\n \"typeRoots\": [\"../../../../node_modules/@types\"]\n },\n \"files\": [\"./node_modules/@metamask/snap-types/global.d.ts\"],\n \"include\": [\"src\"]\n}\n",
|
|
7
7
|
"icon": "<svg width=\"24\" height=\"25\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M17.037 0H6.975C2.605 0 0 2.617 0 6.987v10.05c0 4.37 2.605 6.975 6.975 6.975h10.05c4.37 0 6.975-2.605 6.975-6.976V6.988C24.012 2.617 21.407 0 17.037 0ZM11.49 17.757c0 .36-.18.684-.492.876a.975.975 0 0 1-.54.156 1.11 1.11 0 0 1-.469-.108l-4.202-2.1a1.811 1.811 0 0 1-.985-1.61v-3.973c0-.36.18-.685.493-.877a1.04 1.04 0 0 1 1.008-.048l4.202 2.101a1.8 1.8 0 0 1 .997 1.609v3.974h-.012Zm-.252-6.423L6.723 8.896a1.045 1.045 0 0 1-.528-.924c0-.384.204-.744.528-.924l4.515-2.438a1.631 1.631 0 0 1 1.524 0l4.515 2.438c.324.18.528.528.528.924s-.204.744-.528.924l-4.515 2.438c-.24.132-.504.192-.768.192a1.54 1.54 0 0 1-.756-.192Zm7.972 3.638c0 .684-.385 1.308-.997 1.608l-4.202 2.101c-.144.072-.3.108-.468.108a.975.975 0 0 1-.54-.156 1.017 1.017 0 0 1-.493-.876v-3.974c0-.684.384-1.309.997-1.609l4.202-2.101a1.04 1.04 0 0 1 1.008.048c.313.192.493.516.493.877v3.974Z\" fill=\"#24272A\"/></svg>"
|
|
8
8
|
}
|
|
@@ -6,10 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.updateManifestShasum = exports.initHandler = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
9
|
+
const snap_utils_1 = require("@metamask/snap-utils");
|
|
10
10
|
const mkdirp_1 = __importDefault(require("mkdirp"));
|
|
11
11
|
const utils_1 = require("../../utils");
|
|
12
|
-
const manifestHandler_1 = require("../manifest/manifestHandler");
|
|
13
12
|
const init_template_json_1 = __importDefault(require("./init-template.json"));
|
|
14
13
|
const initUtils_1 = require("./initUtils");
|
|
15
14
|
/**
|
|
@@ -26,7 +25,7 @@ async function initHandler(argv) {
|
|
|
26
25
|
console.log(`MetaMask Snaps: Initialize\n`);
|
|
27
26
|
const packageJson = await (0, initUtils_1.asyncPackageInit)(argv);
|
|
28
27
|
await (0, initUtils_1.prepareWorkingDirectory)();
|
|
29
|
-
console.log(`\nInit: Building '${
|
|
28
|
+
console.log(`\nInit: Building '${snap_utils_1.NpmSnapFileNames.Manifest}'...\n`);
|
|
30
29
|
const [snapManifest, _newArgs] = await (0, initUtils_1.buildSnapManifest)(argv, packageJson);
|
|
31
30
|
const newArgs = Object.keys(_newArgs)
|
|
32
31
|
.sort()
|
|
@@ -36,13 +35,13 @@ async function initHandler(argv) {
|
|
|
36
35
|
}, {});
|
|
37
36
|
const isTypeScript = (0, initUtils_1.isTemplateTypescript)(argv.template);
|
|
38
37
|
try {
|
|
39
|
-
await fs_1.promises.writeFile(
|
|
38
|
+
await fs_1.promises.writeFile(snap_utils_1.NpmSnapFileNames.Manifest, `${JSON.stringify(snapManifest, null, 2)}\n`);
|
|
40
39
|
}
|
|
41
40
|
catch (err) {
|
|
42
|
-
(0, utils_1.logError)(`Init Error: Failed to write '${
|
|
41
|
+
(0, utils_1.logError)(`Init Error: Failed to write '${snap_utils_1.NpmSnapFileNames.Manifest}'.`, err);
|
|
43
42
|
throw err;
|
|
44
43
|
}
|
|
45
|
-
console.log(`\nInit: Created '${
|
|
44
|
+
console.log(`\nInit: Created '${snap_utils_1.NpmSnapFileNames.Manifest}'.`);
|
|
46
45
|
// Write main .js entry file
|
|
47
46
|
const { src } = newArgs;
|
|
48
47
|
try {
|
|
@@ -104,7 +103,7 @@ async function initHandler(argv) {
|
|
|
104
103
|
throw err;
|
|
105
104
|
}
|
|
106
105
|
(0, utils_1.closePrompt)();
|
|
107
|
-
return {
|
|
106
|
+
return Object.assign(Object.assign({}, argv), newArgs);
|
|
108
107
|
}
|
|
109
108
|
exports.initHandler = initHandler;
|
|
110
109
|
/**
|
|
@@ -112,10 +111,10 @@ exports.initHandler = initHandler;
|
|
|
112
111
|
* during the init command.
|
|
113
112
|
*/
|
|
114
113
|
async function updateManifestShasum() {
|
|
115
|
-
const manifest =
|
|
114
|
+
const manifest = await (0, snap_utils_1.readJsonFile)(snap_utils_1.NpmSnapFileNames.Manifest);
|
|
116
115
|
const bundleContents = await fs_1.promises.readFile(manifest.source.location.npm.filePath, 'utf8');
|
|
117
|
-
manifest.source.shasum = (0,
|
|
118
|
-
await fs_1.promises.writeFile(
|
|
116
|
+
manifest.source.shasum = (0, snap_utils_1.getSnapSourceShasum)(bundleContents);
|
|
117
|
+
await fs_1.promises.writeFile(snap_utils_1.NpmSnapFileNames.Manifest, JSON.stringify((0, snap_utils_1.getWritableManifest)(manifest), null, 2));
|
|
119
118
|
}
|
|
120
119
|
exports.updateManifestShasum = updateManifestShasum;
|
|
121
120
|
//# sourceMappingURL=initHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAoC;AACpC,gDAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAoC;AACpC,gDAA6B;AAC7B,qDAM8B;AAC9B,oDAA4B;AAE5B,uCAA6E;AAE7E,8EAA4C;AAC5C,2CAKqB;AAErB;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,OAAO,CAAC,GAAG,CAAC,8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B,IAAI,CAAC,SAAS,CAAC,IAAA,gCAAmB,EAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CACvD,CAAC;AACJ,CAAC;AAbD,oDAaC","sourcesContent":["import { promises as fs } from 'fs';\nimport pathUtils from 'path';\nimport {\n NpmSnapFileNames,\n SnapManifest,\n getSnapSourceShasum,\n getWritableManifest,\n readJsonFile,\n} from '@metamask/snap-utils';\nimport mkdirp from 'mkdirp';\nimport { YargsArgs } from '../../types/yargs';\nimport { closePrompt, CONFIG_FILE, logError, SnapConfig } from '../../utils';\nimport { TemplateType } from '../../builders';\nimport template from './init-template.json';\nimport {\n asyncPackageInit,\n buildSnapManifest,\n isTemplateTypescript,\n prepareWorkingDirectory,\n} from './initUtils';\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 console.log(`MetaMask Snaps: Initialize\\n`);\n\n const packageJson = await asyncPackageInit(argv);\n\n await prepareWorkingDirectory();\n\n console.log(`\\nInit: Building '${NpmSnapFileNames.Manifest}'...\\n`);\n\n const [snapManifest, _newArgs] = await buildSnapManifest(argv, packageJson);\n\n const newArgs = Object.keys(_newArgs)\n .sort()\n .reduce((sorted, key) => {\n sorted[key] = _newArgs[key as keyof typeof _newArgs];\n return sorted;\n }, {} as YargsArgs);\n\n const isTypeScript = isTemplateTypescript(argv.template as TemplateType);\n try {\n await fs.writeFile(\n NpmSnapFileNames.Manifest,\n `${JSON.stringify(snapManifest, null, 2)}\\n`,\n );\n } catch (err) {\n logError(\n `Init Error: Failed to write '${NpmSnapFileNames.Manifest}'.`,\n err,\n );\n throw err;\n }\n\n console.log(`\\nInit: Created '${NpmSnapFileNames.Manifest}'.`);\n\n // Write main .js entry file\n const { src } = newArgs;\n\n try {\n if (pathUtils.basename(src) !== src) {\n await mkdirp(pathUtils.dirname(src));\n }\n\n await fs.writeFile(\n src,\n isTypeScript ? template.typescriptSource : template.source,\n );\n\n console.log(`Init: Created '${src}'.`);\n } catch (err) {\n logError(`Init Error: Failed to write '${src}'.`, err);\n throw err;\n }\n\n // Write index.html\n try {\n await fs.writeFile(\n 'index.html',\n isTypeScript ? template.typescriptHtml : template.html,\n );\n\n console.log(`Init: Created 'index.html'.`);\n } catch (err) {\n logError(`Init Error: Failed to write 'index.html'.`, err);\n throw err;\n }\n\n // Write tsconfig.json\n if (isTypeScript) {\n try {\n await fs.writeFile('tsconfig.json', template.typescriptConfig);\n console.log(`Init: Created 'tsconfig.json'.`);\n } catch (err) {\n logError(`Init Error: Failed to write 'tsconfig.json'.`, err);\n throw err;\n }\n }\n\n // Write config file\n try {\n const defaultConfig: SnapConfig = {\n cliOptions: newArgs,\n };\n const defaultConfigFile = `module.exports = ${JSON.stringify(\n defaultConfig,\n null,\n 2,\n )}\n `;\n await fs.writeFile(CONFIG_FILE, defaultConfigFile);\n console.log(`Init: Wrote '${CONFIG_FILE}' config file`);\n } catch (err) {\n logError(`Init Error: Failed to write '${CONFIG_FILE}'.`, err);\n throw err;\n }\n\n // Write icon\n const iconPath = 'images/icon.svg';\n try {\n if (pathUtils.basename(iconPath) !== iconPath) {\n await mkdirp(pathUtils.dirname(iconPath));\n }\n await fs.writeFile(iconPath, template.icon);\n\n console.log(`Init: Created '${iconPath}'.`);\n } catch (err) {\n logError(`Init Error: Failed to write '${iconPath}'.`, err);\n throw err;\n }\n\n closePrompt();\n return { ...argv, ...newArgs };\n}\n\n/**\n * This updates the Snap shasum value of the manifest after building the Snap\n * during the init command.\n */\nexport async function updateManifestShasum() {\n const manifest = await readJsonFile<SnapManifest>(NpmSnapFileNames.Manifest);\n\n const bundleContents = await fs.readFile(\n manifest.source.location.npm.filePath,\n 'utf8',\n );\n\n manifest.source.shasum = getSnapSourceShasum(bundleContents);\n await fs.writeFile(\n NpmSnapFileNames.Manifest,\n JSON.stringify(getWritableManifest(manifest), null, 2),\n );\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SnapManifest, NpmSnapPackageJson } from '@metamask/snap-utils';
|
|
2
2
|
import { Arguments } from 'yargs';
|
|
3
3
|
import { YargsArgs } from '../../types/yargs';
|
|
4
4
|
import { TemplateType } from '../../builders';
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.isTemplateTypescript = exports.correctDefaultArgs = exports.prepareWorkingDirectory = exports.buildSnapManifest = exports.asyncPackageInit = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
9
|
+
const snap_utils_1 = require("@metamask/snap-utils");
|
|
10
10
|
const init_package_json_1 = __importDefault(require("init-package-json"));
|
|
11
11
|
const mkdirp_1 = __importDefault(require("mkdirp"));
|
|
12
12
|
const slash_1 = __importDefault(require("slash"));
|
|
@@ -26,22 +26,22 @@ const NPM_PUBLIC_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
|
26
26
|
* @returns The contents of the `package.json` file.
|
|
27
27
|
*/
|
|
28
28
|
async function asyncPackageInit(argv) {
|
|
29
|
-
if ((0, fs_1.existsSync)(
|
|
30
|
-
console.log(`Init: Attempting to use existing '${
|
|
29
|
+
if ((0, fs_1.existsSync)(snap_utils_1.NpmSnapFileNames.PackageJson)) {
|
|
30
|
+
console.log(`Init: Attempting to use existing '${snap_utils_1.NpmSnapFileNames.PackageJson}'...`);
|
|
31
31
|
try {
|
|
32
|
-
const packageJson = await (0,
|
|
33
|
-
(0,
|
|
34
|
-
console.log(`Init: Successfully parsed '${
|
|
32
|
+
const packageJson = await (0, snap_utils_1.readJsonFile)(snap_utils_1.NpmSnapFileNames.PackageJson);
|
|
33
|
+
(0, snap_utils_1.validateSnapJsonFile)(snap_utils_1.NpmSnapFileNames.PackageJson, packageJson);
|
|
34
|
+
console.log(`Init: Successfully parsed '${snap_utils_1.NpmSnapFileNames.PackageJson}'!`);
|
|
35
35
|
return packageJson;
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
|
-
(0, utils_1.logError)(`Init Error: Could not parse '${
|
|
38
|
+
(0, utils_1.logError)(`Init Error: Could not parse '${snap_utils_1.NpmSnapFileNames.PackageJson}'. Please verify that the file is correctly formatted and try again.`, error);
|
|
39
39
|
throw error;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
// Exit if yarn.lock is found, or we'll be in trouble
|
|
43
43
|
if ((0, fs_1.existsSync)('yarn.lock')) {
|
|
44
|
-
(0, utils_1.logError)(`Init Error: Found a 'yarn.lock' file but no '${
|
|
44
|
+
(0, utils_1.logError)(`Init Error: Found a 'yarn.lock' file but no '${snap_utils_1.NpmSnapFileNames.PackageJson}'. Please run 'yarn init' and try again.`);
|
|
45
45
|
throw new Error('Already existing yarn.lock file found');
|
|
46
46
|
}
|
|
47
47
|
// Run 'npm init'
|
|
@@ -127,7 +127,7 @@ async function buildSnapManifest(argv, packageJson) {
|
|
|
127
127
|
});
|
|
128
128
|
if (proposedName.length > 0 &&
|
|
129
129
|
proposedName.length <= 214 &&
|
|
130
|
-
|
|
130
|
+
snap_utils_1.PROPOSED_NAME_REGEX.test(proposedName)) {
|
|
131
131
|
invalidProposedName = false;
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
@@ -204,7 +204,7 @@ async function buildSnapManifest(argv, packageJson) {
|
|
|
204
204
|
description,
|
|
205
205
|
proposedName,
|
|
206
206
|
repository: packageJson.repository
|
|
207
|
-
? (0,
|
|
207
|
+
? (0, snap_utils_1.deepClone)(packageJson.repository)
|
|
208
208
|
: null,
|
|
209
209
|
source: {
|
|
210
210
|
shasum: PLACEHOLDER_SHASUM,
|
|
@@ -221,7 +221,7 @@ async function buildSnapManifest(argv, packageJson) {
|
|
|
221
221
|
manifestVersion: '0.1',
|
|
222
222
|
};
|
|
223
223
|
try {
|
|
224
|
-
(0,
|
|
224
|
+
(0, snap_utils_1.validateSnapJsonFile)(snap_utils_1.NpmSnapFileNames.Manifest, manifest);
|
|
225
225
|
}
|
|
226
226
|
catch (error) {
|
|
227
227
|
/* istanbul ignore next */
|
|
@@ -239,7 +239,7 @@ const INIT_FILE_NAMES = new Set([
|
|
|
239
239
|
'index.html',
|
|
240
240
|
utils_1.CONFIG_FILE,
|
|
241
241
|
'dist',
|
|
242
|
-
|
|
242
|
+
snap_utils_1.NpmSnapFileNames.Manifest,
|
|
243
243
|
]);
|
|
244
244
|
/**
|
|
245
245
|
* Checks whether any files in the current working directory will be overwritten
|