@metamask/snaps-cli 0.37.1-flask.1 → 0.38.0-flask.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.browserslistrc +3 -0
  2. package/CHANGELOG.md +20 -431
  3. package/README.md +539 -63
  4. package/dist/cjs/builders.js +40 -41
  5. package/dist/cjs/builders.js.map +1 -1
  6. package/dist/cjs/cli.js +14 -14
  7. package/dist/cjs/cli.js.map +1 -1
  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/{cmds → commands}/build/index.js +18 -5
  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.map +1 -0
  21. package/dist/cjs/commands/manifest/implementation.js +34 -0
  22. package/dist/cjs/commands/manifest/implementation.js.map +1 -0
  23. package/dist/cjs/commands/manifest/index.js +50 -0
  24. package/dist/cjs/commands/manifest/index.js.map +1 -0
  25. package/dist/cjs/commands/manifest/manifest.js +55 -0
  26. package/dist/cjs/commands/manifest/manifest.js.map +1 -0
  27. package/dist/cjs/{cmds → commands}/serve/index.js +4 -2
  28. package/dist/cjs/commands/serve/index.js.map +1 -0
  29. package/dist/cjs/commands/serve/serve.js +21 -0
  30. package/dist/cjs/commands/serve/serve.js.map +1 -0
  31. package/dist/cjs/commands/watch/implementation.js +35 -0
  32. package/dist/cjs/commands/watch/implementation.js.map +1 -0
  33. package/dist/cjs/{cmds → commands}/watch/index.js +19 -4
  34. package/dist/cjs/commands/watch/index.js.map +1 -0
  35. package/dist/cjs/commands/watch/watch.js +51 -0
  36. package/dist/cjs/commands/watch/watch.js.map +1 -0
  37. package/dist/cjs/config.js +290 -0
  38. package/dist/cjs/config.js.map +1 -0
  39. package/dist/cjs/errors.js +37 -0
  40. package/dist/cjs/errors.js.map +1 -0
  41. package/dist/cjs/index.js +28 -3
  42. package/dist/cjs/index.js.map +1 -1
  43. package/dist/cjs/main.js +6 -7
  44. package/dist/cjs/main.js.map +1 -1
  45. package/dist/cjs/utils/cli.js +61 -0
  46. package/dist/cjs/utils/cli.js.map +1 -0
  47. package/dist/cjs/utils/errors.js +42 -0
  48. package/dist/cjs/utils/errors.js.map +1 -0
  49. package/dist/cjs/utils/index.js +6 -2
  50. package/dist/cjs/utils/index.js.map +1 -1
  51. package/dist/cjs/utils/legacy.js +48 -0
  52. package/dist/cjs/utils/legacy.js.map +1 -0
  53. package/dist/cjs/utils/logging.js +46 -0
  54. package/dist/cjs/utils/logging.js.map +1 -0
  55. package/dist/cjs/utils/path.js +16 -0
  56. package/dist/cjs/utils/path.js.map +1 -0
  57. package/dist/cjs/utils/steps.js +52 -0
  58. package/dist/cjs/utils/steps.js.map +1 -0
  59. package/dist/cjs/webpack/compiler.js +96 -0
  60. package/dist/cjs/webpack/compiler.js.map +1 -0
  61. package/dist/cjs/webpack/config.js +234 -0
  62. package/dist/cjs/webpack/config.js.map +1 -0
  63. package/dist/cjs/webpack/index.js +22 -0
  64. package/dist/cjs/webpack/index.js.map +1 -0
  65. package/dist/cjs/webpack/loaders/browserify.js +97 -0
  66. package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
  67. package/dist/cjs/webpack/loaders/wasm.js +36 -0
  68. package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
  69. package/dist/cjs/webpack/plugins.js +340 -0
  70. package/dist/cjs/webpack/plugins.js.map +1 -0
  71. package/dist/cjs/webpack/utils.js +133 -0
  72. package/dist/cjs/webpack/utils.js.map +1 -0
  73. package/dist/esm/builders.js +40 -41
  74. package/dist/esm/builders.js.map +1 -1
  75. package/dist/esm/cli.js +15 -15
  76. package/dist/esm/cli.js.map +1 -1
  77. package/dist/esm/commands/build/build.js +51 -0
  78. package/dist/esm/commands/build/build.js.map +1 -0
  79. package/dist/esm/commands/build/implementation.js +27 -0
  80. package/dist/esm/commands/build/implementation.js.map +1 -0
  81. package/dist/esm/{cmds → commands}/build/index.js +5 -5
  82. package/dist/esm/commands/build/index.js.map +1 -0
  83. package/dist/esm/commands/eval/eval.js +54 -0
  84. package/dist/esm/commands/eval/eval.js.map +1 -0
  85. package/dist/esm/commands/eval/implementation.js +24 -0
  86. package/dist/esm/commands/eval/implementation.js.map +1 -0
  87. package/dist/esm/commands/eval/index.js +22 -0
  88. package/dist/esm/commands/eval/index.js.map +1 -0
  89. package/dist/esm/commands/index.js +15 -0
  90. package/dist/esm/commands/index.js.map +1 -0
  91. package/dist/esm/commands/manifest/implementation.js +33 -0
  92. package/dist/esm/commands/manifest/implementation.js.map +1 -0
  93. package/dist/esm/commands/manifest/index.js +22 -0
  94. package/dist/esm/commands/manifest/index.js.map +1 -0
  95. package/dist/esm/commands/manifest/manifest.js +52 -0
  96. package/dist/esm/commands/manifest/manifest.js.map +1 -0
  97. package/dist/esm/{cmds → commands}/serve/index.js +4 -2
  98. package/dist/esm/commands/serve/index.js.map +1 -0
  99. package/dist/esm/commands/serve/serve.js +17 -0
  100. package/dist/esm/commands/serve/serve.js.map +1 -0
  101. package/dist/esm/commands/watch/implementation.js +34 -0
  102. package/dist/esm/commands/watch/implementation.js.map +1 -0
  103. package/dist/esm/{cmds → commands}/watch/index.js +6 -4
  104. package/dist/esm/commands/watch/index.js.map +1 -0
  105. package/dist/esm/commands/watch/watch.js +50 -0
  106. package/dist/esm/commands/watch/watch.js.map +1 -0
  107. package/dist/esm/config.js +294 -0
  108. package/dist/esm/config.js.map +1 -0
  109. package/dist/esm/errors.js +30 -0
  110. package/dist/esm/errors.js.map +1 -0
  111. package/dist/esm/index.js +3 -0
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/main.js +6 -7
  114. package/dist/esm/main.js.map +1 -1
  115. package/dist/esm/utils/cli.js +43 -0
  116. package/dist/esm/utils/cli.js.map +1 -0
  117. package/dist/esm/utils/errors.js +43 -0
  118. package/dist/esm/utils/errors.js.map +1 -0
  119. package/dist/esm/utils/index.js +6 -2
  120. package/dist/esm/utils/index.js.map +1 -1
  121. package/dist/esm/utils/legacy.js +47 -0
  122. package/dist/esm/utils/legacy.js.map +1 -0
  123. package/dist/esm/utils/logging.js +40 -0
  124. package/dist/esm/utils/logging.js.map +1 -0
  125. package/dist/esm/utils/path.js +13 -0
  126. package/dist/esm/utils/path.js.map +1 -0
  127. package/dist/esm/utils/steps.js +43 -0
  128. package/dist/esm/utils/steps.js.map +1 -0
  129. package/dist/esm/webpack/compiler.js +89 -0
  130. package/dist/esm/webpack/compiler.js.map +1 -0
  131. package/dist/esm/webpack/config.js +236 -0
  132. package/dist/esm/webpack/config.js.map +1 -0
  133. package/dist/esm/webpack/index.js +5 -0
  134. package/dist/esm/webpack/index.js.map +1 -0
  135. package/dist/esm/webpack/loaders/browserify.js +82 -0
  136. package/dist/esm/webpack/loaders/browserify.js.map +1 -0
  137. package/dist/esm/webpack/loaders/wasm.js +26 -0
  138. package/dist/esm/webpack/loaders/wasm.js.map +1 -0
  139. package/dist/esm/webpack/plugins.js +343 -0
  140. package/dist/esm/webpack/plugins.js.map +1 -0
  141. package/dist/esm/webpack/utils.js +160 -0
  142. package/dist/esm/webpack/utils.js.map +1 -0
  143. package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
  144. package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
  145. package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
  146. package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
  147. package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
  148. package/dist/types/builders.d.ts +2 -21
  149. package/dist/types/cli.d.ts +1 -1
  150. package/dist/types/commands/build/build.d.ts +10 -0
  151. package/dist/types/commands/build/implementation.d.ts +10 -0
  152. package/dist/types/{cmds/eval → commands/build}/index.d.ts +1 -0
  153. package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
  154. package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
  155. package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
  156. package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
  157. package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
  158. package/dist/types/commands/eval/eval.d.ts +14 -0
  159. package/dist/types/commands/eval/implementation.d.ts +9 -0
  160. package/dist/types/{cmds/serve → commands/eval}/index.d.ts +1 -0
  161. package/dist/types/commands/manifest/implementation.d.ts +12 -0
  162. package/dist/types/{cmds → commands}/manifest/index.d.ts +1 -0
  163. package/dist/types/commands/manifest/manifest.d.ts +14 -0
  164. package/dist/types/commands/serve/serve.d.ts +16 -0
  165. package/dist/types/commands/watch/implementation.d.ts +14 -0
  166. package/dist/types/commands/watch/index.d.ts +10 -0
  167. package/dist/types/commands/watch/watch.d.ts +19 -0
  168. package/dist/types/config.d.ts +626 -0
  169. package/dist/types/errors.d.ts +25 -0
  170. package/dist/types/index.d.ts +4 -0
  171. package/dist/types/utils/cli.d.ts +17 -0
  172. package/dist/types/utils/errors.d.ts +23 -0
  173. package/dist/types/utils/index.d.ts +6 -2
  174. package/dist/types/utils/legacy.d.ts +27 -0
  175. package/dist/types/utils/logging.d.ts +22 -0
  176. package/dist/types/utils/path.d.ts +9 -0
  177. package/dist/types/utils/steps.d.ts +17 -0
  178. package/dist/types/webpack/compiler.d.ts +29 -0
  179. package/dist/types/webpack/config.d.ts +37 -0
  180. package/dist/types/webpack/index.d.ts +3 -0
  181. package/dist/types/webpack/loaders/browserify.d.ts +16 -0
  182. package/dist/types/webpack/loaders/wasm.d.ts +20 -0
  183. package/dist/types/webpack/plugins.d.ts +147 -0
  184. package/dist/types/webpack/utils.d.ts +156 -0
  185. package/package.json +15 -7
  186. package/dist/cjs/cmds/build/buildHandler.js +0 -36
  187. package/dist/cjs/cmds/build/buildHandler.js.map +0 -1
  188. package/dist/cjs/cmds/build/bundle.js +0 -83
  189. package/dist/cjs/cmds/build/bundle.js.map +0 -1
  190. package/dist/cjs/cmds/build/index.js.map +0 -1
  191. package/dist/cjs/cmds/build/utils.js +0 -79
  192. package/dist/cjs/cmds/build/utils.js.map +0 -1
  193. package/dist/cjs/cmds/eval/evalHandler.js +0 -24
  194. package/dist/cjs/cmds/eval/evalHandler.js.map +0 -1
  195. package/dist/cjs/cmds/eval/index.js +0 -31
  196. package/dist/cjs/cmds/eval/index.js.map +0 -1
  197. package/dist/cjs/cmds/index.js.map +0 -1
  198. package/dist/cjs/cmds/manifest/index.js +0 -44
  199. package/dist/cjs/cmds/manifest/index.js.map +0 -1
  200. package/dist/cjs/cmds/manifest/manifestHandler.js +0 -47
  201. package/dist/cjs/cmds/manifest/manifestHandler.js.map +0 -1
  202. package/dist/cjs/cmds/serve/index.js.map +0 -1
  203. package/dist/cjs/cmds/serve/serveHandler.js +0 -62
  204. package/dist/cjs/cmds/serve/serveHandler.js.map +0 -1
  205. package/dist/cjs/cmds/serve/serveUtils.js +0 -37
  206. package/dist/cjs/cmds/serve/serveUtils.js.map +0 -1
  207. package/dist/cjs/cmds/watch/index.js.map +0 -1
  208. package/dist/cjs/cmds/watch/watchHandler.js +0 -91
  209. package/dist/cjs/cmds/watch/watchHandler.js.map +0 -1
  210. package/dist/cjs/utils/misc.js +0 -142
  211. package/dist/cjs/utils/misc.js.map +0 -1
  212. package/dist/cjs/utils/snap-config.js +0 -104
  213. package/dist/cjs/utils/snap-config.js.map +0 -1
  214. package/dist/esm/cmds/build/buildHandler.js +0 -36
  215. package/dist/esm/cmds/build/buildHandler.js.map +0 -1
  216. package/dist/esm/cmds/build/bundle.js +0 -81
  217. package/dist/esm/cmds/build/bundle.js.map +0 -1
  218. package/dist/esm/cmds/build/index.js.map +0 -1
  219. package/dist/esm/cmds/build/utils.js +0 -88
  220. package/dist/esm/cmds/build/utils.js.map +0 -1
  221. package/dist/esm/cmds/eval/evalHandler.js +0 -20
  222. package/dist/esm/cmds/eval/evalHandler.js.map +0 -1
  223. package/dist/esm/cmds/eval/index.js +0 -16
  224. package/dist/esm/cmds/eval/index.js.map +0 -1
  225. package/dist/esm/cmds/index.js +0 -15
  226. package/dist/esm/cmds/index.js.map +0 -1
  227. package/dist/esm/cmds/manifest/index.js +0 -29
  228. package/dist/esm/cmds/manifest/index.js.map +0 -1
  229. package/dist/esm/cmds/manifest/manifestHandler.js +0 -44
  230. package/dist/esm/cmds/manifest/manifestHandler.js.map +0 -1
  231. package/dist/esm/cmds/serve/index.js.map +0 -1
  232. package/dist/esm/cmds/serve/serveHandler.js +0 -54
  233. package/dist/esm/cmds/serve/serveHandler.js.map +0 -1
  234. package/dist/esm/cmds/serve/serveUtils.js +0 -30
  235. package/dist/esm/cmds/serve/serveUtils.js.map +0 -1
  236. package/dist/esm/cmds/watch/index.js.map +0 -1
  237. package/dist/esm/cmds/watch/watchHandler.js +0 -87
  238. package/dist/esm/cmds/watch/watchHandler.js.map +0 -1
  239. package/dist/esm/utils/misc.js +0 -139
  240. package/dist/esm/utils/misc.js.map +0 -1
  241. package/dist/esm/utils/snap-config.js +0 -107
  242. package/dist/esm/utils/snap-config.js.map +0 -1
  243. package/dist/types/cmds/build/buildHandler.d.ts +0 -13
  244. package/dist/types/cmds/build/bundle.d.ts +0 -15
  245. package/dist/types/cmds/build/utils.d.ts +0 -56
  246. package/dist/types/cmds/eval/evalHandler.d.ts +0 -9
  247. package/dist/types/cmds/manifest/manifestHandler.d.ts +0 -10
  248. package/dist/types/cmds/serve/serveHandler.d.ts +0 -10
  249. package/dist/types/cmds/serve/serveUtils.d.ts +0 -22
  250. package/dist/types/cmds/watch/index.d.ts +0 -9
  251. package/dist/types/cmds/watch/watchHandler.d.ts +0 -14
  252. package/dist/types/utils/misc.d.ts +0 -53
  253. package/dist/types/utils/snap-config.d.ts +0 -48
  254. /package/dist/cjs/{cmds → commands}/index.js +0 -0
  255. /package/dist/types/{cmds → commands}/index.d.ts +0 -0
  256. /package/dist/types/{cmds/build → commands/serve}/index.d.ts +0 -0
