@metamask/snaps-cli 0.36.1-flask.1 → 0.37.0-flask.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/dist/cjs/builders.js.map +1 -1
  3. package/dist/cjs/cli.js.map +1 -1
  4. package/dist/cjs/cmds/build/buildHandler.js.map +1 -1
  5. package/dist/cjs/cmds/build/bundle.js.map +1 -1
  6. package/dist/cjs/cmds/build/index.js.map +1 -1
  7. package/dist/cjs/cmds/build/utils.js.map +1 -1
  8. package/dist/cjs/cmds/eval/evalHandler.js.map +1 -1
  9. package/dist/cjs/cmds/eval/index.js.map +1 -1
  10. package/dist/cjs/cmds/manifest/index.js.map +1 -1
  11. package/dist/cjs/cmds/manifest/manifestHandler.js +1 -0
  12. package/dist/cjs/cmds/manifest/manifestHandler.js.map +1 -1
  13. package/dist/cjs/cmds/serve/index.js.map +1 -1
  14. package/dist/cjs/cmds/serve/serveHandler.js.map +1 -1
  15. package/dist/cjs/cmds/watch/index.js.map +1 -1
  16. package/dist/cjs/cmds/watch/watchHandler.js.map +1 -1
  17. package/dist/cjs/main.js.map +1 -1
  18. package/dist/cjs/utils/misc.js +1 -0
  19. package/dist/cjs/utils/misc.js.map +1 -1
  20. package/dist/cjs/utils/snap-config.js +4 -1
  21. package/dist/cjs/utils/snap-config.js.map +1 -1
  22. package/dist/esm/builders.js.map +1 -1
  23. package/dist/esm/cli.js.map +1 -1
  24. package/dist/esm/cmds/build/buildHandler.js.map +1 -1
  25. package/dist/esm/cmds/build/bundle.js +1 -1
  26. package/dist/esm/cmds/build/bundle.js.map +1 -1
  27. package/dist/esm/cmds/build/index.js.map +1 -1
  28. package/dist/esm/cmds/build/utils.js.map +1 -1
  29. package/dist/esm/cmds/eval/evalHandler.js.map +1 -1
  30. package/dist/esm/cmds/eval/index.js.map +1 -1
  31. package/dist/esm/cmds/manifest/index.js.map +1 -1
  32. package/dist/esm/cmds/manifest/manifestHandler.js +1 -0
  33. package/dist/esm/cmds/manifest/manifestHandler.js.map +1 -1
  34. package/dist/esm/cmds/serve/index.js.map +1 -1
  35. package/dist/esm/cmds/serve/serveHandler.js.map +1 -1
  36. package/dist/esm/cmds/watch/index.js.map +1 -1
  37. package/dist/esm/cmds/watch/watchHandler.js.map +1 -1
  38. package/dist/esm/main.js.map +1 -1
  39. package/dist/esm/utils/misc.js +1 -0
  40. package/dist/esm/utils/misc.js.map +1 -1
  41. package/dist/esm/utils/snap-config.js +4 -1
  42. package/dist/esm/utils/snap-config.js.map +1 -1
  43. package/dist/types/builders.d.ts +1 -1
  44. package/dist/types/cmds/build/buildHandler.d.ts +1 -1
  45. package/dist/types/cmds/build/bundle.d.ts +2 -2
  46. package/dist/types/cmds/build/index.d.ts +2 -2
  47. package/dist/types/cmds/build/utils.d.ts +1 -1
  48. package/dist/types/cmds/eval/evalHandler.d.ts +1 -1
  49. package/dist/types/cmds/eval/index.d.ts +2 -2
  50. package/dist/types/cmds/manifest/index.d.ts +2 -2
  51. package/dist/types/cmds/manifest/manifestHandler.d.ts +1 -1
  52. package/dist/types/cmds/serve/index.d.ts +2 -2
  53. package/dist/types/cmds/serve/serveHandler.d.ts +1 -1
  54. package/dist/types/cmds/watch/index.d.ts +2 -2
  55. package/dist/types/cmds/watch/watchHandler.d.ts +1 -1
  56. package/dist/types/utils/misc.d.ts +1 -1
  57. package/dist/types/utils/snap-config.d.ts +3 -3
  58. package/package.json +9 -8
package/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.37.0-flask.1]
10
+ ### Changed
11
+ - No changes this release.
12
+
9
13
  ## [0.36.1-flask.1]
10
14
  ### Changed
11
15
  - No changes this release.
