@metamask/snaps-cli 0.18.1 → 0.19.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/dist/builders.d.ts +0 -1
- package/dist/builders.js +0 -6
- package/dist/builders.js.map +1 -1
- package/dist/cmds/build/buildHandler.js +7 -6
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/bundle.js +3 -2
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/build/index.js +0 -1
- package/dist/cmds/build/index.js.map +1 -1
- package/dist/cmds/eval/evalHandler.d.ts +1 -1
- package/dist/cmds/eval/evalHandler.js +8 -9
- package/dist/cmds/eval/evalHandler.js.map +1 -1
- package/dist/cmds/eval/index.js +1 -1
- package/dist/cmds/eval/index.js.map +1 -1
- package/dist/cmds/init/initHandler.js +8 -9
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +1 -1
- package/dist/cmds/init/initUtils.js +12 -12
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/manifestHandler.d.ts +1 -10
- package/dist/cmds/manifest/manifestHandler.js +23 -191
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/serve/serveHandler.js +6 -2
- package/dist/cmds/serve/serveHandler.js.map +1 -1
- package/dist/cmds/watch/index.js +0 -1
- package/dist/cmds/watch/index.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +6 -5
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/tsconfig.json +6 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/misc.d.ts +0 -1
- package/dist/utils/misc.js +1 -3
- package/dist/utils/misc.js.map +1 -1
- package/package.json +4 -5
- package/dist/cmds/eval/eval-worker.d.ts +0 -1
- package/dist/cmds/eval/eval-worker.js +0 -33
- package/dist/cmds/eval/eval-worker.js.map +0 -1
- package/dist/cmds/eval/mock.d.ts +0 -14
- package/dist/cmds/eval/mock.js +0 -98
- package/dist/cmds/eval/mock.js.map +0 -1
- package/dist/cmds/eval/workerEval.d.ts +0 -8
- package/dist/cmds/eval/workerEval.js +0 -37
- package/dist/cmds/eval/workerEval.js.map +0 -1
- package/dist/utils/fs.d.ts +0 -24
- package/dist/utils/fs.js +0 -66
- package/dist/utils/fs.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/validate-fs.d.ts +0 -35
- package/dist/utils/validate-fs.js +0 -69
- package/dist/utils/validate-fs.js.map +0 -1
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const utils_2 = require("../../utils");
|
|
18
|
-
const errorPrefix = 'Manifest Error: ';
|
|
19
|
-
const ManifestSortOrder = {
|
|
20
|
-
version: 1,
|
|
21
|
-
proposedName: 2,
|
|
22
|
-
description: 2,
|
|
23
|
-
repository: 3,
|
|
24
|
-
source: 4,
|
|
25
|
-
initialPermissions: 5,
|
|
26
|
-
manifestVersion: 6,
|
|
27
|
-
};
|
|
3
|
+
exports.manifestHandler = void 0;
|
|
4
|
+
const snap_utils_1 = require("@metamask/snap-utils");
|
|
5
|
+
const ERROR_PREFIX = 'Manifest Error: ';
|
|
28
6
|
/**
|
|
29
7
|
* Validates a snap.manifest.json file. Attempts to fix the manifest and write
|
|
30
8
|
* the fixed version to disk if `writeManifest` is true. Throws if validation
|
|
@@ -33,186 +11,40 @@ const ManifestSortOrder = {
|
|
|
33
11
|
* @param argv - The Yargs `argv` object.
|
|
34
12
|
* @param argv.writeManifest - Whether to write the fixed manifest to disk.
|
|
35
13
|
*/
|
|
36
|
-
async function manifestHandler({ writeManifest
|
|
37
|
-
var _a, _b, _c;
|
|
38
|
-
let didUpdate = false;
|
|
39
|
-
let hasWarnings = false;
|
|
40
|
-
const unvalidatedManifest = await readSnapJsonFile(utils_1.NpmSnapFileNames.Manifest);
|
|
41
|
-
const iconPath = unvalidatedManifest && typeof unvalidatedManifest === 'object'
|
|
42
|
-
? (_c = (_b = (_a = unvalidatedManifest.source) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.npm) === null || _c === void 0 ? void 0 : _c.iconPath
|
|
43
|
-
: undefined;
|
|
44
|
-
const snapFiles = {
|
|
45
|
-
manifest: unvalidatedManifest,
|
|
46
|
-
packageJson: await readSnapJsonFile(utils_1.NpmSnapFileNames.PackageJson),
|
|
47
|
-
sourceCode: await getSnapSourceCode(unvalidatedManifest),
|
|
48
|
-
svgIcon: iconPath && (await fs_1.promises.readFile(iconPath, 'utf8')),
|
|
49
|
-
};
|
|
50
|
-
let manifest;
|
|
14
|
+
async function manifestHandler({ writeManifest }) {
|
|
51
15
|
try {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const partiallyValidatedFiles = snapFiles;
|
|
58
|
-
let isInvalid = true;
|
|
59
|
-
const maxAttempts = Object.keys(utils_1.SnapValidationFailureReason).length;
|
|
60
|
-
// Attempt to fix all fixable validation failure reasons. All such reasons
|
|
61
|
-
// are enumerated by the SnapValidationFailureReason enum, so we only
|
|
62
|
-
for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {
|
|
63
|
-
manifest = fixManifest(partiallyValidatedFiles, error);
|
|
64
|
-
try {
|
|
65
|
-
(0, utils_1.validateNpmSnapManifest)(Object.assign(Object.assign({}, partiallyValidatedFiles), { manifest }), errorPrefix);
|
|
66
|
-
isInvalid = false;
|
|
67
|
-
}
|
|
68
|
-
catch (nextValidationError) {
|
|
69
|
-
/* istanbul ignore next: this should be impossible */
|
|
70
|
-
if (!(nextValidationError instanceof utils_1.ProgrammaticallyFixableSnapError) ||
|
|
71
|
-
(attempts === maxAttempts && !isInvalid)) {
|
|
72
|
-
throw new Error(`Internal Error: Failed to fix manifest. This is a bug, please report it. Reason:\n${error.message}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
didUpdate = true;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// TypeScript doesn't see that the 'manifest' variable must be of type
|
|
83
|
-
// SnapManifest at this point, so we cast it.
|
|
84
|
-
const validatedManifest = manifest;
|
|
85
|
-
// Check presence of recommended keys
|
|
86
|
-
const recommendedFields = ['repository'];
|
|
87
|
-
const missingRecommendedFields = recommendedFields.filter((key) => !validatedManifest[key]);
|
|
88
|
-
if (missingRecommendedFields.length > 0) {
|
|
89
|
-
logManifestWarning(`Missing recommended package.json properties:\n${missingRecommendedFields.reduce((allMissing, currentField) => {
|
|
90
|
-
return `${allMissing}\t${currentField}\n`;
|
|
91
|
-
}, '')}`);
|
|
92
|
-
}
|
|
93
|
-
// Validation complete, finish work and notify user.
|
|
94
|
-
if (writeManifest) {
|
|
95
|
-
try {
|
|
96
|
-
await fs_1.promises.writeFile(utils_1.NpmSnapFileNames.Manifest, `${JSON.stringify(getWritableManifest(validatedManifest), null, 2)}\n`);
|
|
97
|
-
if (didUpdate) {
|
|
98
|
-
console.log(`Manifest: Updated snap.manifest.json`);
|
|
99
|
-
}
|
|
16
|
+
const { warnings, errors } = await (0, snap_utils_1.checkManifest)(process.cwd(), Boolean(writeManifest));
|
|
17
|
+
if (!writeManifest && errors.length > 0) {
|
|
18
|
+
console.error(`${ERROR_PREFIX}The manifest is invalid.`);
|
|
19
|
+
errors.forEach(logManifestError);
|
|
20
|
+
process.exit(1);
|
|
100
21
|
}
|
|
101
|
-
|
|
102
|
-
|
|
22
|
+
if (warnings.length > 0) {
|
|
23
|
+
console.log('Manifest Warning: Validation of snap.manifest.json completed with warnings.');
|
|
24
|
+
warnings.forEach(logManifestWarning);
|
|
103
25
|
}
|
|
104
26
|
}
|
|
105
|
-
if (hasWarnings) {
|
|
106
|
-
console.log(`Manifest Warning: Validation of snap.manifest.json completed with warnings. See above.`);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
console.log(`Manifest Success: Validated snap.manifest.json!`);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Logs a manifest warning, if `suppressWarnings` is not enabled.
|
|
113
|
-
*
|
|
114
|
-
* @param message - The message to log.
|
|
115
|
-
*/
|
|
116
|
-
function logManifestWarning(message) {
|
|
117
|
-
if (!global.snaps.suppressWarnings) {
|
|
118
|
-
hasWarnings = true;
|
|
119
|
-
console.warn(`Manifest Warning: ${message}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
exports.manifestHandler = manifestHandler;
|
|
124
|
-
/**
|
|
125
|
-
* Utility function for reading `package.json` or the Snap manifest file.
|
|
126
|
-
* These are assumed to be in the current working directory.
|
|
127
|
-
*
|
|
128
|
-
* @param snapJsonFileName - The name of the file to read.
|
|
129
|
-
* @returns The parsed JSON file.
|
|
130
|
-
*/
|
|
131
|
-
async function readSnapJsonFile(snapJsonFileName) {
|
|
132
|
-
try {
|
|
133
|
-
return await (0, utils_2.readJsonFile)(snapJsonFileName);
|
|
134
|
-
}
|
|
135
27
|
catch (error) {
|
|
136
|
-
|
|
137
|
-
throw new Error(`${errorPrefix}Could not find '${snapJsonFileName}'. Please ensure that ` +
|
|
138
|
-
`you are running the command in the project root directory.`);
|
|
139
|
-
}
|
|
140
|
-
throw new Error(`${errorPrefix}${error.message}`);
|
|
28
|
+
throw new Error(`${ERROR_PREFIX}${error}`);
|
|
141
29
|
}
|
|
142
30
|
}
|
|
31
|
+
exports.manifestHandler = manifestHandler;
|
|
143
32
|
/**
|
|
144
|
-
*
|
|
145
|
-
* bundle source file location and read the file.
|
|
146
|
-
*
|
|
147
|
-
* @param manifest - The unvalidated Snap manifest file contents.
|
|
148
|
-
* @returns The contents of the bundle file, if any.
|
|
149
|
-
*/
|
|
150
|
-
async function getSnapSourceCode(manifest) {
|
|
151
|
-
var _a, _b, _c;
|
|
152
|
-
if (manifest && typeof manifest === 'object' && !Array.isArray(manifest)) {
|
|
153
|
-
/* istanbul ignore next: optional chaining */
|
|
154
|
-
const sourceFilePath = (_c = (_b = (_a = manifest.source) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.npm) === null || _c === void 0 ? void 0 : _c.filePath;
|
|
155
|
-
try {
|
|
156
|
-
return sourceFilePath
|
|
157
|
-
? await fs_1.promises.readFile(sourceFilePath, 'utf8')
|
|
158
|
-
: undefined;
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
throw new Error(`Manifest Error: Failed to read Snap bundle file: ${error.message}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Given the relevant Snap files (manifest, `package.json`, and bundle) and a
|
|
168
|
-
* Snap manifest validation error, fixes the fault in the manifest that caused
|
|
169
|
-
* the error.
|
|
33
|
+
* Logs a manifest warning, if `suppressWarnings` is not enabled.
|
|
170
34
|
*
|
|
171
|
-
* @param
|
|
172
|
-
* @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.
|
|
173
|
-
* @returns A copy of the manifest file where the cause of the error is fixed.
|
|
35
|
+
* @param message - The message to log.
|
|
174
36
|
*/
|
|
175
|
-
function
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
switch (error.reason) {
|
|
179
|
-
case utils_1.SnapValidationFailureReason.NameMismatch:
|
|
180
|
-
manifestCopy.source.location.npm.packageName = packageJson.name;
|
|
181
|
-
break;
|
|
182
|
-
case utils_1.SnapValidationFailureReason.VersionMismatch:
|
|
183
|
-
manifestCopy.version = packageJson.version;
|
|
184
|
-
break;
|
|
185
|
-
case utils_1.SnapValidationFailureReason.RepositoryMismatch:
|
|
186
|
-
manifestCopy.repository = packageJson.repository
|
|
187
|
-
? (0, utils_2.deepClone)(packageJson.repository)
|
|
188
|
-
: null;
|
|
189
|
-
break;
|
|
190
|
-
case utils_1.SnapValidationFailureReason.ShasumMismatch:
|
|
191
|
-
manifestCopy.source.shasum = (0, utils_1.getSnapSourceShasum)(sourceCode);
|
|
192
|
-
break;
|
|
193
|
-
/* istanbul ignore next */
|
|
194
|
-
default:
|
|
195
|
-
// eslint-disable-next-line no-case-declarations
|
|
196
|
-
const failureReason = error.reason;
|
|
197
|
-
throw new Error(`Unrecognized validation failure reason: '${failureReason}'`);
|
|
37
|
+
function logManifestWarning(message) {
|
|
38
|
+
if (!global.snaps.suppressWarnings) {
|
|
39
|
+
console.log(`Manifest Warning: ${message}`);
|
|
198
40
|
}
|
|
199
|
-
return manifestCopy;
|
|
200
41
|
}
|
|
201
42
|
/**
|
|
202
|
-
*
|
|
203
|
-
* `repository` field if it is falsy (it may be `null`).
|
|
43
|
+
* Logs a manifest error.
|
|
204
44
|
*
|
|
205
|
-
* @param
|
|
206
|
-
* @returns The disk-ready manifest.
|
|
45
|
+
* @param message - The message to log.
|
|
207
46
|
*/
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
return Object.keys(repository ? Object.assign(Object.assign({}, remaining), { repository }) : remaining)
|
|
211
|
-
.sort((a, b) => ManifestSortOrder[a] - ManifestSortOrder[b])
|
|
212
|
-
.reduce((outManifest, key) => {
|
|
213
|
-
outManifest[key] = manifest[key];
|
|
214
|
-
return outManifest;
|
|
215
|
-
}, {});
|
|
47
|
+
function logManifestError(message) {
|
|
48
|
+
console.error(`${ERROR_PREFIX}${message}`);
|
|
216
49
|
}
|
|
217
|
-
exports.getWritableManifest = getWritableManifest;
|
|
218
50
|
//# sourceMappingURL=manifestHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../../src/cmds/manifest/manifestHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2BAAoC;AAEpC,uEASqD;AACrD,uCAAsD;AAGtD,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAEvC,MAAM,iBAAiB,GAAuC;IAC5D,OAAO,EAAE,CAAC;IACV,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC;IACT,kBAAkB,EAAE,CAAC;IACrB,eAAe,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CAAC,EACpC,aAAa,GACH;;IACV,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,MAAM,mBAAmB,GAAG,MAAM,gBAAgB,CAAC,wBAAgB,CAAC,QAAQ,CAAC,CAAC;IAE9E,MAAM,QAAQ,GACZ,mBAAmB,IAAI,OAAO,mBAAmB,KAAK,QAAQ;QAC5D,CAAC,CAAC,MAAA,MAAA,MAAC,mBAA6C,CAAC,MAAM,0CAAE,QAAQ,0CAAE,GAAG,0CAChE,QAAQ;QACd,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,SAAS,GAAyB;QACtC,QAAQ,EAAE,mBAAmB;QAC7B,WAAW,EAAE,MAAM,gBAAgB,CAAC,w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AG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,EAAkB,CAAC,CAAC;AAC3B,CAAC;AAZD,kDAYC","sourcesContent":["import { promises as fs } from 'fs';\nimport type { Json, SnapManifest } from '@metamask/snap-controllers';\nimport {\n NpmSnapFileNames,\n UnvalidatedSnapFiles,\n validateNpmSnap,\n validateNpmSnapManifest,\n getSnapSourceShasum,\n ProgrammaticallyFixableSnapError,\n SnapValidationFailureReason,\n SnapFiles,\n} from '@metamask/snap-controllers/dist/snaps/utils';\nimport { deepClone, readJsonFile } from '../../utils';\nimport { YargsArgs } from '../../types/yargs';\n\nconst errorPrefix = 'Manifest Error: ';\n\nconst ManifestSortOrder: Record<keyof SnapManifest, number> = {\n version: 1,\n proposedName: 2,\n description: 2,\n repository: 3,\n source: 4,\n initialPermissions: 5,\n manifestVersion: 6,\n};\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({\n writeManifest,\n}: YargsArgs): Promise<void> {\n let didUpdate = false;\n let hasWarnings = false;\n\n const unvalidatedManifest = await readSnapJsonFile(NpmSnapFileNames.Manifest);\n\n const iconPath =\n unvalidatedManifest && typeof unvalidatedManifest === 'object'\n ? (unvalidatedManifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath\n : undefined;\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: unvalidatedManifest,\n packageJson: await readSnapJsonFile(NpmSnapFileNames.PackageJson),\n sourceCode: await getSnapSourceCode(unvalidatedManifest),\n svgIcon: iconPath && (await fs.readFile(iconPath, 'utf8')),\n };\n\n let manifest: SnapManifest | undefined;\n try {\n ({ manifest } = validateNpmSnap(snapFiles, errorPrefix));\n } catch (error) {\n if (writeManifest && error instanceof ProgrammaticallyFixableSnapError) {\n // If we get here, the files at least have the correct shape.\n const partiallyValidatedFiles = snapFiles as SnapFiles;\n\n let isInvalid = true;\n const maxAttempts = Object.keys(SnapValidationFailureReason).length;\n\n // Attempt to fix all fixable validation failure reasons. All such reasons\n // are enumerated by the SnapValidationFailureReason enum, so we only\n for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {\n manifest = fixManifest(partiallyValidatedFiles, error);\n\n try {\n validateNpmSnapManifest(\n { ...partiallyValidatedFiles, manifest },\n errorPrefix,\n );\n\n isInvalid = false;\n } catch (nextValidationError) {\n /* istanbul ignore next: this should be impossible */\n if (\n !(\n nextValidationError instanceof ProgrammaticallyFixableSnapError\n ) ||\n (attempts === maxAttempts && !isInvalid)\n ) {\n throw new Error(\n `Internal Error: Failed to fix manifest. This is a bug, please report it. Reason:\\n${error.message}`,\n );\n }\n }\n }\n\n didUpdate = true;\n } else {\n throw error;\n }\n }\n\n // TypeScript doesn't see that the 'manifest' variable must be of type\n // SnapManifest at this point, so we cast it.\n const validatedManifest = manifest as SnapManifest;\n\n // Check presence of recommended keys\n const recommendedFields = ['repository'] as const;\n\n const missingRecommendedFields = recommendedFields.filter(\n (key) => !validatedManifest[key],\n );\n\n if (missingRecommendedFields.length > 0) {\n logManifestWarning(\n `Missing recommended package.json properties:\\n${missingRecommendedFields.reduce(\n (allMissing, currentField) => {\n return `${allMissing}\\t${currentField}\\n`;\n },\n '',\n )}`,\n );\n }\n\n // Validation complete, finish work and notify user.\n\n if (writeManifest) {\n try {\n await fs.writeFile(\n NpmSnapFileNames.Manifest,\n `${JSON.stringify(getWritableManifest(validatedManifest), null, 2)}\\n`,\n );\n\n if (didUpdate) {\n console.log(`Manifest: Updated snap.manifest.json`);\n }\n } catch (error) {\n throw new Error(\n `${errorPrefix}Failed to update snap.manifest.json: ${error.message}`,\n );\n }\n }\n\n if (hasWarnings) {\n console.log(\n `Manifest Warning: Validation of snap.manifest.json completed with warnings. See above.`,\n );\n } else {\n console.log(`Manifest Success: Validated snap.manifest.json!`);\n }\n\n /**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\n function logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n hasWarnings = true;\n console.warn(`Manifest Warning: ${message}`);\n }\n }\n}\n\n/**\n * Utility function for reading `package.json` or the Snap manifest file.\n * These are assumed to be in the current working directory.\n *\n * @param snapJsonFileName - The name of the file to read.\n * @returns The parsed JSON file.\n */\nasync function readSnapJsonFile(\n snapJsonFileName: NpmSnapFileNames,\n): Promise<Json> {\n try {\n return await readJsonFile(snapJsonFileName);\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `${errorPrefix}Could not find '${snapJsonFileName}'. Please ensure that ` +\n `you are running the command in the project root directory.`,\n );\n }\n throw new Error(`${errorPrefix}${error.message}`);\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the bundle file, if any.\n */\nasync function getSnapSourceCode(manifest: Json): Promise<string | undefined> {\n if (manifest && typeof manifest === 'object' && !Array.isArray(manifest)) {\n /* istanbul ignore next: optional chaining */\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n try {\n return sourceFilePath\n ? await fs.readFile(sourceFilePath, 'utf8')\n : undefined;\n } catch (error) {\n throw new Error(\n `Manifest Error: Failed to read Snap bundle file: ${error.message}`,\n );\n }\n }\n return undefined;\n}\n\n/**\n * Given the relevant Snap files (manifest, `package.json`, and bundle) and a\n * Snap manifest validation error, fixes the fault in the manifest that caused\n * the error.\n *\n * @param snapFiles - The contents of all Snap files.\n * @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.\n * @returns A copy of the manifest file where the cause of the error is fixed.\n */\nfunction fixManifest(\n snapFiles: SnapFiles,\n error: ProgrammaticallyFixableSnapError,\n): SnapManifest {\n const { manifest, packageJson, sourceCode } = snapFiles;\n const manifestCopy = deepClone(manifest);\n\n switch (error.reason) {\n case SnapValidationFailureReason.NameMismatch:\n manifestCopy.source.location.npm.packageName = packageJson.name;\n break;\n\n case SnapValidationFailureReason.VersionMismatch:\n manifestCopy.version = packageJson.version;\n break;\n\n case SnapValidationFailureReason.RepositoryMismatch:\n manifestCopy.repository = packageJson.repository\n ? deepClone(packageJson.repository)\n : null;\n break;\n\n case SnapValidationFailureReason.ShasumMismatch:\n manifestCopy.source.shasum = getSnapSourceShasum(sourceCode);\n break;\n\n /* istanbul ignore next */\n default:\n // eslint-disable-next-line no-case-declarations\n const failureReason: never = error.reason;\n throw new Error(\n `Unrecognized validation failure reason: '${failureReason}'`,\n );\n }\n\n return manifestCopy;\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n return (\n Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[]\n )\n .sort((a, b) => ManifestSortOrder[a] - ManifestSortOrder[b])\n .reduce((outManifest, key) => {\n (outManifest as any)[key] = manifest[key];\n return outManifest;\n }, {} as SnapManifest);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../../src/cmds/manifest/manifestHandler.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AAGrD,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,0BAAa,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/snap-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 snap_utils_1 = require("@metamask/snap-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, snap_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, {
|
|
@@ -31,6 +31,10 @@ async function serve(argv) {
|
|
|
31
31
|
key: 'Cache-Control',
|
|
32
32
|
value: 'no-cache',
|
|
33
33
|
},
|
|
34
|
+
{
|
|
35
|
+
key: 'Access-Control-Allow-Origin',
|
|
36
|
+
value: '*',
|
|
37
|
+
},
|
|
34
38
|
],
|
|
35
39
|
},
|
|
36
40
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serveHandler.js","sourceRoot":"","sources":["../../../src/cmds/serve/serveHandler.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,kEAAyC;
|
|
1
|
+
{"version":3,"file":"serveHandler.js","sourceRoot":"","sources":["../../../src/cmds/serve/serveHandler.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,kEAAyC;AACzC,qDAAuD;AAEvD,6CAA8E;AAE9E;;;;;;;GAOG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAErC,MAAM,IAAA,4BAAe,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/snap-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"]}
|
package/dist/cmds/watch/index.js
CHANGED
|
@@ -16,7 +16,6 @@ module.exports = {
|
|
|
16
16
|
.option('outfileName', builders_1.default.outfileName)
|
|
17
17
|
.option('sourceMaps', builders_1.default.sourceMaps)
|
|
18
18
|
.option('stripComments', builders_1.default.stripComments)
|
|
19
|
-
.option('transformHtmlComments', builders_1.default.transformHtmlComments)
|
|
20
19
|
.option('transpilationMode', builders_1.default.transpilationMode)
|
|
21
20
|
.option('depsToTranspile', builders_1.default.depsToTranspile)
|
|
22
21
|
.option('manifest', builders_1.default.manifest)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/watch/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,0CAA6D;AAC7D,iDAAuC;AAEvC,iBAAS;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,kBAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/watch/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,0CAA6D;AAC7D,iDAAuC;AAEvC,iBAAS;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,YAAY,EAAE,kBAAQ,CAAC,UAAU,CAAC;aACzC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,mBAAmB,EAAE,kBAAQ,CAAC,iBAAiB,CAAC;aACvD,MAAM,CAAC,iBAAiB,EAAE,kBAAQ,CAAC,eAAe,CAAC;aACnD,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;aAC/C,MAAM,CAAC,OAAO,EAAE,kBAAQ,CAAC,KAAK,CAAC;aAC/B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC;aACpC,OAAO,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;aAC/C,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,mCAA2B,EAAC,IAAW,CAAC,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,IAAA,oBAAK,EAAC,IAAI,CAAC;CAC1C,CAAC","sourcesContent":["import yargs from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { processInvalidTranspilation } from '../build/utils';\nimport { watch } from './watchHandler';\n\nexport = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: (argv: YargsArgs) => watch(argv),\n};\n"]}
|
|
@@ -5,6 +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 snap_utils_1 = require("@metamask/snap-utils");
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
9
10
|
const bundle_1 = require("../build/bundle");
|
|
10
11
|
const evalHandler_1 = require("../eval/evalHandler");
|
|
@@ -25,12 +26,12 @@ const serveHandler_1 = require("../serve/serveHandler");
|
|
|
25
26
|
async function watch(argv) {
|
|
26
27
|
const { dist, eval: shouldEval, manifest, outfileName, src, serve: shouldServe, } = argv;
|
|
27
28
|
if (outfileName) {
|
|
28
|
-
(0,
|
|
29
|
+
(0, snap_utils_1.validateOutfileName)(outfileName);
|
|
29
30
|
}
|
|
30
|
-
await (0,
|
|
31
|
-
await (0,
|
|
31
|
+
await (0, snap_utils_1.validateFilePath)(src);
|
|
32
|
+
await (0, snap_utils_1.validateDirPath)(dist, true);
|
|
32
33
|
const rootDir = src.indexOf('/') === -1 ? '.' : src.substring(0, src.lastIndexOf('/') + 1);
|
|
33
|
-
const outfilePath = (0,
|
|
34
|
+
const outfilePath = (0, snap_utils_1.getOutfilePath)(dist, outfileName);
|
|
34
35
|
const buildSnap = async (path, logMessage) => {
|
|
35
36
|
if (logMessage !== undefined) {
|
|
36
37
|
console.log(logMessage);
|
|
@@ -41,7 +42,7 @@ async function watch(argv) {
|
|
|
41
42
|
await (0, manifestHandler_1.manifestHandler)(argv);
|
|
42
43
|
}
|
|
43
44
|
if (shouldEval) {
|
|
44
|
-
await (0, evalHandler_1.
|
|
45
|
+
await (0, evalHandler_1.evalHandler)(Object.assign(Object.assign({}, argv), { bundle: outfilePath }));
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watchHandler.js","sourceRoot":"","sources":["../../../src/cmds/watch/watchHandler.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;
|
|
1
|
+
{"version":3,"file":"watchHandler.js","sourceRoot":"","sources":["../../../src/cmds/watch/watchHandler.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,qDAK8B;AAE9B,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,gCAAmB,EAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,IAAA,6BAAgB,EAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAA,4BAAe,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,2BAAc,EAAC,IAAI,EAAE,WAAqB,CAAC,CAAC;IAEhE,MAAM,SAAS,GAAG,KAAK,EAAE,IAAa,EAAE,UAAmB,EAAE,EAAE;QAC7D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AS,CAAC,IAAI,EAAE,iBAAiB,IAAI,EAAE,CAAC,CAAC;SAChE,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;SAC5D,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,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/snap-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/tsconfig.json
CHANGED
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -14,9 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./fs"), exports);
|
|
18
17
|
__exportStar(require("./misc"), exports);
|
|
19
18
|
__exportStar(require("./readline"), exports);
|
|
20
19
|
__exportStar(require("./snap-config"), exports);
|
|
21
|
-
__exportStar(require("./validate-fs"), exports);
|
|
22
20
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,6CAA2B;AAC3B,gDAA8B","sourcesContent":["export * from './misc';\nexport * from './readline';\nexport * from './snap-config';\n"]}
|
package/dist/utils/misc.d.ts
CHANGED
package/dist/utils/misc.js
CHANGED
|
@@ -3,12 +3,10 @@ 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.trimPathString = exports.writeError = exports.logWarning = exports.logError = exports.sanitizeInputs = exports.booleanStringToBoolean = exports.setSnapGlobals = exports.CONFIG_FILE = exports.permRequestKeys =
|
|
6
|
+
exports.trimPathString = exports.writeError = exports.logWarning = exports.logError = exports.sanitizeInputs = exports.booleanStringToBoolean = exports.setSnapGlobals = exports.CONFIG_FILE = exports.permRequestKeys = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const utils_1 = require("@metamask/utils");
|
|
10
|
-
const rfdc_1 = __importDefault(require("rfdc"));
|
|
11
|
-
exports.deepClone = (0, rfdc_1.default)({ proto: false, circles: false });
|
|
12
10
|
exports.permRequestKeys = [
|
|
13
11
|
'@context',
|
|
14
12
|
'id',
|
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,2CAA8C;
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAw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ACX,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,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 { 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, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message.\n * @param error - The original error.\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param msg - The error message.\n * @param err - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-skunkworks/issues/81\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
47
47
|
"@babel/preset-env": "^7.16.7",
|
|
48
48
|
"@babel/preset-typescript": "^7.16.7",
|
|
49
|
-
"@metamask/snap-
|
|
50
|
-
"@metamask/snaps-browserify-plugin": "^0.
|
|
49
|
+
"@metamask/snap-utils": "^0.19.0",
|
|
50
|
+
"@metamask/snaps-browserify-plugin": "^0.19.0",
|
|
51
51
|
"@metamask/utils": "^2.0.0",
|
|
52
52
|
"babelify": "^10.0.0",
|
|
53
53
|
"browserify": "^17.0.0",
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
"init-package-json": "^1.10.3",
|
|
56
56
|
"is-url": "^1.2.4",
|
|
57
57
|
"mkdirp": "^1.0.4",
|
|
58
|
-
"rfdc": "^1.3.0",
|
|
59
58
|
"serve-handler": "^6.1.1",
|
|
60
59
|
"ses": "^0.15.15",
|
|
61
60
|
"slash": "^3.0.0",
|
|
@@ -97,7 +96,7 @@
|
|
|
97
96
|
"rimraf": "^3.0.2",
|
|
98
97
|
"ts-auto-guard": "^2.3.0",
|
|
99
98
|
"ts-jest": "^27.1.5",
|
|
100
|
-
"ts-node": "^
|
|
99
|
+
"ts-node": "^10.7.0",
|
|
101
100
|
"tsc-watch": "^4.5.0",
|
|
102
101
|
"typescript": "^4.4.0"
|
|
103
102
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'ses/lockdown';
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
// eslint-disable-next-line import/no-unassigned-import
|
|
6
|
-
require("ses/lockdown");
|
|
7
|
-
const mock_1 = require("./mock");
|
|
8
|
-
lockdown({
|
|
9
|
-
consoleTaming: 'unsafe',
|
|
10
|
-
errorTaming: 'unsafe',
|
|
11
|
-
mathTaming: 'unsafe',
|
|
12
|
-
dateTaming: 'unsafe',
|
|
13
|
-
overrideTaming: 'severe',
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Get mock endowments that don't do anything. This is useful for running the
|
|
17
|
-
* eval, for snaps that try to communicate with the extension on initialisation,
|
|
18
|
-
* for example.
|
|
19
|
-
*
|
|
20
|
-
* @returns The mock endowments.
|
|
21
|
-
*/
|
|
22
|
-
function getMockEndowments() {
|
|
23
|
-
const endowments = (0, mock_1.generateMockEndowments)();
|
|
24
|
-
return Object.assign(Object.assign({}, endowments), { window: endowments, self: endowments });
|
|
25
|
-
}
|
|
26
|
-
const snapFilePath = process.argv[2];
|
|
27
|
-
const snapModule = { exports: {} };
|
|
28
|
-
new Compartment(Object.assign(Object.assign({}, getMockEndowments()), { module: snapModule, exports: snapModule.exports })).evaluate((0, fs_1.readFileSync)(snapFilePath, 'utf8'));
|
|
29
|
-
if (!((_a = snapModule.exports) === null || _a === void 0 ? void 0 : _a.onRpcRequest)) {
|
|
30
|
-
console.warn(`The Snap doesn't have an "onRpcRequest" export defined.`);
|
|
31
|
-
}
|
|
32
|
-
setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
|
|
33
|
-
//# sourceMappingURL=eval-worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAClC,uDAAuD;AACvD,wBAAsB;AACtB,iCAAgD;AAIhD,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;CACzB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,IAAA,6BAAsB,GAAE,CAAC;IAC5C,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,IAChB;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,IAAI,WAAW,iCACV,iBAAiB,EAAE,KACtB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,CAAC,OAAO,IAC3B,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhD,IAAI,CAAC,CAAA,MAAA,UAAU,CAAC,OAAO,0CAAE,YAAY,CAAA,EAAE;IACrC,OAAO,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;CACzE;AAED,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B","sourcesContent":["import { readFileSync } from 'fs';\n// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\nimport { generateMockEndowments } from './mock';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n});\n\n/**\n * Get mock endowments that don't do anything. This is useful for running the\n * eval, for snaps that try to communicate with the extension on initialisation,\n * for example.\n *\n * @returns The mock endowments.\n */\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n self: endowments,\n };\n}\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nnew Compartment({\n ...getMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n}).evaluate(readFileSync(snapFilePath, 'utf8'));\n\nif (!snapModule.exports?.onRpcRequest) {\n console.warn(`The Snap doesn't have an \"onRpcRequest\" export defined.`);\n}\n\nsetTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n"]}
|
package/dist/cmds/eval/mock.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const ALL_APIS: string[];
|
|
2
|
-
/**
|
|
3
|
-
* Check if a value is a constructor.
|
|
4
|
-
*
|
|
5
|
-
* @param value - The value to check.
|
|
6
|
-
* @returns `true` if the value is a constructor, or `false` otherwise.
|
|
7
|
-
*/
|
|
8
|
-
export declare const isConstructor: (value: any) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.
|
|
11
|
-
*
|
|
12
|
-
* @returns A map of endowments.
|
|
13
|
-
*/
|
|
14
|
-
export declare const generateMockEndowments: () => Record<string, any>;
|