@@ -0,0 +1,30 @@
1
+ import { bold, red } from 'chalk';
2
+ /**
3
+ * An error that is thrown when the CLI fails. This is the base error for all
4
+ * CLI errors. It is not thrown directly, but is instead extended by other
5
+ * errors.
6
+ *
7
+ * This error is assumed to have all the information needed to display a
8
+ * readable error message, so it does not include the stack trace when it is
9
+ * thrown.
10
+ */ export 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
+ */ export class CommandError extends CLIError {
17
+ constructor(message, name = 'Error'){
18
+ super(message);
19
+ this.name = bold(red(name));
20
+ }
21
+ }
22
+ /**
23
+ * An error that is thrown when the config file cannot be loaded.
24
+ */ export class ConfigError extends CommandError {
25
+ constructor(message){
26
+ super(message, 'Config Error');
27
+ }
28
+ }
29
+
30
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors.ts"],"sourcesContent":["import { bold, red } from 'chalk';\n\n/**\n * An error that is thrown when the CLI fails. This is the base error for all\n * CLI errors. It is not thrown directly, but is instead extended by other\n * errors.\n *\n * This error is assumed to have all the information needed to display a\n * readable error message, so it does not include the stack trace when it is\n * thrown.\n */\nexport class CLIError extends Error {}\n\n/**\n * An error that is thrown when a command fails.\n *\n * It wraps the error prefix in a bold red \"Error\" string.\n */\nexport class CommandError extends CLIError {\n constructor(message: string, name = 'Error') {\n super(message);\n this.name = bold(red(name));\n }\n}\n\n/**\n * An error that is thrown when the config file cannot be loaded.\n */\nexport class ConfigError extends CommandError {\n constructor(message: string) {\n super(message, 'Config Error');\n }\n}\n"],"names":["bold","red","CLIError","Error","CommandError","constructor","message","name","ConfigError"],"mappings":"AAAA,SAASA,IAAI,EAAEC,GAAG,QAAQ,QAAQ;AAElC;;;;;;;;CAQC,GACD,OAAO,MAAMC,iBAAiBC;AAAO;AAErC;;;;CAIC,GACD,OAAO,MAAMC,qBAAqBF;IAChCG,YAAYC,OAAe,EAAEC,OAAO,OAAO,CAAE;QAC3C,KAAK,CAACD;QACN,IAAI,CAACC,IAAI,GAAGP,KAAKC,IAAIM;IACvB;AACF;AAEA;;CAEC,GACD,OAAO,MAAMC,oBAAoBJ;IAC/BC,YAAYC,OAAe,CAAE;QAC3B,KAAK,CAACA,SAAS;IACjB;AACF"}
package/dist/esm/index.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export * as utils from './utils';
2
+ export { getDefaultConfiguration, SnapsStatsPlugin, SnapsWatchPlugin, SnapsBuiltInResolver, SnapsBundleWarningsPlugin } from './webpack';
3
+ // Re-exported from `snaps-cli` for convenience.
4
+ export { merge } from 'webpack-merge';
2
5
 
