@metamask/snaps-cli 0.23.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +0 -1
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/initHandler.js +7 -11
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.js +6 -12
- 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/misc.d.ts +1 -1
- package/dist/utils/misc.js +6 -1
- package/dist/utils/misc.js.map +1 -1
- package/package.json +7 -6
- package/dist/__mocks__/fs.d.ts +0 -2
- package/dist/__mocks__/fs.js +0 -4
- package/dist/__mocks__/fs.js.map +0 -1
- package/dist/test-utils/fs.d.ts +0 -5
- package/dist/test-utils/fs.js +0 -18
- package/dist/test-utils/fs.js.map +0 -1
- package/dist/test-utils/index.d.ts +0 -1
- package/dist/test-utils/index.js +0 -18
- package/dist/test-utils/index.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.build = void 0;
|
|
4
|
-
const
|
|
4
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
6
|
const manifestHandler_1 = require("../manifest/manifestHandler");
|
|
7
7
|
const evalHandler_1 = require("../eval/evalHandler");
|
|
@@ -20,11 +20,11 @@ const bundle_1 = require("./bundle");
|
|
|
20
20
|
async function build(argv) {
|
|
21
21
|
const { src, dist, outfileName } = argv;
|
|
22
22
|
if (outfileName) {
|
|
23
|
-
(0,
|
|
23
|
+
(0, snaps_utils_1.validateOutfileName)(outfileName);
|
|
24
24
|
}
|
|
25
|
-
await (0,
|
|
26
|
-
await (0,
|
|
27
|
-
const outfilePath = (0,
|
|
25
|
+
await (0, snaps_utils_1.validateFilePath)(src);
|
|
26
|
+
await (0, snaps_utils_1.validateDirPath)(dist, true);
|
|
27
|
+
const outfilePath = (0, snaps_utils_1.getOutfilePath)(dist, outfileName);
|
|
28
28
|
const result = await (0, bundle_1.bundle)(src, outfilePath, argv, (0, utils_1.loadConfig)().bundlerCustomizer);
|
|
29
29
|
if (result && argv.eval) {
|
|
30
30
|
await (0, evalHandler_1.evalHandler)(Object.assign(Object.assign({}, argv), { bundle: outfilePath }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAE/B,uCAAyC;AACzC,iEAA8D;AAC9D,qDAAkD;AAClD,qCAAkC;AAElC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACxC,IAAI,WAAW,EAAE;QACf,IAAA,iCAAmB,EAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,IAAA,8BAAgB,EAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAA,6BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,IAAA,4BAAc,EAAC,IAAI,EAAE,WAAqB,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,IAAA,eAAM,EACzB,GAAG,EACH,WAAW,EACX,IAAI,EACJ,IAAA,kBAAU,GAAE,CAAC,iBAAiB,CAC/B,CAAC;IACF,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;QACvB,MAAM,IAAA,yBAAW,kCAAM,IAAI,KAAE,MAAM,EAAE,WAAW,IAAG,CAAC;KACrD;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,sBAsBC","sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { evalHandler } from '../eval/evalHandler';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Argv from Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.outfileName - The output file name.\n */\nexport async function build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName as string);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName as string);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.evalHandler = void 0;
|
|
4
|
-
const
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
4
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
6
5
|
/**
|
|
7
6
|
* Runs the snap in a worker, to ensure SES compatibility.
|
|
8
7
|
*
|
|
@@ -13,12 +12,11 @@ const utils_1 = require("../../utils");
|
|
|
13
12
|
async function evalHandler(argv) {
|
|
14
13
|
const { bundle: bundlePath } = argv;
|
|
15
14
|
try {
|
|
16
|
-
await (0,
|
|
15
|
+
await (0, snaps_utils_1.evalBundle)(bundlePath);
|
|
17
16
|
console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);
|
|
18
17
|
}
|
|
19
18
|
catch (error) {
|
|
20
|
-
|
|
21
|
-
throw error;
|
|
19
|
+
throw new Error(`Snap evaluation error: ${error.message}`);
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
22
|
exports.evalHandler = evalHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAGnD;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAEpC,IAAI;QACF,MAAM,IAAA,wBAAU,EAAC,UAAoB,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,4BAA4B,UAAU,WAAW,CAAC,CAAC;KAChE;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5D;AACH,CAAC;AATD,kCASC","sourcesContent":["import { evalBundle } from '@metamask/snaps-utils';\nimport { YargsArgs } from '../../types/yargs';\n\n/**\n * Runs the snap in a worker, to ensure SES compatibility.\n *\n * @param argv - The Yargs arguments object.\n * @returns A promise that resolves once the eval has finished.\n * @throws If the eval failed.\n */\nexport async function evalHandler(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n\n try {\n await evalBundle(bundlePath as string);\n console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"]}
|
package/dist/cmds/init/index.js
CHANGED
|
@@ -13,7 +13,6 @@ const initHandler_1 = require("./initHandler");
|
|
|
13
13
|
* @param argv - The Yargs arguments object.
|
|
14
14
|
*/
|
|
15
15
|
async function init(argv) {
|
|
16
|
-
console.log();
|
|
17
16
|
const newArgs = await (0, initHandler_1.initHandler)(argv);
|
|
18
17
|
process.chdir(newArgs.snapLocation);
|
|
19
18
|
await (0, buildHandler_1.build)(Object.assign(Object.assign({}, newArgs), { manifest: false, eval: true }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAW5C;;;;;;GAMG;AACH,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAW5C;;;;;;GAMG;AACH,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC;IAExC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEpC,MAAM,IAAA,oBAAK,kCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,CAAC;AA5BD,iBAAS;IACP,OAAO,EAAE,CAAC,kBAAkB,EAAE,eAAe,CAAC;IAC9C,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,kBAAQ,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC","sourcesContent":["import yargs from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler } from './initHandler';\n\nexport = {\n command: ['init [directory]', 'i [directory]'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg.positional('directory', builders.directory);\n },\n handler: (argv: YargsArgs) => init(argv),\n};\n\n/**\n * The main entrypoint for the init command. This calls the init handler to\n * initialize the snap package, builds the snap, and then updates the manifest\n * with the shasum of the built snap.\n *\n * @param argv - The Yargs arguments object.\n */\nasync function init(argv: YargsArgs): Promise<void> {\n const newArgs = await initHandler(argv);\n\n process.chdir(newArgs.snapLocation);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n console.log('\\nSnap project successfully initiated!');\n}\n"]}
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.initHandler = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
|
-
const
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
9
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
11
10
|
const initUtils_1 = require("./initUtils");
|
|
12
11
|
const SATISFIED_VERSION = '>=16';
|
|
13
12
|
/**
|
|
@@ -22,15 +21,13 @@ const SATISFIED_VERSION = '>=16';
|
|
|
22
21
|
*/
|
|
23
22
|
async function initHandler(argv) {
|
|
24
23
|
const { directory } = argv;
|
|
25
|
-
const isVersionSupported = (0,
|
|
24
|
+
const isVersionSupported = (0, snaps_utils_1.satisfiesVersionRange)(process.version, SATISFIED_VERSION);
|
|
26
25
|
if (!isVersionSupported) {
|
|
27
|
-
|
|
28
|
-
throw new Error('Outdated node version.');
|
|
26
|
+
throw new Error(`Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`);
|
|
29
27
|
}
|
|
30
28
|
const gitExists = (0, initUtils_1.isGitInstalled)();
|
|
31
29
|
if (!gitExists) {
|
|
32
|
-
|
|
33
|
-
throw new Error('Git is not installed.');
|
|
30
|
+
throw new Error(`Init Error: git is not installed. Please install git to continue.`);
|
|
34
31
|
}
|
|
35
32
|
const directoryToUse = directory
|
|
36
33
|
? path_1.default.join(process.cwd(), directory)
|
|
@@ -46,8 +43,7 @@ async function initHandler(argv) {
|
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
45
|
catch (err) {
|
|
49
|
-
|
|
50
|
-
throw err;
|
|
46
|
+
throw new Error('Init Error: Failed to create template.');
|
|
51
47
|
}
|
|
52
48
|
console.log('Installing dependencies...');
|
|
53
49
|
await (0, initUtils_1.yarnInstall)(directoryToUse);
|
|
@@ -56,8 +52,8 @@ async function initHandler(argv) {
|
|
|
56
52
|
await (0, initUtils_1.gitInit)(directoryToUse);
|
|
57
53
|
}
|
|
58
54
|
const snapLocation = path_1.default.join(directoryToUse, initUtils_1.SNAP_LOCATION);
|
|
59
|
-
const manifest = await (0,
|
|
60
|
-
const packageJson = await (0,
|
|
55
|
+
const manifest = await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.Manifest));
|
|
56
|
+
const packageJson = await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.PackageJson));
|
|
61
57
|
const distPath = manifest.source.location.npm.filePath.split('/');
|
|
62
58
|
return Object.assign(Object.assign({}, argv), { dist: distPath[0], outfileName: distPath[1], src: packageJson.main || 'src/index.js', snapLocation });
|
|
63
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,2BAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,2BAAoC;AACpC,uDAM+B;AAE/B,2CAQqB;AAErB,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEjC;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAE3B,MAAM,kBAAkB,GAAG,IAAA,mCAAqB,EAC9C,OAAO,CAAC,OAAO,EACf,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE;QACvB,MAAM,IAAI,KAAK,CACb,0DAA0D,OAAO,CAAC,OAAO,4BAA4B,iBAAiB,GAAG,CAC1H,CAAC;KACH;IAED,MAAM,SAAS,GAAG,IAAA,0BAAc,GAAE,CAAC;IACnC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;KACH;IAED,MAAM,cAAc,GAAG,SAAS;QAC9B,CAAC,CAAC,cAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC;QAC1C,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAElB,OAAO,CAAC,GAAG,CAAC,aAAa,cAAc,KAAK,CAAC,CAAC;IAE9C,MAAM,IAAA,mCAAuB,EAAC,cAAc,CAAC,CAAC;IAE9C,IAAI;QACF,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,MAAM,IAAA,yBAAa,EAAC,cAAc,CAAC,CAAC;QAEpC,aAAE,CAAC,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Range,\n NpmSnapPackageJson,\n} from '@metamask/snaps-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport {\n cloneTemplate,\n gitInit,\n isGitInstalled,\n isInGitRepository,\n prepareWorkingDirectory,\n SNAP_LOCATION,\n yarnInstall,\n} from './initUtils';\n\nconst SATISFIED_VERSION = '>=16';\n\n/**\n * Creates a new snap package, based on one of the provided templates. This\n * creates all the necessary files, like `package.json`, `snap.config.js`, etc.\n * to start developing a snap.\n *\n * @param argv - The Yargs arguments object.\n * @returns The Yargs arguments augmented with the new `dist`, `outfileName` and\n * `src` properties.\n * @throws If initialization of the snap package failed.\n */\nexport async function initHandler(argv: YargsArgs) {\n const { directory } = argv;\n\n const isVersionSupported = satisfiesVersionRange(\n process.version,\n SATISFIED_VERSION,\n );\n\n if (!isVersionSupported) {\n throw new Error(\n `Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`,\n );\n }\n\n const gitExists = isGitInstalled();\n if (!gitExists) {\n throw new Error(\n `Init Error: git is not installed. Please install git to continue.`,\n );\n }\n\n const directoryToUse = directory\n ? pathUtils.join(process.cwd(), directory)\n : process.cwd();\n\n console.log(`Preparing ${directoryToUse}...`);\n\n await prepareWorkingDirectory(directoryToUse);\n\n try {\n console.log(`Cloning template...`);\n await cloneTemplate(directoryToUse);\n\n fs.rm(pathUtils.join(directoryToUse, '.git'), {\n force: true,\n recursive: true,\n });\n } catch (err) {\n throw new Error('Init Error: Failed to create template.');\n }\n\n console.log('Installing dependencies...');\n await yarnInstall(directoryToUse);\n\n if (!isInGitRepository(directoryToUse)) {\n console.log('Initializing git repository...');\n await gitInit(directoryToUse);\n }\n\n const snapLocation = pathUtils.join(directoryToUse, SNAP_LOCATION);\n\n const manifest: SnapManifest = await readJsonFile(\n pathUtils.join(snapLocation, NpmSnapFileNames.Manifest),\n );\n const packageJson: NpmSnapPackageJson = await readJsonFile(\n pathUtils.join(snapLocation, NpmSnapFileNames.PackageJson),\n );\n\n const distPath = manifest.source.location.npm.filePath.split('/');\n\n return {\n ...argv,\n dist: distPath[0],\n outfileName: distPath[1],\n src: packageJson.main || 'src/index.js',\n snapLocation,\n };\n}\n"]}
|
|
@@ -7,7 +7,6 @@ exports.yarnInstall = exports.gitInit = exports.isInGitRepository = exports.isGi
|
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
10
|
exports.TEMPLATE_GIT_URL = 'https://github.com/MetaMask/template-snap-monorepo.git';
|
|
12
11
|
exports.SNAP_LOCATION = 'packages/snap/';
|
|
13
12
|
/**
|
|
@@ -23,18 +22,16 @@ async function prepareWorkingDirectory(directory) {
|
|
|
23
22
|
await fs_1.promises.mkdir(directory, { recursive: true });
|
|
24
23
|
}
|
|
25
24
|
catch (err) {
|
|
26
|
-
|
|
27
|
-
throw err;
|
|
25
|
+
throw new Error('Init Error: Failed to create new directory.');
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
28
|
const existingFiles = await fs_1.promises.readdir(directory);
|
|
31
29
|
if (existingFiles.length > 0) {
|
|
32
|
-
throw new Error(`Directory
|
|
30
|
+
throw new Error(`Directory ${directory} not empty.`);
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
33
|
catch (err) {
|
|
36
|
-
|
|
37
|
-
throw err;
|
|
34
|
+
throw new Error(`Init Error: Failed to prepare working directory with message: ${err.message}`);
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
exports.prepareWorkingDirectory = prepareWorkingDirectory;
|
|
@@ -50,8 +47,7 @@ async function cloneTemplate(directory) {
|
|
|
50
47
|
});
|
|
51
48
|
}
|
|
52
49
|
catch (err) {
|
|
53
|
-
|
|
54
|
-
throw err;
|
|
50
|
+
throw new Error('Init Error: Failed to clone the template.');
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
exports.cloneTemplate = cloneTemplate;
|
|
@@ -102,8 +98,7 @@ async function gitInit(directory) {
|
|
|
102
98
|
});
|
|
103
99
|
}
|
|
104
100
|
catch (err) {
|
|
105
|
-
|
|
106
|
-
throw err;
|
|
101
|
+
throw new Error('Init Error: Failed to init a new git repository.');
|
|
107
102
|
}
|
|
108
103
|
}
|
|
109
104
|
exports.gitInit = gitInit;
|
|
@@ -120,8 +115,7 @@ async function yarnInstall(directory) {
|
|
|
120
115
|
});
|
|
121
116
|
}
|
|
122
117
|
catch (err) {
|
|
123
|
-
|
|
124
|
-
throw err;
|
|
118
|
+
throw new Error('Init Error: Failed to install dependencies.');
|
|
125
119
|
}
|
|
126
120
|
}
|
|
127
121
|
exports.yarnInstall = yarnInstall;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initUtils.js","sourceRoot":"","sources":["../../../src/cmds/init/initUtils.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAoC;AACpC,iDAAyC;AACzC,gDAA6B;
|
|
1
|
+
{"version":3,"file":"initUtils.js","sourceRoot":"","sources":["../../../src/cmds/init/initUtils.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAoC;AACpC,iDAAyC;AACzC,gDAA6B;AAEhB,QAAA,gBAAgB,GAC3B,wDAAwD,CAAC;AAE9C,QAAA,aAAa,GAAG,gBAAgB,CAAC;AAE9C;;;;GAIG;AACI,KAAK,UAAU,uBAAuB,CAC3C,SAAiB;IAEjB,IAAI;QACF,MAAM,kBAAkB,GAAG,SAAS,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC;QAEvD,IAAI,CAAC,kBAAkB,EAAE;YACvB,IAAI;gBACF,MAAM,aAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;aAChD;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;aAChE;SACF;QAED,MAAM,aAAa,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,SAAS,CA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,GAAG,EAAE,cAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7C,CAAC,CAAC;KACJ;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;KACrE;AACH,CAAC;AATD,0BASC;AAED;;;;GAIG;AACI,KAAK,UAAU,WAAW,CAAC,SAAiB;IACjD,IAAI;QACF,IAAA,wBAAQ,EAAC,cAAc,EAAE;YACvB,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAChB,GAAG,EAAE,cAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7C,CAAC,CAAC;KACJ;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAChE;AACH,CAAC;AATD,kCASC","sourcesContent":["import { promises as fs } from 'fs';\nimport { execSync } from 'child_process';\nimport pathUtils from 'path';\n\nexport const TEMPLATE_GIT_URL =\n 'https://github.com/MetaMask/template-snap-monorepo.git';\n\nexport const SNAP_LOCATION = 'packages/snap/';\n\n/**\n * Checks if the destination folder exists and if it's empty. Otherwise create it.\n *\n * @param directory - The desination folder.\n */\nexport async function prepareWorkingDirectory(\n directory: string,\n): Promise<void> {\n try {\n const isCurrentDirectory = directory === process.cwd();\n\n if (!isCurrentDirectory) {\n try {\n await fs.mkdir(directory, { recursive: true });\n } catch (err) {\n throw new Error('Init Error: Failed to create new directory.');\n }\n }\n\n const existingFiles = await fs.readdir(directory);\n\n if (existingFiles.length > 0) {\n throw new Error(`Directory ${directory} not empty.`);\n }\n } catch (err) {\n throw new Error(\n `Init Error: Failed to prepare working directory with message: ${err.message}`,\n );\n }\n}\n\n/**\n * Clones the template in a directory.\n *\n * @param directory - The directory to clone the template in.\n */\nexport async function cloneTemplate(directory: string) {\n try {\n execSync(`git clone --depth=1 ${TEMPLATE_GIT_URL} ${directory}`, {\n stdio: [2],\n });\n } catch (err) {\n throw new Error('Init Error: Failed to clone the template.');\n }\n}\n\n/**\n * Check if git is installed.\n *\n * @returns True if git is installed, or false otherwise.\n */\nexport function isGitInstalled() {\n try {\n execSync('git --version', { stdio: 'ignore' });\n return true;\n } catch (e) {\n return false;\n }\n}\n\n/**\n * Check if the actual working dir is a git repository.\n *\n * @param directory - The directory to check.\n * @returns True if it's a git repository otherwise false.\n */\nexport function isInGitRepository(directory: string) {\n try {\n execSync('git rev-parse --is-inside-work-tree', {\n stdio: 'ignore',\n cwd: pathUtils.resolve(__dirname, directory),\n });\n return true;\n } catch (err) {\n return false;\n }\n}\n\n/**\n * Init a git repository.\n *\n * @param directory - The directory to init.\n */\nexport async function gitInit(directory: string) {\n try {\n execSync('git init', {\n stdio: 'ignore',\n cwd: pathUtils.resolve(__dirname, directory),\n });\n } catch (err) {\n throw new Error('Init Error: Failed to init a new git repository.');\n }\n}\n\n/**\n * Install dependencies in a yarn project.\n *\n * @param directory - The directory containing the project.\n */\nexport async function yarnInstall(directory: string) {\n try {\n execSync('yarn install', {\n stdio: [0, 1, 2],\n cwd: pathUtils.resolve(__dirname, directory),\n });\n } catch (err) {\n throw new Error('Init Error: Failed to install dependencies.');\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.manifestHandler = void 0;
|
|
4
|
-
const
|
|
4
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
5
5
|
const ERROR_PREFIX = 'Manifest Error: ';
|
|
6
6
|
/**
|
|
7
7
|
* Validates a snap.manifest.json file. Attempts to fix the manifest and write
|
|
@@ -13,7 +13,7 @@ const ERROR_PREFIX = 'Manifest Error: ';
|
|
|
13
13
|
*/
|
|
14
14
|
async function manifestHandler({ writeManifest }) {
|
|
15
15
|
try {
|
|
16
|
-
const { warnings, errors } = await (0,
|
|
16
|
+
const { warnings, errors } = await (0, snaps_utils_1.checkManifest)(process.cwd(), Boolean(writeManifest));
|
|
17
17
|
if (!writeManifest && errors.length > 0) {
|
|
18
18
|
console.error(`${ERROR_PREFIX}The manifest is invalid.`);
|
|
19
19
|
errors.forEach(logManifestError);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../../src/cmds/manifest/manifestHandler.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../../src/cmds/manifest/manifestHandler.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AAGtD,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CAAC,EAAE,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,2BAAa,EAC9C,OAAO,CAAC,GAAG,EAAE,EACb,OAAO,CAAC,aAAa,CAAC,CACvB,CAAC;QAEF,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,0BAA0B,CAAC,CAAC;YACzD,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;YAEjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,OAAO,CAAC,GAAG,CACT,6EAA6E,CAC9E,CAAC;YACF,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;SACtC;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,GAAG,KAAK,EAAE,CAAC,CAAC;KAC5C;AACH,CAAC;AAvBD,0CAuBC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,OAAe;IACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE;QAClC,OAAO,CAAC,GAAG,CAAC,qBAAqB,OAAO,EAAE,CAAC,CAAC;KAC7C;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,OAAe;IACvC,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,GAAG,OAAO,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import { checkManifest } from '@metamask/snaps-utils';\nimport { YargsArgs } from '../../types/yargs';\n\nconst ERROR_PREFIX = 'Manifest Error: ';\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param argv - The Yargs `argv` object.\n * @param argv.writeManifest - Whether to write the fixed manifest to disk.\n */\nexport async function manifestHandler({ writeManifest }: YargsArgs) {\n try {\n const { warnings, errors } = await checkManifest(\n process.cwd(),\n Boolean(writeManifest),\n );\n\n if (!writeManifest && errors.length > 0) {\n console.error(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n console.log(\n 'Manifest Warning: Validation of snap.manifest.json completed with warnings.',\n );\n warnings.forEach(logManifestWarning);\n }\n } catch (error) {\n throw new Error(`${ERROR_PREFIX}${error}`);\n }\n}\n\n/**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\nfunction logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n console.log(`Manifest Warning: ${message}`);\n }\n}\n\n/**\n * Logs a manifest error.\n *\n * @param message - The message to log.\n */\nfunction logManifestError(message: string) {\n console.error(`${ERROR_PREFIX}${message}`);\n}\n"]}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.serve = void 0;
|
|
7
7
|
const http_1 = __importDefault(require("http"));
|
|
8
8
|
const serve_handler_1 = __importDefault(require("serve-handler"));
|
|
9
|
-
const
|
|
9
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
10
10
|
const serveUtils_1 = require("./serveUtils");
|
|
11
11
|
/**
|
|
12
12
|
* Starts a local, static HTTP server on the given port with the given root
|
|
@@ -18,7 +18,7 @@ const serveUtils_1 = require("./serveUtils");
|
|
|
18
18
|
*/
|
|
19
19
|
async function serve(argv) {
|
|
20
20
|
const { port, root: rootDir } = argv;
|
|
21
|
-
await (0,
|
|
21
|
+
await (0, snaps_utils_1.validateDirPath)(rootDir, true);
|
|
22
22
|
console.log(`\nStarting server...`);
|
|
23
23
|
const server = http_1.default.createServer(async (req, res) => {
|
|
24
24
|
await (0, serve_handler_1.default)(req, res, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serveHandler.js","sourceRoot":"","sources":["../../../src/cmds/serve/serveHandler.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,kEAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"serveHandler.js","sourceRoot":"","sources":["../../../src/cmds/serve/serveHandler.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,kEAAyC;AACzC,uDAAwD;AAExD,6CAA8E;AAE9E;;;;;;;GAOG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAErC,MAAM,IAAA,6BAAe,EAAC,OAAiB,EAAE,IAAI,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAEpC,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QAClD,MAAM,IAAA,uBAAY,EAAC,GAAG,EAAE,GAAG,EAAE;YAC3B,MAAM,EAAE,OAAiB;YACzB,OAAO,EAAE;gBACP;oBACE,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE;wBACP;4BACE,GAAG,EAAE,eAAe;4BACpB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,GAAG,EAAE,6BAA6B;4BAClC,KAAK,EAAE,GAAG;yBACX;qBACF;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,IAAA,+BAAkB,EAAC,IAAI,CAAC,CAAC,CAAC;IAExD,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,uBAAU,EAAC,OAAO,CAAC,CAAC,CAAC;IAEvD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3B,IAAA,2BAAc,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACtB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC;AAzCD,sBAyCC","sourcesContent":["import http from 'http';\nimport serveHandler from 'serve-handler';\nimport { validateDirPath } from '@metamask/snaps-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { logRequest, logServerError, logServerListening } from './serveUtils';\n\n/**\n * Starts a local, static HTTP server on the given port with the given root\n * directory.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.root - The root directory path string.\n * @param argv.port - The server port.\n */\nexport async function serve(argv: YargsArgs): Promise<void> {\n const { port, root: rootDir } = argv;\n\n await validateDirPath(rootDir as string, true);\n\n console.log(`\\nStarting server...`);\n\n const server = http.createServer(async (req, res) => {\n await serveHandler(req, res, {\n public: rootDir as string,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n });\n });\n\n server.listen({ port }, () => logServerListening(port));\n\n server.on('request', (request) => logRequest(request));\n\n server.on('error', (error) => {\n logServerError(error, argv.port);\n process.exitCode = 1;\n });\n\n server.on('close', () => {\n console.log('Server closed');\n process.exitCode = 1;\n });\n}\n"]}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.watch = void 0;
|
|
7
7
|
const chokidar_1 = __importDefault(require("chokidar"));
|
|
8
|
-
const
|
|
8
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
10
|
const bundle_1 = require("../build/bundle");
|
|
11
11
|
const evalHandler_1 = require("../eval/evalHandler");
|
|
@@ -26,12 +26,12 @@ const serveHandler_1 = require("../serve/serveHandler");
|
|
|
26
26
|
async function watch(argv) {
|
|
27
27
|
const { dist, eval: shouldEval, manifest, outfileName, src, serve: shouldServe, } = argv;
|
|
28
28
|
if (outfileName) {
|
|
29
|
-
(0,
|
|
29
|
+
(0, snaps_utils_1.validateOutfileName)(outfileName);
|
|
30
30
|
}
|
|
31
|
-
await (0,
|
|
32
|
-
await (0,
|
|
31
|
+
await (0, snaps_utils_1.validateFilePath)(src);
|
|
32
|
+
await (0, snaps_utils_1.validateDirPath)(dist, true);
|
|
33
33
|
const rootDir = src.indexOf('/') === -1 ? '.' : src.substring(0, src.lastIndexOf('/') + 1);
|
|
34
|
-
const outfilePath = (0,
|
|
34
|
+
const outfilePath = (0, snaps_utils_1.getOutfilePath)(dist, outfileName);
|
|
35
35
|
const buildSnap = async (path, logMessage) => {
|
|
36
36
|
if (logMessage !== undefined) {
|
|
37
37
|
console.log(logMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watchHandler.js","sourceRoot":"","sources":["../../../src/cmds/watch/watchHandler.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"watchHandler.js","sourceRoot":"","sources":["../../../src/cmds/watch/watchHandler.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,uDAK+B;AAE/B,uCAAmD;AACnD,4CAAyC;AACzC,qDAAkD;AAClD,iEAA8D;AAC9D,wDAA8C;AAE9C;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EACJ,IAAI,EACJ,IAAI,EAAE,UAAU,EAChB,QAAQ,EACR,WAAW,EACX,GAAG,EACH,KAAK,EAAE,WAAW,GACnB,GAAG,IAAI,CAAC;IACT,IAAI,WAAW,EAAE;QACf,IAAA,iCAAmB,EAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,IAAA,8BAAgB,EAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAA,6BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,MAAM,OAAO,GACX,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7E,MAAM,WAAW,GAAG,IAAA,4BAAc,EAAC,IAAI,EAAE,WAAqB,CAAC,CAAC;IAEhE,MAAM,SAAS,GAAG,KAAK,EAAE,IAAa,EAAE,UAAmB,EAAE,EAAE;QAC7D,IAAI,UAAU,KAAK,SAAS,EAAE;YAC5B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;SACzB;QAED,IAAI;YACF,MAAM,IAAA,eAAM,EAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,IAAA,kBAAU,GAAE,CAAC,iBAAiB,CAAC,CAAC;YA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AAY,EAAE,EAAE;QAC5B,IAAA,gBAAQ,EAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC;SAED,GAAG,CAAC,OAAO,CAAC,CAAC;IAEhB,OAAO,CAAC,GAAG,CAAC,aAAa,OAAO,kBAAkB,CAAC,CAAC;AACtD,CAAC;AA5ED,sBA4EC","sourcesContent":["import chokidar from 'chokidar';\nimport {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig, logError } from '../../utils';\nimport { bundle } from '../build/bundle';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { serve } from '../serve/serveHandler';\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.'outfileName' - The output file name.\n */\nexport async function watch(argv: YargsArgs): Promise<void> {\n const {\n dist,\n eval: shouldEval,\n manifest,\n outfileName,\n src,\n serve: shouldServe,\n } = argv;\n if (outfileName) {\n validateOutfileName(outfileName as string);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n const rootDir =\n src.indexOf('/') === -1 ? '.' : src.substring(0, src.lastIndexOf('/') + 1);\n const outfilePath = getOutfilePath(dist, outfileName as string);\n\n const buildSnap = async (path?: string, logMessage?: string) => {\n if (logMessage !== undefined) {\n console.log(logMessage);\n }\n\n try {\n await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);\n\n if (manifest) {\n await manifestHandler(argv);\n }\n\n if (shouldEval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n } catch (error) {\n logError(\n `Error ${\n path === undefined\n ? 'during initial build'\n : `while processing \"${path}\"`\n }.`,\n error,\n );\n }\n };\n\n chokidar\n .watch(rootDir, {\n ignoreInitial: true,\n ignored: [\n '**/node_modules/**',\n `**/${dist}/**`,\n `**/test/**`,\n `**/tests/**`,\n `**/*.test.js`,\n `**/*.test.ts`,\n /* istanbul ignore next */\n (str: string) => str !== '.' && str.startsWith('.'),\n ],\n })\n\n .on('ready', async () => {\n await buildSnap();\n if (shouldServe) {\n await serve(argv);\n }\n })\n .on('add', (path) => buildSnap(path, `File added: ${path}`))\n .on('change', (path) => buildSnap(path, `File changed: ${path}`))\n .on('unlink', (path) => console.log(`File removed: ${path}`))\n .on('error', (error: Error) => {\n logError(`Watcher error: ${error.message}`, error);\n })\n\n .add(rootDir);\n\n console.log(`Watching '${rootDir}' for changes...`);\n}\n"]}
|
package/dist/utils/misc.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare function sanitizeInputs(argv: Arguments): void;
|
|
|
32
32
|
* @param msg - The error message.
|
|
33
33
|
* @param err - The original error.
|
|
34
34
|
*/
|
|
35
|
-
export declare function logError(msg: string, err?: Error): void;
|
|
35
|
+
export declare function logError(msg: string | null, err?: Error): void;
|
|
36
36
|
/**
|
|
37
37
|
* Logs a warning message to console.
|
|
38
38
|
*
|
package/dist/utils/misc.js
CHANGED
|
@@ -99,10 +99,15 @@ exports.sanitizeInputs = sanitizeInputs;
|
|
|
99
99
|
* @param err - The original error.
|
|
100
100
|
*/
|
|
101
101
|
function logError(msg, err) {
|
|
102
|
-
|
|
102
|
+
if (msg !== null) {
|
|
103
|
+
console.error(msg);
|
|
104
|
+
}
|
|
103
105
|
if (err && global.snaps.verboseErrors) {
|
|
104
106
|
console.error(err);
|
|
105
107
|
}
|
|
108
|
+
if (msg === null && (!err || (err && !global.snaps.verboseErrors))) {
|
|
109
|
+
console.error('Unknown error.');
|
|
110
|
+
}
|
|
106
111
|
}
|
|
107
112
|
exports.logError = logError;
|
|
108
113
|
/**
|
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,wCAgBC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAAC,KAAc;IACnD,I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AAC,gBAAgB,CAAC,CAAC;KACjC;AACH,CAAC;AAZD,4BAYC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,GAAW,EAAE,KAAa;IACnD,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE;QACzC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,IAAI,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE;YACvC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACtB;KACF;AACH,CAAC;AAPD,gCAOC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,GAAW,EACX,GAAU,EACV,YAAqB;IAErB,IAAI,eAAe,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACzB,eAAe,IAAI,GAAG,CAAC;KACxB;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,qEAAqE;QACrE,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';\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"shasum": "node ./scripts/computeSnapShasum.js",
|
|
18
|
-
"build:tsc": "tsc --project ./tsconfig.
|
|
18
|
+
"build:tsc": "tsc --project ./tsconfig.build.json",
|
|
19
19
|
"build:chmod": "chmod +x ./dist/main.js",
|
|
20
20
|
"build:readme": "node ./scripts/updateReadme.js",
|
|
21
21
|
"build": "yarn build:tsc && yarn build:post-tsc",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build:clean": "yarn clean && yarn build",
|
|
24
24
|
"build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
|
|
25
25
|
"clean": "rimraf '*.tsbuildinfo' 'dist/*'",
|
|
26
|
-
"test": "jest",
|
|
26
|
+
"test": "jest && yarn posttest",
|
|
27
27
|
"posttest": "jest-it-up",
|
|
28
28
|
"test:watch": "yarn test --watch",
|
|
29
29
|
"test:ci": "yarn test",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
44
44
|
"@babel/preset-env": "^7.16.7",
|
|
45
45
|
"@babel/preset-typescript": "^7.16.7",
|
|
46
|
-
"@metamask/
|
|
47
|
-
"@metamask/snaps-
|
|
48
|
-
"@metamask/utils": "^3.3.
|
|
46
|
+
"@metamask/snaps-browserify-plugin": "^0.24.1",
|
|
47
|
+
"@metamask/snaps-utils": "^0.24.1",
|
|
48
|
+
"@metamask/utils": "^3.3.1",
|
|
49
49
|
"babelify": "^10.0.0",
|
|
50
50
|
"browserify": "^17.0.0",
|
|
51
51
|
"chokidar": "^3.5.2",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"@typescript-eslint/eslint-plugin": "^5.19.0",
|
|
74
74
|
"@typescript-eslint/parser": "^5.19.0",
|
|
75
75
|
"clipboardy": "^2.3.0",
|
|
76
|
+
"deepmerge": "^4.2.2",
|
|
76
77
|
"eslint": "^7.30.0",
|
|
77
78
|
"eslint-config-prettier": "^8.3.0",
|
|
78
79
|
"eslint-plugin-import": "^2.23.4",
|
package/dist/__mocks__/fs.d.ts
DELETED
package/dist/__mocks__/fs.js
DELETED
package/dist/__mocks__/fs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/__mocks__/fs.ts"],"names":[],"mappings":";AAAA,iCAA+B;AAG/B,iBAAS,IAAI,cAAM,EAAE,CAAC","sourcesContent":["import { Volume } from 'memfs';\n\n// Note: `Volume` implements most of the `fs` API, but not all.\nexport = new Volume();\n"]}
|
package/dist/test-utils/fs.d.ts
DELETED
package/dist/test-utils/fs.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resetFileSystem = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
jest.mock('fs');
|
|
6
|
-
/**
|
|
7
|
-
* Clears out all the files in the in-memory file system, and writes the default
|
|
8
|
-
* folders to mimic the on-disk current working directory, including sub-folders.
|
|
9
|
-
*/
|
|
10
|
-
async function resetFileSystem() {
|
|
11
|
-
await fs_1.promises.rm(process.cwd(), { recursive: true, force: true });
|
|
12
|
-
// Using relative path with memfs won't work since process.cwd() specifies the cwd of the on-disk file system
|
|
13
|
-
// This recursively creates the current working directory in the memfs volume.
|
|
14
|
-
// Ref. https://github.com/streamich/memfs/blob/master/docs/relative-paths.md
|
|
15
|
-
await fs_1.promises.mkdir(process.cwd(), { recursive: true });
|
|
16
|
-
}
|
|
17
|
-
exports.resetFileSystem = resetFileSystem;
|
|
18
|
-
//# sourceMappingURL=fs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/test-utils/fs.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AAEpC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEhB;;;GAGG;AACI,KAAK,UAAU,eAAe;IACnC,MAAM,aAAE,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7D,6GAA6G;IAC7G,8EAA8E;IAC9E,6EAA6E;IAC7E,MAAM,aAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACrD,CAAC;AAPD,0CAOC","sourcesContent":["import { promises as fs } from 'fs';\n\njest.mock('fs');\n\n/**\n * Clears out all the files in the in-memory file system, and writes the default\n * folders to mimic the on-disk current working directory, including sub-folders.\n */\nexport async function resetFileSystem() {\n await fs.rm(process.cwd(), { recursive: true, force: true });\n\n // Using relative path with memfs won't work since process.cwd() specifies the cwd of the on-disk file system\n // This recursively creates the current working directory in the memfs volume.\n // Ref. https://github.com/streamich/memfs/blob/master/docs/relative-paths.md\n await fs.mkdir(process.cwd(), { recursive: true });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './fs';
|
package/dist/test-utils/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./fs"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test-utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAqB","sourcesContent":["export * from './fs';\n"]}
|