@metamask/snaps-cli 7.1.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/.browserslistrc +2 -2
  2. package/CHANGELOG.md +22 -1
  3. package/dist/builders.cjs +4 -0
  4. package/dist/builders.cjs.map +1 -1
  5. package/dist/builders.d.cts +4 -0
  6. package/dist/builders.d.cts.map +1 -1
  7. package/dist/builders.d.mts +4 -0
  8. package/dist/builders.d.mts.map +1 -1
  9. package/dist/builders.mjs +4 -0
  10. package/dist/builders.mjs.map +1 -1
  11. package/dist/commands/build/build.cjs +8 -23
  12. package/dist/commands/build/build.cjs.map +1 -1
  13. package/dist/commands/build/build.d.cts +1 -0
  14. package/dist/commands/build/build.d.cts.map +1 -1
  15. package/dist/commands/build/build.d.mts +1 -0
  16. package/dist/commands/build/build.d.mts.map +1 -1
  17. package/dist/commands/build/build.mjs +9 -24
  18. package/dist/commands/build/build.mjs.map +1 -1
  19. package/dist/commands/build/implementation.cjs.map +1 -1
  20. package/dist/commands/build/implementation.d.cts.map +1 -1
  21. package/dist/commands/build/implementation.d.mts.map +1 -1
  22. package/dist/commands/build/implementation.mjs.map +1 -1
  23. package/dist/commands/build/index.cjs +1 -2
  24. package/dist/commands/build/index.cjs.map +1 -1
  25. package/dist/commands/build/index.d.cts.map +1 -1
  26. package/dist/commands/build/index.d.mts.map +1 -1
  27. package/dist/commands/build/index.mjs +1 -2
  28. package/dist/commands/build/index.mjs.map +1 -1
  29. package/dist/commands/manifest/implementation.cjs +8 -4
  30. package/dist/commands/manifest/implementation.cjs.map +1 -1
  31. package/dist/commands/manifest/implementation.d.cts +2 -1
  32. package/dist/commands/manifest/implementation.d.cts.map +1 -1
  33. package/dist/commands/manifest/implementation.d.mts +2 -1
  34. package/dist/commands/manifest/implementation.d.mts.map +1 -1
  35. package/dist/commands/manifest/implementation.mjs +8 -4
  36. package/dist/commands/manifest/implementation.mjs.map +1 -1
  37. package/dist/commands/manifest/index.cjs +5 -1
  38. package/dist/commands/manifest/index.cjs.map +1 -1
  39. package/dist/commands/manifest/index.d.cts.map +1 -1
  40. package/dist/commands/manifest/index.d.mts.map +1 -1
  41. package/dist/commands/manifest/index.mjs +5 -1
  42. package/dist/commands/manifest/index.mjs.map +1 -1
  43. package/dist/commands/manifest/manifest.cjs +20 -4
  44. package/dist/commands/manifest/manifest.cjs.map +1 -1
  45. package/dist/commands/manifest/manifest.d.cts +1 -0
  46. package/dist/commands/manifest/manifest.d.cts.map +1 -1
  47. package/dist/commands/manifest/manifest.d.mts +1 -0
  48. package/dist/commands/manifest/manifest.d.mts.map +1 -1
  49. package/dist/commands/manifest/manifest.mjs +21 -5
  50. package/dist/commands/manifest/manifest.mjs.map +1 -1
  51. package/dist/commands/watch/watch.cjs +1 -1
  52. package/dist/commands/watch/watch.cjs.map +1 -1
  53. package/dist/commands/watch/watch.mjs +1 -1
  54. package/dist/commands/watch/watch.mjs.map +1 -1
  55. package/dist/webpack/config.cjs +1 -1
  56. package/dist/webpack/config.cjs.map +1 -1
  57. package/dist/webpack/config.d.cts.map +1 -1
  58. package/dist/webpack/config.d.mts.map +1 -1
  59. package/dist/webpack/config.mjs +1 -1
  60. package/dist/webpack/config.mjs.map +1 -1
  61. package/dist/webpack/loaders/wasm.cjs +1 -2
  62. package/dist/webpack/loaders/wasm.cjs.map +1 -1
  63. package/dist/webpack/loaders/wasm.mjs +1 -2
  64. package/dist/webpack/loaders/wasm.mjs.map +1 -1
  65. package/dist/webpack/plugins.cjs +149 -119
  66. package/dist/webpack/plugins.cjs.map +1 -1
  67. package/dist/webpack/plugins.d.cts.map +1 -1
  68. package/dist/webpack/plugins.d.mts.map +1 -1
  69. package/dist/webpack/plugins.mjs +148 -118
  70. package/dist/webpack/plugins.mjs.map +1 -1
  71. package/package.json +11 -10
