@metamask/snaps-cli 0.16.0 → 0.18.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 (71) hide show
  1. package/README.md +2 -0
  2. package/dist/builders.d.ts +6 -0
  3. package/dist/builders.js +20 -1
  4. package/dist/builders.js.map +1 -1
  5. package/dist/cli.d.ts +7 -0
  6. package/dist/cli.js +8 -0
  7. package/dist/cli.js.map +1 -1
  8. package/dist/cmds/build/buildHandler.d.ts +4 -4
  9. package/dist/cmds/build/buildHandler.js +5 -5
  10. package/dist/cmds/build/buildHandler.js.map +1 -1
  11. package/dist/cmds/build/bundle.d.ts +3 -2
  12. package/dist/cmds/build/bundle.js +7 -12
  13. package/dist/cmds/build/bundle.js.map +1 -1
  14. package/dist/cmds/build/utils.d.ts +21 -8
  15. package/dist/cmds/build/utils.js +22 -9
  16. package/dist/cmds/build/utils.js.map +1 -1
  17. package/dist/cmds/eval/eval-worker.js +16 -21
  18. package/dist/cmds/eval/eval-worker.js.map +1 -1
  19. package/dist/cmds/eval/evalHandler.d.ts +7 -0
  20. package/dist/cmds/eval/evalHandler.js +7 -0
  21. package/dist/cmds/eval/evalHandler.js.map +1 -1
  22. package/dist/cmds/eval/mock.d.ts +11 -0
  23. package/dist/cmds/eval/mock.js +39 -3
  24. package/dist/cmds/eval/mock.js.map +1 -1
  25. package/dist/cmds/eval/workerEval.d.ts +7 -0
  26. package/dist/cmds/eval/workerEval.js +11 -6
  27. package/dist/cmds/eval/workerEval.js.map +1 -1
  28. package/dist/cmds/init/index.js +14 -6
  29. package/dist/cmds/init/index.js.map +1 -1
  30. package/dist/cmds/init/init-template.json +5 -1
  31. package/dist/cmds/init/initHandler.d.ts +11 -0
  32. package/dist/cmds/init/initHandler.js +39 -4
  33. package/dist/cmds/init/initHandler.js.map +1 -1
  34. package/dist/cmds/init/initUtils.d.ts +21 -4
  35. package/dist/cmds/init/initUtils.js +55 -7
  36. package/dist/cmds/init/initUtils.js.map +1 -1
  37. package/dist/cmds/manifest/index.js +1 -1
  38. package/dist/cmds/manifest/index.js.map +1 -1
  39. package/dist/cmds/manifest/manifestHandler.d.ts +1 -0
  40. package/dist/cmds/manifest/manifestHandler.js +24 -7
  41. package/dist/cmds/manifest/manifestHandler.js.map +1 -1
  42. package/dist/cmds/serve/index.js +2 -44
  43. package/dist/cmds/serve/index.js.map +1 -1
  44. package/dist/cmds/serve/serveHandler.d.ts +10 -0
  45. package/dist/cmds/serve/serveHandler.js +51 -0
  46. package/dist/cmds/serve/serveHandler.js.map +1 -0
  47. package/dist/cmds/serve/serveUtils.d.ts +17 -0
  48. package/dist/cmds/serve/serveUtils.js +17 -0
  49. package/dist/cmds/serve/serveUtils.js.map +1 -1
  50. package/dist/cmds/watch/index.js +3 -0
  51. package/dist/cmds/watch/index.js.map +1 -1
  52. package/dist/cmds/watch/watchHandler.d.ts +4 -4
  53. package/dist/cmds/watch/watchHandler.js +13 -7
  54. package/dist/cmds/watch/watchHandler.js.map +1 -1
  55. package/dist/utils/fs.d.ts +5 -5
  56. package/dist/utils/fs.js +5 -5
  57. package/dist/utils/fs.js.map +1 -1
  58. package/dist/utils/misc.d.ts +16 -13
  59. package/dist/utils/misc.js +16 -13
  60. package/dist/utils/misc.js.map +1 -1
  61. package/dist/utils/readline.d.ts +25 -0
  62. package/dist/utils/readline.js +25 -0
  63. package/dist/utils/readline.js.map +1 -1
  64. package/dist/utils/snap-config.d.ts +14 -0
  65. package/dist/utils/snap-config.js +15 -1
  66. package/dist/utils/snap-config.js.map +1 -1
  67. package/dist/utils/validate-fs.d.ts +19 -18
  68. package/dist/utils/validate-fs.js +21 -20
  69. package/dist/utils/validate-fs.js.map +1 -1
  70. package/package.json +11 -11
  71. package/CHANGELOG.md +0 -227
package/dist/utils/fs.js CHANGED
@@ -7,9 +7,9 @@ const misc_1 = require("./misc");
7
7
  * Checks whether the given path string resolves to an existing directory, and
8
8
  * optionally creates the directory if it doesn't exist.
9
9
  *
10
- * @param pathString - The path string to check
11
- * @param createDir - Whether to create the directory if it doesn't exist
12
- * @returns - Whether the given path is an existing directory
10
+ * @param pathString - The path string to check.
11
+ * @param createDir - Whether to create the directory if it doesn't exist.
12
+ * @returns Whether the given path is an existing directory.
13
13
  */