3
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * as utils from './utils';\n"],"names":["utils"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,UAAU"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * as utils from './utils';\nexport type { SnapConfig } from './config';\nexport {\n getDefaultConfiguration,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n} from './webpack';\nexport type {\n SnapsStatsPluginOptions,\n SnapsWatchPluginOptions,\n SnapsBuiltInResolverOptions,\n SnapsBundleWarningsPluginOptions,\n} from './webpack';\n\n// Re-exported from `snaps-cli` for convenience.\nexport { merge } from 'webpack-merge';\n"],"names":["utils","getDefaultConfiguration","SnapsStatsPlugin","SnapsWatchPlugin","SnapsBuiltInResolver","SnapsBundleWarningsPlugin","merge"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,UAAU;AAEjC,SACEC,uBAAuB,EACvBC,gBAAgB,EAChBC,gBAAgB,EAChBC,oBAAoB,EACpBC,yBAAyB,QACpB,YAAY;AAQnB,gDAAgD;AAChD,SAASC,KAAK,QAAQ,gBAAgB"}
package/dist/esm/main.js CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
+ import { logError } from '@metamask/snaps-utils';
2
3
  import { cli } from './cli';
3
- import commands from './cmds';
4
- global.snaps = {
5
- verboseErrors: false,
6
- suppressWarnings: false,
7
- isWatching: false
8
- };
9
- cli(process.argv, commands);
4
+ import commands from './commands';
5
+ cli(process.argv, commands).catch((error)=>{
6
+ logError(error);
7
+ process.exitCode = 1;
8
+ });
10
9
 
