@metamask/snaps-cli 0.14.0 → 0.15.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/CHANGELOG.md +9 -1
- package/README.md +1 -0
- package/dist/cmds/build/bundle.js +2 -0
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/index.d.ts +1 -0
- package/dist/utils/misc.js +3 -2
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/snap-config.js +3 -3
- package/dist/utils/snap-config.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.15.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add support for building TypeScript Snaps ([#443](https://github.com/MetaMask/snaps-skunkworks/pull/443))
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- Fix an issue where comment stripping would break for large files ([#468](https://github.com/MetaMask/snaps-skunkworks/pull/468))
|
|
15
|
+
|
|
9
16
|
## [0.14.0]
|
|
10
17
|
### Changed
|
|
11
18
|
- **BREAKING:** Increase TypeScript compilation target to ES2020 ([#449](https://github.com/MetaMask/snaps-skunkworks/pull/449))
|
|
@@ -178,7 +185,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
178
185
|
- Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
|
|
179
186
|
- The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
|
|
180
187
|
|
|
181
|
-
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.
|
|
188
|
+
[Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.15.0...HEAD
|
|
189
|
+
[0.15.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.14.0...v0.15.0
|
|
182
190
|
[0.14.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.13.0...v0.14.0
|
|
183
191
|
[0.13.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.12.0...v0.13.0
|
|
184
192
|
[0.12.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.11.1...v0.12.0
|
package/README.md
CHANGED
|
@@ -29,7 +29,9 @@ function bundle(src, dest, argv, bundlerTransform) {
|
|
|
29
29
|
if (transpilationMode !== builders_1.TranspilationModes.none) {
|
|
30
30
|
bundler.transform(require('babelify'), {
|
|
31
31
|
global: transpilationMode === builders_1.TranspilationModes.localAndDeps,
|
|
32
|
+
extensions: ['.js', '.ts'],
|
|
32
33
|
presets: [
|
|
34
|
+
require('@babel/preset-typescript'),
|
|
33
35
|
[
|
|
34
36
|
require('@babel/preset-env'),
|
|
35
37
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0D;AAC1D,6CAAoD;AAEpD,mCAA+D;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,mHAAmH;AAEnH;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CACpB,GAAW,EACX,IAAY,EACZ,IAAe,EACf,gBAAsD;IAEtD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IACtD,MAAM,eAAe,GAAG,IAAA,2BAAmB,EAAC,IAAW,CAAC,CAAC;IACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAE3C,IAAI,iBAAiB,KAAK,6BAAkB,CAAC,IAAI,EAAE;YACjD,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE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AAC;AACL,CAAC;AAvDD,wBAuDC","sourcesContent":["import browserify, { BrowserifyObject } from 'browserify';\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\n */\nexport function bundle(\n src: string,\n dest: string,\n argv: YargsArgs,\n bundlerTransform?: (bundler: BrowserifyObject) => void,\n): Promise<boolean> {\n const { sourceMaps: debug, transpilationMode } = argv;\n const babelifyOptions = processDependencies(argv as any);\n return new Promise((resolve, _reject) => {\n const bundler = browserify(src, { debug });\n\n if (transpilationMode !== TranspilationModes.none) {\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.localAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: ['chrome >= 66', 'firefox >= 68'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-object-rest-spread'),\n require('@babel/plugin-proposal-optional-chaining'),\n require('@babel/plugin-proposal-nullish-coalescing-operator'),\n ],\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin('@metamask/snaps-browserify-plugin', {\n stripComments: argv.stripComments,\n transformHtmlComments: argv.transformHtmlComments,\n });\n\n bundler.bundle(\n async (bundleError, bundleBuffer: Buffer) =>\n await writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n }),\n );\n });\n}\n"]}
|
package/dist/cmds/index.d.ts
CHANGED
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 = [
|
|
@@ -42,10 +43,10 @@ function setSnapGlobals(argv) {
|
|
|
42
43
|
else {
|
|
43
44
|
global.snaps.isWatching = false;
|
|
44
45
|
}
|
|
45
|
-
if (
|
|
46
|
+
if ((0, utils_1.hasProperty)(argv, 'verboseErrors')) {
|
|
46
47
|
global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);
|
|
47
48
|
}
|
|
48
|
-
if (
|
|
49
|
+
if ((0, utils_1.hasProperty)(argv, 'suppressWarnings')) {
|
|
49
50
|
global.snaps.suppressWarnings = booleanStringToBoolean(argv.suppressWarnings);
|
|
50
51
|
}
|
|
51
52
|
}
|
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,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AAC,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 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 * @return `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 */\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 exits.\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"]}
|
|
@@ -5,6 +5,7 @@ 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");
|
|
@@ -66,12 +67,11 @@ function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
|
|
|
66
67
|
delete parsedProcessArgv._; // irrelevant yargs parser artifact
|
|
67
68
|
const commandOptions = new Set(Object.keys(options));
|
|
68
69
|
const shouldSetArg = (key) => {
|
|
69
|
-
return
|
|
70
|
-
!Object.prototype.hasOwnProperty.call(parsedProcessArgv, key));
|
|
70
|
+
return commandOptions.has(key) && !(0, utils_1.hasProperty)(parsedProcessArgv, key);
|
|
71
71
|
};
|
|
72
72
|
const cfg = snapConfig.cliOptions || {};
|
|
73
73
|
for (const key of Object.keys(cfg)) {
|
|
74
|
-
if (
|
|
74
|
+
if ((0, utils_1.hasProperty)(builders_1.default, key)) {
|
|
75
75
|
if (shouldSetArg(key)) {
|
|
76
76
|
yargsArgv[key] = cfg[key];
|
|
77
77
|
}
|
|
@@ -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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AE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GACpC,aACD,CAAC,UAAU,EAGX,CAAC;IAEF,MAAM,iBAAiB,GAAG,IAAA,sBAAU,EAAC,WAAW,EAAE;QAChD,KAAK,EAAE,OAAO;KACf,CAA4B,CAAC;IAC9B,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,mCAAmC;IAE/D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAErD,MAAM,YAAY,GAAG,CAAC,GAAW,EAAW,EAAE;QAC5C,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,mBAAW,EAAC,iBAAiB,EAAE,GAAG,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\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 yarg's .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 */\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.15.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"build:post-tsc": "yarn build:chmod && yarn build:readme",
|
|
27
27
|
"build:clean": "yarn clean && yarn build",
|
|
28
28
|
"build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
|
|
29
|
-
"clean": "rimraf *.tsbuildinfo dist/* src/**/*__GENERATED__*",
|
|
29
|
+
"clean": "rimraf '*.tsbuildinfo' 'dist/*' 'src/**/*__GENERATED__*'",
|
|
30
30
|
"test": "yarn build:init-template && jest",
|
|
31
31
|
"posttest": "jest-it-up",
|
|
32
32
|
"test:watch": "yarn test --watch",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
|
|
47
47
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
48
48
|
"@babel/preset-env": "^7.16.7",
|
|
49
|
-
"@
|
|
50
|
-
"@metamask/snap-controllers": "^0.
|
|
51
|
-
"@metamask/snaps-browserify-plugin": "^0.
|
|
49
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
50
|
+
"@metamask/snap-controllers": "^0.15.0",
|
|
51
|
+
"@metamask/snaps-browserify-plugin": "^0.15.0",
|
|
52
|
+
"@metamask/utils": "^2.0.0",
|
|
52
53
|
"babelify": "^10.0.0",
|
|
53
54
|
"browserify": "^17.0.0",
|
|
54
55
|
"chokidar": "^3.0.2",
|
|
55
|
-
"fast-deep-equal": "^2.0.1",
|
|
56
56
|
"init-package-json": "^1.10.3",
|
|
57
57
|
"is-url": "^1.2.4",
|
|
58
58
|
"mkdirp": "^1.0.4",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@lavamoat/allow-scripts": "^1.0.6",
|
|
68
|
-
"@metamask/auto-changelog": "^2.
|
|
68
|
+
"@metamask/auto-changelog": "^2.6.0",
|
|
69
69
|
"@metamask/eslint-config": "^8.0.0",
|
|
70
70
|
"@metamask/eslint-config-jest": "^8.0.0",
|
|
71
71
|
"@metamask/eslint-config-nodejs": "^8.0.0",
|