@@ -360,7 +364,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
360
364
  - Example snaps ([#72](https://github.com/MetaMask/snaps-monorepo/pull/72))
361
365
  - The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
362
366
 
363
- [Unreleased]: https://github.com/MetaMask/snaps/compare/v0.36.1-flask.1...HEAD
367
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/v0.37.0-flask.1...HEAD
368
+ [0.37.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.36.1-flask.1...v0.37.0-flask.1
364
369
  [0.36.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.36.0-flask.1...v0.36.1-flask.1
365
370
  [0.36.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.35.2-flask.1...v0.36.0-flask.1
366
371
  [0.35.2-flask.1]: https://github.com/MetaMask/snaps/compare/v0.35.1-flask.1...v0.35.2-flask.1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/builders.ts"],"sourcesContent":["import { Options, PositionalOptions } 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 depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly directory: Readonly<PositionalOptions>;\n};\n\nexport enum TranspilationModes {\n LocalAndDeps = 'localAndDeps',\n LocalOnly = 'localOnly',\n None = 'none',\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: ${String(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 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 directory: {\n describe: 'the directory to use',\n type: 'string',\n },\n};\n\nexport default builders;\n"],"names":["TranspilationModes","LocalAndDeps","LocalOnly","None","builders","bundle","alias","describe","type","demandOption","normalize","default","dist","eval","manifest","port","coerce","arg","Number","parseInt","String","isNaN","Error","outfileName","root","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","choices","Object","values","depsToTranspile","verboseErrors","writeManifest","serve","directory"],"mappings":";;;;;;;;;;;;;;IAwKA,OAAwB;eAAxB;;;IAlJO;UAAKA,kBAAkB;IAAlBA,mBACVC,kBAAe;IADLD,mBAEVE,eAAY;IAFFF,mBAGVG,UAAO;GAHGH,uBAAAA;AAMZ,MAAMI,WAA6B;IACjCC,QAAQ;QACNC,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAC,MAAM;QACJN,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAE,MAAM;QACJP,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAG,UAAU;QACRR,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAI,MAAM;QACJT,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;QACTK,QAAQ,CAACC;YACP,MAAMF,OAAOG,OAAOC,QAAQ,CAACC,OAAOH,MAAM;YAC1C,IAAIC,OAAOG,KAAK,CAACN,OAAO;gBACtB,MAAM,IAAIO,MAAM,CAAC,cAAc,EAAEF,OAAOH,KAAK,CAAC;YAChD;YACA,OAAOF;QACT;IACF;IAEAQ,aAAa;QACXjB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAa,MAAM;QACJlB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAc,YAAY;QACVlB,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAe,KAAK;QACHpB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAgB,eAAe;QACbrB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAiB,kBAAkB;QAChBpB,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAkB,mBAAmB;QACjBrB,MAAM;QACND,UACE;QACFE,cAAc;QACdE,SAASX,mBAAmBE,SAAS;QACrC4B,SAASC,OAAOC,MAAM,CAAChC;IACzB;IAEAiC,iBAAiB;QACfzB,MAAM;QACND,UAAU;QACVE,cAAc;IAChB;IAEAyB,eAAe;QACb1B,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAwB,eAAe;QACb5B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAyB,OAAO;QACL7B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEA0B,WAAW;QACT9B,UAAU;QACVC,MAAM;IACR;AACF;MAEA,WAAeJ"}
1
+ {"version":3,"sources":["../../src/builders.ts"],"sourcesContent":["import type { Options, PositionalOptions } 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 depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly directory: Readonly<PositionalOptions>;\n};\n\nexport enum TranspilationModes {\n LocalAndDeps = 'localAndDeps',\n LocalOnly = 'localOnly',\n None = 'none',\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: ${String(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 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 directory: {\n describe: 'the directory to use',\n type: 'string',\n },\n};\n\nexport default builders;\n"],"names":["TranspilationModes","LocalAndDeps","LocalOnly","None","builders","bundle","alias","describe","type","demandOption","normalize","default","dist","eval","manifest","port","coerce","arg","Number","parseInt","String","isNaN","Error","outfileName","root","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","choices","Object","values","depsToTranspile","verboseErrors","writeManifest","serve","directory"],"mappings":";;;;;;;;;;;;;;IAwKA,OAAwB;eAAxB;;;IAlJO;UAAKA,kBAAkB;IAAlBA,mBACVC,kBAAe;IADLD,mBAEVE,eAAY;IAFFF,mBAGVG,UAAO;GAHGH,uBAAAA;AAMZ,MAAMI,WAA6B;IACjCC,QAAQ;QACNC,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAC,MAAM;QACJN,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAE,MAAM;QACJP,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAG,UAAU;QACRR,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAI,MAAM;QACJT,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;QACTK,QAAQ,CAACC;YACP,MAAMF,OAAOG,OAAOC,QAAQ,CAACC,OAAOH,MAAM;YAC1C,IAAIC,OAAOG,KAAK,CAACN,OAAO;gBACtB,MAAM,IAAIO,MAAM,CAAC,cAAc,EAAEF,OAAOH,KAAK,CAAC;YAChD;YACA,OAAOF;QACT;IACF;IAEAQ,aAAa;QACXjB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAa,MAAM;QACJlB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAc,YAAY;QACVlB,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAe,KAAK;QACHpB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAgB,eAAe;QACbrB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAiB,kBAAkB;QAChBpB,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAkB,mBAAmB;QACjBrB,MAAM;QACND,UACE;QACFE,cAAc;QACdE,SAASX,mBAAmBE,SAAS;QACrC4B,SAASC,OAAOC,MAAM,CAAChC;IACzB;IAEAiC,iBAAiB;QACfzB,MAAM;QACND,UAAU;QACVE,cAAc;IAChB;IAEAyB,eAAe;QACb1B,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAwB,eAAe;QACb5B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAyB,OAAO;QACL7B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEA0B,WAAW;QACT9B,UAAU;QACVC,MAAM;IACR;AACF;MAEA,WAAeJ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\n\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, @typescript-eslint/no-floating-promises\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 my-snap',\n `\\tInitialize a snap project in the 'my-snap' 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((message: string, error: Error, _yargs) => {\n logError(message, error);\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"],"names":["cli","argv","commands","rawArgv","slice","yargs","scriptName","usage","example","command","option","builders","verboseErrors","suppressWarnings","strict","middleware","yargsArgv","yargsInstance","applyConfig","loadConfig","setSnapGlobals","sanitizeInputs","fail","message","error","_yargs","logError","process","exitCode","demandCommand","help","alias"],"mappings":";;;;+BAmBgBA;;;eAAAA;;;8DAnBiB;iEAGZ;uBAOd;;;;;;AASA,SAASA,IAAIC,IAAc,EAAEC,QAAa;IAC/C,MAAMC,UAAUF,KAAKG,KAAK,CAAC;IAC3B,6GAA6G;IAC7GC,IAAAA,cAAK,EAACF,SACHG,UAAU,CAAC,WACXC,KAAK,CAAC,iCAENC,OAAO,CAAC,WAAW,CAAC,oDAAoD,CAAC,EACzEA,OAAO,CACN,mBACA,CAAC,sDAAsD,CAAC,EAEzDA,OAAO,CACN,mCACA,CAAC,2CAA2C,CAAC,EAE9CA,OAAO,CACN,8CACA,CAAC,yCAAyC,CAAC,EAE5CA,OAAO,CAAC,mBAAmB,CAAC,qCAAqC,CAAC,EAClEA,OAAO,CAAC,2BAA2B,CAAC,qCAAqC,CAAC,EAC1EA,OAAO,CACN,mCACA,CAAC,8FAA8F,CAAC,EAGjGC,OAAO,CAACP,UAERQ,MAAM,CAAC,iBAAiBC,iBAAQ,CAACC,aAAa,EAE9CF,MAAM,CAAC,oBAAoBC,iBAAQ,CAACE,gBAAgB,EAEpDC,MAAM,EAEP,gEAAgE;IAChE,+EAA+E;IAC/E,0FAA0F;KACzFC,UAAU,CACR,CAACC,WAAsBC;QACtBC,IAAAA,kBAAW,EAACC,IAAAA,iBAAU,KAAIhB,SAASa,WAAWC;QAC9CG,IAAAA,qBAAc,EAACJ;QACfK,IAAAA,qBAAc,EAACL;IACjB,GACA,MAGDM,IAAI,CAAC,CAACC,SAAiBC,OAAcC;QACpCC,IAAAA,eAAQ,EAACH,SAASC;QAClBG,QAAQC,QAAQ,GAAG;IACrB,GAECC,aAAa,CAAC,GAAG,0CAEjBC,IAAI,GACJC,KAAK,CAAC,QAAQ,KAAK9B,IAAI;AAC5B"}
1
+ {"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import type { Arguments } from 'yargs';\nimport yargs from 'yargs';\nimport type yargsType from 'yargs/yargs';\n\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, @typescript-eslint/no-floating-promises\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 my-snap',\n `\\tInitialize a snap project in the 'my-snap' 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((message: string, error: Error, _yargs) => {\n logError(message, error);\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"],"names":["cli","argv","commands","rawArgv","slice","yargs","scriptName","usage","example","command","option","builders","verboseErrors","suppressWarnings","strict","middleware","yargsArgv","yargsInstance","applyConfig","loadConfig","setSnapGlobals","sanitizeInputs","fail","message","error","_yargs","logError","process","exitCode","demandCommand","help","alias"],"mappings":";;;;+BAoBgBA;;;eAAAA;;;8DAnBE;iEAGG;uBAOd;;;;;;AASA,SAASA,IAAIC,IAAc,EAAEC,QAAa;IAC/C,MAAMC,UAAUF,KAAKG,KAAK,CAAC;IAC3B,6GAA6G;IAC7GC,IAAAA,cAAK,EAACF,SACHG,UAAU,CAAC,WACXC,KAAK,CAAC,iCAENC,OAAO,CAAC,WAAW,CAAC,oDAAoD,CAAC,EACzEA,OAAO,CACN,mBACA,CAAC,sDAAsD,CAAC,EAEzDA,OAAO,CACN,mCACA,CAAC,2CAA2C,CAAC,EAE9CA,OAAO,CACN,8CACA,CAAC,yCAAyC,CAAC,EAE5CA,OAAO,CAAC,mBAAmB,CAAC,qCAAqC,CAAC,EAClEA,OAAO,CAAC,2BAA2B,CAAC,qCAAqC,CAAC,EAC1EA,OAAO,CACN,mCACA,CAAC,8FAA8F,CAAC,EAGjGC,OAAO,CAACP,UAERQ,MAAM,CAAC,iBAAiBC,iBAAQ,CAACC,aAAa,EAE9CF,MAAM,CAAC,oBAAoBC,iBAAQ,CAACE,gBAAgB,EAEpDC,MAAM,EAEP,gEAAgE;IAChE,+EAA+E;IAC/E,0FAA0F;KACzFC,UAAU,CACR,CAACC,WAAsBC;QACtBC,IAAAA,kBAAW,EAACC,IAAAA,iBAAU,KAAIhB,SAASa,WAAWC;QAC9CG,IAAAA,qBAAc,EAACJ;QACfK,IAAAA,qBAAc,EAACL;IACjB,GACA,MAGDM,IAAI,CAAC,CAACC,SAAiBC,OAAcC;QACpCC,IAAAA,eAAQ,EAACH,SAASC;QAClBG,QAAQC,QAAQ,GAAG;IACrB,GAECC,aAAa,CAAC,GAAG,0CAEjBC,IAAI,GACJC,KAAK,CAAC,QAAQ,KAAK9B,IAAI;AAC5B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/buildHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { evalHandler } 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);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"],"names":["build","argv","src","dist","outfileName","validateOutfileName","validateFilePath","validateDirPath","outfilePath","getOutfilePath","result","bundle","loadConfig","bundlerCustomizer","eval","evalHandler","manifest","manifestHandler"],"mappings":";;;;+BAwBsBA;;;eAAAA;;;4BAnBf;uBAGoB;6BACC;iCACI;wBACT;AAahB,eAAeA,MAAMC,IAAe;IACzC,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGH;IACnC,IAAIG,aAAa;QACfC,IAAAA,+BAAmB,EAACD;IACtB;IACA,MAAME,IAAAA,4BAAgB,EAACJ;IACvB,MAAMK,IAAAA,2BAAe,EAACJ,MAAM;IAE5B,MAAMK,cAAcC,IAAAA,0BAAc,EAACN,MAAMC;IACzC,MAAMM,SAAS,MAAMC,IAAAA,cAAM,EACzBT,KACAM,aACAP,MACAW,IAAAA,iBAAU,IAAGC,iBAAiB;IAEhC,IAAIH,UAAUT,KAAKa,IAAI,EAAE;QACvB,MAAMC,IAAAA,wBAAW,EAAC;YAAE,GAAGd,IAAI;YAAEU,QAAQH;QAAY;IACnD;IAEA,IAAIP,KAAKe,QAAQ,EAAE;QACjB,MAAMC,IAAAA,gCAAe,EAAChB;IACxB;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/build/buildHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { evalHandler } 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);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"],"names":["build","argv","src","dist","outfileName","validateOutfileName","validateFilePath","validateDirPath","outfilePath","getOutfilePath","result","bundle","loadConfig","bundlerCustomizer","eval","evalHandler","manifest","manifestHandler"],"mappings":";;;;+BAwBsBA;;;eAAAA;;;4BAnBf;uBAGoB;6BACC;iCACI;wBACT;AAahB,eAAeA,MAAMC,IAAe;IACzC,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGH;IACnC,IAAIG,aAAa;QACfC,IAAAA,+BAAmB,EAACD;IACtB;IACA,MAAME,IAAAA,4BAAgB,EAACJ;IACvB,MAAMK,IAAAA,2BAAe,EAACJ,MAAM;IAE5B,MAAMK,cAAcC,IAAAA,0BAAc,EAACN,MAAMC;IACzC,MAAMM,SAAS,MAAMC,IAAAA,cAAM,EACzBT,KACAM,aACAP,MACAW,IAAAA,iBAAU,IAAGC,iBAAiB;IAEhC,IAAIH,UAAUT,KAAKa,IAAI,EAAE;QACvB,MAAMC,IAAAA,wBAAW,EAAC;YAAE,GAAGd,IAAI;YAAEU,QAAQH;QAAY;IACnD;IAEA,IAAIP,KAAKe,QAAQ,EAAE;QACjB,MAAMC,IAAAA,gCAAe,EAAChB;IACxB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/bundle.ts"],"sourcesContent":["import plugin, { Options } from '@metamask/snaps-browserify-plugin';\nimport browserify, { BrowserifyObject } from 'browserify';\n\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 async 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 >= 90', 'firefox >= 91'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\n ],\n parserOpts: {\n attachComment: !argv.stripComments,\n },\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin<Options>(plugin, {\n stripComments: argv.stripComments,\n manifestPath: undefined,\n eval: false,\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"],"names":["bundle","src","dest","argv","bundlerTransform","sourceMaps","debug","transpilationMode","babelifyOptions","processDependencies","Promise","resolve","_reject","bundler","browserify","extensions","standalone","TranspilationModes","None","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","parserOpts","attachComment","stripComments","plugin","manifestPath","undefined","eval","bundleError","bundleBuffer","writeBundleFile"],"mappings":";;;;+BAuBsBA;;;eAAAA;;;8EAvBU;mEACa;0BAEV;uBAEkB;;;;;;AAkB9C,eAAeA,OACpBC,GAAW,EACXC,IAAY,EACZC,IAAe,EACfC,gBAAsD;IAEtD,MAAM,EAAEC,YAAYC,KAAK,EAAEC,iBAAiB,EAAE,GAAGJ;IACjD,MAAMK,kBAAkBC,IAAAA,0BAAmB,EAACN;IAC5C,OAAO,IAAIO,QAAQ,CAACC,SAASC;QAC3B,MAAMC,UAAUC,IAAAA,mBAAU,EAACb,KAAK;YAC9BK;YACAS,YAAY;gBAAC;gBAAO;aAAM;YAC1B,wEAAwE;YACxEC,YAAY;QACd;QAEA,IAAIT,sBAAsBU,4BAAkB,CAACC,IAAI,EAAE;YACjDL,QAAQM,SAAS,CAACC,QAAQ,aAAa;gBACrCC,QAAQd,sBAAsBU,4BAAkB,CAACK,YAAY;gBAC7DP,YAAY;oBAAC;oBAAO;iBAAM;gBAC1BQ,SAAS;oBACPH,QAAQ;oBACR;wBACEA,QAAQ;wBACR;4BACEI,SAAS;gCACPC,UAAU;oCAAC;oCAAgB;iCAAgB;4BAC7C;wBACF;qBACD;iBACF;gBACDC,SAAS;oBACPN,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;iBACT;gBACDO,YAAY;oBACVC,eAAe,CAACzB,KAAK0B,aAAa;gBACpC;gBACA,GAAIrB,eAAe;YACrB;QACF;QAEAJ,mBAAmBS;QAEnBA,QAAQiB,MAAM,CAAUA,8BAAM,EAAE;YAC9BD,eAAe1B,KAAK0B,aAAa;YACjCE,cAAcC;YACdC,MAAM;QACR;QAEApB,QAAQb,MAAM,CACZ,OAAOkC,aAAaC,eAClB,MAAMC,IAAAA,sBAAe,EAAC;gBACpBF;gBACAC;gBACAlC;gBACAC;gBACAS;YACF;IAEN;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/build/bundle.ts"],"sourcesContent":["import type { Options } from '@metamask/snaps-browserify-plugin';\nimport plugin from '@metamask/snaps-browserify-plugin';\nimport type { BrowserifyObject } from 'browserify';\nimport browserify from 'browserify';\n\nimport { TranspilationModes } from '../../builders';\nimport type { 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, n/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 async 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 >= 90', 'firefox >= 91'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\n ],\n parserOpts: {\n attachComment: !argv.stripComments,\n },\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin<Options>(plugin, {\n stripComments: argv.stripComments,\n manifestPath: undefined,\n eval: false,\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"],"names":["bundle","src","dest","argv","bundlerTransform","sourceMaps","debug","transpilationMode","babelifyOptions","processDependencies","Promise","resolve","_reject","bundler","browserify","extensions","standalone","TranspilationModes","None","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","parserOpts","attachComment","stripComments","plugin","manifestPath","undefined","eval","bundleError","bundleBuffer","writeBundleFile"],"mappings":";;;;+BAyBsBA;;;eAAAA;;;8EAxBH;mEAEI;0BAEY;uBAEkB;;;;;;AAkB9C,eAAeA,OACpBC,GAAW,EACXC,IAAY,EACZC,IAAe,EACfC,gBAAsD;IAEtD,MAAM,EAAEC,YAAYC,KAAK,EAAEC,iBAAiB,EAAE,GAAGJ;IACjD,MAAMK,kBAAkBC,IAAAA,0BAAmB,EAACN;IAC5C,OAAO,IAAIO,QAAQ,CAACC,SAASC;QAC3B,MAAMC,UAAUC,IAAAA,mBAAU,EAACb,KAAK;YAC9BK;YACAS,YAAY;gBAAC;gBAAO;aAAM;YAC1B,wEAAwE;YACxEC,YAAY;QACd;QAEA,IAAIT,sBAAsBU,4BAAkB,CAACC,IAAI,EAAE;YACjDL,QAAQM,SAAS,CAACC,QAAQ,aAAa;gBACrCC,QAAQd,sBAAsBU,4BAAkB,CAACK,YAAY;gBAC7DP,YAAY;oBAAC;oBAAO;iBAAM;gBAC1BQ,SAAS;oBACPH,QAAQ;oBACR;wBACEA,QAAQ;wBACR;4BACEI,SAAS;gCACPC,UAAU;oCAAC;oCAAgB;iCAAgB;4BAC7C;wBACF;qBACD;iBACF;gBACDC,SAAS;oBACPN,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;iBACT;gBACDO,YAAY;oBACVC,eAAe,CAACzB,KAAK0B,aAAa;gBACpC;gBACA,GAAIrB,eAAe;YACrB;QACF;QAEAJ,mBAAmBS;QAEnBA,QAAQiB,MAAM,CAAUA,8BAAM,EAAE;YAC9BD,eAAe1B,KAAK0B,aAAa;YACjCE,cAAcC;YACdC,MAAM;QACR;QAEApB,QAAQb,MAAM,CACZ,OAAOkC,aAAaC,eAClB,MAAMC,IAAAA,sBAAe,EAAC;gBACpBF;gBACAC;gBACAlC;gBACAC;gBACAS;YACF;IAEN;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nconst command = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('dist', builders.dist)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('src', builders.src)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => build(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","dist","eval","manifest","outfileName","sourceMaps","src","stripComments","transpilationMode","depsToTranspile","writeManifest","implies","middleware","argv","processInvalidTranspilation","handler","build"],"mappings":";;;;+BA6BA;;;eAAA;;;iEA3BqB;8BAEC;uBACsB;;;;;;AAE5C,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,QAAQC,iBAAQ,CAACC,IAAI,EAC5BF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI,EAC5BH,MAAM,CAAC,YAAYC,iBAAQ,CAACG,QAAQ,EACpCJ,MAAM,CAAC,eAAeC,iBAAQ,CAACI,WAAW,EAC1CL,MAAM,CAAC,cAAcC,iBAAQ,CAACK,UAAU,EACxCN,MAAM,CAAC,OAAOC,iBAAQ,CAACM,GAAG,EAC1BP,MAAM,CAAC,iBAAiBC,iBAAQ,CAACO,aAAa,EAC9CR,MAAM,CAAC,qBAAqBC,iBAAQ,CAACQ,iBAAiB,EACtDT,MAAM,CAAC,mBAAmBC,iBAAQ,CAACS,eAAe,EAClDV,MAAM,CAAC,iBAAiBC,iBAAQ,CAACU,aAAa,EAC9CC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASC,IAAAA,kCAA2B,EAACD;IACtD;IACAE,SAAS,OAAOF,OAAoBG,IAAAA,mBAAK,EAACH;AAC5C;MAEA,WAAelB"}
1
+ {"version":3,"sources":["../../../../src/cmds/build/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nconst command = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('dist', builders.dist)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('src', builders.src)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => build(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","dist","eval","manifest","outfileName","sourceMaps","src","stripComments","transpilationMode","depsToTranspile","writeManifest","implies","middleware","argv","processInvalidTranspilation","handler","build"],"mappings":";;;;+BA6BA;;;eAAA;;;iEA3BqB;8BAEC;uBACsB;;;;;;AAE5C,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,QAAQC,iBAAQ,CAACC,IAAI,EAC5BF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI,EAC5BH,MAAM,CAAC,YAAYC,iBAAQ,CAACG,QAAQ,EACpCJ,MAAM,CAAC,eAAeC,iBAAQ,CAACI,WAAW,EAC1CL,MAAM,CAAC,cAAcC,iBAAQ,CAACK,UAAU,EACxCN,MAAM,CAAC,OAAOC,iBAAQ,CAACM,GAAG,EAC1BP,MAAM,CAAC,iBAAiBC,iBAAQ,CAACO,aAAa,EAC9CR,MAAM,CAAC,qBAAqBC,iBAAQ,CAACQ,iBAAiB,EACtDT,MAAM,CAAC,mBAAmBC,iBAAQ,CAACS,eAAe,EAClDV,MAAM,CAAC,iBAAiBC,iBAAQ,CAACU,aAAa,EAC9CC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASC,IAAAA,kCAA2B,EAACD;IACtD;IACAE,SAAS,OAAOF,OAAoBG,IAAAA,mBAAK,EAACH;AAC5C;MAEA,WAAelB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/utils.ts"],"sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\n\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { writeError } from '../../utils';\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 logInfo(`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"],"names":["writeBundleFile","processDependencies","getDependencyRegExp","sanitizeDependencyPaths","processInvalidTranspilation","bundleError","bundleBuffer","src","dest","resolve","writeError","message","fs","writeFile","toString","logInfo","error","argv","depsToTranspile","transpilationMode","babelifyOptions","TranspilationModes","LocalAndDeps","regexpStr","ignore","dependencies","regexp","includes","length","paths","shift","forEach","path","RegExp","map","dependency","replace","Error"],"mappings":";;;;;;;;;;;IA6BsBA,eAAe;eAAfA;;IA0BNC,mBAAmB;eAAnBA;;IAkBAC,mBAAmB;eAAnBA;;IAkBAC,uBAAuB;eAAvBA;;IAeAC,2BAA2B;eAA3BA;;;4BA1GQ;oBACO;0BAEI;uBAER;AAwBpB,eAAeJ,gBAAgB,EACpCK,WAAW,EACXC,YAAY,EACZC,GAAG,EACHC,IAAI,EACJC,OAAO,EACa;IACpB,IAAIJ,aAAa;QACf,MAAMK,IAAAA,iBAAU,EAAC,gBAAgBL,YAAYM,OAAO,EAAEN;IACxD;IAEA,IAAI;QACF,MAAMO,YAAE,CAACC,SAAS,CAACL,MAAMF,cAAcQ;QACvCC,IAAAA,mBAAO,EAAC,CAAC,gBAAgB,EAAER,IAAI,cAAc,EAAEC,KAAK,EAAE,CAAC;QACvDC,QAAQ;IACV,EAAE,OAAOO,OAAO;QACd,MAAMN,IAAAA,iBAAU,EAAC,gBAAgBM,MAAML,OAAO,EAAEK,OAAOR;IACzD;AACF;AAQO,SAASP,oBAAoBgB,IAAe;IACjD,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAE,GAAGF;IAC/C,MAAMG,kBAAuC,CAAC;IAC9C,IAAID,sBAAsBE,4BAAkB,CAACC,YAAY,EAAE;QACzD,MAAMC,YAAYrB,oBAAoBgB;QACtC,IAAIK,cAAc,MAAM;YACtBH,gBAAgBI,MAAM,GAAG;gBAACD;aAAU;QACtC;IACF;IACA,OAAOH;AACT;AAQO,SAASlB,oBAAoBuB,YAAsB;IACxD,IAAIC,SAAwB;IAC5B,IAAI,CAACD,gBAAgBA,aAAaE,QAAQ,CAAC,QAAQ,CAACF,aAAaG,MAAM,EAAE;QACvE,OAAOF;IACT;IACA,MAAMG,QAAkB1B,wBAAwBsB;IAChDC,SAAS,CAAC,iBAAiB,EAAEG,MAAMC,KAAK,MAAM,GAAG,CAAC;IAClDD,MAAME,OAAO,CAAC,CAACC,OAAUN,UAAU,CAAC,CAAC,EAAEM,KAAK,CAAC;IAC7CN,UAAU;IACV,OAAOO,OAAOP,QAAQ;AACxB;AAQO,SAASvB,wBAAwBsB,YAAsB;IAC5D,OAAOA,aAAaS,GAAG,CAAC,CAACC;QACvB,OAAOA,WAAWC,OAAO,CAAC,YAAY,IAAIA,OAAO,CAAC,YAAY;IAChE;AACF;AAWO,SAAShC,4BAA4Ba,IAAe;IACzD,IACEA,KAAKC,eAAe,IACpBD,KAAKE,iBAAiB,KAAKE,4BAAkB,CAACC,YAAY,EAC1D;QACA,MAAM,IAAIe,MACR;IAEJ;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/build/utils.ts"],"sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\n\nimport { TranspilationModes } from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { writeError } from '../../utils';\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 logInfo(`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"],"names":["writeBundleFile","processDependencies","getDependencyRegExp","sanitizeDependencyPaths","processInvalidTranspilation","bundleError","bundleBuffer","src","dest","resolve","writeError","message","fs","writeFile","toString","logInfo","error","argv","depsToTranspile","transpilationMode","babelifyOptions","TranspilationModes","LocalAndDeps","regexpStr","ignore","dependencies","regexp","includes","length","paths","shift","forEach","path","RegExp","map","dependency","replace","Error"],"mappings":";;;;;;;;;;;IA6BsBA,eAAe;eAAfA;;IA0BNC,mBAAmB;eAAnBA;;IAkBAC,mBAAmB;eAAnBA;;IAkBAC,uBAAuB;eAAvBA;;IAeAC,2BAA2B;eAA3BA;;;4BA1GQ;oBACO;0BAEI;uBAER;AAwBpB,eAAeJ,gBAAgB,EACpCK,WAAW,EACXC,YAAY,EACZC,GAAG,EACHC,IAAI,EACJC,OAAO,EACa;IACpB,IAAIJ,aAAa;QACf,MAAMK,IAAAA,iBAAU,EAAC,gBAAgBL,YAAYM,OAAO,EAAEN;IACxD;IAEA,IAAI;QACF,MAAMO,YAAE,CAACC,SAAS,CAACL,MAAMF,cAAcQ;QACvCC,IAAAA,mBAAO,EAAC,CAAC,gBAAgB,EAAER,IAAI,cAAc,EAAEC,KAAK,EAAE,CAAC;QACvDC,QAAQ;IACV,EAAE,OAAOO,OAAO;QACd,MAAMN,IAAAA,iBAAU,EAAC,gBAAgBM,MAAML,OAAO,EAAEK,OAAOR;IACzD;AACF;AAQO,SAASP,oBAAoBgB,IAAe;IACjD,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAE,GAAGF;IAC/C,MAAMG,kBAAuC,CAAC;IAC9C,IAAID,sBAAsBE,4BAAkB,CAACC,YAAY,EAAE;QACzD,MAAMC,YAAYrB,oBAAoBgB;QACtC,IAAIK,cAAc,MAAM;YACtBH,gBAAgBI,MAAM,GAAG;gBAACD;aAAU;QACtC;IACF;IACA,OAAOH;AACT;AAQO,SAASlB,oBAAoBuB,YAAsB;IACxD,IAAIC,SAAwB;IAC5B,IAAI,CAACD,gBAAgBA,aAAaE,QAAQ,CAAC,QAAQ,CAACF,aAAaG,MAAM,EAAE;QACvE,OAAOF;IACT;IACA,MAAMG,QAAkB1B,wBAAwBsB;IAChDC,SAAS,CAAC,iBAAiB,EAAEG,MAAMC,KAAK,MAAM,GAAG,CAAC;IAClDD,MAAME,OAAO,CAAC,CAACC,OAAUN,UAAU,CAAC,CAAC,EAAEM,KAAK,CAAC;IAC7CN,UAAU;IACV,OAAOO,OAAOP,QAAQ;AACxB;AAQO,SAASvB,wBAAwBsB,YAAsB;IAC5D,OAAOA,aAAaS,GAAG,CAAC,CAACC;QACvB,OAAOA,WAAWC,OAAO,CAAC,YAAY,IAAIA,OAAO,CAAC,YAAY;IAChE;AACF;AAWO,SAAShC,4BAA4Ba,IAAe;IACzD,IACEA,KAAKC,eAAe,IACpBD,KAAKE,iBAAiB,KAAKE,4BAAkB,CAACC,YAAY,EAC1D;QACA,MAAM,IAAIe,MACR;IAEJ;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/eval/evalHandler.ts"],"sourcesContent":["import { evalBundle, logInfo } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport { YargsArgs } from '../../types/yargs';\n\n/**\n * Runs the snap in a worker, to ensure SES compatibility.\n *\n * @param argv - The Yargs arguments object.\n * @returns A promise that resolves once the eval has finished.\n * @throws If the eval failed.\n */\nexport async function evalHandler(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n\n assert(typeof bundlePath === 'string');\n\n try {\n await evalBundle(bundlePath);\n logInfo(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"],"names":["evalHandler","argv","bundle","bundlePath","assert","evalBundle","logInfo","error","Error","message"],"mappings":";;;;+BAYsBA;;;eAAAA;;;4BAZc;uBACb;AAWhB,eAAeA,YAAYC,IAAe;IAC/C,MAAM,EAAEC,QAAQC,UAAU,EAAE,GAAGF;IAE/BG,IAAAA,aAAM,EAAC,OAAOD,eAAe;IAE7B,IAAI;QACF,MAAME,IAAAA,sBAAU,EAACF;QACjBG,IAAAA,mBAAO,EAAC,CAAC,yBAAyB,EAAEH,WAAW,SAAS,CAAC;IAC3D,EAAE,OAAOI,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,uBAAuB,EAAED,MAAME,OAAO,CAAC,CAAC;IAC3D;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/eval/evalHandler.ts"],"sourcesContent":["import { evalBundle, logInfo } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport type { YargsArgs } from '../../types/yargs';\n\n/**\n * Runs the snap in a worker, to ensure SES compatibility.\n *\n * @param argv - The Yargs arguments object.\n * @returns A promise that resolves once the eval has finished.\n * @throws If the eval failed.\n */\nexport async function evalHandler(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n\n assert(typeof bundlePath === 'string');\n\n try {\n await evalBundle(bundlePath);\n logInfo(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"],"names":["evalHandler","argv","bundle","bundlePath","assert","evalBundle","logInfo","error","Error","message"],"mappings":";;;;+BAYsBA;;;eAAAA;;;4BAZc;uBACb;AAWhB,eAAeA,YAAYC,IAAe;IAC/C,MAAM,EAAEC,QAAQC,UAAU,EAAE,GAAGF;IAE/BG,IAAAA,aAAM,EAAC,OAAOD,eAAe;IAE7B,IAAI;QACF,MAAME,IAAAA,sBAAU,EAACF;QACjBG,IAAAA,mBAAO,EAAC,CAAC,yBAAyB,EAAEH,WAAW,SAAS,CAAC;IAC3D,EAAE,OAAOI,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,uBAAuB,EAAED,MAAME,OAAO,CAAC,CAAC;IAC3D;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/eval/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { evalHandler } from './evalHandler';\n\nconst command = {\n command: ['eval', 'e'],\n desc: 'Attempt to evaluate Snap bundle in SES',\n builder: (yarg: yargs.Argv) => {\n yarg.option('bundle', builders.bundle);\n },\n handler: async (argv: YargsArgs) => evalHandler(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","bundle","handler","argv","evalHandler"],"mappings":";;;;+BAeA;;;eAAA;;;iEAbqB;6BAEO;;;;;;AAE5B,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAQ;KAAI;IACtBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,UAAUC,iBAAQ,CAACC,MAAM;IACvC;IACAC,SAAS,OAAOC,OAAoBC,IAAAA,wBAAW,EAACD;AAClD;MAEA,WAAeR"}
1
+ {"version":3,"sources":["../../../../src/cmds/eval/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { evalHandler } from './evalHandler';\n\nconst command = {\n command: ['eval', 'e'],\n desc: 'Attempt to evaluate Snap bundle in SES',\n builder: (yarg: yargs.Argv) => {\n yarg.option('bundle', builders.bundle);\n },\n handler: async (argv: YargsArgs) => evalHandler(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","bundle","handler","argv","evalHandler"],"mappings":";;;;+BAeA;;;eAAA;;;iEAbqB;6BAEO;;;;;;AAE5B,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAQ;KAAI;IACtBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,UAAUC,iBAAQ,CAACC,MAAM;IACvC;IACAC,SAAS,OAAOC,OAAoBC,IAAAA,wBAAW,EAACD;AAClD;MAEA,WAAeR"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/manifest/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\nimport { manifestHandler } from './manifestHandler';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('writeManifest', { ...builders.writeManifest, alias: ['fix'] });\n },\n handler: async (argv: YargsArgs) => {\n try {\n await manifestHandler(argv);\n } catch (error) {\n logError(error.message, error);\n throw error;\n }\n },\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","writeManifest","alias","handler","argv","manifestHandler","error","logError","message"],"mappings":";;;;+BAuBA;;;eAAA;;;iEArBqB;uBAEI;iCACO;;;;;;AAEhC,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAY;KAAI;IAC1BC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,iBAAiB;YAAE,GAAGC,iBAAQ,CAACC,aAAa;YAAEC,OAAO;gBAAC;aAAM;QAAC;IAC3E;IACAC,SAAS,OAAOC;QACd,IAAI;YACF,MAAMC,IAAAA,gCAAe,EAACD;QACxB,EAAE,OAAOE,OAAO;YACdC,IAAAA,eAAQ,EAACD,MAAME,OAAO,EAAEF;YACxB,MAAMA;QACR;IACF;AACF;MAEA,WAAeX"}
1
+ {"version":3,"sources":["../../../../src/cmds/manifest/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\nimport { manifestHandler } from './manifestHandler';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('writeManifest', { ...builders.writeManifest, alias: ['fix'] });\n },\n handler: async (argv: YargsArgs) => {\n try {\n await manifestHandler(argv);\n } catch (error) {\n logError(error.message, error);\n throw error;\n }\n },\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","writeManifest","alias","handler","argv","manifestHandler","error","logError","message"],"mappings":";;;;+BAuBA;;;eAAA;;;iEArBqB;uBAEI;iCACO;;;;;;AAEhC,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAY;KAAI;IAC1BC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,iBAAiB;YAAE,GAAGC,iBAAQ,CAACC,aAAa;YAAEC,OAAO;gBAAC;aAAM;QAAC;IAC3E;IACAC,SAAS,OAAOC;QACd,IAAI;YACF,MAAMC,IAAAA,gCAAe,EAACD;QACxB,EAAE,OAAOE,OAAO;YACdC,IAAAA,eAAQ,EAACD,MAAME,OAAO,EAAEF;YACxB,MAAMA;QACR;IACF;AACF;MAEA,WAAeX"}
@@ -16,6 +16,7 @@ async function manifestHandler({ writeManifest }) {
16
16
  if (!writeManifest && errors.length > 0) {
17
17
  (0, _snapsutils.logError)(`${ERROR_PREFIX}The manifest is invalid.`);
18
18
  errors.forEach(logManifestError);
19
+ // eslint-disable-next-line n/no-process-exit
19
20
  process.exit(1);
20
21
  }
21
22
  if (warnings.length > 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/manifest/manifestHandler.ts"],"sourcesContent":["import { checkManifest, logError, logWarning } from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\n\nconst ERROR_PREFIX = 'Manifest Error: ';\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param argv - The Yargs `argv` object.\n * @param argv.writeManifest - Whether to write the fixed manifest to disk.\n */\nexport async function manifestHandler({ writeManifest }: YargsArgs) {\n try {\n const { warnings, errors } = await checkManifest(\n process.cwd(),\n Boolean(writeManifest),\n );\n\n if (!writeManifest && errors.length > 0) {\n logError(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n logWarning(\n 'Manifest Warning: Validation of snap.manifest.json completed with warnings.',\n );\n warnings.forEach(logManifestWarning);\n }\n } catch (error) {\n throw new Error(`${ERROR_PREFIX}${error}`);\n }\n}\n\n/**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\nfunction logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n logWarning(`Manifest Warning: ${message}`);\n }\n}\n\n/**\n * Logs a manifest error.\n *\n * @param message - The message to log.\n */\nfunction logManifestError(message: string) {\n logError(`${ERROR_PREFIX}${message}`);\n}\n"],"names":["manifestHandler","ERROR_PREFIX","writeManifest","warnings","errors","checkManifest","process","cwd","Boolean","length","logError","forEach","logManifestError","exit","logWarning","logManifestWarning","error","Error","message","global","snaps","suppressWarnings"],"mappings":";;;;+BAcsBA;;;eAAAA;;;4BAd8B;AAIpD,MAAMC,eAAe;AAUd,eAAeD,gBAAgB,EAAEE,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMC,IAAAA,yBAAa,EAC9CC,QAAQC,GAAG,IACXC,QAAQN;QAGV,IAAI,CAACA,iBAAiBE,OAAOK,MAAM,GAAG,GAAG;YACvCC,IAAAA,oBAAQ,EAAC,CAAC,EAAET,aAAa,wBAAwB,CAAC;YAClDG,OAAOO,OAAO,CAACC;YAEfN,QAAQO,IAAI,CAAC;QACf;QAEA,IAAIV,SAASM,MAAM,GAAG,GAAG;YACvBK,IAAAA,sBAAU,EACR;YAEFX,SAASQ,OAAO,CAACI;QACnB;IACF,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,EAAEhB,aAAa,EAAEe,MAAM,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASD,mBAAmBG,OAAe;IACzC,IAAI,CAACC,OAAOC,KAAK,CAACC,gBAAgB,EAAE;QAClCP,IAAAA,sBAAU,EAAC,CAAC,kBAAkB,EAAEI,QAAQ,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASN,iBAAiBM,OAAe;IACvCR,IAAAA,oBAAQ,EAAC,CAAC,EAAET,aAAa,EAAEiB,QAAQ,CAAC;AACtC"}
1
+ {"version":3,"sources":["../../../../src/cmds/manifest/manifestHandler.ts"],"sourcesContent":["import { checkManifest, logError, logWarning } from '@metamask/snaps-utils';\n\nimport type { YargsArgs } from '../../types/yargs';\n\nconst ERROR_PREFIX = 'Manifest Error: ';\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param argv - The Yargs `argv` object.\n * @param argv.writeManifest - Whether to write the fixed manifest to disk.\n */\nexport async function manifestHandler({ writeManifest }: YargsArgs) {\n try {\n const { warnings, errors } = await checkManifest(\n process.cwd(),\n Boolean(writeManifest),\n );\n\n if (!writeManifest && errors.length > 0) {\n logError(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n logWarning(\n 'Manifest Warning: Validation of snap.manifest.json completed with warnings.',\n );\n warnings.forEach(logManifestWarning);\n }\n } catch (error) {\n throw new Error(`${ERROR_PREFIX}${error}`);\n }\n}\n\n/**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\nfunction logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n logWarning(`Manifest Warning: ${message}`);\n }\n}\n\n/**\n * Logs a manifest error.\n *\n * @param message - The message to log.\n */\nfunction logManifestError(message: string) {\n logError(`${ERROR_PREFIX}${message}`);\n}\n"],"names":["manifestHandler","ERROR_PREFIX","writeManifest","warnings","errors","checkManifest","process","cwd","Boolean","length","logError","forEach","logManifestError","exit","logWarning","logManifestWarning","error","Error","message","global","snaps","suppressWarnings"],"mappings":";;;;+BAcsBA;;;eAAAA;;;4BAd8B;AAIpD,MAAMC,eAAe;AAUd,eAAeD,gBAAgB,EAAEE,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMC,IAAAA,yBAAa,EAC9CC,QAAQC,GAAG,IACXC,QAAQN;QAGV,IAAI,CAACA,iBAAiBE,OAAOK,MAAM,GAAG,GAAG;YACvCC,IAAAA,oBAAQ,EAAC,CAAC,EAAET,aAAa,wBAAwB,CAAC;YAClDG,OAAOO,OAAO,CAACC;YAEf,6CAA6C;YAC7CN,QAAQO,IAAI,CAAC;QACf;QAEA,IAAIV,SAASM,MAAM,GAAG,GAAG;YACvBK,IAAAA,sBAAU,EACR;YAEFX,SAASQ,OAAO,CAACI;QACnB;IACF,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,EAAEhB,aAAa,EAAEe,MAAM,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASD,mBAAmBG,OAAe;IACzC,IAAI,CAACC,OAAOC,KAAK,CAACC,gBAAgB,EAAE;QAClCP,IAAAA,sBAAU,EAAC,CAAC,kBAAkB,EAAEI,QAAQ,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASN,iBAAiBM,OAAe;IACvCR,IAAAA,oBAAQ,EAAC,CAAC,EAAET,aAAa,EAAEiB,QAAQ,CAAC;AACtC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/serve/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { serve } from './serveHandler';\n\nconst command = {\n command: ['serve', 's'],\n desc: 'Locally serve Snap file(s) for testing',\n builder: (yarg: yargs.Argv) => {\n yarg.option('root', builders.root).option('port', builders.port);\n },\n handler: async (argv: YargsArgs) => serve(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","root","port","handler","argv","serve"],"mappings":";;;;+BAeA;;;eAAA;;;iEAbqB;8BAEC;;;;;;AAEtB,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,QAAQC,iBAAQ,CAACC,IAAI,EAAEF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI;IACjE;IACAC,SAAS,OAAOC,OAAoBC,IAAAA,mBAAK,EAACD;AAC5C;MAEA,WAAeT"}
1
+ {"version":3,"sources":["../../../../src/cmds/serve/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { serve } from './serveHandler';\n\nconst command = {\n command: ['serve', 's'],\n desc: 'Locally serve Snap file(s) for testing',\n builder: (yarg: yargs.Argv) => {\n yarg.option('root', builders.root).option('port', builders.port);\n },\n handler: async (argv: YargsArgs) => serve(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","root","port","handler","argv","serve"],"mappings":";;;;+BAeA;;;eAAA;;;iEAbqB;8BAEC;;;;;;AAEtB,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,QAAQC,iBAAQ,CAACC,IAAI,EAAEF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI;IACjE;IACAC,SAAS,OAAOC,OAAoBC,IAAAA,mBAAK,EAACD;AAC5C;MAEA,WAAeT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/serve/serveHandler.ts"],"sourcesContent":["import { logInfo, validateDirPath } from '@metamask/snaps-utils';\nimport http from 'http';\nimport serveHandler from 'serve-handler';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { logRequest, logServerError, logServerListening } from './serveUtils';\n\n/**\n * Starts a local, static HTTP server on the given port with the given root\n * directory.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.root - The root directory path string.\n * @param argv.port - The server port.\n */\nexport async function serve(argv: YargsArgs): Promise<void> {\n const { port, root: rootDir } = argv;\n\n await validateDirPath(rootDir as string, true);\n\n logInfo(`\\nStarting server...`);\n\n const server = http.createServer((req, res) => {\n serveHandler(req, res, {\n public: rootDir as string,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n })?.catch((error) => {\n logServerError(error, argv.port);\n res.statusCode = 500;\n res.end();\n });\n });\n\n server.listen({ port }, () => logServerListening(port));\n\n server.on('request', (request) => logRequest(request));\n\n server.on('error', (error) => {\n logServerError(error, argv.port);\n process.exitCode = 1;\n });\n\n server.on('close', () => {\n logInfo('Server closed');\n process.exitCode = 1;\n });\n}\n"],"names":["serve","argv","port","root","rootDir","validateDirPath","logInfo","server","http","createServer","req","res","serveHandler","public","headers","source","key","value","catch","error","logServerError","statusCode","end","listen","logServerListening","on","request","logRequest","process","exitCode"],"mappings":";;;;+BAesBA;;;eAAAA;;;4BAfmB;6DACxB;qEACQ;4BAGsC;;;;;;AAUxD,eAAeA,MAAMC,IAAe;IACzC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAGH;IAEhC,MAAMI,IAAAA,2BAAe,EAACD,SAAmB;IAEzCE,IAAAA,mBAAO,EAAC,CAAC,oBAAoB,CAAC;IAE9B,MAAMC,SAASC,aAAI,CAACC,YAAY,CAAC,CAACC,KAAKC;QACrCC,IAAAA,qBAAY,EAACF,KAAKC,KAAK;YACrBE,QAAQT;YACRU,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MAAM,CAACC;YACTC,IAAAA,0BAAc,EAACD,OAAOlB,KAAKC,IAAI;YAC/BS,IAAIU,UAAU,GAAG;YACjBV,IAAIW,GAAG;QACT;IACF;IAEAf,OAAOgB,MAAM,CAAC;QAAErB;IAAK,GAAG,IAAMsB,IAAAA,8BAAkB,EAACtB;IAEjDK,OAAOkB,EAAE,CAAC,WAAW,CAACC,UAAYC,IAAAA,sBAAU,EAACD;IAE7CnB,OAAOkB,EAAE,CAAC,SAAS,CAACN;QAClBC,IAAAA,0BAAc,EAACD,OAAOlB,KAAKC,IAAI;QAC/B0B,QAAQC,QAAQ,GAAG;IACrB;IAEAtB,OAAOkB,EAAE,CAAC,SAAS;QACjBnB,IAAAA,mBAAO,EAAC;QACRsB,QAAQC,QAAQ,GAAG;IACrB;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/serve/serveHandler.ts"],"sourcesContent":["import { logInfo, validateDirPath } from '@metamask/snaps-utils';\nimport http from 'http';\nimport serveHandler from 'serve-handler';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { logRequest, logServerError, logServerListening } from './serveUtils';\n\n/**\n * Starts a local, static HTTP server on the given port with the given root\n * directory.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.root - The root directory path string.\n * @param argv.port - The server port.\n */\nexport async function serve(argv: YargsArgs): Promise<void> {\n const { port, root: rootDir } = argv;\n\n await validateDirPath(rootDir as string, true);\n\n logInfo(`\\nStarting server...`);\n\n const server = http.createServer((req, res) => {\n serveHandler(req, res, {\n public: rootDir as string,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n })?.catch((error) => {\n logServerError(error, argv.port);\n res.statusCode = 500;\n res.end();\n });\n });\n\n server.listen({ port }, () => logServerListening(port));\n\n server.on('request', (request) => logRequest(request));\n\n server.on('error', (error) => {\n logServerError(error, argv.port);\n process.exitCode = 1;\n });\n\n server.on('close', () => {\n logInfo('Server closed');\n process.exitCode = 1;\n });\n}\n"],"names":["serve","argv","port","root","rootDir","validateDirPath","logInfo","server","http","createServer","req","res","serveHandler","public","headers","source","key","value","catch","error","logServerError","statusCode","end","listen","logServerListening","on","request","logRequest","process","exitCode"],"mappings":";;;;+BAesBA;;;eAAAA;;;4BAfmB;6DACxB;qEACQ;4BAGsC;;;;;;AAUxD,eAAeA,MAAMC,IAAe;IACzC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAGH;IAEhC,MAAMI,IAAAA,2BAAe,EAACD,SAAmB;IAEzCE,IAAAA,mBAAO,EAAC,CAAC,oBAAoB,CAAC;IAE9B,MAAMC,SAASC,aAAI,CAACC,YAAY,CAAC,CAACC,KAAKC;QACrCC,IAAAA,qBAAY,EAACF,KAAKC,KAAK;YACrBE,QAAQT;YACRU,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MAAM,CAACC;YACTC,IAAAA,0BAAc,EAACD,OAAOlB,KAAKC,IAAI;YAC/BS,IAAIU,UAAU,GAAG;YACjBV,IAAIW,GAAG;QACT;IACF;IAEAf,OAAOgB,MAAM,CAAC;QAAErB;IAAK,GAAG,IAAMsB,IAAAA,8BAAkB,EAACtB;IAEjDK,OAAOkB,EAAE,CAAC,WAAW,CAACC,UAAYC,IAAAA,sBAAU,EAACD;IAE7CnB,OAAOkB,EAAE,CAAC,SAAS,CAACN;QAClBC,IAAAA,0BAAc,EAACD,OAAOlB,KAAKC,IAAI;QAC/B0B,QAAQC,QAAQ,GAAG;IACrB;IAEAtB,OAAOkB,EAAE,CAAC,SAAS;QACjBnB,IAAAA,mBAAO,EAAC;QACRsB,QAAQC,QAAQ,GAAG;IACrB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/watch/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { processInvalidTranspilation } from '../build/utils';\nimport { watch } from './watchHandler';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => watch(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","src","eval","dist","outfileName","sourceMaps","stripComments","transpilationMode","depsToTranspile","manifest","writeManifest","serve","root","port","implies","middleware","argv","processInvalidTranspilation","handler","watch"],"mappings":";;;;+BAgCA;;;eAAA;;;iEA9BqB;uBAEuB;8BACtB;;;;;;AAEtB,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,OAAOC,iBAAQ,CAACC,GAAG,EAC1BF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI,EAC5BH,MAAM,CAAC,QAAQC,iBAAQ,CAACG,IAAI,EAC5BJ,MAAM,CAAC,eAAeC,iBAAQ,CAACI,WAAW,EAC1CL,MAAM,CAAC,cAAcC,iBAAQ,CAACK,UAAU,EACxCN,MAAM,CAAC,iBAAiBC,iBAAQ,CAACM,aAAa,EAC9CP,MAAM,CAAC,qBAAqBC,iBAAQ,CAACO,iBAAiB,EACtDR,MAAM,CAAC,mBAAmBC,iBAAQ,CAACQ,eAAe,EAClDT,MAAM,CAAC,YAAYC,iBAAQ,CAACS,QAAQ,EACpCV,MAAM,CAAC,iBAAiBC,iBAAQ,CAACU,aAAa,EAC9CX,MAAM,CAAC,SAASC,iBAAQ,CAACW,KAAK,EAC9BZ,MAAM,CAAC,QAAQC,iBAAQ,CAACY,IAAI,EAC5Bb,MAAM,CAAC,QAAQC,iBAAQ,CAACa,IAAI,EAC5BC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASC,IAAAA,kCAA2B,EAACD;IACtD;IACAE,SAAS,OAAOF,OAAoBG,IAAAA,mBAAK,EAACH;AAC5C;MAEA,WAAerB"}
1
+ {"version":3,"sources":["../../../../src/cmds/watch/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { processInvalidTranspilation } from '../build/utils';\nimport { watch } from './watchHandler';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => watch(argv),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","src","eval","dist","outfileName","sourceMaps","stripComments","transpilationMode","depsToTranspile","manifest","writeManifest","serve","root","port","implies","middleware","argv","processInvalidTranspilation","handler","watch"],"mappings":";;;;+BAgCA;;;eAAA;;;iEA9BqB;uBAEuB;8BACtB;;;;;;AAEtB,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,OAAOC,iBAAQ,CAACC,GAAG,EAC1BF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI,EAC5BH,MAAM,CAAC,QAAQC,iBAAQ,CAACG,IAAI,EAC5BJ,MAAM,CAAC,eAAeC,iBAAQ,CAACI,WAAW,EAC1CL,MAAM,CAAC,cAAcC,iBAAQ,CAACK,UAAU,EACxCN,MAAM,CAAC,iBAAiBC,iBAAQ,CAACM,aAAa,EAC9CP,MAAM,CAAC,qBAAqBC,iBAAQ,CAACO,iBAAiB,EACtDR,MAAM,CAAC,mBAAmBC,iBAAQ,CAACQ,eAAe,EAClDT,MAAM,CAAC,YAAYC,iBAAQ,CAACS,QAAQ,EACpCV,MAAM,CAAC,iBAAiBC,iBAAQ,CAACU,aAAa,EAC9CX,MAAM,CAAC,SAASC,iBAAQ,CAACW,KAAK,EAC9BZ,MAAM,CAAC,QAAQC,iBAAQ,CAACY,IAAI,EAC5Bb,MAAM,CAAC,QAAQC,iBAAQ,CAACa,IAAI,EAC5BC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASC,IAAAA,kCAA2B,EAACD;IACtD;IACAE,SAAS,OAAOF,OAAoBG,IAAAA,mBAAK,EAACH;AAC5C;MAEA,WAAerB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/watch/watchHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n logError,\n logInfo,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n NpmSnapFileNames,\n} from '@metamask/snaps-utils';\nimport chokidar from 'chokidar';\nimport pathUtils from 'path';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { CONFIG_FILE, loadConfig } from '../../utils';\nimport { bundle } from '../build/bundle';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { serve } from '../serve/serveHandler';\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.'outfileName' - The output file name.\n */\nexport async function watch(argv: YargsArgs): Promise<void> {\n const {\n dist,\n eval: shouldEval,\n manifest,\n outfileName,\n src,\n serve: shouldServe,\n } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n const srcDir = pathUtils.dirname(src);\n const watchDirs = [srcDir, NpmSnapFileNames.Manifest, CONFIG_FILE];\n const outfilePath = getOutfilePath(dist, outfileName);\n\n const buildSnap = async (path?: string, logMessage?: string) => {\n if (logMessage !== undefined) {\n logInfo(logMessage);\n }\n\n try {\n await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);\n\n if (manifest) {\n await manifestHandler(argv);\n }\n\n if (shouldEval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n } catch (error) {\n logError(\n `Error ${\n path === undefined\n ? 'during initial build'\n : `while processing \"${path}\"`\n }.`,\n error,\n );\n }\n };\n\n chokidar\n .watch(watchDirs, {\n ignoreInitial: true,\n ignored: [\n '**/node_modules/**',\n `**/${dist}/**`,\n `**/test/**`,\n `**/tests/**`,\n `**/*.test.js`,\n `**/*.test.ts`,\n /* istanbul ignore next */\n (str: string) => str !== '.' && str.startsWith('.'),\n ],\n })\n\n .on('ready', () => {\n buildSnap()\n .then(() => {\n if (shouldServe) {\n return serve(argv);\n }\n\n return undefined;\n })\n .catch((error) => {\n logError('Error during initial build.', error);\n });\n })\n .on('add', (path) => {\n buildSnap(path, `File added: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('change', (path) => {\n buildSnap(path, `File changed: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('unlink', (path) => logInfo(`File removed: ${path}`))\n .on('error', (error: Error) => {\n logError(`Watcher error: ${error.message}`, error);\n });\n\n logInfo(\n `Watching ${watchDirs.map((dir) => `'${dir}'`).join(', ')} for changes...`,\n );\n}\n"],"names":["watch","argv","dist","eval","shouldEval","manifest","outfileName","src","serve","shouldServe","validateOutfileName","validateFilePath","validateDirPath","srcDir","pathUtils","dirname","watchDirs","NpmSnapFileNames","Manifest","CONFIG_FILE","outfilePath","getOutfilePath","buildSnap","path","logMessage","undefined","logInfo","bundle","loadConfig","bundlerCustomizer","manifestHandler","evalHandler","error","logError","chokidar","ignoreInitial","ignored","str","startsWith","on","then","catch","message","map","dir","join"],"mappings":";;;;+BA+BsBA;;;eAAAA;;;4BAvBf;iEACc;6DACC;uBAGkB;wBACjB;6BACK;iCACI;8BACV;;;;;;AAcf,eAAeA,MAAMC,IAAe;IACzC,MAAM,EACJC,IAAI,EACJC,MAAMC,UAAU,EAChBC,QAAQ,EACRC,WAAW,EACXC,GAAG,EACHC,OAAOC,WAAW,EACnB,GAAGR;IACJ,IAAIK,aAAa;QACfI,IAAAA,+BAAmB,EAACJ;IACtB;IACA,MAAMK,IAAAA,4BAAgB,EAACJ;IACvB,MAAMK,IAAAA,2BAAe,EAACV,MAAM;IAC5B,MAAMW,SAASC,aAAS,CAACC,OAAO,CAACR;IACjC,MAAMS,YAAY;QAACH;QAAQI,4BAAgB,CAACC,QAAQ;QAAEC,kBAAW;KAAC;IAClE,MAAMC,cAAcC,IAAAA,0BAAc,EAACnB,MAAMI;IAEzC,MAAMgB,YAAY,OAAOC,MAAeC;QACtC,IAAIA,eAAeC,WAAW;YAC5BC,IAAAA,mBAAO,EAACF;QACV;QAEA,IAAI;YACF,MAAMG,IAAAA,cAAM,EAACpB,KAAKa,aAAan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,CAAC,EAAES;QAChD;IACF,GACCO,EAAE,CAAC,UAAU,CAAChB,OAASG,IAAAA,mBAAO,EAAC,CAAC,cAAc,EAAEH,KAAK,CAAC,GACtDgB,EAAE,CAAC,SAAS,CAACP;QACZC,IAAAA,oBAAQ,EAAC,CAAC,eAAe,EAAED,MAAMU,OAAO,CAAC,CAAC,EAAEV;IAC9C;IAEFN,IAAAA,mBAAO,EACL,CAAC,SAAS,EAAEV,UAAU2B,GAAG,CAAC,CAACC,MAAQ,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,EAAEC,IAAI,CAAC,MAAM,eAAe,CAAC;AAE9E"}
1
+ {"version":3,"sources":["../../../../src/cmds/watch/watchHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n logError,\n logInfo,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n NpmSnapFileNames,\n} from '@metamask/snaps-utils';\nimport chokidar from 'chokidar';\nimport pathUtils from 'path';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { CONFIG_FILE, loadConfig } from '../../utils';\nimport { bundle } from '../build/bundle';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { serve } from '../serve/serveHandler';\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.'outfileName' - The output file name.\n */\nexport async function watch(argv: YargsArgs): Promise<void> {\n const {\n dist,\n eval: shouldEval,\n manifest,\n outfileName,\n src,\n serve: shouldServe,\n } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n const srcDir = pathUtils.dirname(src);\n const watchDirs = [srcDir, NpmSnapFileNames.Manifest, CONFIG_FILE];\n const outfilePath = getOutfilePath(dist, outfileName);\n\n const buildSnap = async (path?: string, logMessage?: string) => {\n if (logMessage !== undefined) {\n logInfo(logMessage);\n }\n\n try {\n await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);\n\n if (manifest) {\n await manifestHandler(argv);\n }\n\n if (shouldEval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n } catch (error) {\n logError(\n `Error ${\n path === undefined\n ? 'during initial build'\n : `while processing \"${path}\"`\n }.`,\n error,\n );\n }\n };\n\n chokidar\n .watch(watchDirs, {\n ignoreInitial: true,\n ignored: [\n '**/node_modules/**',\n `**/${dist}/**`,\n `**/test/**`,\n `**/tests/**`,\n `**/*.test.js`,\n `**/*.test.ts`,\n /* istanbul ignore next */\n (str: string) => str !== '.' && str.startsWith('.'),\n ],\n })\n\n .on('ready', () => {\n buildSnap()\n .then(() => {\n if (shouldServe) {\n return serve(argv);\n }\n\n return undefined;\n })\n .catch((error) => {\n logError('Error during initial build.', error);\n });\n })\n .on('add', (path) => {\n buildSnap(path, `File added: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('change', (path) => {\n buildSnap(path, `File changed: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('unlink', (path) => logInfo(`File removed: ${path}`))\n .on('error', (error: Error) => {\n logError(`Watcher error: ${error.message}`, error);\n });\n\n logInfo(\n `Watching ${watchDirs.map((dir) => `'${dir}'`).join(', ')} for changes...`,\n );\n}\n"],"names":["watch","argv","dist","eval","shouldEval","manifest","outfileName","src","serve","shouldServe","validateOutfileName","validateFilePath","validateDirPath","srcDir","pathUtils","dirname","watchDirs","NpmSnapFileNames","Manifest","CONFIG_FILE","outfilePath","getOutfilePath","buildSnap","path","logMessage","undefined","logInfo","bundle","loadConfig","bundlerCustomizer","manifestHandler","evalHandler","error","logError","chokidar","ignoreInitial","ignored","str","startsWith","on","then","catch","message","map","dir","join"],"mappings":";;;;+BA+BsBA;;;eAAAA;;;4BAvBf;iEACc;6DACC;uBAGkB;wBACj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A,QAAQ,OAAOA,IAAIC,UAAU,CAAC;SAChD;IACH,GAECC,EAAE,CAAC,SAAS;QACXjB,YACGkB,IAAI,CAAC;YACJ,IAAI/B,aAAa;gBACf,OAAOD,IAAAA,mBAAK,EAACP;YACf;YAEA,OAAOwB;QACT,GACCgB,KAAK,CAAC,CAACT;YACNC,IAAAA,oBAAQ,EAAC,+BAA+BD;QAC1C;IACJ,GACCO,EAAE,CAAC,OAAO,CAAChB;QACVD,UAAUC,MAAM,CAAC,YAAY,EAAEA,KAAK,CAAC,EAAEkB,KAAK,CAAC,CAACT;YAC5CC,IAAAA,oBAAQ,EAAC,CAAC,wBAAwB,EAAEV,KAAK,EAAE,CAAC,EAAES;QAChD;IACF,GACCO,EAAE,CAAC,UAAU,CAAChB;QACbD,UAAUC,MAAM,CAAC,cAAc,EAAEA,KAAK,CAAC,EAAEkB,KAAK,CAAC,CAACT;YAC9CC,IAAAA,oBAAQ,EAAC,CAAC,wBAAwB,EAAEV,KAAK,EAAE,CAAC,EAAES;QAChD;IACF,GACCO,EAAE,CAAC,UAAU,CAAChB,OAASG,IAAAA,mBAAO,EAAC,CAAC,cAAc,EAAEH,KAAK,CAAC,GACtDgB,EAAE,CAAC,SAAS,CAACP;QACZC,IAAAA,oBAAQ,EAAC,CAAC,eAAe,EAAED,MAAMU,OAAO,CAAC,CAAC,EAAEV;IAC9C;IAEFN,IAAAA,mBAAO,EACL,CAAC,SAAS,EAAEV,UAAU2B,GAAG,CAAC,CAACC,MAAQ,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,EAAEC,IAAI,CAAC,MAAM,eAAe,CAAC;AAE9E"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/main.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { cli } from './cli';\nimport commands from './cmds';\n\nglobal.snaps = {\n verboseErrors: false,\n suppressWarnings: false,\n isWatching: false,\n};\n\ncli(process.argv, commands);\n"],"names":["global","snaps","verboseErrors","suppressWarnings","isWatching","cli","process","argv","commands"],"mappings":";;;;;qBAEoB;6DACC;;;;;;AAErBA,OAAOC,KAAK,GAAG;IACbC,eAAe;IACfC,kBAAkB;IAClBC,YAAY;AACd;AAEAC,IAAAA,QAAG,EAACC,QAAQC,IAAI,EAAEC,aAAQ"}
1
+ {"version":3,"sources":["../../src/main.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { cli } from './cli';\nimport commands from './cmds';\n\nglobal.snaps = {\n verboseErrors: false,\n suppressWarnings: false,\n isWatching: false,\n};\n\ncli(process.argv, commands);\n"],"names":["global","snaps","verboseErrors","suppressWarnings","isWatching","cli","process","argv","commands"],"mappings":";;;;;qBACoB;6DACC;;;;;;AAErBA,OAAOC,KAAK,GAAG;IACbC,eAAe;IACfC,kBAAkB;IAClBC,YAAY;AACd;AAEAC,IAAAA,QAAG,EAACC,QAAQC,IAAI,EAAEC,aAAQ"}
@@ -131,6 +131,7 @@ async function writeError(prefix, message, error, destFilePath) {
131
131
  if (!global.snaps.isWatching) {
132
132
  // TODO(ritave): Remove process exit and change into collapse of functions
133
133
  // https://github.com/MetaMask/snaps-monorepo/issues/81
134
+ // eslint-disable-next-line n/no-process-exit
134
135
  process.exit(1);
135
136
  }
136
137
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/misc.ts"],"sourcesContent":["import { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { 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_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"],"names":["permRequestKeys","CONFIG_FILE","setSnapGlobals","booleanStringToBoolean","sanitizeInputs","logError","writeError","trimPathString","pathArguments","Set","argv","includes","_","global","snaps","isWatching","hasProperty","verboseErrors","suppressWarnings","value","Error","String","Object","keys","forEach","key","has","path","normalize","message","error","logErrorUtil","prefix","destFilePath","processedPrefix","endsWith","filesystem","unlink","unlinkError","process","exit","pathString","replace"],"mappings":";;;;;;;;;;;IAMaA,eAAe;eAAfA;;IAUAC,WAAW;eAAXA;;IAqBGC,cAAc;eAAdA;;IA0BAC,sBAAsB;eAAtBA;;IAsBAC,cAAc;eAAdA;;IAsBAC,QAAQ;eAARA;;IAuBMC,UAAU;eAAVA;;IAmCNC,cAAc;eAAdA;;;4BArKyB;uBACb;oBACW;6DACtB;;;;;;AAGV,MAAMP,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAEM,MAAMC,cAAc;AAE3B,4CAA4C;AAC5C,MAAMO,gBAAgB,IAAIC,IAAI;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAC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;IACf;IAEA,IAAID,YAAY,QAAS,CAAA,CAACC,SAAUA,SAAS,CAACjB,OAAOC,KAAK,CAACG,aAAa,GAAI;QAC1Ec,IAAAA,oBAAY,EAAC;IACf;AACF;AAWO,eAAezB,WACpB0B,MAAc,EACdH,OAAe,EACfC,KAAY,EACZG,YAAqB;IAErB,IAAIC,kBAAkBF;IACtB,IAAI,CAACA,OAAOG,QAAQ,CAAC,MAAM;QACzBD,mBAAmB;IACrB;IAEA7B,SAAS6B,kBAAkBL,SAASC;IACpC,IAAI;QACF,IAAIG,cAAc;YAChB,MAAMG,YAAU,CAACC,MAAM,CAACJ;QAC1B;IACF,EAAE,OAAOK,aAAa;QACpBjC,SAAS,CAAC,EAAE6B,gBAAgB,8BAA8B,CAAC,EAAEI;IAC/D;IAEA,qCAAqC;IACrC,IAAI,CAACzB,OAAOC,KAAK,CAACC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,qEAAqE;QACrEwB,QAAQC,IAAI,CAAC;IACf;AACF;AASO,SAASjC,eAAekC,UAAkB;IAC/C,OAAOA,WAAWC,OAAO,CAAC,mBAAmB;AAC/C"}
1
+ {"version":3,"sources":["../../../src/utils/misc.ts"],"sourcesContent":["import { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { promises as filesystem } from 'fs';\nimport path from 'path';\nimport type { Arguments } from 'yargs';\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\n // eslint-disable-next-line n/no-process-exit\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"],"names":["permRequestKeys","CONFIG_FILE","setSnapGlobals","booleanStringToBoolean","sanitizeInputs","logError","writeError","trimPathString","pathArguments","Set","argv","includes","_","global","snaps","isWatching","hasProperty","verboseErrors","suppressWarnings","value","Error","String","Object","keys","forEach","key","has","path","normalize","message","error","logErrorUtil","prefix","destFilePath","processedPrefix","endsWith","filesystem","unlink","unlinkError","process","exit","pathString","replace"],"mappings":";;;;;;;;;;;IAMaA,eAAe;eAAfA;;IAUAC,WAAW;eAAXA;;IAqBGC,cAAc;eAAdA;;IA0BAC,sBAAsB;eAAtBA;;IAsBAC,cAAc;eAAdA;;IAsBAC,QAAQ;eAARA;;IAuBMC,UAAU;eAAVA;;IAoCNC,cAAc;eAAdA;;;4BAtKyB;uBACb;oBACW;6DACtB;;;;;;AAGV,MAAMP,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAEM,MAAMC,cAAc;AAE3B,4CAA4C;AAC5C,MAAMO,gBAAgB,IAAIC,IAAI;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AASM,SAASP,eAAeQ,IAAe;IAC5C,IAAI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C,SAAUA,SAAS,CAACjB,OAAOC,KAAK,CAACG,aAAa,GAAI;QAC1Ec,IAAAA,oBAAY,EAAC;IACf;AACF;AAWO,eAAezB,WACpB0B,MAAc,EACdH,OAAe,EACfC,KAAY,EACZG,YAAqB;IAErB,IAAIC,kBAAkBF;IACtB,IAAI,CAACA,OAAOG,QAAQ,CAAC,MAAM;QACzBD,mBAAmB;IACrB;IAEA7B,SAAS6B,kBAAkBL,SAASC;IACpC,IAAI;QACF,IAAIG,cAAc;YAChB,MAAMG,YAAU,CAACC,MAAM,CAACJ;QAC1B;IACF,EAAE,OAAOK,aAAa;QACpBjC,SAAS,CAAC,EAAE6B,gBAAgB,8BAA8B,CAAC,EAAEI;IAC/D;IAEA,qCAAqC;IACrC,IAAI,CAACzB,OAAOC,KAAK,CAACC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,qEAAqE;QACrE,6CAA6C;QAC7CwB,QAAQC,IAAI,CAAC;IACf;AACF;AASO,SAASjC,eAAekC,UAAkB;IAC/C,OAAOA,WAAWC,OAAO,CAAC,mBAAmB;AAC/C"}
@@ -47,7 +47,7 @@ function loadConfig(cached = true) {
47
47
  }
48
48
  let config;
49
49
  try {
50
- // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
50
+ // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
51
51
  config = require(_path.default.resolve(process.cwd(), _misc.CONFIG_FILE));
52
52
  } catch (error) {
53
53
  if (error.code === 'MODULE_NOT_FOUND') {
@@ -55,10 +55,12 @@ function loadConfig(cached = true) {
55
55
  return snapConfigCache;
56
56
  }
57
57
  (0, _misc.logError)(`Error during parsing of ${_misc.CONFIG_FILE}`, error);
58
+ // eslint-disable-next-line n/no-process-exit
58
59
  return process.exit(1);
59
60
  }
60
61
  if (!isSnapConfig(config)) {
61
62
  (0, _misc.logError)(`Can't validate ${_misc.CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
63
+ // eslint-disable-next-line n/no-process-exit
62
64
  return process.exit(1);
63
65
  }
64
66
  snapConfigCache = config;
@@ -93,6 +95,7 @@ function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
93
95
  }
94
96
  } else {
95
97
  (0, _misc.logError)(`Error: Encountered unrecognized config property "options.${key}" in config file "${_misc.CONFIG_FILE}". Remove the property and try again.`);
98
+ // eslint-disable-next-line n/no-process-exit
96
99
  process.exit(1);
97
100
  }
98
101
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/snap-config.ts"],"sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport { object, optional, func, Infer, is } from 'superstruct';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n process.exit(1);\n }\n }\n}\n"],"names":["SnapConfigStruct","isSnapConfig","loadConfig","applyConfig","object","cliOptions","optional","bundlerCustomizer","func","value","is","snapConfigCache","cached","undefined","config","require","path","resolve","process","cwd","CONFIG_FILE","error","code","logError","exit","snapConfig","processArgv","yargsArgv","yargsInstance","alias","aliases","key","options","getOptions","parsedProcessArgv","yargsParse","_","commandOptions","Set","Object","keys","shouldSetArg","has","hasProperty","builders"],"mappings":";;;;;;;;;;;IAaaA,gBAAgB;eAAhBA;;IAqBGC,YAAY;eAAZA;;IAeAC,UAAU;eAAVA;;IA8CAC,WAAW;eAAXA;;;uBA/FY;6DAEX;6BACiC;oEAE3B;iEAGF;sBACiB;;;;;;AAI/B,MAAMH,mBAAmBI,IAAAA,mBAAM,EAAC;IACrCC,YAAYC,IAAAA,qBAAQ,EAACF,IAAAA,mBAAM;IAC3BG,mBAAmBD,IAAAA,qBAAQ,EAACE,IAAAA,iBAAI;AAClC;AAkBO,SAASP,aAAaQ,KAAc;IACzC,OAAOC,IAAAA,eAAE,EAACD,OAAOT;AACnB;AAEA,IAAIW;AAWG,SAAST,WAAWU,SAAS,IAAI;IACtC,IAAID,oBAAoBE,aAAaD,QAAQ;QAC3C,OAAOD;IACT;IAEA,IAAIG;IACJ,IAAI;QACF,iHAAiH;QACjHA,SAASC,QAAQC,aAAI,CAACC,OAAO,CAACC,QAAQC,GAAG,IAAIC,iBAAW;IAC1D,EAAE,OAAOC,OAAY;QACnB,IAAIA,MAAMC,IAAI,KAAK,oBAAoB;YACrCX,kBAAkB,CAAC;YACnB,OAAOA;QACT;QACAY,IAAAA,cAAQ,EAAC,CAA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I,CAAC;QACf;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/utils/snap-config.ts"],"sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport type { Infer } from 'superstruct';\nimport { object, optional, func, is } from 'superstruct';\nimport type { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport type yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n // eslint-disable-next-line n/no-process-exit\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n // eslint-disable-next-line n/no-process-exit\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n }\n}\n"],"names":["SnapConfigStruct","isSnapConfig","loadConfig","applyConfig","object","cliOptions","optional","bundlerCustomizer","func","value","is","snapConfigCache","cached","undefined","config","require","path","resolve","process","cwd","CONFIG_FILE","error","code","logError","exit","snapConfig","processArgv","yargsArgv","yargsInstance","alias","aliases","key","options","getOptions","parsedProcessArgv","yargsParse","_","commandOptions","Set","Object","keys","shouldSetArg","has","hasProperty","builders"],"mappings":";;;;;;;;;;;IAcaA,gBAAgB;eAAhBA;;IAqBGC,YAAY;eAAZA;;IAeAC,UAAU;eAAVA;;IAgDAC,WAAW;eAAXA;;;uBAlGY;6DAEX;6BAE0B;oEAEpB;iEAGF;sBACiB;;;;;;AAI/B,MAAMH,mBAAmBI,IAAAA,mBAAM,EAAC;IACrCC,YAAYC,IAAAA,qBAAQ,EAACF,IAAAA,mBAAM;IAC3BG,mBAAmBD,IAAAA,qBAAQ,EAACE,IAAAA,iBAAI;AAClC;AAkBO,SAASP,aAAaQ,KAAc;IACzC,OAAOC,IAAAA,eAAE,EAACD,OAAOT;AACnB;AAEA,IAAIW;AAWG,SAAST,WAAWU,SAAS,IAAI;IACtC,IAAID,oBAAoBE,aAAaD,QAAQ;QAC3C,OAAOD;IACT;IAEA,IAAIG;IACJ,IAAI;QACF,8GAA8G;QAC9GA,SAASC,QAAQC,aAAI,CAACC,OAAO,CAACC,QAAQC,GAAG,IAAIC,iBAAW;IAC1D,EAAE,OAAOC,OAAY;QACnB,IAAIA,MAAMC,IAAI,KAAK,oBAAoB;YACrCX,kBAAkB,CAAC;YACnB,OAAOA;QACT;QACAY,IAAAA,cAAQ,EAAC,CAAC,wBAAwB,EAAEH,iBAAW,CAAC,CAAC,EAAEC;QACnD,6CAA6C;QAC7C,OAAOH,QAAQM,IAAI,CAAC;IACtB;IAEA,IAAI,CAACvB,aAAaa,SAAS;QACzBS,IAAAA,cAAQ,EACN,CAAC,eAAe,EAAEH,iBAAW,CAAC,iGAAiG,CAAC;QAElI,6CAA6C;QAC7C,OAAOF,QAAQM,IAAI,CAAC;IACtB;IACAb,kBAAkBG;IAClB,OAAOA;AACT;AAoBO,SAASX,YACdsB,UAAsB,EACtBC,WAAqB,EACrBC,SAAoB,EACpBC,aAA2B;IAE3B,uEAAuE;IACvE,wEAAwE;IACxE,6EAA6E;IAC7E,+BAA+B;IAC/B,EAAE;IACF,8EAA8E;IAC9E,2EAA2E;IAC3E,oBAAoB;IACpB,EAAE;IACF,6EAA6E;IAC7E,qBAAqB;IACrB,MAAM,EAAEC,OAAOC,OAAO,EAAEC,KAAKC,OAAO,EAAE,GAAG,AACvCJ,cACAK,UAAU;IAKZ,MAAMC,oBAAoBC,IAAAA,oBAAU,EAACT,aAAa;QAChDG,OAAOC;IACT;IACA,OAAOI,kBAAkBE,CAAC,EAAE,mCAAmC;IAE/D,MAAMC,iBAAiB,IAAIC,IAAIC,OAAOC,IAAI,CAACR;IAE3C,MAAMS,eAAe,CAACV;QACpB,OAAOM,eAAeK,GAAG,CAACX,QAAQ,CAACY,IAAAA,kBAAW,EAACT,mBAAmBH;IACpE;IAEA,MAAMjB,SAAkCW,WAAWpB,UAAU,IAAI,CAAC;IAClE,KAAK,MAAM0B,OAAOQ,OAAOC,IAAI,CAAC1B,QAAS;QACrC,IAAI6B,IAAAA,kBAAW,EAACC,iBAAQ,EAAEb,MAAM;YAC9B,IAAIU,aAAaV,MAAM;gBACrBJ,SAAS,CAACI,IAAI,GAAGjB,MAAM,CAACiB,IAAI;YAC9B;QACF,OAAO;YACLR,IAAAA,cAAQ,EACN,CAAC,yDAAyD,EAAEQ,IAAI,kBAAkB,EAAEX,iBAAW,CAAC,qCAAqC,CAAC;YAExI,6CAA6C;YAC7CF,QAAQM,IAAI,CAAC;QACf;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/builders.ts"],"sourcesContent":["import { Options, PositionalOptions } 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 depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly directory: Readonly<PositionalOptions>;\n};\n\nexport enum TranspilationModes {\n LocalAndDeps = 'localAndDeps',\n LocalOnly = 'localOnly',\n None = 'none',\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: ${String(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 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 directory: {\n describe: 'the directory to use',\n type: 'string',\n },\n};\n\nexport default builders;\n"],"names":["TranspilationModes","LocalAndDeps","LocalOnly","None","builders","bundle","alias","describe","type","demandOption","normalize","default","dist","eval","manifest","port","coerce","arg","Number","parseInt","String","isNaN","Error","outfileName","root","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","choices","Object","values","depsToTranspile","verboseErrors","writeManifest","serve","directory"],"mappings":"WAsBO;UAAKA,kBAAkB;IAAlBA,mBACVC,kBAAe;IADLD,mBAEVE,eAAY;IAFFF,mBAGVG,UAAO;GAHGH,uBAAAA;AAMZ,MAAMI,WAA6B;IACjCC,QAAQ;QACNC,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAC,MAAM;QACJN,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAE,MAAM;QACJP,OAAO;QACPC,UAAU;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AM;QACNC,cAAc;QACdE,SAAS;IACX;IAEA0B,WAAW;QACT9B,UAAU;QACVC,MAAM;IACR;AACF;AAEA,eAAeJ,SAAS"}
1
+ {"version":3,"sources":["../../src/builders.ts"],"sourcesContent":["import type { Options, PositionalOptions } 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 depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly directory: Readonly<PositionalOptions>;\n};\n\nexport enum TranspilationModes {\n LocalAndDeps = 'localAndDeps',\n LocalOnly = 'localOnly',\n None = 'none',\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: ${String(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 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 directory: {\n describe: 'the directory to use',\n type: 'string',\n },\n};\n\nexport default builders;\n"],"names":["TranspilationModes","LocalAndDeps","LocalOnly","None","builders","bundle","alias","describe","type","demandOption","normalize","default","dist","eval","manifest","port","coerce","arg","Number","parseInt","String","isNaN","Error","outfileName","root","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","choices","Object","values","depsToTranspile","verboseErrors","writeManifest","serve","directory"],"mappings":"WAsBO;UAAKA,kBAAkB;IAAlBA,mBACVC,kBAAe;IADLD,mBAEVE,eAAY;IAFFF,mBAGVG,UAAO;GAHGH,uBAAAA;AAMZ,MAAMI,WAA6B;IACjCC,QA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B,MAAM;QACND,UAAU;QACVE,cAAc;IAChB;IAEAyB,eAAe;QACb1B,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAwB,eAAe;QACb5B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAyB,OAAO;QACL7B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEA0B,WAAW;QACT9B,UAAU;QACVC,MAAM;IACR;AACF;AAEA,eAAeJ,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\n\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, @typescript-eslint/no-floating-promises\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 my-snap',\n `\\tInitialize a snap project in the 'my-snap' 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((message: string, error: Error, _yargs) => {\n logError(message, error);\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"],"names":["yargs","builders","applyConfig","loadConfig","sanitizeInputs","setSnapGlobals","logError","cli","argv","commands","rawArgv","slice","scriptName","usage","example","command","option","verboseErrors","suppressWarnings","strict","middleware","yargsArgv","yargsInstance","fail","message","error","_yargs","process","exitCode","demandCommand","help","alias"],"mappings":"AAAA,OAAOA,WAA0B,QAAQ;AAGzC,OAAOC,cAAc,aAAa;AAClC,SACEC,WAAW,EACXC,UAAU,EACVC,cAAc,EACdC,cAAc,EACdC,QAAQ,QACH,UAAU;AAEjB;;;;;;CAMC,GACD,OAAO,SAASC,IAAIC,IAAc,EAAEC,QAAa;IAC/C,MAAMC,UAAUF,KAAKG,KAAK,CAAC;IAC3B,6GAA6G;IAC7GX,MAAMU,SACHE,UAAU,CAAC,WACXC,KAAK,CAAC,iCAENC,OAAO,CAAC,WAAW,CAAC,oDAAoD,CAAC,EACzEA,OAAO,CACN,mBACA,CAAC,sDAAsD,CAAC,EAEzDA,OAAO,CACN,mCACA,CAAC,2CAA2C,CAAC,EAE9CA,OAAO,CACN,8CACA,CAAC,yCAAyC,CAAC,EAE5CA,OAAO,CAAC,mBAAmB,CAAC,qCAAqC,CAAC,EAClEA,OAAO,CAAC,2BAA2B,CAAC,qCAAqC,CAAC,EAC1EA,OAAO,CACN,mCACA,CAAC,8FAA8F,CAAC,EAGjGC,OAAO,CAACN,UAERO,MAAM,CAAC,iBAAiBf,SAASgB,aAAa,EAE9CD,MAAM,CAAC,oBAAoBf,SAASiB,gBAAgB,EAEpDC,MAAM,EAEP,gEAAgE;IAChE,+EAA+E;IAC/E,0FAA0F;KACzFC,UAAU,CACR,CAACC,WAAsBC;QACtBpB,YAAYC,cAAcO,SAASW,WAAWC;QAC9CjB,eAAegB;QACfjB,eAAeiB;IACjB,GACA,MAGDE,IAAI,CAAC,CAACC,SAAiBC,OAAcC;QACpCpB,SAASkB,SAASC;QAClBE,QAAQC,QAAQ,GAAG;IACrB,GAECC,aAAa,CAAC,GAAG,0CAEjBC,IAAI,GACJC,KAAK,CAAC,QAAQ,KAAKvB,IAAI;AAC5B"}
1
+ {"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import type { Arguments } from 'yargs';\nimport yargs from 'yargs';\nimport type yargsType from 'yargs/yargs';\n\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, @typescript-eslint/no-floating-promises\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 my-snap',\n `\\tInitialize a snap project in the 'my-snap' 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((message: string, error: Error, _yargs) => {\n logError(message, error);\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"],"names":["yargs","builders","applyConfig","loadConfig","sanitizeInputs","setSnapGlobals","logError","cli","argv","commands","rawArgv","slice","scriptName","usage","example","command","option","verboseErrors","suppressWarnings","strict","middleware","yargsArgv","yargsInstance","fail","message","error","_yargs","process","exitCode","demandCommand","help","alias"],"mappings":"AACA,OAAOA,WAAW,QAAQ;AAG1B,OAAOC,cAAc,aAAa;AAClC,SACEC,WAAW,EACXC,UAAU,EACVC,cAAc,EACdC,cAAc,EACdC,QAAQ,QACH,UAAU;AAEjB;;;;;;CAMC,GACD,OAAO,SAASC,IAAIC,IAAc,EAAEC,QAAa;IAC/C,MAAMC,UAAUF,KAAKG,KAAK,CAAC;IAC3B,6GAA6G;IAC7GX,MAAMU,SACHE,UAAU,CAAC,WACXC,KAAK,CAAC,iCAENC,OAAO,CAAC,WAAW,CAAC,oDAAoD,CAAC,EACzEA,OAAO,CACN,mBACA,CAAC,sDAAsD,CAAC,EAEzDA,OAAO,CACN,mCACA,CAAC,2CAA2C,CAAC,EAE9CA,OAAO,CACN,8CACA,CAAC,yCAAyC,CAAC,EAE5CA,OAAO,CAAC,mBAAmB,CAAC,qCAAqC,CAAC,EAClEA,OAAO,CAAC,2BAA2B,CAAC,qCAAqC,CAAC,EAC1EA,OAAO,CACN,mCACA,CAAC,8FAA8F,CAAC,EAGjGC,OAAO,CAACN,UAERO,MAAM,CAAC,iBAAiBf,SAASgB,aAAa,EAE9CD,MAAM,CAAC,oBAAoBf,SAASiB,gBAAgB,EAEpDC,MAAM,EAEP,gEAAgE;IAChE,+EAA+E;IAC/E,0FAA0F;KACzFC,UAAU,CACR,CAACC,WAAsBC;QACtBpB,YAAYC,cAAcO,SAASW,WAAWC;QAC9CjB,eAAegB;QACfjB,eAAeiB;IACjB,GACA,MAGDE,IAAI,CAAC,CAACC,SAAiBC,OAAcC;QACpCpB,SAASkB,SAASC;QAClBE,QAAQC,QAAQ,GAAG;IACrB,GAECC,aAAa,CAAC,GAAG,0CAEjBC,IAAI,GACJC,KAAK,CAAC,QAAQ,KAAKvB,IAAI;AAC5B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/buildHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { evalHandler } 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);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"],"names":["getOutfilePath","validateDirPath","validateFilePath","validateOutfileName","loadConfig","evalHandler","manifestHandler","bundle","build","argv","src","dist","outfileName","outfilePath","result","bundlerCustomizer","eval","manifest"],"mappings":"AAAA,SACEA,cAAc,EACdC,eAAe,EACfC,gBAAgB,EAChBC,mBAAmB,QACd,wBAAwB;AAG/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,WAAW,QAAQ,sBAAsB;AAClD,SAASC,eAAe,QAAQ,8BAA8B;AAC9D,SAASC,MAAM,QAAQ,WAAW;AAElC;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,MAAMC,IAAe;IACzC,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGH;IACnC,IAAIG,aAAa;QACfT,oBAAoBS;IACtB;IACA,MAAMV,iBAAiBQ;IACvB,MAAMT,gBAAgBU,MAAM;IAE5B,MAAME,cAAcb,eAAeW,MAAMC;IACzC,MAAME,SAAS,MAAMP,OACnBG,KACAG,aACAJ,MACAL,aAAaW,iBAAiB;IAEhC,IAAID,UAAUL,KAAKO,IAAI,EAAE;QACvB,MAAMX,YAAY;YAAE,GAAGI,IAAI;YAAEF,QAAQM;QAAY;IACnD;IAEA,IAAIJ,KAAKQ,QAAQ,EAAE;QACjB,MAAMX,gBAAgBG;IACxB;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/build/buildHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { evalHandler } 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);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"],"names":["getOutfilePath","validateDirPath","validateFilePath","validateOutfileName","loadConfig","evalHandler","manifestHandler","bundle","build","argv","src","dist","outfileName","outfilePath","result","bundlerCustomizer","eval","manifest"],"mappings":"AAAA,SACEA,cAAc,EACdC,eAAe,EACfC,gBAAgB,EAChBC,mBAAmB,QACd,wBAAwB;AAG/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,WAAW,QAAQ,sBAAsB;AAClD,SAASC,eAAe,QAAQ,8BAA8B;AAC9D,SAASC,MAAM,QAAQ,WAAW;AAElC;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,MAAMC,IAAe;IACzC,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGH;IACnC,IAAIG,aAAa;QACfT,oBAAoBS;IACtB;IACA,MAAMV,iBAAiBQ;IACvB,MAAMT,gBAAgBU,MAAM;IAE5B,MAAME,cAAcb,eAAeW,MAAMC;IACzC,MAAME,SAAS,MAAMP,OACnBG,KACAG,aACAJ,MACAL,aAAaW,iBAAiB;IAEhC,IAAID,UAAUL,KAAKO,IAAI,EAAE;QACvB,MAAMX,YAAY;YAAE,GAAGI,IAAI;YAAEF,QAAQM;QAAY;IACnD;IAEA,IAAIJ,KAAKQ,QAAQ,EAAE;QACjB,MAAMX,gBAAgBG;IACxB;AACF"}
@@ -4,7 +4,7 @@ import { TranspilationModes } from '../../builders';
4
4
  import { processDependencies, writeBundleFile } from './utils';
5
5
  // We need to statically import all Browserify transforms and all Babel presets
6
6
  // and plugins, and calling `require` is the sanest way to do that.
7
- /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */ /**
7
+ /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */ /**
8
8
  * Builds a Snap bundle JS file from its JavaScript source.
9
9
  *
10
10
  * @param src - The source file path.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/bundle.ts"],"sourcesContent":["import plugin, { Options } from '@metamask/snaps-browserify-plugin';\nimport browserify, { BrowserifyObject } from 'browserify';\n\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 async 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 >= 90', 'firefox >= 91'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\n ],\n parserOpts: {\n attachComment: !argv.stripComments,\n },\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin<Options>(plugin, {\n stripComments: argv.stripComments,\n manifestPath: undefined,\n eval: false,\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"],"names":["plugin","browserify","TranspilationModes","processDependencies","writeBundleFile","bundle","src","dest","argv","bundlerTransform","sourceMaps","debug","transpilationMode","babelifyOptions","Promise","resolve","_reject","bundler","extensions","standalone","None","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","parserOpts","attachComment","stripComments","manifestPath","undefined","eval","bundleError","bundleBuffer"],"mappings":"AAAA,OAAOA,YAAyB,oCAAoC;AACpE,OAAOC,gBAAsC,aAAa;AAE1D,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,mBAAmB,EAAEC,eAAe,QAAQ,UAAU;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,iHAAiH,GAEjH;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,OACpBC,GAAW,EACXC,IAAY,EACZC,IAAe,EACfC,gBAAsD;IAEtD,MAAM,EAAEC,YAAYC,KAAK,EAAEC,iBAAiB,EAAE,GAAGJ;IACjD,MAAMK,kBAAkBV,oBAAoBK;IAC5C,OAAO,IAAIM,QAAQ,CAACC,SAASC;QAC3B,MAAMC,UAAUhB,WAAWK,KAAK;YAC9BK;YACAO,YAAY;gBAAC;gBAAO;aAAM;YAC1B,wEAAwE;YACxEC,YAAY;QACd;QAEA,IAAIP,sBAAsBV,mBAAmBkB,IAAI,EAAE;YACjDH,QAAQI,SAAS,CAACC,QAAQ,aAAa;gBACrCC,QAAQX,sBAAsBV,mBAAmBsB,YAAY;gBAC7DN,YAAY;oBAAC;oBAAO;iBAAM;gBAC1BO,SAAS;oBACPH,QAAQ;oBACR;wBACEA,QAAQ;wBACR;4BACEI,SAAS;gCACPC,UAAU;oCAAC;oCAAgB;iCAAgB;4BAC7C;wBACF;qBACD;iBACF;gBACDC,SAAS;oBACPN,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;iBACT;gBACDO,YAAY;oBACVC,eAAe,CAACtB,KAAKuB,aAAa;gBACpC;gBACA,GAAIlB,eAAe;YACrB;QACF;QAEAJ,mBAAmBQ;QAEnBA,QAAQjB,MAAM,CAAUA,QAAQ;YAC9B+B,eAAevB,KAAKuB,aAAa;YACjCC,cAAcC;YACdC,MAAM;QACR;QAEAjB,QAAQZ,MAAM,CACZ,OAAO8B,aAAaC,eAClB,MAAMhC,gBAAgB;gBACpB+B;gBACAC;gBACA9B;gBACAC;gBACAQ;YACF;IAEN;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/build/bundle.ts"],"sourcesContent":["import type { Options } from '@metamask/snaps-browserify-plugin';\nimport plugin from '@metamask/snaps-browserify-plugin';\nimport type { BrowserifyObject } from 'browserify';\nimport browserify from 'browserify';\n\nimport { TranspilationModes } from '../../builders';\nimport type { 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, n/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 async 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 >= 90', 'firefox >= 91'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\n ],\n parserOpts: {\n attachComment: !argv.stripComments,\n },\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin<Options>(plugin, {\n stripComments: argv.stripComments,\n manifestPath: undefined,\n eval: false,\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"],"names":["plugin","browserify","TranspilationModes","processDependencies","writeBundleFile","bundle","src","dest","argv","bundlerTransform","sourceMaps","debug","transpilationMode","babelifyOptions","Promise","resolve","_reject","bundler","extensions","standalone","None","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","parserOpts","attachComment","stripComments","manifestPath","undefined","eval","bundleError","bundleBuffer"],"mappings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;YACF;IAEN;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nconst command = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('dist', builders.dist)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('src', builders.src)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => build(argv),\n};\n\nexport default command;\n"],"names":["builders","build","processInvalidTranspilation","command","desc","builder","yarg","option","dist","eval","manifest","outfileName","sourceMaps","src","stripComments","transpilationMode","depsToTranspile","writeManifest","implies","middleware","argv","handler"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,2BAA2B,QAAQ,UAAU;AAEtD,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,QAAQP,SAASQ,IAAI,EAC5BD,MAAM,CAAC,QAAQP,SAASS,IAAI,EAC5BF,MAAM,CAAC,YAAYP,SAASU,QAAQ,EACpCH,MAAM,CAAC,eAAeP,SAASW,WAAW,EAC1CJ,MAAM,CAAC,cAAcP,SAASY,UAAU,EACxCL,MAAM,CAAC,OAAOP,SAASa,GAAG,EAC1BN,MAAM,CAAC,iBAAiBP,SAASc,aAAa,EAC9CP,MAAM,CAAC,qBAAqBP,SAASe,iBAAiB,EACtDR,MAAM,CAAC,mBAAmBP,SAASgB,eAAe,EAClDT,MAAM,CAAC,iBAAiBP,SAASiB,aAAa,EAC9CC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASlB,4BAA4BkB;IACtD;IACAC,SAAS,OAAOD,OAAoBnB,MAAMmB;AAC5C;AAEA,eAAejB,QAAQ"}
1
+ {"version":3,"sources":["../../../../src/cmds/build/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nconst command = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('dist', builders.dist)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('src', builders.src)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => build(argv),\n};\n\nexport default command;\n"],"names":["builders","build","processInvalidTranspilation","command","desc","builder","yarg","option","dist","eval","manifest","outfileName","sourceMaps","src","stripComments","transpilationMode","depsToTranspile","writeManifest","implies","middleware","argv","handler"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,2BAA2B,QAAQ,UAAU;AAEtD,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,QAAQP,SAASQ,IAAI,EAC5BD,MAAM,CAAC,QAAQP,SAASS,IAAI,EAC5BF,MAAM,CAAC,YAAYP,SAASU,QAAQ,EACpCH,MAAM,CAAC,eAAeP,SAASW,WAAW,EAC1CJ,MAAM,CAAC,cAAcP,SAASY,UAAU,EACxCL,MAAM,CAAC,OAAOP,SAASa,GAAG,EAC1BN,MAAM,CAAC,iBAAiBP,SAASc,aAAa,EAC9CP,MAAM,CAAC,qBAAqBP,SAASe,iBAAiB,EACtDR,MAAM,CAAC,mBAAmBP,SAASgB,eAAe,EAClDT,MAAM,CAAC,iBAAiBP,SAASiB,aAAa,EAC9CC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASlB,4BAA4BkB;IACtD;IACAC,SAAS,OAAOD,OAAoBnB,MAAMmB;AAC5C;AAEA,eAAejB,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/build/utils.ts"],"sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\n\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { writeError } from '../../utils';\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 logInfo(`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"],"names":["logInfo","promises","fs","TranspilationModes","writeError","writeBundleFile","bundleError","bundleBuffer","src","dest","resolve","message","writeFile","toString","error","processDependencies","argv","depsToTranspile","transpilationMode","babelifyOptions","LocalAndDeps","regexpStr","getDependencyRegExp","ignore","dependencies","regexp","includes","length","paths","sanitizeDependencyPaths","shift","forEach","path","RegExp","map","dependency","replace","processInvalidTranspilation","Error"],"mappings":"AAAA,SAASA,OAAO,QAAQ,wBAAwB;AAChD,SAASC,YAAYC,EAAE,QAAQ,KAAK;AAEpC,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,UAAU,QAAQ,cAAc;AAUzC;;;;;;;;;;;;;CAaC,GACD,OAAO,eAAeC,gBAAgB,EACpCC,WAAW,EACXC,YAAY,EACZC,GAAG,EACHC,IAAI,EACJC,OAAO,EACa;IACpB,IAAIJ,aAAa;QACf,MAAMF,WAAW,gBAAgBE,YAAYK,OAAO,EAAEL;IACxD;IAEA,IAAI;QACF,MAAMJ,GAAGU,SAAS,CAACH,MAAMF,cAAcM;QACvCb,QAAQ,CAAC,gBAAgB,EAAEQ,IAAI,cAAc,EAAEC,KAAK,EAAE,CAAC;QACvDC,QAAQ;IACV,EAAE,OAAOI,OAAO;QACd,MAAMV,WAAW,gBAAgBU,MAAMH,OAAO,EAAEG,OAAOL;IACzD;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASM,oBAAoBC,IAAe;IACjD,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAE,GAAGF;IAC/C,MAAMG,kBAAuC,CAAC;IAC9C,IAAID,sBAAsBf,mBAAmBiB,YAAY,EAAE;QACzD,MAAMC,YAAYC,oBAAoBL;QACtC,IAAII,cAAc,MAAM;YACtBF,gBAAgBI,MAAM,GAAG;gBAACF;aAAU;QACtC;IACF;IACA,OAAOF;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASG,oBAAoBE,YAAsB;IACxD,IAAIC,SAAwB;IAC5B,IAAI,CAACD,gBAAgBA,aAAaE,QAAQ,CAAC,QAAQ,CAACF,aAAaG,MAAM,EAAE;QACvE,OAAOF;IACT;IACA,MAAMG,QAAkBC,wBAAwBL;IAChDC,SAAS,CAAC,iBAAiB,EAAEG,MAAME,KAAK,MAAM,GAAG,CAAC;IAClDF,MAAMG,OAAO,CAAC,CAACC,OAAUP,UAAU,CAAC,CAAC,EAAEO,KAAK,CAAC;IAC7CP,UAAU;IACV,OAAOQ,OAAOR,QAAQ;AACxB;AAEA;;;;;CAKC,GACD,OAAO,SAASI,wBAAwBL,YAAsB;IAC5D,OAAOA,aAAaU,GAAG,CAAC,CAACC;QACvB,OAAOA,WAAWC,OAAO,CAAC,YAAY,IAAIA,OAAO,CAAC,YAAY;IAChE;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASC,4BAA4BrB,IAAe;IACzD,IACEA,KAAKC,eAAe,IACpBD,KAAKE,iBAAiB,KAAKf,mBAAmBiB,YAAY,EAC1D;QACA,MAAM,IAAIkB,MACR;IAEJ;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/build/utils.ts"],"sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\n\nimport { TranspilationModes } from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { writeError } from '../../utils';\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 logInfo(`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"],"names":["logInfo","promises","fs","TranspilationModes","writeError","writeBundleFile","bundleError","bundleBuffer","src","dest","resolve","message","writeFile","toString","error","processDependencies","argv","depsToTranspile","transpilationMode","babelifyOptions","LocalAndDeps","regexpStr","getDependencyRegExp","ignore","dependencies","regexp","includes","length","paths","sanitizeDependencyPaths","shift","forEach","path","RegExp","map","dependency","replace","processInvalidTranspilation","Error"],"mappings":"AAAA,SAASA,OAAO,QAAQ,wBAAwB;AAChD,SAASC,YAAYC,EAAE,QAAQ,KAAK;AAEpC,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,UAAU,QAAQ,cAAc;AAUzC;;;;;;;;;;;;;CAaC,GACD,OAAO,eAAeC,gBAAgB,EACpCC,WAAW,EACXC,YAAY,EACZC,GAAG,EACHC,IAAI,EACJC,OAAO,EACa;IACpB,IAAIJ,aAAa;QACf,MAAMF,WAAW,gBAAgBE,YAAYK,OAAO,EAAEL;IACxD;IAEA,IAAI;QACF,MAAMJ,GAAGU,SAAS,CAACH,MAAMF,cAAcM;QACvCb,QAAQ,CAAC,gBAAgB,EAAEQ,IAAI,cAAc,EAAEC,KAAK,EAAE,CAAC;QACvDC,QAAQ;IACV,EAAE,OAAOI,OAAO;QACd,MAAMV,WAAW,gBAAgBU,MAAMH,OAAO,EAAEG,OAAOL;IACzD;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASM,oBAAoBC,IAAe;IACjD,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAE,GAAGF;IAC/C,MAAMG,kBAAuC,CAAC;IAC9C,IAAID,sBAAsBf,mBAAmBiB,YAAY,EAAE;QACzD,MAAMC,YAAYC,oBAAoBL;QACtC,IAAII,cAAc,MAAM;YACtBF,gBAAgBI,MAAM,GAAG;gBAACF;aAAU;QACtC;IACF;IACA,OAAOF;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASG,oBAAoBE,YAAsB;IACxD,IAAIC,SAAwB;IAC5B,IAAI,CAACD,gBAAgBA,aAAaE,QAAQ,CAAC,QAAQ,CAACF,aAAaG,MAAM,EAAE;QACvE,OAAOF;IACT;IACA,MAAMG,QAAkBC,wBAAwBL;IAChDC,SAAS,CAAC,iBAAiB,EAAEG,MAAME,KAAK,MAAM,GAAG,CAAC;IAClDF,MAAMG,OAAO,CAAC,CAACC,OAAUP,UAAU,CAAC,CAAC,EAAEO,KAAK,CAAC;IAC7CP,UAAU;IACV,OAAOQ,OAAOR,QAAQ;AACxB;AAEA;;;;;CAKC,GACD,OAAO,SAASI,wBAAwBL,YAAsB;IAC5D,OAAOA,aAAaU,GAAG,CAAC,CAACC;QACvB,OAAOA,WAAWC,OAAO,CAAC,YAAY,IAAIA,OAAO,CAAC,YAAY;IAChE;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASC,4BAA4BrB,IAAe;IACzD,IACEA,KAAKC,eAAe,IACpBD,KAAKE,iBAAiB,KAAKf,mBAAmBiB,YAAY,EAC1D;QACA,MAAM,IAAIkB,MACR;IAEJ;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/eval/evalHandler.ts"],"sourcesContent":["import { evalBundle, logInfo } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport { YargsArgs } from '../../types/yargs';\n\n/**\n * Runs the snap in a worker, to ensure SES compatibility.\n *\n * @param argv - The Yargs arguments object.\n * @returns A promise that resolves once the eval has finished.\n * @throws If the eval failed.\n */\nexport async function evalHandler(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n\n assert(typeof bundlePath === 'string');\n\n try {\n await evalBundle(bundlePath);\n logInfo(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"],"names":["evalBundle","logInfo","assert","evalHandler","argv","bundle","bundlePath","error","Error","message"],"mappings":"AAAA,SAASA,UAAU,EAAEC,OAAO,QAAQ,wBAAwB;AAC5D,SAASC,MAAM,QAAQ,kBAAkB;AAIzC;;;;;;CAMC,GACD,OAAO,eAAeC,YAAYC,IAAe;IAC/C,MAAM,EAAEC,QAAQC,UAAU,EAAE,GAAGF;IAE/BF,OAAO,OAAOI,eAAe;IAE7B,IAAI;QACF,MAAMN,WAAWM;QACjBL,QAAQ,CAAC,yBAAyB,EAAEK,WAAW,SAAS,CAAC;IAC3D,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,uBAAuB,EAAED,MAAME,OAAO,CAAC,CAAC;IAC3D;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/eval/evalHandler.ts"],"sourcesContent":["import { evalBundle, logInfo } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport type { YargsArgs } from '../../types/yargs';\n\n/**\n * Runs the snap in a worker, to ensure SES compatibility.\n *\n * @param argv - The Yargs arguments object.\n * @returns A promise that resolves once the eval has finished.\n * @throws If the eval failed.\n */\nexport async function evalHandler(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n\n assert(typeof bundlePath === 'string');\n\n try {\n await evalBundle(bundlePath);\n logInfo(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"],"names":["evalBundle","logInfo","assert","evalHandler","argv","bundle","bundlePath","error","Error","message"],"mappings":"AAAA,SAASA,UAAU,EAAEC,OAAO,QAAQ,wBAAwB;AAC5D,SAASC,MAAM,QAAQ,kBAAkB;AAIzC;;;;;;CAMC,GACD,OAAO,eAAeC,YAAYC,IAAe;IAC/C,MAAM,EAAEC,QAAQC,UAAU,EAAE,GAAGF;IAE/BF,OAAO,OAAOI,eAAe;IAE7B,IAAI;QACF,MAAMN,WAAWM;QACjBL,QAAQ,CAAC,yBAAyB,EAAEK,WAAW,SAAS,CAAC;IAC3D,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,uBAAuB,EAAED,MAAME,OAAO,CAAC,CAAC;IAC3D;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/eval/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { evalHandler } from './evalHandler';\n\nconst command = {\n command: ['eval', 'e'],\n desc: 'Attempt to evaluate Snap bundle in SES',\n builder: (yarg: yargs.Argv) => {\n yarg.option('bundle', builders.bundle);\n },\n handler: async (argv: YargsArgs) => evalHandler(argv),\n};\n\nexport default command;\n"],"names":["builders","evalHandler","command","desc","builder","yarg","option","bundle","handler","argv"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,WAAW,QAAQ,gBAAgB;AAE5C,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAQ;KAAI;IACtBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,UAAUN,SAASO,MAAM;IACvC;IACAC,SAAS,OAAOC,OAAoBR,YAAYQ;AAClD;AAEA,eAAeP,QAAQ"}
1
+ {"version":3,"sources":["../../../../src/cmds/eval/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { evalHandler } from './evalHandler';\n\nconst command = {\n command: ['eval', 'e'],\n desc: 'Attempt to evaluate Snap bundle in SES',\n builder: (yarg: yargs.Argv) => {\n yarg.option('bundle', builders.bundle);\n },\n handler: async (argv: YargsArgs) => evalHandler(argv),\n};\n\nexport default command;\n"],"names":["builders","evalHandler","command","desc","builder","yarg","option","bundle","handler","argv"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,WAAW,QAAQ,gBAAgB;AAE5C,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAQ;KAAI;IACtBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,UAAUN,SAASO,MAAM;IACvC;IACAC,SAAS,OAAOC,OAAoBR,YAAYQ;AAClD;AAEA,eAAeP,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/manifest/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\nimport { manifestHandler } from './manifestHandler';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('writeManifest', { ...builders.writeManifest, alias: ['fix'] });\n },\n handler: async (argv: YargsArgs) => {\n try {\n await manifestHandler(argv);\n } catch (error) {\n logError(error.message, error);\n throw error;\n }\n },\n};\n\nexport default command;\n"],"names":["builders","logError","manifestHandler","command","desc","builder","yarg","option","writeManifest","alias","handler","argv","error","message"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,QAAQ,QAAQ,cAAc;AACvC,SAASC,eAAe,QAAQ,oBAAoB;AAEpD,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAY;KAAI;IAC1BC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,iBAAiB;YAAE,GAAGP,SAASQ,aAAa;YAAEC,OAAO;gBAAC;aAAM;QAAC;IAC3E;IACAC,SAAS,OAAOC;QACd,IAAI;YACF,MAAMT,gBAAgBS;QACxB,EAAE,OAAOC,OAAO;YACdX,SAASW,MAAMC,OAAO,EAAED;YACxB,MAAMA;QACR;IACF;AACF;AAEA,eAAeT,QAAQ"}
1
+ {"version":3,"sources":["../../../../src/cmds/manifest/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\nimport { manifestHandler } from './manifestHandler';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('writeManifest', { ...builders.writeManifest, alias: ['fix'] });\n },\n handler: async (argv: YargsArgs) => {\n try {\n await manifestHandler(argv);\n } catch (error) {\n logError(error.message, error);\n throw error;\n }\n },\n};\n\nexport default command;\n"],"names":["builders","logError","manifestHandler","command","desc","builder","yarg","option","writeManifest","alias","handler","argv","error","message"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,QAAQ,QAAQ,cAAc;AACvC,SAASC,eAAe,QAAQ,oBAAoB;AAEpD,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAY;KAAI;IAC1BC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,iBAAiB;YAAE,GAAGP,SAASQ,aAAa;YAAEC,OAAO;gBAAC;aAAM;QAAC;IAC3E;IACAC,SAAS,OAAOC;QACd,IAAI;YACF,MAAMT,gBAAgBS;QACxB,EAAE,OAAOC,OAAO;YACdX,SAASW,MAAMC,OAAO,EAAED;YACxB,MAAMA;QACR;IACF;AACF;AAEA,eAAeT,QAAQ"}
@@ -13,6 +13,7 @@ const ERROR_PREFIX = 'Manifest Error: ';
13
13
  if (!writeManifest && errors.length > 0) {
14
14
  logError(`${ERROR_PREFIX}The manifest is invalid.`);
15
15
  errors.forEach(logManifestError);
16
+ // eslint-disable-next-line n/no-process-exit
16
17
  process.exit(1);
17
18
  }
18
19
  if (warnings.length > 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/manifest/manifestHandler.ts"],"sourcesContent":["import { checkManifest, logError, logWarning } from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\n\nconst ERROR_PREFIX = 'Manifest Error: ';\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param argv - The Yargs `argv` object.\n * @param argv.writeManifest - Whether to write the fixed manifest to disk.\n */\nexport async function manifestHandler({ writeManifest }: YargsArgs) {\n try {\n const { warnings, errors } = await checkManifest(\n process.cwd(),\n Boolean(writeManifest),\n );\n\n if (!writeManifest && errors.length > 0) {\n logError(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n logWarning(\n 'Manifest Warning: Validation of snap.manifest.json completed with warnings.',\n );\n warnings.forEach(logManifestWarning);\n }\n } catch (error) {\n throw new Error(`${ERROR_PREFIX}${error}`);\n }\n}\n\n/**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\nfunction logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n logWarning(`Manifest Warning: ${message}`);\n }\n}\n\n/**\n * Logs a manifest error.\n *\n * @param message - The message to log.\n */\nfunction logManifestError(message: string) {\n logError(`${ERROR_PREFIX}${message}`);\n}\n"],"names":["checkManifest","logError","logWarning","ERROR_PREFIX","manifestHandler","writeManifest","warnings","errors","process","cwd","Boolean","length","forEach","logManifestError","exit","logManifestWarning","error","Error","message","global","snaps","suppressWarnings"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,EAAEC,UAAU,QAAQ,wBAAwB;AAI5E,MAAMC,eAAe;AAErB;;;;;;;CAOC,GACD,OAAO,eAAeC,gBAAgB,EAAEC,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMP,cACjCQ,QAAQC,GAAG,IACXC,QAAQL;QAGV,IAAI,CAACA,iBAAiBE,OAAOI,MAAM,GAAG,GAAG;YACvCV,SAAS,CAAC,EAAEE,aAAa,wBAAwB,CAAC;YAClDI,OAAOK,OAAO,CAACC;YAEfL,QAAQM,IAAI,CAAC;QACf;QAEA,IAAIR,SAASK,MAAM,GAAG,GAAG;YACvBT,WACE;YAEFI,SAASM,OAAO,CAACG;QACnB;IACF,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,EAAEd,aAAa,EAAEa,MAAM,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASD,mBAAmBG,OAAe;IACzC,IAAI,CAACC,OAAOC,KAAK,CAACC,gBAAgB,EAAE;QAClCnB,WAAW,CAAC,kBAAkB,EAAEgB,QAAQ,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASL,iBAAiBK,OAAe;IACvCjB,SAAS,CAAC,EAAEE,aAAa,EAAEe,QAAQ,CAAC;AACtC"}
1
+ {"version":3,"sources":["../../../../src/cmds/manifest/manifestHandler.ts"],"sourcesContent":["import { checkManifest, logError, logWarning } from '@metamask/snaps-utils';\n\nimport type { YargsArgs } from '../../types/yargs';\n\nconst ERROR_PREFIX = 'Manifest Error: ';\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param argv - The Yargs `argv` object.\n * @param argv.writeManifest - Whether to write the fixed manifest to disk.\n */\nexport async function manifestHandler({ writeManifest }: YargsArgs) {\n try {\n const { warnings, errors } = await checkManifest(\n process.cwd(),\n Boolean(writeManifest),\n );\n\n if (!writeManifest && errors.length > 0) {\n logError(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n logWarning(\n 'Manifest Warning: Validation of snap.manifest.json completed with warnings.',\n );\n warnings.forEach(logManifestWarning);\n }\n } catch (error) {\n throw new Error(`${ERROR_PREFIX}${error}`);\n }\n}\n\n/**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\nfunction logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n logWarning(`Manifest Warning: ${message}`);\n }\n}\n\n/**\n * Logs a manifest error.\n *\n * @param message - The message to log.\n */\nfunction logManifestError(message: string) {\n logError(`${ERROR_PREFIX}${message}`);\n}\n"],"names":["checkManifest","logError","logWarning","ERROR_PREFIX","manifestHandler","writeManifest","warnings","errors","process","cwd","Boolean","length","forEach","logManifestError","exit","logManifestWarning","error","Error","message","global","snaps","suppressWarnings"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,EAAEC,UAAU,QAAQ,wBAAwB;AAI5E,MAAMC,eAAe;AAErB;;;;;;;CAOC,GACD,OAAO,eAAeC,gBAAgB,EAAEC,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMP,cACjCQ,QAAQC,GAAG,IACXC,QAAQL;QAGV,IAAI,CAACA,iBAAiBE,OAAOI,MAAM,GAAG,GAAG;YACvCV,SAAS,CAAC,EAAEE,aAAa,wBAAwB,CAAC;YAClDI,OAAOK,OAAO,CAACC;YAEf,6CAA6C;YAC7CL,QAAQM,IAAI,CAAC;QACf;QAEA,IAAIR,SAASK,MAAM,GAAG,GAAG;YACvBT,WACE;YAEFI,SAASM,OAAO,CAACG;QACnB;IACF,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MAAM,CAAC,EAAEd,aAAa,EAAEa,MAAM,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASD,mBAAmBG,OAAe;IACzC,IAAI,CAACC,OAAOC,KAAK,CAACC,gBAAgB,EAAE;QAClCnB,WAAW,CAAC,kBAAkB,EAAEgB,QAAQ,CAAC;IAC3C;AACF;AAEA;;;;CAIC,GACD,SAASL,iBAAiBK,OAAe;IACvCjB,SAAS,CAAC,EAAEE,aAAa,EAAEe,QAAQ,CAAC;AACtC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/serve/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { serve } from './serveHandler';\n\nconst command = {\n command: ['serve', 's'],\n desc: 'Locally serve Snap file(s) for testing',\n builder: (yarg: yargs.Argv) => {\n yarg.option('root', builders.root).option('port', builders.port);\n },\n handler: async (argv: YargsArgs) => serve(argv),\n};\n\nexport default command;\n"],"names":["builders","serve","command","desc","builder","yarg","option","root","port","handler","argv"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,QAAQN,SAASO,IAAI,EAAED,MAAM,CAAC,QAAQN,SAASQ,IAAI;IACjE;IACAC,SAAS,OAAOC,OAAoBT,MAAMS;AAC5C;AAEA,eAAeR,QAAQ"}
1
+ {"version":3,"sources":["../../../../src/cmds/serve/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { serve } from './serveHandler';\n\nconst command = {\n command: ['serve', 's'],\n desc: 'Locally serve Snap file(s) for testing',\n builder: (yarg: yargs.Argv) => {\n yarg.option('root', builders.root).option('port', builders.port);\n },\n handler: async (argv: YargsArgs) => serve(argv),\n};\n\nexport default command;\n"],"names":["builders","serve","command","desc","builder","yarg","option","root","port","handler","argv"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,QAAQN,SAASO,IAAI,EAAED,MAAM,CAAC,QAAQN,SAASQ,IAAI;IACjE;IACAC,SAAS,OAAOC,OAAoBT,MAAMS;AAC5C;AAEA,eAAeR,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/serve/serveHandler.ts"],"sourcesContent":["import { logInfo, validateDirPath } from '@metamask/snaps-utils';\nimport http from 'http';\nimport serveHandler from 'serve-handler';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { logRequest, logServerError, logServerListening } from './serveUtils';\n\n/**\n * Starts a local, static HTTP server on the given port with the given root\n * directory.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.root - The root directory path string.\n * @param argv.port - The server port.\n */\nexport async function serve(argv: YargsArgs): Promise<void> {\n const { port, root: rootDir } = argv;\n\n await validateDirPath(rootDir as string, true);\n\n logInfo(`\\nStarting server...`);\n\n const server = http.createServer((req, res) => {\n serveHandler(req, res, {\n public: rootDir as string,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n })?.catch((error) => {\n logServerError(error, argv.port);\n res.statusCode = 500;\n res.end();\n });\n });\n\n server.listen({ port }, () => logServerListening(port));\n\n server.on('request', (request) => logRequest(request));\n\n server.on('error', (error) => {\n logServerError(error, argv.port);\n process.exitCode = 1;\n });\n\n server.on('close', () => {\n logInfo('Server closed');\n process.exitCode = 1;\n });\n}\n"],"names":["logInfo","validateDirPath","http","serveHandler","logRequest","logServerError","logServerListening","serve","argv","port","root","rootDir","server","createServer","req","res","public","headers","source","key","value","catch","error","statusCode","end","listen","on","request","process","exitCode"],"mappings":"AAAA,SAASA,OAAO,EAAEC,eAAe,QAAQ,wBAAwB;AACjE,OAAOC,UAAU,OAAO;AACxB,OAAOC,kBAAkB,gBAAgB;AAGzC,SAASC,UAAU,EAAEC,cAAc,EAAEC,kBAAkB,QAAQ,eAAe;AAE9E;;;;;;;CAOC,GACD,OAAO,eAAeC,MAAMC,IAAe;IACzC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAGH;IAEhC,MAAMP,gBAAgBU,SAAmB;IAEzCX,QAAQ,CAAC,oBAAoB,CAAC;IAE9B,MAAMY,SAASV,KAAKW,YAAY,CAAC,CAACC,KAAKC;QACrCZ,aAAaW,KAAKC,KAAK;YACrBC,QAAQL;YACRM,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MAAM,CAACC;YACTjB,eAAeiB,OAAOd,KAAKC,IAAI;YAC/BM,IAAIQ,UAAU,GAAG;YACjBR,IAAIS,GAAG;QACT;IACF;IAEAZ,OAAOa,MAAM,CAAC;QAAEhB;IAAK,GAAG,IAAMH,mBAAmBG;IAEjDG,OAAOc,EAAE,CAAC,WAAW,CAACC,UAAYvB,WAAWuB;IAE7Cf,OAAOc,EAAE,CAAC,SAAS,CAACJ;QAClBjB,eAAeiB,OAAOd,KAAKC,IAAI;QAC/BmB,QAAQC,QAAQ,GAAG;IACrB;IAEAjB,OAAOc,EAAE,CAAC,SAAS;QACjB1B,QAAQ;QACR4B,QAAQC,QAAQ,GAAG;IACrB;AACF"}
1
+ {"version":3,"sources":["../../../../src/cmds/serve/serveHandler.ts"],"sourcesContent":["import { logInfo, validateDirPath } from '@metamask/snaps-utils';\nimport http from 'http';\nimport serveHandler from 'serve-handler';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { logRequest, logServerError, logServerListening } from './serveUtils';\n\n/**\n * Starts a local, static HTTP server on the given port with the given root\n * directory.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.root - The root directory path string.\n * @param argv.port - The server port.\n */\nexport async function serve(argv: YargsArgs): Promise<void> {\n const { port, root: rootDir } = argv;\n\n await validateDirPath(rootDir as string, true);\n\n logInfo(`\\nStarting server...`);\n\n const server = http.createServer((req, res) => {\n serveHandler(req, res, {\n public: rootDir as string,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n })?.catch((error) => {\n logServerError(error, argv.port);\n res.statusCode = 500;\n res.end();\n });\n });\n\n server.listen({ port }, () => logServerListening(port));\n\n server.on('request', (request) => logRequest(request));\n\n server.on('error', (error) => {\n logServerError(error, argv.port);\n process.exitCode = 1;\n });\n\n server.on('close', () => {\n logInfo('Server closed');\n process.exitCode = 1;\n });\n}\n"],"names":["logInfo","validateDirPath","http","serveHandler","logRequest","logServerError","logServerListening","serve","argv","port","root","rootDir","server","createServer","req","res","public","headers","source","key","value","catch","error","statusCode","end","listen","on","request","process","exitCode"],"mappings":"AAAA,SAASA,OAAO,EAAEC,eAAe,QAAQ,wBAAwB;AACjE,OAAOC,UAAU,OAAO;AACxB,OAAOC,kBAAkB,gBAAgB;AAGzC,SAASC,UAAU,EAAEC,cAAc,EAAEC,kBAAkB,QAAQ,eAAe;AAE9E;;;;;;;CAOC,GACD,OAAO,eAAeC,MAAMC,IAAe;IACzC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAE,GAAGH;IAEhC,MAAMP,gBAAgBU,SAAmB;IAEzCX,QAAQ,CAAC,oBAAoB,CAAC;IAE9B,MAAMY,SAASV,KAAKW,YAAY,CAAC,CAACC,KAAKC;QACrCZ,aAAaW,KAAKC,KAAK;YACrBC,QAAQL;YACRM,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MAAM,CAACC;YACTjB,eAAeiB,OAAOd,KAAKC,IAAI;YAC/BM,IAAIQ,UAAU,GAAG;YACjBR,IAAIS,GAAG;QACT;IACF;IAEAZ,OAAOa,MAAM,CAAC;QAAEhB;IAAK,GAAG,IAAMH,mBAAmBG;IAEjDG,OAAOc,EAAE,CAAC,WAAW,CAACC,UAAYvB,WAAWuB;IAE7Cf,OAAOc,EAAE,CAAC,SAAS,CAACJ;QAClBjB,eAAeiB,OAAOd,KAAKC,IAAI;QAC/BmB,QAAQC,QAAQ,GAAG;IACrB;IAEAjB,OAAOc,EAAE,CAAC,SAAS;QACjB1B,QAAQ;QACR4B,QAAQC,QAAQ,GAAG;IACrB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/watch/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { processInvalidTranspilation } from '../build/utils';\nimport { watch } from './watchHandler';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => watch(argv),\n};\n\nexport default command;\n"],"names":["builders","processInvalidTranspilation","watch","command","desc","builder","yarg","option","src","eval","dist","outfileName","sourceMaps","stripComments","transpilationMode","depsToTranspile","manifest","writeManifest","serve","root","port","implies","middleware","argv","handler"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,2BAA2B,QAAQ,iBAAiB;AAC7D,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,OAAOP,SAASQ,GAAG,EAC1BD,MAAM,CAAC,QAAQP,SAASS,IAAI,EAC5BF,MAAM,CAAC,QAAQP,SAASU,IAAI,EAC5BH,MAAM,CAAC,eAAeP,SAASW,WAAW,EAC1CJ,MAAM,CAAC,cAAcP,SAASY,UAAU,EACxCL,MAAM,CAAC,iBAAiBP,SAASa,aAAa,EAC9CN,MAAM,CAAC,qBAAqBP,SAASc,iBAAiB,EACtDP,MAAM,CAAC,mBAAmBP,SAASe,eAAe,EAClDR,MAAM,CAAC,YAAYP,SAASgB,QAAQ,EACpCT,MAAM,CAAC,iBAAiBP,SAASiB,aAAa,EAC9CV,MAAM,CAAC,SAASP,SAASkB,KAAK,EAC9BX,MAAM,CAAC,QAAQP,SAASmB,IAAI,EAC5BZ,MAAM,CAAC,QAAQP,SAASoB,IAAI,EAC5BC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAAStB,4BAA4BsB;IACtD;IACAC,SAAS,OAAOD,OAAoBrB,MAAMqB;AAC5C;AAEA,eAAepB,QAAQ"}
1
+ {"version":3,"sources":["../../../../src/cmds/watch/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { processInvalidTranspilation } from '../build/utils';\nimport { watch } from './watchHandler';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => watch(argv),\n};\n\nexport default command;\n"],"names":["builders","processInvalidTranspilation","watch","command","desc","builder","yarg","option","src","eval","dist","outfileName","sourceMaps","stripComments","transpilationMode","depsToTranspile","manifest","writeManifest","serve","root","port","implies","middleware","argv","handler"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,2BAA2B,QAAQ,iBAAiB;AAC7D,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,OAAOP,SAASQ,GAAG,EAC1BD,MAAM,CAAC,QAAQP,SAASS,IAAI,EAC5BF,MAAM,CAAC,QAAQP,SAASU,IAAI,EAC5BH,MAAM,CAAC,eAAeP,SAASW,WAAW,EAC1CJ,MAAM,CAAC,cAAcP,SAASY,UAAU,EACxCL,MAAM,CAAC,iBAAiBP,SAASa,aAAa,EAC9CN,MAAM,CAAC,qBAAqBP,SAASc,iBAAiB,EACtDP,MAAM,CAAC,mBAAmBP,SAASe,eAAe,EAClDR,MAAM,CAAC,YAAYP,SAASgB,QAAQ,EACpCT,MAAM,CAAC,iBAAiBP,SAASiB,aAAa,EAC9CV,MAAM,CAAC,SAASP,SAASkB,KAAK,EAC9BX,MAAM,CAAC,QAAQP,SAASmB,IAAI,EAC5BZ,MAAM,CAAC,QAAQP,SAASoB,IAAI,EAC5BC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAAStB,4BAA4BsB;IACtD;IACAC,SAAS,OAAOD,OAAoBrB,MAAMqB;AAC5C;AAEA,eAAepB,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/cmds/watch/watchHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n logError,\n logInfo,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n NpmSnapFileNames,\n} from '@metamask/snaps-utils';\nimport chokidar from 'chokidar';\nimport pathUtils from 'path';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { CONFIG_FILE, loadConfig } from '../../utils';\nimport { bundle } from '../build/bundle';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { serve } from '../serve/serveHandler';\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.'outfileName' - The output file name.\n */\nexport async function watch(argv: YargsArgs): Promise<void> {\n const {\n dist,\n eval: shouldEval,\n manifest,\n outfileName,\n src,\n serve: shouldServe,\n } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n const srcDir = pathUtils.dirname(src);\n const watchDirs = [srcDir, NpmSnapFileNames.Manifest, CONFIG_FILE];\n const outfilePath = getOutfilePath(dist, outfileName);\n\n const buildSnap = async (path?: string, logMessage?: string) => {\n if (logMessage !== undefined) {\n logInfo(logMessage);\n }\n\n try {\n await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);\n\n if (manifest) {\n await manifestHandler(argv);\n }\n\n if (shouldEval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n } catch (error) {\n logError(\n `Error ${\n path === undefined\n ? 'during initial build'\n : `while processing \"${path}\"`\n }.`,\n error,\n );\n }\n };\n\n chokidar\n .watch(watchDirs, {\n ignoreInitial: true,\n ignored: [\n '**/node_modules/**',\n `**/${dist}/**`,\n `**/test/**`,\n `**/tests/**`,\n `**/*.test.js`,\n `**/*.test.ts`,\n /* istanbul ignore next */\n (str: string) => str !== '.' && str.startsWith('.'),\n ],\n })\n\n .on('ready', () => {\n buildSnap()\n .then(() => {\n if (shouldServe) {\n return serve(argv);\n }\n\n return undefined;\n })\n .catch((error) => {\n logError('Error during initial build.', error);\n });\n })\n .on('add', (path) => {\n buildSnap(path, `File added: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('change', (path) => {\n buildSnap(path, `File changed: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('unlink', (path) => logInfo(`File removed: ${path}`))\n .on('error', (error: Error) => {\n logError(`Watcher error: ${error.message}`, error);\n });\n\n logInfo(\n `Watching ${watchDirs.map((dir) => `'${dir}'`).join(', ')} for changes...`,\n );\n}\n"],"names":["getOutfilePath","logError","logInfo","validateDirPath","validateFilePath","validateOutfileName","NpmSnapFileNames","chokidar","pathUtils","CONFIG_FILE","loadConfig","bundle","evalHandler","manifestHandler","serve","watch","argv","dist","eval","shouldEval","manifest","outfileName","src","shouldServe","srcDir","dirname","watchDirs","Manifest","outfilePath","buildSnap","path","logMessage","undefined","bundlerCustomizer","error","ignoreInitial","ignored","str","startsWith","on","then","catch","message","map","dir","join"],"mappings":"AAAA,SACEA,cAAc,EACdC,QAAQ,EACRC,OAAO,EACPC,eAAe,EACfC,gBAAgB,EAChBC,mBAAmB,EACnBC,gBAAgB,QACX,wBAAwB;AAC/B,OAAOC,cAAc,WAAW;AAChC,OAAOC,eAAe,OAAO;AAG7B,SAASC,WAAW,EAAEC,UAAU,QAAQ,cAAc;AACtD,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,WAAW,QAAQ,sBAAsB;AAClD,SAASC,eAAe,QAAQ,8BAA8B;AAC9D,SAASC,KAAK,QAAQ,wBAAwB;AAE9C;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,MAAMC,IAAe;IACzC,MAAM,EACJC,IAAI,EACJC,MAAMC,UAAU,EAChBC,QAAQ,EACRC,WAAW,EACXC,GAAG,EACHR,OAAOS,WAAW,EACnB,GAAGP;IACJ,IAAIK,aAAa;QACfhB,oBAAoBgB;IACtB;IACA,MAAMjB,iBAAiBkB;IACvB,MAAMnB,gBAAgBc,MAAM;IAC5B,MAAMO,SAAShB,UAAUiB,OAAO,CAACH;IACjC,MAAMI,YAAY;QAACF;QAAQlB,iBAAiBqB,QAAQ;QAAElB;KAAY;IAClE,MAAMmB,cAAc5B,eA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6B,KAAK,EAAE,CAAC,EAAEI;QAChD;IACF,GACCK,EAAE,CAAC,UAAU,CAACT,OAAS5B,QAAQ,CAAC,cAAc,EAAE4B,KAAK,CAAC,GACtDS,EAAE,CAAC,SAAS,CAACL;QACZjC,SAAS,CAAC,eAAe,EAAEiC,MAAMQ,OAAO,CAAC,CAAC,EAAER;IAC9C;IAEFhC,QACE,CAAC,SAAS,EAAEwB,UAAUiB,GAAG,CAAC,CAACC,MAAQ,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,EAAEC,IAAI,CAAC,MAAM,eAAe,CAAC;AAE9E"}
1
+ {"version":3,"sources":["../../../../src/cmds/watch/watchHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n logError,\n logInfo,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n NpmSnapFileNames,\n} from '@metamask/snaps-utils';\nimport chokidar from 'chokidar';\nimport pathUtils from 'path';\n\nimport type { YargsArgs } from '../../types/yargs';\nimport { CONFIG_FILE, loadConfig } from '../../utils';\nimport { bundle } from '../build/bundle';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { serve } from '../serve/serveHandler';\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Arguments as an object generated by Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.'outfileName' - The output file name.\n */\nexport async function watch(argv: YargsArgs): Promise<void> {\n const {\n dist,\n eval: shouldEval,\n manifest,\n outfileName,\n src,\n serve: shouldServe,\n } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n const srcDir = pathUtils.dirname(src);\n const watchDirs = [srcDir, NpmSnapFileNames.Manifest, CONFIG_FILE];\n const outfilePath = getOutfilePath(dist, outfileName);\n\n const buildSnap = async (path?: string, logMessage?: string) => {\n if (logMessage !== undefined) {\n logInfo(logMessage);\n }\n\n try {\n await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);\n\n if (manifest) {\n await manifestHandler(argv);\n }\n\n if (shouldEval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n } catch (error) {\n logError(\n `Error ${\n path === undefined\n ? 'during initial build'\n : `while processing \"${path}\"`\n }.`,\n error,\n );\n }\n };\n\n chokidar\n .watch(watchDirs, {\n ignoreInitial: true,\n ignored: [\n '**/node_modules/**',\n `**/${dist}/**`,\n `**/test/**`,\n `**/tests/**`,\n `**/*.test.js`,\n `**/*.test.ts`,\n /* istanbul ignore next */\n (str: string) => str !== '.' && str.startsWith('.'),\n ],\n })\n\n .on('ready', () => {\n buildSnap()\n .then(() => {\n if (shouldServe) {\n return serve(argv);\n }\n\n return undefined;\n })\n .catch((error) => {\n logError('Error during initial build.', error);\n });\n })\n .on('add', (path) => {\n buildSnap(path, `File added: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('change', (path) => {\n buildSnap(path, `File changed: ${path}`).catch((error) => {\n logError(`Error while processing \"${path}\".`, error);\n });\n })\n .on('unlink', (path) => logInfo(`File removed: ${path}`))\n .on('error', (error: Error) => {\n logError(`Watcher error: ${error.message}`, error);\n });\n\n logInfo(\n `Watching ${watchDirs.map((dir) => `'${dir}'`).join(', ')} for changes...`,\n );\n}\n"],"names":["getOutfilePath","logError","logInfo","validateDirPath","validateFilePath","validateOutfileName","NpmSnapFileNames","chokidar","pathUtils","CONFIG_FILE","loadConfig","bundle","evalHandler","manifestHandler","serve","watch","argv","dist","eval","shouldEval","manifest","outfileName","src","shouldServe","srcDir","dirname","watchDirs","Manifest","outfilePath","buildSnap","path","logMessage","undefined","bundlerCustomizer","error","ignoreInitial","ignored","str","startsWith","on","then","catch","message","map","dir","join"],"mappings":"AAAA,SACEA,cAAc,EACdC,QAAQ,EACRC,OAAO,EACPC,eAAe,EACfC,gBAAgB,EAChBC,mBA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;YACf,CAAC,UAAU,CAAC;YACZ,CAAC,WAAW,CAAC;YACb,CAAC,YAAY,CAAC;YACd,CAAC,YAAY,CAAC;YACd,wBAAwB,GACxB,CAACoB,MAAgBA,QAAQ,OAAOA,IAAIC,UAAU,CAAC;SAChD;IACH,GAECC,EAAE,CAAC,SAAS;QACXV,YACGW,IAAI,CAAC;YACJ,IAAIjB,aAAa;gBACf,OAAOT,MAAME;YACf;YAEA,OAAOgB;QACT,GACCS,KAAK,CAAC,CAACP;YACNjC,SAAS,+BAA+BiC;QAC1C;IACJ,GACCK,EAAE,CAAC,OAAO,CAACT;QACVD,UAAUC,MAAM,CAAC,YAAY,EAAEA,KAAK,CAAC,EAAEW,KAAK,CAAC,CAACP;YAC5CjC,SAAS,CAAC,wBAAwB,EAAE6B,KAAK,EAAE,CAAC,EAAEI;QAChD;IACF,GACCK,EAAE,CAAC,UAAU,CAACT;QACbD,UAAUC,MAAM,CAAC,cAAc,EAAEA,KAAK,CAAC,EAAEW,KAAK,CAAC,CAACP;YAC9CjC,SAAS,CAAC,wBAAwB,EAAE6B,KAAK,EAAE,CAAC,EAAEI;QAChD;IACF,GACCK,EAAE,CAAC,UAAU,CAACT,OAAS5B,QAAQ,CAAC,cAAc,EAAE4B,KAAK,CAAC,GACtDS,EAAE,CAAC,SAAS,CAACL;QACZjC,SAAS,CAAC,eAAe,EAAEiC,MAAMQ,OAAO,CAAC,CAAC,EAAER;IAC9C;IAEFhC,QACE,CAAC,SAAS,EAAEwB,UAAUiB,GAAG,CAAC,CAACC,MAAQ,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,EAAEC,IAAI,CAAC,MAAM,eAAe,CAAC;AAE9E"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/main.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { cli } from './cli';\nimport commands from './cmds';\n\nglobal.snaps = {\n verboseErrors: false,\n suppressWarnings: false,\n isWatching: false,\n};\n\ncli(process.argv, commands);\n"],"names":["cli","commands","global","snaps","verboseErrors","suppressWarnings","isWatching","process","argv"],"mappings":";AAEA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,OAAOC,cAAc,SAAS;AAE9BC,OAAOC,KAAK,GAAG;IACbC,eAAe;IACfC,kBAAkB;IAClBC,YAAY;AACd;AAEAN,IAAIO,QAAQC,IAAI,EAAEP"}
1
+ {"version":3,"sources":["../../src/main.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { cli } from './cli';\nimport commands from './cmds';\n\nglobal.snaps = {\n verboseErrors: false,\n suppressWarnings: false,\n isWatching: false,\n};\n\ncli(process.argv, commands);\n"],"names":["cli","commands","global","snaps","verboseErrors","suppressWarnings","isWatching","process","argv"],"mappings":";AACA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,OAAOC,cAAc,SAAS;AAE9BC,OAAOC,KAAK,GAAG;IACbC,eAAe;IACfC,kBAAkB;IAClBC,YAAY;AACd;AAEAN,IAAIO,QAAQC,IAAI,EAAEP"}
@@ -122,6 +122,7 @@ const pathArguments = new Set([
122
122
  if (!global.snaps.isWatching) {
123
123
  // TODO(ritave): Remove process exit and change into collapse of functions
124
124
  // https://github.com/MetaMask/snaps-monorepo/issues/81
125
+ // eslint-disable-next-line n/no-process-exit
125
126
  process.exit(1);
126
127
  }
127
128
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/misc.ts"],"sourcesContent":["import { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { 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_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"],"names":["logError","logErrorUtil","hasProperty","promises","filesystem","path","permRequestKeys","CONFIG_FILE","pathArguments","Set","setSnapGlobals","argv","includes","_","global","snaps","isWatching","verboseErrors","booleanStringToBoolean","suppressWarnings","value","Error","String","sanitizeInputs","Object","keys","forEach","key","has","normalize","message","error","writeError","prefix","destFilePath","processedPrefix","endsWith","unlink","unlinkError","process","exit","trimPathString","pathString","replace"],"mappings":"AAAA,SAASA,YAAYC,YAAY,QAAQ,wBAAwB;AACjE,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,YAAYC,UAAU,QAAQ,KAAK;AAC5C,OAAOC,UAAU,OAAO;AAGxB,OAAO,MAAMC,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,cAAc,iBAAiB;AAE5C,4CAA4C;AAC5C,MAAMC,gBAAgB,IAAIC,IAAI;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;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AOC,KAAK,CAACE,aAAa,EAAE;QACvChB,aAAa8B;IACf;IAEA,IAAID,YAAY,QAAS,CAAA,CAACC,SAAUA,SAAS,CAACjB,OAAOC,KAAK,CAACE,aAAa,GAAI;QAC1EhB,aAAa;IACf;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,eAAe+B,WACpBC,MAAc,EACdH,OAAe,EACfC,KAAY,EACZG,YAAqB;IAErB,IAAIC,kBAAkBF;IACtB,IAAI,CAACA,OAAOG,QAAQ,CAAC,MAAM;QACzBD,mBAAmB;IACrB;IAEAnC,SAASmC,kBAAkBL,SAASC;IACpC,IAAI;QACF,IAAIG,cAAc;YAChB,MAAM9B,WAAWiC,MAAM,CAACH;QAC1B;IACF,EAAE,OAAOI,aAAa;QACpBtC,SAAS,CAAC,EAAEmC,gBAAgB,8BAA8B,CAAC,EAAEG;IAC/D;IAEA,qCAAqC;IACrC,IAAI,CAACxB,OAAOC,KAAK,CAACC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,qEAAqE;QACrEuB,QAAQC,IAAI,CAAC;IACf;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,eAAeC,UAAkB;IAC/C,OAAOA,WAAWC,OAAO,CAAC,mBAAmB;AAC/C"}
1
+ {"version":3,"sources":["../../../src/utils/misc.ts"],"sourcesContent":["import { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { promises as filesystem } from 'fs';\nimport path from 'path';\nimport type { Arguments } from 'yargs';\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\n // eslint-disable-next-line n/no-process-exit\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"],"names":["logError","logErrorUtil","hasProperty","promises","filesystem","path","permRequestKeys","CONFIG_FILE","pathArguments","Set","setSnapGlobals","argv","includes","_","global","snaps","isWatching","verboseErrors","booleanStringToBoolean","suppressWarnings","value","Error","String","sanitizeInputs","Object","keys","forEach","key","has","normalize","message","error","writeError","prefix","destFilePath","processedPrefix","endsWith","unlink","unlinkError","process","exit","trimPathString","pathString","replace"],"mappings":"AAAA,SAASA,YAAYC,YAAY,QAAQ,wBAAwB;AACjE,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,YAAYC,UAAU,QAAQ,KAAK;AAC5C,OAAOC,UAAU,OAAO;AAGxB,OAAO,MAAMC,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,cAAc,iBAAiB;AAE5C,4CAA4C;AAC5C,MAAMC,gBAAgB,IAAIC,IAAI;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;CAMC,GACD,OAA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AAa,EAAE;QACvChB,aAAa8B;IACf;IAEA,IAAID,YAAY,QAAS,CAAA,CAACC,SAAUA,SAAS,CAACjB,OAAOC,KAAK,CAACE,aAAa,GAAI;QAC1EhB,aAAa;IACf;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,eAAe+B,WACpBC,MAAc,EACdH,OAAe,EACfC,KAAY,EACZG,YAAqB;IAErB,IAAIC,kBAAkBF;IACtB,IAAI,CAACA,OAAOG,QAAQ,CAAC,MAAM;QACzBD,mBAAmB;IACrB;IAEAnC,SAASmC,kBAAkBL,SAASC;IACpC,IAAI;QACF,IAAIG,cAAc;YAChB,MAAM9B,WAAWiC,MAAM,CAACH;QAC1B;IACF,EAAE,OAAOI,aAAa;QACpBtC,SAAS,CAAC,EAAEmC,gBAAgB,8BAA8B,CAAC,EAAEG;IAC/D;IAEA,qCAAqC;IACrC,IAAI,CAACxB,OAAOC,KAAK,CAACC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,qEAAqE;QACrE,6CAA6C;QAC7CuB,QAAQC,IAAI,CAAC;IACf;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,eAAeC,UAAkB;IAC/C,OAAOA,WAAWC,OAAO,CAAC,mBAAmB;AAC/C"}
@@ -34,7 +34,7 @@ let snapConfigCache;
34
34
  }
35
35
  let config;
36
36
  try {
37
- // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
37
+ // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
38
38
  config = require(path.resolve(process.cwd(), CONFIG_FILE));
39
39
  } catch (error) {
40
40
  if (error.code === 'MODULE_NOT_FOUND') {
@@ -42,10 +42,12 @@ let snapConfigCache;
42
42
  return snapConfigCache;
43
43
  }
44
44
  logError(`Error during parsing of ${CONFIG_FILE}`, error);
45
+ // eslint-disable-next-line n/no-process-exit
45
46
  return process.exit(1);
46
47
  }
47
48
  if (!isSnapConfig(config)) {
48
49
  logError(`Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
50
+ // eslint-disable-next-line n/no-process-exit
49
51
  return process.exit(1);
50
52
  }
51
53
  snapConfigCache = config;
@@ -96,6 +98,7 @@ let snapConfigCache;
96
98
  }
97
99
  } else {
98
100
  logError(`Error: Encountered unrecognized config property "options.${key}" in config file "${CONFIG_FILE}". Remove the property and try again.`);
101
+ // eslint-disable-next-line n/no-process-exit
99
102
  process.exit(1);
100
103
  }
101
104
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/snap-config.ts"],"sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport { object, optional, func, Infer, is } from 'superstruct';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n process.exit(1);\n }\n }\n}\n"],"names":["hasProperty","path","object","optional","func","is","yargsParse","builders","CONFIG_FILE","logError","SnapConfigStruct","cliOptions","bundlerCustomizer","isSnapConfig","value","snapConfigCache","loadConfig","cached","undefined","config","require","resolve","process","cwd","error","code","exit","applyConfig","snapConfig","processArgv","yargsArgv","yargsInstance","alias","aliases","key","options","getOptions","parsedProcessArgv","_","commandOptions","Set","Object","keys","shouldSetArg","has"],"mappings":"AAAA,SAASA,WAAW,QAAQ,kBAAkB;AAE9C,OAAOC,UAAU,OAAO;AACxB,SAASC,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAASC,EAAE,QAAQ,cAAc;AAEhE,OAAOC,gBAAgB,eAAe;AAGtC,OAAOC,cAAc,cAAc;AACnC,SAASC,WAAW,EAAEC,QAAQ,QAAQ,SAAS;AAI/C,OAAO,MAAMC,mBAAmBR,OAAO;IACrCS,YAAYR,SAASD;IACrBU,mBAAmBT,SAASC;AAC9B,GAAG;AASH;;;;;;;;CAQC,GACD,OAAO,SAASS,aAAaC,KAAc;IACzC,OAAOT,GAAGS,OAAOJ;AACnB;AAEA,IAAIK;AAEJ;;;;;;;;CAQC,GACD,OAAO,SAASC,WAAWC,SAAS,IAAI;IACtC,IAAIF,oBAAoBG,aAAaD,QAAQ;QAC3C,OAAOF;IACT;IAEA,IAAII;IACJ,IAAI;QACF,iHAAiH;QACjHA,SAASC,QAAQnB,KAAKoB,OAAO,CAACC,QAAQC,GAAG,IAAIf;IAC/C,EAAE,OAAOgB,OAAY;QACnB,IAAIA,MAAMC,IAAI,KAAK,oBAAoB;YACrCV,kBAAkB,CAAC;YACn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CAAqC,CAAC;YAExIc,QAAQI,IAAI,CAAC;QACf;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/utils/snap-config.ts"],"sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport type { Infer } from 'superstruct';\nimport { object, optional, func, is } from 'superstruct';\nimport type { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport type yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n // eslint-disable-next-line n/no-process-exit\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n // eslint-disable-next-line n/no-process-exit\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n }\n}\n"],"names":["hasProperty","path","object","optional","func","is","yargsParse","builders","CONFIG_FILE","logError","SnapConfigStruct","cliOptions","bundlerCustomizer","isSnapConfig","value","snapConfigCache","loadConfig","cached","undefined","config","require","resolve","process","cwd","error","code","exit","applyConfig","snapConfig","processArgv","yargsArgv","yargsInstance","alias","aliases","key","options","getOptions","parsedProcessArgv","_","commandOptions","Set","Object","keys","shouldSetArg","has"],"mappings":"AAAA,SAASA,WAAW,QAAQ,kBAAkB;AAE9C,OAAOC,UAAU,OAAO;AAExB,SAASC,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,EAAE,QAAQ,cAAc;AAEzD,OAAOC,gBAAgB,eAAe;AAGtC,OAAOC,cAAc,cAAc;AACnC,SAASC,WAAW,EAAEC,QAAQ,QAAQ,SAAS;AAI/C,OAAO,MAAMC,mBAAmBR,OAAO;IACrCS,YAAYR,SAASD;IACrBU,mBAAmBT,SAASC;AAC9B,GAAG;AASH;;;;;;;;CAQC,GACD,OAAO,SAASS,aAAaC,KAAc;IACzC,OAAOT,GAAGS,OAAOJ;AACnB;AAEA,IAAIK;AAEJ;;;;;;;;CAQC,GACD,OAAO,SAASC,WAAWC,SAAS,IAAI;IACtC,IAAIF,oBAAoBG,aAAaD,QAAQ;QAC3C,OAAOF;IACT;IAEA,IAAII;IACJ,IAAI;QACF,8GAA8G;QAC9GA,SAASC,QAAQnB,KAAKoB,OAAO,CAACC,QAAQC,GAAG,IAAIf;IAC/C,EAAE,OAAOgB,OAAY;QACnB,IAAIA,MAAMC,IAAI,KAAK,oBAAoB;YACrCV,kBAAkB,CAAC;YACnB,OAAOA;QACT;QACAN,SAAS,CAAC,wBAAwB,EAAED,YAAY,CAAC,EAAEgB;QACnD,6CAA6C;QAC7C,OAAOF,QAAQI,IAAI,CAAC;IACtB;IAEA,IAAI,CAACb,aAAaM,SAAS;QACzBV,S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Options, PositionalOptions } from 'yargs';
2
2
  export declare type SnapsCliBuilders = {
3
3
  readonly bundle: Readonly<Options>;
4
4
  readonly dist: Readonly<Options>;
@@ -1,4 +1,4 @@
1
- import { YargsArgs } from '../../types/yargs';
1
+ import type { YargsArgs } from '../../types/yargs';
2
2
  /**
3
3
  * Builds all files in the given source directory to the given destination
4
4
  * directory.
@@ -1,5 +1,5 @@
1
- import { BrowserifyObject } from 'browserify';
2
- import { YargsArgs } from '../../types/yargs';
1
+ import type { BrowserifyObject } from 'browserify';
2
+ import type { YargsArgs } from '../../types/yargs';
3
3
  /**
4
4
  * Builds a Snap bundle JS file from its JavaScript source.
5
5
  *
@@ -1,5 +1,5 @@
1
- import yargs from 'yargs';
2
- import { YargsArgs } from '../../types/yargs';
1
+ import type yargs from 'yargs';
2
+ import type { YargsArgs } from '../../types/yargs';
3
3
  declare const command: {
4
4
  command: string[];
5
5
  desc: string;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { YargsArgs } from '../../types/yargs';
2
+ import type { YargsArgs } from '../../types/yargs';
3
3
  declare type WriteBundleFileArgs = {
4
4
  bundleError: Error;
5
5
  bundleBuffer: Buffer;
@@ -1,4 +1,4 @@
1
- import { YargsArgs } from '../../types/yargs';
1
+ import type { YargsArgs } from '../../types/yargs';
2
2
  /**
3
3
  * Runs the snap in a worker, to ensure SES compatibility.
4
4
  *
@@ -1,5 +1,5 @@
1
- import yargs from 'yargs';
2
- import { YargsArgs } from '../../types/yargs';
1
+ import type yargs from 'yargs';
2
+ import type { YargsArgs } from '../../types/yargs';
3
3
  declare const command: {
4
4
  command: string[];
5
5
  desc: string;
@@ -1,5 +1,5 @@
1
- import yargs from 'yargs';
2
- import { YargsArgs } from '../../types/yargs';
1
+ import type yargs from 'yargs';
2
+ import type { YargsArgs } from '../../types/yargs';
3
3
  declare const command: {
4
4
  command: string[];
5
5
  desc: string;
@@ -1,4 +1,4 @@
1
- import { YargsArgs } from '../../types/yargs';
1
+ import type { YargsArgs } from '../../types/yargs';
2
2
  /**
3
3
  * Validates a snap.manifest.json file. Attempts to fix the manifest and write
4
4
  * the fixed version to disk if `writeManifest` is true. Throws if validation
@@ -1,5 +1,5 @@
1
- import yargs from 'yargs';
2
- import { YargsArgs } from '../../types/yargs';
1
+ import type yargs from 'yargs';
2
+ import type { YargsArgs } from '../../types/yargs';
3
3
  declare const command: {
4
4
  command: string[];
5
5
  desc: string;
@@ -1,4 +1,4 @@
1
- import { YargsArgs } from '../../types/yargs';
1
+ import type { YargsArgs } from '../../types/yargs';
2
2
  /**
3
3
  * Starts a local, static HTTP server on the given port with the given root
4
4
  * directory.
@@ -1,5 +1,5 @@
1
- import yargs from 'yargs';
2
- import { YargsArgs } from '../../types/yargs';
1
+ import type yargs from 'yargs';
2
+ import type { YargsArgs } from '../../types/yargs';
3
3
  declare const command: {
4
4
  command: string[];
5
5
  desc: string;
@@ -1,4 +1,4 @@
1
- import { YargsArgs } from '../../types/yargs';
1
+ import type { YargsArgs } from '../../types/yargs';
2
2
  /**
3
3
  * Watch a directory and its subdirectories for changes, and build when files
4
4
  * are added or changed.
@@ -1,4 +1,4 @@
1
- import { Arguments } from 'yargs';
1
+ import type { Arguments } from 'yargs';
2
2
  export declare const permRequestKeys: string[];
3
3
  export declare const CONFIG_FILE = "snap.config.js";
4
4
  /**
@@ -1,7 +1,7 @@
1
1
  import type browserify from 'browserify';
2
- import { Infer } from 'superstruct';
3
- import { Arguments } from 'yargs';
4
- import yargs from 'yargs/yargs';
2
+ import type { Infer } from 'superstruct';
3
+ import type { Arguments } from 'yargs';
4
+ import type yargs from 'yargs/yargs';
5
5
  export declare type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;
6
6
  export declare const SnapConfigStruct: import("superstruct").Struct<{
7
7
  cliOptions?: Record<string, unknown> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "0.36.1-flask.1",
3
+ "version": "0.37.0-flask.1",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -53,8 +53,8 @@
53
53
  "@babel/plugin-transform-runtime": "^7.16.7",
54
54
  "@babel/preset-env": "^7.20.12",
55
55
  "@babel/preset-typescript": "^7.20.12",
56
- "@metamask/snaps-browserify-plugin": "^0.36.1-flask.1",
57
- "@metamask/snaps-utils": "^0.36.1-flask.1",
56
+ "@metamask/snaps-browserify-plugin": "^0.37.0-flask.1",
57
+ "@metamask/snaps-utils": "^0.37.0-flask.1",
58
58
  "@metamask/utils": "^6.0.1",
59
59
  "babelify": "^10.0.0",
60
60
  "browserify": "^17.0.0",
@@ -69,10 +69,10 @@
69
69
  "devDependencies": {
70
70
  "@lavamoat/allow-scripts": "^2.3.1",
71
71
  "@metamask/auto-changelog": "^3.1.0",
72
- "@metamask/eslint-config": "^11.0.0",
73
- "@metamask/eslint-config-jest": "^11.0.0",
74
- "@metamask/eslint-config-nodejs": "^11.0.1",
75
- "@metamask/eslint-config-typescript": "^11.0.0",
72
+ "@metamask/eslint-config": "^12.1.0",
73
+ "@metamask/eslint-config-jest": "^12.1.0",
74
+ "@metamask/eslint-config-nodejs": "^12.1.0",
75
+ "@metamask/eslint-config-typescript": "^12.1.0",
76
76
  "@swc/cli": "^0.1.62",
77
77
  "@swc/core": "^1.3.66",
78
78
  "@swc/jest": "^0.2.26",
@@ -94,8 +94,9 @@
94
94
  "eslint-plugin-import": "^2.26.0",
95
95
  "eslint-plugin-jest": "^27.1.5",
96
96
  "eslint-plugin-jsdoc": "^39.6.2",
97
- "eslint-plugin-node": "^11.1.0",
97
+ "eslint-plugin-n": "^15.7.0",
98
98
  "eslint-plugin-prettier": "^4.2.1",
99
+ "eslint-plugin-promise": "^6.1.1",
99
100
  "execa": "^5.1.1",
100
101
  "jest": "^29.0.2",
101
102
  "jest-it-up": "^2.0.0",