11
10
  //# sourceMappingURL=main.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/main.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { cli } from './cli';\nimport commands from './cmds';\n\nglobal.snaps = {\n verboseErrors: false,\n suppressWarnings: false,\n isWatching: false,\n};\n\ncli(process.argv, commands);\n"],"names":["cli","commands","global","snaps","verboseErrors","suppressWarnings","isWatching","process","argv"],"mappings":";AACA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,OAAOC,cAAc,SAAS;AAE9BC,OAAOC,KAAK,GAAG;IACbC,eAAe;IACfC,kBAAkB;IAClBC,YAAY;AACd;AAEAN,IAAIO,QAAQC,IAAI,EAAEP"}
1
+ {"version":3,"sources":["../../src/main.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { logError } from '@metamask/snaps-utils';\n\nimport { cli } from './cli';\nimport commands from './commands';\n\ncli(process.argv, commands).catch((error) => {\n logError(error);\n process.exitCode = 1;\n});\n"],"names":["logError","cli","commands","process","argv","catch","error","exitCode"],"mappings":";AAEA,SAASA,QAAQ,QAAQ,wBAAwB;AAEjD,SAASC,GAAG,QAAQ,QAAQ;AAC5B,OAAOC,cAAc,aAAa;AAElCD,IAAIE,QAAQC,IAAI,EAAEF,UAAUG,KAAK,CAAC,CAACC;IACjCN,SAASM;IACTH,QAAQI,QAAQ,GAAG;AACrB"}
@@ -0,0 +1,43 @@
1
+ import path from 'path';
2
+ export const CONFIG_FILE = 'snap.config.js';
3
+ export const TS_CONFIG_FILE = 'snap.config.ts';
4
+ // CLI arguments whose values are file paths.
5
+ const pathArguments = new Set([
6
+ 'src',
7
+ 's',
8
+ 'dist',
9
+ 'd',
10
+ 'bundle',
11
+ 'b',
12
+ 'root',
13
+ 'r'
14
+ ]);
15
+ /**
16
+ * Sanitizes inputs. Currently normalizes "./" paths to ".".
17
+ * Yargs handles other path normalization as specified in builders.
18
+ *
19
+ * @param argv - Arguments as an object generated by yargs.
20
+ */ export function sanitizeInputs(argv) {
21
+ Object.keys(argv).forEach((key)=>{
22
+ if (typeof argv[key] === 'string') {
23
+ // Node's path.normalize() does not do this
24
+ if (argv[key] === './') {
25
+ argv[key] = '.';
26
+ }
27
+ if (pathArguments.has(key)) {
28
+ argv[key] = path.normalize(argv[key]);
29
+ }
30
+ }
31
+ });
32
+ }
33
+ /**
34
+ * Trims leading and trailing periods "." and forward slashes "/" from the
35
+ * given path string.
36
+ *
37
+ * @param pathString - The path string to trim.
38
+ * @returns The trimmed path string.
39
+ */ export function trimPathString(pathString) {
40
+ return pathString.replace(/^[./]+|[./]+$/gu, '');
41
+ }
42
+
43
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/cli.ts"],"sourcesContent":["import path from 'path';\n\nexport const CONFIG_FILE = 'snap.config.js';\nexport const TS_CONFIG_FILE = 'snap.config.ts';\n\n// CLI arguments whose values are file paths.\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Record<string, unknown>) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"],"names":["path","CONFIG_FILE","TS_CONFIG_FILE","pathArguments","Set","sanitizeInputs","argv","Object","keys","forEach","key","has","normalize","trimPathString","pathString","replace"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AAExB,OAAO,MAAMC,cAAc,iBAAiB;AAC5C,OAAO,MAAMC,iBAAiB,iBAAiB;AAE/C,6CAA6C;AAC7C,MAAMC,gBAAgB,IAAIC,IAAI;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;CAKC,GACD,OAAO,SAASC,eAAeC,IAA6B;IAC1DC,OAAOC,IAAI,CAACF,MAAMG,OAAO,CAAC,CAACC;QACzB,IAAI,OAAOJ,IAAI,CAACI,IAAI,KAAK,UAAU;YACjC,2CAA2C;YAC3C,IAAIJ,IAAI,CAACI,IAAI,KAAK,MAAM;gBACtBJ,IAAI,CAACI,IAAI,GAAG;YACd;YAEA,IAAIP,cAAcQ,GAAG,CAACD,MAAM;gBAC1BJ,IAAI,CAACI,IAAI,GAAGV,KAAKY,SAAS,CAACN,IAAI,CAACI,IAAI;YACtC;QACF;IACF;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASG,eAAeC,UAAkB;IAC/C,OAAOA,WAAWC,OAAO,CAAC,mBAAmB;AAC/C"}
@@ -0,0 +1,43 @@
1
+ import { hasProperty, isObject } from '@metamask/utils';
2
+ import { CLIError } from '../errors';
3
+ /**
4
+ * Get the error message from an error in a Yargs `fail` handler. If the error
5
+ * is not `undefined`, {@link getErrorMessage} is used to get the error message.
6
+ * Otherwise, the given message is returned.
7
+ *
8
+ * @param message - The error message.
9
+ * @param error - The error object. This may be `undefined`.
10
+ * @returns The error message.
11
+ */ export function getYargsErrorMessage(message, error) {
12
+ if (error) {
13
+ if (error instanceof CLIError) {
14
+ return error.message;
15
+ }
16
+ return getErrorMessage(error);
17
+ }
18
+ return message;
19
+ }
20
+ /**
21
+ * Get the error message from an error.
22
+ *
23
+ * - If the error is an object with a `stack` property, the `stack` property is
24
+ * returned.
25
+ * - If the error is an object with a `message` property, the `message`
26
+ * property is returned.
27
+ * - Otherwise, the error is converted to a string and returned.
28
+ *
29
+ * @param error - The error to get the message from.
30
+ * @returns The error message.
31
+ */ export function getErrorMessage(error) {
32
+ if (isObject(error)) {
33
+ if (hasProperty(error, 'stack') && typeof error.stack === 'string') {
34
+ return error.stack;
35
+ }
36
+ if (hasProperty(error, 'message') && typeof error.message === 'string') {
37
+ return error.message;
38
+ }
39
+ }
40
+ return String(error);
41
+ }
42
+
43
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/errors.ts"],"sourcesContent":["import { hasProperty, isObject } from '@metamask/utils';\n\nimport { CLIError } from '../errors';\n\n/**\n * Get the error message from an error in a Yargs `fail` handler. If the error\n * is not `undefined`, {@link getErrorMessage} is used to get the error message.\n * Otherwise, the given message is returned.\n *\n * @param message - The error message.\n * @param error - The error object. This may be `undefined`.\n * @returns The error message.\n */\nexport function getYargsErrorMessage(message: string, error?: unknown): string {\n if (error) {\n if (error instanceof CLIError) {\n return error.message;\n }\n\n return getErrorMessage(error);\n }\n\n return message;\n}\n\n/**\n * Get the error message from an error.\n *\n * - If the error is an object with a `stack` property, the `stack` property is\n * returned.\n * - If the error is an object with a `message` property, the `message`\n * property is returned.\n * - Otherwise, the error is converted to a string and returned.\n *\n * @param error - The error to get the message from.\n * @returns The error message.\n */\nexport function getErrorMessage(error: unknown): string {\n if (isObject(error)) {\n if (hasProperty(error, 'stack') && typeof error.stack === 'string') {\n return error.stack;\n }\n\n if (hasProperty(error, 'message') && typeof error.message === 'string') {\n return error.message;\n }\n }\n\n return String(error);\n}\n"],"names":["hasProperty","isObject","CLIError","getYargsErrorMessage","message","error","getErrorMessage","stack","String"],"mappings":"AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,kBAAkB;AAExD,SAASC,QAAQ,QAAQ,YAAY;AAErC;;;;;;;;CAQC,GACD,OAAO,SAASC,qBAAqBC,OAAe,EAAEC,KAAe;IACnE,IAAIA,OAAO;QACT,IAAIA,iBAAiBH,UAAU;YAC7B,OAAOG,MAAMD,OAAO;QACtB;QAEA,OAAOE,gBAAgBD;IACzB;IAEA,OAAOD;AACT;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASE,gBAAgBD,KAAc;IAC5C,IAAIJ,SAASI,QAAQ;QACnB,IAAIL,YAAYK,OAAO,YAAY,OAAOA,MAAME,KAAK,KAAK,UAAU;YAClE,OAAOF,MAAME,KAAK;QACpB;QAEA,IAAIP,YAAYK,OAAO,cAAc,OAAOA,MAAMD,OAAO,KAAK,UAAU;YACtE,OAAOC,MAAMD,OAAO;QACtB;IACF;IAEA,OAAOI,OAAOH;AAChB"}
@@ -1,4 +1,8 @@
1
- export * from './misc';
2
- export * from './snap-config';
1
+ export * from './cli';
2
+ export * from './errors';
3
+ export * from './legacy';
4
+ export * from './logging';
5
+ export * from './path';
6
+ export * from './steps';
3
7
 