@@ -1 +1 @@
1
- {"version":3,"file":"implementation.mjs","sourceRoot":"","sources":["../../../src/commands/manifest/implementation.ts"],"names":[],"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C,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,OAAO,GAAG,yCAAyC,eAAe,EAAE,CAAC;QACzE,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO;gBACL,2EAA2E,CAAC;QAChF,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;QACrB,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CACF,+CAA+C,cAAc,EAAE,EAC/D,OAAO,CACR,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9C,IAAI,CACF,2CAA2C,iBAAiB,EAAE,EAC9D,OAAO,CACR,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,IAAI,EAAE,CAAC;QAChB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { checkManifest, indent } from '@metamask/snaps-utils/node';\nimport { writeManifest } from '@metamask/snaps-webpack-plugin';\nimport { assert } from '@metamask/utils';\nimport { red, yellow, green } from 'chalk';\nimport type { Ora } from 'ora';\nimport { dirname } from 'path';\n\nimport { error, info, warn } from '../../utils';\n\n/**\n * Check the snap manifest file at the given path. If `write` is `true`, the\n * manifest will be written to disk if it is invalid. If `write` is `false`,\n * the manifest will not be written to disk, and the function will log any\n * errors and warnings to the console.\n *\n * @param path - The path to the manifest file.\n * @param write - Whether to write the manifest to disk if it is invalid.\n * @param spinner - An optional spinner to use for logging.\n * @returns Whether the manifest is valid.\n */\nexport async function manifest(\n path: string,\n write: boolean,\n spinner?: Ora,\n): Promise<boolean> {\n const { reports, updated } = await checkManifest(dirname(path), {\n updateAndWriteManifest: write,\n writeFileFn: writeManifest,\n });\n\n const errors = [];\n const fixed = [];\n const warnings = [];\n\n for (const report of reports) {\n if (report.severity === 'error' && !report.wasFixed) {\n errors.push(indent(red(`• ${report.message}`)));\n } else if (report.wasFixed) {\n fixed.push(indent(yellow(`• ${report.message}`) + green(' (fixed)')));\n } else {\n assert(report.severity === 'warning');\n warnings.push(indent(yellow(`• ${report.message}`)));\n }\n }\n\n if (errors.length > 0) {\n const formattedErrors = errors.join('\\n');\n let message = `The snap manifest file is invalid.\\n\\n${formattedErrors}`;\n if (!write) {\n message +=\n '\\n\\nRun the command with the `--fix` flag to attempt to fix the manifest.';\n }\n\n error(message, spinner);\n }\n\n if (write && updated) {\n const formattedFixed = fixed.join('\\n');\n info(\n `The snap manifest file has been updated.\\n\\n${formattedFixed}`,\n spinner,\n );\n }\n\n if (warnings.length > 0) {\n const formattedWarnings = warnings.join('\\n');\n\n warn(\n `The snap manifest file has warnings.\\n\\n${formattedWarnings}`,\n spinner,\n );\n }\n\n if (errors.length > 0) {\n spinner?.stop();\n process.exitCode = 1;\n return false;\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"implementation.mjs","sourceRoot":"","sources":["../../../src/commands/manifest/implementation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,oCAAoC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,mCAAmC;AACnE,OAAO,EAAE,aAAa,EAAE,uCAAuC;AAC/D,OAAO,EAAE,MAAM,EAAE,wBAAwB;;;AAGzC,OAAO,EAAE,OAAO,EAAE,aAAa;AAE/B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,E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AyC,eAAe,EAAE,CAAC;QACzE,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO;gBACL,2EAA2E,CAAC;QAChF,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;QACrB,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CACF,+CAA+C,cAAc,EAAE,EAC/D,OAAO,CACR,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9C,IAAI,CACF,2CAA2C,iBAAiB,EAAE,EAC9D,OAAO,CACR,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,IAAI,EAAE,CAAC;QAChB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { handlerEndowments } from '@metamask/snaps-rpc-methods';\nimport { checkManifest, indent } from '@metamask/snaps-utils/node';\nimport { writeManifest } from '@metamask/snaps-webpack-plugin';\nimport { assert } from '@metamask/utils';\nimport { red, yellow, green } from 'chalk';\nimport type { Ora } from 'ora';\nimport { dirname } from 'path';\n\nimport { error, info, warn } from '../../utils';\n\n/**\n * Check the snap manifest file at the given path. If `write` is `true`, the\n * manifest will be written to disk if it is invalid. If `write` is `false`,\n * the manifest will not be written to disk, and the function will log any\n * errors and warnings to the console.\n *\n * @param path - The path to the manifest file.\n * @param write - Whether to write the manifest to disk if it is invalid.\n * @param exports - The exports to check in the manifest.\n * @param spinner - An optional spinner to use for logging.\n * @returns Whether the manifest is valid.\n */\nexport async function manifest(\n path: string,\n write: boolean,\n exports?: string[],\n spinner?: Ora,\n): Promise<boolean> {\n const { reports, updated } = await checkManifest(dirname(path), {\n exports,\n handlerEndowments,\n updateAndWriteManifest: write,\n writeFileFn: writeManifest,\n });\n\n const errors = [];\n const fixed = [];\n const warnings = [];\n\n for (const report of reports) {\n if (report.severity === 'error' && !report.wasFixed) {\n errors.push(indent(red(`• ${report.message}`)));\n } else if (report.wasFixed) {\n fixed.push(indent(yellow(`• ${report.message}`) + green(' (fixed)')));\n } else {\n assert(report.severity === 'warning');\n warnings.push(indent(yellow(`• ${report.message}`)));\n }\n }\n\n if (errors.length > 0) {\n const formattedErrors = errors.join('\\n');\n let message = `The Snap manifest file is invalid.\\n\\n${formattedErrors}`;\n if (!write) {\n message +=\n '\\n\\nRun the command with the `--fix` flag to attempt to fix the manifest.';\n }\n\n error(message, spinner);\n }\n\n if (write && updated) {\n const formattedFixed = fixed.join('\\n');\n info(\n `The Snap manifest file has been updated.\\n\\n${formattedFixed}`,\n spinner,\n );\n }\n\n if (warnings.length > 0) {\n const formattedWarnings = warnings.join('\\n');\n\n warn(\n `The Snap manifest file has warnings.\\n\\n${formattedWarnings}`,\n spinner,\n );\n }\n\n if (errors.length > 0) {\n spinner?.stop();\n process.exitCode = 1;\n return false;\n }\n\n return true;\n}\n"]}
@@ -24,8 +24,12 @@ const command = {
24
24
  desc: 'Validate the snap.manifest.json file',
25
25
  builder: (yarg) => {
26
26
  yarg.option('fix', builders_1.default.fix);
27
+ yarg.option('eval', builders_1.default.eval);
27
28
  },
28
- handler: async (argv) => (0, manifest_1.manifestHandler)(argv.context.config, { fix: argv.fix }),
29
+ handler: async (argv) => (0, manifest_1.manifestHandler)(argv.context.config, {
30
+ fix: argv.fix,
31
+ eval: argv.eval ?? argv.context.config.evaluate,
32
+ }),
29
33
  };
30
34
  __exportStar(require("./implementation.cjs"), exports);
31
35
  exports.default = command;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/commands/manifest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAEA,6CAA6C;AAC7C,kEAAsC;AAGtC,MAAM,OAAO,GAAG;IACd,OAAO,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC;IAC1B,IAAI,EAAE,sCAAsC;IAC5C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CACjC,IAAA,0BAAe,EAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;CAC1D,CAAC;AAEF,uDAAiC;AACjC,kBAAe,OAAO,CAAC","sourcesContent":["import type yargs from 'yargs';\n\nimport { manifestHandler } from './manifest';\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('fix', builders.fix);\n },\n handler: async (argv: YargsArgs) =>\n manifestHandler(argv.context.config, { fix: argv.fix }),\n};\n\nexport * from './implementation';\nexport default command;\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/commands/manifest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAEA,6CAA6C;AAC7C,kEAAsC;AAGtC,MAAM,OAAO,GAAG;IACd,OAAO,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC;IAC1B,IAAI,EAAE,sCAAsC;IAC5C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CACjC,IAAA,0BAAe,EAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnC,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ;KAChD,CAAC;CACL,CAAC;AAEF,uDAAiC;AACjC,kBAAe,OAAO,CAAC","sourcesContent":["import type yargs from 'yargs';\n\nimport { manifestHandler } from './manifest';\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('fix', builders.fix);\n yarg.option('eval', builders.eval);\n },\n handler: async (argv: YargsArgs) =>\n manifestHandler(argv.context.config, {\n fix: argv.fix,\n eval: argv.eval ?? argv.context.config.evaluate,\n }),\n};\n\nexport * from './implementation';\nexport default command;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/commands/manifest/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc;AAI/B,OAAO,KAAK,EAAE,SAAS,EAAE,gCAA0B;AAEnD,QAAA,MAAM,OAAO;;;oBAGK,MAAM,IAAI;oBAGJ,SAAS;CAEhC,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/commands/manifest/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc;AAI/B,OAAO,KAAK,EAAE,SAAS,EAAE,gCAA0B;AAEnD,QAAA,MAAM,OAAO;;;oBAGK,MAAM,IAAI;oBAIJ,SAAS;CAKhC,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/commands/manifest/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc;AAI/B,OAAO,KAAK,EAAE,SAAS,EAAE,gCAA0B;AAEnD,QAAA,MAAM,OAAO;;;oBAGK,MAAM,IAAI;oBAGJ,SAAS;CAEhC,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/commands/manifest/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,cAAc;AAI/B,OAAO,KAAK,EAAE,SAAS,EAAE,gCAA0B;AAEnD,QAAA,MAAM,OAAO;;;oBAGK,MAAM,IAAI;oBAIJ,SAAS;CAKhC,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC"}
