@metamask/snaps-cli 0.35.0-flask.1 → 1.0.0-prerelease.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -26
- package/README.md +6 -5
- package/dist/{esm/builders.js → builders.js} +29 -27
- package/dist/{cjs/builders.js.map → builders.js.map} +1 -1
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +1 -0
- package/dist/cmds/build/buildHandler.js +37 -0
- package/dist/cmds/build/buildHandler.js.map +1 -0
- package/dist/cmds/build/bundle.js +80 -0
- package/dist/cmds/build/bundle.js.map +1 -0
- package/dist/{types/cmds/serve → cmds/build}/index.d.ts +2 -2
- package/dist/cmds/build/index.js +29 -0
- package/dist/cmds/build/index.js.map +1 -0
- package/dist/{esm/cmds → cmds}/build/utils.js +34 -22
- package/dist/cmds/build/utils.js.map +1 -0
- package/dist/cmds/eval/evalHandler.js +25 -0
- package/dist/cmds/eval/evalHandler.js.map +1 -0
- package/dist/{types/cmds/manifest → cmds/eval}/index.d.ts +2 -2
- package/dist/cmds/eval/index.js +15 -0
- package/dist/cmds/eval/index.js.map +1 -0
- package/dist/cmds/index.js +14 -0
- package/dist/cmds/index.js.map +1 -0
- package/dist/{types/cmds/build → cmds/init}/index.d.ts +2 -2
- package/dist/cmds/init/index.js +34 -0
- package/dist/cmds/init/index.js.map +1 -0
- package/dist/cmds/init/initHandler.d.ts +26 -0
- package/dist/cmds/init/initHandler.js +69 -0
- package/dist/cmds/init/initHandler.js.map +1 -0
- package/dist/cmds/init/initUtils.d.ts +39 -0
- package/dist/cmds/init/initUtils.js +122 -0
- package/dist/cmds/init/initUtils.js.map +1 -0
- package/dist/{types/cmds/eval → cmds/manifest}/index.d.ts +2 -2
- package/dist/cmds/manifest/index.js +24 -0
- package/dist/cmds/manifest/index.js.map +1 -0
- package/dist/cmds/manifest/manifestHandler.js +50 -0
- package/dist/cmds/manifest/manifestHandler.js.map +1 -0
- package/dist/cmds/serve/index.d.ts +9 -0
- package/dist/cmds/serve/index.js +15 -0
- package/dist/cmds/serve/index.js.map +1 -0
- package/dist/cmds/serve/serveHandler.js +59 -0
- package/dist/cmds/serve/serveHandler.js.map +1 -0
- package/dist/cmds/serve/serveUtils.js +39 -0
- package/dist/cmds/serve/serveUtils.js.map +1 -0
- package/dist/cmds/watch/index.d.ts +9 -0
- package/dist/cmds/watch/index.js +32 -0
- package/dist/cmds/watch/index.js.map +1 -0
- package/dist/cmds/watch/watchHandler.js +100 -0
- package/dist/cmds/watch/watchHandler.js.map +1 -0
- package/dist/main.js +15 -0
- package/dist/main.js.map +1 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/{esm/utils → utils}/misc.js +50 -32
- package/dist/utils/misc.js.map +1 -0
- package/dist/{esm/utils → utils}/snap-config.js +39 -26
- package/dist/utils/snap-config.js.map +1 -0
- package/package.json +27 -65
- package/dist/cjs/builders.js +0 -149
- package/dist/cjs/cli.js +0 -35
- package/dist/cjs/cli.js.map +0 -1
- package/dist/cjs/cmds/build/buildHandler.js +0 -36
- package/dist/cjs/cmds/build/buildHandler.js.map +0 -1
- package/dist/cjs/cmds/build/bundle.js +0 -83
- package/dist/cjs/cmds/build/bundle.js.map +0 -1
- package/dist/cjs/cmds/build/index.js +0 -32
- package/dist/cjs/cmds/build/index.js.map +0 -1
- package/dist/cjs/cmds/build/utils.js +0 -79
- package/dist/cjs/cmds/build/utils.js.map +0 -1
- package/dist/cjs/cmds/eval/evalHandler.js +0 -24
- package/dist/cjs/cmds/eval/evalHandler.js.map +0 -1
- package/dist/cjs/cmds/eval/index.js +0 -31
- package/dist/cjs/cmds/eval/index.js.map +0 -1
- package/dist/cjs/cmds/index.js +0 -30
- package/dist/cjs/cmds/index.js.map +0 -1
- package/dist/cjs/cmds/manifest/index.js +0 -44
- package/dist/cjs/cmds/manifest/index.js.map +0 -1
- package/dist/cjs/cmds/manifest/manifestHandler.js +0 -46
- package/dist/cjs/cmds/manifest/manifestHandler.js.map +0 -1
- package/dist/cjs/cmds/serve/index.js +0 -31
- package/dist/cjs/cmds/serve/index.js.map +0 -1
- package/dist/cjs/cmds/serve/serveHandler.js +0 -62
- package/dist/cjs/cmds/serve/serveHandler.js.map +0 -1
- package/dist/cjs/cmds/serve/serveUtils.js +0 -37
- package/dist/cjs/cmds/serve/serveUtils.js.map +0 -1
- package/dist/cjs/cmds/watch/index.js +0 -32
- package/dist/cjs/cmds/watch/index.js.map +0 -1
- package/dist/cjs/cmds/watch/watchHandler.js +0 -91
- package/dist/cjs/cmds/watch/watchHandler.js.map +0 -1
- package/dist/cjs/index.js +0 -52
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/main.js +0 -20
- package/dist/cjs/main.js.map +0 -1
- package/dist/cjs/utils/index.js +0 -21
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/misc.js +0 -141
- package/dist/cjs/utils/misc.js.map +0 -1
- package/dist/cjs/utils/snap-config.js +0 -101
- package/dist/cjs/utils/snap-config.js.map +0 -1
- package/dist/esm/builders.js.map +0 -1
- package/dist/esm/cli.js +0 -26
- package/dist/esm/cli.js.map +0 -1
- package/dist/esm/cmds/build/buildHandler.js +0 -36
- package/dist/esm/cmds/build/buildHandler.js.map +0 -1
- package/dist/esm/cmds/build/bundle.js +0 -81
- package/dist/esm/cmds/build/bundle.js.map +0 -1
- package/dist/esm/cmds/build/index.js +0 -17
- package/dist/esm/cmds/build/index.js.map +0 -1
- package/dist/esm/cmds/build/utils.js.map +0 -1
- package/dist/esm/cmds/eval/evalHandler.js +0 -20
- package/dist/esm/cmds/eval/evalHandler.js.map +0 -1
- package/dist/esm/cmds/eval/index.js +0 -16
- package/dist/esm/cmds/eval/index.js.map +0 -1
- package/dist/esm/cmds/index.js +0 -15
- package/dist/esm/cmds/index.js.map +0 -1
- package/dist/esm/cmds/manifest/index.js +0 -29
- package/dist/esm/cmds/manifest/index.js.map +0 -1
- package/dist/esm/cmds/manifest/manifestHandler.js +0 -43
- package/dist/esm/cmds/manifest/manifestHandler.js.map +0 -1
- package/dist/esm/cmds/serve/index.js +0 -16
- package/dist/esm/cmds/serve/index.js.map +0 -1
- package/dist/esm/cmds/serve/serveHandler.js +0 -54
- package/dist/esm/cmds/serve/serveHandler.js.map +0 -1
- package/dist/esm/cmds/serve/serveUtils.js +0 -30
- package/dist/esm/cmds/serve/serveUtils.js.map +0 -1
- package/dist/esm/cmds/watch/index.js +0 -17
- package/dist/esm/cmds/watch/index.js.map +0 -1
- package/dist/esm/cmds/watch/watchHandler.js +0 -87
- package/dist/esm/cmds/watch/watchHandler.js.map +0 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/main.js +0 -11
- package/dist/esm/main.js.map +0 -1
- package/dist/esm/utils/index.js +0 -4
- package/dist/esm/utils/index.js.map +0 -1
- package/dist/esm/utils/misc.js.map +0 -1
- package/dist/esm/utils/snap-config.js.map +0 -1
- package/dist/types/cmds/watch/index.d.ts +0 -9
- package/dist/types/index.d.ts +0 -1
- /package/dist/{types/builders.d.ts → builders.d.ts} +0 -0
- /package/dist/{types/cli.d.ts → cli.d.ts} +0 -0
- /package/dist/{types/cmds → cmds}/build/buildHandler.d.ts +0 -0
- /package/dist/{types/cmds → cmds}/build/bundle.d.ts +0 -0
- /package/dist/{types/cmds → cmds}/build/utils.d.ts +0 -0
- /package/dist/{types/cmds → cmds}/eval/evalHandler.d.ts +0 -0
- /package/dist/{types/cmds → cmds}/index.d.ts +0 -0
- /package/dist/{types/cmds → cmds}/manifest/manifestHandler.d.ts +0 -0
- /package/dist/{types/cmds → cmds}/serve/serveHandler.d.ts +0 -0
- /package/dist/{types/cmds → cmds}/serve/serveUtils.d.ts +0 -0
- /package/dist/{types/cmds → cmds}/watch/watchHandler.d.ts +0 -0
- /package/dist/{types/main.d.ts → main.d.ts} +0 -0
- /package/dist/{types/utils → utils}/index.d.ts +0 -0
- /package/dist/{types/utils → utils}/misc.d.ts +0 -0
- /package/dist/{types/utils → utils}/snap-config.d.ts +0 -0
package/dist/cjs/utils/misc.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
permRequestKeys: function() {
|
|
13
|
-
return permRequestKeys;
|
|
14
|
-
},
|
|
15
|
-
CONFIG_FILE: function() {
|
|
16
|
-
return CONFIG_FILE;
|
|
17
|
-
},
|
|
18
|
-
setSnapGlobals: function() {
|
|
19
|
-
return setSnapGlobals;
|
|
20
|
-
},
|
|
21
|
-
booleanStringToBoolean: function() {
|
|
22
|
-
return booleanStringToBoolean;
|
|
23
|
-
},
|
|
24
|
-
sanitizeInputs: function() {
|
|
25
|
-
return sanitizeInputs;
|
|
26
|
-
},
|
|
27
|
-
logError: function() {
|
|
28
|
-
return logError;
|
|
29
|
-
},
|
|
30
|
-
writeError: function() {
|
|
31
|
-
return writeError;
|
|
32
|
-
},
|
|
33
|
-
trimPathString: function() {
|
|
34
|
-
return trimPathString;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
const _snapsutils = require("@metamask/snaps-utils");
|
|
38
|
-
const _utils = require("@metamask/utils");
|
|
39
|
-
const _fs = require("fs");
|
|
40
|
-
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
41
|
-
function _interop_require_default(obj) {
|
|
42
|
-
return obj && obj.__esModule ? obj : {
|
|
43
|
-
default: obj
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const permRequestKeys = [
|
|
47
|
-
'@context',
|
|
48
|
-
'id',
|
|
49
|
-
'parentCapability',
|
|
50
|
-
'invoker',
|
|
51
|
-
'date',
|
|
52
|
-
'caveats',
|
|
53
|
-
'proof'
|
|
54
|
-
];
|
|
55
|
-
const CONFIG_FILE = 'snap.config.js';
|
|
56
|
-
// CLI arguments whose values are file paths
|
|
57
|
-
const pathArguments = new Set([
|
|
58
|
-
'src',
|
|
59
|
-
's',
|
|
60
|
-
'dist',
|
|
61
|
-
'd',
|
|
62
|
-
'bundle',
|
|
63
|
-
'b',
|
|
64
|
-
'root',
|
|
65
|
-
'r'
|
|
66
|
-
]);
|
|
67
|
-
function setSnapGlobals(argv) {
|
|
68
|
-
if ([
|
|
69
|
-
'w',
|
|
70
|
-
'watch'
|
|
71
|
-
].includes(argv._[0])) {
|
|
72
|
-
global.snaps.isWatching = true;
|
|
73
|
-
} else {
|
|
74
|
-
global.snaps.isWatching = false;
|
|
75
|
-
}
|
|
76
|
-
if ((0, _utils.hasProperty)(argv, 'verboseErrors')) {
|
|
77
|
-
global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);
|
|
78
|
-
}
|
|
79
|
-
if ((0, _utils.hasProperty)(argv, 'suppressWarnings')) {
|
|
80
|
-
global.snaps.suppressWarnings = booleanStringToBoolean(argv.suppressWarnings);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function booleanStringToBoolean(value) {
|
|
84
|
-
if (typeof value === 'boolean') {
|
|
85
|
-
return value;
|
|
86
|
-
} else if (value === 'true') {
|
|
87
|
-
return true;
|
|
88
|
-
} else if (value === 'false') {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
throw new Error(`Expected a boolean or the strings "true" or "false". Received: "${String(value)}"`);
|
|
92
|
-
}
|
|
93
|
-
function sanitizeInputs(argv) {
|
|
94
|
-
Object.keys(argv).forEach((key)=>{
|
|
95
|
-
if (typeof argv[key] === 'string') {
|
|
96
|
-
// Node's path.normalize() does not do this
|
|
97
|
-
if (argv[key] === './') {
|
|
98
|
-
argv[key] = '.';
|
|
99
|
-
}
|
|
100
|
-
if (pathArguments.has(key)) {
|
|
101
|
-
argv[key] = _path.default.normalize(argv[key]);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function logError(message, error) {
|
|
107
|
-
if (message !== null) {
|
|
108
|
-
(0, _snapsutils.logError)(message);
|
|
109
|
-
}
|
|
110
|
-
if (error && global.snaps.verboseErrors) {
|
|
111
|
-
(0, _snapsutils.logError)(error);
|
|
112
|
-
}
|
|
113
|
-
if (message === null && (!error || error && !global.snaps.verboseErrors)) {
|
|
114
|
-
(0, _snapsutils.logError)('Unknown error.');
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
async function writeError(prefix, message, error, destFilePath) {
|
|
118
|
-
let processedPrefix = prefix;
|
|
119
|
-
if (!prefix.endsWith(' ')) {
|
|
120
|
-
processedPrefix += ' ';
|
|
121
|
-
}
|
|
122
|
-
logError(processedPrefix + message, error);
|
|
123
|
-
try {
|
|
124
|
-
if (destFilePath) {
|
|
125
|
-
await _fs.promises.unlink(destFilePath);
|
|
126
|
-
}
|
|
127
|
-
} catch (unlinkError) {
|
|
128
|
-
logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);
|
|
129
|
-
}
|
|
130
|
-
// unless the watcher is active, exit
|
|
131
|
-
if (!global.snaps.isWatching) {
|
|
132
|
-
// TODO(ritave): Remove process exit and change into collapse of functions
|
|
133
|
-
// https://github.com/MetaMask/snaps-monorepo/issues/81
|
|
134
|
-
process.exit(1);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function trimPathString(pathString) {
|
|
138
|
-
return pathString.replace(/^[./]+|[./]+$/gu, '');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
//# sourceMappingURL=misc.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/misc.ts"],"sourcesContent":["import { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { promises as filesystem } from 'fs';\nimport path from 'path';\nimport { Arguments } from 'yargs';\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"],"names":["permRequestKeys","CONFIG_FILE","setSnapGlobals","booleanStringToBoolean","sanitizeInputs","logError","writeError","trimPathString","pathArguments","Set","argv","includes","_","global","snaps","isWatching","hasProperty","verboseErrors","suppressWarnings","value","Error","String","Object","keys","forEach","key","has","path","normalize","message","error","logErrorUtil","prefix","destFilePath","processedPrefix","endsWith","filesystem","unlink","unlinkError","process","exit","pathString","replace"],"mappings":";;;;;;;;;;;IAMaA,eAAe;eAAfA;;IAUAC,WAAW;eAAXA;;IAqBGC,cAAc;eAAdA;;IA0BAC,sBAAsB;eAAtBA;;IAsBAC,cAAc;eAAdA;;IAsBAC,QAAQ;eAARA;;IAuBMC,UAAU;eAAVA;;IAmCNC,cAAc;eAAdA;;;4BArKyB;uBACb;oBACW;6DACtB;;;;;;AAGV,MAAMP,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAEM,MAAMC,cAAc;AAE3B,4CAA4C;AAC5C,MAAMO,gBAAgB,IAAIC,IAAI;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AASM,SAASP,eAAeQ,IAAe;IAC5C,IAAI;QAAC;QAAK;KAAQ,CAACC,QAAQ,CAACD,KAAKE,CAAC,CAAC,EAAE,GAAa;QAChDC,OAAOC,KAAK,CAACC,UAAU,GAAG;IAC5B,OAAO;QACLF,OAAOC,KAAK,CAACC,UAAU,GAAG;IAC5B;IAEA,IAAIC,IAAAA,kBAAW,EAACN,MAAM,kBAAkB;QACtCG,OAAOC,KAAK,CAACG,aAAa,GAAGd,uBAAuBO,KAAKO,aAAa;IACxE;IAEA,IAAID,IAAAA,kBAAW,EAACN,MAAM,qBAAqB;QACzCG,OAAOC,KAAK,CAACI,gBAAgB,GAAGf,uBAC9BO,KAAKQ,gBAAgB;IAEzB;AACF;AAUO,SAASf,uBAAuBgB,KAAc;IACnD,IAAI,OAAOA,UAAU,WAAW;QAC9B,OAAOA;IACT,OAAO,IAAIA,UAAU,QAAQ;QAC3B,OAAO;IACT,OAAO,IAAIA,UAAU,SAAS;QAC5B,OAAO;IACT;IAEA,MAAM,IAAIC,MACR,CAAC,gEAAgE,EAAEC,OACjEF,OACA,CAAC,CAAC;AAER;AAQO,SAASf,eAAeM,IAAe;IAC5CY,OAAOC,IAAI,CAACb,MAAMc,OAAO,CAAC,CAACC;QACzB,IAAI,OAAOf,IAAI,CAACe,IAAI,KAAK,UAAU;YACjC,2CAA2C;YAC3C,IAAIf,IAAI,CAACe,IAAI,KAAK,MAAM;gBACtBf,IAAI,CAACe,IAAI,GAAG;YACd;YAEA,IAAIjB,cAAckB,GAAG,CAACD,MAAM;gBAC1Bf,IAAI,CAACe,IAAI,GAAGE,aAAI,CAACC,SAAS,CAAClB,IAAI,CAACe,IAAI;YACtC;QACF;IACF;AACF;AASO,SAASpB,SAASwB,OAAsB,EAAEC,KAAa;IAC5D,IAAID,YAAY,MAAM;QACpBE,IAAAA,oBAAY,EAACF;IACf;IAEA,IAAIC,SAASjB,OAAOC,KAAK,CAACG,aAAa,EAAE;QACvCc,IAAAA,oBAAY,EAACD;IACf;IAEA,IAAID,YAAY,QAAS,CAAA,CAACC,SAAUA,SAAS,CAACjB,OAAOC,KAAK,CAACG,aAAa,GAAI;QAC1Ec,IAAAA,oBAAY,EAAC;IACf;AACF;AAWO,eAAezB,WACpB0B,MAAc,EACdH,OAAe,EACfC,KAAY,EACZG,YAAqB;IAErB,IAAIC,kBAAkBF;IACtB,IAAI,CAACA,OAAOG,QAAQ,CAAC,MAAM;QACzBD,mBAAmB;IACrB;IAEA7B,SAAS6B,kBAAkBL,SAASC;IACpC,IAAI;QACF,IAAIG,cAAc;YAChB,MAAMG,YAAU,CAACC,MAAM,CAACJ;QAC1B;IACF,EAAE,OAAOK,aAAa;QACpBjC,SAAS,CAAC,EAAE6B,gBAAgB,8BAA8B,CAAC,EAAEI;IAC/D;IAEA,qCAAqC;IACrC,IAAI,CAACzB,OAAOC,KAAK,CAACC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,qEAAqE;QACrEwB,QAAQC,IAAI,CAAC;IACf;AACF;AASO,SAASjC,eAAekC,UAAkB;IAC/C,OAAOA,WAAWC,OAAO,CAAC,mBAAmB;AAC/C"}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
SnapConfigStruct: function() {
|
|
13
|
-
return SnapConfigStruct;
|
|
14
|
-
},
|
|
15
|
-
isSnapConfig: function() {
|
|
16
|
-
return isSnapConfig;
|
|
17
|
-
},
|
|
18
|
-
loadConfig: function() {
|
|
19
|
-
return loadConfig;
|
|
20
|
-
},
|
|
21
|
-
applyConfig: function() {
|
|
22
|
-
return applyConfig;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const _utils = require("@metamask/utils");
|
|
26
|
-
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
27
|
-
const _superstruct = require("superstruct");
|
|
28
|
-
const _yargsparser = /*#__PURE__*/ _interop_require_default(require("yargs-parser"));
|
|
29
|
-
const _builders = /*#__PURE__*/ _interop_require_default(require("../builders"));
|
|
30
|
-
const _misc = require("./misc");
|
|
31
|
-
function _interop_require_default(obj) {
|
|
32
|
-
return obj && obj.__esModule ? obj : {
|
|
33
|
-
default: obj
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
const SnapConfigStruct = (0, _superstruct.object)({
|
|
37
|
-
cliOptions: (0, _superstruct.optional)((0, _superstruct.object)()),
|
|
38
|
-
bundlerCustomizer: (0, _superstruct.optional)((0, _superstruct.func)())
|
|
39
|
-
});
|
|
40
|
-
function isSnapConfig(value) {
|
|
41
|
-
return (0, _superstruct.is)(value, SnapConfigStruct);
|
|
42
|
-
}
|
|
43
|
-
let snapConfigCache;
|
|
44
|
-
function loadConfig(cached = true) {
|
|
45
|
-
if (snapConfigCache !== undefined && cached) {
|
|
46
|
-
return snapConfigCache;
|
|
47
|
-
}
|
|
48
|
-
let config;
|
|
49
|
-
try {
|
|
50
|
-
// eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
|
|
51
|
-
config = require(_path.default.resolve(process.cwd(), _misc.CONFIG_FILE));
|
|
52
|
-
} catch (error) {
|
|
53
|
-
if (error.code === 'MODULE_NOT_FOUND') {
|
|
54
|
-
snapConfigCache = {};
|
|
55
|
-
return snapConfigCache;
|
|
56
|
-
}
|
|
57
|
-
(0, _misc.logError)(`Error during parsing of ${_misc.CONFIG_FILE}`, error);
|
|
58
|
-
return process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
if (!isSnapConfig(config)) {
|
|
61
|
-
(0, _misc.logError)(`Can't validate ${_misc.CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
|
|
62
|
-
return process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
snapConfigCache = config;
|
|
65
|
-
return config;
|
|
66
|
-
}
|
|
67
|
-
function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
|
|
68
|
-
// Instances of yargs has a number of undocumented functions, including
|
|
69
|
-
// getOptions. This function returns an object with properties "key" and
|
|
70
|
-
// "alias", which specify the options associated with the current command and
|
|
71
|
-
// their aliases, respectively.
|
|
72
|
-
//
|
|
73
|
-
// We leverage this to ensure that the config is only applied to args that are
|
|
74
|
-
// valid for the current command, and that weren't specified by the user on
|
|
75
|
-
// the command line.
|
|
76
|
-
//
|
|
77
|
-
// If we set args that aren't valid for the current command, yargs will error
|
|
78
|
-
// during validation.
|
|
79
|
-
const { alias: aliases, key: options } = yargsInstance.getOptions();
|
|
80
|
-
const parsedProcessArgv = (0, _yargsparser.default)(processArgv, {
|
|
81
|
-
alias: aliases
|
|
82
|
-
});
|
|
83
|
-
delete parsedProcessArgv._; // irrelevant yargs parser artifact
|
|
84
|
-
const commandOptions = new Set(Object.keys(options));
|
|
85
|
-
const shouldSetArg = (key)=>{
|
|
86
|
-
return commandOptions.has(key) && !(0, _utils.hasProperty)(parsedProcessArgv, key);
|
|
87
|
-
};
|
|
88
|
-
const config = snapConfig.cliOptions ?? {};
|
|
89
|
-
for (const key of Object.keys(config)){
|
|
90
|
-
if ((0, _utils.hasProperty)(_builders.default, key)) {
|
|
91
|
-
if (shouldSetArg(key)) {
|
|
92
|
-
yargsArgv[key] = config[key];
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
(0, _misc.logError)(`Error: Encountered unrecognized config property "options.${key}" in config file "${_misc.CONFIG_FILE}". Remove the property and try again.`);
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//# sourceMappingURL=snap-config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/snap-config.ts"],"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"],"names":["SnapConfigStruct","isSnapConfig","loadConfig","applyConfig","object","cliOptions","optional","bundlerCustomizer","func","value","is","snapConfigCache","cached","undefined","config","require","path","resolve","process","cwd","CONFIG_FILE","error","code","logError","exit","snapConfig","processArgv","yargsArgv","yargsInstance","alias","aliases","key","options","getOptions","parsedProcessArgv","yargsParse","_","commandOptions","Set","Object","keys","shouldSetArg","has","hasProperty","builders"],"mappings":";;;;;;;;;;;IAaaA,gBAAgB;eAAhBA;;IAqBGC,YAAY;eAAZA;;IAeAC,UAAU;eAAVA;;IA8CAC,WAAW;eAAXA;;;uBA/FY;6DAEX;6BACiC;oEAE3B;iEAGF;sBACiB;;;;;;AAI/B,MAAMH,mBAAmBI,IAAAA,mBAAM,EAAC;IACrCC,YAAYC,IAAAA,qBAAQ,EAACF,IAAAA,mBAAM;IAC3BG,mBAAmBD,IAAAA,qBAAQ,EAACE,IAAAA,iBAAI;AAClC;AAkBO,SAASP,aAAaQ,KAAc;IACzC,OAAOC,IAAAA,eAAE,EAACD,OAAOT;AACnB;AAEA,IAAIW;AAWG,SAAST,WAAWU,SAAS,IAAI;IACtC,IAAID,oBAAoBE,aAAaD,QAAQ;QAC3C,OAAOD;IACT;IAEA,IAAIG;IACJ,IAAI;QACF,iHAAiH;QACjHA,SAASC,QAAQC,aAAI,CAACC,OAAO,CAACC,QAAQC,GAAG,IAAIC,iBAAW;IAC1D,EAAE,OAAOC,OAAY;QACnB,IAAIA,MAAMC,IAAI,KAAK,oBAAoB;YACrCX,kBAAkB,CAAC;YACnB,OAAOA;QACT;QACAY,IAAAA,cAAQ,EAAC,CAAC,wBAAwB,EAAEH,iBAAW,CAAC,CAAC,EAAEC;QACnD,OAAOH,QAAQM,IAAI,CAAC;IACtB;IAEA,IAAI,CAACvB,aAAaa,SAAS;QACzBS,IAAAA,cAAQ,EACN,CAAC,eAAe,EAAEH,iBAAW,CAAC,iGAAiG,CAAC;QAElI,OAAOF,QAAQM,IAAI,CAAC;IACtB;IACAb,kBAAkBG;IAClB,OAAOA;AACT;AAoBO,SAASX,YACdsB,UAAsB,EACtBC,WAAqB,EACrBC,SAAoB,EACpBC,aAA2B;IAE3B,uEAAuE;IACvE,wEAAwE;IACxE,6EAA6E;IAC7E,+BAA+B;IAC/B,EAAE;IACF,8EAA8E;IAC9E,2EAA2E;IAC3E,oBAAoB;IACpB,EAAE;IACF,6EAA6E;IAC7E,qBAAqB;IACrB,MAAM,EAAEC,OAAOC,OAAO,EAAEC,KAAKC,OAAO,EAAE,GAAG,AACvCJ,cACAK,UAAU;IAKZ,MAAMC,oBAAoBC,IAAAA,oBAAU,EAACT,aAAa;QAChDG,OAAOC;IACT;IACA,OAAOI,kBAAkBE,CAAC,EAAE,mCAAmC;IAE/D,MAAMC,iBAAiB,IAAIC,IAAIC,OAAOC,IAAI,CAACR;IAE3C,MAAMS,eAAe,CAACV;QACpB,OAAOM,eAAeK,GAAG,CAACX,QAAQ,CAACY,IAAAA,kBAAW,EAACT,mBAAmBH;IACpE;IAEA,MAAMjB,SAAkCW,WAAWpB,UAAU,IAAI,CAAC;IAClE,KAAK,MAAM0B,OAAOQ,OAAOC,IAAI,CAAC1B,QAAS;QACrC,IAAI6B,IAAAA,kBAAW,EAACC,iBAAQ,EAAEb,MAAM;YAC9B,IAAIU,aAAaV,MAAM;gBACrBJ,SAAS,CAACI,IAAI,GAAGjB,MAAM,CAACiB,IAAI;YAC9B;QACF,OAAO;YACLR,IAAAA,cAAQ,EACN,CAAC,yDAAyD,EAAEQ,IAAI,kBAAkB,EAAEX,iBAAW,CAAC,qCAAqC,CAAC;YAExIF,QAAQM,IAAI,CAAC;QACf;IACF;AACF"}
|
package/dist/esm/builders.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/builders.ts"],"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"],"names":["TranspilationModes","LocalAndDeps","LocalOnly","None","builders","bundle","alias","describe","type","demandOption","normalize","default","dist","eval","manifest","port","coerce","arg","Number","parseInt","String","isNaN","Error","outfileName","root","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","choices","Object","values","depsToTranspile","verboseErrors","writeManifest","serve","directory"],"mappings":"WAsBO;UAAKA,kBAAkB;IAAlBA,mBACVC,kBAAe;IADLD,mBAEVE,eAAY;IAFFF,mBAGVG,UAAO;GAHGH,uBAAAA;AAMZ,MAAMI,WAA6B;IACjCC,QAAQ;QACNC,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAC,MAAM;QACJN,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAE,MAAM;QACJP,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAG,UAAU;QACRR,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAI,MAAM;QACJT,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;QACTK,QAAQ,CAACC;YACP,MAAMF,OAAOG,OAAOC,QAAQ,CAACC,OAAOH,MAAM;YAC1C,IAAIC,OAAOG,KAAK,CAACN,OAAO;gBACtB,MAAM,IAAIO,MAAM,CAAC,cAAc,EAAEF,OAAOH,KAAK,CAAC;YAChD;YACA,OAAOF;QACT;IACF;IAEAQ,aAAa;QACXjB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAa,MAAM;QACJlB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAc,YAAY;QACVlB,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAe,KAAK;QACHpB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAgB,eAAe;QACbrB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAiB,kBAAkB;QAChBpB,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAkB,mBAAmB;QACjBrB,MAAM;QACND,UACE;QACFE,cAAc;QACdE,SAASX,mBAAmBE,SAAS;QACrC4B,SAASC,OAAOC,MAAM,CAAChC;IACzB;IAEAiC,iBAAiB;QACfzB,MAAM;QACND,UAAU;QACVE,cAAc;IAChB;IAEAyB,eAAe;QACb1B,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAwB,eAAe;QACb5B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAyB,OAAO;QACL7B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEA0B,WAAW;QACT9B,UAAU;QACVC,MAAM;IACR;AACF;AAEA,eAAeJ,SAAS"}
|
package/dist/esm/cli.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import yargs from 'yargs';
|
|
2
|
-
import builders from './builders';
|
|
3
|
-
import { applyConfig, loadConfig, sanitizeInputs, setSnapGlobals, logError } from './utils';
|
|
4
|
-
/**
|
|
5
|
-
* The main CLI entry point function. This processes the command line args, and
|
|
6
|
-
* runs the appropriate function.
|
|
7
|
-
*
|
|
8
|
-
* @param argv - The raw command line arguments, i.e., `process.argv`.
|
|
9
|
-
* @param commands - The list of commands to use.
|
|
10
|
-
*/ export function cli(argv, commands) {
|
|
11
|
-
const rawArgv = argv.slice(2);
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/no-floating-promises
|
|
13
|
-
yargs(rawArgv).scriptName('mm-snap').usage('Usage: $0 <command> [options]').example('$0 init', `\tInitialize a snap project in the current directory`).example('$0 init my-snap', `\tInitialize a snap project in the 'my-snap' directory`).example('$0 build -s src/index.js -d out', `\tBuild 'src/index.js' as './out/bundle.js'`).example('$0 build -s src/index.js -d out -n snap.js', `\tBuild 'src/index.js' as './out/snap.js'`).example('$0 serve -r out', `\tServe files in './out' on port 8080`).example('$0 serve -r out -p 9000', `\tServe files in './out' on port 9000`).example('$0 watch -s src/index.js -d out', `\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`).command(commands).option('verboseErrors', builders.verboseErrors).option('suppressWarnings', builders.suppressWarnings).strict()// Typecast: The @types/yargs type for .middleware is incorrect.
|
|
14
|
-
// yargs middleware functions receive the yargs instance as a second parameter.
|
|
15
|
-
// ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation
|
|
16
|
-
.middleware((yargsArgv, yargsInstance)=>{
|
|
17
|
-
applyConfig(loadConfig(), rawArgv, yargsArgv, yargsInstance);
|
|
18
|
-
setSnapGlobals(yargsArgv);
|
|
19
|
-
sanitizeInputs(yargsArgv);
|
|
20
|
-
}, true).fail((message, error, _yargs)=>{
|
|
21
|
-
logError(message, error);
|
|
22
|
-
process.exitCode = 1;
|
|
23
|
-
}).demandCommand(1, 'You must specify at least one command.').help().alias('help', 'h').argv;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/esm/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli.ts"],"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, @typescript-eslint/no-floating-promises\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 my-snap',\n `\\tInitialize a snap project in the 'my-snap' 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"],"names":["yargs","builders","applyConfig","loadConfig","sanitizeInputs","setSnapGlobals","logError","cli","argv","commands","rawArgv","slice","scriptName","usage","example","command","option","verboseErrors","suppressWarnings","strict","middleware","yargsArgv","yargsInstance","fail","message","error","_yargs","process","exitCode","demandCommand","help","alias"],"mappings":"AAAA,OAAOA,WAA0B,QAAQ;AAGzC,OAAOC,cAAc,aAAa;AAClC,SACEC,WAAW,EACXC,UAAU,EACVC,cAAc,EACdC,cAAc,EACdC,QAAQ,QACH,UAAU;AAEjB;;;;;;CAMC,GACD,OAAO,SAASC,IAAIC,IAAc,EAAEC,QAAa;IAC/C,MAAMC,UAAUF,KAAKG,KAAK,CAAC;IAC3B,6GAA6G;IAC7GX,MAAMU,SACHE,UAAU,CAAC,WACXC,KAAK,CAAC,iCAENC,OAAO,CAAC,WAAW,CAAC,oDAAoD,CAAC,EACzEA,OAAO,CACN,mBACA,CAAC,sDAAsD,CAAC,EAEzDA,OAAO,CACN,mCACA,CAAC,2CAA2C,CAAC,EAE9CA,OAAO,CACN,8CACA,CAAC,yCAAyC,CAAC,EAE5CA,OAAO,CAAC,mBAAmB,CAAC,qCAAqC,CAAC,EAClEA,OAAO,CAAC,2BAA2B,CAAC,qCAAqC,CAAC,EAC1EA,OAAO,CACN,mCACA,CAAC,8FAA8F,CAAC,EAGjGC,OAAO,CAACN,UAERO,MAAM,CAAC,iBAAiBf,SAASgB,aAAa,EAE9CD,MAAM,CAAC,oBAAoBf,SAASiB,gBAAgB,EAEpDC,MAAM,EAEP,gEAAgE;IAChE,+EAA+E;IAC/E,0FAA0F;KACzFC,UAAU,CACR,CAACC,WAAsBC;QACtBpB,YAAYC,cAAcO,SAASW,WAAWC;QAC9CjB,eAAegB;QACfjB,eAAeiB;IACjB,GACA,MAGDE,IAAI,CAAC,CAACC,SAAiBC,OAAcC;QACpCpB,SAASkB,SAASC;QAClBE,QAAQC,QAAQ,GAAG;IACrB,GAECC,aAAa,CAAC,GAAG,0CAEjBC,IAAI,GACJC,KAAK,CAAC,QAAQ,KAAKvB,IAAI;AAC5B"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { getOutfilePath, validateDirPath, validateFilePath, validateOutfileName } from '@metamask/snaps-utils';
|
|
2
|
-
import { loadConfig } from '../../utils';
|
|
3
|
-
import { evalHandler } from '../eval/evalHandler';
|
|
4
|
-
import { manifestHandler } from '../manifest/manifestHandler';
|
|
5
|
-
import { bundle } from './bundle';
|
|
6
|
-
/**
|
|
7
|
-
* Builds all files in the given source directory to the given destination
|
|
8
|
-
* directory.
|
|
9
|
-
*
|
|
10
|
-
* Creates destination directory if it doesn't exist.
|
|
11
|
-
*
|
|
12
|
-
* @param argv - Argv from Yargs.
|
|
13
|
-
* @param argv.src - The source file path.
|
|
14
|
-
* @param argv.dist - The output directory path.
|
|
15
|
-
* @param argv.outfileName - The output file name.
|
|
16
|
-
*/ export async function build(argv) {
|
|
17
|
-
const { src, dist, outfileName } = argv;
|
|
18
|
-
if (outfileName) {
|
|
19
|
-
validateOutfileName(outfileName);
|
|
20
|
-
}
|
|
21
|
-
await validateFilePath(src);
|
|
22
|
-
await validateDirPath(dist, true);
|
|
23
|
-
const outfilePath = getOutfilePath(dist, outfileName);
|
|
24
|
-
const result = await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);
|
|
25
|
-
if (result && argv.eval) {
|
|
26
|
-
await evalHandler({
|
|
27
|
-
...argv,
|
|
28
|
-
bundle: outfilePath
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (argv.manifest) {
|
|
32
|
-
await manifestHandler(argv);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//# sourceMappingURL=buildHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cmds/build/buildHandler.ts"],"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"],"names":["getOutfilePath","validateDirPath","validateFilePath","validateOutfileName","loadConfig","evalHandler","manifestHandler","bundle","build","argv","src","dist","outfileName","outfilePath","result","bundlerCustomizer","eval","manifest"],"mappings":"AAAA,SACEA,cAAc,EACdC,eAAe,EACfC,gBAAgB,EAChBC,mBAAmB,QACd,wBAAwB;AAG/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,WAAW,QAAQ,sBAAsB;AAClD,SAASC,eAAe,QAAQ,8BAA8B;AAC9D,SAASC,MAAM,QAAQ,WAAW;AAElC;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,MAAMC,IAAe;IACzC,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGH;IACnC,IAAIG,aAAa;QACfT,oBAAoBS;IACtB;IACA,MAAMV,iBAAiBQ;IACvB,MAAMT,gBAAgBU,MAAM;IAE5B,MAAME,cAAcb,eAAeW,MAAMC;IACzC,MAAME,SAAS,MAAMP,OACnBG,KACAG,aACAJ,MACAL,aAAaW,iBAAiB;IAEhC,IAAID,UAAUL,KAAKO,IAAI,EAAE;QACvB,MAAMX,YAAY;YAAE,GAAGI,IAAI;YAAEF,QAAQM;QAAY;IACnD;IAEA,IAAIJ,KAAKQ,QAAQ,EAAE;QACjB,MAAMX,gBAAgBG;IACxB;AACF"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import plugin from '@metamask/snaps-browserify-plugin';
|
|
2
|
-
import browserify from 'browserify';
|
|
3
|
-
import { TranspilationModes } from '../../builders';
|
|
4
|
-
import { processDependencies, writeBundleFile } from './utils';
|
|
5
|
-
// We need to statically import all Browserify transforms and all Babel presets
|
|
6
|
-
// and plugins, and calling `require` is the sanest way to do that.
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */ /**
|
|
8
|
-
* Builds a Snap bundle JS file from its JavaScript source.
|
|
9
|
-
*
|
|
10
|
-
* @param src - The source file path.
|
|
11
|
-
* @param dest - The destination file path.
|
|
12
|
-
* @param argv - Arguments as an object generated by `yargs`.
|
|
13
|
-
* @param argv.sourceMaps - Whether to output sourcemaps.
|
|
14
|
-
* @param argv.stripComments - Whether to remove comments from code.
|
|
15
|
-
* @param argv.transpilationMode - The Babel transpilation mode.
|
|
16
|
-
* @param bundlerTransform - An optional function which can be used to transform
|
|
17
|
-
* the Browserify instance, e.g., adding a custom transform or plugin.
|
|
18
|
-
*/ export async function bundle(src, dest, argv, bundlerTransform) {
|
|
19
|
-
const { sourceMaps: debug, transpilationMode } = argv;
|
|
20
|
-
const babelifyOptions = processDependencies(argv);
|
|
21
|
-
return new Promise((resolve, _reject)=>{
|
|
22
|
-
const bundler = browserify(src, {
|
|
23
|
-
debug,
|
|
24
|
-
extensions: [
|
|
25
|
-
'.js',
|
|
26
|
-
'.ts'
|
|
27
|
-
],
|
|
28
|
-
// Standalone is required to properly support Snaps using module.exports
|
|
29
|
-
standalone: '<snap>'
|
|
30
|
-
});
|
|
31
|
-
if (transpilationMode !== TranspilationModes.None) {
|
|
32
|
-
bundler.transform(require('babelify'), {
|
|
33
|
-
global: transpilationMode === TranspilationModes.LocalAndDeps,
|
|
34
|
-
extensions: [
|
|
35
|
-
'.js',
|
|
36
|
-
'.ts'
|
|
37
|
-
],
|
|
38
|
-
presets: [
|
|
39
|
-
require('@babel/preset-typescript'),
|
|
40
|
-
[
|
|
41
|
-
require('@babel/preset-env'),
|
|
42
|
-
{
|
|
43
|
-
targets: {
|
|
44
|
-
browsers: [
|
|
45
|
-
'chrome >= 90',
|
|
46
|
-
'firefox >= 91'
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
],
|
|
52
|
-
plugins: [
|
|
53
|
-
require('@babel/plugin-transform-runtime'),
|
|
54
|
-
require('@babel/plugin-proposal-class-properties'),
|
|
55
|
-
require('@babel/plugin-proposal-private-methods'),
|
|
56
|
-
require('@babel/plugin-proposal-class-static-block'),
|
|
57
|
-
require('@babel/plugin-proposal-private-property-in-object')
|
|
58
|
-
],
|
|
59
|
-
parserOpts: {
|
|
60
|
-
attachComment: !argv.stripComments
|
|
61
|
-
},
|
|
62
|
-
...babelifyOptions
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
bundlerTransform?.(bundler);
|
|
66
|
-
bundler.plugin(plugin, {
|
|
67
|
-
stripComments: argv.stripComments,
|
|
68
|
-
manifestPath: undefined,
|
|
69
|
-
eval: false
|
|
70
|
-
});
|
|
71
|
-
bundler.bundle(async (bundleError, bundleBuffer)=>await writeBundleFile({
|
|
72
|
-
bundleError,
|
|
73
|
-
bundleBuffer,
|
|
74
|
-
src,
|
|
75
|
-
dest,
|
|
76
|
-
resolve
|
|
77
|
-
}));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//# sourceMappingURL=bundle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cmds/build/bundle.ts"],"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 >= 90', 'firefox >= 91'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\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"],"names":["plugin","browserify","TranspilationModes","processDependencies","writeBundleFile","bundle","src","dest","argv","bundlerTransform","sourceMaps","debug","transpilationMode","babelifyOptions","Promise","resolve","_reject","bundler","extensions","standalone","None","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","parserOpts","attachComment","stripComments","manifestPath","undefined","eval","bundleError","bundleBuffer"],"mappings":"AAAA,OAAOA,YAAyB,oCAAoC;AACpE,OAAOC,gBAAsC,aAAa;AAE1D,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,mBAAmB,EAAEC,eAAe,QAAQ,UAAU;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,iHAAiH,GAEjH;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,OACpBC,GAAW,EACXC,IAAY,EACZC,IAAe,EACfC,gBAAsD;IAEtD,MAAM,EAAEC,YAAYC,KAAK,EAAEC,iBAAiB,EAAE,GAAGJ;IACjD,MAAMK,kBAAkBV,oBAAoBK;IAC5C,OAAO,IAAIM,QAAQ,CAACC,SAASC;QAC3B,MAAMC,UAAUhB,WAAWK,KAAK;YAC9BK;YACAO,YAAY;gBAAC;gBAAO;aAAM;YAC1B,wEAAwE;YACxEC,YAAY;QACd;QAEA,IAAIP,sBAAsBV,mBAAmBkB,IAAI,EAAE;YACjDH,QAAQI,SAAS,CAACC,QAAQ,aAAa;gBACrCC,QAAQX,sBAAsBV,mBAAmBsB,YAAY;gBAC7DN,YAAY;oBAAC;oBAAO;iBAAM;gBAC1BO,SAAS;oBACPH,QAAQ;oBACR;wBACEA,QAAQ;wBACR;4BACEI,SAAS;gCACPC,UAAU;oCAAC;oCAAgB;iCAAgB;4BAC7C;wBACF;qBACD;iBACF;gBACDC,SAAS;oBACPN,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;iBACT;gBACDO,YAAY;oBACVC,eAAe,CAACtB,KAAKuB,aAAa;gBACpC;gBACA,GAAIlB,eAAe;YACrB;QACF;QAEAJ,mBAAmBQ;QAEnBA,QAAQjB,MAAM,CAAUA,QAAQ;YAC9B+B,eAAevB,KAAKuB,aAAa;YACjCC,cAAcC;YACdC,MAAM;QACR;QAEAjB,QAAQZ,MAAM,CACZ,OAAO8B,aAAaC,eAClB,MAAMhC,gBAAgB;gBACpB+B;gBACAC;gBACA9B;gBACAC;gBACAQ;YACF;IAEN;AACF"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import builders from '../../builders';
|
|
2
|
-
import { build } from './buildHandler';
|
|
3
|
-
import { processInvalidTranspilation } from './utils';
|
|
4
|
-
const command = {
|
|
5
|
-
command: [
|
|
6
|
-
'build',
|
|
7
|
-
'b'
|
|
8
|
-
],
|
|
9
|
-
desc: 'Build Snap from source',
|
|
10
|
-
builder: (yarg)=>{
|
|
11
|
-
yarg.option('dist', builders.dist).option('eval', builders.eval).option('manifest', builders.manifest).option('outfileName', builders.outfileName).option('sourceMaps', builders.sourceMaps).option('src', builders.src).option('stripComments', builders.stripComments).option('transpilationMode', builders.transpilationMode).option('depsToTranspile', builders.depsToTranspile).option('writeManifest', builders.writeManifest).implies('writeManifest', 'manifest').implies('depsToTranspile', 'transpilationMode').middleware((argv)=>processInvalidTranspilation(argv));
|
|
12
|
-
},
|
|
13
|
-
handler: async (argv)=>build(argv)
|
|
14
|
-
};
|
|
15
|
-
export default command;
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cmds/build/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nconst command = {\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\nexport default command;\n"],"names":["builders","build","processInvalidTranspilation","command","desc","builder","yarg","option","dist","eval","manifest","outfileName","sourceMaps","src","stripComments","transpilationMode","depsToTranspile","writeManifest","implies","middleware","argv","handler"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,2BAA2B,QAAQ,UAAU;AAEtD,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,QAAQP,SAASQ,IAAI,EAC5BD,MAAM,CAAC,QAAQP,SAASS,IAAI,EAC5BF,MAAM,CAAC,YAAYP,SAASU,QAAQ,EACpCH,MAAM,CAAC,eAAeP,SAASW,WAAW,EAC1CJ,MAAM,CAAC,cAAcP,SAASY,UAAU,EACxCL,MAAM,CAAC,OAAOP,SAASa,GAAG,EAC1BN,MAAM,CAAC,iBAAiBP,SAASc,aAAa,EAC9CP,MAAM,CAAC,qBAAqBP,SAASe,iBAAiB,EACtDR,MAAM,CAAC,mBAAmBP,SAASgB,eAAe,EAClDT,MAAM,CAAC,iBAAiBP,SAASiB,aAAa,EAC9CC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASlB,4BAA4BkB;IACtD;IACAC,SAAS,OAAOD,OAAoBnB,MAAMmB;AAC5C;AAEA,eAAejB,QAAQ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cmds/build/utils.ts"],"sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\n\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { writeError } from '../../utils';\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 logInfo(`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"],"names":["logInfo","promises","fs","TranspilationModes","writeError","writeBundleFile","bundleError","bundleBuffer","src","dest","resolve","message","writeFile","toString","error","processDependencies","argv","depsToTranspile","transpilationMode","babelifyOptions","LocalAndDeps","regexpStr","getDependencyRegExp","ignore","dependencies","regexp","includes","length","paths","sanitizeDependencyPaths","shift","forEach","path","RegExp","map","dependency","replace","processInvalidTranspilation","Error"],"mappings":"AAAA,SAASA,OAAO,QAAQ,wBAAwB;AAChD,SAASC,YAAYC,EAAE,QAAQ,KAAK;AAEpC,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,UAAU,QAAQ,cAAc;AAUzC;;;;;;;;;;;;;CAaC,GACD,OAAO,eAAeC,gBAAgB,EACpCC,WAAW,EACXC,YAAY,EACZC,GAAG,EACHC,IAAI,EACJC,OAAO,EACa;IACpB,IAAIJ,aAAa;QACf,MAAMF,WAAW,gBAAgBE,YAAYK,OAAO,EAAEL;IACxD;IAEA,IAAI;QACF,MAAMJ,GAAGU,SAAS,CAACH,MAAMF,cAAcM;QACvCb,QAAQ,CAAC,gBAAgB,EAAEQ,IAAI,cAAc,EAAEC,KAAK,EAAE,CAAC;QACvDC,QAAQ;IACV,EAAE,OAAOI,OAAO;QACd,MAAMV,WAAW,gBAAgBU,MAAMH,OAAO,EAAEG,OAAOL;IACzD;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASM,oBAAoBC,IAAe;IACjD,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAE,GAAGF;IAC/C,MAAMG,kBAAuC,CAAC;IAC9C,IAAID,sBAAsBf,mBAAmBiB,YAAY,EAAE;QACzD,MAAMC,YAAYC,oBAAoBL;QACtC,IAAII,cAAc,MAAM;YACtBF,gBAAgBI,MAAM,GAAG;gBAACF;aAAU;QACtC;IACF;IACA,OAAOF;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASG,oBAAoBE,YAAsB;IACxD,IAAIC,SAAwB;IAC5B,IAAI,CAACD,gBAAgBA,aAAaE,QAAQ,CAAC,QAAQ,CAACF,aAAaG,MAAM,EAAE;QACvE,OAAOF;IACT;IACA,MAAMG,QAAkBC,wBAAwBL;IAChDC,SAAS,CAAC,iBAAiB,EAAEG,MAAME,KAAK,MAAM,GAAG,CAAC;IAClDF,MAAMG,OAAO,CAAC,CAACC,OAAUP,UAAU,CAAC,CAAC,EAAEO,KAAK,CAAC;IAC7CP,UAAU;IACV,OAAOQ,OAAOR,QAAQ;AACxB;AAEA;;;;;CAKC,GACD,OAAO,SAASI,wBAAwBL,YAAsB;IAC5D,OAAOA,aAAaU,GAAG,CAAC,CAACC;QACvB,OAAOA,WAAWC,OAAO,CAAC,YAAY,IAAIA,OAAO,CAAC,YAAY;IAChE;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASC,4BAA4BrB,IAAe;IACzD,IACEA,KAAKC,eAAe,IACpBD,KAAKE,iBAAiB,KAAKf,mBAAmBiB,YAAY,EAC1D;QACA,MAAM,IAAIkB,MACR;IAEJ;AACF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { evalBundle, logInfo } from '@metamask/snaps-utils';
|
|
2
|
-
import { assert } from '@metamask/utils';
|
|
3
|
-
/**
|
|
4
|
-
* Runs the snap in a worker, to ensure SES compatibility.
|
|
5
|
-
*
|
|
6
|
-
* @param argv - The Yargs arguments object.
|
|
7
|
-
* @returns A promise that resolves once the eval has finished.
|
|
8
|
-
* @throws If the eval failed.
|
|
9
|
-
*/ export async function evalHandler(argv) {
|
|
10
|
-
const { bundle: bundlePath } = argv;
|
|
11
|
-
assert(typeof bundlePath === 'string');
|
|
12
|
-
try {
|
|
13
|
-
await evalBundle(bundlePath);
|
|
14
|
-
logInfo(`Eval Success: evaluated '${bundlePath}' in SES!`);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
throw new Error(`Snap evaluation error: ${error.message}`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=evalHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cmds/eval/evalHandler.ts"],"sourcesContent":["import { evalBundle, logInfo } 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 logInfo(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"],"names":["evalBundle","logInfo","assert","evalHandler","argv","bundle","bundlePath","error","Error","message"],"mappings":"AAAA,SAASA,UAAU,EAAEC,OAAO,QAAQ,wBAAwB;AAC5D,SAASC,MAAM,QAAQ,kBAAkB;AAIzC;;;;;;CAMC,GACD,OAAO,eAAeC,YAAYC,IAAe;IAC/C,MAAM,EAAEC,QAAQC,UAAU,EAAE,GAAGF;IAE/BF,OAAO,OAAOI,eAAe;IAE7B,IAAI;QACF,MAAMN,WAAWM;QACjBL,QAAQ,CAAC,yBAAyB,EAAEK,WAAW,SAAS,CAAC;IAC3D,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,uBAAuB,EAAED,MAAME,OAAO,CAAC,CAAC;IAC3D;AACF"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import builders from '../../builders';
|
|
2
|
-
import { evalHandler } from './evalHandler';
|
|
3
|
-
const command = {
|
|
4
|
-
command: [
|
|
5
|
-
'eval',
|
|
6
|
-
'e'
|
|
7
|
-
],
|
|
8
|
-
desc: 'Attempt to evaluate Snap bundle in SES',
|
|
9
|
-
builder: (yarg)=>{
|
|
10
|
-
yarg.option('bundle', builders.bundle);
|
|
11
|
-
},
|
|
12
|
-
handler: async (argv)=>evalHandler(argv)
|
|
13
|
-
};
|
|
14
|
-
export default command;
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cmds/eval/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { evalHandler } from './evalHandler';\n\nconst command = {\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\nexport default command;\n"],"names":["builders","evalHandler","command","desc","builder","yarg","option","bundle","handler","argv"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,WAAW,QAAQ,gBAAgB;AAE5C,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAQ;KAAI;IACtBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,UAAUN,SAASO,MAAM;IACvC;IACAC,SAAS,OAAOC,OAAoBR,YAAYQ;AAClD;AAEA,eAAeP,QAAQ"}
|
package/dist/esm/cmds/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import build from './build';
|
|
2
|
-
import evaluate from './eval';
|
|
3
|
-
import manifest from './manifest';
|
|
4
|
-
import serve from './serve';
|
|
5
|
-
import watch from './watch';
|
|
6
|
-
const commands = [
|
|
7
|
-
build,
|
|
8
|
-
evaluate,
|
|
9
|
-
manifest,
|
|
10
|
-
serve,
|
|
11
|
-
watch
|
|
12
|
-
];
|
|
13
|
-
export default commands;
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cmds/index.ts"],"sourcesContent":["import build from './build';\nimport evaluate from './eval';\nimport manifest from './manifest';\nimport serve from './serve';\nimport watch from './watch';\n\nconst commands = [build, evaluate, manifest, serve, watch];\nexport default commands;\n"],"names":["build","evaluate","manifest","serve","watch","commands"],"mappings":"AAAA,OAAOA,WAAW,UAAU;AAC5B,OAAOC,cAAc,SAAS;AAC9B,OAAOC,cAAc,aAAa;AAClC,OAAOC,WAAW,UAAU;AAC5B,OAAOC,WAAW,UAAU;AAE5B,MAAMC,WAAW;IAACL;IAAOC;IAAUC;IAAUC;IAAOC;CAAM;AAC1D,eAAeC,SAAS"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import builders from '../../builders';
|
|
2
|
-
import { logError } from '../../utils';
|
|
3
|
-
import { manifestHandler } from './manifestHandler';
|
|
4
|
-
const command = {
|
|
5
|
-
command: [
|
|
6
|
-
'manifest',
|
|
7
|
-
'm'
|
|
8
|
-
],
|
|
9
|
-
desc: 'Validate the snap.manifest.json file',
|
|
10
|
-
builder: (yarg)=>{
|
|
11
|
-
yarg.option('writeManifest', {
|
|
12
|
-
...builders.writeManifest,
|
|
13
|
-
alias: [
|
|
14
|
-
'fix'
|
|
15
|
-
]
|
|
16
|
-
});
|
|
17
|
-
},
|
|
18
|
-
handler: async (argv)=>{
|
|
19
|
-
try {
|
|
20
|
-
await manifestHandler(argv);
|
|
21
|
-
} catch (error) {
|
|
22
|
-
logError(error.message, error);
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
export default command;
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cmds/manifest/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\nimport { manifestHandler } from './manifestHandler';\n\nconst command = {\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\nexport default command;\n"],"names":["builders","logError","manifestHandler","command","desc","builder","yarg","option","writeManifest","alias","handler","argv","error","message"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,QAAQ,QAAQ,cAAc;AACvC,SAASC,eAAe,QAAQ,oBAAoB;AAEpD,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAY;KAAI;IAC1BC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,iBAAiB;YAAE,GAAGP,SAASQ,aAAa;YAAEC,OAAO;gBAAC;aAAM;QAAC;IAC3E;IACAC,SAAS,OAAOC;QACd,IAAI;YACF,MAAMT,gBAAgBS;QACxB,EAAE,OAAOC,OAAO;YACdX,SAASW,MAAMC,OAAO,EAAED;YACxB,MAAMA;QACR;IACF;AACF;AAEA,eAAeT,QAAQ"}
|