@metamask/snaps-cli 0.2.2 → 0.5.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 CHANGED
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.5.0]
10
+ ### Changed
11
+ - **BREAKING:** Convert all TypeScript `interface` declarations to `type` equivalents ([#143](https://github.com/MetaMask/snaps-skunkworks/pull/143))
12
+
13
+ ## [0.4.0]
14
+ ### Fixed
15
+ - Make Windows-compatible ([#131](https://github.com/MetaMask/snaps-skunkworks/pull/131))
16
+
17
+ ## [0.3.1]
18
+ ### Changed
19
+ - No changes this release.
20
+
21
+ ## [0.3.0]
22
+ ### Changed
23
+ - **BREAKING:** Enforce consistent naming for Snaps-related functionality ([#119](https://github.com/MetaMask/snaps-skunkworks/pull/119))
24
+
9
25
  ## [0.2.2]
10
26
  ### Fixed
11
27
  - Package script issues ([#97](https://github.com/MetaMask/snaps-skunkworks/pull/97), [#98](https://github.com/MetaMask/snaps-skunkworks/pull/98))
@@ -33,7 +49,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
33
49
  - Example snaps ([#72](https://github.com/MetaMask/snaps-skunkworks/pull/72))
34
50
  - The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
35
51
 
36
- [Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.2.2...HEAD
52
+ [Unreleased]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.5.0...HEAD
53
+ [0.5.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.4.0...v0.5.0
54
+ [0.4.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.3.1...v0.4.0
55
+ [0.3.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.3.0...v0.3.1
56
+ [0.3.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.2.2...v0.3.0
37
57
  [0.2.2]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.2.1...v0.2.2
38
58
  [0.2.1]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.2.0...v0.2.1
39
59
  [0.2.0]: https://github.com/MetaMask/snaps-skunkworks/compare/v0.1.1...v0.2.0
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAIzC,mCAAsE;AACtE,0DAAkC;AAUlC,SAAgB,GAAG,CAAC,IAAc,EAAE,QAAa;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,oEAAoE;IACpE,eAAK,CAAC,OAAO,CAAC;SACX,KAAK,CAAC,+BAA+B,CAAC;SAEtC,OAAO,CAAC,SAAS,EAAE,wCAAwC,CAAC;SAC5D,OAAO,CACN,6BAA6B,EAC7B,yCAAyC,CAC1C;SACA,OAAO,CACN,wCAAwC,EACxC,uCAAuC,CACxC;SACA,OAAO,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;SACnE,OAAO,CAAC,yBAAyB,EAAE,uCAAuC,CAAC;SAC3E,OAAO,CACN,6BAA6B,EAC7B,4FAA4F,CAC7F;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,mBAAW,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC/C,sBAAc,CAAC,SAAS,CAAC,CAAC;QAC1B,sBAAc,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAQ,EACT,IAAI,CACL;SAEA,IAAI,CAAC,CAAC,GAAW,EAAE,GAAU,EAAE,MAAM,EAAE,EAAE;QACxC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,KAAK,KAAI,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC1B;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;SAED,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAE1D,IAAI,EAAE;SACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAtDD,kBAsDC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\n\nimport { SnapsCliGlobals } from './types/package';\nimport { applyConfig, sanitizeInputs, setSnapGlobals } from './utils';\nimport builders from './builders';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace NodeJS {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface Global extends SnapsCliGlobals {}\n }\n}\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 .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize Snap package from scratch`)\n .example(\n '$0 build -s index.js -d out',\n `\\tBuild 'index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s index.js -d out -n snap.js',\n `\\tBuild '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 index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in '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(rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((msg: string, err: Error, _yargs) => {\n console.error(msg || err.message);\n if (err?.stack && global.snaps.verboseErrors) {\n console.error(err.stack);\n }\n process.exit(1);\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAIzC,mCAAsE;AACtE,0DAAkC;AAUlC,SAAgB,GAAG,CAAC,IAAc,EAAE,QAAa;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,oEAAoE;IACpE,eAAK,CAAC,OAAO,CAAC;SACX,KAAK,CAAC,+BAA+B,CAAC;SAEtC,OAAO,CAAC,SAAS,EAAE,wCAAwC,CAAC;SAC5D,OAAO,CACN,6BAA6B,EAC7B,yCAAyC,CAC1C;SACA,OAAO,CACN,wCAAwC,EACxC,uCAAuC,CACxC;SACA,OAAO,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;SACnE,OAAO,CAAC,yBAAyB,EAAE,uCAAuC,CAAC;SAC3E,OAAO,CACN,6BAA6B,EAC7B,4FAA4F,CAC7F;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,mBAAW,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC/C,sBAAc,CAAC,SAAS,CAAC,CAAC;QAC1B,sBAAc,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAQ,EACT,IAAI,CACL;SAEA,IAAI,CAAC,CAAC,GAAW,EAAE,GAAU,EAAE,MAAM,EAAE,EAAE;QACxC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,KAAK,KAAI,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC1B;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;SAED,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAE1D,IAAI,EAAE;SACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAtDD,kBAsDC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\n\nimport { SnapsCliGlobals } from './types/package';\nimport { applyConfig, sanitizeInputs, setSnapGlobals } from './utils';\nimport builders from './builders';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace NodeJS {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/consistent-type-definitions\n interface Global extends SnapsCliGlobals {}\n }\n}\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 .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize Snap package from scratch`)\n .example(\n '$0 build -s index.js -d out',\n `\\tBuild 'index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s index.js -d out -n snap.js',\n `\\tBuild '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 index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in '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(rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((msg: string, err: Error, _yargs) => {\n console.error(msg || err.message);\n if (err?.stack && global.snaps.verboseErrors) {\n console.error(err.stack);\n }\n process.exit(1);\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}
@@ -7,7 +7,7 @@ import { Option, YargsArgs } from '../../types/yargs';
7
7
  * @returns - The stream
8
8
  */
9
9
  export declare function createBundleStream(dest: string): NodeJS.WritableStream;
10
- interface CloseStreamArgs {
10
+ declare type CloseStreamArgs = {
11
11
  bundleError: Error;
12
12
  bundleBuffer: Buffer;
13
13
  bundleStream: NodeJS.WritableStream;
@@ -15,7 +15,7 @@ interface CloseStreamArgs {
15
15
  dest: string;
16
16
  resolve: (value: boolean) => void;
17
17
  argv: YargsArgs;
18
- }
18
+ };
19
19
  /**
20
20
  * Postprocesses the bundle string and closes the write stream.
21
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"bundleUtils.js","sourceRoot":"","sources":["../../../src/cmds/build/bundleUtils.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAuC;AACvC,oEAA2C;AAC3C,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;AAChB,CAAC;AATD,gDASC;AAYD;;;;;;;GAOG;AACI,KAAK,UAAU,iBAAiB,CAAC,EACtC,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,OAAO,EACP,IAAI,GACY;IAChB,IAAI,WAAW,EAAE;QACf,MAAM,iBAAU,CAAC,cAAc,EAAE,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;KACpE;IAED,IAAI;QACF,YAAY,CAAC,GAAG,CACd,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YACzD,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAW,CACb,CAAC;QAEF,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,iBAAiB,IAAI,IAAI,CAAC,CAAC;SAC9D;QACD,OAAO,CAAC,IAAI,CAAC,CAAC;KACf;IAAC,OAAO,UAAU,EAAE;QACnB,MAAM,iBAAU,CAAC,cAAc,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;KACxE;AACH,CAAC;AA3BD,8CA2BC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CACzB,YAA2B,EAC3B,UAA2B,EAAE;IAE7B,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;QACpC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,eAAe,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;IAE1C,IAAI,OAAO,CAAC,aAAa,EAAE;QACzB,eAAe,GAAG,wBAAa,CAAC,eAAe,CAAC,CAAC;KAClD;IAED,wDAAwD;IACxD,eAAe,GAAG,eAAe,CAAC,OAAO,CACvC,2CAA2C,EAC3C,WAAW,CACZ,CAAC;IAEF,4EAA4E;IAC5E,8CAA8C;IAC9C,kCAAkC;IAClC,eAAe,GAAG,eAAe,CAAC,OAAO,CACvC,yBAAyB,EACzB,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 '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\ninterface 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"]}
1
+ {"version":3,"file":"bundleUtils.js","sourceRoot":"","sources":["../../../src/cmds/build/bundleUtils.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAuC;AACvC,oEAA2C;AAC3C,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;AAChB,CAAC;AATD,gDASC;AAYD;;;;;;;GAOG;AACI,KAAK,UAAU,iBAAiB,CAAC,EACtC,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,OAAO,EACP,IAAI,GACY;IAChB,IAAI,WAAW,EAAE;QACf,MAAM,iBAAU,CAAC,cAAc,EAAE,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;KACpE;IAED,IAAI;QACF,YAAY,CAAC,GAAG,CACd,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YACzD,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAW,CACb,CAAC;QAEF,IAAI,YAAY,EAAE;YAChB,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,iBAAiB,IAAI,IAAI,CAAC,CAAC;SAC9D;QACD,OAAO,CAAC,IAAI,CAAC,CAAC;KACf;IAAC,OAAO,UAAU,EAAE;QACnB,MAAM,iBAAU,CAAC,cAAc,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;KACxE;AACH,CAAC;AA3BD,8CA2BC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CACzB,YAA2B,EAC3B,UAA2B,EAAE;IAE7B,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;QACpC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,eAAe,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;IAE1C,IAAI,OAAO,CAAC,aAAa,EAAE;QACzB,eAAe,GAAG,wBAAa,CAAC,eAAe,CAAC,CAAC;KAClD;IAED,wDAAwD;IACxD,eAAe,GAAG,eAAe,CAAC,OAAO,CACvC,2CAA2C,EAC3C,WAAW,CACZ,CAAC;IAEF,4EAA4E;IAC5E,8CAA8C;IAC9C,kCAAkC;IAClC,eAAe,GAAG,eAAe,CAAC,OAAO,CACvC,yBAAyB,EACzB,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 '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"]}
@@ -15,8 +15,8 @@ lockdown({
15
15
  });
16
16
  if (worker_threads_1.parentPort !== null) {
17
17
  worker_threads_1.parentPort.on('message', (message) => {
18
- const { pluginFilePath } = message;
19
- new Compartment(getMockEndowments()).evaluate(fs_1.readFileSync(pluginFilePath, 'utf8'));
18
+ const { snapFilePath } = message;
19
+ new Compartment(getMockEndowments()).evaluate(fs_1.readFileSync(snapFilePath, 'utf8'));
20
20
  setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
21
21
  });
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;;;;AAAA,mCAAsC;AACtC,mDAA4C;AAC5C,2BAAkC;AAClC,oDAA4B;AAE5B,uDAAuD;AACvD,wBAAsB;AAStB,QAAQ,CAAC;IACP,UAAU,EAAE,QAAQ;IACpB,WAAW,EAAE,QAAQ;CACtB,CAAC,CAAC;AAEH,IAAI,2BAAU,KAAK,IAAI,EAAE;IACvB,2BAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAmC,EAAE,EAAE;QAC/D,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;QAEnC,IAAI,WAAW,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,CAC3C,iBAAY,CAAC,cAAc,EAAE,MAAM,CAAC,CACrC,CAAC;QACF,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B;IACzE,CAAC,CAAC,CAAC;CACJ;AAED,SAAS,mBAAmB;IAC1B,MAAM,YAAY,GAAG,IAAI,qBAAY,EAA+B,CAAC;IACrE,YAAY,CAAC,yBAAyB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;IACpD,YAAY,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;IACxC,OAAO,YAAgC,CAAC;AAC1C,CAAC;AAED,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG;QACjB,MAAM;QACN,MAAM;QACN,OAAO;QACP,MAAM,EAAN,gBAAM;QACN,IAAI;QACJ,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;QACjB,IAAI;QACJ,MAAM,EAAE,mBAAmB,EAAE;QAC7B,UAAU;QACV,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;QAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;QACrB,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;KAC3B,CAAC;IAEF,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,IAClB;AACJ,CAAC","sourcesContent":["import { EventEmitter } from 'events';\nimport { parentPort } from 'worker_threads';\nimport { readFileSync } from 'fs';\nimport crypto from 'crypto';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\ndeclare let lockdown: any, Compartment: any;\n\ntype MockSnapProvider = EventEmitter & {\n registerRpcMessageHandler: () => any;\n request: () => Promise<any>;\n};\n\nlockdown({\n mathTaming: 'unsafe',\n errorTaming: 'unsafe',\n});\n\nif (parentPort !== null) {\n parentPort.on('message', (message: { pluginFilePath: string }) => {\n const { pluginFilePath } = message;\n\n new Compartment(getMockEndowments()).evaluate(\n readFileSync(pluginFilePath, 'utf8'),\n );\n setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n });\n}\n\nfunction getMockSnapProvider(): MockSnapProvider {\n const mockProvider = new EventEmitter() as Partial<MockSnapProvider>;\n mockProvider.registerRpcMessageHandler = () => true;\n mockProvider.request = async () => true;\n return mockProvider as MockSnapProvider;\n}\n\nfunction getMockEndowments() {\n const endowments = {\n BigInt,\n Buffer,\n console,\n crypto,\n Date,\n fetch: () => true,\n Math,\n wallet: getMockSnapProvider(),\n setTimeout,\n SubtleCrypto: () => undefined,\n WebSocket: () => true,\n XMLHttpRequest: () => true,\n };\n\n return {\n ...endowments,\n window: endowments,\n };\n}\n"]}
1
+ {"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../../../src/cmds/eval/eval-worker.ts"],"names":[],"mappings":";;;;;AAAA,mCAAsC;AACtC,mDAA4C;AAC5C,2BAAkC;AAClC,oDAA4B;AAE5B,uDAAuD;AACvD,wBAAsB;AAStB,QAAQ,CAAC;IACP,UAAU,EAAE,QAAQ;IACpB,WAAW,EAAE,QAAQ;CACtB,CAAC,CAAC;AAEH,IAAI,2BAAU,KAAK,IAAI,EAAE;IACvB,2BAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAiC,EAAE,EAAE;QAC7D,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAEjC,IAAI,WAAW,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,CAC3C,iBAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CACnC,CAAC;QACF,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B;IACzE,CAAC,CAAC,CAAC;CACJ;AAED,SAAS,mBAAmB;IAC1B,MAAM,YAAY,GAAG,IAAI,qBAAY,EAA+B,CAAC;IACrE,YAAY,CAAC,yBAAyB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;IACpD,YAAY,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;IACxC,OAAO,YAAgC,CAAC;AAC1C,CAAC;AAED,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG;QACjB,MAAM;QACN,MAAM;QACN,OAAO;QACP,MAAM,EAAN,gBAAM;QACN,IAAI;QACJ,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;QACjB,IAAI;QACJ,MAAM,EAAE,mBAAmB,EAAE;QAC7B,UAAU;QACV,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;QAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;QACrB,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;KAC3B,CAAC;IAEF,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,IAClB;AACJ,CAAC","sourcesContent":["import { EventEmitter } from 'events';\nimport { parentPort } from 'worker_threads';\nimport { readFileSync } from 'fs';\nimport crypto from 'crypto';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\ndeclare let lockdown: any, Compartment: any;\n\ntype MockSnapProvider = EventEmitter & {\n registerRpcMessageHandler: () => any;\n request: () => Promise<any>;\n};\n\nlockdown({\n mathTaming: 'unsafe',\n errorTaming: 'unsafe',\n});\n\nif (parentPort !== null) {\n parentPort.on('message', (message: { snapFilePath: string }) => {\n const { snapFilePath } = message;\n\n new Compartment(getMockEndowments()).evaluate(\n readFileSync(snapFilePath, 'utf8'),\n );\n setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n });\n}\n\nfunction getMockSnapProvider(): MockSnapProvider {\n const mockProvider = new EventEmitter() as Partial<MockSnapProvider>;\n mockProvider.registerRpcMessageHandler = () => true;\n mockProvider.request = async () => true;\n return mockProvider as MockSnapProvider;\n}\n\nfunction getMockEndowments() {\n const endowments = {\n BigInt,\n Buffer,\n console,\n crypto,\n Date,\n fetch: () => true,\n Math,\n wallet: getMockSnapProvider(),\n setTimeout,\n SubtleCrypto: () => undefined,\n WebSocket: () => true,\n XMLHttpRequest: () => true,\n };\n\n return {\n ...endowments,\n window: endowments,\n };\n}\n"]}
@@ -18,7 +18,7 @@ function workerEval(bundlePath) {
18
18
  }
19
19
  })
20
20
  .postMessage({
21
- pluginFilePath: bundlePath,
21
+ snapFilePath: bundlePath,
22
22
  });
23
23
  });
24
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"workerEval.js","sourceRoot":"","sources":["../../../src/cmds/eval/workerEval.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAwC;AACxC,gDAA6B;AAE7B,SAAgB,UAAU,CAAC,UAAkB;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,uBAAM,CAAC,iBAAiB,EAAE,CAAC;aAC5B,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YAC/B,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,CAAC,IAAI,CAAC,CAAC;aACf;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;aAChE;QACH,CAAC,CAAC;aACD,WAAW,CAAC;YACX,cAAc,EAAE,UAAU;SAC3B,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AAdD,gCAcC;AAED;;GAEG;AACH,SAAS,iBAAiB;IACxB,OAAO,cAAS,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { Worker } from 'worker_threads';\nimport pathUtils from 'path';\n\nexport function workerEval(bundlePath: string): Promise<null> {\n return new Promise((resolve) => {\n new Worker(getEvalWorkerPath())\n .on('exit', (exitCode: number) => {\n if (exitCode === 0) {\n resolve(null);\n } else {\n throw new Error(`Worker exited abnormally! Code: ${exitCode}`);\n }\n })\n .postMessage({\n pluginFilePath: bundlePath,\n });\n });\n}\n\n/**\n * @returns The path to the eval worker file.\n */\nfunction getEvalWorkerPath(): string {\n return pathUtils.join(__dirname, 'eval-worker.js');\n}\n"]}
1
+ {"version":3,"file":"workerEval.js","sourceRoot":"","sources":["../../../src/cmds/eval/workerEval.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAwC;AACxC,gDAA6B;AAE7B,SAAgB,UAAU,CAAC,UAAkB;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,uBAAM,CAAC,iBAAiB,EAAE,CAAC;aAC5B,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YAC/B,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,CAAC,IAAI,CAAC,CAAC;aACf;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;aAChE;QACH,CAAC,CAAC;aACD,WAAW,CAAC;YACX,YAAY,EAAE,UAAU;SACzB,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AAdD,gCAcC;AAED;;GAEG;AACH,SAAS,iBAAiB;IACxB,OAAO,cAAS,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { Worker } from 'worker_threads';\nimport pathUtils from 'path';\n\nexport function workerEval(bundlePath: string): Promise<null> {\n return new Promise((resolve) => {\n new Worker(getEvalWorkerPath())\n .on('exit', (exitCode: number) => {\n if (exitCode === 0) {\n resolve(null);\n } else {\n throw new Error(`Worker exited abnormally! Code: ${exitCode}`);\n }\n })\n .postMessage({\n snapFilePath: bundlePath,\n });\n });\n}\n\n/**\n * @returns The path to the eval worker file.\n */\nfunction getEvalWorkerPath(): string {\n return pathUtils.join(__dirname, 'eval-worker.js');\n}\n"]}
@@ -9,7 +9,7 @@ async function init(argv) {
9
9
  console.log();
10
10
  const newArgs = await initHandler_1.initHandler(argv);
11
11
  await buildHandler_1.build(Object.assign(Object.assign({}, newArgs), { manifest: false, eval: true }));
12
- console.log('\nPlugin project successfully initiated!');
12
+ console.log('\nSnap project successfully initiated!');
13
13
  }
14
14
  module.exports = {
15
15
  command: ['init', 'i'],
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAe5C,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,MAAM,OAAO,GAAG,MAAM,yBAAW,CAAC,IAAI,CAAC,CAAC;IAExC,MAAM,oBAAK,iCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;AAC1D,CAAC;AAxBD,iBAAS;IACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC;IACtB,IAAI,EAAE,yBAAyB;IAC/B,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,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC","sourcesContent":["import yargs from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler } from './initHandler';\n\nexport = {\n command: ['init', 'i'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('port', builders.port);\n },\n handler: (argv: YargsArgs) => init(argv),\n};\n\nasync function init(argv: YargsArgs): Promise<void> {\n console.log();\n const newArgs = await initHandler(argv);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n console.log('\\nPlugin project successfully initiated!');\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAe5C,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,MAAM,OAAO,GAAG,MAAM,yBAAW,CAAC,IAAI,CAAC,CAAC;IAExC,MAAM,oBAAK,iCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,CAAC;AAxBD,iBAAS;IACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC;IACtB,IAAI,EAAE,yBAAyB;IAC/B,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,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC","sourcesContent":["import yargs from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler } from './initHandler';\n\nexport = {\n command: ['init', 'i'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('port', builders.port);\n },\n handler: (argv: YargsArgs) => init(argv),\n};\n\nasync function init(argv: YargsArgs): Promise<void> {\n console.log();\n const newArgs = await initHandler(argv);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n console.log('\\nSnap project successfully initiated!');\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  {
2
- "html": "<!doctype html>\n\n<html>\n\n </head>\n <title>Hello Snaps!</title>\n </head>\n\n <body>\n <h1>Hello Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The Snap <b>package.json</b> must be located in located in the server root directory\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by <b>package.json:web3Wallet.bundle.url</b>\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n\n // we identify the Snap by the location of its package.json file\n const snapId = new URL('package.json', window.location.href).toString()\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the plugin\n async function connect () {\n await ethereum.request({\n method: 'wallet_enable',\n params: [{\n wallet_plugin: { [snapId]: {} },\n }]\n })\n }\n\n // here we call the plugin's \"hello\" method\n async function send () {\n try {\n const response = await ethereum.request({\n method: 'wallet_invokePlugin',\n params: [snapId, {\n method: 'hello'\n }]\n })\n } catch (err) {\n console.error(err)\n alert('Problem happened: ' + err.message || err)\n }\n }\n\n </script>\n\n</html>\n",
2
+ "html": "<!doctype html>\n\n<html>\n\n </head>\n <title>Hello Snaps!</title>\n </head>\n\n <body>\n <h1>Hello Snaps!</h1>\n <details>\n <summary>Instructions</summary>\n <ul>\n <li>First, click \"Connect\". Then, try out the other buttons!</li>\n <li>Please note that:</li>\n <ul>\n <li>\n The Snap <b>package.json</b> must be located in located in the server root directory\n </li>\n <li>\n The Snap bundle must be hosted at the location specified by <b>package.json:web3Wallet.bundle.url</b>\n </li>\n </ul>\n </ul>\n </details>\n <br/>\n\n <button class=\"connect\">Connect</button>\n <button class=\"sendHello\">Send Hello</button>\n </body>\n\n <script>\n\n // we identify the Snap by the location of its package.json file\n const snapId = new URL('package.json', window.location.href).toString()\n\n const connectButton = document.querySelector('button.connect')\n const sendButton = document.querySelector('button.sendHello')\n\n connectButton.addEventListener('click', connect)\n sendButton.addEventListener('click', send)\n\n // here we get permissions to interact with and install the snap\n async function connect () {\n await ethereum.request({\n method: 'wallet_enable',\n params: [{\n wallet_snap: { [snapId]: {} },\n }]\n })\n }\n\n // here we call the snap's \"hello\" method\n async function send () {\n try {\n const response = await ethereum.request({\n method: 'wallet_invokeSnap',\n params: [snapId, {\n method: 'hello'\n }]\n })\n } catch (err) {\n console.error(err)\n alert('Problem happened: ' + err.message || err)\n }\n }\n\n </script>\n\n</html>\n",
3
3
  "js": "wallet.registerRpcMessageHandler(async (originString, requestObject) => {\n switch (requestObject.method) {\n case 'hello':\n return wallet.request({\n method: 'snap_confirm',\n params: [`Hello, ${originString}!`],\n });\n default:\n throw new Error('Method not found.');\n }\n});\n"
4
4
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.trimPathString = exports.writeError = exports.logWarning = exports.logError = exports.sanitizeInputs = exports.setSnapGlobals = exports.CONFIG_PATHS = exports.permRequestKeys = void 0;
4
7
  const fs_1 = require("fs");
8
+ const path_1 = __importDefault(require("path"));
5
9
  exports.permRequestKeys = [
6
10
  '@context',
7
11
  'id',
@@ -12,6 +16,17 @@ exports.permRequestKeys = [
12
16
  'proof',
13
17
  ];
14
18
  exports.CONFIG_PATHS = ['snap.config.json'];
19
+ // CLI arguments whose values are file paths
20
+ const pathArguments = new Set([
21
+ 'src',
22
+ 's',
23
+ 'dist',
24
+ 'd',
25
+ 'bundle',
26
+ 'b',
27
+ 'root',
28
+ 'r',
29
+ ]);
15
30
  /**
16
31
  * Sets global variable snaps which tracks user settings:
17
32
  * watch mode activation, verbose errors messages, and whether to suppress warnings.
@@ -46,6 +61,9 @@ function sanitizeInputs(argv) {
46
61
  if (argv[key] === './') {
47
62
  argv[key] = '.';
48
63
  }
64
+ if (pathArguments.has(key)) {
65
+ argv[key] = path_1.default.normalize(argv[key]);
66
+ }
49
67
  }
50
68
  });
51
69
  }
@@ -1 +1 @@
1
- {"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"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","sourcesContent":["import { promises as filesystem } from 'fs';\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_PATHS = ['snap.config.json'];\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress warnings.\n *\n * @param {Argument} 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 (Object.prototype.hasOwnProperty.call(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = Boolean(argv.verboseErrors);\n }\n\n if (Object.prototype.hasOwnProperty.call(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = Boolean(argv.suppressWarnings);\n }\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param {Argument} 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 });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param msg - The error message\n * @param err - The original error\n */\nexport function logError(msg: string, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and exits.\n *\n * @param prefix - The message prefix\n * @param msg - The error message\n * @param err - The original error\n * @param destFilePath - The output file path\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n 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"]}
1
+ {"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"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","sourcesContent":["import { promises as filesystem } from 'fs';\nimport path from 'path';\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_PATHS = ['snap.config.json'];\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress warnings.\n *\n * @param {Argument} 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 (Object.prototype.hasOwnProperty.call(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = Boolean(argv.verboseErrors);\n }\n\n if (Object.prototype.hasOwnProperty.call(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = Boolean(argv.suppressWarnings);\n }\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param {Argument} argv - arguments as an object generated by yargs\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param msg - The error message\n * @param err - The original error\n */\nexport function logError(msg: string, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and exits.\n *\n * @param prefix - The message prefix\n * @param msg - The error message\n * @param err - The original error\n * @param destFilePath - The output file path\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n 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"]}
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import readline from 'readline';
3
- interface PromptArgs {
3
+ declare type PromptArgs = {
4
4
  question: string;
5
5
  defaultValue?: string;
6
6
  shouldClose?: boolean;
7
7
  readlineInterface?: readline.Interface;
8
- }
8
+ };
9
9
  export declare function prompt({ question, defaultValue, shouldClose, readlineInterface, }: PromptArgs): Promise<string>;
10
10
  export declare function closePrompt(readlineInterface?: readline.Interface): void;
11
11
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"readline.js","sourceRoot":"","sources":["../../src/utils/readline.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAEhC,IAAI,0BAA8C,CAAC;AASnD,SAAS,UAAU;IACjB,0BAA0B,GAAG,kBAAQ,CAAC,eAAe,CAAC;QACpD,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,MAAM,CAAC,EACrB,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,iBAAiB,GAAG,0BAA0B,GACnC;IACX,IAAI,kBAAkB,GAAG,iBAAiB,CAAC;IAC3C,IAAI,CAAC,kBAAkB,EAAE;QACvB,UAAU,EAAE,CAAC;QACb,kBAAkB,GAAG,0BAA0B,CAAC;KACjD;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,IAAI,WAAW,GAAG,GAAG,QAAQ,GAAG,CAAC;QACjC,IAAI,YAAY,EAAE;YAChB,WAAW,IAAI,IAAI,YAAY,IAAI,CAAC;SACrC;QAED,kBAAkB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,MAAc,EAAE,EAAE;YAC1D,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE;gBAC7B,IAAI,YAAY,KAAK,SAAS,EAAE;oBAC9B,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvB;aACF;YACD,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YACvB,IAAI,WAAW,EAAE;gBACf,kBAAkB,CAAC,KAAK,EAAE,CAAC;aAC5B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA9BD,wBA8BC;AAED,SAAgB,WAAW,CACzB,iBAAiB,GAAG,0BAA0B;IAE9C,IAAI,iBAAiB,EAAE;QACrB,iBAAiB,CAAC,KAAK,EAAE,CAAC;KAC3B;AACH,CAAC;AAND,kCAMC","sourcesContent":["import readline from 'readline';\n\nlet singletonReadlineInterface: readline.Interface;\n\ninterface PromptArgs {\n question: string;\n defaultValue?: string;\n shouldClose?: boolean;\n readlineInterface?: readline.Interface;\n}\n\nfunction openPrompt(): void {\n singletonReadlineInterface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n}\n\nexport function prompt({\n question,\n defaultValue,\n shouldClose,\n readlineInterface = singletonReadlineInterface,\n}: PromptArgs): Promise<string> {\n let _readlineInterface = readlineInterface;\n if (!_readlineInterface) {\n openPrompt();\n _readlineInterface = singletonReadlineInterface;\n }\n\n return new Promise((resolve, _reject) => {\n let queryString = `${question} `;\n if (defaultValue) {\n queryString += `(${defaultValue}) `;\n }\n\n _readlineInterface.question(queryString, (answer: string) => {\n if (!answer || !answer.trim()) {\n if (defaultValue !== undefined) {\n resolve(defaultValue);\n }\n }\n resolve(answer.trim());\n if (shouldClose) {\n _readlineInterface.close();\n }\n });\n });\n}\n\nexport function closePrompt(\n readlineInterface = singletonReadlineInterface,\n): void {\n if (readlineInterface) {\n readlineInterface.close();\n }\n}\n"]}
1
+ {"version":3,"file":"readline.js","sourceRoot":"","sources":["../../src/utils/readline.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAEhC,IAAI,0BAA8C,CAAC;AASnD,SAAS,UAAU;IACjB,0BAA0B,GAAG,kBAAQ,CAAC,eAAe,CAAC;QACpD,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,MAAM,CAAC,EACrB,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,iBAAiB,GAAG,0BAA0B,GACnC;IACX,IAAI,kBAAkB,GAAG,iBAAiB,CAAC;IAC3C,IAAI,CAAC,kBAAkB,EAAE;QACvB,UAAU,EAAE,CAAC;QACb,kBAAkB,GAAG,0BAA0B,CAAC;KACjD;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,IAAI,WAAW,GAAG,GAAG,QAAQ,GAAG,CAAC;QACjC,IAAI,YAAY,EAAE;YAChB,WAAW,IAAI,IAAI,YAAY,IAAI,CAAC;SACrC;QAED,kBAAkB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,MAAc,EAAE,EAAE;YAC1D,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE;gBAC7B,IAAI,YAAY,KAAK,SAAS,EAAE;oBAC9B,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvB;aACF;YACD,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YACvB,IAAI,WAAW,EAAE;gBACf,kBAAkB,CAAC,KAAK,EAAE,CAAC;aAC5B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA9BD,wBA8BC;AAED,SAAgB,WAAW,CACzB,iBAAiB,GAAG,0BAA0B;IAE9C,IAAI,iBAAiB,EAAE;QACrB,iBAAiB,CAAC,KAAK,EAAE,CAAC;KAC3B;AACH,CAAC;AAND,kCAMC","sourcesContent":["import readline from 'readline';\n\nlet singletonReadlineInterface: readline.Interface;\n\ntype PromptArgs = {\n question: string;\n defaultValue?: string;\n shouldClose?: boolean;\n readlineInterface?: readline.Interface;\n};\n\nfunction openPrompt(): void {\n singletonReadlineInterface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n}\n\nexport function prompt({\n question,\n defaultValue,\n shouldClose,\n readlineInterface = singletonReadlineInterface,\n}: PromptArgs): Promise<string> {\n let _readlineInterface = readlineInterface;\n if (!_readlineInterface) {\n openPrompt();\n _readlineInterface = singletonReadlineInterface;\n }\n\n return new Promise((resolve, _reject) => {\n let queryString = `${question} `;\n if (defaultValue) {\n queryString += `(${defaultValue}) `;\n }\n\n _readlineInterface.question(queryString, (answer: string) => {\n if (!answer || !answer.trim()) {\n if (defaultValue !== undefined) {\n resolve(defaultValue);\n }\n }\n resolve(answer.trim());\n if (shouldClose) {\n _readlineInterface.close();\n }\n });\n });\n}\n\nexport function closePrompt(\n readlineInterface = singletonReadlineInterface,\n): void {\n if (readlineInterface) {\n readlineInterface.close();\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "0.2.2",
3
+ "version": "0.5.0",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,7 +19,8 @@
19
19
  "build:typescript": "tsc --project ./tsconfig.local.json",
20
20
  "build:chmod": "chmod +x ./dist/main.js",
21
21
  "build": "yarn build:init-template && yarn build:typescript && yarn build:chmod",
22
- "build:clean": "yarn rimraf dist/* && yarn build",
22
+ "build:clean": "yarn clean && yarn build",
23
+ "clean": "rimraf dist/*",
23
24
  "test": "jest",
24
25
  "test:watch": "jest --watch",
25
26
  "test:ci": "yarn test",