@@ -5,8 +5,12 @@ const command = {
5
5
  desc: 'Validate the snap.manifest.json file',
6
6
  builder: (yarg) => {
7
7
  yarg.option('fix', builders.fix);
8
+ yarg.option('eval', builders.eval);
8
9
  },
9
- handler: async (argv) => manifestHandler(argv.context.config, { fix: argv.fix }),
10
+ handler: async (argv) => manifestHandler(argv.context.config, {
11
+ fix: argv.fix,
12
+ eval: argv.eval ?? argv.context.config.evaluate,
13
+ }),
10
14
  };
11
15
  export * from "./implementation.mjs";
12
16
  export default command;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/commands/manifest/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,QAAQ,2BAAuB;AAGtC,MAAM,OAAO,GAAG;IACd,OAAO,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC;IAC1B,IAAI,EAAE,sCAAsC;IAC5C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CACjC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;CAC1D,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC","sourcesContent":["import type yargs from 'yargs';\n\nimport { manifestHandler } from './manifest';\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('fix', builders.fix);\n },\n handler: async (argv: YargsArgs) =>\n manifestHandler(argv.context.config, { fix: argv.fix }),\n};\n\nexport * from './implementation';\nexport default command;\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/commands/manifest/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,QAAQ,2BAAuB;AAGtC,MAAM,OAAO,GAAG;IACd,OAAO,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC;IAC1B,IAAI,EAAE,sCAAsC;IAC5C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CACjC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnC,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ;KAChD,CAAC;CACL,CAAC;AAEF,qCAAiC;AACjC,eAAe,OAAO,CAAC","sourcesContent":["import type yargs from 'yargs';\n\nimport { manifestHandler } from './manifest';\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('fix', builders.fix);\n yarg.option('eval', builders.eval);\n },\n handler: async (argv: YargsArgs) =>\n manifestHandler(argv.context.config, {\n fix: argv.fix,\n eval: argv.eval ?? argv.context.config.evaluate,\n }),\n};\n\nexport * from './implementation';\nexport default command;\n"]}
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.manifestHandler = void 0;
4
4
  const node_1 = require("@metamask/snaps-utils/node");
5
+ const path_1 = require("path");
5
6
  const implementation_1 = require("./implementation.cjs");
6
7
  const errors_1 = require("../../errors.cjs");
7
8
  const utils_1 = require("../../utils/index.cjs");
