@metamask/snaps-cli 0.15.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/builders.d.ts +6 -0
- package/dist/builders.js +20 -1
- package/dist/builders.js.map +1 -1
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +8 -0
- package/dist/cli.js.map +1 -1
- package/dist/cmds/build/buildHandler.d.ts +4 -4
- package/dist/cmds/build/buildHandler.js +5 -5
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/bundle.d.ts +4 -2
- package/dist/cmds/build/bundle.js +15 -14
- package/dist/cmds/build/bundle.js.map +1 -1
- package/dist/cmds/build/utils.d.ts +21 -8
- package/dist/cmds/build/utils.js +22 -9
- package/dist/cmds/build/utils.js.map +1 -1
- package/dist/cmds/eval/eval-worker.js +17 -14
- package/dist/cmds/eval/eval-worker.js.map +1 -1
- package/dist/cmds/eval/evalHandler.d.ts +7 -0
- package/dist/cmds/eval/evalHandler.js +7 -0
- package/dist/cmds/eval/evalHandler.js.map +1 -1
- package/dist/cmds/eval/mock.d.ts +11 -0
- package/dist/cmds/eval/mock.js +39 -4
- package/dist/cmds/eval/mock.js.map +1 -1
- package/dist/cmds/eval/workerEval.d.ts +7 -0
- package/dist/cmds/eval/workerEval.js +11 -6
- package/dist/cmds/eval/workerEval.js.map +1 -1
- package/dist/cmds/init/index.js +14 -6
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/init-template.json +5 -1
- package/dist/cmds/init/initHandler.d.ts +11 -0
- package/dist/cmds/init/initHandler.js +39 -4
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +21 -4
- package/dist/cmds/init/initUtils.js +55 -7
- 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/manifest/manifestHandler.d.ts +1 -0
- package/dist/cmds/manifest/manifestHandler.js +24 -7
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/serve/index.js +2 -44
- package/dist/cmds/serve/index.js.map +1 -1
- package/dist/cmds/serve/serveHandler.d.ts +10 -0
- package/dist/cmds/serve/serveHandler.js +51 -0
- package/dist/cmds/serve/serveHandler.js.map +1 -0
- package/dist/cmds/serve/serveUtils.d.ts +17 -0
- package/dist/cmds/serve/serveUtils.js +17 -0
- package/dist/cmds/serve/serveUtils.js.map +1 -1
- package/dist/cmds/watch/index.js +3 -0
- package/dist/cmds/watch/index.js.map +1 -1
- package/dist/cmds/watch/watchHandler.d.ts +4 -4
- package/dist/cmds/watch/watchHandler.js +13 -7
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/utils/fs.d.ts +5 -5
- package/dist/utils/fs.js +5 -5
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/misc.d.ts +16 -13
- package/dist/utils/misc.js +16 -13
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/readline.d.ts +25 -0
- package/dist/utils/readline.js +25 -0
- package/dist/utils/readline.js.map +1 -1
- package/dist/utils/snap-config.d.ts +15 -0
- package/dist/utils/snap-config.js +15 -1
- package/dist/utils/snap-config.js.map +1 -1
- package/dist/utils/validate-fs.d.ts +19 -18
- package/dist/utils/validate-fs.js +21 -20
- package/dist/utils/validate-fs.js.map +1 -1
- package/package.json +16 -15
- package/CHANGELOG.md +0 -217
package/README.md
CHANGED
|
@@ -34,6 +34,8 @@ Options:
|
|
|
34
34
|
Examples:
|
|
35
35
|
mm-snap init Initialize a snap project in the
|
|
36
36
|
current directory
|
|
37
|
+
mm-snap init --template javascript Initialize a snap JavaScript project
|
|
38
|
+
in the current directory
|
|
37
39
|
mm-snap build -s src/index.js -d out Build 'src/index.js' as
|
|
38
40
|
'./out/bundle.js'
|
|
39
41
|
mm-snap build -s src/index.js -d out -n Build 'src/index.js' as
|
|
@@ -112,7 +114,7 @@ The defaults can be overwritten using the `snap.config.json` [config file](#conf
|
|
|
112
114
|
|
|
113
115
|
### Configuration File
|
|
114
116
|
|
|
115
|
-
`snap.config.js`
|
|
117
|
+
`snap.config.js` should be placed in the project root directory. It can override cli options - the property `cliOptions` should have string keys matching command arguments. Values become argument defaults, which can still be overridden on the command line.
|
|
116
118
|
|
|
117
119
|
Example:
|
|
118
120
|
|
|
@@ -126,7 +128,7 @@ module.exports = {
|
|
|
126
128
|
};
|
|
127
129
|
```
|
|
128
130
|
|
|
129
|
-
|
|
131
|
+
If you want to customize the Browserify build process, you can provide `bundlerCustomizer` property. It's a function that takes one argument - [browserify object](https://github.com/browserify/browserify#api-example) which we use internally to bundle the snap. You can transform it in any way you want, for example adding plugins.
|
|
130
132
|
|
|
131
133
|
Example:
|
|
132
134
|
|
package/dist/builders.d.ts
CHANGED
|
@@ -16,11 +16,17 @@ export declare type SnapsCliBuilders = {
|
|
|
16
16
|
readonly depsToTranspile: Readonly<Options>;
|
|
17
17
|
readonly verboseErrors: Readonly<Options>;
|
|
18
18
|
readonly writeManifest: Readonly<Options>;
|
|
19
|
+
readonly serve: Readonly<Options>;
|
|
20
|
+
readonly template: Readonly<Options>;
|
|
19
21
|
};
|
|
20
22
|
export declare enum TranspilationModes {
|
|
21
23
|
localAndDeps = "localAndDeps",
|
|
22
24
|
localOnly = "localOnly",
|
|
23
25
|
none = "none"
|
|
24
26
|
}
|
|
27
|
+
export declare enum TemplateType {
|
|
28
|
+
TypeScript = "typescript",
|
|
29
|
+
JavaScript = "javascript"
|
|
30
|
+
}
|
|
25
31
|
declare const builders: SnapsCliBuilders;
|
|
26
32
|
export default builders;
|
package/dist/builders.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TranspilationModes = void 0;
|
|
3
|
+
exports.TemplateType = exports.TranspilationModes = void 0;
|
|
4
4
|
var TranspilationModes;
|
|
5
5
|
(function (TranspilationModes) {
|
|
6
6
|
TranspilationModes["localAndDeps"] = "localAndDeps";
|
|
7
7
|
TranspilationModes["localOnly"] = "localOnly";
|
|
8
8
|
TranspilationModes["none"] = "none";
|
|
9
9
|
})(TranspilationModes = exports.TranspilationModes || (exports.TranspilationModes = {}));
|
|
10
|
+
var TemplateType;
|
|
11
|
+
(function (TemplateType) {
|
|
12
|
+
TemplateType["TypeScript"] = "typescript";
|
|
13
|
+
TemplateType["JavaScript"] = "javascript";
|
|
14
|
+
})(TemplateType = exports.TemplateType || (exports.TemplateType = {}));
|
|
10
15
|
const builders = {
|
|
11
16
|
bundle: {
|
|
12
17
|
alias: 'b',
|
|
@@ -124,6 +129,20 @@ const builders = {
|
|
|
124
129
|
demandOption: false,
|
|
125
130
|
default: true,
|
|
126
131
|
},
|
|
132
|
+
serve: {
|
|
133
|
+
describe: 'Serve Snap file(s) locally for testing',
|
|
134
|
+
type: 'boolean',
|
|
135
|
+
demandOption: false,
|
|
136
|
+
default: true,
|
|
137
|
+
},
|
|
138
|
+
template: {
|
|
139
|
+
alias: 't',
|
|
140
|
+
describe: 'Specify which template to use (TypeScript or JavaScript)',
|
|
141
|
+
type: 'string',
|
|
142
|
+
demandOption: false,
|
|
143
|
+
default: TemplateType.TypeScript,
|
|
144
|
+
choices: Object.values(TemplateType),
|
|
145
|
+
},
|
|
127
146
|
};
|
|
128
147
|
exports.default = builders;
|
|
129
148
|
//# sourceMappingURL=builders.js.map
|
package/dist/builders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;AAuBA,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,mDAA6B,CAAA;IAC7B,6CAAuB,CAAA;IACvB,mCAAa,CAAA;AACf,CAAC,EAJW,kBAAkB,GAAlB,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f,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,yCAAyC;QACnD,YAAY,EAAE,KAAK;KACpB;IAED,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,yBAAyB;QACnC,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,aAAa,EAAE;QACb,QAAQ,EAAE,kDAAkD;QAC5D,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,KAAK,EAAE;QACL,QAAQ,EAAE,wCAAwC;QAClD,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,QAAQ,EAAE;QACR,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,0DAA0D;QACpE,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,YAAY,CAAC,UAAU;QAChC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;KACrC;CACF,CAAC;AAEF,kBAAe,QAAQ,CAAC","sourcesContent":["import { Options } from 'yargs';\n\nexport type SnapsCliBuilders = {\n readonly bundle: Readonly<Options>;\n readonly dist: Readonly<Options>;\n readonly eval: Readonly<Options>;\n readonly manifest: Readonly<Options>;\n readonly outfileName: Readonly<Options>;\n readonly port: Readonly<Options>;\n readonly root: Readonly<Options>;\n readonly sourceMaps: Readonly<Options>;\n readonly src: Readonly<Options>;\n readonly stripComments: Readonly<Options>;\n readonly suppressWarnings: Readonly<Options>;\n readonly transpilationMode: Readonly<Options>;\n readonly transformHtmlComments: Readonly<Options>;\n readonly depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly template: Readonly<Options>;\n};\n\nexport enum TranspilationModes {\n localAndDeps = 'localAndDeps',\n localOnly = 'localOnly',\n none = 'none',\n}\n\nexport enum TemplateType {\n TypeScript = 'typescript',\n JavaScript = 'javascript',\n}\n\nconst builders: SnapsCliBuilders = {\n bundle: {\n alias: 'b',\n describe: 'Snap bundle file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist/bundle.js',\n },\n\n dist: {\n alias: 'd',\n describe: 'Output directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist',\n },\n\n eval: {\n alias: 'e',\n describe: 'Attempt to evaluate Snap bundle in SES',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n manifest: {\n alias: 'm',\n describe: 'Validate snap.manifest.json',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n port: {\n alias: 'p',\n describe: 'Local server port for testing',\n type: 'number',\n demandOption: true,\n default: 8081,\n coerce: (arg: unknown) => {\n const port = Number.parseInt(String(arg), 10);\n if (Number.isNaN(port)) {\n throw new Error(`Invalid port: ${arg}`);\n }\n return port;\n },\n },\n\n outfileName: {\n alias: 'n',\n describe: 'Output file name',\n type: 'string',\n demandOption: false,\n default: 'bundle.js',\n },\n\n root: {\n alias: 'r',\n describe: 'Server root directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: '.',\n },\n\n sourceMaps: {\n describe: 'Whether builds include sourcemaps',\n type: 'boolean',\n demandOption: false,\n default: false,\n },\n\n src: {\n alias: 's',\n describe: 'Source file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'src/index.js',\n },\n\n stripComments: {\n alias: 'strip',\n describe: 'Whether to remove code comments from the build output',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n suppressWarnings: {\n type: 'boolean',\n describe: 'Whether to suppress warnings',\n demandOption: false,\n default: false,\n },\n\n transpilationMode: {\n type: 'string',\n describe:\n 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',\n demandOption: false,\n default: TranspilationModes.localOnly,\n choices: Object.values(TranspilationModes),\n },\n\n transformHtmlComments: {\n type: 'boolean',\n describe:\n 'Whether to break up HTML comment tokens wherever they appear in your source code.',\n demandOption: true,\n default: true,\n },\n\n depsToTranspile: {\n type: 'array',\n describe: 'Transpile only the listed dependencies.',\n demandOption: false,\n },\n\n verboseErrors: {\n type: 'boolean',\n describe: 'Display original errors',\n demandOption: false,\n default: true,\n },\n\n writeManifest: {\n describe: 'Make necessary changes to the Snap manifest file',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n serve: {\n describe: 'Serve Snap file(s) locally for testing',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n template: {\n alias: 't',\n describe: 'Specify which template to use (TypeScript or JavaScript)',\n type: 'string',\n demandOption: false,\n default: TemplateType.TypeScript,\n choices: Object.values(TemplateType),\n },\n};\n\nexport default builders;\n"]}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The main CLI entry point function. This processes the command line args, and
|
|
3
|
+
* runs the appropriate function.
|
|
4
|
+
*
|
|
5
|
+
* @param argv - The raw command line arguments, i.e., `process.argv`.
|
|
6
|
+
* @param commands - The list of commands to use.
|
|
7
|
+
*/
|
|
1
8
|
export declare function cli(argv: string[], commands: any): void;
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,13 @@ exports.cli = void 0;
|
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
8
|
const builders_1 = __importDefault(require("./builders"));
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* The main CLI entry point function. This processes the command line args, and
|
|
12
|
+
* runs the appropriate function.
|
|
13
|
+
*
|
|
14
|
+
* @param argv - The raw command line arguments, i.e., `process.argv`.
|
|
15
|
+
* @param commands - The list of commands to use.
|
|
16
|
+
*/
|
|
10
17
|
function cli(argv, commands) {
|
|
11
18
|
const rawArgv = argv.slice(2);
|
|
12
19
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
@@ -14,6 +21,7 @@ function cli(argv, commands) {
|
|
|
14
21
|
.scriptName('mm-snap')
|
|
15
22
|
.usage('Usage: $0 <command> [options]')
|
|
16
23
|
.example('$0 init', `\tInitialize a snap project in the current directory`)
|
|
24
|
+
.example('$0 init --template javascript', `\tInitialize a snap JavaScript project in the current directory`)
|
|
17
25
|
.example('$0 build -s src/index.js -d out', `\tBuild 'src/index.js' as './out/bundle.js'`)
|
|
18
26
|
.example('$0 build -s src/index.js -d out -n snap.js', `\tBuild 'src/index.js' as './out/snap.js'`)
|
|
19
27
|
.example('$0 serve -r out', `\tServe files in './out' on port 8080`)
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAEzC,0DAAkC;AAClC,mCAMiB;AAEjB,SAAgB,GAAG,CAAC,IAAc,EAAE,QAAa;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,oEAAoE;IACpE,IAAA,eAAK,EAAC,OAAO,CAAC;SACX,UAAU,CAAC,SAAS,CAAC;SACrB,KAAK,CAAC,+BAA+B,CAAC;SAEtC,OAAO,CAAC,SAAS,EAAE,sDAAsD,CAAC;SAC1E,OAAO,CACN,iCAAiC,EACjC,6CAA6C,CAC9C;SACA,OAAO,CACN,4CAA4C,EAC5C,2CAA2C,CAC5C;SACA,OAAO,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;SACnE,OAAO,CAAC,yBAAyB,EAAE,uCAAuC,CAAC;SAC3E,OAAO,CACN,iCAAiC,EACjC,gGAAgG,CACjG;SAEA,OAAO,CAAC,QAAQ,CAAC;SAEjB,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;SAE/C,MAAM,CAAC,kBAAkB,EAAE,kBAAQ,CAAC,gBAAgB,CAAC;SAErD,MAAM,EAAE;QAET,gEAAgE;QAChE,+EAA+E;QAC/E,0FAA0F;SACzF,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE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,gGAAgG,CACjG;SAEA,OAAO,CAAC,QAAQ,CAAC;SAEjB,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;SAE/C,MAAM,CAAC,kBAAkB,EAAE,kBAAQ,CAAC,gBAAgB,CAAC;SAErD,MAAM,EAAE;QAET,gEAAgE;QAChE,+EAA+E;QAC/E,0FAA0F;SACzF,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE,aAA+B,EAAE,EAAE;QACzD,IAAA,mBAAW,EAAC,IAAA,kBAAU,GAAE,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC7D,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;QAC1B,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAQ,EACT,IAAI,CACL;SAEA,IAAI,CAAC,CAAC,GAAW,EAAE,GAAU,EAAE,MAAM,EAAE,EAAE;QACxC,IAAA,gBAAQ,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC;SAED,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAE1D,IAAI,EAAE;SACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAxDD,kBAwDC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\nimport builders from './builders';\nimport {\n applyConfig,\n loadConfig,\n sanitizeInputs,\n setSnapGlobals,\n logError,\n} from './utils';\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport function cli(argv: string[], commands: any): void {\n const rawArgv = argv.slice(2);\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n yargs(rawArgv)\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize a snap project in the current directory`)\n .example(\n '$0 init --template javascript',\n `\\tInitialize a snap JavaScript project in the current directory`,\n )\n .example(\n '$0 build -s src/index.js -d out',\n `\\tBuild 'src/index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s src/index.js -d out -n snap.js',\n `\\tBuild 'src/index.js' as './out/snap.js'`,\n )\n .example('$0 serve -r out', `\\tServe files in './out' on port 8080`)\n .example('$0 serve -r out -p 9000', `\\tServe files in './out' on port 9000`)\n .example(\n '$0 watch -s src/index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`,\n )\n\n .command(commands)\n\n .option('verboseErrors', builders.verboseErrors)\n\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n // Typecast: The @types/yargs type for .middleware is incorrect.\n // yargs middleware functions receive the yargs instance as a second parameter.\n // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation\n .middleware(\n ((yargsArgv: Arguments, yargsInstance: typeof yargsType) => {\n applyConfig(loadConfig(), rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((msg: string, err: Error, _yargs) => {\n logError(msg, err);\n process.exitCode = 1;\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}
|
|
@@ -5,9 +5,9 @@ import { YargsArgs } from '../../types/yargs';
|
|
|
5
5
|
*
|
|
6
6
|
* Creates destination directory if it doesn't exist.
|
|
7
7
|
*
|
|
8
|
-
* @param argv -
|
|
9
|
-
* @param argv.src - The source file path
|
|
10
|
-
* @param argv.dist - The output directory path
|
|
11
|
-
* @param argv.outfileName - The output file name
|
|
8
|
+
* @param argv - Argv from Yargs.
|
|
9
|
+
* @param argv.src - The source file path.
|
|
10
|
+
* @param argv.dist - The output directory path.
|
|
11
|
+
* @param argv.outfileName - The output file name.
|
|
12
12
|
*/
|
|
13
13
|
export declare function build(argv: YargsArgs): Promise<void>;
|
|
@@ -11,10 +11,10 @@ const bundle_1 = require("./bundle");
|
|
|
11
11
|
*
|
|
12
12
|
* Creates destination directory if it doesn't exist.
|
|
13
13
|
*
|
|
14
|
-
* @param argv -
|
|
15
|
-
* @param argv.src - The source file path
|
|
16
|
-
* @param argv.dist - The output directory path
|
|
17
|
-
* @param argv.outfileName - The output file name
|
|
14
|
+
* @param argv - Argv from Yargs.
|
|
15
|
+
* @param argv.src - The source file path.
|
|
16
|
+
* @param argv.dist - The output directory path.
|
|
17
|
+
* @param argv.outfileName - The output file name.
|
|
18
18
|
*/
|
|
19
19
|
async function build(argv) {
|
|
20
20
|
const { src, dist, outfileName } = argv;
|
|
@@ -26,7 +26,7 @@ async function build(argv) {
|
|
|
26
26
|
const outfilePath = (0, utils_1.getOutfilePath)(dist, outfileName);
|
|
27
27
|
const result = await (0, bundle_1.bundle)(src, outfilePath, argv, (0, utils_1.loadConfig)().bundlerCustomizer);
|
|
28
28
|
if (result && argv.eval) {
|
|
29
|
-
await (0, evalHandler_1.snapEval)({
|
|
29
|
+
await (0, evalHandler_1.snapEval)(Object.assign(Object.assign({}, argv), { bundle: outfilePath }));
|
|
30
30
|
}
|
|
31
31
|
if (argv.manifest) {
|
|
32
32
|
await (0, manifestHandler_1.manifestHandler)(argv);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AACA,uCAMqB;AACrB,qDAA+C;AAC/C,iEAA8D;AAC9D,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,2BAAmB,EAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,IAAA,wBAAgB,E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AI,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,sBAsBC","sourcesContent":["import { YargsArgs } from '../../types/yargs';\nimport {\n getOutfilePath,\n loadConfig,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '../../utils';\nimport { snapEval } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\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 snapEval({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="watchify" />
|
|
1
2
|
import { BrowserifyObject } from 'browserify';
|
|
2
3
|
import { YargsArgs } from '../../types/yargs';
|
|
3
4
|
/**
|
|
@@ -5,10 +6,11 @@ import { YargsArgs } from '../../types/yargs';
|
|
|
5
6
|
*
|
|
6
7
|
* @param src - The source file path.
|
|
7
8
|
* @param dest - The destination file path.
|
|
8
|
-
* @param argv -
|
|
9
|
+
* @param argv - Arguments as an object generated by `yargs`.
|
|
9
10
|
* @param argv.sourceMaps - Whether to output sourcemaps.
|
|
10
11
|
* @param argv.stripComments - Whether to remove comments from code.
|
|
11
12
|
* @param argv.transpilationMode - The Babel transpilation mode.
|
|
12
|
-
* @param bundlerTransform
|
|
13
|
+
* @param bundlerTransform - An optional function which can be used to transform
|
|
14
|
+
* the Browserify instance, e.g., adding a custom transform or plugin.
|
|
13
15
|
*/
|
|
14
16
|
export declare function bundle(src: string, dest: string, argv: YargsArgs, bundlerTransform?: (bundler: BrowserifyObject) => void): Promise<boolean>;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.bundle = void 0;
|
|
7
7
|
const browserify_1 = __importDefault(require("browserify"));
|
|
8
|
+
const snaps_browserify_plugin_1 = __importDefault(require("@metamask/snaps-browserify-plugin"));
|
|
8
9
|
const builders_1 = require("../../builders");
|
|
9
10
|
const utils_1 = require("./utils");
|
|
10
11
|
// We need to statically import all Browserify transforms and all Babel presets
|
|
@@ -15,22 +16,25 @@ const utils_1 = require("./utils");
|
|
|
15
16
|
*
|
|
16
17
|
* @param src - The source file path.
|
|
17
18
|
* @param dest - The destination file path.
|
|
18
|
-
* @param argv -
|
|
19
|
+
* @param argv - Arguments as an object generated by `yargs`.
|
|
19
20
|
* @param argv.sourceMaps - Whether to output sourcemaps.
|
|
20
21
|
* @param argv.stripComments - Whether to remove comments from code.
|
|
21
22
|
* @param argv.transpilationMode - The Babel transpilation mode.
|
|
22
|
-
* @param bundlerTransform
|
|
23
|
+
* @param bundlerTransform - An optional function which can be used to transform
|
|
24
|
+
* the Browserify instance, e.g., adding a custom transform or plugin.
|
|
23
25
|
*/
|
|
24
26
|
function bundle(src, dest, argv, bundlerTransform) {
|
|
25
27
|
const { sourceMaps: debug, transpilationMode } = argv;
|
|
26
28
|
const babelifyOptions = (0, utils_1.processDependencies)(argv);
|
|
27
29
|
return new Promise((resolve, _reject) => {
|
|
28
|
-
const bundler = (0, browserify_1.default)(src, {
|
|
30
|
+
const bundler = (0, browserify_1.default)(src, {
|
|
31
|
+
debug,
|
|
32
|
+
extensions: ['.js', '.ts'],
|
|
33
|
+
// Standalone is required to properly support Snaps using module.exports
|
|
34
|
+
standalone: '<snap>',
|
|
35
|
+
});
|
|
29
36
|
if (transpilationMode !== builders_1.TranspilationModes.none) {
|
|
30
|
-
bundler.transform(require('babelify'), {
|
|
31
|
-
global: transpilationMode === builders_1.TranspilationModes.localAndDeps,
|
|
32
|
-
extensions: ['.js', '.ts'],
|
|
33
|
-
presets: [
|
|
37
|
+
bundler.transform(require('babelify'), Object.assign({ global: transpilationMode === builders_1.TranspilationModes.localAndDeps, extensions: ['.js', '.ts'], presets: [
|
|
34
38
|
require('@babel/preset-typescript'),
|
|
35
39
|
[
|
|
36
40
|
require('@babel/preset-env'),
|
|
@@ -40,19 +44,16 @@ function bundle(src, dest, argv, bundlerTransform) {
|
|
|
40
44
|
},
|
|
41
45
|
},
|
|
42
46
|
],
|
|
43
|
-
],
|
|
44
|
-
plugins: [
|
|
47
|
+
], plugins: [
|
|
45
48
|
require('@babel/plugin-transform-runtime'),
|
|
46
49
|
require('@babel/plugin-proposal-class-properties'),
|
|
47
50
|
require('@babel/plugin-proposal-object-rest-spread'),
|
|
48
51
|
require('@babel/plugin-proposal-optional-chaining'),
|
|
49
52
|
require('@babel/plugin-proposal-nullish-coalescing-operator'),
|
|
50
|
-
],
|
|
51
|
-
...babelifyOptions,
|
|
52
|
-
});
|
|
53
|
+
] }, babelifyOptions));
|
|
53
54
|
}
|
|
54
|
-
bundlerTransform
|
|
55
|
-
bundler.plugin(
|
|
55
|
+
bundlerTransform === null || bundlerTransform === void 0 ? void 0 : bundlerTransform(bundler);
|
|
56
|
+
bundler.plugin(snaps_browserify_plugin_1.default, {
|
|
56
57
|
stripComments: argv.stripComments,
|
|
57
58
|
transformHtmlComments: argv.transformHtmlComments,
|
|
58
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/cmds/build/bundle.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0D;AAC1D,6CAAoD;AAEpD,mCAA+D;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,mHAAmH;AAEnH
|
|
1
|
+
{"version":3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AAC;iBAC9D,IACG,eAAuB,EAC3B,CAAC;SACJ;QAED,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAG,OAAO,CAAC,CAAC;QAE5B,OAAO,CAAC,MAAM,CAAC,iCAAM,EAAE;YACrB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;SAClD,CAAC,CAAC;QAEH,OAAO,CAAC,MAAM,CACZ,KAAK,EAAE,WAAW,EAAE,YAAoB,EAAE,EAAE,CAC1C,MAAM,IAAA,uBAAe,EAAC;YACpB,WAAW;YACX,YAAY;YACZ,GAAG;YACH,IAAI;YACJ,OAAO;SACR,CAAC,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AA5DD,wBA4DC","sourcesContent":["import browserify, { BrowserifyObject } from 'browserify';\nimport plugin from '@metamask/snaps-browserify-plugin';\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { processDependencies, writeBundleFile } from './utils';\n\n// We need to statically import all Browserify transforms and all Babel presets\n// and plugins, and calling `require` is the sanest way to do that.\n/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */\n\n/**\n * Builds a Snap bundle JS file from its JavaScript source.\n *\n * @param src - The source file path.\n * @param dest - The destination file path.\n * @param argv - Arguments as an object generated by `yargs`.\n * @param argv.sourceMaps - Whether to output sourcemaps.\n * @param argv.stripComments - Whether to remove comments from code.\n * @param argv.transpilationMode - The Babel transpilation mode.\n * @param bundlerTransform - An optional function which can be used to transform\n * the Browserify instance, e.g., adding a custom transform or plugin.\n */\nexport function bundle(\n src: string,\n dest: string,\n argv: YargsArgs,\n bundlerTransform?: (bundler: BrowserifyObject) => void,\n): Promise<boolean> {\n const { sourceMaps: debug, transpilationMode } = argv;\n const babelifyOptions = processDependencies(argv as any);\n return new Promise((resolve, _reject) => {\n const bundler = browserify(src, {\n debug,\n extensions: ['.js', '.ts'],\n // Standalone is required to properly support Snaps using module.exports\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.none) {\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.localAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: ['chrome >= 66', 'firefox >= 68'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-object-rest-spread'),\n require('@babel/plugin-proposal-optional-chaining'),\n require('@babel/plugin-proposal-nullish-coalescing-operator'),\n ],\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin(plugin, {\n stripComments: argv.stripComments,\n transformHtmlComments: argv.transformHtmlComments,\n });\n\n bundler.bundle(\n async (bundleError, bundleBuffer: Buffer) =>\n await writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n }),\n );\n });\n}\n"]}
|
|
@@ -23,21 +23,34 @@ declare type WriteBundleFileArgs = {
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve, }: WriteBundleFileArgs): Promise<void>;
|
|
25
25
|
/**
|
|
26
|
-
* Processes dependencies and updates argv with an options object
|
|
27
|
-
*
|
|
26
|
+
* Processes dependencies and updates `argv` with an options object.
|
|
27
|
+
*
|
|
28
|
+
* @param argv - The Yargs arguments object.
|
|
29
|
+
* @returns An object with options that can be passed to Babelify.
|
|
28
30
|
*/
|
|
29
31
|
export declare function processDependencies(argv: YargsArgs): Record<string, any>;
|
|
30
32
|
/**
|
|
31
|
-
* Processes a string of space delimited dependencies into one
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
33
|
+
* Processes a string of space delimited dependencies into one RegExp string.
|
|
34
|
+
*
|
|
35
|
+
* @param dependencies - An array of dependencies to add to the RegExp.
|
|
36
|
+
* @returns A RegExp object.
|
|
34
37
|
*/
|
|
35
38
|
export declare function getDependencyRegExp(dependencies: string[]): RegExp | null;
|
|
36
39
|
/**
|
|
37
|
-
* Helper function remove any leading and trailing slashes from dependency list
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
40
|
+
* Helper function remove any leading and trailing slashes from dependency list.
|
|
41
|
+
*
|
|
42
|
+
* @param dependencies - An array of dependencies to sanitize.
|
|
43
|
+
* @returns An array of sanitized paths.
|
|
40
44
|
*/
|
|
41
45
|
export declare function sanitizeDependencyPaths(dependencies: string[]): string[];
|
|
46
|
+
/**
|
|
47
|
+
* Check the Yargs argv object, to see if the provided options are valid. The
|
|
48
|
+
* options are invalid if both `depsToTranspile` are provided, and
|
|
49
|
+
* `transpilationMode` is not set to `localAndDeps`.
|
|
50
|
+
*
|
|
51
|
+
* @param argv - The Yargs arguments object.
|
|
52
|
+
* @throws If the `depsToTranspile` is set, and `transpilationMode` is not set
|
|
53
|
+
* to `localAndDeps`.
|
|
54
|
+
*/
|
|
42
55
|
export declare function processInvalidTranspilation(argv: YargsArgs): void;
|
|
43
56
|
export {};
|
package/dist/cmds/build/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ async function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve,
|
|
|
23
23
|
await (0, misc_1.writeError)('Build error:', bundleError.message, bundleError);
|
|
24
24
|
}
|
|
25
25
|
try {
|
|
26
|
-
await fs_1.promises.writeFile(dest, bundleBuffer
|
|
26
|
+
await fs_1.promises.writeFile(dest, bundleBuffer === null || bundleBuffer === void 0 ? void 0 : bundleBuffer.toString());
|
|
27
27
|
console.log(`Build success: '${src}' bundled as '${dest}'!`);
|
|
28
28
|
resolve(true);
|
|
29
29
|
}
|
|
@@ -33,8 +33,10 @@ async function writeBundleFile({ bundleError, bundleBuffer, src, dest, resolve,
|
|
|
33
33
|
}
|
|
34
34
|
exports.writeBundleFile = writeBundleFile;
|
|
35
35
|
/**
|
|
36
|
-
* Processes dependencies and updates argv with an options object
|
|
37
|
-
*
|
|
36
|
+
* Processes dependencies and updates `argv` with an options object.
|
|
37
|
+
*
|
|
38
|
+
* @param argv - The Yargs arguments object.
|
|
39
|
+
* @returns An object with options that can be passed to Babelify.
|
|
38
40
|
*/
|
|
39
41
|
function processDependencies(argv) {
|
|
40
42
|
const { depsToTranspile, transpilationMode } = argv;
|
|
@@ -49,9 +51,10 @@ function processDependencies(argv) {
|
|
|
49
51
|
}
|
|
50
52
|
exports.processDependencies = processDependencies;
|
|
51
53
|
/**
|
|
52
|
-
* Processes a string of space delimited dependencies into one
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
54
|
+
* Processes a string of space delimited dependencies into one RegExp string.
|
|
55
|
+
*
|
|
56
|
+
* @param dependencies - An array of dependencies to add to the RegExp.
|
|
57
|
+
* @returns A RegExp object.
|
|
55
58
|
*/
|
|
56
59
|
function getDependencyRegExp(dependencies) {
|
|
57
60
|
let regexp = null;
|
|
@@ -66,9 +69,10 @@ function getDependencyRegExp(dependencies) {
|
|
|
66
69
|
}
|
|
67
70
|
exports.getDependencyRegExp = getDependencyRegExp;
|
|
68
71
|
/**
|
|
69
|
-
* Helper function remove any leading and trailing slashes from dependency list
|
|
70
|
-
*
|
|
71
|
-
* @
|
|
72
|
+
* Helper function remove any leading and trailing slashes from dependency list.
|
|
73
|
+
*
|
|
74
|
+
* @param dependencies - An array of dependencies to sanitize.
|
|
75
|
+
* @returns An array of sanitized paths.
|
|
72
76
|
*/
|
|
73
77
|
function sanitizeDependencyPaths(dependencies) {
|
|
74
78
|
return dependencies.map((dependency) => {
|
|
@@ -76,6 +80,15 @@ function sanitizeDependencyPaths(dependencies) {
|
|
|
76
80
|
});
|
|
77
81
|
}
|
|
78
82
|
exports.sanitizeDependencyPaths = sanitizeDependencyPaths;
|
|
83
|
+
/**
|
|
84
|
+
* Check the Yargs argv object, to see if the provided options are valid. The
|
|
85
|
+
* options are invalid if both `depsToTranspile` are provided, and
|
|
86
|
+
* `transpilationMode` is not set to `localAndDeps`.
|
|
87
|
+
*
|
|
88
|
+
* @param argv - The Yargs arguments object.
|
|
89
|
+
* @throws If the `depsToTranspile` is set, and `transpilationMode` is not set
|
|
90
|
+
* to `localAndDeps`.
|
|
91
|
+
*/
|
|
79
92
|
function processInvalidTranspilation(argv) {
|
|
80
93
|
if (argv.depsToTranspile &&
|
|
81
94
|
argv.transpilationMode !== builders_1.TranspilationModes.localAndDeps) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/cmds/build/utils.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,2CAA8C;AAE9C,6CAAoD;AAUpD;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,eAAe,CAAC,EACpC,WAAW,EACX,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,OAAO,GACa;IACpB,IAAI,WAAW,EAAE;QACf,MAAM,IAAA,iBAAU,EAAC,cAAc,EAAE,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;KACpE;IAED,IAAI;QACF,MAAM,aAAE,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/cmds/build/utils.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,2CAA8C;AAE9C,6CAAoD;AAUpD;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,eAAe,CAAC,EACpC,WAAW,EACX,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,OAAO,GACa;IACpB,IAAI,WAAW,EAAE;QACf,MAAM,IAAA,iBAAU,EAAC,cAAc,EAAE,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;KACpE;IAED,IAAI;QACF,MAAM,aAAE,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,QAAQ,EAAE,CAAC,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,iBAAiB,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,YAAsB;IAC5D,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QACrC,OAAO,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,0DAIC;AAED;;;;;;;;GAQG;AACH,SAAgB,2BAA2B,CAAC,IAAe;IACzD,IACE,IAAI,CAAC,eAAe;QACpB,IAAI,CAAC,iBAAiB,KAAK,6BAAkB,CAAC,YAAY,EAC1D;QACA,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;AACH,CAAC;AATD,kEASC","sourcesContent":["import { promises as fs } from 'fs';\nimport { writeError } from '../../utils/misc';\nimport { YargsArgs } from '../../types/yargs';\nimport { TranspilationModes } from '../../builders';\n\ntype WriteBundleFileArgs = {\n bundleError: Error;\n bundleBuffer: Buffer;\n src: string;\n dest: string;\n resolve: (value: boolean) => void;\n};\n\n/**\n * Performs postprocessing on the bundle contents and writes them to disk.\n * Intended to be used in the callback passed to the Browserify `.bundle()`\n * call.\n *\n * @param options - Options bag.\n * @param options.bundleError - Any error received from Browserify.\n * @param options.bundleBuffer - The {@link Buffer} with the bundle contents\n * from Browserify.\n * @param options.src - The source file path.\n * @param options.dest - The destination file path.\n * @param options.resolve - A {@link Promise} resolution function, so that we\n * can use promises and `async`/`await` even though Browserify uses callbacks.\n */\nexport async function writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n}: WriteBundleFileArgs) {\n if (bundleError) {\n await writeError('Build error:', bundleError.message, bundleError);\n }\n\n try {\n await fs.writeFile(dest, bundleBuffer?.toString());\n console.log(`Build success: '${src}' bundled as '${dest}'!`);\n resolve(true);\n } catch (error) {\n await writeError('Write error:', error.message, error, dest);\n }\n}\n\n/**\n * Processes dependencies and updates `argv` with an options object.\n *\n * @param argv - The Yargs arguments object.\n * @returns An object with options that can be passed to Babelify.\n */\nexport function processDependencies(argv: YargsArgs) {\n const { depsToTranspile, transpilationMode } = argv;\n const babelifyOptions: Record<string, any> = {};\n if (transpilationMode === TranspilationModes.localAndDeps) {\n const regexpStr = getDependencyRegExp(depsToTranspile as string[]);\n if (regexpStr !== null) {\n babelifyOptions.ignore = [regexpStr];\n }\n }\n return babelifyOptions;\n}\n\n/**\n * Processes a string of space delimited dependencies into one RegExp string.\n *\n * @param dependencies - An array of dependencies to add to the RegExp.\n * @returns A RegExp object.\n */\nexport function getDependencyRegExp(dependencies: string[]): RegExp | null {\n let regexp: string | null = null;\n if (!dependencies || dependencies.includes('.') || !dependencies.length) {\n return regexp;\n }\n const paths: string[] = sanitizeDependencyPaths(dependencies);\n regexp = `/node_modules/(?!${paths.shift()}`;\n paths.forEach((path) => (regexp += `|${path}`));\n regexp += '/)';\n return RegExp(regexp, 'u');\n}\n\n/**\n * Helper function remove any leading and trailing slashes from dependency list.\n *\n * @param dependencies - An array of dependencies to sanitize.\n * @returns An array of sanitized paths.\n */\nexport function sanitizeDependencyPaths(dependencies: string[]): string[] {\n return dependencies.map((dependency) => {\n return dependency.replace(/^[/\\\\]+/u, '').replace(/[/\\\\]+$/u, '');\n });\n}\n\n/**\n * Check the Yargs argv object, to see if the provided options are valid. The\n * options are invalid if both `depsToTranspile` are provided, and\n * `transpilationMode` is not set to `localAndDeps`.\n *\n * @param argv - The Yargs arguments object.\n * @throws If the `depsToTranspile` is set, and `transpilationMode` is not set\n * to `localAndDeps`.\n */\nexport function processInvalidTranspilation(argv: YargsArgs) {\n if (\n argv.depsToTranspile &&\n argv.transpilationMode !== TranspilationModes.localAndDeps\n ) {\n throw new Error(\n '\"depsToTranspile\" can only be specified if \"transpilationMode\" is set to \"localAndDeps\" .',\n );\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const worker_threads_1 = require("worker_threads");
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
|
-
const mock_1 = require("./mock");
|
|
6
5
|
// eslint-disable-next-line import/no-unassigned-import
|
|
7
6
|
require("ses/lockdown");
|
|
7
|
+
const mock_1 = require("./mock");
|
|
8
8
|
lockdown({
|
|
9
9
|
consoleTaming: 'unsafe',
|
|
10
10
|
errorTaming: 'unsafe',
|
|
@@ -12,19 +12,22 @@ lockdown({
|
|
|
12
12
|
dateTaming: 'unsafe',
|
|
13
13
|
overrideTaming: 'severe',
|
|
14
14
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
22
|
function getMockEndowments() {
|
|
23
23
|
const endowments = (0, mock_1.generateMockEndowments)();
|
|
24
|
-
return {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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.`);
|
|
29
31
|
}
|
|
32
|
+
setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
|
|
30
33
|
//# sourceMappingURL=eval-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":"
|
|
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"]}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { YargsArgs } from '../../types/yargs';
|
|
2
|
+
/**
|
|
3
|
+
* Runs the snap in a worker, to ensure SES compatibility.
|
|
4
|
+
*
|
|
5
|
+
* @param argv - The Yargs arguments object.
|
|
6
|
+
* @returns A promise that resolves once the eval has finished.
|
|
7
|
+
* @throws If the eval failed.
|
|
8
|
+
*/
|
|
2
9
|
export declare function snapEval(argv: YargsArgs): Promise<void>;
|
|
@@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.snapEval = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const workerEval_1 = require("./workerEval");
|
|
6
|
+
/**
|
|
7
|
+
* Runs the snap in a worker, to ensure SES compatibility.
|
|
8
|
+
*
|
|
9
|
+
* @param argv - The Yargs arguments object.
|
|
10
|
+
* @returns A promise that resolves once the eval has finished.
|
|
11
|
+
* @throws If the eval failed.
|
|
12
|
+
*/
|
|
6
13
|
async function snapEval(argv) {
|
|
7
14
|
const { bundle: bundlePath } = argv;
|
|
8
15
|
await (0, utils_1.validateFilePath)(bundlePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AACA,uCAAyD;AACzD,6CAA0C;
|
|
1
|
+
{"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AACA,uCAAyD;AACzD,6CAA0C;AAE1C;;;;;;GAMG;AACI,KAAK,UAAU,QAAQ,CAAC,IAAe;IAC5C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IACpC,MAAM,IAAA,wBAAgB,EAAC,UAAoB,CAAC,CAAC;IAC7C,IAAI;QACF,MAAM,IAAA,uBAAU,EAAC,UAAoB,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,4BAA4B,UAAU,WAAW,CAAC,CAAC;KAChE;IAAC,OAAO,GAAG,EAAE;QACZ,IAAA,gBAAQ,EAAC,0BAA0B,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;QACvD,MAAM,GAAG,CAAC;KACX;AACH,CAAC;AAVD,4BAUC","sourcesContent":["import { YargsArgs } from '../../types/yargs';\nimport { logError, validateFilePath } from '../../utils';\nimport { workerEval } from './workerEval';\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 snapEval(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n await validateFilePath(bundlePath as string);\n try {\n await workerEval(bundlePath as string);\n console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (err) {\n logError(`Snap evaluation error: ${err.message}`, err);\n throw err;\n }\n}\n"]}
|
package/dist/cmds/eval/mock.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
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
|
+
*/
|
|
2
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
|
+
*/
|
|
3
14
|
export declare const generateMockEndowments: () => Record<string, any>;
|