14
14
  async function isDirectory(pathString, createDir) {
15
15
  try {
@@ -37,8 +37,8 @@ exports.isDirectory = isDirectory;
37
37
  /**
38
38
  * Checks whether the given path string resolves to an existing file.
39
39
  *
40
- * @param pathString - The path string to check
41
- * @returns Whether the given path is an existing file
40
+ * @param pathString - The path string to check.
41
+ * @returns Whether the given path is an existing file.
42
42
  */
43
43
  async function isFile(pathString) {
44
44
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AAEpC,iCAAkC;AAElC;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,SAAkB;IAElB,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;KAC5B;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC3B,IAAI,CAAC,SAAS,EAAE;gBACd,OAAO,KAAK,CAAC;aACd;YAED,IAAI;gBACF,MAAM,aAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBAC3B,OAAO,IAAI,CAAC;aACb;YAAC,OAAO,UAAU,EAAE;gBACnB,IAAA,eAAQ,EAAC,cAAc,UAAU,yBAAyB,EAAE,UAAU,CAAC,CAAC;gBACxE,MAAM,UAAU,CAAC;aAClB;SACF;QACD,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAvBD,kCAuBC;AAED;;;;;GAKG;AACI,KAAK,UAAU,MAAM,CAAC,UAAkB;IAC7C,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;KACvB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wBAOC;AAED;;;;;GAKG;AACI,KAAK,UAAU,YAAY,CAAC,UAAkB;IACnD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,aAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3D,CAAC;AAND,oCAMC","sourcesContent":["import { promises as fs } from 'fs';\nimport type { Json } from '@metamask/snap-controllers';\nimport { logError } from './misc';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check\n * @param createDir - Whether to create the directory if it doesn't exist\n * @returns - Whether the given path is an existing directory\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n try {\n await fs.mkdir(pathString);\n return true;\n } catch (mkdirError) {\n logError(`Directory '${pathString}' could not be created.`, mkdirError);\n throw mkdirError;\n }\n }\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check\n * @returns Whether the given path is an existing file\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile(pathString: string): Promise<Json> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n return JSON.parse(await fs.readFile(pathString, 'utf8'));\n}\n"]}
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AAEpC,iCAAkC;AAElC;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,SAAkB;IAElB,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;KAC5B;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC3B,IAAI,CAAC,SAAS,EAAE;gBACd,OAAO,KAAK,CAAC;aACd;YAED,IAAI;gBACF,MAAM,aAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBAC3B,OAAO,IAAI,CAAC;aACb;YAAC,OAAO,UAAU,EAAE;gBACnB,IAAA,eAAQ,EAAC,cAAc,UAAU,yBAAyB,EAAE,UAAU,CAAC,CAAC;gBACxE,MAAM,UAAU,CAAC;aAClB;SACF;QACD,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAvBD,kCAuBC;AAED;;;;;GAKG;AACI,KAAK,UAAU,MAAM,CAAC,UAAkB;IAC7C,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;KACvB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wBAOC;AAED;;;;;GAKG;AACI,KAAK,UAAU,YAAY,CAAC,UAAkB;IACnD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,aAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3D,CAAC;AAND,oCAMC","sourcesContent":["import { promises as fs } from 'fs';\nimport type { Json } from '@metamask/snap-controllers';\nimport { logError } from './misc';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n try {\n await fs.mkdir(pathString);\n return true;\n } catch (mkdirError) {\n logError(`Directory '${pathString}' could not be created.`, mkdirError);\n throw mkdirError;\n }\n }\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile(pathString: string): Promise<Json> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n return JSON.parse(await fs.readFile(pathString, 'utf8'));\n}\n"]}
@@ -4,16 +4,17 @@ export declare const permRequestKeys: string[];
4
4
  export declare const CONFIG_FILE = "snap.config.js";
5
5
  /**
6
6
  * Sets global variable snaps which tracks user settings:
7
- * watch mode activation, verbose errors messages, and whether to suppress warnings.
7
+ * watch mode activation, verbose errors messages, and whether to suppress
8
+ * warnings.
8
9
  *
9
- * @param argv - arguments as an object generated by yargs
10
+ * @param argv - Arguments as an object generated by `yargs`.
10
11
  */
11
12
  export declare function setSnapGlobals(argv: Arguments): void;
12
13
  /**
13
14
  * Attempts to convert a string to a boolean and throws if the value is invalid.
14
15
  *
15
16
  * @param value - The value to convert to a boolean.
16
- * @return `true` if the value is the string `"true"`, `false` if it is the
17
+ * @returns `true` if the value is the string `"true"`, `false` if it is the
17
18
  * string `"false"`, the value if it is already a boolean, or an error
18
19
  * otherwise.
19
20
  */
@@ -22,30 +23,32 @@ export declare function booleanStringToBoolean(value: unknown): boolean;
22
23
  * Sanitizes inputs. Currently normalizes "./" paths to ".".
23
24
  * Yargs handles other path normalization as specified in builders.
24
25
  *
25
- * @param argv - arguments as an object generated by yargs
26
+ * @param argv - Arguments as an object generated by yargs.
26
27
  */
27
28
  export declare function sanitizeInputs(argv: Arguments): void;
28
29
  /**
29
30
  * Logs an error message to console. Logs original error if it exists and
30
31
  * the verboseErrors global is true.
31
32
  *
32
- * @param msg - The error message
33
- * @param err - The original error
33
+ * @param msg - The error message.
34
+ * @param err - The original error.
34
35
  */
35
36
  export declare function logError(msg: string, err?: Error): void;
36
37
  /**
37
38
  * Logs a warning message to console.
38
39
  *
39
- * @param msg - The warning message
40
+ * @param msg - The warning message.
41
+ * @param error - The original error.
40
42
  */
41
43
  export declare function logWarning(msg: string, error?: Error): void;
42
44
  /**
43
- * Logs an error, attempts to unlink the destination file, and exits.
45
+ * Logs an error, attempts to unlink the destination file, and kills the
46
+ * process.
44
47
  *
45
- * @param prefix - The message prefix
46
- * @param msg - The error message
47
- * @param err - The original error
48
- * @param destFilePath - The output file path
48
+ * @param prefix - The message prefix.
49
+ * @param msg - The error message.
50
+ * @param err - The original error.
51
+ * @param destFilePath - The output file path.
49
52
  */
50
53
  export declare function writeError(prefix: string, msg: string, err: Error, destFilePath?: string): Promise<void>;
51
54
  /**
@@ -53,6 +56,6 @@ export declare function writeError(prefix: string, msg: string, err: Error, dest
53
56
  * given path string.
54
57
  *
55
58
  * @param pathString - The path string to trim.
56
- * @returns - The trimmed path string.
59
+ * @returns The trimmed path string.
57
60
  */
58
61
  export declare function trimPathString(pathString: string): string;
@@ -32,9 +32,10 @@ const pathArguments = new Set([
32
32
  ]);
33
33
  /**
34
34
  * Sets global variable snaps which tracks user settings:
35
- * watch mode activation, verbose errors messages, and whether to suppress warnings.
35
+ * watch mode activation, verbose errors messages, and whether to suppress
36
+ * warnings.
36
37
  *
37
- * @param argv - arguments as an object generated by yargs
38
+ * @param argv - Arguments as an object generated by `yargs`.
38
39
  */
39
40
  function setSnapGlobals(argv) {
40
41
  if (['w', 'watch'].includes(argv._[0])) {
@@ -55,7 +56,7 @@ exports.setSnapGlobals = setSnapGlobals;
55
56
  * Attempts to convert a string to a boolean and throws if the value is invalid.
56
57
  *
57
58
  * @param value - The value to convert to a boolean.
58
- * @return `true` if the value is the string `"true"`, `false` if it is the
59
+ * @returns `true` if the value is the string `"true"`, `false` if it is the
59
60
  * string `"false"`, the value if it is already a boolean, or an error
60
61
  * otherwise.
61
62
  */
@@ -76,7 +77,7 @@ exports.booleanStringToBoolean = booleanStringToBoolean;
76
77
  * Sanitizes inputs. Currently normalizes "./" paths to ".".
77
78
  * Yargs handles other path normalization as specified in builders.
78
79
  *
79
- * @param argv - arguments as an object generated by yargs
80
+ * @param argv - Arguments as an object generated by yargs.
80
81
  */
81
82
  function sanitizeInputs(argv) {
82
83
  Object.keys(argv).forEach((key) => {
@@ -96,8 +97,8 @@ exports.sanitizeInputs = sanitizeInputs;
96
97
  * Logs an error message to console. Logs original error if it exists and
97
98
  * the verboseErrors global is true.
98
99
  *
99
- * @param msg - The error message
100
- * @param err - The original error
100
+ * @param msg - The error message.
101
+ * @param err - The original error.
101
102
  */
102
103
  function logError(msg, err) {
103
104
  console.error(msg);
@@ -109,7 +110,8 @@ exports.logError = logError;
109
110
  /**
110
111
  * Logs a warning message to console.
111
112
  *
112
- * @param msg - The warning message
113
+ * @param msg - The warning message.
114
+ * @param error - The original error.
113
115
  */
114
116
  function logWarning(msg, error) {
115
117
  if (msg && !global.snaps.suppressWarnings) {
@@ -121,12 +123,13 @@ function logWarning(msg, error) {
121
123
  }
122
124
  exports.logWarning = logWarning;
123
125
  /**
124
- * Logs an error, attempts to unlink the destination file, and exits.
126
+ * Logs an error, attempts to unlink the destination file, and kills the
127
+ * process.
125
128
  *
126
- * @param prefix - The message prefix
127
- * @param msg - The error message
128
- * @param err - The original error
129
- * @param destFilePath - The output file path
129
+ * @param prefix - The message prefix.
130
+ * @param msg - The error message.
131
+ * @param err - The original error.
132
+ * @param destFilePath - The output file path.
130
133
  */
131
134
  async function writeError(prefix, msg, err, destFilePath) {
132
135
  let processedPrefix = prefix;
@@ -155,7 +158,7 @@ exports.writeError = writeError;
155
158
  * given path string.
156
159
  *
157
160
  * @param pathString - The path string to trim.
158
- * @returns - The trimmed path string.
161
+ * @returns The trimmed path string.
159
162
  */
160
163
  function trimPathString(pathString) {
161
164
  return pathString.replace(/^[./]+|[./]+$/gu, '');
@@ -1 +1 @@
1
- {"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AACxB,2CAA8C;AAC9C,gDAAwB;AAGX,QAAA,SAAS,GAAG,IAAA,cAAI,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAEnD,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,WAAW,GAAG,gBAAgB,CAAC;AAE5C,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,KAAK;IACL,GAAG;IACH,MAAM;IACN,GAAG;IACH,QAAQ;IACR,GAAG;IACH,MAAM;IACN,GAAG;CACJ,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,IAAe;IAC5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,CAAC;KAC3E;IAED,qCAAqC;IACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,uEAAuE;QACvE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AA1BD,gCA0BC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,UAAkB;IAC/C,OAAO,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import { promises as filesystem } from 'fs';\nimport path from 'path';\nimport { hasProperty } from '@metamask/utils';\nimport rfdc from 'rfdc';\nimport { Arguments } from 'yargs';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress warnings.\n *\n * @param argv - arguments as an object generated by yargs\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @return `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${value}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - arguments as an object generated by yargs\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param msg - The error message\n * @param err - The original error\n */\nexport function logError(msg: string, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and exits.\n *\n * @param prefix - The message prefix\n * @param msg - The error message\n * @param err - The original error\n * @param destFilePath - The output file path\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-skunkworks/issues/81\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns - The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"]}
1
+ {"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AACxB,2CAA8C;AAC9C,gDAAwB;AAGX,QAAA,SAAS,GAAG,IAAA,cAAI,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAEnD,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,WAAW,GAAG,gBAAgB,CAAC;AAE5C,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,KAAK;IACL,GAAG;IACH,MAAM;IACN,GAAG;IACH,QAAQ;IACR,GAAG;IACH,MAAM;IACN,GAAG;CACJ,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,IAAe;IAC5C,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAW,CAAC,EAAE;QAChD,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;KAChC;SAAM;QACL,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;KACjC;IAED,IAAI,IAAA,mBAAW,EAAC,IAAI,EAAE,eAAe,CAAC,EAAE;QACtC,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,sBAAsB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KACzE;IAED,IAAI,IAAA,mBAAW,EAAC,IAAI,EAAE,kBAAkB,CAAC,EAAE;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BAKC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,GAAW,EAAE,KAAa;IACnD,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE;QACzC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,IAAI,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE;YACvC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACtB;KACF;AACH,CAAC;AAPD,gCAOC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,GAAW,EACX,GAAU,EACV,YAAqB;IAErB,IAAI,eAAe,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACzB,eAAe,IAAI,GAAG,CAAC;KACxB;IAED,QAAQ,CAAC,eAAe,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IACrC,IAAI;QACF,IAAI,YAAY,EAAE;YAChB,MAAM,aAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;SACvC;KACF;IAAC,OAAO,WAAW,EAAE;QACpB,QAAQ,CAAC,GAAG,eAAe,gCAAgC,EAAE,WAAW,CAAC,CAAC;KAC3E;IAED,qCAAqC;IACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,uEAAuE;QACvE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AA1BD,gCA0BC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,UAAkB;IAC/C,OAAO,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import { promises as filesystem } from 'fs';\nimport path from 'path';\nimport { hasProperty } from '@metamask/utils';\nimport rfdc from 'rfdc';\nimport { Arguments } from 'yargs';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${value}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param msg - The error message.\n * @param err - The original error.\n */\nexport function logError(msg: string, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message.\n * @param error - The original error.\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param msg - The error message.\n * @param err - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-skunkworks/issues/81\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"]}
@@ -6,7 +6,32 @@ declare type PromptArgs = {
6
6
  shouldClose?: boolean;
7
7
  readlineInterface?: readline.Interface;
8
8
  };
9
+ /**
10
+ * Open a readline interface, to prompt for user input. Avoid using this
11
+ * function directly. Use the {@link prompt} function instead.
12
+ */
9
13
  export declare function openPrompt(): void;
14
+ /**
15
+ * Prompt for user input on the command line. If the prompt isn't open, it will
16
+ * be opened.
17
+ *
18
+ * @param args - The prompt arguments.
19
+ * @param args.question - The question to ask.
20
+ * @param args.defaultValue - The default value to use, if no answer is provided.
21
+ * @param args.shouldClose - Whether to close the readline interface after
22
+ * prompting.
23
+ * @param args.readlineInterface - The readline interface to use. Uses the
24
+ * global readline interface if none provided.
25
+ * @returns The user's input, or the default value if none provided.
26
+ */
10
27
  export declare function prompt({ question, defaultValue, shouldClose, readlineInterface, }: PromptArgs): Promise<string>;
28
+ /**
29
+ * Close the readline interface.
30
+ *
31
+ * @param readlineInterface - The readline interface to close. Uses the global
32
+ * readline interface if none provided.
33
+ * @throws If no readline interface is provided, and the global interface isn't
34
+ * open.
35
+ */
11
36
  export declare function closePrompt(readlineInterface?: readline.Interface): void;
12
37
  export {};
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.closePrompt = exports.prompt = exports.openPrompt = void 0;
7
7
  const readline_1 = __importDefault(require("readline"));
8
8
  let singletonReadlineInterface;
9
+ /**
10
+ * Open a readline interface, to prompt for user input. Avoid using this
11
+ * function directly. Use the {@link prompt} function instead.
12
+ */
9
13
  function openPrompt() {
10
14
  singletonReadlineInterface = readline_1.default.createInterface({
11
15
  input: process.stdin,
@@ -13,6 +17,19 @@ function openPrompt() {
13
17
  });
14
18
  }
15
19
  exports.openPrompt = openPrompt;
20
+ /**
21
+ * Prompt for user input on the command line. If the prompt isn't open, it will
22
+ * be opened.
23
+ *
24
+ * @param args - The prompt arguments.
25
+ * @param args.question - The question to ask.
26
+ * @param args.defaultValue - The default value to use, if no answer is provided.
27
+ * @param args.shouldClose - Whether to close the readline interface after
28
+ * prompting.
29
+ * @param args.readlineInterface - The readline interface to use. Uses the
30
+ * global readline interface if none provided.
31
+ * @returns The user's input, or the default value if none provided.
32
+ */
16
33
  function prompt({ question, defaultValue, shouldClose, readlineInterface = singletonReadlineInterface, }) {
17
34
  let _readlineInterface = readlineInterface;
18
35
  if (!_readlineInterface) {
@@ -38,6 +55,14 @@ function prompt({ question, defaultValue, shouldClose, readlineInterface = singl
38
55
  });
39
56
  }
40
57
  exports.prompt = prompt;
58
+ /**
59
+ * Close the readline interface.
60
+ *
61
+ * @param readlineInterface - The readline interface to close. Uses the global
62
+ * readline interface if none provided.
63
+ * @throws If no readline interface is provided, and the global interface isn't
64
+ * open.
65
+ */
41
66
  function closePrompt(readlineInterface = singletonReadlineInterface) {
42
67
  if (readlineInterface) {
43
68
  readlineInterface.close();
@@ -1 +1 @@
1
- {"version":3,"file":"readline.js","sourceRoot":"","sources":["../../src/utils/readline.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAEhC,IAAI,0BAA8C,CAAC;AASnD,SAAgB,UAAU;IACxB,0BAA0B,GAAG,kBAAQ,CAAC,eAAe,CAAC;QACpD,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC;AALD,gCAKC;AAED,SAAgB,MAAM,CAAC,EACrB,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,iBAAiB,GAAG,0BAA0B,GACnC;IACX,IAAI,kBAAkB,GAAG,iBAAiB,CAAC;IAC3C,IAAI,CAAC,kBAAkB,EAAE;QACvB,UAAU,EAAE,CAAC;QACb,kBAAkB,GAAG,0BAA0B,CAAC;KACjD;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACtC,IAAI,WAAW,GAAG,GAAG,QAAQ,GAAG,CAAC;QACjC,IAAI,YAAY,EAAE;YAChB,WAAW,IAAI,IAAI,YAAY,IAAI,CAAC;SACrC;QAED,kBAAkB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,MAAc,EAAE,EAAE;YAC1D,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE;gBAC7B,IAAI,YAAY,KAAK,SAAS,EAAE;oBAC9B,OAAO,CAAC,YAAY,CAAC,CAAC;iBACvB;aACF;YACD,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YACvB,IAAI,WAAW,EAAE;gBACf,kBAAkB,CAAC,KAAK,EAAE,CAAC;aAC5B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA9BD,wBA8BC;AAED,SAAgB,WAAW,CACzB,iBAAiB,GAAG,0BAA0B;IAE9C,IAAI,iBAAiB,EAAE;QACrB,iBAAiB,CAAC,KAAK,EAAE,CAAC;KAC3B;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;KACvE;AACH,CAAC;AARD,kCAQC","sourcesContent":["import readline from 'readline';\n\nlet singletonReadlineInterface: readline.Interface;\n\ntype PromptArgs = {\n question: string;\n defaultValue?: string;\n shouldClose?: boolean;\n readlineInterface?: readline.Interface;\n};\n\nexport function openPrompt(): void {\n singletonReadlineInterface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n}\n\nexport function prompt({\n question,\n defaultValue,\n shouldClose,\n readlineInterface = singletonReadlineInterface,\n}: PromptArgs): Promise<string> {\n let _readlineInterface = readlineInterface;\n if (!_readlineInterface) {\n openPrompt();\n _readlineInterface = singletonReadlineInterface;\n }\n\n return new Promise((resolve, _reject) => {\n let queryString = `${question} `;\n if (defaultValue) {\n queryString += `(${defaultValue}) `;\n }\n\n _readlineInterface.question(queryString, (answer: string) => {\n if (!answer || !answer.trim()) {\n if (defaultValue !== undefined) {\n resolve(defaultValue);\n }\n }\n resolve(answer.trim());\n if (shouldClose) {\n _readlineInterface.close();\n }\n });\n });\n}\n\nexport function closePrompt(\n readlineInterface = singletonReadlineInterface,\n): void {\n if (readlineInterface) {\n readlineInterface.close();\n } else {\n throw new Error('You are attempting to close a non existent prompt.');\n }\n}\n"]}
1
+ {"version":3,"file":"readline.js","sourceRoot":"","sources":["../../src/utils/readline.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAEhC,IAAI,0BAA8C,CAAC;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oD,CAAC,CAAC;KACvE;AACH,CAAC;AARD,kCAQC","sourcesContent":["import readline from 'readline';\n\nlet singletonReadlineInterface: readline.Interface;\n\ntype PromptArgs = {\n question: string;\n defaultValue?: string;\n shouldClose?: boolean;\n readlineInterface?: readline.Interface;\n};\n\n/**\n * Open a readline interface, to prompt for user input. Avoid using this\n * function directly. Use the {@link prompt} function instead.\n */\nexport function openPrompt(): void {\n singletonReadlineInterface = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n}\n\n/**\n * Prompt for user input on the command line. If the prompt isn't open, it will\n * be opened.\n *\n * @param args - The prompt arguments.\n * @param args.question - The question to ask.\n * @param args.defaultValue - The default value to use, if no answer is provided.\n * @param args.shouldClose - Whether to close the readline interface after\n * prompting.\n * @param args.readlineInterface - The readline interface to use. Uses the\n * global readline interface if none provided.\n * @returns The user's input, or the default value if none provided.\n */\nexport function prompt({\n question,\n defaultValue,\n shouldClose,\n readlineInterface = singletonReadlineInterface,\n}: PromptArgs): Promise<string> {\n let _readlineInterface = readlineInterface;\n if (!_readlineInterface) {\n openPrompt();\n _readlineInterface = singletonReadlineInterface;\n }\n\n return new Promise((resolve, _reject) => {\n let queryString = `${question} `;\n if (defaultValue) {\n queryString += `(${defaultValue}) `;\n }\n\n _readlineInterface.question(queryString, (answer: string) => {\n if (!answer || !answer.trim()) {\n if (defaultValue !== undefined) {\n resolve(defaultValue);\n }\n }\n resolve(answer.trim());\n if (shouldClose) {\n _readlineInterface.close();\n }\n });\n });\n}\n\n/**\n * Close the readline interface.\n *\n * @param readlineInterface - The readline interface to close. Uses the global\n * readline interface if none provided.\n * @throws If no readline interface is provided, and the global interface isn't\n * open.\n */\nexport function closePrompt(\n readlineInterface = singletonReadlineInterface,\n): void {\n if (readlineInterface) {\n readlineInterface.close();\n } else {\n throw new Error('You are attempting to close a non existent prompt.');\n }\n}\n"]}
@@ -7,6 +7,15 @@ export declare type SnapConfig = {
7
7
  cliOptions?: Record<string, unknown>;
8
8
  bundlerCustomizer?: (bundler: browserify.BrowserifyObject) => void;
9
9
  };
10
+ /**
11
+ * Attempt to load the snap config file (`snap.config.js`). By default will use
12
+ * the cached config, if it was loaded before, and `cached` is `true`. If the
13
+ * config file is not found, or the config is invalid, this function will kill
14
+ * the process.
15
+ *
16
+ * @param cached - Whether to use the cached config. Defaults to `true`.
17
+ * @returns The snap config.
18
+ */
10
19
  export declare function loadConfig(cached?: boolean): SnapConfig;
11
20
  /**
12
21
  * Attempts to read configuration options for package.json and the config file,
@@ -14,5 +23,10 @@ export declare function loadConfig(cached?: boolean): SnapConfig;
14
23
  *
15
24
  * Arguments are only set per the snap-cli config file if they were not specified
16
25
  * on the command line.
26
+ *
27
+ * @param snapConfig - The snap config.
28
+ * @param processArgv - The command line arguments, i.e., `process.argv`.
29
+ * @param yargsArgv - The processed `yargs` arguments.
30
+ * @param yargsInstance - An instance of `yargs`.
17
31
  */
18
32
  export declare function applyConfig(snapConfig: SnapConfig, processArgv: string[], yargsArgv: Arguments, yargsInstance: typeof yargs): void;
@@ -11,6 +11,15 @@ const builders_1 = __importDefault(require("../builders"));
11
11
  const misc_1 = require("./misc");
12
12
  const snap_config___GENERATED__1 = require("./snap-config.__GENERATED__");
13
13
  let snapConfigCache;
14
+ /**
15
+ * Attempt to load the snap config file (`snap.config.js`). By default will use
16
+ * the cached config, if it was loaded before, and `cached` is `true`. If the
17
+ * config file is not found, or the config is invalid, this function will kill
18
+ * the process.
19
+ *
20
+ * @param cached - Whether to use the cached config. Defaults to `true`.
21
+ * @returns The snap config.
22
+ */
14
23
  function loadConfig(cached = true) {
15
24
  if (snapConfigCache !== undefined && cached === true) {
16
25
  return snapConfigCache;
@@ -36,7 +45,7 @@ function loadConfig(cached = true) {
36
45
  return config;
37
46
  }
38
47
  exports.loadConfig = loadConfig;
39
- // Note that the below function is necessary because yarg's .config() function
48
+ // Note that the below function is necessary because yargs' .config() function
40
49
  // leaves much to be desired.
41
50
  //
42
51
  // In particular, it will set all properties included in the config file
@@ -47,6 +56,11 @@ exports.loadConfig = loadConfig;
47
56
  *
48
57
  * Arguments are only set per the snap-cli config file if they were not specified
49
58
  * on the command line.
59
+ *
60
+ * @param snapConfig - The snap config.
61
+ * @param processArgv - The command line arguments, i.e., `process.argv`.
62
+ * @param yargsArgv - The processed `yargs` arguments.
63
+ * @param yargsInstance - An instance of `yargs`.
50
64
  */
51
65
  function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
52
66
  // Instances of yargs has a number of undocumented functions, including
@@ -1 +1 @@
1
- {"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,2CAA8C;AAG9C,gEAAsC;AAEtC,2DAAmC;AACnC,iCAA+C;AAC/C,0EAA2D;AAQ3D,IAAI,eAAuC,CAAC;AAE5C,SAAgB,UAAU,CAAC,MAAM,GAAG,IAAI;IACtC,IAAI,eAAe,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE;QACpD,OAAO,eAAe,CAAC;KACxB;IAED,IAAI,MAAW,CAAC;IAChB,IAAI;QACF,iHAAiH;QACjH,MAAM,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,kBAAW,CAAC,CAAC,CAAC;KAC5D;IAAC,OAAO,GAAQ,EAAE;QACjB,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACnC,eAAe,GAAG,EAAE,CAAC;YACrB,OAAO,eAAe,CAAC;SACxB;QACD,IAAA,eAAQ,EAAC,2BAA2B,kBAAW,EAAE,EAAE,GAAG,CAAC,CAAC;QACxD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACxB;IAED,IAAI,CAAC,IAAA,uCAAY,EAAC,MAAM,CAAC,EAAE;QACzB,IAAA,eAAQ,EACN,kBAAkB,kBAAW,mGAAmG,CACjI,CAAC;QACF,OAAO,OAAO,CAAC,IAAI,CAAC,CAA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AC,GAAG,CAAC,CAAC;aAC3B;SACF;aAAM;YACL,IAAA,eAAQ,EACN,4DAA4D,GAAG,qBAAqB,kBAAW,uCAAuC,CACvI,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;KACF;AACH,CAAC;AAhDD,kCAgDC","sourcesContent":["import path from 'path';\nimport { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\nimport { isSnapConfig } from './snap-config.__GENERATED__';\n\n/** @see {isSnapConfig} ts-auto-guard:type-guard */\nexport type SnapConfig = {\n cliOptions?: Record<string, unknown>;\n bundlerCustomizer?: (bundler: browserify.BrowserifyObject) => void;\n};\n\nlet snapConfigCache: SnapConfig | undefined;\n\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached === true) {\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 (err: any) {\n if (err.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, err);\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 yarg's .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 */\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 cfg: Record<string, unknown> = snapConfig.cliOptions || {};\n for (const key of Object.keys(cfg)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = cfg[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"]}
1
+ {"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,2CAA8C;AAG9C,gEAAsC;AAEtC,2DAAmC;AACnC,iCAA+C;AAC/C,0EAA2D;AAQ3D,IAAI,eAAuC,CAAC;AAE5C;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAC,MAAM,GAAG,IAAI;IACtC,IAAI,eAAe,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE;QACpD,OAAO,eAAe,CAAC;KACxB;IAED,IAAI,MAAW,CAAC;IAChB,IAAI;QACF,iHAAiH;QACjH,MAAM,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,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AM,YAAY,GAAG,CAAC,GAAW,EAAW,EAAE;QAC5C,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,mBAAW,EAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACzE,CAAC,CAAC;IAEF,MAAM,GAAG,GAA4B,UAAU,CAAC,UAAU,IAAI,EAAE,CAAC;IACjE,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAClC,IAAI,IAAA,mBAAW,EAAC,kBAAQ,EAAE,GAAG,CAAC,EAAE;YAC9B,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE;gBACrB,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;aAC3B;SACF;aAAM;YACL,IAAA,eAAQ,EACN,4DAA4D,GAAG,qBAAqB,kBAAW,uCAAuC,CACvI,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;KACF;AACH,CAAC;AAhDD,kCAgDC","sourcesContent":["import path from 'path';\nimport { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\nimport { isSnapConfig } from './snap-config.__GENERATED__';\n\n/** @see {isSnapConfig} ts-auto-guard:type-guard */\nexport type SnapConfig = {\n cliOptions?: Record<string, unknown>;\n bundlerCustomizer?: (bundler: browserify.BrowserifyObject) => void;\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 === true) {\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 (err: any) {\n if (err.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, err);\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 cfg: Record<string, unknown> = snapConfig.cliOptions || {};\n for (const key of Object.keys(cfg)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = cfg[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"]}
@@ -1,34 +1,35 @@
1
1
  /**
2
- * Gets the complete out file path from the source file path and output
2
+ * Gets the complete out file path from an output file name and parent
3
3
  * directory path.
4
4
  *
5
- * @param srcFilePath - The source file path
6
- * @param outDir - The out file directory
7
- * @returns - The complete out file path
5
+ * @param outDir - The path to the out file's parent directory.
6
+ * @param outFileName - The out file's name.
7
+ * @returns The complete path to the out file.
8
8
  */
9
9
  export declare function getOutfilePath(outDir: string, outFileName: string): string;
10
10
  /**
11
- * Ensures that the outfile name is just a js file name.
12
- * Throws on validation failure
11
+ * Ensures that the outfile name is just a `.js` file name.
12
+ * Throws on validation failure.
13
13
  *
14
- * @param filename - The file name to validate
15
- * @returns - True if validation succeeded
14
+ * @param filename - The file name to validate.
15
+ * @returns `true` if validation succeeded.
16
+ * @throws If the file name is invalid.
16
17
  */
17
18
  export declare function validateOutfileName(filename: string): boolean;
18
19
  /**
19
- * Validates a file path.
20
- * Throws on validation failure
20
+ * Validates a file path. Throws on validation failure.
21
21
  *
22
- * @param filePath - The file path to validate
23
- * @returns - True if validation succeeded
22
+ * @param filePath - The file path to validate.
23
+ * @returns `true` if validation succeeded.
24
+ * @throws If the path does not resolve to a file.
24
25
  */
25
26
  export declare function validateFilePath(filePath: string): Promise<boolean>;
26
27
  /**
27
- * Validates a directory path.
28
- * Throws on validation failure.
28
+ * Validates a directory path. Throws on validation failure.
29
29
  *
30
- * @param dirPath - The directory path to validate
31
- * @param createDir - Whether to create the directory if it doesn't exist
32
- * @returns - True if validation succeeded
30
+ * @param dirPath - The directory path to validate.
31
+ * @param createDir - Whether to create the directory if it doesn't exist.
32
+ * @returns `true` if validation succeeded or the directory was created.
33
+ * @throws If the directory does not exist or could not be created.
33
34
  */
34
- export declare function validateDirPath(dirName: string, createDir: boolean): Promise<boolean>;
35
+ export declare function validateDirPath(dirPath: string, createDir: boolean): Promise<boolean>;
@@ -7,23 +7,24 @@ exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = require("./fs");
9
9
  /**
10
- * Gets the complete out file path from the source file path and output
10
+ * Gets the complete out file path from an output file name and parent
11
11
  * directory path.
12
12
  *
13
- * @param srcFilePath - The source file path
14
- * @param outDir - The out file directory
15
- * @returns - The complete out file path
13
+ * @param outDir - The path to the out file's parent directory.
14
+ * @param outFileName - The out file's name.
15
+ * @returns The complete path to the out file.
16
16
  */
17
17
  function getOutfilePath(outDir, outFileName) {
18
18
  return path_1.default.join(outDir, outFileName || 'bundle.js');
19
19
  }
20
20
  exports.getOutfilePath = getOutfilePath;
21
21
  /**
22
- * Ensures that the outfile name is just a js file name.
23
- * Throws on validation failure
22
+ * Ensures that the outfile name is just a `.js` file name.
23
+ * Throws on validation failure.
24
24
  *
25
- * @param filename - The file name to validate
26
- * @returns - True if validation succeeded
25
+ * @param filename - The file name to validate.
26
+ * @returns `true` if validation succeeded.
27
+ * @throws If the file name is invalid.
27
28
  */
28
29
  function validateOutfileName(filename) {
29
30
  if (!filename.endsWith('.js') ||
@@ -35,11 +36,11 @@ function validateOutfileName(filename) {
35
36
  }
36
37
  exports.validateOutfileName = validateOutfileName;
37
38
  /**
38
- * Validates a file path.
39
- * Throws on validation failure
39
+ * Validates a file path. Throws on validation failure.
40
40
  *
41
- * @param filePath - The file path to validate
42
- * @returns - True if validation succeeded
41
+ * @param filePath - The file path to validate.
42
+ * @returns `true` if validation succeeded.
43
+ * @throws If the path does not resolve to a file.
43
44
  */
44
45
  async function validateFilePath(filePath) {
45
46
  const exists = await (0, fs_1.isFile)(filePath);
@@ -50,17 +51,17 @@ async function validateFilePath(filePath) {
50
51
  }
51
52
  exports.validateFilePath = validateFilePath;
52
53
  /**
53
- * Validates a directory path.
54
- * Throws on validation failure.
54
+ * Validates a directory path. Throws on validation failure.
55
55
  *
56
- * @param dirPath - The directory path to validate
57
- * @param createDir - Whether to create the directory if it doesn't exist
58
- * @returns - True if validation succeeded
56
+ * @param dirPath - The directory path to validate.
57
+ * @param createDir - Whether to create the directory if it doesn't exist.
58
+ * @returns `true` if validation succeeded or the directory was created.
59
+ * @throws If the directory does not exist or could not be created.
59
60
  */
60
- async function validateDirPath(dirName, createDir) {
61
- const exists = await (0, fs_1.isDirectory)(dirName, createDir);
61
+ async function validateDirPath(dirPath, createDir) {
62
+ const exists = await (0, fs_1.isDirectory)(dirPath, createDir);
62
63
  if (!exists) {
63
- throw new Error(`Invalid params: '${dirName}' is not a directory or could not be created.`);
64
+ throw new Error(`Invalid params: '${dirPath}' is not a directory or could not be created.`);
64
65
  }
65
66
  return true;
66
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"validate-fs.js","sourceRoot":"","sources":["../../src/utils/validate-fs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,6BAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,WAAmB;IAChE,OAAO,cAAS,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,IAAI,WAAW,CAAC,CAAC;AAC5D,CAAC;AAFD,wCAEC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QACzB,QAAQ,KAAK,KAAK;QAClB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAC5B;QACA,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,sBAAsB,CAAC,CAAC;KAC1E;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AATD,kDASC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IACrD,MAAM,MAAM,GAAG,MAAM,IAAA,WAAM,EAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,QAAQ,oCAAoC,CACjE,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AARD,4CAQC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAW,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,+CAA+C,CAC3E,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,0CAWC","sourcesContent":["import pathUtils from 'path';\nimport { isFile, isDirectory } from './fs';\n\n/**\n * Gets the complete out file path from the source file path and output\n * directory path.\n *\n * @param srcFilePath - The source file path\n * @param outDir - The out file directory\n * @returns - The complete out file path\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a js file name.\n * Throws on validation failure\n *\n * @param filename - The file name to validate\n * @returns - True if validation succeeded\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n filename.indexOf('/') !== -1\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path.\n * Throws on validation failure\n *\n * @param filePath - The file path to validate\n * @returns - True if validation succeeded\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path.\n * Throws on validation failure.\n *\n * @param dirPath - The directory path to validate\n * @param createDir - Whether to create the directory if it doesn't exist\n * @returns - True if validation succeeded\n */\nexport async function validateDirPath(\n dirName: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirName, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirName}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n"]}
1
+ {"version":3,"file":"validate-fs.js","sourceRoot":"","sources":["../../src/utils/validate-fs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,6BAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,WAAmB;IAChE,OAAO,cAAS,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,IAAI,WAAW,CAAC,CAAC;AAC5D,CAAC;AAFD,wCAEC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QACzB,QAAQ,KAAK,KAAK;QAClB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAC5B;QACA,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,sBAAsB,CAAC,CAAC;KAC1E;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AATD,kDASC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IACrD,MAAM,MAAM,GAAG,MAAM,IAAA,WAAM,EAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,QAAQ,oCAAoC,CACjE,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AARD,4CAQC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAW,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,+CAA+C,CAC3E,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,0CAWC","sourcesContent":["import pathUtils from 'path';\nimport { isFile, isDirectory } from './fs';\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n filename.indexOf('/') !== -1\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n"]}