9
+ const eval_1 = require("../eval/index.cjs");
8
10
  const steps = [
9
11
  {
10
12
  name: 'Checking the input file.',
@@ -15,12 +17,26 @@ const steps = [
15
17
  },
16
18
  },
17
19
  {
18
- name: 'Validating the snap manifest.',
19
- task: async ({ input, options, spinner }) => {
20
+ name: 'Evaluating the Snap bundle.',
21
+ condition: ({ options }) => options.eval,
22
+ task: async (context) => {
23
+ const { config, spinner } = context;
24
+ const path = (0, path_1.resolve)(process.cwd(), config.output.path, config.output.filename);
25
+ const { exports } = await (0, eval_1.evaluate)(path);
26
+ (0, utils_1.info)(`Snap bundle evaluated successfully.`, spinner);
27
+ return {
28
+ ...context,
29
+ exports,
30
+ };
31
+ },
32
+ },
33
+ {
34
+ name: 'Validating the Snap manifest.',
35
+ task: async ({ input, options, exports, spinner }) => {
20
36
  const write = getWriteManifest(options);
21
- const valid = await (0, implementation_1.manifest)(input, write, spinner);
37
+ const valid = await (0, implementation_1.manifest)(input, write, exports, spinner);
22
38
  if (valid) {
23
- spinner.succeed('The snap manifest file is valid.');
39
+ spinner.succeed('The Snap manifest file is valid.');
24
40
  }
25
41
  },
26
42
  },
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.cjs","sourceRoot":"","sources":["../../../src/commands/manifest/manifest.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAEpD,yDAA4C;AAE5C,6CAA4C;AAE5C,iDAA2C;AAY3C,MAAM,KAAK,GAA2B;IACpC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;YACxB,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,qBAAY,CACpB,6BAA6B,KAAK,2DAA2D,CAC9F,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,+BAA+B;QACrC,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC1C,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,KAAK,GAAG,MAAM,IAAA,yBAAQ,EAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAEpD,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;KACF;CACF,CAAC;AAEF;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAwB;IAChD,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,MAAuB,EACvB,OAAwB;IAExB,MAAM,IAAA,oBAAY,EAAC,KAAK,EAAE;QACxB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;QAC3B,MAAM;QACN,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AATD,0CASC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport { manifest } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps } from '../../utils';\n\ntype ManifestOptions = {\n fix?: boolean;\n};\n\ntype ManifestContext = {\n input: string;\n config: ProcessedConfig;\n options: ManifestOptions;\n};\n\nconst steps: Steps<ManifestContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ input }) => {\n if (!(await isFile(input))) {\n throw new CommandError(\n `Manifest file not found: \"${input}\". Make sure that the \\`snap.manifest.json\\` file exists.`,\n );\n }\n },\n },\n {\n name: 'Validating the snap manifest.',\n task: async ({ input, options, spinner }) => {\n const write = getWriteManifest(options);\n const valid = await manifest(input, write, spinner);\n\n if (valid) {\n spinner.succeed('The snap manifest file is valid.');\n }\n },\n },\n];\n\n/**\n * Get whether to write the manifest to disk.\n *\n * @param options - The options object.\n * @returns Whether to write the manifest to disk.\n */\nfunction getWriteManifest(options: ManifestOptions) {\n if (typeof options.fix === 'boolean') {\n return options.fix;\n }\n\n return false;\n}\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function manifestHandler(\n config: ProcessedConfig,\n options: ManifestOptions,\n) {\n await executeSteps(steps, {\n input: config.manifest.path,\n config,\n options,\n });\n}\n"]}
1
+ {"version":3,"file":"manifest.cjs","sourceRoot":"","sources":["../../../src/commands/manifest/manifest.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AACpD,+BAA+B;AAE/B,yDAA4C;AAE5C,6CAA4C;AAE5C,iDAAiD;AACjD,4CAAmC;AAcnC,MAAM,KAAK,GAA2B;IACpC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;YACxB,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC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OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,MAAuB,EACvB,OAAwB;IAExB,MAAM,IAAA,oBAAY,EAAC,KAAK,EAAE;QACxB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;QAC3B,MAAM;QACN,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AATD,0CASC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\nimport { resolve } from 'path';\n\nimport { manifest } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { info, executeSteps } from '../../utils';\nimport { evaluate } from '../eval';\n\ntype ManifestOptions = {\n fix?: boolean;\n eval: boolean;\n};\n\ntype ManifestContext = {\n input: string;\n config: ProcessedConfig;\n options: ManifestOptions;\n exports?: string[];\n};\n\nconst steps: Steps<ManifestContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ input }) => {\n if (!(await isFile(input))) {\n throw new CommandError(\n `Manifest file not found: \"${input}\". Make sure that the \\`snap.manifest.json\\` file exists.`,\n );\n }\n },\n },\n {\n name: 'Evaluating the Snap bundle.',\n condition: ({ options }) => options.eval,\n task: async (context) => {\n const { config, spinner } = context;\n const path = resolve(\n process.cwd(),\n config.output.path,\n config.output.filename,\n );\n\n const { exports } = await evaluate(path);\n\n info(`Snap bundle evaluated successfully.`, spinner);\n\n return {\n ...context,\n exports,\n };\n },\n },\n {\n name: 'Validating the Snap manifest.',\n task: async ({ input, options, exports, spinner }) => {\n const write = getWriteManifest(options);\n const valid = await manifest(input, write, exports, spinner);\n\n if (valid) {\n spinner.succeed('The Snap manifest file is valid.');\n }\n },\n },\n];\n\n/**\n * Get whether to write the manifest to disk.\n *\n * @param options - The options object.\n * @returns Whether to write the manifest to disk.\n */\nfunction getWriteManifest(options: ManifestOptions) {\n if (typeof options.fix === 'boolean') {\n return options.fix;\n }\n\n return false;\n}\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function manifestHandler(\n config: ProcessedConfig,\n options: ManifestOptions,\n) {\n await executeSteps(steps, {\n input: config.manifest.path,\n config,\n options,\n });\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { ProcessedConfig } from "../../config.cjs";
2
2
  type ManifestOptions = {
3
3
  fix?: boolean;
4
+ eval: boolean;
4
5
  };
5
6
  /**
6
7
  * Validates a snap.manifest.json file. Attempts to fix the manifest and write
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.cts","sourceRoot":"","sources":["../../../src/commands/manifest/manifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AAKpD,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AA8CF;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,iBAOzB"}
1
+ {"version":3,"file":"manifest.d.cts","sourceRoot":"","sources":["../../../src/commands/manifest/manifest.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AAMpD,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAoEF;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,iBAOzB"}
@@ -1,6 +1,7 @@
1
1
  import type { ProcessedConfig } from "../../config.mjs";
2
2
  type ManifestOptions = {
3
3
  fix?: boolean;
4
+ eval: boolean;
4
5
  };
5
6
  /**
6
7
  * Validates a snap.manifest.json file. Attempts to fix the manifest and write
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.mts","sourceRoot":"","sources":["../../../src/commands/manifest/manifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AAKpD,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AA8CF;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,iBAOzB"}
1
+ {"version":3,"file":"manifest.d.mts","sourceRoot":"","sources":["../../../src/commands/manifest/manifest.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AAMpD,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAoEF;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,iBAOzB"}
@@ -1,7 +1,9 @@
1
1
  import { isFile } from "@metamask/snaps-utils/node";
2
+ import { resolve } from "path";
2
3
  import { manifest } from "./implementation.mjs";
3
4
  import { CommandError } from "../../errors.mjs";
4
- import { executeSteps } from "../../utils/index.mjs";
5
+ import { info, executeSteps } from "../../utils/index.mjs";
6
+ import { evaluate } from "../eval/index.mjs";
5
7
  const steps = [
6
8
  {
7
9
  name: 'Checking the input file.',
@@ -12,12 +14,26 @@ const steps = [
12
14
  },
13
15
  },
14
16
  {
15
- name: 'Validating the snap manifest.',
16
- task: async ({ input, options, spinner }) => {
17
+ name: 'Evaluating the Snap bundle.',
18
+ condition: ({ options }) => options.eval,
19
+ task: async (context) => {
20
+ const { config, spinner } = context;
21
+ const path = resolve(process.cwd(), config.output.path, config.output.filename);
22
+ const { exports } = await evaluate(path);
23
+ info(`Snap bundle evaluated successfully.`, spinner);
24
+ return {
25
+ ...context,
26
+ exports,
27
+ };
28
+ },
29
+ },
30
+ {
31
+ name: 'Validating the Snap manifest.',
32
+ task: async ({ input, options, exports, spinner }) => {
17
33
  const write = getWriteManifest(options);
18
- const valid = await manifest(input, write, spinner);
34
+ const valid = await manifest(input, write, exports, spinner);
19
35
  if (valid) {
20
- spinner.succeed('The snap manifest file is valid.');
36
+ spinner.succeed('The Snap manifest file is valid.');
21
37
  }
22
38
  },
23
39
  },
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.mjs","sourceRoot":"","sources":["../../../src/commands/manifest/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mCAAmC;AAEpD,OAAO,EAAE,QAAQ,EAAE,6BAAyB;AAE5C,OAAO,EAAE,YAAY,EAAE,yBAAqB;AAE5C,OAAO,EAAE,YAAY,EAAE,8BAAoB;AAY3C,MAAM,KAAK,GAA2B;IACpC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;YACxB,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,YAAY,CACpB,6BAA6B,KAAK,2DAA2D,CAC9F,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,+BAA+B;QACrC,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC1C,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAEpD,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;KACF;CACF,CAAC;AAEF;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAwB;IAChD,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAuB,EACvB,OAAwB;IAExB,MAAM,YAAY,CAAC,KAAK,EAAE;QACxB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;QAC3B,MAAM;QACN,OAAO;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport { manifest } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps } from '../../utils';\n\ntype ManifestOptions = {\n fix?: boolean;\n};\n\ntype ManifestContext = {\n input: string;\n config: ProcessedConfig;\n options: ManifestOptions;\n};\n\nconst steps: Steps<ManifestContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ input }) => {\n if (!(await isFile(input))) {\n throw new CommandError(\n `Manifest file not found: \"${input}\". Make sure that the \\`snap.manifest.json\\` file exists.`,\n );\n }\n },\n },\n {\n name: 'Validating the snap manifest.',\n task: async ({ input, options, spinner }) => {\n const write = getWriteManifest(options);\n const valid = await manifest(input, write, spinner);\n\n if (valid) {\n spinner.succeed('The snap manifest file is valid.');\n }\n },\n },\n];\n\n/**\n * Get whether to write the manifest to disk.\n *\n * @param options - The options object.\n * @returns Whether to write the manifest to disk.\n */\nfunction getWriteManifest(options: ManifestOptions) {\n if (typeof options.fix === 'boolean') {\n return options.fix;\n }\n\n return false;\n}\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function manifestHandler(\n config: ProcessedConfig,\n options: ManifestOptions,\n) {\n await executeSteps(steps, {\n input: config.manifest.path,\n config,\n options,\n });\n}\n"]}
1
+ {"version":3,"file":"manifest.mj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E,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YACnD,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAE7D,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;KACF;CACF,CAAC;AAEF;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAwB;IAChD,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAuB,EACvB,OAAwB;IAExB,MAAM,YAAY,CAAC,KAAK,EAAE;QACxB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;QAC3B,MAAM;QACN,OAAO;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\nimport { resolve } from 'path';\n\nimport { manifest } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { info, executeSteps } from '../../utils';\nimport { evaluate } from '../eval';\n\ntype ManifestOptions = {\n fix?: boolean;\n eval: boolean;\n};\n\ntype ManifestContext = {\n input: string;\n config: ProcessedConfig;\n options: ManifestOptions;\n exports?: string[];\n};\n\nconst steps: Steps<ManifestContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ input }) => {\n if (!(await isFile(input))) {\n throw new CommandError(\n `Manifest file not found: \"${input}\". Make sure that the \\`snap.manifest.json\\` file exists.`,\n );\n }\n },\n },\n {\n name: 'Evaluating the Snap bundle.',\n condition: ({ options }) => options.eval,\n task: async (context) => {\n const { config, spinner } = context;\n const path = resolve(\n process.cwd(),\n config.output.path,\n config.output.filename,\n );\n\n const { exports } = await evaluate(path);\n\n info(`Snap bundle evaluated successfully.`, spinner);\n\n return {\n ...context,\n exports,\n };\n },\n },\n {\n name: 'Validating the Snap manifest.',\n task: async ({ input, options, exports, spinner }) => {\n const write = getWriteManifest(options);\n const valid = await manifest(input, write, exports, spinner);\n\n if (valid) {\n spinner.succeed('The Snap manifest file is valid.');\n }\n },\n },\n];\n\n/**\n * Get whether to write the manifest to disk.\n *\n * @param options - The options object.\n * @returns Whether to write the manifest to disk.\n */\nfunction getWriteManifest(options: ManifestOptions) {\n if (typeof options.fix === 'boolean') {\n return options.fix;\n }\n\n return false;\n}\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function manifestHandler(\n config: ProcessedConfig,\n options: ManifestOptions,\n) {\n await executeSteps(steps, {\n input: config.manifest.path,\n config,\n options,\n });\n}\n"]}
@@ -26,7 +26,7 @@ const steps = [
26
26
  },
27
27
  },
