@metamask/snaps-cli 1.0.2 → 2.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 (253) hide show
  1. package/.browserslistrc +3 -0
  2. package/CHANGELOG.md +32 -377
  3. package/README.md +548 -69
  4. package/dist/cjs/builders.js +148 -0
  5. package/dist/cjs/builders.js.map +1 -0
  6. package/dist/cjs/cli.js +35 -0
  7. package/dist/cjs/cli.js.map +1 -0
  8. package/dist/cjs/commands/build/build.js +54 -0
  9. package/dist/cjs/commands/build/build.js.map +1 -0
  10. package/dist/cjs/commands/build/implementation.js +31 -0
  11. package/dist/cjs/commands/build/implementation.js.map +1 -0
  12. package/dist/cjs/commands/build/index.js +45 -0
  13. package/dist/cjs/commands/build/index.js.map +1 -0
  14. package/dist/cjs/commands/eval/eval.js +57 -0
  15. package/dist/cjs/commands/eval/eval.js.map +1 -0
  16. package/dist/cjs/commands/eval/implementation.js +27 -0
  17. package/dist/cjs/commands/eval/implementation.js.map +1 -0
  18. package/dist/cjs/commands/eval/index.js +50 -0
  19. package/dist/cjs/commands/eval/index.js.map +1 -0
  20. package/dist/cjs/commands/index.js +30 -0
  21. package/dist/cjs/commands/index.js.map +1 -0
  22. package/dist/cjs/commands/manifest/implementation.js +34 -0
  23. package/dist/cjs/commands/manifest/implementation.js.map +1 -0
  24. package/dist/cjs/commands/manifest/index.js +50 -0
  25. package/dist/cjs/commands/manifest/index.js.map +1 -0
  26. package/dist/cjs/commands/manifest/manifest.js +55 -0
  27. package/dist/cjs/commands/manifest/manifest.js.map +1 -0
  28. package/dist/cjs/commands/serve/index.js +33 -0
  29. package/dist/cjs/commands/serve/index.js.map +1 -0
  30. package/dist/cjs/commands/serve/serve.js +21 -0
  31. package/dist/cjs/commands/serve/serve.js.map +1 -0
  32. package/dist/cjs/commands/watch/implementation.js +35 -0
  33. package/dist/cjs/commands/watch/implementation.js.map +1 -0
  34. package/dist/cjs/commands/watch/index.js +47 -0
  35. package/dist/cjs/commands/watch/index.js.map +1 -0
  36. package/dist/cjs/commands/watch/watch.js +51 -0
  37. package/dist/cjs/commands/watch/watch.js.map +1 -0
  38. package/dist/cjs/config.js +323 -0
  39. package/dist/cjs/config.js.map +1 -0
  40. package/dist/cjs/errors.js +37 -0
  41. package/dist/cjs/errors.js.map +1 -0
  42. package/dist/cjs/index.js +77 -0
  43. package/dist/cjs/index.js.map +1 -0
  44. package/dist/cjs/main.js +19 -0
  45. package/dist/cjs/main.js.map +1 -0
  46. package/dist/cjs/utils/cli.js +61 -0
  47. package/dist/cjs/utils/cli.js.map +1 -0
  48. package/dist/cjs/utils/errors.js +42 -0
  49. package/dist/cjs/utils/errors.js.map +1 -0
  50. package/dist/cjs/utils/index.js +25 -0
  51. package/dist/cjs/utils/index.js.map +1 -0
  52. package/dist/cjs/utils/legacy.js +48 -0
  53. package/dist/cjs/utils/legacy.js.map +1 -0
  54. package/dist/cjs/utils/logging.js +46 -0
  55. package/dist/cjs/utils/logging.js.map +1 -0
  56. package/dist/cjs/utils/path.js +16 -0
  57. package/dist/cjs/utils/path.js.map +1 -0
  58. package/dist/cjs/utils/steps.js +52 -0
  59. package/dist/cjs/utils/steps.js.map +1 -0
  60. package/dist/cjs/webpack/compiler.js +96 -0
  61. package/dist/cjs/webpack/compiler.js.map +1 -0
  62. package/dist/cjs/webpack/config.js +239 -0
  63. package/dist/cjs/webpack/config.js.map +1 -0
  64. package/dist/cjs/webpack/index.js +22 -0
  65. package/dist/cjs/webpack/index.js.map +1 -0
  66. package/dist/cjs/webpack/loaders/browserify.js +97 -0
  67. package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
  68. package/dist/cjs/webpack/loaders/wasm.js +36 -0
  69. package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
  70. package/dist/cjs/webpack/plugins.js +340 -0
  71. package/dist/cjs/webpack/plugins.js.map +1 -0
  72. package/dist/cjs/webpack/utils.js +181 -0
  73. package/dist/cjs/webpack/utils.js.map +1 -0
  74. package/dist/{builders.js → esm/builders.js} +48 -51
  75. package/dist/esm/builders.js.map +1 -0
  76. package/dist/esm/cli.js +26 -0
  77. package/dist/esm/cli.js.map +1 -0
  78. package/dist/esm/commands/build/build.js +51 -0
  79. package/dist/esm/commands/build/build.js.map +1 -0
  80. package/dist/esm/commands/build/implementation.js +27 -0
  81. package/dist/esm/commands/build/implementation.js.map +1 -0
  82. package/dist/esm/commands/build/index.js +17 -0
  83. package/dist/esm/commands/build/index.js.map +1 -0
  84. package/dist/esm/commands/eval/eval.js +54 -0
  85. package/dist/esm/commands/eval/eval.js.map +1 -0
  86. package/dist/esm/commands/eval/implementation.js +24 -0
  87. package/dist/esm/commands/eval/implementation.js.map +1 -0
  88. package/dist/esm/commands/eval/index.js +22 -0
  89. package/dist/esm/commands/eval/index.js.map +1 -0
  90. package/dist/esm/commands/index.js +15 -0
  91. package/dist/esm/commands/index.js.map +1 -0
  92. package/dist/esm/commands/manifest/implementation.js +33 -0
  93. package/dist/esm/commands/manifest/implementation.js.map +1 -0
  94. package/dist/esm/commands/manifest/index.js +22 -0
  95. package/dist/esm/commands/manifest/index.js.map +1 -0
  96. package/dist/esm/commands/manifest/manifest.js +52 -0
  97. package/dist/esm/commands/manifest/manifest.js.map +1 -0
  98. package/dist/esm/commands/serve/index.js +18 -0
  99. package/dist/esm/commands/serve/index.js.map +1 -0
  100. package/dist/esm/commands/serve/serve.js +17 -0
  101. package/dist/esm/commands/serve/serve.js.map +1 -0
  102. package/dist/esm/commands/watch/implementation.js +34 -0
  103. package/dist/esm/commands/watch/implementation.js.map +1 -0
  104. package/dist/esm/commands/watch/index.js +19 -0
  105. package/dist/esm/commands/watch/index.js.map +1 -0
  106. package/dist/esm/commands/watch/watch.js +50 -0
  107. package/dist/esm/commands/watch/watch.js.map +1 -0
  108. package/dist/esm/config.js +327 -0
  109. package/dist/esm/config.js.map +1 -0
  110. package/dist/esm/errors.js +30 -0
  111. package/dist/esm/errors.js.map +1 -0
  112. package/dist/esm/index.js +6 -0
  113. package/dist/esm/index.js.map +1 -0
  114. package/dist/esm/main.js +10 -0
  115. package/dist/esm/main.js.map +1 -0
  116. package/dist/esm/utils/cli.js +43 -0
  117. package/dist/esm/utils/cli.js.map +1 -0
  118. package/dist/esm/utils/errors.js +43 -0
  119. package/dist/esm/utils/errors.js.map +1 -0
  120. package/dist/esm/utils/index.js +8 -0
  121. package/dist/esm/utils/index.js.map +1 -0
  122. package/dist/esm/utils/legacy.js +47 -0
  123. package/dist/esm/utils/legacy.js.map +1 -0
  124. package/dist/esm/utils/logging.js +40 -0
  125. package/dist/esm/utils/logging.js.map +1 -0
  126. package/dist/esm/utils/path.js +13 -0
  127. package/dist/esm/utils/path.js.map +1 -0
  128. package/dist/esm/utils/steps.js +43 -0
  129. package/dist/esm/utils/steps.js.map +1 -0
  130. package/dist/esm/webpack/compiler.js +89 -0
  131. package/dist/esm/webpack/compiler.js.map +1 -0
  132. package/dist/esm/webpack/config.js +241 -0
  133. package/dist/esm/webpack/config.js.map +1 -0
  134. package/dist/esm/webpack/index.js +5 -0
  135. package/dist/esm/webpack/index.js.map +1 -0
  136. package/dist/esm/webpack/loaders/browserify.js +82 -0
  137. package/dist/esm/webpack/loaders/browserify.js.map +1 -0
  138. package/dist/esm/webpack/loaders/wasm.js +26 -0
  139. package/dist/esm/webpack/loaders/wasm.js.map +1 -0
  140. package/dist/esm/webpack/plugins.js +343 -0
  141. package/dist/esm/webpack/plugins.js.map +1 -0
  142. package/dist/esm/webpack/utils.js +208 -0
  143. package/dist/esm/webpack/utils.js.map +1 -0
  144. package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
  145. package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
  146. package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
  147. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  148. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
  149. package/dist/types/builders.d.ts +8 -0
  150. package/dist/{cli.d.ts → types/cli.d.ts} +1 -1
  151. package/dist/types/commands/build/build.d.ts +10 -0
  152. package/dist/types/commands/build/implementation.d.ts +10 -0
  153. package/dist/types/commands/build/index.d.ts +10 -0
  154. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
  155. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
  156. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
  157. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
  158. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
  159. package/dist/types/commands/eval/eval.d.ts +14 -0
  160. package/dist/types/commands/eval/implementation.d.ts +9 -0
  161. package/dist/types/commands/eval/index.d.ts +10 -0
  162. package/dist/types/commands/manifest/implementation.d.ts +12 -0
  163. package/dist/types/commands/manifest/index.d.ts +10 -0
  164. package/dist/types/commands/manifest/manifest.d.ts +14 -0
  165. package/dist/{cmds/build → types/commands/serve}/index.d.ts +4 -4
  166. package/dist/types/commands/serve/serve.d.ts +16 -0
  167. package/dist/types/commands/watch/implementation.d.ts +14 -0
  168. package/dist/types/commands/watch/index.d.ts +10 -0
  169. package/dist/types/commands/watch/watch.d.ts +19 -0
  170. package/dist/types/config.d.ts +792 -0
  171. package/dist/types/errors.d.ts +25 -0
  172. package/dist/types/index.d.ts +5 -0
  173. package/dist/types/utils/cli.d.ts +17 -0
  174. package/dist/types/utils/errors.d.ts +23 -0
  175. package/dist/types/utils/index.d.ts +6 -0
  176. package/dist/types/utils/legacy.d.ts +27 -0
  177. package/dist/types/utils/logging.d.ts +22 -0
  178. package/dist/types/utils/path.d.ts +9 -0
  179. package/dist/types/utils/steps.d.ts +17 -0
  180. package/dist/types/webpack/compiler.d.ts +29 -0
  181. package/dist/types/webpack/config.d.ts +37 -0
  182. package/dist/types/webpack/index.d.ts +3 -0
  183. package/dist/types/webpack/loaders/browserify.d.ts +16 -0
  184. package/dist/types/webpack/loaders/wasm.d.ts +20 -0
  185. package/dist/types/webpack/plugins.d.ts +147 -0
  186. package/dist/types/webpack/utils.d.ts +188 -0
  187. package/package.json +83 -43
  188. package/dist/builders.d.ts +0 -27
  189. package/dist/builders.js.map +0 -1
  190. package/dist/cli.js +0 -51
  191. package/dist/cli.js.map +0 -1
  192. package/dist/cmds/build/buildHandler.d.ts +0 -13
  193. package/dist/cmds/build/buildHandler.js +0 -37
  194. package/dist/cmds/build/buildHandler.js.map +0 -1
  195. package/dist/cmds/build/bundle.d.ts +0 -15
  196. package/dist/cmds/build/bundle.js +0 -80
  197. package/dist/cmds/build/bundle.js.map +0 -1
  198. package/dist/cmds/build/index.js +0 -29
  199. package/dist/cmds/build/index.js.map +0 -1
  200. package/dist/cmds/build/utils.d.ts +0 -56
  201. package/dist/cmds/build/utils.js +0 -100
  202. package/dist/cmds/build/utils.js.map +0 -1
  203. package/dist/cmds/eval/evalHandler.d.ts +0 -9
  204. package/dist/cmds/eval/evalHandler.js +0 -25
  205. package/dist/cmds/eval/evalHandler.js.map +0 -1
  206. package/dist/cmds/eval/index.d.ts +0 -9
  207. package/dist/cmds/eval/index.js +0 -15
  208. package/dist/cmds/eval/index.js.map +0 -1
  209. package/dist/cmds/index.js +0 -14
  210. package/dist/cmds/index.js.map +0 -1
  211. package/dist/cmds/init/index.d.ts +0 -9
  212. package/dist/cmds/init/index.js +0 -34
  213. package/dist/cmds/init/index.js.map +0 -1
  214. package/dist/cmds/init/initHandler.d.ts +0 -26
  215. package/dist/cmds/init/initHandler.js +0 -69
  216. package/dist/cmds/init/initHandler.js.map +0 -1
  217. package/dist/cmds/init/initUtils.d.ts +0 -39
  218. package/dist/cmds/init/initUtils.js +0 -122
  219. package/dist/cmds/init/initUtils.js.map +0 -1
  220. package/dist/cmds/manifest/index.d.ts +0 -9
  221. package/dist/cmds/manifest/index.js +0 -24
  222. package/dist/cmds/manifest/index.js.map +0 -1
  223. package/dist/cmds/manifest/manifestHandler.d.ts +0 -10
  224. package/dist/cmds/manifest/manifestHandler.js +0 -50
  225. package/dist/cmds/manifest/manifestHandler.js.map +0 -1
  226. package/dist/cmds/serve/index.d.ts +0 -9
  227. package/dist/cmds/serve/index.js +0 -15
  228. package/dist/cmds/serve/index.js.map +0 -1
  229. package/dist/cmds/serve/serveHandler.d.ts +0 -10
  230. package/dist/cmds/serve/serveHandler.js +0 -59
  231. package/dist/cmds/serve/serveHandler.js.map +0 -1
  232. package/dist/cmds/serve/serveUtils.d.ts +0 -22
  233. package/dist/cmds/serve/serveUtils.js +0 -39
  234. package/dist/cmds/serve/serveUtils.js.map +0 -1
  235. package/dist/cmds/watch/index.d.ts +0 -9
  236. package/dist/cmds/watch/index.js +0 -32
  237. package/dist/cmds/watch/index.js.map +0 -1
  238. package/dist/cmds/watch/watchHandler.d.ts +0 -14
  239. package/dist/cmds/watch/watchHandler.js +0 -100
  240. package/dist/cmds/watch/watchHandler.js.map +0 -1
  241. package/dist/main.js +0 -15
  242. package/dist/main.js.map +0 -1
  243. package/dist/utils/index.d.ts +0 -2
  244. package/dist/utils/index.js +0 -19
  245. package/dist/utils/index.js.map +0 -1
  246. package/dist/utils/misc.d.ts +0 -53
  247. package/dist/utils/misc.js +0 -156
  248. package/dist/utils/misc.js.map +0 -1
  249. package/dist/utils/snap-config.d.ts +0 -48
  250. package/dist/utils/snap-config.js +0 -117
  251. package/dist/utils/snap-config.js.map +0 -1
  252. /package/dist/{cmds → types/commands}/index.d.ts +0 -0
  253. /package/dist/{main.d.ts → types/main.d.ts} +0 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * An error that is thrown when the CLI fails. This is the base error for all