4
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/index.ts"],"sourcesContent":["export * from './misc';\nexport * from './snap-config';\n"],"names":[],"mappings":"AAAA,cAAc,SAAS;AACvB,cAAc,gBAAgB"}
1
+ {"version":3,"sources":["../../../src/utils/index.ts"],"sourcesContent":["export * from './cli';\nexport * from './errors';\nexport * from './legacy';\nexport * from './logging';\nexport * from './path';\nexport * from './steps';\n"],"names":[],"mappings":"AAAA,cAAc,QAAQ;AACtB,cAAc,WAAW;AACzB,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,UAAU"}
@@ -0,0 +1,47 @@
1
+ import { TranspilationModes } from '../builders';
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
+ */ export function processDependencies(config) {
12
+ const { depsToTranspile, transpilationMode } = config;
13
+ if (transpilationMode === TranspilationModes.LocalAndDeps) {
14
+ const regex = getDependencyRegExp(depsToTranspile);
15
+ if (regex !== null) {
16
+ return [
17
+ regex
18
+ ];
19
+ }
20
+ }
21
+ return [];
22
+ }
23
+ /**
24
+ * Processes a string of space delimited dependencies into one RegExp string.
25
+ *
26
+ * @param dependencies - An array of dependencies to add to the RegExp.
27
+ * @returns A RegExp object.
28
+ */ export function getDependencyRegExp(dependencies) {
29
+ if (!dependencies || dependencies.includes('.') || !dependencies.length) {
30
+ return null;
31
+ }
32
+ const paths = sanitizeDependencyPaths(dependencies);
33
+ return RegExp(`/node_modules/(?!${paths.join('|')})`, 'u');
34
+ }
35
+ /**
36
+ * Helper function to remove any leading and trailing slashes from dependency
37
+ * list.
38
+ *
39
+ * @param dependencies - An array of dependencies to sanitize.
40
+ * @returns An array of sanitized paths.
41
+ */ export function sanitizeDependencyPaths(dependencies) {
42
+ return dependencies.map((dependency)=>{
43
+ return dependency.replace(/^[/\\]+/u, '').replace(/[/\\]+$/u, '');
44
+ });
45
+ }
46
+
47
+ //# sourceMappingURL=legacy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/legacy.ts"],"sourcesContent":["import { TranspilationModes } from '../builders';\nimport type { LegacyOptions } from '../config';\n\n/**\n * Get the dependencies to transpile, as well as the regular input file.\n *\n * If `transpilationMode` is not set to `localAndDeps`, this will return an\n * empty array.\n *\n * @param config - The config object.\n * @returns An array with regular expressions of dependencies that should be\n * transpiled.\n */\nexport function processDependencies(config: LegacyOptions) {\n const { depsToTranspile, transpilationMode } = config;\n if (transpilationMode === TranspilationModes.LocalAndDeps) {\n const regex = getDependencyRegExp(depsToTranspile);\n if (regex !== null) {\n return [regex];\n }\n }\n\n return [];\n}\n\n/**\n * Processes a string of space delimited dependencies into one RegExp string.\n *\n * @param dependencies - An array of dependencies to add to the RegExp.\n * @returns A RegExp object.\n */\nexport function getDependencyRegExp(dependencies: string[]): RegExp | null {\n if (!dependencies || dependencies.includes('.') || !dependencies.length) {\n return null;\n }\n\n const paths: string[] = sanitizeDependencyPaths(dependencies);\n return RegExp(`/node_modules/(?!${paths.join('|')})`, 'u');\n}\n\n/**\n * Helper function to remove any leading and trailing slashes from dependency\n * list.\n *\n * @param dependencies - An array of dependencies to sanitize.\n * @returns An array of sanitized paths.\n */\nexport function sanitizeDependencyPaths(dependencies: string[]): string[] {\n return dependencies.map((dependency) => {\n return dependency.replace(/^[/\\\\]+/u, '').replace(/[/\\\\]+$/u, '');\n });\n}\n"],"names":["TranspilationModes","processDependencies","config","depsToTranspile","transpilationMode","LocalAndDeps","regex","getDependencyRegExp","dependencies","includes","length","paths","sanitizeDependencyPaths","RegExp","join","map","dependency","replace"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,cAAc;AAGjD;;;;;;;;;CASC,GACD,OAAO,SAASC,oBAAoBC,MAAqB;IACvD,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAE,GAAGF;IAC/C,IAAIE,sBAAsBJ,mBAAmBK,YAAY,EAAE;QACzD,MAAMC,QAAQC,oBAAoBJ;QAClC,IAAIG,UAAU,MAAM;YAClB,OAAO;gBAACA;aAAM;QAChB;IACF;IAEA,OAAO,EAAE;AACX;AAEA;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,YAAsB;IACxD,IAAI,CAACA,gBAAgBA,aAAaC,QAAQ,CAAC,QAAQ,CAACD,aAAaE,MAAM,EAAE;QACvE,OAAO;IACT;IAEA,MAAMC,QAAkBC,wBAAwBJ;IAChD,OAAOK,OAAO,CAAC,iBAAiB,EAAEF,MAAMG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;AACxD;AAEA;;;;;;CAMC,GACD,OAAO,SAASF,wBAAwBJ,YAAsB;IAC5D,OAAOA,aAAaO,GAAG,CAAC,CAACC;QACvB,OAAOA,WAAWC,OAAO,CAAC,YAAY,IAAIA,OAAO,CAAC,YAAY;IAChE;AACF"}
@@ -0,0 +1,40 @@
1
+ import { logError, logInfo, logWarning } from '@metamask/snaps-utils';
2
+ import { blue, dim, red, yellow } from 'chalk';
3
+ /**
4
+ * Log a warning message. The message is prefixed with "Warning:".
5
+ *
6
+ * @param message - The message to log.
7
+ * @param spinner - The spinner to clear.
8
+ */ export function warn(message, spinner) {
9
+ if (spinner) {
10
+ spinner.clear();
11
+ spinner.frame();
12
+ }
13
+ logWarning(`${yellow('⚠')} ${message}`);
14
+ }
15
+ /**
16
+ * Log an info message.
17
+ *
18
+ * @param message - The message to log.
19
+ * @param spinner - The spinner to clear.
20
+ */ export function info(message, spinner) {
21
+ if (spinner) {
22
+ spinner.clear();
23
+ spinner.frame();
24
+ }
25
+ logInfo(`${blue('ℹ')} ${dim(message)}`);
26
+ }
27
+ /**
28
+ * Log an error message. The message is prefixed with "Error:".
29
+ *
30
+ * @param message - The message to log.
31
+ * @param spinner - The spinner to clear.
32
+ */ export function error(message, spinner) {
33
+ if (spinner) {
34
+ spinner.clear();
35
+ spinner.frame();
36
+ }
37
+ logError(`${red('✖')} ${message}`);
38
+ }
39
+
40
+ //# sourceMappingURL=logging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/logging.ts"],"sourcesContent":["import { logError, logInfo, logWarning } from '@metamask/snaps-utils';\nimport { blue, dim, red, yellow } from 'chalk';\nimport type { Ora } from 'ora';\n\n/**\n * Log a warning message. The message is prefixed with \"Warning:\".\n *\n * @param message - The message to log.\n * @param spinner - The spinner to clear.\n */\nexport function warn(message: string, spinner?: Ora) {\n if (spinner) {\n spinner.clear();\n spinner.frame();\n }\n\n logWarning(`${yellow('⚠')} ${message}`);\n}\n\n/**\n * Log an info message.\n *\n * @param message - The message to log.\n * @param spinner - The spinner to clear.\n */\nexport function info(message: string, spinner?: Ora) {\n if (spinner) {\n spinner.clear();\n spinner.frame();\n }\n\n logInfo(`${blue('ℹ')} ${dim(message)}`);\n}\n\n/**\n * Log an error message. The message is prefixed with \"Error:\".\n *\n * @param message - The message to log.\n * @param spinner - The spinner to clear.\n */\nexport function error(message: string, spinner?: Ora) {\n if (spinner) {\n spinner.clear();\n spinner.frame();\n }\n\n logError(`${red('✖')} ${message}`);\n}\n"],"names":["logError","logInfo","logWarning","blue","dim","red","yellow","warn","message","spinner","clear","frame","info","error"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,UAAU,QAAQ,wBAAwB;AACtE,SAASC,IAAI,EAAEC,GAAG,EAAEC,GAAG,EAAEC,MAAM,QAAQ,QAAQ;AAG/C;;;;;CAKC,GACD,OAAO,SAASC,KAAKC,OAAe,EAAEC,OAAa;IACjD,IAAIA,SAAS;QACXA,QAAQC,KAAK;QACbD,QAAQE,KAAK;IACf;IAEAT,WAAW,CAAC,EAAEI,OAAO,KAAK,CAAC,EAAEE,QAAQ,CAAC;AACxC;AAEA;;;;;CAKC,GACD,OAAO,SAASI,KAAKJ,OAAe,EAAEC,OAAa;IACjD,IAAIA,SAAS;QACXA,QAAQC,KAAK;QACbD,QAAQE,KAAK;IACf;IAEAV,QAAQ,CAAC,EAAEE,KAAK,KAAK,CAAC,EAAEC,IAAII,SAAS,CAAC;AACxC;AAEA;;;;;CAKC,GACD,OAAO,SAASK,MAAML,OAAe,EAAEC,OAAa;IAClD,IAAIA,SAAS;QACXA,QAAQC,KAAK;QACbD,QAAQE,KAAK;IACf;IAEAX,SAAS,CAAC,EAAEK,IAAI,KAAK,CAAC,EAAEG,QAAQ,CAAC;AACnC"}
@@ -0,0 +1,13 @@
1
+ import { relative } from 'path';
2
+ /**
3
+ * Get the relative path from the current working directory to the given
4
+ * absolute path.
5
+ *
6
+ * @param absolutePath - The absolute path.
7
+ * @param cwd - The current working directory. Defaults to `process.cwd()`.
8
+ * @returns The relative path.
9
+ */ export function getRelativePath(absolutePath, cwd = process.cwd()) {
10
+ return relative(cwd, absolutePath);
11
+ }
12
+
13
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/path.ts"],"sourcesContent":["import { relative } from 'path';\n\n/**\n * Get the relative path from the current working directory to the given\n * absolute path.\n *\n * @param absolutePath - The absolute path.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The relative path.\n */\nexport function getRelativePath(absolutePath: string, cwd = process.cwd()) {\n return relative(cwd, absolutePath);\n}\n"],"names":["relative","getRelativePath","absolutePath","cwd","process"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,OAAO;AAEhC;;;;;;;CAOC,GACD,OAAO,SAASC,gBAAgBC,YAAoB,EAAEC,MAAMC,QAAQD,GAAG,EAAE;IACvE,OAAOH,SAASG,KAAKD;AACvB"}
@@ -0,0 +1,43 @@
1
+ import { dim } from 'chalk';
2
+ import createSpinner from 'ora';
3
+ import { getErrorMessage } from './errors';
4
+ import { error } from './logging';
5
+ /**
6
+ * Execute a list of steps in series. Each step receives the context object and
7
+ * a spinner instance.
8
+ *
9
+ * @param steps - The steps to execute.
10
+ * @param context - The context object that will be passed to each step.
11
+ */ export async function executeSteps(steps, context) {
12
+ const spinner = createSpinner({
13
+ // Ora writes to `process.stderr` by default.
14
+ stream: process.stdout
15
+ });
16
+ spinner.start();
17
+ try {
18
+ for (const step of steps){
19
+ // If the step has a condition, and it returns false, we skip the step.
20
+ if (step.condition && !step.condition(context)) {
21
+ continue;
22
+ }
23
+ // Calling `start` here instead of setting `spinner.text` seems to work
24
+ // better when the process doesn't have a TTY.
25
+ spinner.start(dim(step.name));
26
+ await step.task({
27
+ ...context,
28
+ spinner
29
+ });
30
+ }
31
+ // The spinner may have been stopped by a step, so we only succeed if it's
32
+ // still spinning.
33
+ if (spinner.isSpinning) {
34
+ spinner.succeed('Done!');
35
+ }
36
+ } catch (_error) {
37
+ error(getErrorMessage(_error), spinner);
38
+ spinner.stop();
39
+ process.exitCode = 1;
40
+ }
41
+ }
42
+
43
+ //# sourceMappingURL=steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/steps.ts"],"sourcesContent":["import { dim } from 'chalk';\nimport type { Ora } from 'ora';\nimport createSpinner from 'ora';\n\nimport { getErrorMessage } from './errors';\nimport { error } from './logging';\n\nexport type Step<Context extends Record<string, unknown>> = {\n name: string;\n condition?: (context: Context) => boolean;\n task: (context: Context & { spinner: Ora }) => Promise<void>;\n};\n\nexport type Steps<Context extends Record<string, unknown>> = Readonly<\n Step<Context>[]\n>;\n\n/**\n * Execute a list of steps in series. Each step receives the context object and\n * a spinner instance.\n *\n * @param steps - The steps to execute.\n * @param context - The context object that will be passed to each step.\n */\nexport async function executeSteps<Context extends Record<string, unknown>>(\n steps: Steps<Context>,\n context: Context,\n) {\n const spinner = createSpinner({\n // Ora writes to `process.stderr` by default.\n stream: process.stdout,\n });\n\n spinner.start();\n\n try {\n for (const step of steps) {\n // If the step has a condition, and it returns false, we skip the step.\n if (step.condition && !step.condition(context)) {\n continue;\n }\n\n // Calling `start` here instead of setting `spinner.text` seems to work\n // better when the process doesn't have a TTY.\n spinner.start(dim(step.name));\n\n await step.task({\n ...context,\n spinner,\n });\n }\n\n // The spinner may have been stopped by a step, so we only succeed if it's\n // still spinning.\n if (spinner.isSpinning) {\n spinner.succeed('Done!');\n }\n } catch (_error) {\n error(getErrorMessage(_error), spinner);\n spinner.stop();\n process.exitCode = 1;\n }\n}\n"],"names":["dim","createSpinner","getErrorMessage","error","executeSteps","steps","context","spinner","stream","process","stdout","start","step","condition","name","task","isSpinning","succeed","_error","stop","exitCode"],"mappings":"AAAA,SAASA,GAAG,QAAQ,QAAQ;AAE5B,OAAOC,mBAAmB,MAAM;AAEhC,SAASC,eAAe,QAAQ,WAAW;AAC3C,SAASC,KAAK,QAAQ,YAAY;AAYlC;;;;;;CAMC,GACD,OAAO,eAAeC,aACpBC,KAAqB,EACrBC,OAAgB;IAEhB,MAAMC,UAAUN,cAAc;QAC5B,6CAA6C;QAC7CO,QAAQC,QAAQC,MAAM;IACxB;IAEAH,QAAQI,KAAK;IAEb,IAAI;QACF,KAAK,MAAMC,QAAQP,MAAO;YACxB,uEAAuE;YACvE,IAAIO,KAAKC,SAAS,IAAI,CAACD,KAAKC,SAAS,CAACP,UAAU;gBAC9C;YACF;YAEA,uEAAuE;YACvE,8CAA8C;YAC9CC,QAAQI,KAAK,CAACX,IAAIY,KAAKE,IAAI;YAE3B,MAAMF,KAAKG,IAAI,CAAC;gBACd,GAAGT,OAAO;gBACVC;YACF;QACF;QAEA,0EAA0E;QAC1E,kBAAkB;QAClB,IAAIA,QAAQS,UAAU,EAAE;YACtBT,QAAQU,OAAO,CAAC;QAClB;IACF,EAAE,OAAOC,QAAQ;QACff,MAAMD,gBAAgBgB,SAASX;QAC/BA,QAAQY,IAAI;QACZV,QAAQW,QAAQ,GAAG;IACrB;AACF"}
@@ -0,0 +1,89 @@
1
+ import { createServer } from 'http';
2
+ import serveMiddleware from 'serve-handler';
3
+ import { webpack } from 'webpack';
4
+ import { getDefaultConfiguration } from './config';
5
+ /**
6
+ * Get a Webpack compiler for the given config.
7
+ *
8
+ * @param config - The config object.
9
+ * @param options - The Webpack options.
10
+ * @returns The Webpack compiler.
11
+ */ export async function getCompiler(config, options) {
12
+ const baseWebpackConfig = await getDefaultConfiguration(config, options);
13
+ const webpackConfig = config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;
14
+ return webpack(webpackConfig);
15
+ }
16
+ /**
17
+ * Get a static server for development purposes.
18
+ *
19
+ * Note: We're intentionally not using `webpack-dev-server` here because it
20
+ * adds a lot of extra stuff to the output that we don't need, and it's
21
+ * difficult to customize.
22
+ *
23
+ * @param config - The config object.
24
+ * @returns An object with a `listen` method that returns a promise that
25
+ * resolves when the server is listening.
26
+ */ export function getServer(config) {
27
+ const server = createServer((request, response)=>{
28
+ serveMiddleware(request, response, {
29
+ public: config.server.root,
30
+ headers: [
31
+ {
32
+ source: '**/*',
33
+ headers: [
34
+ {
35
+ key: 'Cache-Control',
36
+ value: 'no-cache'
37
+ },
38
+ {
39
+ key: 'Access-Control-Allow-Origin',
40
+ value: '*'
41
+ }
42
+ ]
43
+ }
44
+ ]
45
+ })?.catch(/* istanbul ignore next */ ()=>{
46
+ response.statusCode = 500;
47
+ response.end();
48
+ });
49
+ });
50
+ /**
51
+ * Start the server on the port specified in the config.
52
+ *
53
+ * @param port - The port to listen on.
54
+ * @returns A promise that resolves when the server is listening. The promise
55
+ * resolves to an object with the port and the server instance. Note that if
56
+ * the `config.server.port` is `0`, the OS will choose a random port for us,
57
+ * so we need to get the port from the server after it starts.
58
+ */ const listen = async (port = config.server.port)=>{
59
+ return new Promise((resolve, reject)=>{
60
+ try {
61
+ server.listen(port, ()=>{
62
+ const close = async ()=>{
63
+ await new Promise((resolveClose, rejectClose)=>{
64
+ server.close((closeError)=>{
65
+ if (closeError) {
66
+ return rejectClose(closeError);
67
+ }
68
+ return resolveClose();
69
+ });
70
+ });
71
+ };
72
+ const address = server.address();
73
+ resolve({
74
+ port: address.port,
75
+ server,
76
+ close
77
+ });
78
+ });
79
+ } catch (listenError) {
80
+ reject(listenError);
81
+ }
82
+ });
83
+ };
84
+ return {
85
+ listen
86
+ };
87
+ }
88
+
89
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webpack/compiler.ts"],"sourcesContent":["import type { Server } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport serveMiddleware from 'serve-handler';\nimport { webpack } from 'webpack';\n\nimport type { ProcessedConfig, ProcessedWebpackConfig } from '../config';\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedWebpackConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n\n/**\n * Get a static server for development purposes.\n *\n * Note: We're intentionally not using `webpack-dev-server` here because it\n * adds a lot of extra stuff to the output that we don't need, and it's\n * difficult to customize.\n *\n * @param config - The config object.\n * @returns An object with a `listen` method that returns a promise that\n * resolves when the server is listening.\n */\nexport function getServer(config: ProcessedConfig) {\n const server = createServer((request, response) => {\n serveMiddleware(request, response, {\n public: config.server.root,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n })?.catch(\n /* istanbul ignore next */ () => {\n response.statusCode = 500;\n response.end();\n },\n );\n });\n\n /**\n * Start the server on the port specified in the config.\n *\n * @param port - The port to listen on.\n * @returns A promise that resolves when the server is listening. The promise\n * resolves to an object with the port and the server instance. Note that if\n * the `config.server.port` is `0`, the OS will choose a random port for us,\n * so we need to get the port from the server after it starts.\n */\n const listen = async (port = config.server.port) => {\n return new Promise<{\n port: number;\n server: Server;\n close: () => Promise<void>;\n }>((resolve, reject) => {\n try {\n server.listen(port, () => {\n const close = async () => {\n await new Promise<void>((resolveClose, rejectClose) => {\n server.close((closeError) => {\n if (closeError) {\n return rejectClose(closeError);\n }\n\n return resolveClose();\n });\n });\n };\n\n const address = server.address() as AddressInfo;\n resolve({ port: address.port, server, close });\n });\n } catch (listenError) {\n reject(listenError);\n }\n });\n };\n\n return { listen };\n}\n"],"names":["createServer","serveMiddleware","webpack","getDefaultConfiguration","getCompiler","config","options","baseWebpackConfig","webpackConfig","customizeWebpackConfig","getServer","server","request","response","public","root","headers","source","key","value","catch","statusCode","end","listen","port","Promise","resolve","reject","close","resolveClose","rejectClose","closeError","address","listenError"],"mappings":"AACA,SAASA,YAAY,QAAQ,OAAO;AAEpC,OAAOC,qBAAqB,gBAAgB;AAC5C,SAASC,OAAO,QAAQ,UAAU;AAIlC,SAASC,uBAAuB,QAAQ,WAAW;AAEnD;;;;;;CAMC,GACD,OAAO,eAAeC,YACpBC,MAA8B,EAC9BC,OAAwB;IAExB,MAAMC,oBAAoB,MAAMJ,wBAAwBE,QAAQC;IAChE,MAAME,gBACJH,OAAOI,sBAAsB,GAAGF,sBAAsBA;IAExD,OAAOL,QAAQM;AACjB;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASE,UAAUL,MAAuB;IAC/C,MAAMM,SAASX,aAAa,CAACY,SAASC;QACpCZ,gBAAgBW,SAASC,UAAU;YACjCC,QAAQT,OAAOM,MAAM,CAACI,IAAI;YAC1BC,SAAS;gBACP;oBACEC,QAAQ;oBACRD,SAAS;wBACP;4BACEE,KAAK;4BACLC,OAAO;wBACT;wBACA;4BACED,KAAK;4BACLC,OAAO;wBACT;qBACD;gBACH;aACD;QACH,IAAIC,MACF,wBAAwB,GAAG;YACzBP,SAASQ,UAAU,GAAG;YACtBR,SAASS,GAAG;QACd;IAEJ;IAEA;;;;;;;;GAQC,GACD,MAAMC,SAAS,OAAOC,OAAOnB,OAAOM,MAAM,CAACa,IAAI;QAC7C,OAAO,IAAIC,QAIR,CAACC,SAASC;YACX,IAAI;gBACFhB,OAAOY,MAAM,CAACC,MAAM;oBAClB,MAAMI,QAAQ;wBACZ,MAAM,IAAIH,QAAc,CAACI,cAAcC;4BACrCnB,OAAOiB,KAAK,CAAC,CAACG;gCACZ,IAAIA,YAAY;oCACd,OAAOD,YAAYC;gCACrB;gCAEA,OAAOF;4BACT;wBACF;oBACF;oBAEA,MAAMG,UAAUrB,OAAOqB,OAAO;oBAC9BN,QAAQ;wBAAEF,MAAMQ,QAAQR,IAAI;wBAAEb;wBAAQiB;oBAAM;gBAC9C;YACF,EAAE,OAAOK,aAAa;gBACpBN,OAAOM;YACT;QACF;IACF;IAEA,OAAO;QAAEV;IAAO;AAClB"}