28
28
  {
29
- name: 'Building the snap bundle.',
29
+ name: 'Building the Snap bundle.',
30
30
  task: async ({ config, spinner }) => {
31
31
  await (0, implementation_1.watch)(config, { spinner });
32
32
  },
@@ -1 +1 @@
1
- {"version":3,"file":"watch.cjs","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAEpD,yDAAyC;AAEzC,6CAA4C;AAE5C,iDAAiD;AACjD,qDAA0C;AAc1C,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAEzB,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,qBAAY,CACpB,0BAA0B,KAAK,qEAAqE,CACrG,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QAChD,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,IAAA,mBAAS,EAAC,MAAM,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzE,IAAA,YAAI,EAAC,+CAA+C,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;YAClC,MAAM,IAAA,sBAAK,EAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;KACF;CACF,CAAC;AAEF;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,OAAqB;IAErB,MAAM,IAAA,oBAAY,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC;AALD,oCAKC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport { watch } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\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 config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"]}
1
+ {"version":3,"file":"watch.cjs","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAEpD,yDAAyC;AAEzC,6CAA4C;AAE5C,iDAAiD;AACjD,qDAA0C;AAc1C,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAEzB,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,qBAAY,CACpB,0BAA0B,KAAK,qEAAqE,CACrG,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QAChD,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,IAAA,mBAAS,EAAC,MAAM,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzE,IAAA,YAAI,EAAC,+CAA+C,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;YAClC,MAAM,IAAA,sBAAK,EAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;KACF;CACF,CAAC;AAEF;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,OAAqB;IAErB,MAAM,IAAA,oBAAY,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC;AALD,oCAKC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport { watch } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the Snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\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 config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"]}
@@ -23,7 +23,7 @@ const steps = [
23
23
  },
