@metamask/snaps-cli 0.14.0 → 0.17.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/README.md +5 -2
- package/dist/builders.d.ts +6 -0
- package/dist/builders.js +20 -1
- package/dist/builders.js.map +1 -1
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +8 -0
- package/dist/cli.js.map +1 -1
- package/dist/cmds/build/buildHandler.d.ts +4 -4
- package/dist/cmds/build/buildHandler.js +4 -4
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/bundle.d.ts +4 -2
- package/dist/cmds/build/bundle.js +13 -4
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/build/utils.d.ts +21 -8
- package/dist/cmds/build/utils.js +21 -8
- package/dist/cmds/build/utils.js.map +1 -1
- package/dist/cmds/eval/eval-worker.js +19 -9
- package/dist/cmds/eval/eval-worker.js.map +1 -1
- package/dist/cmds/eval/evalHandler.d.ts +7 -0
- package/dist/cmds/eval/evalHandler.js +7 -0
- package/dist/cmds/eval/evalHandler.js.map +1 -1
- package/dist/cmds/eval/mock.d.ts +11 -0
- package/dist/cmds/eval/mock.js +36 -1
- package/dist/cmds/eval/mock.js.map +1 -1
- package/dist/cmds/eval/workerEval.d.ts +7 -0
- package/dist/cmds/eval/workerEval.js +11 -6
- package/dist/cmds/eval/workerEval.js.map +1 -1
- package/dist/cmds/index.d.ts +1 -0
- package/dist/cmds/init/index.js +13 -1
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/init-template.json +5 -1
- package/dist/cmds/init/initHandler.d.ts +11 -0
- package/dist/cmds/init/initHandler.js +38 -3
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +21 -4
- package/dist/cmds/init/initUtils.js +55 -7
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/manifestHandler.d.ts +1 -0
- package/dist/cmds/manifest/manifestHandler.js +6 -0
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/serve/index.js +2 -44
- package/dist/cmds/serve/index.js.map +1 -1
- package/dist/cmds/serve/serveHandler.d.ts +10 -0
- package/dist/cmds/serve/serveHandler.js +51 -0
- package/dist/cmds/serve/serveHandler.js.map +1 -0
- package/dist/cmds/serve/serveUtils.d.ts +17 -0
- package/dist/cmds/serve/serveUtils.js +17 -0
- package/dist/cmds/serve/serveUtils.js.map +1 -1
- package/dist/cmds/watch/index.js +3 -0
- package/dist/cmds/watch/index.js.map +1 -1
- package/dist/cmds/watch/watchHandler.d.ts +4 -4
- package/dist/cmds/watch/watchHandler.js +12 -6
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/utils/fs.d.ts +5 -5
- package/dist/utils/fs.js +5 -5
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/misc.d.ts +16 -13
- package/dist/utils/misc.js +19 -15
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/readline.d.ts +25 -0
- package/dist/utils/readline.js +25 -0
- package/dist/utils/readline.js.map +1 -1
- package/dist/utils/snap-config.d.ts +15 -0
- package/dist/utils/snap-config.js +18 -4
- package/dist/utils/snap-config.js.map +1 -1
- package/dist/utils/validate-fs.d.ts +19 -18
- package/dist/utils/validate-fs.js +21 -20
- package/dist/utils/validate-fs.js.map +1 -1
- package/package.json +20 -19
- package/CHANGELOG.md +0 -209
package/dist/utils/misc.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.trimPathString = exports.writeError = exports.logWarning = exports.logError = exports.sanitizeInputs = exports.booleanStringToBoolean = exports.setSnapGlobals = exports.CONFIG_FILE = exports.permRequestKeys = exports.deepClone = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const utils_1 = require("@metamask/utils");
|
|
9
10
|
const rfdc_1 = __importDefault(require("rfdc"));
|
|
10
11
|
exports.deepClone = (0, rfdc_1.default)({ proto: false, circles: false });
|
|
11
12
|
exports.permRequestKeys = [
|
|
@@ -31,9 +32,10 @@ const pathArguments = new Set([
|
|
|
31
32
|
]);
|
|
32
33
|
/**
|
|
33
34
|
* Sets global variable snaps which tracks user settings:
|
|
34
|
-
* watch mode activation, verbose errors messages, and whether to suppress
|
|
35
|
+
* watch mode activation, verbose errors messages, and whether to suppress
|
|
36
|
+
* warnings.
|
|
35
37
|
*
|
|
36
|
-
* @param argv -
|
|
38
|
+
* @param argv - Arguments as an object generated by `yargs`.
|
|
37
39
|
*/
|
|
38
40
|
function setSnapGlobals(argv) {
|
|
39
41
|
if (['w', 'watch'].includes(argv._[0])) {
|
|
@@ -42,10 +44,10 @@ function setSnapGlobals(argv) {
|
|
|
42
44
|
else {
|
|
43
45
|
global.snaps.isWatching = false;
|
|
44
46
|
}
|
|
45
|
-
if (
|
|
47
|
+
if ((0, utils_1.hasProperty)(argv, 'verboseErrors')) {
|
|
46
48
|
global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);
|
|
47
49
|
}
|
|
48
|
-
if (
|
|
50
|
+
if ((0, utils_1.hasProperty)(argv, 'suppressWarnings')) {
|
|
49
51
|
global.snaps.suppressWarnings = booleanStringToBoolean(argv.suppressWarnings);
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -54,7 +56,7 @@ exports.setSnapGlobals = setSnapGlobals;
|
|
|
54
56
|
* Attempts to convert a string to a boolean and throws if the value is invalid.
|
|
55
57
|
*
|
|
56
58
|
* @param value - The value to convert to a boolean.
|
|
57
|
-
* @
|
|
59
|
+
* @returns `true` if the value is the string `"true"`, `false` if it is the
|
|
58
60
|
* string `"false"`, the value if it is already a boolean, or an error
|
|
59
61
|
* otherwise.
|
|
60
62
|
*/
|
|
@@ -75,7 +77,7 @@ exports.booleanStringToBoolean = booleanStringToBoolean;
|
|
|
75
77
|
* Sanitizes inputs. Currently normalizes "./" paths to ".".
|
|
76
78
|
* Yargs handles other path normalization as specified in builders.
|
|
77
79
|
*
|
|
78
|
-
* @param argv -
|
|
80
|
+
* @param argv - Arguments as an object generated by yargs.
|
|
79
81
|
*/
|
|
80
82
|
function sanitizeInputs(argv) {
|
|
81
83
|
Object.keys(argv).forEach((key) => {
|
|
@@ -95,8 +97,8 @@ exports.sanitizeInputs = sanitizeInputs;
|
|
|
95
97
|
* Logs an error message to console. Logs original error if it exists and
|
|
96
98
|
* the verboseErrors global is true.
|
|
97
99
|
*
|
|
98
|
-
* @param msg - The error message
|
|
99
|
-
* @param err - The original error
|
|
100
|
+
* @param msg - The error message.
|
|
101
|
+
* @param err - The original error.
|
|
100
102
|
*/
|
|
101
103
|
function logError(msg, err) {
|
|
102
104
|
console.error(msg);
|
|
@@ -108,7 +110,8 @@ exports.logError = logError;
|
|
|
108
110
|
/**
|
|
109
111
|
* Logs a warning message to console.
|
|
110
112
|
*
|
|
111
|
-
* @param msg - The warning message
|
|
113
|
+
* @param msg - The warning message.
|
|
114
|
+
* @param error - The original error.
|
|
112
115
|
*/
|
|
113
116
|
function logWarning(msg, error) {
|
|
114
117
|
if (msg && !global.snaps.suppressWarnings) {
|
|
@@ -120,12 +123,13 @@ function logWarning(msg, error) {
|
|
|
120
123
|
}
|
|
121
124
|
exports.logWarning = logWarning;
|
|
122
125
|
/**
|
|
123
|
-
* Logs an error, attempts to unlink the destination file, and
|
|
126
|
+
* Logs an error, attempts to unlink the destination file, and kills the
|
|
127
|
+
* process.
|
|
124
128
|
*
|
|
125
|
-
* @param prefix - The message prefix
|
|
126
|
-
* @param msg - The error message
|
|
127
|
-
* @param err - The original error
|
|
128
|
-
* @param destFilePath - The output file path
|
|
129
|
+
* @param prefix - The message prefix.
|
|
130
|
+
* @param msg - The error message.
|
|
131
|
+
* @param err - The original error.
|
|
132
|
+
* @param destFilePath - The output file path.
|
|
129
133
|
*/
|
|
130
134
|
async function writeError(prefix, msg, err, destFilePath) {
|
|
131
135
|
let processedPrefix = prefix;
|
|
@@ -154,7 +158,7 @@ exports.writeError = writeError;
|
|
|
154
158
|
* given path string.
|
|
155
159
|
*
|
|
156
160
|
* @param pathString - The path string to trim.
|
|
157
|
-
* @returns
|
|
161
|
+
* @returns The trimmed path string.
|
|
158
162
|
*/
|
|
159
163
|
function trimPathString(pathString) {
|
|
160
164
|
return pathString.replace(/^[./]+|[./]+$/gu, '');
|
package/dist/utils/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AACxB,gDAAwB;AAGX,QAAA,SAAS,GAAG,IAAA,cAAI,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAEnD,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,WAAW,GAAG,gBAAgB,CAAC;AAE5C,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,KAAK;IACL,GAAG;IACH,MAAM;IACN,GAAG;IACH,QAAQ;IACR,GAAG;IACH,MAAM;IACN,GAAG;CACJ,CAAC,CAAC;AAEH
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AACxB,2CAA8C;AAC9C,gDAAwB;AAGX,QAAA,SAAS,GAAG,IAAA,cAAI,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAEnD,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,WAAW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xB;IAED,QAAQ,CAAC,eAAe,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IACrC,IAAI;QACF,IAAI,YAAY,EAAE;YAChB,MAAM,aAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;SACvC;KACF;IAAC,OAAO,WAAW,EAAE;QACpB,QAAQ,CAAC,GAAG,eAAe,gCAAgC,EAAE,WAAW,CAAC,CAAC;KAC3E;IAED,qCAAqC;IACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,uEAAuE;QACvE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AA1BD,gCA0BC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,UAAkB;IAC/C,OAAO,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import { promises as filesystem } from 'fs';\nimport path from 'path';\nimport { hasProperty } from '@metamask/utils';\nimport rfdc from 'rfdc';\nimport { Arguments } from 'yargs';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\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: \"${value}\"`,\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 msg - The error message.\n * @param err - The original error.\n */\nexport function logError(msg: string, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message.\n * @param error - The original error.\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param msg - The error message.\n * @param err - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-skunkworks/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"]}
|
package/dist/utils/readline.d.ts
CHANGED
|
@@ -6,7 +6,32 @@ declare type PromptArgs = {
|
|
|
6
6
|
shouldClose?: boolean;
|
|
7
7
|
readlineInterface?: readline.Interface;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Open a readline interface, to prompt for user input. Avoid using this
|
|
11
|
+
* function directly. Use the {@link prompt} function instead.
|
|
12
|
+
*/
|
|
9
13
|
export declare function openPrompt(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Prompt for user input on the command line. If the prompt isn't open, it will
|
|
16
|
+
* be opened.
|
|
17
|
+
*
|
|
18
|
+
* @param args - The prompt arguments.
|
|
19
|
+
* @param args.question - The question to ask.
|
|
20
|
+
* @param args.defaultValue - The default value to use, if no answer is provided.
|
|
21
|
+
* @param args.shouldClose - Whether to close the readline interface after
|
|
22
|
+
* prompting.
|
|
23
|
+
* @param args.readlineInterface - The readline interface to use. Uses the
|
|
24
|
+
* global readline interface if none provided.
|
|
25
|
+
* @returns The user's input, or the default value if none provided.
|
|
26
|
+
*/
|
|
10
27
|
export declare function prompt({ question, defaultValue, shouldClose, readlineInterface, }: PromptArgs): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Close the readline interface.
|
|
30
|
+
*
|
|
31
|
+
* @param readlineInterface - The readline interface to close. Uses the global
|
|
32
|
+
* readline interface if none provided.
|
|
33
|
+
* @throws If no readline interface is provided, and the global interface isn't
|
|
34
|
+
* open.
|
|
35
|
+
*/
|
|
11
36
|
export declare function closePrompt(readlineInterface?: readline.Interface): void;
|
|
12
37
|
export {};
|
package/dist/utils/readline.js
CHANGED
|
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.closePrompt = exports.prompt = exports.openPrompt = void 0;
|
|
7
7
|
const readline_1 = __importDefault(require("readline"));
|
|
8
8
|
let singletonReadlineInterface;
|
|
9
|
+
/**
|
|
10
|
+
* Open a readline interface, to prompt for user input. Avoid using this
|
|
11
|
+
* function directly. Use the {@link prompt} function instead.
|
|
12
|
+
*/
|
|
9
13
|
function openPrompt() {
|
|
10
14
|
singletonReadlineInterface = readline_1.default.createInterface({
|
|
11
15
|
input: process.stdin,
|
|
@@ -13,6 +17,19 @@ function openPrompt() {
|
|
|
13
17
|
});
|
|
14
18
|
}
|
|
15
19
|
exports.openPrompt = openPrompt;
|
|
20
|
+
/**
|
|
21
|
+
* Prompt for user input on the command line. If the prompt isn't open, it will
|
|
22
|
+
* be opened.
|
|
23
|
+
*
|
|
24
|
+
* @param args - The prompt arguments.
|
|
25
|
+
* @param args.question - The question to ask.
|
|
26
|
+
* @param args.defaultValue - The default value to use, if no answer is provided.
|
|
27
|
+
* @param args.shouldClose - Whether to close the readline interface after
|
|
28
|
+
* prompting.
|
|
29
|
+
* @param args.readlineInterface - The readline interface to use. Uses the
|
|
30
|
+
* global readline interface if none provided.
|
|
31
|
+
* @returns The user's input, or the default value if none provided.
|
|
32
|
+
*/
|
|
16
33
|
function prompt({ question, defaultValue, shouldClose, readlineInterface = singletonReadlineInterface, }) {
|
|
17
34
|
let _readlineInterface = readlineInterface;
|
|
18
35
|
if (!_readlineInterface) {
|
|
@@ -38,6 +55,14 @@ function prompt({ question, defaultValue, shouldClose, readlineInterface = singl
|
|
|
38
55
|
});
|
|
39
56
|
}
|
|
40
57
|
exports.prompt = prompt;
|
|
58
|
+
/**
|
|
59
|
+
* Close the readline interface.
|
|
60
|
+
*
|
|
61
|
+
* @param readlineInterface - The readline interface to close. Uses the global
|
|
62
|
+
* readline interface if none provided.
|
|
63
|
+
* @throws If no readline interface is provided, and the global interface isn't
|
|
64
|
+
* open.
|
|
65
|
+
*/
|
|
41
66
|
function closePrompt(readlineInterface = singletonReadlineInterface) {
|
|
42
67
|
if (readlineInterface) {
|
|
43
68
|
readlineInterface.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readline.js","sourceRoot":"","sources":["../../src/utils/readline.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAEhC,IAAI,0BAA8C,CAAC;AASnD,SAAgB,UAAU;IACxB,0BAA0B,GAAG,kBAAQ,CAAC,eAAe,CAAC;QACpD,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC;AALD,gCAKC;AAED,SAAgB,MAAM,CAAC,EACrB,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,iBAAiB,GAAG,0BAA0B,GACnC;IACX,IAAI,kBAAkB,GAAG,iBAAiB,CAAC;IAC3C,IAAI,CAAC,kBAAkB,EAAE;QACvB,UAAU,EAAE,CAAC;QACb,kBAAkB,GAAG,0BAA0B,CAAC;KACjD;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,IAAI,WAAW,GAAG,GAAG,QAAQ,GAAG,CAAC;QACjC,IAAI,YAAY,EAAE;YAChB,WAAW,IAAI,IAAI,YAAY,IAAI,CAAC;SACrC;QAED,kBAAkB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,MAAc,EAAE,EAAE;YAC1D,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE;gBAC7B,IAAI,YAAY,KAAK,SAAS,EAAE;oBAC9B,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvB;aACF;YACD,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YACvB,IAAI,WAAW,EAAE;gBACf,kBAAkB,CAAC,KAAK,EAAE,CAAC;aAC5B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA9BD,wBA8BC;AAED,SAAgB,WAAW,CACzB,iBAAiB,GAAG,0BAA0B;IAE9C,IAAI,iBAAiB,EAAE;QACrB,iBAAiB,CAAC,KAAK,EAAE,CAAC;KAC3B;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;KACvE;AACH,CAAC;AARD,kCAQC","sourcesContent":["import readline from 'readline';\n\nlet singletonReadlineInterface: readline.Interface;\n\ntype PromptArgs = {\n question: string;\n defaultValue?: string;\n shouldClose?: boolean;\n readlineInterface?: readline.Interface;\n};\n\nexport function openPrompt(): void {\n singletonReadlineInterface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n}\n\nexport function prompt({\n question,\n defaultValue,\n shouldClose,\n readlineInterface = singletonReadlineInterface,\n}: PromptArgs): Promise<string> {\n let _readlineInterface = readlineInterface;\n if (!_readlineInterface) {\n openPrompt();\n _readlineInterface = singletonReadlineInterface;\n }\n\n return new Promise((resolve, _reject) => {\n let queryString = `${question} `;\n if (defaultValue) {\n queryString += `(${defaultValue}) `;\n }\n\n _readlineInterface.question(queryString, (answer: string) => {\n if (!answer || !answer.trim()) {\n if (defaultValue !== undefined) {\n resolve(defaultValue);\n }\n }\n resolve(answer.trim());\n if (shouldClose) {\n _readlineInterface.close();\n }\n });\n });\n}\n\nexport function closePrompt(\n readlineInterface = singletonReadlineInterface,\n): void {\n if (readlineInterface) {\n readlineInterface.close();\n } else {\n throw new Error('You are attempting to close a non existent prompt.');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"readline.js","sourceRoot":"","sources":["../../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AiB,CAAC,KAAK,EAAE,CAAC;KAC3B;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;KACvE;AACH,CAAC;AARD,kCAQC","sourcesContent":["import readline from 'readline';\n\nlet singletonReadlineInterface: readline.Interface;\n\ntype PromptArgs = {\n question: string;\n defaultValue?: string;\n shouldClose?: boolean;\n readlineInterface?: readline.Interface;\n};\n\n/**\n * Open a readline interface, to prompt for user input. Avoid using this\n * function directly. Use the {@link prompt} function instead.\n */\nexport function openPrompt(): void {\n singletonReadlineInterface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n}\n\n/**\n * Prompt for user input on the command line. If the prompt isn't open, it will\n * be opened.\n *\n * @param args - The prompt arguments.\n * @param args.question - The question to ask.\n * @param args.defaultValue - The default value to use, if no answer is provided.\n * @param args.shouldClose - Whether to close the readline interface after\n * prompting.\n * @param args.readlineInterface - The readline interface to use. Uses the\n * global readline interface if none provided.\n * @returns The user's input, or the default value if none provided.\n */\nexport function prompt({\n question,\n defaultValue,\n shouldClose,\n readlineInterface = singletonReadlineInterface,\n}: PromptArgs): Promise<string> {\n let _readlineInterface = readlineInterface;\n if (!_readlineInterface) {\n openPrompt();\n _readlineInterface = singletonReadlineInterface;\n }\n\n return new Promise((resolve, _reject) => {\n let queryString = `${question} `;\n if (defaultValue) {\n queryString += `(${defaultValue}) `;\n }\n\n _readlineInterface.question(queryString, (answer: string) => {\n if (!answer || !answer.trim()) {\n if (defaultValue !== undefined) {\n resolve(defaultValue);\n }\n }\n resolve(answer.trim());\n if (shouldClose) {\n _readlineInterface.close();\n }\n });\n });\n}\n\n/**\n * Close the readline interface.\n *\n * @param readlineInterface - The readline interface to close. Uses the global\n * readline interface if none provided.\n * @throws If no readline interface is provided, and the global interface isn't\n * open.\n */\nexport function closePrompt(\n readlineInterface = singletonReadlineInterface,\n): void {\n if (readlineInterface) {\n readlineInterface.close();\n } else {\n throw new Error('You are attempting to close a non existent prompt.');\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="watchify" />
|
|
1
2
|
import type browserify from 'browserify';
|
|
2
3
|
import { Arguments } from 'yargs';
|
|
3
4
|
import yargs from 'yargs/yargs';
|
|
@@ -6,6 +7,15 @@ export declare type SnapConfig = {
|
|
|
6
7
|
cliOptions?: Record<string, unknown>;
|
|
7
8
|
bundlerCustomizer?: (bundler: browserify.BrowserifyObject) => void;
|
|
8
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Attempt to load the snap config file (`snap.config.js`). By default will use
|
|
12
|
+
* the cached config, if it was loaded before, and `cached` is `true`. If the
|
|
13
|
+
* config file is not found, or the config is invalid, this function will kill
|
|
14
|
+
* the process.
|
|
15
|
+
*
|
|
16
|
+
* @param cached - Whether to use the cached config. Defaults to `true`.
|
|
17
|
+
* @returns The snap config.
|
|
18
|
+
*/
|
|
9
19
|
export declare function loadConfig(cached?: boolean): SnapConfig;
|
|
10
20
|
/**
|
|
11
21
|
* Attempts to read configuration options for package.json and the config file,
|
|
@@ -13,5 +23,10 @@ export declare function loadConfig(cached?: boolean): SnapConfig;
|
|
|
13
23
|
*
|
|
14
24
|
* Arguments are only set per the snap-cli config file if they were not specified
|
|
15
25
|
* on the command line.
|
|
26
|
+
*
|
|
27
|
+
* @param snapConfig - The snap config.
|
|
28
|
+
* @param processArgv - The command line arguments, i.e., `process.argv`.
|
|
29
|
+
* @param yargsArgv - The processed `yargs` arguments.
|
|
30
|
+
* @param yargsInstance - An instance of `yargs`.
|
|
16
31
|
*/
|
|
17
32
|
export declare function applyConfig(snapConfig: SnapConfig, processArgv: string[], yargsArgv: Arguments, yargsInstance: typeof yargs): void;
|
|
@@ -5,11 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.applyConfig = exports.loadConfig = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const utils_1 = require("@metamask/utils");
|
|
8
9
|
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
9
10
|
const builders_1 = __importDefault(require("../builders"));
|
|
10
11
|
const misc_1 = require("./misc");
|
|
11
12
|
const snap_config___GENERATED__1 = require("./snap-config.__GENERATED__");
|
|
12
13
|
let snapConfigCache;
|
|
14
|
+
/**
|
|
15
|
+
* Attempt to load the snap config file (`snap.config.js`). By default will use
|
|
16
|
+
* the cached config, if it was loaded before, and `cached` is `true`. If the
|
|
17
|
+
* config file is not found, or the config is invalid, this function will kill
|
|
18
|
+
* the process.
|
|
19
|
+
*
|
|
20
|
+
* @param cached - Whether to use the cached config. Defaults to `true`.
|
|
21
|
+
* @returns The snap config.
|
|
22
|
+
*/
|
|
13
23
|
function loadConfig(cached = true) {
|
|
14
24
|
if (snapConfigCache !== undefined && cached === true) {
|
|
15
25
|
return snapConfigCache;
|
|
@@ -35,7 +45,7 @@ function loadConfig(cached = true) {
|
|
|
35
45
|
return config;
|
|
36
46
|
}
|
|
37
47
|
exports.loadConfig = loadConfig;
|
|
38
|
-
// Note that the below function is necessary because
|
|
48
|
+
// Note that the below function is necessary because yargs' .config() function
|
|
39
49
|
// leaves much to be desired.
|
|
40
50
|
//
|
|
41
51
|
// In particular, it will set all properties included in the config file
|
|
@@ -46,6 +56,11 @@ exports.loadConfig = loadConfig;
|
|
|
46
56
|
*
|
|
47
57
|
* Arguments are only set per the snap-cli config file if they were not specified
|
|
48
58
|
* on the command line.
|
|
59
|
+
*
|
|
60
|
+
* @param snapConfig - The snap config.
|
|
61
|
+
* @param processArgv - The command line arguments, i.e., `process.argv`.
|
|
62
|
+
* @param yargsArgv - The processed `yargs` arguments.
|
|
63
|
+
* @param yargsInstance - An instance of `yargs`.
|
|
49
64
|
*/
|
|
50
65
|
function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
|
|
51
66
|
// Instances of yargs has a number of undocumented functions, including
|
|
@@ -66,12 +81,11 @@ function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
|
|
|
66
81
|
delete parsedProcessArgv._; // irrelevant yargs parser artifact
|
|
67
82
|
const commandOptions = new Set(Object.keys(options));
|
|
68
83
|
const shouldSetArg = (key) => {
|
|
69
|
-
return
|
|
70
|
-
!Object.prototype.hasOwnProperty.call(parsedProcessArgv, key));
|
|
84
|
+
return commandOptions.has(key) && !(0, utils_1.hasProperty)(parsedProcessArgv, key);
|
|
71
85
|
};
|
|
72
86
|
const cfg = snapConfig.cliOptions || {};
|
|
73
87
|
for (const key of Object.keys(cfg)) {
|
|
74
|
-
if (
|
|
88
|
+
if ((0, utils_1.hasProperty)(builders_1.default, key)) {
|
|
75
89
|
if (shouldSetArg(key)) {
|
|
76
90
|
yargsArgv[key] = cfg[key];
|
|
77
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;
|
|
1
|
+
{"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,2CAA8C;AAG9C,gEAAsC;AAEtC,2DAAmC;AACnC,iCAA+C;AAC/C,0EAA2D;AAQ3D,IAAI,eAAuC,CAAC;AAE5C;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAC,MAAM,GAAG,IAAI;IACtC,IAAI,eAAe,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE;QACpD,OAAO,eAAe,CAAC;KACxB;IAED,IAAI,MAAW,CAAC;IAChB,IAAI;QACF,iHAAiH;QACjH,MAAM,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,kBAAW,CAAC,CAAC,CAAC;KAC5D;IAAC,OAAO,GAAQ,EAAE;QACjB,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACnC,eAAe,GAAG,EAAE,CAAC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AG,CAAC,CAAC;IACzE,CAAC,CAAC;IAEF,MAAM,GAAG,GAA4B,UAAU,CAAC,UAAU,IAAI,EAAE,CAAC;IACjE,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAClC,IAAI,IAAA,mBAAW,EAAC,kBAAQ,EAAE,GAAG,CAAC,EAAE;YAC9B,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE;gBACrB,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;aAC3B;SACF;aAAM;YACL,IAAA,eAAQ,EACN,4DAA4D,GAAG,qBAAqB,kBAAW,uCAAuC,CACvI,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;KACF;AACH,CAAC;AAhDD,kCAgDC","sourcesContent":["import path from 'path';\nimport { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\nimport { isSnapConfig } from './snap-config.__GENERATED__';\n\n/** @see {isSnapConfig} ts-auto-guard:type-guard */\nexport type SnapConfig = {\n cliOptions?: Record<string, unknown>;\n bundlerCustomizer?: (bundler: browserify.BrowserifyObject) => void;\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 === true) {\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 (err: any) {\n if (err.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, err);\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 cfg: Record<string, unknown> = snapConfig.cliOptions || {};\n for (const key of Object.keys(cfg)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = cfg[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"]}
|
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gets the complete out file path from
|
|
2
|
+
* Gets the complete out file path from an output file name and parent
|
|
3
3
|
* directory path.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @returns
|
|
5
|
+
* @param outDir - The path to the out file's parent directory.
|
|
6
|
+
* @param outFileName - The out file's name.
|
|
7
|
+
* @returns The complete path to the out file.
|
|
8
8
|
*/
|
|
9
9
|
export declare function getOutfilePath(outDir: string, outFileName: string): string;
|
|
10
10
|
/**
|
|
11
|
-
* Ensures that the outfile name is just a js file name.
|
|
12
|
-
* Throws on validation failure
|
|
11
|
+
* Ensures that the outfile name is just a `.js` file name.
|
|
12
|
+
* Throws on validation failure.
|
|
13
13
|
*
|
|
14
|
-
* @param filename - The file name to validate
|
|
15
|
-
* @returns
|
|
14
|
+
* @param filename - The file name to validate.
|
|
15
|
+
* @returns `true` if validation succeeded.
|
|
16
|
+
* @throws If the file name is invalid.
|
|
16
17
|
*/
|
|
17
18
|
export declare function validateOutfileName(filename: string): boolean;
|
|
18
19
|
/**
|
|
19
|
-
* Validates a file path.
|
|
20
|
-
* Throws on validation failure
|
|
20
|
+
* Validates a file path. Throws on validation failure.
|
|
21
21
|
*
|
|
22
|
-
* @param filePath - The file path to validate
|
|
23
|
-
* @returns
|
|
22
|
+
* @param filePath - The file path to validate.
|
|
23
|
+
* @returns `true` if validation succeeded.
|
|
24
|
+
* @throws If the path does not resolve to a file.
|
|
24
25
|
*/
|
|
25
26
|
export declare function validateFilePath(filePath: string): Promise<boolean>;
|
|
26
27
|
/**
|
|
27
|
-
* Validates a directory path.
|
|
28
|
-
* Throws on validation failure.
|
|
28
|
+
* Validates a directory path. Throws on validation failure.
|
|
29
29
|
*
|
|
30
|
-
* @param dirPath - The directory path to validate
|
|
31
|
-
* @param createDir - Whether to create the directory if it doesn't exist
|
|
32
|
-
* @returns
|
|
30
|
+
* @param dirPath - The directory path to validate.
|
|
31
|
+
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
32
|
+
* @returns `true` if validation succeeded or the directory was created.
|
|
33
|
+
* @throws If the directory does not exist or could not be created.
|
|
33
34
|
*/
|
|
34
|
-
export declare function validateDirPath(
|
|
35
|
+
export declare function validateDirPath(dirPath: string, createDir: boolean): Promise<boolean>;
|
|
@@ -7,23 +7,24 @@ exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = require("./fs");
|
|
9
9
|
/**
|
|
10
|
-
* Gets the complete out file path from
|
|
10
|
+
* Gets the complete out file path from an output file name and parent
|
|
11
11
|
* directory path.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @returns
|
|
13
|
+
* @param outDir - The path to the out file's parent directory.
|
|
14
|
+
* @param outFileName - The out file's name.
|
|
15
|
+
* @returns The complete path to the out file.
|
|
16
16
|
*/
|
|
17
17
|
function getOutfilePath(outDir, outFileName) {
|
|
18
18
|
return path_1.default.join(outDir, outFileName || 'bundle.js');
|
|
19
19
|
}
|
|
20
20
|
exports.getOutfilePath = getOutfilePath;
|
|
21
21
|
/**
|
|
22
|
-
* Ensures that the outfile name is just a js file name.
|
|
23
|
-
* Throws on validation failure
|
|
22
|
+
* Ensures that the outfile name is just a `.js` file name.
|
|
23
|
+
* Throws on validation failure.
|
|
24
24
|
*
|
|
25
|
-
* @param filename - The file name to validate
|
|
26
|
-
* @returns
|
|
25
|
+
* @param filename - The file name to validate.
|
|
26
|
+
* @returns `true` if validation succeeded.
|
|
27
|
+
* @throws If the file name is invalid.
|
|
27
28
|
*/
|
|
28
29
|
function validateOutfileName(filename) {
|
|
29
30
|
if (!filename.endsWith('.js') ||
|
|
@@ -35,11 +36,11 @@ function validateOutfileName(filename) {
|
|
|
35
36
|
}
|
|
36
37
|
exports.validateOutfileName = validateOutfileName;
|
|
37
38
|
/**
|
|
38
|
-
* Validates a file path.
|
|
39
|
-
* Throws on validation failure
|
|
39
|
+
* Validates a file path. Throws on validation failure.
|
|
40
40
|
*
|
|
41
|
-
* @param filePath - The file path to validate
|
|
42
|
-
* @returns
|
|
41
|
+
* @param filePath - The file path to validate.
|
|
42
|
+
* @returns `true` if validation succeeded.
|
|
43
|
+
* @throws If the path does not resolve to a file.
|
|
43
44
|
*/
|
|
44
45
|
async function validateFilePath(filePath) {
|
|
45
46
|
const exists = await (0, fs_1.isFile)(filePath);
|
|
@@ -50,17 +51,17 @@ async function validateFilePath(filePath) {
|
|
|
50
51
|
}
|
|
51
52
|
exports.validateFilePath = validateFilePath;
|
|
52
53
|
/**
|
|
53
|
-
* Validates a directory path.
|
|
54
|
-
* Throws on validation failure.
|
|
54
|
+
* Validates a directory path. Throws on validation failure.
|
|
55
55
|
*
|
|
56
|
-
* @param dirPath - The directory path to validate
|
|
57
|
-
* @param createDir - Whether to create the directory if it doesn't exist
|
|
58
|
-
* @returns
|
|
56
|
+
* @param dirPath - The directory path to validate.
|
|
57
|
+
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
58
|
+
* @returns `true` if validation succeeded or the directory was created.
|
|
59
|
+
* @throws If the directory does not exist or could not be created.
|
|
59
60
|
*/
|
|
60
|
-
async function validateDirPath(
|
|
61
|
-
const exists = await (0, fs_1.isDirectory)(
|
|
61
|
+
async function validateDirPath(dirPath, createDir) {
|
|
62
|
+
const exists = await (0, fs_1.isDirectory)(dirPath, createDir);
|
|
62
63
|
if (!exists) {
|
|
63
|
-
throw new Error(`Invalid params: '${
|
|
64
|
+
throw new Error(`Invalid params: '${dirPath}' is not a directory or could not be created.`);
|
|
64
65
|
}
|
|
65
66
|
return true;
|
|
66
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-fs.js","sourceRoot":"","sources":["../../src/utils/validate-fs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,6BAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,WAAmB;IAChE,OAAO,cAAS,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,IAAI,WAAW,CAAC,CAAC;AAC5D,CAAC;AAFD,wCAEC;AAED
|
|
1
|
+
{"version":3,"file":"validate-fs.js","sourceRoot":"","sources":["../../src/utils/validate-fs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,6BAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,WAAmB;IAChE,OAAO,cAAS,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,IAAI,WAAW,CAAC,CAAC;AAC5D,CAAC;AAFD,wCAEC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QACzB,QAAQ,KAAK,KAAK;QAClB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAC5B;QACA,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,sBAAsB,CAAC,CAAC;KAC1E;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AATD,kDASC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IACrD,MAAM,MAAM,GAAG,MAAM,IAAA,WAAM,EAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,QAAQ,oCAAoC,CACjE,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AARD,4CAQC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAW,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,+CAA+C,CAC3E,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,0CAWC","sourcesContent":["import pathUtils from 'path';\nimport { isFile, isDirectory } from './fs';\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n filename.indexOf('/') !== -1\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"dist/"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"setup": "yarn install && yarn allow-scripts",
|
|
18
17
|
"shasum": "node ./scripts/computeSnapShasum.js",
|
|
19
18
|
"build:init-template": "node ./scripts/createInitTemplate.js && yarn prettier --check src/cmds/init/init-template.json",
|
|
20
19
|
"build:guards": "ts-auto-guard --guard-file-name=__GENERATED__ ./src/utils/snap-config.ts",
|
|
@@ -26,7 +25,7 @@
|
|
|
26
25
|
"build:post-tsc": "yarn build:chmod && yarn build:readme",
|
|
27
26
|
"build:clean": "yarn clean && yarn build",
|
|
28
27
|
"build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
|
|
29
|
-
"clean": "rimraf *.tsbuildinfo dist/* src/**/*__GENERATED__*",
|
|
28
|
+
"clean": "rimraf '*.tsbuildinfo' 'dist/*' 'src/**/*__GENERATED__*'",
|
|
30
29
|
"test": "yarn build:init-template && jest",
|
|
31
30
|
"posttest": "jest-it-up",
|
|
32
31
|
"test:watch": "yarn test --watch",
|
|
@@ -36,7 +35,7 @@
|
|
|
36
35
|
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
|
|
37
36
|
"lint": "yarn lint:eslint && yarn lint:misc --check",
|
|
38
37
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
39
|
-
"publish": "../../scripts/publish-package.sh"
|
|
38
|
+
"publish:package": "../../scripts/publish-package.sh"
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
41
|
"@babel/core": "^7.16.7",
|
|
@@ -46,13 +45,13 @@
|
|
|
46
45
|
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
|
|
47
46
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
48
47
|
"@babel/preset-env": "^7.16.7",
|
|
49
|
-
"@
|
|
50
|
-
"@metamask/snap-controllers": "^0.
|
|
51
|
-
"@metamask/snaps-browserify-plugin": "^0.
|
|
48
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
49
|
+
"@metamask/snap-controllers": "^0.17.0",
|
|
50
|
+
"@metamask/snaps-browserify-plugin": "^0.17.0",
|
|
51
|
+
"@metamask/utils": "^2.0.0",
|
|
52
52
|
"babelify": "^10.0.0",
|
|
53
53
|
"browserify": "^17.0.0",
|
|
54
|
-
"chokidar": "^3.
|
|
55
|
-
"fast-deep-equal": "^2.0.1",
|
|
54
|
+
"chokidar": "^3.5.2",
|
|
56
55
|
"init-package-json": "^1.10.3",
|
|
57
56
|
"is-url": "^1.2.4",
|
|
58
57
|
"mkdirp": "^1.0.4",
|
|
@@ -64,16 +63,16 @@
|
|
|
64
63
|
"yargs-parser": "^20.2.2"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
67
|
-
"@lavamoat/allow-scripts": "^
|
|
68
|
-
"@metamask/auto-changelog": "^2.
|
|
69
|
-
"@metamask/eslint-config": "^
|
|
70
|
-
"@metamask/eslint-config-jest": "^
|
|
71
|
-
"@metamask/eslint-config-nodejs": "^
|
|
72
|
-
"@metamask/eslint-config-typescript": "^
|
|
66
|
+
"@lavamoat/allow-scripts": "^2.0.3",
|
|
67
|
+
"@metamask/auto-changelog": "^2.6.0",
|
|
68
|
+
"@metamask/eslint-config": "^9.0.0",
|
|
69
|
+
"@metamask/eslint-config-jest": "^9.0.0",
|
|
70
|
+
"@metamask/eslint-config-nodejs": "^9.0.0",
|
|
71
|
+
"@metamask/eslint-config-typescript": "^9.0.1",
|
|
73
72
|
"@types/browserify": "^12.0.36",
|
|
74
73
|
"@types/init-package-json": "^1.10.0",
|
|
75
74
|
"@types/is-url": "^1.2.28",
|
|
76
|
-
"@types/jest": "^
|
|
75
|
+
"@types/jest": "^27.5.1",
|
|
77
76
|
"@types/mkdirp": "^1.0.2",
|
|
78
77
|
"@types/node": "^14.14.25",
|
|
79
78
|
"@types/rimraf": "^3.0.0",
|
|
@@ -86,22 +85,24 @@
|
|
|
86
85
|
"eslint-config-prettier": "^8.3.0",
|
|
87
86
|
"eslint-plugin-import": "^2.23.4",
|
|
88
87
|
"eslint-plugin-jest": "^24.4.0",
|
|
88
|
+
"eslint-plugin-jsdoc": "^36.1.0",
|
|
89
89
|
"eslint-plugin-node": "^11.1.0",
|
|
90
90
|
"eslint-plugin-prettier": "^3.4.0",
|
|
91
91
|
"execa": "^5.1.1",
|
|
92
|
-
"jest": "^
|
|
92
|
+
"jest": "^27.5.1",
|
|
93
93
|
"jest-it-up": "^2.0.0",
|
|
94
94
|
"patch-package": "^6.4.7",
|
|
95
95
|
"prettier": "^2.3.2",
|
|
96
|
+
"prettier-plugin-packagejson": "^2.2.11",
|
|
96
97
|
"rimraf": "^3.0.2",
|
|
97
98
|
"ts-auto-guard": "^2.3.0",
|
|
98
|
-
"ts-jest": "^
|
|
99
|
+
"ts-jest": "^27.1.5",
|
|
99
100
|
"ts-node": "^9.1.1",
|
|
100
101
|
"tsc-watch": "^4.5.0",
|
|
101
102
|
"typescript": "^4.4.0"
|
|
102
103
|
},
|
|
103
104
|
"engines": {
|
|
104
|
-
"node": ">=
|
|
105
|
+
"node": ">=16.0.0"
|
|
105
106
|
},
|
|
106
107
|
"publishConfig": {
|
|
107
108
|
"access": "public",
|