@metamask/snaps-cli 1.0.1 → 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 -372
  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
@@ -1,48 +0,0 @@
1
- import type browserify from 'browserify';
2
- import { Infer } from 'superstruct';
3
- import { Arguments } from 'yargs';
4
- import yargs from 'yargs/yargs';
5
- export declare type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;
6
- export declare const SnapConfigStruct: import("superstruct").Struct<{
7
- cliOptions?: Record<string, unknown> | undefined;
8
- bundlerCustomizer?: Function | undefined;
9
- }, {
10
- cliOptions: import("superstruct").Struct<Record<string, unknown> | undefined, null>;
11
- bundlerCustomizer: import("superstruct").Struct<Function | undefined, null>;
12
- }>;
13
- export declare type SnapConfig = Omit<Infer<typeof SnapConfigStruct>, 'bundlerCustomizer'> & {
14
- bundlerCustomizer?: BundleCustomizer;
15
- };
16
- /**
17
- * Check if the given value is a {@link SnapConfig} object. Note that this
18
- * function does not check the validity of the `bundleCustomizer` property, as
19
- * it is not possible to check the validity of a function in JavaScript.
20
- *
21
- * @param value - The value to check.
22
- * @returns `true` if the value is a valid {@link SnapConfig} object, `false`
23
- * otherwise.
24
- */
25
- export declare function isSnapConfig(value: unknown): value is SnapConfig;
26
- /**
27
- * Attempt to load the snap config file (`snap.config.js`). By default will use
28
- * the cached config, if it was loaded before, and `cached` is `true`. If the
29
- * config file is not found, or the config is invalid, this function will kill
30
- * the process.
31
- *
32
- * @param cached - Whether to use the cached config. Defaults to `true`.
33
- * @returns The snap config.
34
- */
35
- export declare function loadConfig(cached?: boolean): SnapConfig;
36
- /**
37
- * Attempts to read configuration options for package.json and the config file,
38
- * and apply them to argv if they weren't already set.
39
- *
40
- * Arguments are only set per the snap-cli config file if they were not specified
41
- * on the command line.
42
- *
43
- * @param snapConfig - The snap config.
44
- * @param processArgv - The command line arguments, i.e., `process.argv`.
45
- * @param yargsArgv - The processed `yargs` arguments.
46
- * @param yargsInstance - An instance of `yargs`.
47
- */
48
- export declare function applyConfig(snapConfig: SnapConfig, processArgv: string[], yargsArgv: Arguments, yargsInstance: typeof yargs): void;
@@ -1,117 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.applyConfig = exports.loadConfig = exports.isSnapConfig = exports.SnapConfigStruct = void 0;
7
- const utils_1 = require("@metamask/utils");
8
- const path_1 = __importDefault(require("path"));
9
- const superstruct_1 = require("superstruct");
10
- const yargs_parser_1 = __importDefault(require("yargs-parser"));
11
- const builders_1 = __importDefault(require("../builders"));
12
- const misc_1 = require("./misc");
13
- exports.SnapConfigStruct = (0, superstruct_1.object)({
14
- cliOptions: (0, superstruct_1.optional)((0, superstruct_1.object)()),
15
- bundlerCustomizer: (0, superstruct_1.optional)((0, superstruct_1.func)()),
16
- });
17
- /**
18
- * Check if the given value is a {@link SnapConfig} object. Note that this
19
- * function does not check the validity of the `bundleCustomizer` property, as
20
- * it is not possible to check the validity of a function in JavaScript.
21
- *
22
- * @param value - The value to check.
23
- * @returns `true` if the value is a valid {@link SnapConfig} object, `false`
24
- * otherwise.
25
- */
26
- function isSnapConfig(value) {
27
- return (0, superstruct_1.is)(value, exports.SnapConfigStruct);
28
- }
29
- exports.isSnapConfig = isSnapConfig;
30
- let snapConfigCache;
31
- /**
32
- * Attempt to load the snap config file (`snap.config.js`). By default will use
33
- * the cached config, if it was loaded before, and `cached` is `true`. If the
34
- * config file is not found, or the config is invalid, this function will kill
35
- * the process.
36
- *
37
- * @param cached - Whether to use the cached config. Defaults to `true`.
38
- * @returns The snap config.
39
- */
40
- function loadConfig(cached = true) {
41
- if (snapConfigCache !== undefined && cached) {
42
- return snapConfigCache;
43
- }
44
- let config;
45
- try {
46
- // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
47
- config = require(path_1.default.resolve(process.cwd(), misc_1.CONFIG_FILE));
48
- }
49
- catch (error) {
50
- if (error.code === 'MODULE_NOT_FOUND') {
51
- snapConfigCache = {};
52
- return snapConfigCache;
53
- }
54
- (0, misc_1.logError)(`Error during parsing of ${misc_1.CONFIG_FILE}`, error);
55
- return process.exit(1);
56
- }
57
- if (!isSnapConfig(config)) {
58
- (0, misc_1.logError)(`Can't validate ${misc_1.CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
59
- return process.exit(1);
60
- }
61
- snapConfigCache = config;
62
- return config;
63
- }
64
- exports.loadConfig = loadConfig;
65
- // Note that the below function is necessary because yargs' .config() function
66
- // leaves much to be desired.
67
- //
68
- // In particular, it will set all properties included in the config file
69
- // regardless of the command, which fails during validation.
70
- /**
71
- * Attempts to read configuration options for package.json and the config file,
72
- * and apply them to argv if they weren't already set.
73
- *
74
- * Arguments are only set per the snap-cli config file if they were not specified
75
- * on the command line.
76
- *
77
- * @param snapConfig - The snap config.
78
- * @param processArgv - The command line arguments, i.e., `process.argv`.
79
- * @param yargsArgv - The processed `yargs` arguments.
80
- * @param yargsInstance - An instance of `yargs`.
81
- */
82
- function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
83
- // Instances of yargs has a number of undocumented functions, including
84
- // getOptions. This function returns an object with properties "key" and
85
- // "alias", which specify the options associated with the current command and
86
- // their aliases, respectively.
87
- //
88
- // We leverage this to ensure that the config is only applied to args that are
89
- // valid for the current command, and that weren't specified by the user on
90
- // the command line.
91
- //
92
- // If we set args that aren't valid for the current command, yargs will error
93
- // during validation.
94
- const { alias: aliases, key: options } = yargsInstance.getOptions();
95
- const parsedProcessArgv = (0, yargs_parser_1.default)(processArgv, {
96
- alias: aliases,
97
- });
98
- delete parsedProcessArgv._; // irrelevant yargs parser artifact
99
- const commandOptions = new Set(Object.keys(options));
100
- const shouldSetArg = (key) => {
101
- return commandOptions.has(key) && !(0, utils_1.hasProperty)(parsedProcessArgv, key);
102
- };
103
- const config = snapConfig.cliOptions ?? {};
104
- for (const key of Object.keys(config)) {
105
- if ((0, utils_1.hasProperty)(builders_1.default, key)) {
106
- if (shouldSetArg(key)) {
107
- yargsArgv[key] = config[key];
108
- }
109
- }
110
- else {
111
- (0, misc_1.logError)(`Error: Encountered unrecognized config property "options.${key}" in config file "${misc_1.CONFIG_FILE}". Remove the property and try again.`);
112
- process.exit(1);
113
- }
114
- }
115
- }
116
- exports.applyConfig = applyConfig;
117
- //# sourceMappingURL=snap-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA8C;AAE9C,gDAAwB;AACxB,6C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AuC,CACvI,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;KACF;AACH,CAAC;AAhDD,kCAgDC","sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport { object, optional, func, Infer, is } from 'superstruct';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n process.exit(1);\n }\n }\n}\n"]}
File without changes
File without changes