24
24
  },
25
25
  {
26
- name: 'Building the snap bundle.',
26
+ name: 'Building the Snap bundle.',
27
27
  task: async ({ config, spinner }) => {
28
28
  await watch(config, { spinner });
29
29
  },
@@ -1 +1 @@
1
- {"version":3,"file":"watch.mjs","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mCAAmC;AAEpD,OAAO,EAAE,KAAK,EAAE,6BAAyB;AAEzC,OAAO,EAAE,YAAY,EAAE,yBAAqB;AAE5C,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,8BAAoB;AACjD,OAAO,EAAE,SAAS,EAAE,gCAAsB;AAc1C,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAEzB,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,YAAY,CACpB,0BAA0B,KAAK,qEAAqE,CACrG,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QAChD,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzE,IAAI,CAAC,+CAA+C,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;YAClC,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;KACF;CACF,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,OAAqB;IAErB,MAAM,YAAY,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport { watch } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\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 config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"]}
1
+ {"version":3,"file":"watch.mjs","sourceRoot":"","sources":["../../../src/commands/watch/watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mCAAmC;AAEpD,OAAO,EAAE,KAAK,EAAE,6BAAyB;AAEzC,OAAO,EAAE,YAAY,EAAE,yBAAqB;AAE5C,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,8BAAoB;AACjD,OAAO,EAAE,SAAS,EAAE,gCAAsB;AAc1C,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;YAEzB,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,YAAY,CACpB,0BAA0B,KAAK,qEAAqE,CACrG,CAAC;YACJ,CAAC;QACH,CAAC;KACF;IACD;QACE,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QAChD,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzE,IAAI,CAAC,+CAA+C,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;KACF;IACD;QACE,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;YAClC,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;KACF;CACF,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,OAAqB;IAErB,MAAM,YAAY,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { isFile } from '@metamask/snaps-utils/node';\n\nimport { watch } from './implementation';\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the Snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\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 config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"]}
@@ -247,7 +247,7 @@ async function getDefaultConfiguration(config, options = {
247
247
  manifestPath: config.manifest.path,
248
248
  writeManifest: config.manifest.update,
249
249
  eval: !options.watch && options.evaluate,
250
- }),
250
+ }, options.spinner),
251
251
  /**
252
252
  * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats
253
253
  * output. It's used to show the stats in the terminal, in a format that
@@ -1 +1 @@
1
- {"version":3,"file":"config.cjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,0FAAgE;AAChE,oGAAwE;AAExE,+BAA+B;AAC/B,kFAAiD;AAEjD,qCAAsE;AACtE,qEAA+D;AAE/D,iDAAoD;AACpD,2CAKmB;AACnB,uCAQiB;AA0BjB;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,uBAAuB,CAC3C,MAAuB,EACvB,UAA0B;IACxB,QAAQ,EAAE,MAAM,CAAC,QAAQ;CAC1B;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;IAC1C,MAAM,eAAe,GACnB,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,8BAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE3E,OAAO;QACL;;;;;;;WAOG;QACH,MAAM,EAAE,gBAAgB,yBAAiB,EAAE;QAE3C;;;;;WAKG;QACH,IAAI,EAAE,YAAY;QAElB;;;;WAIG;QACH,KAAK,EAAE,MAAM,CAAC,KAAK;QAEnB;;;;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iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC;AA7WD,0DA6WC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\nimport type { ProcessedConfig } from '../config';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(config.environment)),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin({\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n }),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\n }),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"]}
1
+ {"version":3,"file":"config.cjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,0FAAgE;AAChE,oGAAwE;AAExE,+BAA+B;AAC/B,kFAAiD;AAEjD,qCAAsE;AACtE,qEAA+D;AAE/D,iDAAoD;AACpD,2CAKmB;AACnB,uCAQiB;AA0BjB;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,uBAAuB,CAC3C,MAAuB,EACvB,UAA0B;IACxB,QAAQ,EAAE,MAAM,CAAC,QAAQ;CAC1B;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;IAC1C,MAAM,eAAe,GACnB,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,8BAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE3E,OAAO;QACL;;;;;;;WAOG;QACH,MAAM,EAAE,gBAAgB,yBAAiB,EAAE;QAE3C;;;;;WAKG;QACH,IAAI,EAAE,YAAY;QAElB;;;;WAIG;QACH,KAAK,EAAE,MAAM,CAAC,KAAK;QAEnB;;;;;WAKG;QACH,OAAO,EAAE,IAAA,kBAAU,EAAC,MAAM,CAAC,SAAS,CAAC;QAErC;;;;;;WAMG;QACH,KAAK,EAAE,MAAM;QAEb;;;;WAIG;QACH,MAAM,EAAE;YACN;;;;;;eAMG;YACH,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;YAE1B;;;;;eAKG;YACH,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;;;eAKG;YACH,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI;YAExB;;;;;eAKG;YACH,UAAU,EAAE,GAAG;YAEf;;;;;eAKG;YACH,OAAO,EAAE;gBACP;;;;;;;;mBAQG;gBACH,IAAI,EAAE,QAAQ;gBACd,IAA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AAM,CAAC,QAAQ,CAAC;oBAC3D,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,KAAK,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;iBAC9B,EACD,OAAO,CAAC,OAAO,CAChB;YAEH,OAAO,CAAC,OAAO;gBACb,IAAI,8CAAoB,CAAC;oBACvB,YAAY,EAAE,CAAC;oBACf,QAAQ,EAAE,QAAQ;oBAClB,YAAY,EAAE,KAAK;iBACpB,CAAC;YAEJ;;;eAGG;YACH,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI;gBACxB,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,uBAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,+BAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC;AAhXD,0DAgXC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\nimport type { ProcessedConfig } from '../config';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin(\n {\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n },\n options.spinner,\n ),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(config.environment)),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin({\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n }),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\n }),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.cts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAoB7C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAwWxB"}
1
+ {"version":3,"file":"config.d.cts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAoB7C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CA2WxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAoB7C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CAwWxB"}
1
+ {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAoB7C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,cAER,GACA,OAAO,CAAC,aAAa,CAAC,CA2WxB"}
@@ -250,7 +250,7 @@ export async function getDefaultConfiguration(config, options = {
250
250
  manifestPath: config.manifest.path,
251
251
  writeManifest: config.manifest.update,
252
252
  eval: !options.watch && options.evaluate,
253
- }),
253
+ }, options.spinner),
254
254
  /**
255
255
  * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats
256
256
  * output. It's used to show the stats in the terminal, in a format that
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,uCAAuC;AAChE,OAAO,2BAA0B,uCAAuC;;AAExE,OAAO,EAAE,OAAO,EAAE,aAAa;AAC/B,OAAO,aAAY,8BAA8B;;;;AAG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,EAAE,OAAO,CAAC,QAAQ;oBAC1B,KAAK,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;iBAC9B,EACD,OAAO,CAAC,OAAO,CAChB;YAEH,OAAO,CAAC,OAAO;gBACb,IAAI,oBAAoB,CAAC;oBACvB,YAAY,EAAE,CAAC;oBACf,QAAQ,EAAE,QAAQ;oBAClB,YAAY,EAAE,KAAK;iBACpB,CAAC;YAEJ;;;eAGG;YACH,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI;gBACxB,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,aAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,YAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\nimport type { ProcessedConfig } from '../config';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(config.environment)),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin({\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n }),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\n }),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"]}
1
+ {"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../src/webpack/config.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,uCAAuC;AAChE,OAAO,2BAA0B,uCAAuC;;AAExE,OAAO,EAAE,OAAO,EAAE,aAAa;AAC/B,OAAO,aAAY,8BAA8B;;;;AAGjD,OAAO,EAAE,oBAAoB,EAAE,gCAAgC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,4BAAkB;AACpD,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,EACjB,sBAAkB;AACnB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,u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Q,EAAE,QAAQ;oBAClB,YAAY,EAAE,KAAK;iBACpB,CAAC;YAEJ;;;eAGG;YACH,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI;gBACxB,CAAC,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,aAAa,CAAC;oBAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;iBAC7B,CAAC;SACL,CAAC,MAAM,CAAC,OAAO,CAAC;QAEjB;;;;WAIG;QACH,YAAY,EAAE;YACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAEhC;;;eAGG;YACH,OAAO,EAAE,KAAK;YAEd;;eAEG;YACH,SAAS,EAAE;gBACT,IAAI,YAAY,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;SACF;QAED;;;;;WAKG;QACH,WAAW,EAAE;YACX;;;;;eAKG;YACH,KAAK,EAAE,KAAK;SACb;QAED;;;;;WAKG;QACH,qBAAqB,EAAE;YACrB;;;eAGG;YACH,KAAK,EAAE,MAAM;SACd;KACF,CAAC;AACJ,CAAC","sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { DefinePlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\nimport { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';\n\nimport { getFunctionLoader, wasm } from './loaders';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getEnvironmentVariables,\n getFallbacks,\n getImageSVG,\n getProgressHandler,\n} from './utils';\nimport type { ProcessedConfig } from '../config';\n\nexport type WebpackOptions = {\n /**\n * Whether to analyze the bundle.\n */\n analyze?: boolean;\n\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns && new SnapsBuiltInResolver(config.stats.builtIns);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle via assignment to module.exports.\n * We do this to mimic CommonJS, but still allow for usage of async initialization logic\n * via top level await.\n *\n * CommonJS is currently the only supported format for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'assign',\n name: 'module.exports',\n },\n\n /**\n * The chunk format. This tells Webpack how to export chunks. This is\n * required because we use browserslist to target browsers, but Snaps are\n * not fully compatible with browser APIs (such as `window` and\n * `document`).\n *\n * @see https://webpack.js.org/configuration/output/#outputchunkformat\n */\n chunkFormat: 'commonjs',\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.(js|jsx|mjs|cjs|ts|tsx)$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js$/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n /**\n * This allows importing `.svg` files as a string.\n */\n config.features.images && {\n test: /\\.svg$/u,\n // `asset/source` returns the source as a UTF-8 string.\n type: 'asset/source',\n },\n\n /**\n * This allows importing `.png` files as a data URL.\n */\n config.features.images && {\n test: /\\.png$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/png'),\n },\n },\n\n /**\n * This allows importing `.jpe?g` files as a data URL.\n */\n config.features.images && {\n test: /\\.jpe?g$/u,\n type: 'asset/inline',\n generator: {\n dataUrl: getImageSVG.bind(null, 'image/jpeg'),\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: getFunctionLoader(wasm, {}),\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.(c|m)?jsx?` and\n * `.tsx?` files.\n */\n extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `ForkTsCheckerWebpackPlugin` is a Webpack plugin that checks\n * Typescript type definitions, it does this in a separate process for speed.\n */\n config.typescript.enabled &&\n new ForkTsCheckerWebpackPlugin({\n typescript: {\n build: true,\n configFile: config.typescript.configFile,\n },\n }),\n\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin(\n {\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n },\n options.spinner,\n ),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `DefinePlugin` is a Webpack plugin that adds static values to the\n * bundle. We use it to add the `NODE_DEBUG`, `NODE_ENV`, and `DEBUG`\n * environment variables, as well as any custom environment\n * variables (as `process.env`).\n */\n new DefinePlugin(getEnvironmentVariables(config.environment)),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin({\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n }),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n options.analyze &&\n new BundleAnalyzerPlugin({\n analyzerPort: 0,\n logLevel: 'silent',\n openAnalyzer: false,\n }),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * We disable the nodeEnv optimization as we already add process.NODE_ENV\n * via the DefinePlugin in the section above this.\n */\n nodeEnv: false,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The performance configuration. This tells Webpack how to handle\n * performance hints.\n *\n * @see https://webpack.js.org/configuration/performance/\n */\n performance: {\n /**\n * The hints to show. We set it to `false`, so that we don't get\n * performance hints, as they are not relevant for Snaps.\n *\n * @see https://webpack.js.org/configuration/performance/#performancehints\n */\n hints: false,\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"]}
@@ -68,8 +68,7 @@ const loader = async function loader(source) {
68
68
  const wasmModule = await WebAssembly.compile(source);
69
69
  const exports = WebAssembly.Module.exports(wasmModule);
70
70
  const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
71
- var _a;
72
- target[_a = descriptor.module] ?? (target[_a] = []);
71
+ target[descriptor.module] ??= [];
73
72
  target[descriptor.module].push(descriptor.name);
74
73
  return target;
75
74
  }, {});
