@metamask/snaps-cli 0.7.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -1
- package/README.md +67 -25
- package/dist/builders.d.ts +16 -8
- package/dist/builders.js +66 -41
- package/dist/builders.js.map +1 -1
- package/dist/cli.js +5 -4
- package/dist/cli.js.map +1 -1
- package/dist/cmds/build/buildHandler.js +1 -1
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/bundle.d.ts +9 -7
- package/dist/cmds/build/bundle.js +35 -31
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/build/index.js +10 -4
- package/dist/cmds/build/index.js.map +1 -1
- package/dist/cmds/build/utils.d.ts +59 -0
- package/dist/cmds/build/utils.js +152 -0
- package/dist/cmds/build/utils.js.map +1 -0
- package/dist/cmds/eval/evalHandler.d.ts +1 -1
- package/dist/cmds/eval/evalHandler.js +1 -2
- package/dist/cmds/eval/evalHandler.js.map +1 -1
- package/dist/cmds/eval/index.d.ts +1 -1
- package/dist/cmds/index.d.ts +2 -7
- package/dist/cmds/init/init-template.json +2 -2
- package/dist/cmds/init/initHandler.d.ts +2 -0
- package/dist/cmds/init/initHandler.js +11 -6
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.js +4 -4
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/index.js +1 -1
- package/dist/cmds/manifest/index.js.map +1 -1
- package/dist/cmds/serve/index.js +2 -2
- package/dist/cmds/serve/index.js.map +1 -1
- package/dist/cmds/watch/index.js +11 -1
- package/dist/cmds/watch/index.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +32 -19
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/utils/fs.js +1 -1
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/misc.d.ts +10 -1
- package/dist/utils/misc.js +27 -4
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/snap-config.__GENERATED__.d.ts +2 -0
- package/dist/utils/snap-config.__GENERATED__.js +18 -0
- package/dist/utils/snap-config.__GENERATED__.js.map +1 -0
- package/dist/utils/snap-config.d.ts +8 -1
- package/dist/utils/snap-config.js +39 -32
- package/dist/utils/snap-config.js.map +1 -1
- package/package.json +11 -7
- package/dist/cmds/build/bundleUtils.d.ts +0 -42
- package/dist/cmds/build/bundleUtils.js +0 -95
- package/dist/cmds/build/bundleUtils.js.map +0 -1
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.postProcess = exports.closeBundleStream = exports.createBundleStream = void 0;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const strip_comments_1 = __importDefault(require("@nodefactory/strip-comments"));
|
|
9
|
-
const misc_1 = require("../../utils/misc");
|
|
10
|
-
/**
|
|
11
|
-
* Opens a stream to write the destination file path.
|
|
12
|
-
*
|
|
13
|
-
* @param dest - The output file path
|
|
14
|
-
* @returns - The stream
|
|
15
|
-
*/
|
|
16
|
-
function createBundleStream(dest) {
|
|
17
|
-
const stream = fs_1.createWriteStream(dest, {
|
|
18
|
-
autoClose: false,
|
|
19
|
-
encoding: 'utf8',
|
|
20
|
-
});
|
|
21
|
-
stream.on('error', (err) => {
|
|
22
|
-
misc_1.writeError('Write error:', err.message, err, dest);
|
|
23
|
-
});
|
|
24
|
-
return stream;
|
|
25
|
-
}
|
|
26
|
-
exports.createBundleStream = createBundleStream;
|
|
27
|
-
/**
|
|
28
|
-
* Postprocesses the bundle string and closes the write stream.
|
|
29
|
-
*
|
|
30
|
-
* @param stream - The write stream
|
|
31
|
-
* @param bundleString - The bundle string
|
|
32
|
-
* @param options - post process options
|
|
33
|
-
* @param options.stripComments
|
|
34
|
-
*/
|
|
35
|
-
async function closeBundleStream({ bundleError, bundleBuffer, bundleStream, src, dest, resolve, argv, }) {
|
|
36
|
-
if (bundleError) {
|
|
37
|
-
await misc_1.writeError('Build error:', bundleError.message, bundleError);
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
bundleStream.end(postProcess(bundleBuffer ? bundleBuffer.toString() : null, {
|
|
41
|
-
stripComments: argv.stripComments,
|
|
42
|
-
}));
|
|
43
|
-
if (bundleBuffer) {
|
|
44
|
-
console.log(`Build success: '${src}' bundled as '${dest}'!`);
|
|
45
|
-
}
|
|
46
|
-
resolve(true);
|
|
47
|
-
}
|
|
48
|
-
catch (closeError) {
|
|
49
|
-
await misc_1.writeError('Write error:', closeError.message, closeError, dest);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.closeBundleStream = closeBundleStream;
|
|
53
|
-
/**
|
|
54
|
-
* Postprocesses a JavaScript bundle string such that it can be evaluated in SES.
|
|
55
|
-
* Currently:
|
|
56
|
-
* - converts certain dot notation to string notation (for indexing)
|
|
57
|
-
* - makes all direct calls to eval indirect
|
|
58
|
-
* - wraps original bundle in anonymous function
|
|
59
|
-
* - handles certain Babel-related edge cases
|
|
60
|
-
*
|
|
61
|
-
* @param bundleString - The bundle string
|
|
62
|
-
* @param options - post process options
|
|
63
|
-
* @param options.stripComments
|
|
64
|
-
* @returns - The postprocessed bundle string
|
|
65
|
-
*/
|
|
66
|
-
function postProcess(bundleString, options = {}) {
|
|
67
|
-
if (typeof bundleString !== 'string') {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
let processedString = bundleString.trim();
|
|
71
|
-
if (options.stripComments) {
|
|
72
|
-
processedString = strip_comments_1.default(processedString);
|
|
73
|
-
}
|
|
74
|
-
// stuff.eval(otherStuff) => (1, stuff.eval)(otherStuff)
|
|
75
|
-
processedString = processedString.replace(/((?:\b[\w\d]*[\])]?\.)+eval)(\([^)]*\))/gu, '(1, $1)$2');
|
|
76
|
-
// if we don't do the above, the below causes syntax errors if it encounters
|
|
77
|
-
// things of the form: "something.eval(stuff)"
|
|
78
|
-
// eval(stuff) => (1, eval)(stuff)
|
|
79
|
-
processedString = processedString.replace(/(\b)(eval)(\([^)]*\))/gu, '$1(1, $2)$3');
|
|
80
|
-
// Browserify provides the Buffer global as an argument to modules that use
|
|
81
|
-
// it, but this does not work in SES. Since we pass in Buffer as an endowment,
|
|
82
|
-
// we can simply remove the argument.
|
|
83
|
-
processedString = processedString.replace(/^\(function \(Buffer\)\{$/gmu, '(function (){');
|
|
84
|
-
if (processedString.length === 0) {
|
|
85
|
-
throw new Error(`Bundled code is empty after postprocessing.`);
|
|
86
|
-
}
|
|
87
|
-
// handle some cases by declaring missing globals
|
|
88
|
-
// Babel regeneratorRuntime
|
|
89
|
-
if (processedString.indexOf('regeneratorRuntime') !== -1) {
|
|
90
|
-
processedString = `var regeneratorRuntime;\n${processedString}`;
|
|
91
|
-
}
|
|
92
|
-
return processedString;
|
|
93
|
-
}
|
|
94
|
-
exports.postProcess = postProcess;
|
|
95
|
-
//# sourceMappingURL=bundleUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundleUtils.js","sourceRoot":"","sources":["../../../src/cmds/build/bundleUtils.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAuC;AACvC,iFAAwD;AACxD,2CAA8C;AAG9C;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,MAAM,GAAG,sBAAiB,CAAC,IAAI,EAAE;QACrC,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,iBAAU,CAAC,cAAc,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AACh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B,aAAa,CACd,CAAC;IAEF,2EAA2E;IAC3E,8EAA8E;IAC9E,qCAAqC;IACrC,eAAe,GAAG,eAAe,CAAC,OAAO,CACvC,8BAA8B,EAC9B,eAAe,CAChB,CAAC;IAEF,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAChE;IAED,iDAAiD;IACjD,2BAA2B;IAC3B,IAAI,eAAe,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,EAAE;QACxD,eAAe,GAAG,4BAA4B,eAAe,EAAE,CAAC;KACjE;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AA/CD,kCA+CC","sourcesContent":["import { createWriteStream } from 'fs';\nimport stripComments from '@nodefactory/strip-comments';\nimport { writeError } from '../../utils/misc';\nimport { Option, YargsArgs } from '../../types/yargs';\n\n/**\n * Opens a stream to write the destination file path.\n *\n * @param dest - The output file path\n * @returns - The stream\n */\nexport function createBundleStream(dest: string): NodeJS.WritableStream {\n const stream = createWriteStream(dest, {\n autoClose: false,\n encoding: 'utf8',\n });\n stream.on('error', (err) => {\n writeError('Write error:', err.message, err, dest);\n });\n return stream;\n}\n\ntype CloseStreamArgs = {\n bundleError: Error;\n bundleBuffer: Buffer;\n bundleStream: NodeJS.WritableStream;\n src: string;\n dest: string;\n resolve: (value: boolean) => void;\n argv: YargsArgs;\n};\n\n/**\n * Postprocesses the bundle string and closes the write stream.\n *\n * @param stream - The write stream\n * @param bundleString - The bundle string\n * @param options - post process options\n * @param options.stripComments\n */\nexport async function closeBundleStream({\n bundleError,\n bundleBuffer,\n bundleStream,\n src,\n dest,\n resolve,\n argv,\n}: CloseStreamArgs) {\n if (bundleError) {\n await writeError('Build error:', bundleError.message, bundleError);\n }\n\n try {\n bundleStream.end(\n postProcess(bundleBuffer ? bundleBuffer.toString() : null, {\n stripComments: argv.stripComments,\n }) as string,\n );\n\n if (bundleBuffer) {\n console.log(`Build success: '${src}' bundled as '${dest}'!`);\n }\n resolve(true);\n } catch (closeError) {\n await writeError('Write error:', closeError.message, closeError, dest);\n }\n}\n\n/**\n * Postprocesses a JavaScript bundle string such that it can be evaluated in SES.\n * Currently:\n * - converts certain dot notation to string notation (for indexing)\n * - makes all direct calls to eval indirect\n * - wraps original bundle in anonymous function\n * - handles certain Babel-related edge cases\n *\n * @param bundleString - The bundle string\n * @param options - post process options\n * @param options.stripComments\n * @returns - The postprocessed bundle string\n */\nexport function postProcess(\n bundleString: string | null,\n options: Partial<Option> = {},\n): string | null {\n if (typeof bundleString !== 'string') {\n return null;\n }\n\n let processedString = bundleString.trim();\n\n if (options.stripComments) {\n processedString = stripComments(processedString);\n }\n\n // stuff.eval(otherStuff) => (1, stuff.eval)(otherStuff)\n processedString = processedString.replace(\n /((?:\\b[\\w\\d]*[\\])]?\\.)+eval)(\\([^)]*\\))/gu,\n '(1, $1)$2',\n );\n\n // if we don't do the above, the below causes syntax errors if it encounters\n // things of the form: \"something.eval(stuff)\"\n // eval(stuff) => (1, eval)(stuff)\n processedString = processedString.replace(\n /(\\b)(eval)(\\([^)]*\\))/gu,\n '$1(1, $2)$3',\n );\n\n // Browserify provides the Buffer global as an argument to modules that use\n // it, but this does not work in SES. Since we pass in Buffer as an endowment,\n // we can simply remove the argument.\n processedString = processedString.replace(\n /^\\(function \\(Buffer\\)\\{$/gmu,\n '(function (){',\n );\n\n if (processedString.length === 0) {\n throw new Error(`Bundled code is empty after postprocessing.`);\n }\n\n // handle some cases by declaring missing globals\n // Babel regeneratorRuntime\n if (processedString.indexOf('regeneratorRuntime') !== -1) {\n processedString = `var regeneratorRuntime;\\n${processedString}`;\n }\n\n return processedString;\n}\n"]}
|