3
+ * CLI errors. It is not thrown directly, but is instead extended by other
4
+ * errors.
5
+ *
6
+ * This error is assumed to have all the information needed to display a
7
+ * readable error message, so it does not include the stack trace when it is
8
+ * thrown.
9
+ */
10
+ export declare class CLIError extends Error {
11
+ }
12
+ /**
13
+ * An error that is thrown when a command fails.
14
+ *
15
+ * It wraps the error prefix in a bold red "Error" string.
16
+ */
17
+ export declare class CommandError extends CLIError {
18
+ constructor(message: string, name?: string);
19
+ }
20
+ /**
21
+ * An error that is thrown when the config file cannot be loaded.
22
+ */
23
+ export declare class ConfigError extends CommandError {
24
+ constructor(message: string);
25
+ }
@@ -0,0 +1,5 @@
1
+ export * as utils from './utils';
2
+ export type { SnapConfig } from './config';
3
+ export { getDefaultConfiguration, SnapsStatsPlugin, SnapsWatchPlugin, SnapsBuiltInResolver, SnapsBundleWarningsPlugin, } from './webpack';
4
+ export type { SnapsStatsPluginOptions, SnapsWatchPluginOptions, SnapsBuiltInResolverOptions, SnapsBundleWarningsPluginOptions, } from './webpack';
5
+ export { merge } from 'webpack-merge';
@@ -0,0 +1,17 @@
1
+ export declare const CONFIG_FILE = "snap.config.js";
2
+ export declare const TS_CONFIG_FILE = "snap.config.ts";
3
+ /**
4
+ * Sanitizes inputs. Currently normalizes "./" paths to ".".
5
+ * Yargs handles other path normalization as specified in builders.
6
+ *
7
+ * @param argv - Arguments as an object generated by yargs.
8
+ */
9
+ export declare function sanitizeInputs(argv: Record<string, unknown>): void;
10
+ /**
11
+ * Trims leading and trailing periods "." and forward slashes "/" from the
12
+ * given path string.
13
+ *
14
+ * @param pathString - The path string to trim.
15
+ * @returns The trimmed path string.
16
+ */
17
+ export declare function trimPathString(pathString: string): string;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Get the error message from an error in a Yargs `fail` handler. If the error
3
+ * is not `undefined`, {@link getErrorMessage} is used to get the error message.
4
+ * Otherwise, the given message is returned.
5
+ *
6
+ * @param message - The error message.
7
+ * @param error - The error object. This may be `undefined`.
8
+ * @returns The error message.
9
+ */
10
+ export declare function getYargsErrorMessage(message: string, error?: unknown): string;
11
+ /**
12
+ * Get the error message from an error.
13
+ *
14
+ * - If the error is an object with a `stack` property, the `stack` property is
15
+ * returned.
16
+ * - If the error is an object with a `message` property, the `message`
17
+ * property is returned.
18
+ * - Otherwise, the error is converted to a string and returned.
19
+ *
20
+ * @param error - The error to get the message from.
21
+ * @returns The error message.
22
+ */
23
+ export declare function getErrorMessage(error: unknown): string;
@@ -0,0 +1,6 @@
1
+ export * from './cli';
2
+ export * from './errors';
3
+ export * from './legacy';
4
+ export * from './logging';
5
+ export * from './path';
6
+ export * from './steps';
@@ -0,0 +1,27 @@
1
+ import type { LegacyOptions } from '../config';
2
+ /**
3
+ * Get the dependencies to transpile, as well as the regular input file.
4
+ *
5
+ * If `transpilationMode` is not set to `localAndDeps`, this will return an
6
+ * empty array.
7
+ *
8
+ * @param config - The config object.
9
+ * @returns An array with regular expressions of dependencies that should be
10
+ * transpiled.
11
+ */
12
+ export declare function processDependencies(config: LegacyOptions): RegExp[];
13
+ /**
14
+ * Processes a string of space delimited dependencies into one RegExp string.
15
+ *
16
+ * @param dependencies - An array of dependencies to add to the RegExp.
17
+ * @returns A RegExp object.
18
+ */
19
+ export declare function getDependencyRegExp(dependencies: string[]): RegExp | null;
20
+ /**
21
+ * Helper function to remove any leading and trailing slashes from dependency
22
+ * list.
23
+ *
24
+ * @param dependencies - An array of dependencies to sanitize.
25
+ * @returns An array of sanitized paths.
26
+ */
27
+ export declare function sanitizeDependencyPaths(dependencies: string[]): string[];
@@ -0,0 +1,22 @@
1
+ import type { Ora } from 'ora';
2
+ /**
3
+ * Log a warning message. The message is prefixed with "Warning:".
4
+ *
5
+ * @param message - The message to log.
6
+ * @param spinner - The spinner to clear.
7
+ */
8
+ export declare function warn(message: string, spinner?: Ora): void;
9
+ /**
10
+ * Log an info message.
11
+ *
12
+ * @param message - The message to log.
13
+ * @param spinner - The spinner to clear.
14
+ */
15
+ export declare function info(message: string, spinner?: Ora): void;
16
+ /**
17
+ * Log an error message. The message is prefixed with "Error:".
18
+ *
19
+ * @param message - The message to log.
20
+ * @param spinner - The spinner to clear.
21
+ */
22
+ export declare function error(message: string, spinner?: Ora): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get the relative path from the current working directory to the given
3
+ * absolute path.
4
+ *
5
+ * @param absolutePath - The absolute path.
6
+ * @param cwd - The current working directory. Defaults to `process.cwd()`.
7
+ * @returns The relative path.
8
+ */
9
+ export declare function getRelativePath(absolutePath: string, cwd?: string): string;
@@ -0,0 +1,17 @@
1
+ import type { Ora } from 'ora';
2
+ export declare type Step<Context extends Record<string, unknown>> = {
3
+ name: string;
4
+ condition?: (context: Context) => boolean;
5
+ task: (context: Context & {
6
+ spinner: Ora;
7
+ }) => Promise<void>;
8
+ };
9
+ export declare type Steps<Context extends Record<string, unknown>> = Readonly<Step<Context>[]>;
10
+ /**
11
+ * Execute a list of steps in series. Each step receives the context object and
12
+ * a spinner instance.
13
+ *
14
+ * @param steps - The steps to execute.
15
+ * @param context - The context object that will be passed to each step.
16
+ */
17
+ export declare function executeSteps<Context extends Record<string, unknown>>(steps: Steps<Context>, context: Context): Promise<void>;
@@ -0,0 +1,29 @@
1
+ import type { Server } from 'http';
2
+ import type { ProcessedConfig, ProcessedWebpackConfig } from '../config';
3
+ import type { WebpackOptions } from './config';
4
+ /**
5
+ * Get a Webpack compiler for the given config.
6
+ *
7
+ * @param config - The config object.
8
+ * @param options - The Webpack options.
9
+ * @returns The Webpack compiler.
10
+ */
11
+ export declare function getCompiler(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
12
+ /**
13
+ * Get a static server for development purposes.
14
+ *
15
+ * Note: We're intentionally not using `webpack-dev-server` here because it
16
+ * adds a lot of extra stuff to the output that we don't need, and it's
17
+ * difficult to customize.
18
+ *
19
+ * @param config - The config object.
20
+ * @returns An object with a `listen` method that returns a promise that
21
+ * resolves when the server is listening.
22
+ */
23
+ export declare function getServer(config: ProcessedConfig): {
24
+ listen: (port?: number) => Promise<{
25
+ port: number;
26
+ server: Server;
27
+ close: () => Promise<void>;
28
+ }>;
29
+ };
@@ -0,0 +1,37 @@
1
+ import type { Ora } from 'ora';
2
+ import type { Configuration } from 'webpack';
3
+ import type { ProcessedWebpackConfig } from '../config';
4
+ export declare type WebpackOptions = {
5
+ /**
6
+ * Whether to watch for changes.
7
+ */
8
+ watch?: boolean;
9
+ /**
10
+ * Whether to evaluate the bundle. If this is set, it will override the
11
+ * `evaluate` option in the config object.
12
+ */
13
+ evaluate?: boolean;
14
+ /**
15
+ * The spinner to use for logging.
16
+ */
17
+ spinner?: Ora;
18
+ };
19
+ /**
20
+ * Get the default Webpack configuration. This is the configuration that will
21
+ * be used if the user doesn't provide a custom Webpack configuration. The
22
+ * configuration is based on the snap config.
23
+ *
24
+ * The default configuration includes:
25
+ *
26
+ * - `SWC` to transpile TypeScript and JavaScript files.
27
+ * - `TerserPlugin` to minify the bundle.
28
+ * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.
29
+ *
30
+ * It can be customized through the `customizeWebpackConfig` function in the
31
+ * snap config, but in most cases, you shouldn't need to do that.
32
+ *
33
+ * @param config - The processed snap Webpack config.
34
+ * @param options - The Webpack options.
35
+ * @returns The default Webpack configuration.
36
+ */
37
+ export declare function getDefaultConfiguration(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<Configuration>;
@@ -0,0 +1,3 @@
1
+ export * from './compiler';
2
+ export * from './config';
3
+ export * from './plugins';
@@ -0,0 +1,16 @@
1
+ import type { LoaderDefinitionFunction } from 'webpack';
2
+ import type { LegacyOptions } from '../../config';
3
+ /**
4
+ * A Browserify loader for Webpack. This exists for backwards compatibility with
5
+ * the legacy configuration format, in order to support the `bundlerCustomizer`
6
+ * function.
7
+ *
8
+ * When this loader is used, the input file will be processed by Browserify, and
9
+ * written to disk by Webpack. Most processing will be handled by Browserify, so
10
+ * there are no benefits like tree-shaking.
11
+ *
12
+ * @param content - The input file contents as a string.
13
+ * @param sourceMap - The source map of the input file.
14
+ */
15
+ declare const loader: LoaderDefinitionFunction<LegacyOptions>;
16
+ export default loader;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A Webpack loader that inlines the WASM module as a `Uint8Array`. This makes
3
+ * it possible to import the WASM module directly, and use it with the
4
+ * `WebAssembly.instantiate` function.
5
+ *
6
+ * This is useful, because snaps are not allowed to import assets from outside
7
+ * of their package. This loader allows you to inline the WASM module as a
8
+ * `Uint8Array`, which can then be passed to `WebAssembly.instantiate`.
9
+ *
10
+ * @param source - The WASM module as a string.
11
+ * @returns A string that exports the WASM module as a `Uint8Array`.
12
+ * @example
13
+ * ```ts
14
+ * import wasm from './program.wasm';
15
+ *
16
+ * const { instance } = await WebAssembly.instantiate(wasm, {});
17
+ * // Do something with the WASM module...
18
+ * ```
19
+ */
20
+ export default function loader(source: unknown): string;
@@ -0,0 +1,147 @@
1
+ import type { Ora } from 'ora';
2
+ import type { Compiler, ResolvePluginInstance, Resolver, WebpackPluginInstance } from 'webpack';
3
+ export declare type SnapsStatsPluginOptions = {
4
+ /**
5
+ * Whether to log the verbose stats.
6
+ */
7
+ verbose?: boolean;
8
+ };
9
+ /**
10
+ * A plugin that logs the stats after compilation. This is useful for logging
11
+ * the number of files compiled, and the time taken to compile them.
12
+ */
13
+ export declare class SnapsStatsPlugin implements WebpackPluginInstance {
14
+ #private;
15
+ /**
16
+ * The options for the plugin.
17
+ */
18
+ readonly options: SnapsStatsPluginOptions;
19
+ constructor(options?: SnapsStatsPluginOptions, spinner?: Ora);
20
+ /**
21
+ * Apply the plugin to the Webpack compiler.
22
+ *
23
+ * @param compiler - The Webpack compiler.
24
+ */
25
+ apply(compiler: Compiler): void;
26
+ }
27
+ /**
28
+ * The options for the {@link SnapsWatchPlugin}.
29
+ */
30
+ export declare type SnapsWatchPluginOptions = {
31
+ /**
32
+ * The bundle path. This is the file that will be evaluated, if the `evaluate`
33
+ * option is set.
34
+ */
35
+ bundle?: string;
36
+ /**
37
+ * Whether to evaluate the bundle. This only applies if the `bundle` option is
38
+ * set.
39
+ */
40
+ evaluate?: boolean;
41
+ /**
42
+ * The extra files to watch.
43
+ */
44
+ files?: string[];
45
+ };
46
+ /**
47
+ * A plugin that adds extra files to watch. This is useful for watching files
48
+ * that are not imported by the entry point, such as the `snap.manifest.json`
49
+ * file.
50
+ */
51
+ export declare class SnapsWatchPlugin implements WebpackPluginInstance {
52
+ #private;
53
+ /**
54
+ * The options for the plugin.
55
+ */
56
+ readonly options: SnapsWatchPluginOptions;
57
+ constructor(options: SnapsWatchPluginOptions, spinner?: Ora);
58
+ /**
59
+ * Apply the plugin to the Webpack compiler.
60
+ *
61
+ * @param compiler - The Webpack compiler.
62
+ */
63
+ apply(compiler: Compiler): void;
64
+ }
65
+ /**
66
+ * The options for the {@link SnapsBuiltInResolver}.
67
+ */
68
+ export declare type SnapsBuiltInResolverOptions = {
69
+ /**
70
+ * The built-in modules to ignore.
71
+ */
72
+ ignore?: string[];
73
+ };
74
+ /**
75
+ * A plugin that logs a message when a built-in module is not resolved. The
76
+ * MetaMask Snaps CLI does not support built-in modules by default, and this
77
+ * plugin is used to warn the user when they try to import a built-in module,
78
+ * when no fallback is configured.
79
+ */
80
+ export declare class SnapsBuiltInResolver implements ResolvePluginInstance {
81
+ #private;
82
+ /**
83
+ * The built-in modules that have been imported, but not resolved.
84
+ */
85
+ readonly unresolvedModules: Set<string>;
86
+ /**
87
+ * The options for the plugin.
88
+ */
89
+ readonly options: SnapsBuiltInResolverOptions;
90
+ constructor(options?: SnapsBuiltInResolverOptions, spinner?: Ora);
91
+ /**
92
+ * Apply the plugin to the Webpack resolver.
93
+ *
94
+ * @param resolver - The Webpack resolver.
95
+ */
96
+ apply(resolver: Resolver): void;
97
+ }
98
+ /**
99
+ * The options for the {@link SnapsBundleWarningsPlugin}.
100
+ */
101
+ export declare type SnapsBundleWarningsPluginOptions = {
102
+ /**
103
+ * The {@link SnapsBuiltInResolver} instance to use for detecting built-in
104
+ * modules.
105
+ */
106
+ builtInResolver?: SnapsBuiltInResolver | false;
107
+ /**
108
+ * Whether to show warnings if built-in modules are used, but not provided by
109
+ * Webpack's `fallback` configuration.
110
+ */
111
+ builtIns?: boolean;
112
+ /**
113
+ * Whether to show warnings if the `Buffer` global is used, but not provided
114
+ * by Webpack's `DefinePlugin`.
115
+ */
116
+ buffer?: boolean;
117
+ };
118
+ /**
119
+ * A plugin that logs a message when:
120
+ *
121
+ * - A built-in module is not resolved. The MetaMask Snaps CLI does not support
122
+ * built-in modules by default, and this plugin is used to warn the user when
123
+ * they try to import a built-in module, when no fallback is configured.
124
+ * - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support
125
+ * the `Buffer` global by default, and this plugin is used to warn the user when
126
+ * they try to use the `Buffer` global.
127
+ *
128
+ * We use both a resolver and a plugin, because the resolver is used to detect
129
+ * when a built-in module is imported, and the plugin is used to log a single
130
+ * message when the compilation is complete. We can't do everything in a single
131
+ * plugin, because the resolver doesn't have access to the compilation, and the
132
+ * plugin doesn't have access to the resolver.
133
+ */
134
+ export declare class SnapsBundleWarningsPlugin implements WebpackPluginInstance {
135
+ #private;
136
+ /**
137
+ * The options for the plugin.
138
+ */
139
+ readonly options: SnapsBundleWarningsPluginOptions;
140
+ constructor(options?: SnapsBundleWarningsPluginOptions, spinner?: Ora);
141
+ /**
142
+ * Apply the plugin to the Webpack compiler.
143
+ *
144
+ * @param compiler - The Webpack compiler.
145
+ */
146
+ apply(compiler: Compiler): void;
147
+ }
@@ -0,0 +1,188 @@
1
+ /// <reference types="browserify" />
2
+ import type { Ora } from 'ora';
3
+ import type { Configuration } from 'webpack';
4
+ import type { ProcessedWebpackConfig } from '../config';
5
+ export declare const BROWSERSLIST_FILE: string;
6
+ export declare const WEBPACK_FALLBACKS: {
7
+ assert: string;
8
+ buffer: string;
9
+ console: string;
10
+ constants: string;
11
+ crypto: string;
12
+ domain: string;
13
+ events: string;
14
+ http: string;
15
+ https: string;
16
+ os: string;
17
+ path: string;
18
+ punycode: string;
19
+ process: string;
20
+ querystring: string;
21
+ stream: string;
22
+ _stream_duplex: string;
23
+ _stream_passthrough: string;
24
+ _stream_readable: string;
25
+ _stream_transform: string;
26
+ _stream_writable: string;
27
+ string_decoder: string;
28
+ sys: string;
29
+ timers: string;
30
+ tty: string;
31
+ url: string;
32
+ util: string;
33
+ vm: string;
34
+ zlib: string;
35
+ };
36
+ /**
37
+ * Get the default loader for JavaScript and TypeScript files, based on the
38
+ * config object.
39
+ *
40
+ * - If the `legacy` option is set, we use the custom `browserify` loader. This
41
+ * uses the legacy Browserify config to transpile the code.
42
+ * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the
43
+ * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's
44
+ * own compiler.
45
+ *
46
+ * @param config - The processed snap Webpack config.
47
+ * @param config.legacy - The legacy config object, if any.
48
+ * @param config.sourceMap - Whether to generate source maps.
49
+ * @see https://swc.rs/docs/usage/swc-loader
50
+ * @returns The default loader.
51
+ */
52
+ export declare function getDefaultLoader({ legacy, sourceMap, }: ProcessedWebpackConfig): Promise<{
53
+ /**
54
+ * If the snap uses the legacy config, we use the custom `browserify`
55
+ * loader. This uses the legacy Browserify config to transpile the code.
56
+ * This is necessary for backwards compatibility with the
57
+ * `bundlerCustomizer` function.
58
+ */
59
+ loader: string;
60
+ /**
61
+ * The options for the `browserify` loader. These can be overridden in the
62
+ * snap config.
63
+ */
64
+ options: {
65
+ transpilationMode: import("../builders").TranspilationModes.LocalAndDeps;
66
+ depsToTranspile: string[];
67
+ writeManifest: boolean;
68
+ bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
69
+ } | {
70
+ transpilationMode: import("../builders").TranspilationModes.LocalOnly | import("../builders").TranspilationModes.None;
71
+ depsToTranspile: unknown[];
72
+ writeManifest: boolean;
73
+ bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
74
+ };
75
+ } | {
76
+ /**
77
+ * We use the `swc-loader` to transpile TypeScript and JavaScript files.
78
+ * This is a Webpack loader that uses the `SWC` compiler, which is a much
79
+ * faster alternative to Babel and TypeScript's own compiler.
80
+ */
81
+ loader: string;
82
+ /**
83
+ * The options for the `swc-loader`. These can be overridden in the
84
+ * `.swcrc` file.
85
+ *
86
+ * @see https://swc.rs/docs/configuration/swcrc
87
+ */
88
+ options: {
89
+ sync: boolean;
90
+ /**
91
+ * This tells SWC to generate source maps. We set it to the
92
+ * `sourceMap` value from the config object.
93
+ *
94
+ * This must be enabled if source maps are enabled in the config.
95
+ */
96
+ sourceMaps: boolean;
97
+ jsc: {
98
+ parser: {
99
+ /**
100
+ * This tells the parser to parse TypeScript files. If you
101
+ * don't need to support TypeScript, you can set this to
102
+ * `ecmascript` instead, but there's no harm in leaving it
103
+ * as `typescript`.
104
+ *
105
+ * @see https://swc.rs/docs/configuration/compilation#jscparser
106
+ */
107
+ syntax: string;
108
+ };
109
+ };
110
+ /**
111
+ * The module configuration. This tells SWC how to output the
112
+ * transpiled code.
113
+ *
114
+ * @see https://swc.rs/docs/configuration/modules
115
+ */
116
+ module: {
117
+ /**
118
+ * This tells SWC to output CommonJS modules. MetaMask Snaps
119
+ * doesn't support ES modules yet, so this is necessary.
120
+ *
121
+ * @see https://swc.rs/docs/configuration/modules#commonjs
122
+ */
123
+ type: string;
124
+ };
125
+ env: {
126
+ targets: string;
127
+ };
128
+ };
129
+ }>;
130
+ /**
131
+ * Get the Webpack devtool configuration based on the given snap config.
132
+ *
133
+ * - If `sourceMap` is `inline`, return `inline-source-map`.
134
+ * - If `sourceMap` is `true`, return `source-map`.
135
+ * - Otherwise, return `false`.
136
+ *
137
+ * @param sourceMap - The `sourceMap` value from the snap config.
138
+ * @returns The Webpack devtool configuration.
139
+ */
140
+ export declare function getDevTool(sourceMap: ProcessedWebpackConfig['sourceMap']): Configuration['devtool'];
141
+ /**
142
+ * Get a function that can be used as handler function for Webpack's
143
+ * `ProgressPlugin`.
144
+ *
145
+ * @param spinner - The spinner to update.
146
+ * @param spinnerText - The initial spinner text. This will be prepended to the
147
+ * percentage.
148
+ * @returns A function that can be used as handler function for Webpack's
149
+ * `ProgressPlugin`.
150
+ */
151
+ export declare function getProgressHandler(spinner?: Ora, spinnerText?: string): (percentage: number) => void;
152
+ /**
153
+ * Get the targets from the `.browserslistrc` file.
154
+ *
155
+ * @returns The browser targets as an array of strings.
156
+ */
157
+ export declare function getBrowserslistTargets(): Promise<string[]>;
158
+ /**
159
+ * Get a singular or plural string based on the given count. This is useful for
160
+ * generating messages like "1 error" or "2 errors". By default, the plural
161
+ * string is the singular string with an "s" appended to it.
162
+ *
163
+ * This assumes that the text is in English, and likely won't work for some
164
+ * other languages.
165
+ *
166
+ * @param count - The count.
167
+ * @param singular - The singular string.
168
+ * @param plural - The plural string.
169
+ * @returns The singular or plural string.
170
+ * @example
171
+ * ```typescript
172
+ * pluralize(1, 'error'); // => 'error'
173
+ * pluralize(2, 'error'); // => 'errors'
174
+ * pluralize(1, 'error', 'problem'); // => 'error'
175
+ * pluralize(2, 'error', 'problems'); // => 'problems'
176
+ * ```
177
+ */
178
+ export declare function pluralize(count: number, singular: string, plural?: string): string;
179
+ /**
180
+ * Get an object that can be used as fallback config for Webpack's
181
+ * `fallback` config.
182
+ *
183
+ * @param polyfills - The polyfill object from the snap config.
184
+ * @returns The webpack fallback config.
185
+ */
186
+ export declare function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {
187
+ [index: string]: string | false;
188
+ };