@@ -1 +1 @@
1
- {"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AACxD,+BAAwC;AAGxC;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,C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O,CAAC,UAAU,CAAC,CAAC,MAAM,CAE3D,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;;QACvB,MAAM,MAAC,UAAU,CAAC,MAAM,MAAxB,MAAM,OAAwB,EAAE,EAAC;QACjC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEhD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,wEAAwE;IACxE,WAAW;IACX,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,IAAA,cAAO,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;QAa/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACxD,QAAA,GAAG,GAAG,IAAI,CAAC","sourcesContent":["import { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const { instance } = await WebAssembly.instantiate(bytes, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
1
+ {"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AACxD,+BAAwC;AAGxC;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CACzD,UAAU,CACX,GAAG,CACP;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AATD,gCASC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,SAAmC;IAClE,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAClE;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAPD,4CAOC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,WAAiD;IAC1E,OAAO,WAAW;SACf,GAA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AC,IAAA,cAAO,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;QAa/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACxD,QAAA,GAAG,GAAG,IAAI,CAAC","sourcesContent":["import { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const { instance } = await WebAssembly.instantiate(bytes, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
@@ -62,8 +62,7 @@ const loader = async function loader(source) {
62
62
  const wasmModule = await WebAssembly.compile(source);
63
63
  const exports = WebAssembly.Module.exports(wasmModule);
64
64
  const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
65
- var _a;
66
- target[_a = descriptor.module] ?? (target[_a] = []);
65
+ target[descriptor.module] ??= [];
67
66
  target[descriptor.module].push(descriptor.name);
68
67
  return target;
69
68
  }, {});