@metamask/snaps-cli 0.22.3 → 0.24.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 +6 -6
- package/dist/builders.d.ts +2 -6
- package/dist/builders.js +3 -12
- package/dist/builders.js.map +1 -1
- package/dist/cmds/build/buildHandler.js +5 -5
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/eval/evalHandler.js +3 -5
- package/dist/cmds/eval/evalHandler.js.map +1 -1
- package/dist/cmds/init/index.js +3 -13
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/initHandler.d.ts +5 -9
- package/dist/cmds/init/initHandler.js +37 -96
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +25 -32
- package/dist/cmds/init/initUtils.js +80 -250
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/manifestHandler.js +2 -2
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/serve/serveHandler.js +2 -2
- package/dist/cmds/serve/serveHandler.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +5 -5
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/misc.d.ts +1 -1
- package/dist/utils/misc.js +6 -1
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/snap-config.d.ts +21 -4
- package/dist/utils/snap-config.js +20 -3
- package/dist/utils/snap-config.js.map +1 -1
- package/package.json +13 -19
- package/dist/cmds/init/init-template.json +0 -8
- package/dist/tsconfig.json +0 -8
- package/dist/utils/readline.d.ts +0 -37
- package/dist/utils/readline.js +0 -75
- package/dist/utils/readline.js.map +0 -1
- package/dist/utils/snap-config.__GENERATED__.d.ts +0 -2
- package/dist/utils/snap-config.__GENERATED__.js +0 -18
- package/dist/utils/snap-config.__GENERATED__.js.map +0 -1
package/dist/utils/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AAExB,2CAA8C;AAGjC,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,WAAW,GAAG,gBAAgB,CAAC;AAE5C,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,KAAK;IACL,GAAG;IACH,MAAM;IACN,GAAG;IACH,QAAQ;IACR,GAAG;IACH,MAAM;IACN,GAAG;CACJ,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,IAAe;IAC5C,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAW,CAAC,EAAE;QAChD,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;KAChC;SAAM;QACL,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;KACjC;IAED,IAAI,IAAA,mBAAW,EAAC,IAAI,EAAE,eAAe,CAAC,EAAE;QACtC,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,sBAAsB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KACzE;IAED,IAAI,IAAA,mBAAW,EAAC,IAAI,EAAE,kBAAkB,CAAC,EAAE;QACzC,MAAM,CAAC,KAAK,CAAC,gBAAgB,GAAG,sBAAsB,CACpD,IAAI,CAAC,gBAAgB,CACtB,CAAC;KACH;AACH,CAAC;AAhBD,wCAgB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C","sourcesContent":["import { promises as filesystem } from 'fs';\nimport path from 'path';\n\nimport { hasProperty } from '@metamask/utils';\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: \"${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 | null, err?: Error): void {\n if (msg !== null) {\n console.error(msg);\n }\n\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n\n if (msg === null && (!err || (err && !global.snaps.verboseErrors))) {\n console.error('Unknown error.');\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-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"]}
|
|
@@ -2,11 +2,28 @@
|
|
|
2
2
|
import type browserify from 'browserify';
|
|
3
3
|
import { Arguments } from 'yargs';
|
|
4
4
|
import yargs from 'yargs/yargs';
|
|
5
|
-
|
|
6
|
-
export declare type
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import { Infer } from 'superstruct';
|
|
6
|
+
export declare type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;
|
|
7
|
+
export declare const SnapConfigStruct: import("superstruct").Struct<{
|
|
8
|
+
cliOptions?: Record<string, unknown> | undefined;
|
|
9
|
+
bundlerCustomizer?: Function | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
cliOptions: import("superstruct").Struct<Record<string, unknown> | undefined, null>;
|
|
12
|
+
bundlerCustomizer: import("superstruct").Struct<Function | undefined, null>;
|
|
13
|
+
}>;
|
|
14
|
+
export declare type SnapConfig = Omit<Infer<typeof SnapConfigStruct>, 'bundlerCustomizer'> & {
|
|
15
|
+
bundlerCustomizer?: BundleCustomizer;
|
|
9
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Check if the given value is a {@link SnapConfig} object. Note that this
|
|
19
|
+
* function does not check the validity of the `bundleCustomizer` property, as
|
|
20
|
+
* it is not possible to check the validity of a function in JavaScript.
|
|
21
|
+
*
|
|
22
|
+
* @param value - The value to check.
|
|
23
|
+
* @returns `true` if the value is a valid {@link SnapConfig} object, `false`
|
|
24
|
+
* otherwise.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isSnapConfig(value: unknown): value is SnapConfig;
|
|
10
27
|
/**
|
|
11
28
|
* Attempt to load the snap config file (`snap.config.js`). By default will use
|
|
12
29
|
* the cached config, if it was loaded before, and `cached` is `true`. If the
|
|
@@ -3,13 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.applyConfig = exports.loadConfig = void 0;
|
|
6
|
+
exports.applyConfig = exports.loadConfig = exports.isSnapConfig = exports.SnapConfigStruct = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const utils_1 = require("@metamask/utils");
|
|
9
9
|
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
10
|
+
const superstruct_1 = require("superstruct");
|
|
10
11
|
const builders_1 = __importDefault(require("../builders"));
|
|
11
12
|
const misc_1 = require("./misc");
|
|
12
|
-
|
|
13
|
+
exports.SnapConfigStruct = (0, superstruct_1.object)({
|
|
14
|
+
cliOptions: (0, superstruct_1.optional)((0, superstruct_1.object)()),
|
|
15
|
+
bundlerCustomizer: (0, superstruct_1.optional)((0, superstruct_1.func)()),
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Check if the given value is a {@link SnapConfig} object. Note that this
|
|
19
|
+
* function does not check the validity of the `bundleCustomizer` property, as
|
|
20
|
+
* it is not possible to check the validity of a function in JavaScript.
|
|
21
|
+
*
|
|
22
|
+
* @param value - The value to check.
|
|
23
|
+
* @returns `true` if the value is a valid {@link SnapConfig} object, `false`
|
|
24
|
+
* otherwise.
|
|
25
|
+
*/
|
|
26
|
+
function isSnapConfig(value) {
|
|
27
|
+
return (0, superstruct_1.is)(value, exports.SnapConfigStruct);
|
|
28
|
+
}
|
|
29
|
+
exports.isSnapConfig = isSnapConfig;
|
|
13
30
|
let snapConfigCache;
|
|
14
31
|
/**
|
|
15
32
|
* Attempt to load the snap config file (`snap.config.js`). By default will use
|
|
@@ -37,7 +54,7 @@ function loadConfig(cached = true) {
|
|
|
37
54
|
(0, misc_1.logError)(`Error during parsing of ${misc_1.CONFIG_FILE}`, err);
|
|
38
55
|
return process.exit(1);
|
|
39
56
|
}
|
|
40
|
-
if (!
|
|
57
|
+
if (!isSnapConfig(config)) {
|
|
41
58
|
(0, misc_1.logError)(`Can't validate ${misc_1.CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
|
|
42
59
|
return process.exit(1);
|
|
43
60
|
}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,2CAA8C;AAG9C,gEAAsC;AAEtC,6CAAgE;AAChE,2DAAmC;AACnC,iCAA+C;AAIlC,QAAA,gBAAgB,GAAG,IAAA,oBAAM,EAAC;IACrC,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC9B,iBAAiB,EAAE,IAAA,sBAAQ,EAAC,IAAA,kBAAI,GAAE,CAAC;CACpC,CAAC,CAAC;AASH;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,wBAAgB,CAAC,CAAC;AACrC,CAAC;AAFD,oCAEC;AAED,IAAI,eAAuC,CAAC;AAE5C;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAC,MAAM,GAAG,IAAI;IACtC,IAAI,eAAe,KAAK,SAAS,IAAI,MAAM,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;YACrB,OAAO,eAAe,CAAC;SACxB;QACD,IAAA,eAAQ,EAAC,2BAA2B,kBAAW,EAAE,EAAE,GAAG,CAAC,CAAC;QACxD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC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E;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 { object, optional, func, Infer, is } from 'superstruct';\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 === 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,18 +15,15 @@
|
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"shasum": "node ./scripts/computeSnapShasum.js",
|
|
18
|
-
"build:
|
|
19
|
-
"build:guards": "ts-auto-guard --guard-file-name=__GENERATED__ ./src/utils/snap-config.ts",
|
|
20
|
-
"build:tsc": "tsc --project ./tsconfig.local.json",
|
|
18
|
+
"build:tsc": "tsc --project ./tsconfig.build.json",
|
|
21
19
|
"build:chmod": "chmod +x ./dist/main.js",
|
|
22
20
|
"build:readme": "node ./scripts/updateReadme.js",
|
|
23
|
-
"build": "yarn build:
|
|
24
|
-
"build:pre-tsc": "yarn build:init-template && yarn build:guards",
|
|
21
|
+
"build": "yarn build:tsc && yarn build:post-tsc",
|
|
25
22
|
"build:post-tsc": "yarn build:chmod && yarn build:readme",
|
|
26
23
|
"build:clean": "yarn clean && yarn build",
|
|
27
24
|
"build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
|
|
28
|
-
"clean": "rimraf '*.tsbuildinfo' 'dist/*'
|
|
29
|
-
"test": "
|
|
25
|
+
"clean": "rimraf '*.tsbuildinfo' 'dist/*'",
|
|
26
|
+
"test": "jest && yarn posttest",
|
|
30
27
|
"posttest": "jest-it-up",
|
|
31
28
|
"test:watch": "yarn test --watch",
|
|
32
29
|
"test:ci": "yarn test",
|
|
@@ -46,18 +43,16 @@
|
|
|
46
43
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
47
44
|
"@babel/preset-env": "^7.16.7",
|
|
48
45
|
"@babel/preset-typescript": "^7.16.7",
|
|
49
|
-
"@metamask/
|
|
50
|
-
"@metamask/snaps-
|
|
51
|
-
"@metamask/utils": "^3.1
|
|
46
|
+
"@metamask/snaps-browserify-plugin": "^0.24.0",
|
|
47
|
+
"@metamask/snaps-utils": "^0.24.0",
|
|
48
|
+
"@metamask/utils": "^3.3.1",
|
|
52
49
|
"babelify": "^10.0.0",
|
|
53
50
|
"browserify": "^17.0.0",
|
|
54
51
|
"chokidar": "^3.5.2",
|
|
55
|
-
"init-package-json": "^1.10.3",
|
|
56
52
|
"is-url": "^1.2.4",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"slash": "^3.0.0",
|
|
53
|
+
"serve-handler": "^6.1.5",
|
|
54
|
+
"ses": "^0.17.0",
|
|
55
|
+
"superstruct": "^0.16.7",
|
|
61
56
|
"yargs": "^16.2.0",
|
|
62
57
|
"yargs-parser": "^20.2.2"
|
|
63
58
|
},
|
|
@@ -69,10 +64,8 @@
|
|
|
69
64
|
"@metamask/eslint-config-nodejs": "^9.0.0",
|
|
70
65
|
"@metamask/eslint-config-typescript": "^9.0.1",
|
|
71
66
|
"@types/browserify": "^12.0.36",
|
|
72
|
-
"@types/init-package-json": "^1.10.0",
|
|
73
67
|
"@types/is-url": "^1.2.28",
|
|
74
68
|
"@types/jest": "^27.5.1",
|
|
75
|
-
"@types/mkdirp": "^1.0.2",
|
|
76
69
|
"@types/node": "^14.14.25",
|
|
77
70
|
"@types/rimraf": "^3.0.0",
|
|
78
71
|
"@types/serve-handler": "^6.1.0",
|
|
@@ -80,6 +73,7 @@
|
|
|
80
73
|
"@typescript-eslint/eslint-plugin": "^5.19.0",
|
|
81
74
|
"@typescript-eslint/parser": "^5.19.0",
|
|
82
75
|
"clipboardy": "^2.3.0",
|
|
76
|
+
"deepmerge": "^4.2.2",
|
|
83
77
|
"eslint": "^7.30.0",
|
|
84
78
|
"eslint-config-prettier": "^8.3.0",
|
|
85
79
|
"eslint-plugin-import": "^2.23.4",
|
|
@@ -90,10 +84,10 @@
|
|
|
90
84
|
"execa": "^5.1.1",
|
|
91
85
|
"jest": "^29.0.2",
|
|
92
86
|
"jest-it-up": "^2.0.0",
|
|
87
|
+
"memfs": "^3.4.10",
|
|
93
88
|
"prettier": "^2.3.2",
|
|
94
89
|
"prettier-plugin-packagejson": "^2.2.11",
|
|
95
90
|
"rimraf": "^3.0.2",
|
|
96
|
-
"ts-auto-guard": "^2.3.0",
|
|
97
91
|
"ts-jest": "^29.0.0",
|
|
98
92
|
"ts-node": "^10.7.0",
|
|
99
93
|
"tsc-watch": "^4.5.0",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"html": "<!doctype html>\n<html>\n <head>\n <title>Hello, Snaps!</title>\n <link rel=\"icon\" type=\"image/svg\" href=\"./images/icon.svg\"/>\n </head>\n\n <body>\n <h1>Hello, Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The <code>snap.manifest.json</code> and <code>package.json</code> must be located in the server root directory..\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by the <code>location</code> field of <code>snap.manifest.json</code>.\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n const snapId = `local:${window.location.href}`;\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the snap\n async function connect () {\n await ethereum.request({\n method: 'wallet_enable',\n params: [{\n wallet_snap: { [snapId]: {} },\n }]\n })\n }\n\n // here we call the snap's \"hello\" method\n async function send () {\n try {\n const response = await ethereum.request({\n method: 'wallet_invokeSnap',\n params: [snapId, {\n method: 'hello'\n }]\n })\n } catch (err) {\n console.error(err)\n alert('Problem happened: ' + err.message || err)\n }\n }\n </script>\n</html>\n",
|
|
3
|
-
"source": "module.exports.onRpcRequest = async ({ origin, request }) => {\n switch (request.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [\n {\n prompt: `Hello, ${origin}!`,\n description:\n 'This custom confirmation is just for display purposes.',\n textAreaContent:\n 'But you can edit the snap source code to make it do something, if you want to!',\n },\n ],\n });\n default:\n throw new Error('Method not found.');\n }\n};\n",
|
|
4
|
-
"typescriptHtml": "<!doctype html>\n<html>\n </head>\n <title>Hello, Snaps!</title>\n <link rel=\"icon\" type=\"image/svg\" href=\"./images/icon.svg\"/>\n </head>\n\n <body>\n <h1>Hello, Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The <code>snap.manifest.json</code> and <code>package.json</code> must be located in the server root directory...\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by the <code>location</code> field of <code>snap.manifest.json</code>.\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n const snapId = `local:${window.location.href}`;\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the snap\n async function connect () {\n await ethereum.request({\n method: 'wallet_enable',\n params: [{\n wallet_snap: { [snapId]: {} },\n }]\n })\n }\n\n // here we call the snap's \"hello\" method\n async function send () {\n try {\n await ethereum.request({\n method: 'wallet_invokeSnap',\n params: [snapId, {\n method: 'hello'\n }]\n })\n } catch (err) {\n console.error(err)\n alert('Problem happened: ' + err.message || err)\n }\n }\n </script>\n</html>\n",
|
|
5
|
-
"typescriptSource": "import { OnRpcRequestHandler } from '@metamask/snap-types';\n\nexport const onRpcRequest: OnRpcRequestHandler = ({ origin, request }) => {\n switch (request.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [\n {\n prompt: `Hello, ${origin}!`,\n description:\n 'This custom confirmation is just for display purposes.',\n textAreaContent:\n 'But you can edit the snap source code to make it do something, if you want to!',\n },\n ],\n });\n default:\n throw new Error('Method not found.');\n }\n};\n",
|
|
6
|
-
"typescriptConfig": "{\n \"extends\": \"../../../../tsconfig.packages.json\",\n \"compilerOptions\": {\n \"typeRoots\": [\"../../../../node_modules/@types\"]\n },\n \"files\": [\"./node_modules/@metamask/snap-types/global.d.ts\"],\n \"include\": [\"src\"]\n}\n",
|
|
7
|
-
"icon": "<svg width=\"24\" height=\"25\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M17.037 0H6.975C2.605 0 0 2.617 0 6.987v10.05c0 4.37 2.605 6.975 6.975 6.975h10.05c4.37 0 6.975-2.605 6.975-6.976V6.988C24.012 2.617 21.407 0 17.037 0ZM11.49 17.757c0 .36-.18.684-.492.876a.975.975 0 0 1-.54.156 1.11 1.11 0 0 1-.469-.108l-4.202-2.1a1.811 1.811 0 0 1-.985-1.61v-3.973c0-.36.18-.685.493-.877a1.04 1.04 0 0 1 1.008-.048l4.202 2.101a1.8 1.8 0 0 1 .997 1.609v3.974h-.012Zm-.252-6.423L6.723 8.896a1.045 1.045 0 0 1-.528-.924c0-.384.204-.744.528-.924l4.515-2.438a1.631 1.631 0 0 1 1.524 0l4.515 2.438c.324.18.528.528.528.924s-.204.744-.528.924l-4.515 2.438c-.24.132-.504.192-.768.192a1.54 1.54 0 0 1-.756-.192Zm7.972 3.638c0 .684-.385 1.308-.997 1.608l-4.202 2.101c-.144.072-.3.108-.468.108a.975.975 0 0 1-.54-.156 1.017 1.017 0 0 1-.493-.876v-3.974c0-.684.384-1.309.997-1.609l4.202-2.101a1.04 1.04 0 0 1 1.008.048c.313.192.493.516.493.877v3.974Z\" fill=\"#24272A\"/></svg>"
|
|
8
|
-
}
|
package/dist/tsconfig.json
DELETED
package/dist/utils/readline.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import readline from 'readline';
|
|
3
|
-
declare type PromptArgs = {
|
|
4
|
-
question: string;
|
|
5
|
-
defaultValue?: string;
|
|
6
|
-
shouldClose?: boolean;
|
|
7
|
-
readlineInterface?: readline.Interface;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
36
|
-
export declare function closePrompt(readlineInterface?: readline.Interface): void;
|
|
37
|
-
export {};
|
package/dist/utils/readline.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.closePrompt = exports.prompt = exports.openPrompt = void 0;
|
|
7
|
-
const readline_1 = __importDefault(require("readline"));
|
|
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
|
-
*/
|
|
13
|
-
function openPrompt() {
|
|
14
|
-
singletonReadlineInterface = readline_1.default.createInterface({
|
|
15
|
-
input: process.stdin,
|
|
16
|
-
output: process.stdout,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
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
|
-
*/
|
|
33
|
-
function prompt({ question, defaultValue, shouldClose, readlineInterface = singletonReadlineInterface, }) {
|
|
34
|
-
let _readlineInterface = readlineInterface;
|
|
35
|
-
if (!_readlineInterface) {
|
|
36
|
-
openPrompt();
|
|
37
|
-
_readlineInterface = singletonReadlineInterface;
|
|
38
|
-
}
|
|
39
|
-
return new Promise((resolve, _reject) => {
|
|
40
|
-
let queryString = `${question} `;
|
|
41
|
-
if (defaultValue) {
|
|
42
|
-
queryString += `(${defaultValue}) `;
|
|
43
|
-
}
|
|
44
|
-
_readlineInterface.question(queryString, (answer) => {
|
|
45
|
-
if (!answer || !answer.trim()) {
|
|
46
|
-
if (defaultValue !== undefined) {
|
|
47
|
-
resolve(defaultValue);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
resolve(answer.trim());
|
|
51
|
-
if (shouldClose) {
|
|
52
|
-
_readlineInterface.close();
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
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
|
-
*/
|
|
66
|
-
function closePrompt(readlineInterface = singletonReadlineInterface) {
|
|
67
|
-
if (readlineInterface) {
|
|
68
|
-
readlineInterface.close();
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
throw new Error('You are attempting to close a non existent prompt.');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.closePrompt = closePrompt;
|
|
75
|
-
//# sourceMappingURL=readline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readline.js","sourceRoot":"","sources":["../../src/utils/readline.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAEhC,IAAI,0BAA8C,CAAC;AASnD;;;GAGG;AACH,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;;;;;;;;;;;;GAYG;AACH,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;;;;;;;GAOG;AACH,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\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,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSnapConfig = void 0;
|
|
4
|
-
function isSnapConfig(obj, _argumentName) {
|
|
5
|
-
return ((obj !== null &&
|
|
6
|
-
typeof obj === "object" ||
|
|
7
|
-
typeof obj === "function") &&
|
|
8
|
-
(typeof obj.cliOptions === "undefined" ||
|
|
9
|
-
(obj.cliOptions !== null &&
|
|
10
|
-
typeof obj.cliOptions === "object" ||
|
|
11
|
-
typeof obj.cliOptions === "function") &&
|
|
12
|
-
Object.entries(obj.cliOptions)
|
|
13
|
-
.every(([key, _value]) => (typeof key === "string"))) &&
|
|
14
|
-
(typeof obj.bundlerCustomizer === "undefined" ||
|
|
15
|
-
typeof obj.bundlerCustomizer === "function"));
|
|
16
|
-
}
|
|
17
|
-
exports.isSnapConfig = isSnapConfig;
|
|
18
|
-
//# sourceMappingURL=snap-config.__GENERATED__.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snap-config.__GENERATED__.js","sourceRoot":"","sources":["../../src/utils/snap-config.__GENERATED__.ts"],"names":[],"mappings":";;;AAMA,SAAgB,YAAY,CAAC,GAAQ,EAAE,aAAsB;IACzD,OAAO,CACH,CAAC,GAAG,KAAK,IAAI;QACT,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,GAAG,KAAK,UAAU,CAAC;QAC9B,CAAC,OAAO,GAAG,CAAC,UAAU,KAAK,WAAW;YAClC,CAAC,GAAG,CAAC,UAAU,KAAK,IAAI;gBACpB,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ;gBAClC,OAAO,GAAG,CAAC,UAAU,KAAK,UAAU,CAAC;gBACzC,MAAM,CAAC,OAAO,CAAM,GAAG,CAAC,UAAU,CAAC;qBAC9B,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;QAC7D,CAAC,OAAO,GAAG,CAAC,iBAAiB,KAAK,WAAW;YACzC,OAAO,GAAG,CAAC,iBAAiB,KAAK,UAAU,CAAC,CACnD,CAAA;AACL,CAAC;AAdD,oCAcC","sourcesContent":["/*\n * Generated type guards for \"snap-config.ts\".\n * WARNING: Do not manually change this file.\n */\nimport { SnapConfig } from \"./snap-config\";\n\nexport function isSnapConfig(obj: any, _argumentName?: string): obj is SnapConfig {\n return (\n (obj !== null &&\n typeof obj === \"object\" ||\n typeof obj === \"function\") &&\n (typeof obj.cliOptions === \"undefined\" ||\n (obj.cliOptions !== null &&\n typeof obj.cliOptions === \"object\" ||\n typeof obj.cliOptions === \"function\") &&\n Object.entries<any>(obj.cliOptions)\n .every(([key, _value]) => (typeof key === \"string\"))) &&\n (typeof obj.bundlerCustomizer === \"undefined\" ||\n typeof obj.bundlerCustomizer === \"function\")\n )\n}\n"]}
|