mathjs 9.2.0 → 9.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (936) hide show
  1. package/HISTORY.md +47 -1
  2. package/README.md +6 -5
  3. package/bin/cli.js +11 -11
  4. package/docs/datatypes/matrices.md +15 -0
  5. package/docs/expressions/parsing.md +21 -4
  6. package/docs/expressions/syntax.md +7 -0
  7. package/docs/reference/functions/complex.md +5 -49
  8. package/docs/reference/functions/eigs.md +12 -12
  9. package/docs/reference/functions/flatten.md +1 -0
  10. package/docs/reference/functions/lsolveAll.md +2 -2
  11. package/docs/reference/functions/matrixFromColumns.md +43 -0
  12. package/docs/reference/functions/matrixFromFunction.md +48 -0
  13. package/docs/reference/functions/matrixFromRows.md +43 -0
  14. package/docs/reference/functions/usolveAll.md +2 -2
  15. package/docs/reference/functions.md +6 -3
  16. package/examples/advanced/custom_scope_objects.js +115 -0
  17. package/examples/node_modules/.bin/envinfo +15 -0
  18. package/examples/node_modules/.bin/envinfo.cmd +17 -0
  19. package/examples/node_modules/.bin/envinfo.ps1 +18 -0
  20. package/examples/node_modules/.bin/import-local-fixture +15 -0
  21. package/examples/node_modules/.bin/import-local-fixture.cmd +17 -0
  22. package/examples/node_modules/.bin/import-local-fixture.ps1 +18 -0
  23. package/examples/node_modules/.bin/node-which +15 -0
  24. package/examples/node_modules/.bin/node-which.cmd +17 -0
  25. package/examples/node_modules/.bin/node-which.ps1 +18 -0
  26. package/examples/node_modules/.bin/webpack-cli +15 -0
  27. package/examples/node_modules/.bin/webpack-cli.cmd +17 -0
  28. package/examples/node_modules/.bin/webpack-cli.ps1 +18 -0
  29. package/examples/node_modules/@discoveryjs/json-ext/CHANGELOG.md +42 -0
  30. package/examples/node_modules/@discoveryjs/json-ext/LICENSE +21 -0
  31. package/examples/node_modules/@discoveryjs/json-ext/README.md +255 -0
  32. package/examples/node_modules/@discoveryjs/json-ext/dist/json-ext.js +808 -0
  33. package/examples/node_modules/@discoveryjs/json-ext/dist/json-ext.min.js +1 -0
  34. package/examples/node_modules/@discoveryjs/json-ext/package.json +93 -0
  35. package/examples/node_modules/@discoveryjs/json-ext/src/index.js +6 -0
  36. package/examples/node_modules/@discoveryjs/json-ext/src/parse-chunked.js +339 -0
  37. package/examples/node_modules/@discoveryjs/json-ext/src/stringify-info.js +224 -0
  38. package/examples/node_modules/@discoveryjs/json-ext/src/stringify-stream-browser.js +3 -0
  39. package/examples/node_modules/@discoveryjs/json-ext/src/stringify-stream.js +394 -0
  40. package/examples/node_modules/@discoveryjs/json-ext/src/text-decoder-browser.js +1 -0
  41. package/examples/node_modules/@discoveryjs/json-ext/src/text-decoder.js +1 -0
  42. package/examples/node_modules/@discoveryjs/json-ext/src/utils.js +148 -0
  43. package/examples/node_modules/@webpack-cli/configtest/CHANGELOG.md +18 -0
  44. package/examples/node_modules/@webpack-cli/configtest/LICENSE +20 -0
  45. package/examples/node_modules/@webpack-cli/configtest/lib/index.d.ts +4 -0
  46. package/examples/node_modules/@webpack-cli/configtest/lib/index.js +62 -0
  47. package/examples/node_modules/@webpack-cli/configtest/package.json +45 -0
  48. package/examples/node_modules/@webpack-cli/info/CHANGELOG.md +61 -0
  49. package/examples/node_modules/@webpack-cli/info/LICENSE +20 -0
  50. package/examples/node_modules/@webpack-cli/info/README.md +49 -0
  51. package/examples/node_modules/@webpack-cli/info/lib/index.d.ts +4 -0
  52. package/examples/node_modules/@webpack-cli/info/lib/index.js +66 -0
  53. package/examples/node_modules/@webpack-cli/info/package.json +47 -0
  54. package/examples/node_modules/@webpack-cli/serve/CHANGELOG.md +93 -0
  55. package/examples/node_modules/@webpack-cli/serve/LICENSE +20 -0
  56. package/examples/node_modules/@webpack-cli/serve/README.md +26 -0
  57. package/examples/node_modules/@webpack-cli/serve/lib/index.d.ts +4 -0
  58. package/examples/node_modules/@webpack-cli/serve/lib/index.js +107 -0
  59. package/examples/node_modules/@webpack-cli/serve/lib/startDevServer.d.ts +12 -0
  60. package/examples/node_modules/@webpack-cli/serve/lib/startDevServer.js +113 -0
  61. package/examples/node_modules/@webpack-cli/serve/lib/types.d.ts +48 -0
  62. package/examples/node_modules/@webpack-cli/serve/lib/types.js +12 -0
  63. package/examples/node_modules/@webpack-cli/serve/package.json +50 -0
  64. package/examples/node_modules/ansi-colors/LICENSE +21 -0
  65. package/examples/node_modules/ansi-colors/README.md +315 -0
  66. package/examples/node_modules/ansi-colors/index.js +177 -0
  67. package/examples/node_modules/ansi-colors/package.json +152 -0
  68. package/examples/node_modules/ansi-colors/symbols.js +70 -0
  69. package/examples/node_modules/ansi-colors/types/index.d.ts +161 -0
  70. package/examples/node_modules/clone-deep/LICENSE +21 -0
  71. package/examples/node_modules/clone-deep/README.md +106 -0
  72. package/examples/node_modules/clone-deep/index.js +49 -0
  73. package/examples/node_modules/clone-deep/package.json +112 -0
  74. package/examples/node_modules/colorette/LICENSE.md +7 -0
  75. package/examples/node_modules/colorette/README.md +102 -0
  76. package/examples/node_modules/colorette/index.cjs +73 -0
  77. package/examples/node_modules/colorette/index.d.ts +49 -0
  78. package/examples/node_modules/colorette/index.js +73 -0
  79. package/examples/node_modules/colorette/package.json +73 -0
  80. package/examples/node_modules/commander/CHANGELOG.md +440 -0
  81. package/examples/node_modules/commander/LICENSE +22 -0
  82. package/examples/node_modules/commander/Readme.md +917 -0
  83. package/examples/node_modules/commander/esm.mjs +4 -0
  84. package/examples/node_modules/commander/index.js +2217 -0
  85. package/examples/node_modules/commander/package-support.json +16 -0
  86. package/examples/node_modules/commander/package.json +100 -0
  87. package/examples/node_modules/commander/typings/index.d.ts +627 -0
  88. package/examples/node_modules/cross-spawn/CHANGELOG.md +130 -0
  89. package/examples/node_modules/cross-spawn/LICENSE +21 -0
  90. package/examples/node_modules/cross-spawn/README.md +96 -0
  91. package/examples/node_modules/cross-spawn/index.js +39 -0
  92. package/examples/node_modules/cross-spawn/lib/enoent.js +59 -0
  93. package/examples/node_modules/cross-spawn/lib/parse.js +91 -0
  94. package/examples/node_modules/cross-spawn/lib/util/escape.js +45 -0
  95. package/examples/node_modules/cross-spawn/lib/util/readShebang.js +23 -0
  96. package/examples/node_modules/cross-spawn/lib/util/resolveCommand.js +52 -0
  97. package/examples/node_modules/cross-spawn/package.json +104 -0
  98. package/examples/node_modules/enquirer/CHANGELOG.md +135 -0
  99. package/examples/node_modules/enquirer/LICENSE +21 -0
  100. package/examples/node_modules/enquirer/README.md +1752 -0
  101. package/examples/node_modules/enquirer/index.d.ts +151 -0
  102. package/examples/node_modules/enquirer/index.js +250 -0
  103. package/examples/node_modules/enquirer/lib/ansi.js +116 -0
  104. package/examples/node_modules/enquirer/lib/combos.js +75 -0
  105. package/examples/node_modules/enquirer/lib/completer.js +52 -0
  106. package/examples/node_modules/enquirer/lib/interpolate.js +266 -0
  107. package/examples/node_modules/enquirer/lib/keypress.js +243 -0
  108. package/examples/node_modules/enquirer/lib/placeholder.js +63 -0
  109. package/examples/node_modules/enquirer/lib/prompt.js +485 -0
  110. package/examples/node_modules/enquirer/lib/prompts/autocomplete.js +113 -0
  111. package/examples/node_modules/enquirer/lib/prompts/basicauth.js +41 -0
  112. package/examples/node_modules/enquirer/lib/prompts/confirm.js +13 -0
  113. package/examples/node_modules/enquirer/lib/prompts/editable.js +136 -0
  114. package/examples/node_modules/enquirer/lib/prompts/form.js +196 -0
  115. package/examples/node_modules/enquirer/lib/prompts/index.js +28 -0
  116. package/examples/node_modules/enquirer/lib/prompts/input.js +55 -0
  117. package/examples/node_modules/enquirer/lib/prompts/invisible.js +11 -0
  118. package/examples/node_modules/enquirer/lib/prompts/list.js +36 -0
  119. package/examples/node_modules/enquirer/lib/prompts/multiselect.js +11 -0
  120. package/examples/node_modules/enquirer/lib/prompts/numeral.js +1 -0
  121. package/examples/node_modules/enquirer/lib/prompts/password.js +18 -0
  122. package/examples/node_modules/enquirer/lib/prompts/quiz.js +37 -0
  123. package/examples/node_modules/enquirer/lib/prompts/scale.js +237 -0
  124. package/examples/node_modules/enquirer/lib/prompts/select.js +139 -0
  125. package/examples/node_modules/enquirer/lib/prompts/snippet.js +185 -0
  126. package/examples/node_modules/enquirer/lib/prompts/sort.js +37 -0
  127. package/examples/node_modules/enquirer/lib/prompts/survey.js +163 -0
  128. package/examples/node_modules/enquirer/lib/prompts/text.js +1 -0
  129. package/examples/node_modules/enquirer/lib/prompts/toggle.js +109 -0
  130. package/examples/node_modules/enquirer/lib/render.js +33 -0
  131. package/examples/node_modules/enquirer/lib/roles.js +46 -0
  132. package/examples/node_modules/enquirer/lib/state.js +69 -0
  133. package/examples/node_modules/enquirer/lib/styles.js +144 -0
  134. package/examples/node_modules/enquirer/lib/symbols.js +66 -0
  135. package/examples/node_modules/enquirer/lib/theme.js +11 -0
  136. package/examples/node_modules/enquirer/lib/timer.js +38 -0
  137. package/examples/node_modules/enquirer/lib/types/array.js +658 -0
  138. package/examples/node_modules/enquirer/lib/types/auth.js +29 -0
  139. package/examples/node_modules/enquirer/lib/types/boolean.js +88 -0
  140. package/examples/node_modules/enquirer/lib/types/index.js +7 -0
  141. package/examples/node_modules/enquirer/lib/types/number.js +86 -0
  142. package/examples/node_modules/enquirer/lib/types/string.js +185 -0
  143. package/examples/node_modules/enquirer/lib/utils.js +268 -0
  144. package/examples/node_modules/enquirer/package.json +148 -0
  145. package/examples/node_modules/envinfo/LICENSE +21 -0
  146. package/examples/node_modules/envinfo/README.md +285 -0
  147. package/examples/node_modules/envinfo/dist/cli.js +2 -0
  148. package/examples/node_modules/envinfo/dist/envinfo.js +1 -0
  149. package/examples/node_modules/envinfo/package.json +130 -0
  150. package/examples/node_modules/execa/index.d.ts +554 -0
  151. package/examples/node_modules/execa/index.js +258 -0
  152. package/examples/node_modules/execa/lib/command.js +32 -0
  153. package/examples/node_modules/execa/lib/error.js +86 -0
  154. package/examples/node_modules/execa/lib/kill.js +112 -0
  155. package/examples/node_modules/execa/lib/promise.js +46 -0
  156. package/examples/node_modules/execa/lib/stdio.js +52 -0
  157. package/examples/node_modules/execa/lib/stream.js +97 -0
  158. package/examples/node_modules/execa/license +9 -0
  159. package/examples/node_modules/execa/package.json +102 -0
  160. package/examples/node_modules/execa/readme.md +650 -0
  161. package/examples/node_modules/fastest-levenshtein/.eslintrc.js +27 -0
  162. package/examples/node_modules/fastest-levenshtein/.prettierrc +4 -0
  163. package/examples/node_modules/fastest-levenshtein/.travis.yml +17 -0
  164. package/examples/node_modules/fastest-levenshtein/LICENSE.md +21 -0
  165. package/examples/node_modules/fastest-levenshtein/README.md +55 -0
  166. package/examples/node_modules/fastest-levenshtein/index.d.ts +2 -0
  167. package/examples/node_modules/fastest-levenshtein/index.js +147 -0
  168. package/examples/node_modules/fastest-levenshtein/package.json +90 -0
  169. package/examples/node_modules/fastest-levenshtein/test.js +64 -0
  170. package/examples/node_modules/find-up/index.d.ts +137 -0
  171. package/examples/node_modules/find-up/index.js +89 -0
  172. package/examples/node_modules/find-up/license +9 -0
  173. package/examples/node_modules/find-up/package.json +85 -0
  174. package/examples/node_modules/find-up/readme.md +156 -0
  175. package/examples/node_modules/function-bind/.editorconfig +20 -0
  176. package/examples/node_modules/function-bind/.eslintrc +15 -0
  177. package/examples/node_modules/function-bind/.jscs.json +176 -0
  178. package/examples/node_modules/function-bind/.npmignore +22 -0
  179. package/examples/node_modules/function-bind/.travis.yml +168 -0
  180. package/examples/node_modules/function-bind/LICENSE +20 -0
  181. package/examples/node_modules/function-bind/README.md +48 -0
  182. package/examples/node_modules/function-bind/implementation.js +52 -0
  183. package/examples/node_modules/function-bind/index.js +5 -0
  184. package/examples/node_modules/function-bind/package.json +94 -0
  185. package/examples/node_modules/function-bind/test/.eslintrc +9 -0
  186. package/examples/node_modules/function-bind/test/index.js +252 -0
  187. package/examples/node_modules/get-stream/buffer-stream.js +52 -0
  188. package/examples/node_modules/get-stream/index.d.ts +105 -0
  189. package/examples/node_modules/get-stream/index.js +61 -0
  190. package/examples/node_modules/get-stream/license +9 -0
  191. package/examples/node_modules/get-stream/package.json +79 -0
  192. package/examples/node_modules/get-stream/readme.md +124 -0
  193. package/examples/node_modules/has/LICENSE-MIT +22 -0
  194. package/examples/node_modules/has/README.md +18 -0
  195. package/examples/node_modules/has/package.json +73 -0
  196. package/examples/node_modules/has/src/index.js +5 -0
  197. package/examples/node_modules/has/test/index.js +10 -0
  198. package/examples/node_modules/human-signals/CHANGELOG.md +11 -0
  199. package/examples/node_modules/human-signals/LICENSE +201 -0
  200. package/examples/node_modules/human-signals/README.md +165 -0
  201. package/examples/node_modules/human-signals/build/src/core.js +273 -0
  202. package/examples/node_modules/human-signals/build/src/core.js.map +1 -0
  203. package/examples/node_modules/human-signals/build/src/main.d.ts +52 -0
  204. package/examples/node_modules/human-signals/build/src/main.js +71 -0
  205. package/examples/node_modules/human-signals/build/src/main.js.map +1 -0
  206. package/examples/node_modules/human-signals/build/src/realtime.js +19 -0
  207. package/examples/node_modules/human-signals/build/src/realtime.js.map +1 -0
  208. package/examples/node_modules/human-signals/build/src/signals.js +35 -0
  209. package/examples/node_modules/human-signals/build/src/signals.js.map +1 -0
  210. package/examples/node_modules/human-signals/package.json +96 -0
  211. package/examples/node_modules/import-local/fixtures/cli.js +7 -0
  212. package/examples/node_modules/import-local/index.js +19 -0
  213. package/examples/node_modules/import-local/license +9 -0
  214. package/examples/node_modules/import-local/package.json +83 -0
  215. package/examples/node_modules/import-local/readme.md +38 -0
  216. package/examples/node_modules/interpret/CHANGELOG +115 -0
  217. package/examples/node_modules/interpret/LICENSE +22 -0
  218. package/examples/node_modules/interpret/README.md +229 -0
  219. package/examples/node_modules/interpret/index.js +211 -0
  220. package/examples/node_modules/interpret/mjs-stub.js +1 -0
  221. package/examples/node_modules/interpret/package.json +118 -0
  222. package/examples/node_modules/is-core-module/.eslintignore +1 -0
  223. package/examples/node_modules/is-core-module/.eslintrc +18 -0
  224. package/examples/node_modules/is-core-module/.github/FUNDING.yml +12 -0
  225. package/examples/node_modules/is-core-module/.github/workflows/node-4+.yml +54 -0
  226. package/examples/node_modules/is-core-module/.github/workflows/node-iojs.yml +58 -0
  227. package/examples/node_modules/is-core-module/.github/workflows/node-pretest.yml +26 -0
  228. package/examples/node_modules/is-core-module/.github/workflows/node-zero.yml +58 -0
  229. package/examples/node_modules/is-core-module/.github/workflows/rebase.yml +15 -0
  230. package/examples/node_modules/is-core-module/.github/workflows/require-allow-edits.yml +14 -0
  231. package/examples/node_modules/is-core-module/.nycrc +13 -0
  232. package/examples/node_modules/is-core-module/CHANGELOG.md +58 -0
  233. package/examples/node_modules/is-core-module/LICENSE +20 -0
  234. package/examples/node_modules/is-core-module/README.md +37 -0
  235. package/examples/node_modules/is-core-module/core.json +83 -0
  236. package/examples/node_modules/is-core-module/index.js +69 -0
  237. package/examples/node_modules/is-core-module/package.json +94 -0
  238. package/examples/node_modules/is-core-module/test/index.js +83 -0
  239. package/examples/node_modules/is-plain-object/LICENSE +21 -0
  240. package/examples/node_modules/is-plain-object/README.md +104 -0
  241. package/examples/node_modules/is-plain-object/index.d.ts +5 -0
  242. package/examples/node_modules/is-plain-object/index.js +37 -0
  243. package/examples/node_modules/is-plain-object/package.json +121 -0
  244. package/examples/node_modules/is-stream/index.d.ts +80 -0
  245. package/examples/node_modules/is-stream/index.js +29 -0
  246. package/examples/node_modules/is-stream/license +9 -0
  247. package/examples/node_modules/is-stream/package.json +73 -0
  248. package/examples/node_modules/is-stream/readme.md +57 -0
  249. package/examples/node_modules/isexe/.npmignore +2 -0
  250. package/examples/node_modules/isexe/LICENSE +15 -0
  251. package/examples/node_modules/isexe/README.md +51 -0
  252. package/examples/node_modules/isexe/index.js +57 -0
  253. package/examples/node_modules/isexe/mode.js +41 -0
  254. package/examples/node_modules/isexe/package.json +60 -0
  255. package/examples/node_modules/isexe/test/basic.js +221 -0
  256. package/examples/node_modules/isexe/windows.js +42 -0
  257. package/examples/node_modules/isobject/LICENSE +21 -0
  258. package/examples/node_modules/isobject/README.md +122 -0
  259. package/examples/node_modules/isobject/index.d.ts +5 -0
  260. package/examples/node_modules/isobject/index.js +12 -0
  261. package/examples/node_modules/isobject/package.json +119 -0
  262. package/examples/node_modules/kind-of/CHANGELOG.md +160 -0
  263. package/examples/node_modules/kind-of/LICENSE +21 -0
  264. package/examples/node_modules/kind-of/README.md +367 -0
  265. package/examples/node_modules/kind-of/index.js +129 -0
  266. package/examples/node_modules/kind-of/package.json +144 -0
  267. package/examples/node_modules/locate-path/index.d.ts +83 -0
  268. package/examples/node_modules/locate-path/index.js +65 -0
  269. package/examples/node_modules/locate-path/license +9 -0
  270. package/examples/node_modules/locate-path/package.json +77 -0
  271. package/examples/node_modules/locate-path/readme.md +122 -0
  272. package/examples/node_modules/merge-stream/LICENSE +21 -0
  273. package/examples/node_modules/merge-stream/README.md +78 -0
  274. package/examples/node_modules/merge-stream/index.js +41 -0
  275. package/examples/node_modules/merge-stream/package.json +54 -0
  276. package/examples/node_modules/mimic-fn/index.d.ts +54 -0
  277. package/examples/node_modules/mimic-fn/index.js +13 -0
  278. package/examples/node_modules/mimic-fn/license +9 -0
  279. package/examples/node_modules/mimic-fn/package.json +74 -0
  280. package/examples/node_modules/mimic-fn/readme.md +69 -0
  281. package/examples/node_modules/npm-run-path/index.d.ts +89 -0
  282. package/examples/node_modules/npm-run-path/index.js +47 -0
  283. package/examples/node_modules/npm-run-path/license +9 -0
  284. package/examples/node_modules/npm-run-path/package.json +76 -0
  285. package/examples/node_modules/npm-run-path/readme.md +115 -0
  286. package/examples/node_modules/onetime/index.d.ts +64 -0
  287. package/examples/node_modules/onetime/index.js +44 -0
  288. package/examples/node_modules/onetime/license +9 -0
  289. package/examples/node_modules/onetime/package.json +75 -0
  290. package/examples/node_modules/onetime/readme.md +94 -0
  291. package/examples/node_modules/p-limit/index.d.ts +38 -0
  292. package/examples/node_modules/p-limit/index.js +57 -0
  293. package/examples/node_modules/p-limit/license +9 -0
  294. package/examples/node_modules/p-limit/package.json +84 -0
  295. package/examples/node_modules/p-limit/readme.md +101 -0
  296. package/examples/node_modules/p-locate/index.d.ts +64 -0
  297. package/examples/node_modules/p-locate/index.js +52 -0
  298. package/examples/node_modules/p-locate/license +9 -0
  299. package/examples/node_modules/p-locate/package.json +85 -0
  300. package/examples/node_modules/p-locate/readme.md +90 -0
  301. package/examples/node_modules/p-try/index.d.ts +39 -0
  302. package/examples/node_modules/p-try/index.js +9 -0
  303. package/examples/node_modules/p-try/license +9 -0
  304. package/examples/node_modules/p-try/package.json +74 -0
  305. package/examples/node_modules/p-try/readme.md +58 -0
  306. package/examples/node_modules/path-exists/index.d.ts +28 -0
  307. package/examples/node_modules/path-exists/index.js +23 -0
  308. package/examples/node_modules/path-exists/license +9 -0
  309. package/examples/node_modules/path-exists/package.json +71 -0
  310. package/examples/node_modules/path-exists/readme.md +52 -0
  311. package/examples/node_modules/path-key/index.d.ts +40 -0
  312. package/examples/node_modules/path-key/index.js +16 -0
  313. package/examples/node_modules/path-key/license +9 -0
  314. package/examples/node_modules/path-key/package.json +72 -0
  315. package/examples/node_modules/path-key/readme.md +61 -0
  316. package/examples/node_modules/path-parse/.travis.yml +9 -0
  317. package/examples/node_modules/path-parse/LICENSE +21 -0
  318. package/examples/node_modules/path-parse/README.md +42 -0
  319. package/examples/node_modules/path-parse/index.js +93 -0
  320. package/examples/node_modules/path-parse/package.json +61 -0
  321. package/examples/node_modules/path-parse/test.js +77 -0
  322. package/examples/node_modules/pkg-dir/index.d.ts +44 -0
  323. package/examples/node_modules/pkg-dir/index.js +17 -0
  324. package/examples/node_modules/pkg-dir/license +9 -0
  325. package/examples/node_modules/pkg-dir/package.json +88 -0
  326. package/examples/node_modules/pkg-dir/readme.md +66 -0
  327. package/examples/node_modules/rechoir/LICENSE +24 -0
  328. package/examples/node_modules/rechoir/README.md +74 -0
  329. package/examples/node_modules/rechoir/index.js +67 -0
  330. package/examples/node_modules/rechoir/lib/extension.js +19 -0
  331. package/examples/node_modules/rechoir/lib/normalize.js +13 -0
  332. package/examples/node_modules/rechoir/lib/register.js +15 -0
  333. package/examples/node_modules/rechoir/package.json +89 -0
  334. package/examples/node_modules/resolve/.editorconfig +37 -0
  335. package/examples/node_modules/resolve/.eslintignore +1 -0
  336. package/examples/node_modules/resolve/.eslintrc +39 -0
  337. package/examples/node_modules/resolve/LICENSE +21 -0
  338. package/examples/node_modules/resolve/SECURITY.md +3 -0
  339. package/examples/node_modules/resolve/appveyor.yml +74 -0
  340. package/examples/node_modules/resolve/example/async.js +5 -0
  341. package/examples/node_modules/resolve/example/sync.js +3 -0
  342. package/examples/node_modules/resolve/index.js +6 -0
  343. package/examples/node_modules/resolve/lib/async.js +320 -0
  344. package/examples/node_modules/resolve/lib/caller.js +8 -0
  345. package/examples/node_modules/resolve/lib/core.js +53 -0
  346. package/examples/node_modules/resolve/lib/core.json +83 -0
  347. package/examples/node_modules/resolve/lib/is-core.js +5 -0
  348. package/examples/node_modules/resolve/lib/node-modules-paths.js +42 -0
  349. package/examples/node_modules/resolve/lib/normalize-options.js +10 -0
  350. package/examples/node_modules/resolve/lib/sync.js +199 -0
  351. package/examples/node_modules/resolve/package.json +80 -0
  352. package/examples/node_modules/resolve/readme.markdown +279 -0
  353. package/examples/node_modules/resolve/test/.eslintrc +5 -0
  354. package/examples/node_modules/resolve/test/core.js +81 -0
  355. package/examples/node_modules/resolve/test/dotdot/abc/index.js +2 -0
  356. package/examples/node_modules/resolve/test/dotdot/index.js +1 -0
  357. package/examples/node_modules/resolve/test/dotdot.js +29 -0
  358. package/examples/node_modules/resolve/test/faulty_basedir.js +29 -0
  359. package/examples/node_modules/resolve/test/filter.js +34 -0
  360. package/examples/node_modules/resolve/test/filter_sync.js +33 -0
  361. package/examples/node_modules/resolve/test/mock.js +315 -0
  362. package/examples/node_modules/resolve/test/mock_sync.js +216 -0
  363. package/examples/node_modules/resolve/test/module_dir/xmodules/aaa/index.js +1 -0
  364. package/examples/node_modules/resolve/test/module_dir/ymodules/aaa/index.js +1 -0
  365. package/examples/node_modules/resolve/test/module_dir/zmodules/bbb/main.js +1 -0
  366. package/examples/node_modules/resolve/test/module_dir/zmodules/bbb/package.json +3 -0
  367. package/examples/node_modules/resolve/test/module_dir.js +56 -0
  368. package/examples/node_modules/resolve/test/node-modules-paths.js +143 -0
  369. package/examples/node_modules/resolve/test/node_path/x/aaa/index.js +1 -0
  370. package/examples/node_modules/resolve/test/node_path/x/ccc/index.js +1 -0
  371. package/examples/node_modules/resolve/test/node_path/y/bbb/index.js +1 -0
  372. package/examples/node_modules/resolve/test/node_path/y/ccc/index.js +1 -0
  373. package/examples/node_modules/resolve/test/node_path.js +70 -0
  374. package/examples/node_modules/resolve/test/nonstring.js +9 -0
  375. package/examples/node_modules/resolve/test/pathfilter/deep_ref/main.js +0 -0
  376. package/examples/node_modules/resolve/test/pathfilter.js +75 -0
  377. package/examples/node_modules/resolve/test/precedence/aaa/index.js +1 -0
  378. package/examples/node_modules/resolve/test/precedence/aaa/main.js +1 -0
  379. package/examples/node_modules/resolve/test/precedence/aaa.js +1 -0
  380. package/examples/node_modules/resolve/test/precedence/bbb/main.js +1 -0
  381. package/examples/node_modules/resolve/test/precedence/bbb.js +1 -0
  382. package/examples/node_modules/resolve/test/precedence.js +23 -0
  383. package/examples/node_modules/resolve/test/resolver/baz/doom.js +0 -0
  384. package/examples/node_modules/resolve/test/resolver/baz/package.json +4 -0
  385. package/examples/node_modules/resolve/test/resolver/baz/quux.js +1 -0
  386. package/examples/node_modules/resolve/test/resolver/browser_field/a.js +0 -0
  387. package/examples/node_modules/resolve/test/resolver/browser_field/b.js +0 -0
  388. package/examples/node_modules/resolve/test/resolver/browser_field/package.json +5 -0
  389. package/examples/node_modules/resolve/test/resolver/cup.coffee +1 -0
  390. package/examples/node_modules/resolve/test/resolver/dot_main/index.js +1 -0
  391. package/examples/node_modules/resolve/test/resolver/dot_main/package.json +3 -0
  392. package/examples/node_modules/resolve/test/resolver/dot_slash_main/index.js +1 -0
  393. package/examples/node_modules/resolve/test/resolver/dot_slash_main/package.json +3 -0
  394. package/examples/node_modules/resolve/test/resolver/foo.js +1 -0
  395. package/examples/node_modules/resolve/test/resolver/incorrect_main/index.js +2 -0
  396. package/examples/node_modules/resolve/test/resolver/incorrect_main/package.json +3 -0
  397. package/examples/node_modules/resolve/test/resolver/invalid_main/package.json +7 -0
  398. package/examples/node_modules/resolve/test/resolver/mug.coffee +0 -0
  399. package/examples/node_modules/resolve/test/resolver/mug.js +0 -0
  400. package/examples/node_modules/resolve/test/resolver/multirepo/lerna.json +6 -0
  401. package/examples/node_modules/resolve/test/resolver/multirepo/package.json +20 -0
  402. package/examples/node_modules/resolve/test/resolver/multirepo/packages/package-a/index.js +35 -0
  403. package/examples/node_modules/resolve/test/resolver/multirepo/packages/package-a/package.json +14 -0
  404. package/examples/node_modules/resolve/test/resolver/multirepo/packages/package-b/index.js +0 -0
  405. package/examples/node_modules/resolve/test/resolver/multirepo/packages/package-b/package.json +14 -0
  406. package/examples/node_modules/resolve/test/resolver/nested_symlinks/mylib/async.js +26 -0
  407. package/examples/node_modules/resolve/test/resolver/nested_symlinks/mylib/package.json +15 -0
  408. package/examples/node_modules/resolve/test/resolver/nested_symlinks/mylib/sync.js +12 -0
  409. package/examples/node_modules/resolve/test/resolver/other_path/lib/other-lib.js +0 -0
  410. package/examples/node_modules/resolve/test/resolver/other_path/root.js +0 -0
  411. package/examples/node_modules/resolve/test/resolver/quux/foo/index.js +1 -0
  412. package/examples/node_modules/resolve/test/resolver/same_names/foo/index.js +1 -0
  413. package/examples/node_modules/resolve/test/resolver/same_names/foo.js +1 -0
  414. package/examples/node_modules/resolve/test/resolver/symlinked/_/node_modules/foo.js +0 -0
  415. package/examples/node_modules/resolve/test/resolver/symlinked/_/symlink_target/.gitkeep +0 -0
  416. package/examples/node_modules/resolve/test/resolver/symlinked/package/bar.js +1 -0
  417. package/examples/node_modules/resolve/test/resolver/symlinked/package/package.json +3 -0
  418. package/examples/node_modules/resolve/test/resolver/without_basedir/main.js +5 -0
  419. package/examples/node_modules/resolve/test/resolver.js +450 -0
  420. package/examples/node_modules/resolve/test/resolver_sync.js +358 -0
  421. package/examples/node_modules/resolve/test/shadowed_core/node_modules/util/index.js +0 -0
  422. package/examples/node_modules/resolve/test/shadowed_core.js +54 -0
  423. package/examples/node_modules/resolve/test/subdirs.js +13 -0
  424. package/examples/node_modules/resolve/test/symlinks.js +176 -0
  425. package/examples/node_modules/resolve-cwd/index.d.ts +48 -0
  426. package/examples/node_modules/resolve-cwd/index.js +5 -0
  427. package/examples/node_modules/resolve-cwd/license +9 -0
  428. package/examples/node_modules/resolve-cwd/package.json +75 -0
  429. package/examples/node_modules/resolve-cwd/readme.md +58 -0
  430. package/examples/node_modules/resolve-from/index.d.ts +31 -0
  431. package/examples/node_modules/resolve-from/index.js +47 -0
  432. package/examples/node_modules/resolve-from/license +9 -0
  433. package/examples/node_modules/resolve-from/package.json +68 -0
  434. package/examples/node_modules/resolve-from/readme.md +72 -0
  435. package/examples/node_modules/shallow-clone/LICENSE +21 -0
  436. package/examples/node_modules/shallow-clone/README.md +153 -0
  437. package/examples/node_modules/shallow-clone/index.js +83 -0
  438. package/examples/node_modules/shallow-clone/package.json +101 -0
  439. package/examples/node_modules/shebang-command/index.js +19 -0
  440. package/examples/node_modules/shebang-command/license +9 -0
  441. package/examples/node_modules/shebang-command/package.json +66 -0
  442. package/examples/node_modules/shebang-command/readme.md +34 -0
  443. package/examples/node_modules/shebang-regex/index.d.ts +22 -0
  444. package/examples/node_modules/shebang-regex/index.js +2 -0
  445. package/examples/node_modules/shebang-regex/license +9 -0
  446. package/examples/node_modules/shebang-regex/package.json +67 -0
  447. package/examples/node_modules/shebang-regex/readme.md +33 -0
  448. package/examples/node_modules/signal-exit/CHANGELOG.md +35 -0
  449. package/examples/node_modules/signal-exit/LICENSE.txt +16 -0
  450. package/examples/node_modules/signal-exit/README.md +39 -0
  451. package/examples/node_modules/signal-exit/index.js +163 -0
  452. package/examples/node_modules/signal-exit/package.json +66 -0
  453. package/examples/node_modules/signal-exit/signals.js +53 -0
  454. package/examples/node_modules/strip-final-newline/index.js +16 -0
  455. package/examples/node_modules/strip-final-newline/license +9 -0
  456. package/examples/node_modules/strip-final-newline/package.json +72 -0
  457. package/examples/node_modules/strip-final-newline/readme.md +30 -0
  458. package/examples/node_modules/v8-compile-cache/CHANGELOG.md +53 -0
  459. package/examples/node_modules/v8-compile-cache/LICENSE +21 -0
  460. package/examples/node_modules/v8-compile-cache/README.md +55 -0
  461. package/examples/node_modules/v8-compile-cache/package.json +66 -0
  462. package/examples/node_modules/v8-compile-cache/v8-compile-cache.js +371 -0
  463. package/examples/node_modules/webpack-cli/CHANGELOG.md +501 -0
  464. package/examples/node_modules/webpack-cli/LICENSE +20 -0
  465. package/examples/node_modules/webpack-cli/README.md +116 -0
  466. package/examples/node_modules/webpack-cli/bin/cli.js +40 -0
  467. package/examples/node_modules/webpack-cli/lib/bootstrap.js +18 -0
  468. package/examples/node_modules/webpack-cli/lib/index.js +5 -0
  469. package/examples/node_modules/webpack-cli/lib/plugins/CLIPlugin.js +99 -0
  470. package/examples/node_modules/webpack-cli/lib/utils/__tests__/get-package-manager.test.js +108 -0
  471. package/examples/node_modules/webpack-cli/lib/utils/__tests__/prompt-installation.test.js +118 -0
  472. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-all-lock/package-lock.json +0 -0
  473. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-all-lock/pnpm-lock.yaml +0 -0
  474. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-all-lock/yarn.lock +0 -0
  475. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-npm-and-pnpm/package-lock.json +0 -0
  476. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-npm-and-pnpm/pnpm-lock.yaml +0 -0
  477. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-npm-and-yarn/package-lock.json +0 -0
  478. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-npm-and-yarn/yarn.lock +0 -0
  479. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-npm-lock/package-lock.json +0 -0
  480. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-pnpm-lock/pnpm-lock.yaml +0 -0
  481. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-yarn-and-pnpm/pnpm-lock.yaml +0 -0
  482. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-yarn-and-pnpm/yarn.lock +0 -0
  483. package/examples/node_modules/webpack-cli/lib/utils/__tests__/test-yarn-lock/yarn.lock +0 -0
  484. package/examples/node_modules/webpack-cli/lib/utils/capitalize-first-letter.js +9 -0
  485. package/examples/node_modules/webpack-cli/lib/utils/dynamic-import-loader.js +13 -0
  486. package/examples/node_modules/webpack-cli/lib/utils/get-package-manager.js +65 -0
  487. package/examples/node_modules/webpack-cli/lib/utils/index.js +49 -0
  488. package/examples/node_modules/webpack-cli/lib/utils/logger.js +11 -0
  489. package/examples/node_modules/webpack-cli/lib/utils/package-exists.js +9 -0
  490. package/examples/node_modules/webpack-cli/lib/utils/prompt-installation.js +58 -0
  491. package/examples/node_modules/webpack-cli/lib/utils/run-command.js +13 -0
  492. package/examples/node_modules/webpack-cli/lib/utils/to-kebab-case.js +5 -0
  493. package/examples/node_modules/webpack-cli/lib/webpack-cli.js +1803 -0
  494. package/examples/node_modules/webpack-cli/package.json +96 -0
  495. package/examples/node_modules/webpack-merge/CHANGELOG.md +421 -0
  496. package/examples/node_modules/webpack-merge/LICENSE +20 -0
  497. package/examples/node_modules/webpack-merge/README.md +314 -0
  498. package/examples/node_modules/webpack-merge/dist/index.d.ts +15 -0
  499. package/examples/node_modules/webpack-merge/dist/index.js +262 -0
  500. package/examples/node_modules/webpack-merge/dist/index.js.map +1 -0
  501. package/examples/node_modules/webpack-merge/dist/join-arrays.d.ts +6 -0
  502. package/examples/node_modules/webpack-merge/dist/join-arrays.js +69 -0
  503. package/examples/node_modules/webpack-merge/dist/join-arrays.js.map +1 -0
  504. package/examples/node_modules/webpack-merge/dist/merge-with.d.ts +2 -0
  505. package/examples/node_modules/webpack-merge/dist/merge-with.js +38 -0
  506. package/examples/node_modules/webpack-merge/dist/merge-with.js.map +1 -0
  507. package/examples/node_modules/webpack-merge/dist/types.d.ts +13 -0
  508. package/examples/node_modules/webpack-merge/dist/types.js +12 -0
  509. package/examples/node_modules/webpack-merge/dist/types.js.map +1 -0
  510. package/examples/node_modules/webpack-merge/dist/unique.d.ts +2 -0
  511. package/examples/node_modules/webpack-merge/dist/unique.js +40 -0
  512. package/examples/node_modules/webpack-merge/dist/unique.js.map +1 -0
  513. package/examples/node_modules/webpack-merge/dist/utils.d.ts +5 -0
  514. package/examples/node_modules/webpack-merge/dist/utils.js +24 -0
  515. package/examples/node_modules/webpack-merge/dist/utils.js.map +1 -0
  516. package/examples/node_modules/webpack-merge/package.json +86 -0
  517. package/examples/node_modules/which/CHANGELOG.md +166 -0
  518. package/examples/node_modules/which/LICENSE +15 -0
  519. package/examples/node_modules/which/README.md +54 -0
  520. package/examples/node_modules/which/bin/node-which +52 -0
  521. package/examples/node_modules/which/package.json +76 -0
  522. package/examples/node_modules/which/which.js +125 -0
  523. package/examples/node_modules/wildcard/.travis.yml +9 -0
  524. package/examples/node_modules/wildcard/README.md +99 -0
  525. package/examples/node_modules/wildcard/docs.json +9 -0
  526. package/examples/node_modules/wildcard/examples/arrays.js +10 -0
  527. package/examples/node_modules/wildcard/examples/objects.js +10 -0
  528. package/examples/node_modules/wildcard/examples/strings.js +7 -0
  529. package/examples/node_modules/wildcard/index.js +114 -0
  530. package/examples/node_modules/wildcard/package.json +82 -0
  531. package/examples/node_modules/wildcard/test/all.js +3 -0
  532. package/examples/node_modules/wildcard/test/arrays.js +33 -0
  533. package/examples/node_modules/wildcard/test/objects.js +106 -0
  534. package/examples/node_modules/wildcard/test/strings.js +46 -0
  535. package/examples/node_modules/wildcard/yarn.lock +228 -0
  536. package/lib/browser/math.js +10 -10
  537. package/lib/browser/math.js.map +1 -1
  538. package/lib/cjs/core/create.js +8 -7
  539. package/lib/cjs/core/function/import.js +9 -7
  540. package/lib/cjs/core/function/typed.js +6 -1
  541. package/lib/cjs/defaultInstance.js +3 -3
  542. package/lib/cjs/entry/allFactoriesAny.js +3 -3
  543. package/lib/cjs/entry/allFactoriesNumber.js +3 -3
  544. package/lib/cjs/entry/configReadonly.js +5 -4
  545. package/lib/cjs/entry/dependenciesAny/dependenciesEigs.generated.js +51 -0
  546. package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromColumns.generated.js +29 -0
  547. package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromFunction.generated.js +26 -0
  548. package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromRows.generated.js +29 -0
  549. package/lib/cjs/entry/dependenciesAny.generated.js +24 -0
  550. package/lib/cjs/entry/impureFunctionsAny.generated.js +22 -17
  551. package/lib/cjs/entry/impureFunctionsNumber.generated.js +11 -9
  552. package/lib/cjs/entry/pureFunctionsAny.generated.js +78 -41
  553. package/lib/cjs/expression/Parser.js +22 -15
  554. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +9 -0
  555. package/lib/cjs/expression/embeddedDocs/function/matrix/column.js +1 -1
  556. package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromColumns.js +15 -0
  557. package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromFunction.js +15 -0
  558. package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromRows.js +15 -0
  559. package/lib/cjs/expression/embeddedDocs/function/matrix/row.js +1 -1
  560. package/lib/cjs/expression/function/evaluate.js +6 -4
  561. package/lib/cjs/expression/keywords.js +1 -3
  562. package/lib/cjs/expression/node/AccessorNode.js +1 -0
  563. package/lib/cjs/expression/node/AssignmentNode.js +6 -3
  564. package/lib/cjs/expression/node/FunctionAssignmentNode.js +2 -4
  565. package/lib/cjs/expression/node/FunctionNode.js +86 -39
  566. package/lib/cjs/expression/node/IndexNode.js +5 -13
  567. package/lib/cjs/expression/node/Node.js +15 -9
  568. package/lib/cjs/expression/node/ObjectNode.js +5 -3
  569. package/lib/cjs/expression/node/SymbolNode.js +4 -4
  570. package/lib/cjs/expression/node/utils/access.js +5 -3
  571. package/lib/cjs/expression/node/utils/assign.js +5 -3
  572. package/lib/cjs/expression/parse.js +23 -20
  573. package/lib/cjs/expression/transform/utils/compileInlineExpression.js +5 -3
  574. package/lib/cjs/factoriesAny.js +24 -0
  575. package/lib/cjs/function/algebra/decomposition/qr.js +5 -3
  576. package/lib/cjs/function/algebra/simplify/resolve.js +7 -1
  577. package/lib/cjs/function/algebra/simplify.js +20 -14
  578. package/lib/cjs/function/algebra/solver/lsolveAll.js +9 -19
  579. package/lib/cjs/function/algebra/solver/usolveAll.js +9 -19
  580. package/lib/cjs/function/arithmetic/ceil.js +6 -16
  581. package/lib/cjs/function/arithmetic/floor.js +6 -16
  582. package/lib/cjs/function/arithmetic/norm.js +2 -2
  583. package/lib/cjs/function/arithmetic/pow.js +9 -7
  584. package/lib/cjs/function/arithmetic/round.js +7 -5
  585. package/lib/cjs/function/complex/im.js +3 -0
  586. package/lib/cjs/function/complex/re.js +3 -0
  587. package/lib/cjs/function/matrix/eigs/complexEigs.js +631 -0
  588. package/lib/cjs/function/matrix/eigs/realSymetric.js +341 -0
  589. package/lib/cjs/function/matrix/eigs.js +188 -334
  590. package/lib/cjs/function/matrix/flatten.js +1 -0
  591. package/lib/cjs/function/matrix/matrixFromColumns.js +118 -0
  592. package/lib/cjs/function/matrix/matrixFromFunction.js +85 -0
  593. package/lib/cjs/function/matrix/matrixFromRows.js +108 -0
  594. package/lib/cjs/function/probability/pickRandom.js +1 -1
  595. package/lib/cjs/function/probability/util/seededRNG.js +2 -2
  596. package/lib/cjs/function/relational/compareNatural.js +2 -2
  597. package/lib/cjs/function/utils/isPrime.js +67 -3
  598. package/lib/cjs/header.js +2 -2
  599. package/lib/cjs/plain/bignumber/index.js +2 -2
  600. package/lib/cjs/type/bignumber/BigNumber.js +2 -2
  601. package/lib/cjs/type/bignumber/function/bignumber.js +4 -4
  602. package/lib/cjs/type/complex/Complex.js +5 -5
  603. package/lib/cjs/type/fraction/Fraction.js +2 -2
  604. package/lib/cjs/type/matrix/DenseMatrix.js +138 -0
  605. package/lib/cjs/type/matrix/Matrix.js +10 -0
  606. package/lib/cjs/type/matrix/SparseMatrix.js +77 -3
  607. package/lib/cjs/type/matrix/function/matrix.js +2 -1
  608. package/lib/cjs/type/number.js +63 -5
  609. package/lib/cjs/type/unit/Unit.js +15 -13
  610. package/lib/cjs/utils/array.js +1 -1
  611. package/lib/cjs/utils/customs.js +18 -4
  612. package/lib/cjs/utils/emitter.js +2 -2
  613. package/lib/cjs/utils/function.js +6 -2
  614. package/lib/cjs/utils/is.js +7 -5
  615. package/lib/cjs/utils/latex.js +2 -2
  616. package/lib/cjs/utils/map.js +197 -0
  617. package/lib/cjs/utils/object.js +6 -5
  618. package/lib/cjs/utils/scope.js +33 -0
  619. package/lib/cjs/utils/snapshot.js +17 -16
  620. package/lib/cjs/utils/string.js +6 -4
  621. package/lib/cjs/version.js +1 -1
  622. package/lib/esm/constants.js +15 -15
  623. package/lib/esm/core/create.js +1 -2
  624. package/lib/esm/core/function/typed.js +5 -1
  625. package/lib/esm/entry/configReadonly.js +1 -2
  626. package/lib/esm/entry/dependenciesAny/dependenciesEigs.generated.js +34 -0
  627. package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromColumns.generated.js +16 -0
  628. package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromFunction.generated.js +14 -0
  629. package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromRows.generated.js +16 -0
  630. package/lib/esm/entry/dependenciesAny.generated.js +3 -0
  631. package/lib/esm/entry/impureFunctionsAny.generated.js +13 -10
  632. package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -1
  633. package/lib/esm/entry/pureFunctionsAny.generated.js +66 -32
  634. package/lib/esm/expression/Help.js +1 -1
  635. package/lib/esm/expression/Parser.js +23 -15
  636. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +6 -0
  637. package/lib/esm/expression/embeddedDocs/function/matrix/column.js +1 -1
  638. package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromColumns.js +8 -0
  639. package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromFunction.js +8 -0
  640. package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromRows.js +8 -0
  641. package/lib/esm/expression/embeddedDocs/function/matrix/row.js +1 -1
  642. package/lib/esm/expression/function/compile.js +1 -1
  643. package/lib/esm/expression/function/evaluate.js +6 -5
  644. package/lib/esm/expression/function/help.js +1 -1
  645. package/lib/esm/expression/function/parser.js +1 -1
  646. package/lib/esm/expression/keywords.js +1 -3
  647. package/lib/esm/expression/node/AccessorNode.js +2 -1
  648. package/lib/esm/expression/node/ArrayNode.js +1 -1
  649. package/lib/esm/expression/node/AssignmentNode.js +7 -4
  650. package/lib/esm/expression/node/BlockNode.js +1 -1
  651. package/lib/esm/expression/node/ConditionalNode.js +1 -1
  652. package/lib/esm/expression/node/ConstantNode.js +1 -1
  653. package/lib/esm/expression/node/FunctionAssignmentNode.js +3 -4
  654. package/lib/esm/expression/node/FunctionNode.js +68 -33
  655. package/lib/esm/expression/node/IndexNode.js +1 -1
  656. package/lib/esm/expression/node/Node.js +7 -8
  657. package/lib/esm/expression/node/ObjectNode.js +1 -1
  658. package/lib/esm/expression/node/OperatorNode.js +1 -1
  659. package/lib/esm/expression/node/ParenthesisNode.js +1 -1
  660. package/lib/esm/expression/node/RangeNode.js +1 -1
  661. package/lib/esm/expression/node/RelationalNode.js +1 -1
  662. package/lib/esm/expression/node/SymbolNode.js +5 -5
  663. package/lib/esm/expression/parse.js +15 -9
  664. package/lib/esm/expression/transform/apply.transform.js +1 -1
  665. package/lib/esm/expression/transform/column.transform.js +1 -1
  666. package/lib/esm/expression/transform/concat.transform.js +1 -1
  667. package/lib/esm/expression/transform/diff.transform.js +1 -1
  668. package/lib/esm/expression/transform/filter.transform.js +1 -1
  669. package/lib/esm/expression/transform/forEach.transform.js +1 -1
  670. package/lib/esm/expression/transform/index.transform.js +1 -1
  671. package/lib/esm/expression/transform/map.transform.js +1 -1
  672. package/lib/esm/expression/transform/max.transform.js +1 -1
  673. package/lib/esm/expression/transform/mean.transform.js +1 -1
  674. package/lib/esm/expression/transform/min.transform.js +1 -1
  675. package/lib/esm/expression/transform/range.transform.js +1 -1
  676. package/lib/esm/expression/transform/row.transform.js +1 -1
  677. package/lib/esm/expression/transform/std.transform.js +1 -1
  678. package/lib/esm/expression/transform/subset.transform.js +1 -1
  679. package/lib/esm/expression/transform/sum.transform.js +1 -1
  680. package/lib/esm/expression/transform/utils/compileInlineExpression.js +4 -3
  681. package/lib/esm/expression/transform/variance.transform.js +1 -1
  682. package/lib/esm/factoriesAny.js +3 -0
  683. package/lib/esm/factoriesNumber.js +1 -1
  684. package/lib/esm/function/algebra/decomposition/lup.js +1 -1
  685. package/lib/esm/function/algebra/decomposition/qr.js +2 -3
  686. package/lib/esm/function/algebra/decomposition/slu.js +1 -1
  687. package/lib/esm/function/algebra/derivative.js +1 -1
  688. package/lib/esm/function/algebra/rationalize.js +1 -1
  689. package/lib/esm/function/algebra/simplify/resolve.js +7 -2
  690. package/lib/esm/function/algebra/simplify/simplifyConstant.js +1 -1
  691. package/lib/esm/function/algebra/simplify/simplifyCore.js +1 -1
  692. package/lib/esm/function/algebra/simplify/util.js +1 -1
  693. package/lib/esm/function/algebra/simplify.js +16 -12
  694. package/lib/esm/function/algebra/solver/lsolve.js +1 -1
  695. package/lib/esm/function/algebra/solver/lsolveAll.js +4 -4
  696. package/lib/esm/function/algebra/solver/lusolve.js +1 -1
  697. package/lib/esm/function/algebra/solver/usolve.js +1 -1
  698. package/lib/esm/function/algebra/solver/usolveAll.js +4 -4
  699. package/lib/esm/function/algebra/sparse/csAmd.js +1 -1
  700. package/lib/esm/function/algebra/sparse/csChol.js +1 -1
  701. package/lib/esm/function/algebra/sparse/csCounts.js +1 -1
  702. package/lib/esm/function/algebra/sparse/csLu.js +1 -1
  703. package/lib/esm/function/algebra/sparse/csSpsolve.js +1 -1
  704. package/lib/esm/function/algebra/sparse/csSqr.js +1 -1
  705. package/lib/esm/function/algebra/sparse/csSymperm.js +1 -1
  706. package/lib/esm/function/arithmetic/abs.js +1 -1
  707. package/lib/esm/function/arithmetic/add.js +1 -1
  708. package/lib/esm/function/arithmetic/addScalar.js +1 -1
  709. package/lib/esm/function/arithmetic/cbrt.js +1 -1
  710. package/lib/esm/function/arithmetic/ceil.js +1 -1
  711. package/lib/esm/function/arithmetic/cube.js +1 -1
  712. package/lib/esm/function/arithmetic/divide.js +1 -1
  713. package/lib/esm/function/arithmetic/divideScalar.js +1 -1
  714. package/lib/esm/function/arithmetic/dotDivide.js +1 -1
  715. package/lib/esm/function/arithmetic/dotMultiply.js +1 -1
  716. package/lib/esm/function/arithmetic/dotPow.js +1 -1
  717. package/lib/esm/function/arithmetic/exp.js +1 -1
  718. package/lib/esm/function/arithmetic/expm1.js +1 -1
  719. package/lib/esm/function/arithmetic/fix.js +1 -1
  720. package/lib/esm/function/arithmetic/floor.js +1 -1
  721. package/lib/esm/function/arithmetic/gcd.js +1 -1
  722. package/lib/esm/function/arithmetic/hypot.js +1 -1
  723. package/lib/esm/function/arithmetic/lcm.js +1 -1
  724. package/lib/esm/function/arithmetic/log.js +1 -1
  725. package/lib/esm/function/arithmetic/log10.js +1 -1
  726. package/lib/esm/function/arithmetic/log1p.js +1 -1
  727. package/lib/esm/function/arithmetic/log2.js +1 -1
  728. package/lib/esm/function/arithmetic/mod.js +1 -1
  729. package/lib/esm/function/arithmetic/multiply.js +1 -1
  730. package/lib/esm/function/arithmetic/multiplyScalar.js +1 -1
  731. package/lib/esm/function/arithmetic/norm.js +3 -3
  732. package/lib/esm/function/arithmetic/nthRoot.js +2 -2
  733. package/lib/esm/function/arithmetic/nthRoots.js +1 -1
  734. package/lib/esm/function/arithmetic/pow.js +10 -8
  735. package/lib/esm/function/arithmetic/round.js +6 -6
  736. package/lib/esm/function/arithmetic/sign.js +1 -1
  737. package/lib/esm/function/arithmetic/sqrt.js +1 -1
  738. package/lib/esm/function/arithmetic/square.js +1 -1
  739. package/lib/esm/function/arithmetic/subtract.js +1 -1
  740. package/lib/esm/function/arithmetic/unaryMinus.js +1 -1
  741. package/lib/esm/function/arithmetic/unaryPlus.js +1 -1
  742. package/lib/esm/function/arithmetic/xgcd.js +1 -1
  743. package/lib/esm/function/bitwise/bitAnd.js +1 -1
  744. package/lib/esm/function/bitwise/bitNot.js +1 -1
  745. package/lib/esm/function/bitwise/bitOr.js +1 -1
  746. package/lib/esm/function/bitwise/bitXor.js +1 -1
  747. package/lib/esm/function/bitwise/leftShift.js +1 -1
  748. package/lib/esm/function/bitwise/rightArithShift.js +1 -1
  749. package/lib/esm/function/bitwise/rightLogShift.js +1 -1
  750. package/lib/esm/function/combinatorics/bellNumbers.js +1 -1
  751. package/lib/esm/function/combinatorics/catalan.js +1 -1
  752. package/lib/esm/function/combinatorics/composition.js +1 -1
  753. package/lib/esm/function/combinatorics/stirlingS2.js +1 -1
  754. package/lib/esm/function/complex/arg.js +1 -1
  755. package/lib/esm/function/complex/conj.js +1 -1
  756. package/lib/esm/function/complex/im.js +4 -1
  757. package/lib/esm/function/complex/re.js +4 -1
  758. package/lib/esm/function/geometry/distance.js +1 -1
  759. package/lib/esm/function/geometry/intersect.js +1 -1
  760. package/lib/esm/function/logical/and.js +1 -1
  761. package/lib/esm/function/logical/not.js +1 -1
  762. package/lib/esm/function/logical/or.js +1 -1
  763. package/lib/esm/function/logical/xor.js +1 -1
  764. package/lib/esm/function/matrix/apply.js +1 -1
  765. package/lib/esm/function/matrix/column.js +1 -1
  766. package/lib/esm/function/matrix/concat.js +1 -1
  767. package/lib/esm/function/matrix/count.js +1 -1
  768. package/lib/esm/function/matrix/cross.js +1 -1
  769. package/lib/esm/function/matrix/ctranspose.js +1 -1
  770. package/lib/esm/function/matrix/det.js +1 -1
  771. package/lib/esm/function/matrix/diag.js +1 -1
  772. package/lib/esm/function/matrix/diff.js +1 -1
  773. package/lib/esm/function/matrix/dot.js +1 -1
  774. package/lib/esm/function/matrix/eigs/complexEigs.js +586 -0
  775. package/lib/esm/function/matrix/eigs/realSymetric.js +335 -0
  776. package/lib/esm/function/matrix/eigs.js +187 -335
  777. package/lib/esm/function/matrix/expm.js +1 -1
  778. package/lib/esm/function/matrix/filter.js +1 -1
  779. package/lib/esm/function/matrix/flatten.js +2 -1
  780. package/lib/esm/function/matrix/forEach.js +1 -1
  781. package/lib/esm/function/matrix/getMatrixDataType.js +1 -1
  782. package/lib/esm/function/matrix/identity.js +1 -1
  783. package/lib/esm/function/matrix/inv.js +1 -1
  784. package/lib/esm/function/matrix/kron.js +1 -1
  785. package/lib/esm/function/matrix/map.js +1 -1
  786. package/lib/esm/function/matrix/matrixFromColumns.js +93 -0
  787. package/lib/esm/function/matrix/matrixFromFunction.js +78 -0
  788. package/lib/esm/function/matrix/matrixFromRows.js +83 -0
  789. package/lib/esm/function/matrix/ones.js +1 -1
  790. package/lib/esm/function/matrix/partitionSelect.js +1 -1
  791. package/lib/esm/function/matrix/range.js +1 -1
  792. package/lib/esm/function/matrix/reshape.js +1 -1
  793. package/lib/esm/function/matrix/resize.js +1 -1
  794. package/lib/esm/function/matrix/rotate.js +1 -1
  795. package/lib/esm/function/matrix/rotationMatrix.js +1 -1
  796. package/lib/esm/function/matrix/row.js +1 -1
  797. package/lib/esm/function/matrix/size.js +1 -1
  798. package/lib/esm/function/matrix/sort.js +1 -1
  799. package/lib/esm/function/matrix/sqrtm.js +1 -1
  800. package/lib/esm/function/matrix/squeeze.js +1 -1
  801. package/lib/esm/function/matrix/subset.js +1 -1
  802. package/lib/esm/function/matrix/trace.js +1 -1
  803. package/lib/esm/function/matrix/transpose.js +1 -1
  804. package/lib/esm/function/matrix/zeros.js +1 -1
  805. package/lib/esm/function/probability/combinations.js +1 -1
  806. package/lib/esm/function/probability/combinationsWithRep.js +1 -1
  807. package/lib/esm/function/probability/factorial.js +1 -1
  808. package/lib/esm/function/probability/gamma.js +1 -1
  809. package/lib/esm/function/probability/kldivergence.js +1 -1
  810. package/lib/esm/function/probability/multinomial.js +1 -1
  811. package/lib/esm/function/probability/permutations.js +1 -1
  812. package/lib/esm/function/probability/pickRandom.js +2 -2
  813. package/lib/esm/function/probability/random.js +2 -2
  814. package/lib/esm/function/probability/randomInt.js +1 -1
  815. package/lib/esm/function/relational/compare.js +2 -2
  816. package/lib/esm/function/relational/compareNatural.js +1 -1
  817. package/lib/esm/function/relational/compareText.js +2 -2
  818. package/lib/esm/function/relational/deepEqual.js +1 -1
  819. package/lib/esm/function/relational/equal.js +2 -2
  820. package/lib/esm/function/relational/equalScalar.js +2 -2
  821. package/lib/esm/function/relational/equalText.js +1 -1
  822. package/lib/esm/function/relational/larger.js +2 -2
  823. package/lib/esm/function/relational/largerEq.js +2 -2
  824. package/lib/esm/function/relational/smaller.js +2 -2
  825. package/lib/esm/function/relational/smallerEq.js +2 -2
  826. package/lib/esm/function/relational/unequal.js +2 -2
  827. package/lib/esm/function/set/setCartesian.js +1 -1
  828. package/lib/esm/function/set/setDifference.js +1 -1
  829. package/lib/esm/function/set/setDistinct.js +1 -1
  830. package/lib/esm/function/set/setIntersect.js +1 -1
  831. package/lib/esm/function/set/setIsSubset.js +1 -1
  832. package/lib/esm/function/set/setMultiplicity.js +1 -1
  833. package/lib/esm/function/set/setPowerset.js +1 -1
  834. package/lib/esm/function/set/setSize.js +1 -1
  835. package/lib/esm/function/set/setSymDifference.js +1 -1
  836. package/lib/esm/function/set/setUnion.js +1 -1
  837. package/lib/esm/function/special/erf.js +1 -1
  838. package/lib/esm/function/statistics/mad.js +1 -1
  839. package/lib/esm/function/statistics/max.js +1 -1
  840. package/lib/esm/function/statistics/mean.js +1 -1
  841. package/lib/esm/function/statistics/median.js +1 -1
  842. package/lib/esm/function/statistics/min.js +1 -1
  843. package/lib/esm/function/statistics/mode.js +1 -1
  844. package/lib/esm/function/statistics/prod.js +1 -1
  845. package/lib/esm/function/statistics/quantileSeq.js +1 -1
  846. package/lib/esm/function/statistics/std.js +1 -1
  847. package/lib/esm/function/statistics/sum.js +1 -1
  848. package/lib/esm/function/statistics/variance.js +1 -1
  849. package/lib/esm/function/string/bin.js +1 -1
  850. package/lib/esm/function/string/format.js +1 -1
  851. package/lib/esm/function/string/hex.js +1 -1
  852. package/lib/esm/function/string/oct.js +1 -1
  853. package/lib/esm/function/string/print.js +1 -1
  854. package/lib/esm/function/trigonometry/acos.js +1 -1
  855. package/lib/esm/function/trigonometry/acosh.js +1 -1
  856. package/lib/esm/function/trigonometry/acot.js +1 -1
  857. package/lib/esm/function/trigonometry/acoth.js +1 -1
  858. package/lib/esm/function/trigonometry/acsc.js +1 -1
  859. package/lib/esm/function/trigonometry/acsch.js +1 -1
  860. package/lib/esm/function/trigonometry/asec.js +1 -1
  861. package/lib/esm/function/trigonometry/asech.js +1 -1
  862. package/lib/esm/function/trigonometry/asin.js +1 -1
  863. package/lib/esm/function/trigonometry/asinh.js +1 -1
  864. package/lib/esm/function/trigonometry/atan.js +1 -1
  865. package/lib/esm/function/trigonometry/atan2.js +1 -1
  866. package/lib/esm/function/trigonometry/atanh.js +1 -1
  867. package/lib/esm/function/trigonometry/cos.js +1 -1
  868. package/lib/esm/function/trigonometry/cosh.js +1 -1
  869. package/lib/esm/function/trigonometry/cot.js +1 -1
  870. package/lib/esm/function/trigonometry/coth.js +1 -1
  871. package/lib/esm/function/trigonometry/csc.js +1 -1
  872. package/lib/esm/function/trigonometry/csch.js +1 -1
  873. package/lib/esm/function/trigonometry/sec.js +1 -1
  874. package/lib/esm/function/trigonometry/sech.js +1 -1
  875. package/lib/esm/function/trigonometry/sin.js +1 -1
  876. package/lib/esm/function/trigonometry/sinh.js +1 -1
  877. package/lib/esm/function/trigonometry/tan.js +1 -1
  878. package/lib/esm/function/trigonometry/tanh.js +1 -1
  879. package/lib/esm/function/unit/to.js +1 -1
  880. package/lib/esm/function/utils/clone.js +1 -1
  881. package/lib/esm/function/utils/hasNumericValue.js +1 -1
  882. package/lib/esm/function/utils/isInteger.js +1 -1
  883. package/lib/esm/function/utils/isNaN.js +1 -1
  884. package/lib/esm/function/utils/isNegative.js +1 -1
  885. package/lib/esm/function/utils/isNumeric.js +1 -1
  886. package/lib/esm/function/utils/isPositive.js +1 -1
  887. package/lib/esm/function/utils/isPrime.js +66 -4
  888. package/lib/esm/function/utils/isZero.js +1 -1
  889. package/lib/esm/function/utils/numeric.js +1 -1
  890. package/lib/esm/function/utils/typeOf.js +1 -1
  891. package/lib/esm/json/reviver.js +1 -1
  892. package/lib/esm/type/bignumber/BigNumber.js +1 -1
  893. package/lib/esm/type/bignumber/function/bignumber.js +5 -5
  894. package/lib/esm/type/boolean.js +1 -1
  895. package/lib/esm/type/chain/Chain.js +1 -1
  896. package/lib/esm/type/chain/function/chain.js +1 -1
  897. package/lib/esm/type/complex/function/complex.js +1 -1
  898. package/lib/esm/type/fraction/function/fraction.js +1 -1
  899. package/lib/esm/type/matrix/DenseMatrix.js +75 -1
  900. package/lib/esm/type/matrix/FibonacciHeap.js +1 -1
  901. package/lib/esm/type/matrix/ImmutableDenseMatrix.js +1 -1
  902. package/lib/esm/type/matrix/Matrix.js +10 -0
  903. package/lib/esm/type/matrix/MatrixIndex.js +1 -1
  904. package/lib/esm/type/matrix/Spa.js +1 -1
  905. package/lib/esm/type/matrix/SparseMatrix.js +37 -3
  906. package/lib/esm/type/matrix/function/index.js +1 -1
  907. package/lib/esm/type/matrix/function/matrix.js +3 -2
  908. package/lib/esm/type/matrix/function/sparse.js +1 -1
  909. package/lib/esm/type/matrix/utils/algorithm01.js +1 -1
  910. package/lib/esm/type/matrix/utils/algorithm02.js +1 -1
  911. package/lib/esm/type/matrix/utils/algorithm03.js +1 -1
  912. package/lib/esm/type/matrix/utils/algorithm04.js +1 -1
  913. package/lib/esm/type/matrix/utils/algorithm05.js +1 -1
  914. package/lib/esm/type/matrix/utils/algorithm06.js +1 -1
  915. package/lib/esm/type/matrix/utils/algorithm07.js +1 -1
  916. package/lib/esm/type/matrix/utils/algorithm08.js +1 -1
  917. package/lib/esm/type/matrix/utils/algorithm09.js +1 -1
  918. package/lib/esm/type/matrix/utils/algorithm10.js +1 -1
  919. package/lib/esm/type/matrix/utils/algorithm11.js +1 -1
  920. package/lib/esm/type/matrix/utils/algorithm12.js +1 -1
  921. package/lib/esm/type/matrix/utils/algorithm13.js +1 -1
  922. package/lib/esm/type/matrix/utils/algorithm14.js +1 -1
  923. package/lib/esm/type/number.js +64 -6
  924. package/lib/esm/type/string.js +1 -1
  925. package/lib/esm/type/unit/Unit.js +4 -5
  926. package/lib/esm/type/unit/function/createUnit.js +1 -1
  927. package/lib/esm/type/unit/function/splitUnit.js +1 -1
  928. package/lib/esm/type/unit/function/unit.js +1 -1
  929. package/lib/esm/type/unit/physicalConstants.js +2 -2
  930. package/lib/esm/utils/array.js +1 -1
  931. package/lib/esm/utils/customs.js +10 -0
  932. package/lib/esm/utils/map.js +135 -0
  933. package/lib/esm/utils/scope.js +26 -0
  934. package/lib/esm/utils/snapshot.js +3 -4
  935. package/lib/esm/version.js +1 -1
  936. package/package.json +22 -13
@@ -0,0 +1,1803 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { pathToFileURL } = require('url');
4
+ const Module = require('module');
5
+
6
+ const { program } = require('commander');
7
+ const utils = require('./utils');
8
+
9
+ class WebpackCLI {
10
+ constructor() {
11
+ // Global
12
+ this.webpack = require('webpack');
13
+ this.logger = utils.logger;
14
+ this.utils = utils;
15
+
16
+ // Initialize program
17
+ this.program = program;
18
+ this.program.name('webpack');
19
+ this.program.configureOutput({
20
+ writeErr: this.logger.error,
21
+ outputError: (str, write) => write(`Error: ${this.utils.capitalizeFirstLetter(str.replace(/^error:/, '').trim())}`),
22
+ });
23
+ }
24
+
25
+ async makeCommand(commandOptions, options, action) {
26
+ const alreadyLoaded = this.program.commands.find(
27
+ (command) => command.name() === commandOptions.name || command.aliases().includes(commandOptions.alias),
28
+ );
29
+
30
+ if (alreadyLoaded) {
31
+ return;
32
+ }
33
+
34
+ const command = this.program.command(commandOptions.name, {
35
+ noHelp: commandOptions.noHelp,
36
+ hidden: commandOptions.hidden,
37
+ isDefault: commandOptions.isDefault,
38
+ });
39
+
40
+ if (commandOptions.description) {
41
+ command.description(commandOptions.description);
42
+ }
43
+
44
+ if (commandOptions.usage) {
45
+ command.usage(commandOptions.usage);
46
+ }
47
+
48
+ if (Array.isArray(commandOptions.alias)) {
49
+ command.aliases(commandOptions.alias);
50
+ } else {
51
+ command.alias(commandOptions.alias);
52
+ }
53
+
54
+ if (commandOptions.pkg) {
55
+ command.pkg = commandOptions.pkg;
56
+ } else {
57
+ command.pkg = 'webpack-cli';
58
+ }
59
+
60
+ const { forHelp } = this.program;
61
+
62
+ let allDependenciesInstalled = true;
63
+
64
+ if (commandOptions.dependencies && commandOptions.dependencies.length > 0) {
65
+ for (const dependency of commandOptions.dependencies) {
66
+ const { packageExists } = this.utils;
67
+ const isPkgExist = packageExists(dependency);
68
+
69
+ if (isPkgExist) {
70
+ continue;
71
+ } else if (!isPkgExist && forHelp) {
72
+ allDependenciesInstalled = false;
73
+ continue;
74
+ }
75
+
76
+ const { promptInstallation, colors } = this.utils;
77
+
78
+ try {
79
+ await promptInstallation(dependency, () => {
80
+ this.logger.error(
81
+ `For using '${colors.green(commandOptions.name.split(' ')[0])}' command you need to install: '${colors.green(
82
+ dependency,
83
+ )}' package`,
84
+ );
85
+ });
86
+ } catch (error) {
87
+ this.logger.error("Action Interrupted, use 'webpack-cli help' to see possible commands.");
88
+ this.logger.error(error);
89
+ process.exit(2);
90
+ }
91
+ }
92
+ }
93
+
94
+ if (options) {
95
+ if (typeof options === 'function') {
96
+ if (forHelp && !allDependenciesInstalled) {
97
+ command.description(
98
+ `${commandOptions.description} To see all available options you need to install ${commandOptions.dependencies
99
+ .map((dependency) => `'${dependency}'`)
100
+ .join(',')}.`,
101
+ );
102
+ options = [];
103
+ } else {
104
+ options = options();
105
+ }
106
+ }
107
+
108
+ options.forEach((optionForCommand) => {
109
+ this.makeOption(command, optionForCommand);
110
+ });
111
+ }
112
+
113
+ command.action(action);
114
+
115
+ return command;
116
+ }
117
+
118
+ makeOption(command, option) {
119
+ let type = option.type;
120
+ let isMultipleTypes = Array.isArray(type);
121
+ let isOptional = false;
122
+
123
+ if (isMultipleTypes) {
124
+ if (type.length === 1) {
125
+ type = type[0];
126
+ isMultipleTypes = false;
127
+ } else {
128
+ isOptional = type.includes(Boolean);
129
+ }
130
+ }
131
+
132
+ const isMultiple = option.multiple;
133
+ const isRequired = type !== Boolean && typeof type !== 'undefined';
134
+
135
+ let flags = option.alias ? `-${option.alias}, --${option.name}` : `--${option.name}`;
136
+
137
+ if (isOptional) {
138
+ // `commander.js` recognizes [value] as an optional placeholder, making this flag work either as a string or a boolean
139
+ flags = `${flags} [value${isMultiple ? '...' : ''}]`;
140
+ } else if (isRequired) {
141
+ // <value> is a required placeholder for any non-Boolean types
142
+ flags = `${flags} <value${isMultiple ? '...' : ''}>`;
143
+ }
144
+
145
+ // TODO `describe` used by `webpack-dev-server@3`
146
+ const description = option.description || option.describe || '';
147
+ const defaultValue = option.defaultValue;
148
+
149
+ if (type === Boolean) {
150
+ command.option(flags, description, defaultValue);
151
+ } else if (type === Number) {
152
+ let skipDefault = true;
153
+
154
+ command.option(
155
+ flags,
156
+ description,
157
+ (value, prev = []) => {
158
+ if (defaultValue && isMultiple && skipDefault) {
159
+ prev = [];
160
+ skipDefault = false;
161
+ }
162
+
163
+ return isMultiple ? [].concat(prev).concat(Number(value)) : Number(value);
164
+ },
165
+ defaultValue,
166
+ );
167
+ } else if (type === String) {
168
+ let skipDefault = true;
169
+
170
+ command.option(
171
+ flags,
172
+ description,
173
+ (value, prev = []) => {
174
+ if (defaultValue && isMultiple && skipDefault) {
175
+ prev = [];
176
+ skipDefault = false;
177
+ }
178
+
179
+ return isMultiple ? [].concat(prev).concat(value) : value;
180
+ },
181
+ defaultValue,
182
+ );
183
+ } else if (isMultipleTypes) {
184
+ let skipDefault = true;
185
+
186
+ command.option(
187
+ flags,
188
+ description,
189
+ (value, prev = []) => {
190
+ if (defaultValue && isMultiple && skipDefault) {
191
+ prev = [];
192
+ skipDefault = false;
193
+ }
194
+
195
+ if (type.includes(Number)) {
196
+ const numberValue = Number(value);
197
+
198
+ if (!isNaN(numberValue)) {
199
+ return isMultiple ? [].concat(prev).concat(numberValue) : numberValue;
200
+ }
201
+ }
202
+
203
+ if (type.includes(String)) {
204
+ return isMultiple ? [].concat(prev).concat(value) : value;
205
+ }
206
+
207
+ return value;
208
+ },
209
+ defaultValue,
210
+ );
211
+ } else {
212
+ command.option(flags, description, type, defaultValue);
213
+ }
214
+
215
+ if (option.negative) {
216
+ // commander requires explicitly adding the negated version of boolean flags
217
+ const negatedFlag = `--no-${option.name}`;
218
+
219
+ command.option(negatedFlag, option.negatedDescription ? option.negatedDescription : `Negative '${option.name}' option.`);
220
+ }
221
+ }
222
+
223
+ getBuiltInOptions() {
224
+ if (this.builtInOptionsCache) {
225
+ return this.builtInOptionsCache;
226
+ }
227
+
228
+ const minimumHelpFlags = [
229
+ 'config',
230
+ 'config-name',
231
+ 'merge',
232
+ 'env',
233
+ 'mode',
234
+ 'watch',
235
+ 'watch-options-stdin',
236
+ 'stats',
237
+ 'devtool',
238
+ 'entry',
239
+ 'target',
240
+ 'progress',
241
+ 'json',
242
+ 'name',
243
+ 'output-path',
244
+ ];
245
+
246
+ const builtInFlags = [
247
+ // For configs
248
+ {
249
+ name: 'config',
250
+ alias: 'c',
251
+ type: String,
252
+ multiple: true,
253
+ description: 'Provide path to a webpack configuration file e.g. ./webpack.config.js.',
254
+ },
255
+ {
256
+ name: 'config-name',
257
+ type: String,
258
+ multiple: true,
259
+ description: 'Name of the configuration to use.',
260
+ },
261
+ {
262
+ name: 'merge',
263
+ alias: 'm',
264
+ type: Boolean,
265
+ description: "Merge two or more configurations using 'webpack-merge'.",
266
+ },
267
+ // Complex configs
268
+ {
269
+ name: 'env',
270
+ type: (value, previous = {}) => {
271
+ // This ensures we're only splitting by the first `=`
272
+ const [allKeys, val] = value.split(/=(.+)/, 2);
273
+ const splitKeys = allKeys.split(/\.(?!$)/);
274
+
275
+ let prevRef = previous;
276
+
277
+ splitKeys.forEach((someKey, index) => {
278
+ if (!prevRef[someKey]) {
279
+ prevRef[someKey] = {};
280
+ }
281
+
282
+ if (typeof prevRef[someKey] === 'string') {
283
+ prevRef[someKey] = {};
284
+ }
285
+
286
+ if (index === splitKeys.length - 1) {
287
+ prevRef[someKey] = val || true;
288
+ }
289
+
290
+ prevRef = prevRef[someKey];
291
+ });
292
+
293
+ return previous;
294
+ },
295
+ multiple: true,
296
+ description: 'Environment passed to the configuration when it is a function.',
297
+ },
298
+ {
299
+ name: 'node-env',
300
+ type: String,
301
+ multiple: false,
302
+ description: 'Sets process.env.NODE_ENV to the specified value',
303
+ },
304
+
305
+ // Adding more plugins
306
+ {
307
+ name: 'hot',
308
+ alias: 'h',
309
+ type: Boolean,
310
+ negative: true,
311
+ description: 'Enables Hot Module Replacement',
312
+ negatedDescription: 'Disables Hot Module Replacement.',
313
+ },
314
+ {
315
+ name: 'analyze',
316
+ type: Boolean,
317
+ multiple: false,
318
+ description: 'It invokes webpack-bundle-analyzer plugin to get bundle information.',
319
+ },
320
+ {
321
+ name: 'progress',
322
+ type: [Boolean, String],
323
+ description: 'Print compilation progress during build.',
324
+ },
325
+ {
326
+ name: 'prefetch',
327
+ type: String,
328
+ description: 'Prefetch this request.',
329
+ },
330
+
331
+ // Output options
332
+ {
333
+ name: 'json',
334
+ type: [String, Boolean],
335
+ alias: 'j',
336
+ description: 'Prints result as JSON or store it in a file.',
337
+ },
338
+
339
+ // For webpack@4
340
+ {
341
+ name: 'entry',
342
+ type: String,
343
+ multiple: true,
344
+ description: 'The entry point(s) of your application e.g. ./src/main.js.',
345
+ },
346
+ {
347
+ name: 'output-path',
348
+ alias: 'o',
349
+ type: String,
350
+ description: 'Output location of the file generated by webpack e.g. ./dist/.',
351
+ },
352
+ {
353
+ name: 'target',
354
+ alias: 't',
355
+ type: String,
356
+ multiple: this.webpack.cli !== undefined,
357
+ description: 'Sets the build target e.g. node.',
358
+ },
359
+ {
360
+ name: 'devtool',
361
+ type: String,
362
+ negative: true,
363
+ alias: 'd',
364
+ description: 'Determine source maps to use.',
365
+ negatedDescription: 'Do not generate source maps.',
366
+ },
367
+ {
368
+ name: 'mode',
369
+ type: String,
370
+ description: 'Defines the mode to pass to webpack.',
371
+ },
372
+ {
373
+ name: 'name',
374
+ type: String,
375
+ description: 'Name of the configuration. Used when loading multiple configurations.',
376
+ },
377
+ {
378
+ name: 'stats',
379
+ type: [String, Boolean],
380
+ negative: true,
381
+ description: 'It instructs webpack on how to treat the stats e.g. verbose.',
382
+ negatedDescription: 'Disable stats output.',
383
+ },
384
+ {
385
+ name: 'watch',
386
+ type: Boolean,
387
+ negative: true,
388
+ alias: 'w',
389
+ description: 'Watch for files changes.',
390
+ negatedDescription: 'Do not watch for file changes.',
391
+ },
392
+ {
393
+ name: 'watch-options-stdin',
394
+ type: Boolean,
395
+ negative: true,
396
+ description: 'Stop watching when stdin stream has ended.',
397
+ negatedDescription: 'Do not stop watching when stdin stream has ended.',
398
+ },
399
+ ];
400
+
401
+ // Extract all the flags being exported from core.
402
+ // A list of cli flags generated by core can be found here https://github.com/webpack/webpack/blob/master/test/__snapshots__/Cli.test.js.snap
403
+ const coreFlags = this.webpack.cli
404
+ ? Object.entries(this.webpack.cli.getArguments()).map(([flag, meta]) => {
405
+ if (meta.simpleType === 'string') {
406
+ meta.type = String;
407
+ } else if (meta.simpleType === 'number') {
408
+ meta.type = Number;
409
+ } else {
410
+ meta.type = Boolean;
411
+ meta.negative = !flag.endsWith('-reset');
412
+ }
413
+
414
+ const inBuiltIn = builtInFlags.find((builtInFlag) => builtInFlag.name === flag);
415
+
416
+ if (inBuiltIn) {
417
+ return { ...meta, name: flag, group: 'core', ...inBuiltIn };
418
+ }
419
+
420
+ return { ...meta, name: flag, group: 'core' };
421
+ })
422
+ : [];
423
+
424
+ const options = []
425
+ .concat(builtInFlags.filter((builtInFlag) => !coreFlags.find((coreFlag) => builtInFlag.name === coreFlag.name)))
426
+ .concat(coreFlags)
427
+ .map((option) => {
428
+ option.help = minimumHelpFlags.includes(option.name) ? 'minimum' : 'verbose';
429
+
430
+ return option;
431
+ });
432
+
433
+ this.builtInOptionsCache = options;
434
+
435
+ return options;
436
+ }
437
+
438
+ applyNodeEnv(options) {
439
+ if (typeof options.nodeEnv === 'string') {
440
+ process.env.NODE_ENV = options.nodeEnv;
441
+ }
442
+ }
443
+
444
+ async run(args, parseOptions) {
445
+ // Built-in internal commands
446
+ const buildCommandOptions = {
447
+ name: 'build [entries...]',
448
+ alias: ['bundle', 'b'],
449
+ description: 'Run webpack (default command, can be omitted).',
450
+ usage: '[entries...] [options]',
451
+ };
452
+ const watchCommandOptions = {
453
+ name: 'watch [entries...]',
454
+ alias: 'w',
455
+ description: 'Run webpack and watch for files changes.',
456
+ usage: '[entries...] [options]',
457
+ };
458
+ const versionCommandOptions = {
459
+ name: 'version [commands...]',
460
+ alias: 'v',
461
+ description: "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.",
462
+ };
463
+ const helpCommandOptions = {
464
+ name: 'help [command] [option]',
465
+ alias: 'h',
466
+ description: 'Display help for commands and options.',
467
+ };
468
+ // Built-in external commands
469
+ const externalBuiltInCommandsInfo = [
470
+ {
471
+ name: 'serve [entries...]',
472
+ alias: 's',
473
+ pkg: '@webpack-cli/serve',
474
+ },
475
+ {
476
+ name: 'info',
477
+ alias: 'i',
478
+ pkg: '@webpack-cli/info',
479
+ },
480
+ {
481
+ name: 'init',
482
+ alias: 'c',
483
+ pkg: '@webpack-cli/init',
484
+ },
485
+ {
486
+ name: 'loader',
487
+ alias: 'l',
488
+ pkg: '@webpack-cli/generators',
489
+ },
490
+ {
491
+ name: 'plugin',
492
+ alias: 'p',
493
+ pkg: '@webpack-cli/generators',
494
+ },
495
+ {
496
+ name: 'migrate',
497
+ alias: 'm',
498
+ pkg: '@webpack-cli/migrate',
499
+ },
500
+ {
501
+ name: 'configtest [config-path]',
502
+ alias: 't',
503
+ pkg: '@webpack-cli/configtest',
504
+ },
505
+ ];
506
+
507
+ const knownCommands = [
508
+ buildCommandOptions,
509
+ watchCommandOptions,
510
+ versionCommandOptions,
511
+ helpCommandOptions,
512
+ ...externalBuiltInCommandsInfo,
513
+ ];
514
+ const getCommandName = (name) => name.split(' ')[0];
515
+ const isKnownCommand = (name) =>
516
+ knownCommands.find(
517
+ (command) =>
518
+ getCommandName(command.name) === name ||
519
+ (Array.isArray(command.alias) ? command.alias.includes(name) : command.alias === name),
520
+ );
521
+ const isCommand = (input, commandOptions) => {
522
+ const longName = getCommandName(commandOptions.name);
523
+
524
+ if (input === longName) {
525
+ return true;
526
+ }
527
+
528
+ if (commandOptions.alias) {
529
+ if (Array.isArray(commandOptions.alias)) {
530
+ return commandOptions.alias.includes(input);
531
+ } else {
532
+ return commandOptions.alias === input;
533
+ }
534
+ }
535
+
536
+ return false;
537
+ };
538
+ const findCommandByName = (name) =>
539
+ this.program.commands.find((command) => name === command.name() || command.alias().includes(name));
540
+ const isOption = (value) => value.startsWith('-');
541
+ const isGlobalOption = (value) =>
542
+ value === '--color' ||
543
+ value === '--no-color' ||
544
+ value === '-v' ||
545
+ value === '--version' ||
546
+ value === '-h' ||
547
+ value === '--help';
548
+
549
+ const loadCommandByName = async (commandName, allowToInstall = false) => {
550
+ const isBuildCommandUsed = isCommand(commandName, buildCommandOptions);
551
+ const isWatchCommandUsed = isCommand(commandName, watchCommandOptions);
552
+
553
+ if (isBuildCommandUsed || isWatchCommandUsed) {
554
+ const options = this.getBuiltInOptions();
555
+
556
+ await this.makeCommand(
557
+ isBuildCommandUsed ? buildCommandOptions : watchCommandOptions,
558
+ isWatchCommandUsed ? options.filter((option) => option.name !== 'watch') : options,
559
+ async (entries, options) => {
560
+ if (entries.length > 0) {
561
+ options.entry = [...entries, ...(options.entry || [])];
562
+ }
563
+
564
+ await this.buildCommand(options, isWatchCommandUsed);
565
+ },
566
+ );
567
+ } else if (isCommand(commandName, helpCommandOptions)) {
568
+ // Stub for the `help` command
569
+ this.makeCommand(helpCommandOptions, [], () => {});
570
+ } else if (isCommand(commandName, versionCommandOptions)) {
571
+ // Stub for the `help` command
572
+ this.makeCommand(versionCommandOptions, [], () => {});
573
+ } else {
574
+ const builtInExternalCommandInfo = externalBuiltInCommandsInfo.find(
575
+ (externalBuiltInCommandInfo) =>
576
+ getCommandName(externalBuiltInCommandInfo.name) === commandName ||
577
+ (Array.isArray(externalBuiltInCommandInfo.alias)
578
+ ? externalBuiltInCommandInfo.alias.includes(commandName)
579
+ : externalBuiltInCommandInfo.alias === commandName),
580
+ );
581
+
582
+ let pkg;
583
+
584
+ if (builtInExternalCommandInfo) {
585
+ ({ pkg } = builtInExternalCommandInfo);
586
+ } else {
587
+ pkg = commandName;
588
+ }
589
+
590
+ if (pkg !== 'webpack-cli' && !this.utils.packageExists(pkg)) {
591
+ if (!allowToInstall) {
592
+ return;
593
+ }
594
+
595
+ const { promptInstallation, colors } = this.utils;
596
+
597
+ try {
598
+ pkg = await promptInstallation(pkg, () => {
599
+ this.logger.error(`For using this command you need to install: '${colors.green(pkg)}' package`);
600
+ });
601
+ } catch (error) {
602
+ this.logger.error(`Action Interrupted, use '${colors.cyan('webpack-cli help')}' to see possible commands`);
603
+ process.exit(2);
604
+ }
605
+ }
606
+
607
+ let loadedCommand;
608
+
609
+ try {
610
+ loadedCommand = require(pkg);
611
+ } catch (error) {
612
+ // Ignore, command is not installed
613
+
614
+ return;
615
+ }
616
+
617
+ if (loadedCommand.default) {
618
+ loadedCommand = loadedCommand.default;
619
+ }
620
+
621
+ let command;
622
+
623
+ try {
624
+ command = new loadedCommand();
625
+
626
+ await command.apply(this);
627
+ } catch (error) {
628
+ this.logger.error(`Unable to load '${pkg}' command`);
629
+ this.logger.error(error);
630
+ process.exit(2);
631
+ }
632
+ }
633
+ };
634
+
635
+ // Register own exit
636
+ this.program.exitOverride(async (error) => {
637
+ if (error.exitCode === 0) {
638
+ process.exit(0);
639
+ }
640
+
641
+ if (error.code === 'executeSubCommandAsync') {
642
+ process.exit(2);
643
+ }
644
+
645
+ if (error.code === 'commander.help') {
646
+ process.exit(0);
647
+ }
648
+
649
+ if (error.code === 'commander.unknownOption') {
650
+ let name = error.message.match(/'(.+)'/);
651
+
652
+ if (name) {
653
+ name = name[1].substr(2);
654
+
655
+ if (name.includes('=')) {
656
+ name = name.split('=')[0];
657
+ }
658
+
659
+ const { operands } = this.program.parseOptions(this.program.args);
660
+ const operand = typeof operands[0] !== 'undefined' ? operands[0] : getCommandName(buildCommandOptions.name);
661
+
662
+ if (operand) {
663
+ const command = findCommandByName(operand);
664
+
665
+ if (!command) {
666
+ this.logger.error(`Can't find and load command '${operand}'`);
667
+ this.logger.error("Run 'webpack --help' to see available commands and options");
668
+ process.exit(2);
669
+ }
670
+
671
+ command.options.forEach((option) => {
672
+ if (this.utils.levenshtein.distance(name, option.long.slice(2)) < 3) {
673
+ this.logger.error(`Did you mean '--${option.name()}'?`);
674
+ }
675
+ });
676
+ }
677
+ }
678
+ }
679
+
680
+ // Codes:
681
+ // - commander.unknownCommand
682
+ // - commander.missingArgument
683
+ // - commander.missingMandatoryOptionValue
684
+ // - commander.optionMissingArgument
685
+
686
+ this.logger.error("Run 'webpack --help' to see available commands and options");
687
+ process.exit(2);
688
+ });
689
+
690
+ // Default `--color` and `--no-color` options
691
+ const cli = this;
692
+ this.program.option('--color', 'Enable colors on console.');
693
+ this.program.on('option:color', function () {
694
+ const { color } = this.opts();
695
+
696
+ cli.utils.colors.options.changed = true;
697
+ cli.utils.colors.options.enabled = color;
698
+ });
699
+ this.program.option('--no-color', 'Disable colors on console.');
700
+ this.program.on('option:no-color', function () {
701
+ const { color } = this.opts();
702
+
703
+ cli.utils.colors.options.changed = true;
704
+ cli.utils.colors.options.enabled = color;
705
+ });
706
+
707
+ // Make `-v, --version` options
708
+ // Make `version|v [commands...]` command
709
+ const outputVersion = async (options) => {
710
+ // Filter `bundle`, `watch`, `version` and `help` commands
711
+ const possibleCommandNames = options.filter(
712
+ (option) =>
713
+ !isCommand(option, buildCommandOptions) &&
714
+ !isCommand(option, watchCommandOptions) &&
715
+ !isCommand(option, versionCommandOptions) &&
716
+ !isCommand(option, helpCommandOptions),
717
+ );
718
+
719
+ possibleCommandNames.forEach((possibleCommandName) => {
720
+ if (!isOption(possibleCommandName)) {
721
+ return;
722
+ }
723
+
724
+ this.logger.error(`Unknown option '${possibleCommandName}'`);
725
+ this.logger.error("Run 'webpack --help' to see available commands and options");
726
+ process.exit(2);
727
+ });
728
+
729
+ if (possibleCommandNames.length > 0) {
730
+ await Promise.all(possibleCommandNames.map((possibleCommand) => loadCommandByName(possibleCommand)));
731
+
732
+ for (const possibleCommandName of possibleCommandNames) {
733
+ const foundCommand = findCommandByName(possibleCommandName);
734
+
735
+ if (!foundCommand) {
736
+ this.logger.error(`Unknown command '${possibleCommandName}'`);
737
+ this.logger.error("Run 'webpack --help' to see available commands and options");
738
+ process.exit(2);
739
+ }
740
+
741
+ try {
742
+ const { name, version } = require(`${foundCommand.pkg}/package.json`);
743
+
744
+ this.logger.raw(`${name} ${version}`);
745
+ } catch (e) {
746
+ this.logger.error(`Error: External package '${foundCommand.pkg}' not found`);
747
+ process.exit(2);
748
+ }
749
+ }
750
+ }
751
+
752
+ const pkgJSON = require('../package.json');
753
+
754
+ this.logger.raw(`webpack ${this.webpack.version}`);
755
+ this.logger.raw(`webpack-cli ${pkgJSON.version}`);
756
+
757
+ if (this.utils.packageExists('webpack-dev-server')) {
758
+ // eslint-disable-next-line
759
+ const { version } = require('webpack-dev-server/package.json');
760
+
761
+ this.logger.raw(`webpack-dev-server ${version}`);
762
+ }
763
+
764
+ process.exit(0);
765
+ };
766
+ this.program.option(
767
+ '-v, --version',
768
+ "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.",
769
+ );
770
+
771
+ const outputHelp = async (options, isVerbose, isHelpCommandSyntax, program) => {
772
+ const { bold } = this.utils.colors;
773
+
774
+ const outputIncorrectUsageOfHelp = () => {
775
+ this.logger.error('Incorrect use of help');
776
+ this.logger.error("Please use: 'webpack help [command] [option]' | 'webpack [command] --help'");
777
+ this.logger.error("Run 'webpack --help' to see available commands and options");
778
+ process.exit(2);
779
+ };
780
+
781
+ const isGlobalHelp = options.length === 0;
782
+ const isCommandHelp = options.length === 1 && !isOption(options[0]);
783
+
784
+ if (isGlobalHelp || isCommandHelp) {
785
+ const cliAPI = this;
786
+
787
+ program.configureHelp({
788
+ sortSubcommands: true,
789
+ // Support multiple aliases
790
+ commandUsage: (command) => {
791
+ let parentCmdNames = '';
792
+
793
+ for (let parentCmd = command.parent; parentCmd; parentCmd = parentCmd.parent) {
794
+ parentCmdNames = `${parentCmd.name()} ${parentCmdNames}`;
795
+ }
796
+
797
+ if (isGlobalHelp) {
798
+ return `${parentCmdNames}${command.usage()}\n${this.utils.colors.bold(
799
+ 'Alternative usage to run commands:',
800
+ )} ${parentCmdNames}[command] [options]`;
801
+ }
802
+
803
+ return `${parentCmdNames}${command.name()}|${command.aliases().join('|')} ${command.usage()}`;
804
+ },
805
+ // Support multiple aliases
806
+ subcommandTerm: (command) => {
807
+ const humanReadableArgumentName = (argument) => {
808
+ const nameOutput = argument.name + (argument.variadic === true ? '...' : '');
809
+
810
+ return argument.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']';
811
+ };
812
+ const args = command._args.map((arg) => humanReadableArgumentName(arg)).join(' ');
813
+
814
+ return `${command.name()}|${command.aliases().join('|')}${args ? ` ${args}` : ''}${
815
+ command.options.length > 0 ? ' [options]' : ''
816
+ }`;
817
+ },
818
+ visibleOptions: function visibleOptions(command) {
819
+ const options = cliAPI.getBuiltInOptions();
820
+
821
+ return command.options.filter((option) => {
822
+ if (option.hidden) {
823
+ return false;
824
+ }
825
+
826
+ if (!isVerbose) {
827
+ const foundOption = options.find((flag) => {
828
+ if (option.negate && flag.negative) {
829
+ return `no-${flag.name}` === option.name();
830
+ }
831
+
832
+ return flag.name === option.name();
833
+ });
834
+
835
+ if (foundOption) {
836
+ return foundOption.help === 'minimum';
837
+ }
838
+
839
+ return true;
840
+ }
841
+
842
+ return true;
843
+ });
844
+ },
845
+ padWidth(command, helper) {
846
+ return Math.max(
847
+ helper.longestArgumentTermLength(command, helper),
848
+ helper.longestOptionTermLength(command, helper),
849
+ // For global options
850
+ helper.longestOptionTermLength(program, helper),
851
+ helper.longestSubcommandTermLength(isGlobalHelp ? program : command, helper),
852
+ );
853
+ },
854
+ formatHelp: (command, helper) => {
855
+ const termWidth = helper.padWidth(command, helper);
856
+ const helpWidth = helper.helpWidth || 80;
857
+ const itemIndentWidth = 2;
858
+ const itemSeparatorWidth = 2; // between term and description
859
+
860
+ const formatItem = (term, description) => {
861
+ if (description) {
862
+ const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
863
+
864
+ return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
865
+ }
866
+
867
+ return term;
868
+ };
869
+
870
+ const formatList = (textArray) => textArray.join('\n').replace(/^/gm, ' '.repeat(itemIndentWidth));
871
+
872
+ // Usage
873
+ let output = [`${bold('Usage:')} ${helper.commandUsage(command)}`, ''];
874
+
875
+ // Description
876
+ const commandDescription = isGlobalHelp
877
+ ? 'The build tool for modern web applications.'
878
+ : helper.commandDescription(command);
879
+
880
+ if (commandDescription.length > 0) {
881
+ output = output.concat([commandDescription, '']);
882
+ }
883
+
884
+ // Arguments
885
+ const argumentList = helper
886
+ .visibleArguments(command)
887
+ .map((argument) => formatItem(argument.term, argument.description));
888
+
889
+ if (argumentList.length > 0) {
890
+ output = output.concat([bold('Arguments:'), formatList(argumentList), '']);
891
+ }
892
+
893
+ // Options
894
+ const optionList = helper
895
+ .visibleOptions(command)
896
+ .map((option) => formatItem(helper.optionTerm(option), helper.optionDescription(option)));
897
+
898
+ if (optionList.length > 0) {
899
+ output = output.concat([bold('Options:'), formatList(optionList), '']);
900
+ }
901
+
902
+ // Global options
903
+ const globalOptionList = program.options.map((option) =>
904
+ formatItem(helper.optionTerm(option), helper.optionDescription(option)),
905
+ );
906
+
907
+ if (globalOptionList.length > 0) {
908
+ output = output.concat([bold('Global options:'), formatList(globalOptionList), '']);
909
+ }
910
+
911
+ // Commands
912
+ const commandList = helper
913
+ .visibleCommands(isGlobalHelp ? program : command)
914
+ .map((command) => formatItem(helper.subcommandTerm(command), helper.subcommandDescription(command)));
915
+
916
+ if (commandList.length > 0) {
917
+ output = output.concat([bold('Commands:'), formatList(commandList), '']);
918
+ }
919
+
920
+ return output.join('\n');
921
+ },
922
+ });
923
+
924
+ if (isGlobalHelp) {
925
+ await Promise.all(
926
+ knownCommands.map((knownCommand) => {
927
+ return loadCommandByName(getCommandName(knownCommand.name));
928
+ }),
929
+ );
930
+
931
+ const buildCommand = findCommandByName(getCommandName(buildCommandOptions.name));
932
+
933
+ this.logger.raw(buildCommand.helpInformation());
934
+ } else {
935
+ const name = options[0];
936
+
937
+ await loadCommandByName(name);
938
+
939
+ const command = findCommandByName(name);
940
+
941
+ if (!command) {
942
+ this.logger.error(`Can't find and load command '${name}'`);
943
+ this.logger.error("Run 'webpack --help' to see available commands and options");
944
+ process.exit(2);
945
+ }
946
+
947
+ this.logger.raw(command.helpInformation());
948
+ }
949
+ } else if (isHelpCommandSyntax) {
950
+ let isCommandSpecified = false;
951
+ let commandName = getCommandName(buildCommandOptions.name);
952
+ let optionName;
953
+
954
+ if (options.length === 1) {
955
+ optionName = options[0];
956
+ } else if (options.length === 2) {
957
+ isCommandSpecified = true;
958
+ commandName = options[0];
959
+ optionName = options[1];
960
+
961
+ if (isOption(commandName)) {
962
+ outputIncorrectUsageOfHelp();
963
+ }
964
+ } else {
965
+ outputIncorrectUsageOfHelp();
966
+ }
967
+
968
+ await loadCommandByName(commandName);
969
+
970
+ const command = isGlobalOption(optionName) ? program : findCommandByName(commandName);
971
+
972
+ if (!command) {
973
+ this.logger.error(`Can't find and load command '${commandName}'`);
974
+ this.logger.error("Run 'webpack --help' to see available commands and options");
975
+ process.exit(2);
976
+ }
977
+
978
+ const option = command.options.find((option) => option.short === optionName || option.long === optionName);
979
+
980
+ if (!option) {
981
+ this.logger.error(`Unknown option '${optionName}'`);
982
+ this.logger.error("Run 'webpack --help' to see available commands and options");
983
+ process.exit(2);
984
+ }
985
+
986
+ const nameOutput =
987
+ option.flags.replace(/^.+[[<]/, '').replace(/(\.\.\.)?[\]>].*$/, '') + (option.variadic === true ? '...' : '');
988
+ const value = option.required ? '<' + nameOutput + '>' : option.optional ? '[' + nameOutput + ']' : '';
989
+
990
+ this.logger.raw(
991
+ `${bold('Usage')}: webpack${isCommandSpecified ? ` ${commandName}` : ''} ${option.long}${value ? ` ${value}` : ''}`,
992
+ );
993
+
994
+ if (option.short) {
995
+ this.logger.raw(
996
+ `${bold('Short:')} webpack${isCommandSpecified ? ` ${commandName}` : ''} ${option.short}${
997
+ value ? ` ${value}` : ''
998
+ }`,
999
+ );
1000
+ }
1001
+
1002
+ if (option.description) {
1003
+ this.logger.raw(`${bold('Description:')} ${option.description}`);
1004
+ }
1005
+
1006
+ if (!option.negate && options.defaultValue) {
1007
+ this.logger.raw(`${bold('Default value:')} ${JSON.stringify(option.defaultValue)}`);
1008
+ }
1009
+
1010
+ this.logger.raw('');
1011
+
1012
+ // TODO implement this after refactor cli arguments
1013
+ // logger.raw('Possible values: foo | bar');
1014
+ // logger.raw('Documentation: https://webpack.js.org/option/name/');
1015
+ } else {
1016
+ outputIncorrectUsageOfHelp();
1017
+ }
1018
+
1019
+ this.logger.raw("To see list of all supported commands and options run 'webpack --help=verbose'.\n");
1020
+ this.logger.raw(`${bold('Webpack documentation:')} https://webpack.js.org/.`);
1021
+ this.logger.raw(`${bold('CLI documentation:')} https://webpack.js.org/api/cli/.`);
1022
+ this.logger.raw(`${bold('Made with ♥ by the webpack team')}.`);
1023
+ process.exit(0);
1024
+ };
1025
+ this.program.helpOption(false);
1026
+ this.program.addHelpCommand(false);
1027
+ this.program.option('-h, --help [verbose]', 'Display help for commands and options.');
1028
+
1029
+ let isInternalActionCalled = false;
1030
+
1031
+ // Default action
1032
+ this.program.usage('[options]');
1033
+ this.program.allowUnknownOption(true);
1034
+ this.program.action(async (options, program) => {
1035
+ if (!isInternalActionCalled) {
1036
+ isInternalActionCalled = true;
1037
+ } else {
1038
+ this.logger.error('No commands found to run');
1039
+ process.exit(2);
1040
+ }
1041
+
1042
+ // Command and options
1043
+ const { operands, unknown } = this.program.parseOptions(program.args);
1044
+ const defaultCommandToRun = getCommandName(buildCommandOptions.name);
1045
+ const hasOperand = typeof operands[0] !== 'undefined';
1046
+ const operand = hasOperand ? operands[0] : defaultCommandToRun;
1047
+
1048
+ const isHelpCommandSyntax = isCommand(operand, helpCommandOptions);
1049
+
1050
+ if (options.help || isHelpCommandSyntax) {
1051
+ let isVerbose = false;
1052
+
1053
+ if (options.help) {
1054
+ if (typeof options.help === 'string') {
1055
+ if (options.help !== 'verbose') {
1056
+ this.logger.error("Unknown value for '--help' option, please use '--help=verbose'");
1057
+ process.exit(2);
1058
+ }
1059
+
1060
+ isVerbose = true;
1061
+ }
1062
+ }
1063
+
1064
+ this.program.forHelp = true;
1065
+
1066
+ const optionsForHelp = []
1067
+ .concat(options.help && hasOperand ? [operand] : [])
1068
+ // Syntax `webpack help [command]`
1069
+ .concat(operands.slice(1))
1070
+ // Syntax `webpack help [option]`
1071
+ .concat(unknown)
1072
+ .concat(isHelpCommandSyntax && typeof options.color !== 'undefined' ? [options.color ? '--color' : '--no-color'] : [])
1073
+ .concat(isHelpCommandSyntax && typeof options.version !== 'undefined' ? ['--version'] : []);
1074
+
1075
+ await outputHelp(optionsForHelp, isVerbose, isHelpCommandSyntax, program);
1076
+ }
1077
+
1078
+ if (options.version || isCommand(operand, versionCommandOptions)) {
1079
+ const optionsForVersion = []
1080
+ .concat(options.version ? [operand] : [])
1081
+ .concat(operands.slice(1))
1082
+ .concat(unknown);
1083
+
1084
+ await outputVersion(optionsForVersion, program);
1085
+ }
1086
+
1087
+ let commandToRun = operand;
1088
+ let commandOperands = operands.slice(1);
1089
+
1090
+ if (isKnownCommand(commandToRun)) {
1091
+ await loadCommandByName(commandToRun, true);
1092
+ } else {
1093
+ let isEntrySyntax = fs.existsSync(operand);
1094
+
1095
+ if (isEntrySyntax) {
1096
+ commandToRun = defaultCommandToRun;
1097
+ commandOperands = operands;
1098
+
1099
+ await loadCommandByName(commandToRun);
1100
+ } else {
1101
+ this.logger.error(`Unknown command or entry '${operand}'`);
1102
+
1103
+ const found = knownCommands.find(
1104
+ (commandOptions) => this.utils.levenshtein.distance(operand, getCommandName(commandOptions.name)) < 3,
1105
+ );
1106
+
1107
+ if (found) {
1108
+ this.logger.error(
1109
+ `Did you mean '${getCommandName(found.name)}' (alias '${
1110
+ Array.isArray(found.alias) ? found.alias.join(', ') : found.alias
1111
+ }')?`,
1112
+ );
1113
+ }
1114
+
1115
+ this.logger.error("Run 'webpack --help' to see available commands and options");
1116
+ process.exit(2);
1117
+ }
1118
+ }
1119
+
1120
+ await this.program.parseAsync([commandToRun, ...commandOperands, ...unknown], { from: 'user' });
1121
+ });
1122
+
1123
+ await this.program.parseAsync(args, parseOptions);
1124
+ }
1125
+
1126
+ async resolveConfig(options) {
1127
+ const loadConfig = async (configPath) => {
1128
+ const { interpret } = this.utils;
1129
+ const ext = path.extname(configPath);
1130
+ const interpreted = Object.keys(interpret.jsVariants).find((variant) => variant === ext);
1131
+
1132
+ if (interpreted) {
1133
+ const { rechoir } = this.utils;
1134
+
1135
+ try {
1136
+ rechoir.prepare(interpret.extensions, configPath);
1137
+ } catch (error) {
1138
+ if (error.failures) {
1139
+ this.logger.error(`Unable load '${configPath}'`);
1140
+ this.logger.error(error.message);
1141
+
1142
+ error.failures.forEach((failure) => {
1143
+ this.logger.error(failure.error.message);
1144
+ });
1145
+ this.logger.error('Please install one of them');
1146
+ process.exit(2);
1147
+ }
1148
+
1149
+ this.logger.error(error);
1150
+ process.exit(2);
1151
+ }
1152
+ }
1153
+
1154
+ let options;
1155
+
1156
+ try {
1157
+ try {
1158
+ options = require(configPath);
1159
+ } catch (error) {
1160
+ let previousModuleCompile;
1161
+
1162
+ // TODO Workaround https://github.com/zertosh/v8-compile-cache/issues/30
1163
+ if (this._originalModuleCompile) {
1164
+ previousModuleCompile = Module.prototype._compile;
1165
+
1166
+ Module.prototype._compile = this._originalModuleCompile;
1167
+ }
1168
+
1169
+ const dynamicImportLoader = this.utils.dynamicImportLoader();
1170
+
1171
+ if (this._originalModuleCompile) {
1172
+ Module.prototype._compile = previousModuleCompile;
1173
+ }
1174
+
1175
+ if (
1176
+ (error.code === 'ERR_REQUIRE_ESM' || process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) &&
1177
+ pathToFileURL &&
1178
+ dynamicImportLoader
1179
+ ) {
1180
+ const urlForConfig = pathToFileURL(configPath);
1181
+
1182
+ options = await dynamicImportLoader(urlForConfig);
1183
+ options = options.default;
1184
+
1185
+ return { options, path: configPath };
1186
+ }
1187
+
1188
+ throw error;
1189
+ }
1190
+ } catch (error) {
1191
+ this.logger.error(`Failed to load '${configPath}' config`);
1192
+
1193
+ if (this.isValidationError(error)) {
1194
+ this.logger.error(error.message);
1195
+ } else {
1196
+ this.logger.error(error);
1197
+ }
1198
+
1199
+ process.exit(2);
1200
+ }
1201
+
1202
+ if (options.default) {
1203
+ options = options.default;
1204
+ }
1205
+
1206
+ return { options, path: configPath };
1207
+ };
1208
+
1209
+ const evaluateConfig = async (loadedConfig, argv) => {
1210
+ const isMultiCompiler = Array.isArray(loadedConfig.options);
1211
+ const config = isMultiCompiler ? loadedConfig.options : [loadedConfig.options];
1212
+
1213
+ let evaluatedConfig = await Promise.all(
1214
+ config.map(async (rawConfig) => {
1215
+ if (typeof rawConfig.then === 'function') {
1216
+ rawConfig = await rawConfig;
1217
+ }
1218
+
1219
+ // `Promise` may return `Function`
1220
+ if (typeof rawConfig === 'function') {
1221
+ // when config is a function, pass the env from args to the config function
1222
+ rawConfig = await rawConfig(argv.env, argv);
1223
+ }
1224
+
1225
+ return rawConfig;
1226
+ }),
1227
+ );
1228
+
1229
+ loadedConfig.options = isMultiCompiler ? evaluatedConfig : evaluatedConfig[0];
1230
+
1231
+ const isObject = (value) => typeof value === 'object' && value !== null;
1232
+
1233
+ if (!isObject(loadedConfig.options) && !Array.isArray(loadedConfig.options)) {
1234
+ this.logger.error(`Invalid configuration in '${loadedConfig.path}'`);
1235
+ process.exit(2);
1236
+ }
1237
+
1238
+ return loadedConfig;
1239
+ };
1240
+
1241
+ let config = { options: {}, path: new WeakMap() };
1242
+
1243
+ if (options.config && options.config.length > 0) {
1244
+ const evaluatedConfigs = await Promise.all(
1245
+ options.config.map(async (value) => evaluateConfig(await loadConfig(path.resolve(value)), options.argv || {})),
1246
+ );
1247
+
1248
+ config.options = [];
1249
+
1250
+ evaluatedConfigs.forEach((evaluatedConfig) => {
1251
+ if (Array.isArray(evaluatedConfig.options)) {
1252
+ evaluatedConfig.options.forEach((options) => {
1253
+ config.options.push(options);
1254
+ config.path.set(options, evaluatedConfig.path);
1255
+ });
1256
+ } else {
1257
+ config.options.push(evaluatedConfig.options);
1258
+ config.path.set(evaluatedConfig.options, evaluatedConfig.path);
1259
+ }
1260
+ });
1261
+
1262
+ config.options = config.options.length === 1 ? config.options[0] : config.options;
1263
+ } else {
1264
+ const { interpret } = this.utils;
1265
+
1266
+ // Order defines the priority, in increasing order
1267
+ const defaultConfigFiles = ['webpack.config', '.webpack/webpack.config', '.webpack/webpackfile']
1268
+ .map((filename) =>
1269
+ // Since .cjs is not available on interpret side add it manually to default config extension list
1270
+ [...Object.keys(interpret.extensions), '.cjs'].map((ext) => ({
1271
+ path: path.resolve(filename + ext),
1272
+ ext: ext,
1273
+ module: interpret.extensions[ext],
1274
+ })),
1275
+ )
1276
+ .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);
1277
+
1278
+ let foundDefaultConfigFile;
1279
+
1280
+ for (const defaultConfigFile of defaultConfigFiles) {
1281
+ if (!fs.existsSync(defaultConfigFile.path)) {
1282
+ continue;
1283
+ }
1284
+
1285
+ foundDefaultConfigFile = defaultConfigFile;
1286
+ break;
1287
+ }
1288
+
1289
+ if (foundDefaultConfigFile) {
1290
+ const loadedConfig = await loadConfig(foundDefaultConfigFile.path);
1291
+ const evaluatedConfig = await evaluateConfig(loadedConfig, options.argv || {});
1292
+
1293
+ config.options = evaluatedConfig.options;
1294
+
1295
+ if (Array.isArray(config.options)) {
1296
+ config.options.forEach((options) => {
1297
+ config.path.set(options, evaluatedConfig.path);
1298
+ });
1299
+ } else {
1300
+ config.path.set(evaluatedConfig.options, evaluatedConfig.path);
1301
+ }
1302
+ }
1303
+ }
1304
+
1305
+ if (options.configName) {
1306
+ const notfoundConfigNames = [];
1307
+
1308
+ config.options = options.configName.map((configName) => {
1309
+ let found;
1310
+
1311
+ if (Array.isArray(config.options)) {
1312
+ found = config.options.find((options) => options.name === configName);
1313
+ } else {
1314
+ found = config.options.name === configName ? config.options : undefined;
1315
+ }
1316
+
1317
+ if (!found) {
1318
+ notfoundConfigNames.push(configName);
1319
+ }
1320
+
1321
+ return found;
1322
+ });
1323
+
1324
+ if (notfoundConfigNames.length > 0) {
1325
+ this.logger.error(
1326
+ notfoundConfigNames.map((configName) => `Configuration with the name "${configName}" was not found.`).join(' '),
1327
+ );
1328
+ process.exit(2);
1329
+ }
1330
+ }
1331
+
1332
+ if (options.merge) {
1333
+ const { merge } = require('webpack-merge');
1334
+
1335
+ // we can only merge when there are multiple configurations
1336
+ // either by passing multiple configs by flags or passing a
1337
+ // single config exporting an array
1338
+ if (!Array.isArray(config.options) || config.options.length <= 1) {
1339
+ this.logger.error('At least two configurations are required for merge.');
1340
+ process.exit(2);
1341
+ }
1342
+
1343
+ const mergedConfigPaths = [];
1344
+
1345
+ config.options = config.options.reduce((accumulator, options) => {
1346
+ const configPath = config.path.get(options);
1347
+ const mergedOptions = merge(accumulator, options);
1348
+
1349
+ mergedConfigPaths.push(configPath);
1350
+
1351
+ return mergedOptions;
1352
+ }, {});
1353
+ config.path.set(config.options, mergedConfigPaths);
1354
+ }
1355
+
1356
+ return config;
1357
+ }
1358
+
1359
+ // TODO refactor
1360
+ async applyOptions(config, options) {
1361
+ if (options.analyze) {
1362
+ if (!this.utils.packageExists('webpack-bundle-analyzer')) {
1363
+ const { promptInstallation, colors } = this.utils;
1364
+
1365
+ try {
1366
+ await promptInstallation('webpack-bundle-analyzer', () => {
1367
+ this.logger.error(`It looks like ${colors.yellow('webpack-bundle-analyzer')} is not installed.`);
1368
+ });
1369
+ } catch (error) {
1370
+ this.logger.error(
1371
+ `Action Interrupted, Please try once again or install ${colors.yellow('webpack-bundle-analyzer')} manually.`,
1372
+ );
1373
+ process.exit(2);
1374
+ }
1375
+
1376
+ this.logger.success(`${colors.yellow('webpack-bundle-analyzer')} was installed successfully.`);
1377
+ }
1378
+ }
1379
+
1380
+ if (typeof options.progress === 'string' && options.progress !== 'profile') {
1381
+ this.logger.error(`'${options.progress}' is an invalid value for the --progress option. Only 'profile' is allowed.`);
1382
+ process.exit(2);
1383
+ }
1384
+
1385
+ const outputHints = (configOptions) => {
1386
+ if (
1387
+ configOptions.watch &&
1388
+ options.argv &&
1389
+ options.argv.env &&
1390
+ (options.argv.env['WEBPACK_WATCH'] || options.argv.env['WEBPACK_SERVE'])
1391
+ ) {
1392
+ this.logger.warn(
1393
+ `No need to use the '${
1394
+ options.argv.env['WEBPACK_WATCH'] ? 'watch' : 'serve'
1395
+ }' command together with '{ watch: true }' configuration, it does not make sense.`,
1396
+ );
1397
+
1398
+ if (options.argv.env['WEBPACK_SERVE']) {
1399
+ configOptions.watch = false;
1400
+ }
1401
+ }
1402
+
1403
+ return configOptions;
1404
+ };
1405
+
1406
+ config.options = Array.isArray(config.options)
1407
+ ? config.options.map((options) => outputHints(options))
1408
+ : outputHints(config.options);
1409
+
1410
+ if (this.webpack.cli) {
1411
+ const processArguments = (configOptions) => {
1412
+ const args = this.getBuiltInOptions()
1413
+ .filter((flag) => flag.group === 'core')
1414
+ .reduce((accumulator, flag) => {
1415
+ accumulator[flag.name] = flag;
1416
+
1417
+ return accumulator;
1418
+ }, {});
1419
+
1420
+ const values = Object.keys(options).reduce((accumulator, name) => {
1421
+ if (name === 'argv') {
1422
+ return accumulator;
1423
+ }
1424
+
1425
+ const kebabName = this.utils.toKebabCase(name);
1426
+
1427
+ if (args[kebabName]) {
1428
+ accumulator[kebabName] = options[name];
1429
+ }
1430
+
1431
+ return accumulator;
1432
+ }, {});
1433
+
1434
+ const problems = this.webpack.cli.processArguments(args, configOptions, values);
1435
+
1436
+ if (problems) {
1437
+ const groupBy = (xs, key) => {
1438
+ return xs.reduce((rv, x) => {
1439
+ (rv[x[key]] = rv[x[key]] || []).push(x);
1440
+
1441
+ return rv;
1442
+ }, {});
1443
+ };
1444
+ const problemsByPath = groupBy(problems, 'path');
1445
+
1446
+ for (const path in problemsByPath) {
1447
+ const problems = problemsByPath[path];
1448
+
1449
+ problems.forEach((problem) => {
1450
+ this.logger.error(
1451
+ `${this.utils.capitalizeFirstLetter(problem.type.replace(/-/g, ' '))}${
1452
+ problem.value ? ` '${problem.value}'` : ''
1453
+ } for the '--${problem.argument}' option${problem.index ? ` by index '${problem.index}'` : ''}`,
1454
+ );
1455
+
1456
+ if (problem.expected) {
1457
+ this.logger.error(`Expected: '${problem.expected}'`);
1458
+ }
1459
+ });
1460
+ }
1461
+
1462
+ process.exit(2);
1463
+ }
1464
+
1465
+ return configOptions;
1466
+ };
1467
+
1468
+ config.options = Array.isArray(config.options)
1469
+ ? config.options.map((options) => processArguments(options))
1470
+ : processArguments(config.options);
1471
+
1472
+ const setupDefaultOptions = (configOptions) => {
1473
+ // No need to run for webpack@4
1474
+ if (configOptions.cache && configOptions.cache.type === 'filesystem') {
1475
+ const configPath = config.path.get(configOptions);
1476
+
1477
+ if (configPath) {
1478
+ if (!configOptions.cache.buildDependencies) {
1479
+ configOptions.cache.buildDependencies = {};
1480
+ }
1481
+
1482
+ if (!configOptions.cache.buildDependencies.defaultConfig) {
1483
+ configOptions.cache.buildDependencies.defaultConfig = [];
1484
+ }
1485
+
1486
+ if (Array.isArray(configPath)) {
1487
+ configPath.forEach((item) => {
1488
+ configOptions.cache.buildDependencies.defaultConfig.push(item);
1489
+ });
1490
+ } else {
1491
+ configOptions.cache.buildDependencies.defaultConfig.push(configPath);
1492
+ }
1493
+ }
1494
+ }
1495
+
1496
+ return configOptions;
1497
+ };
1498
+
1499
+ config.options = Array.isArray(config.options)
1500
+ ? config.options.map((options) => setupDefaultOptions(options))
1501
+ : setupDefaultOptions(config.options);
1502
+ }
1503
+
1504
+ // Logic for webpack@4
1505
+ // TODO remove after drop webpack@4
1506
+ const processLegacyArguments = (configOptions) => {
1507
+ if (options.entry) {
1508
+ configOptions.entry = options.entry;
1509
+ }
1510
+
1511
+ if (options.outputPath) {
1512
+ configOptions.output = {
1513
+ ...configOptions.output,
1514
+ ...{ path: path.resolve(options.outputPath) },
1515
+ };
1516
+ }
1517
+
1518
+ if (options.target) {
1519
+ configOptions.target = options.target;
1520
+ }
1521
+
1522
+ if (typeof options.devtool !== 'undefined') {
1523
+ configOptions.devtool = options.devtool;
1524
+ }
1525
+
1526
+ if (options.mode) {
1527
+ configOptions.mode = options.mode;
1528
+ } else if (
1529
+ !configOptions.mode &&
1530
+ process.env &&
1531
+ process.env.NODE_ENV &&
1532
+ (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'none')
1533
+ ) {
1534
+ configOptions.mode = process.env.NODE_ENV;
1535
+ }
1536
+
1537
+ if (options.name) {
1538
+ configOptions.name = options.name;
1539
+ }
1540
+
1541
+ if (typeof options.stats !== 'undefined') {
1542
+ configOptions.stats = options.stats;
1543
+ }
1544
+
1545
+ if (typeof options.watch !== 'undefined') {
1546
+ configOptions.watch = options.watch;
1547
+ }
1548
+
1549
+ if (typeof options.watchOptionsStdin !== 'undefined') {
1550
+ configOptions.watchOptions = {
1551
+ ...configOptions.watchOptions,
1552
+ ...{ stdin: options.watchOptionsStdin },
1553
+ };
1554
+ }
1555
+
1556
+ return configOptions;
1557
+ };
1558
+
1559
+ config.options = Array.isArray(config.options)
1560
+ ? config.options.map((options) => processLegacyArguments(options))
1561
+ : processLegacyArguments(config.options);
1562
+
1563
+ // Apply `stats` and `stats.colors` options
1564
+ const applyStatsColors = (configOptions) => {
1565
+ // TODO remove after drop webpack@4
1566
+ const statsForWebpack4 = this.webpack.Stats && this.webpack.Stats.presetToOptions;
1567
+
1568
+ if (statsForWebpack4) {
1569
+ if (typeof configOptions.stats === 'undefined') {
1570
+ configOptions.stats = {};
1571
+ } else if (typeof configOptions.stats === 'boolean' || typeof configOptions.stats === 'string') {
1572
+ if (
1573
+ typeof configOptions.stats === 'string' &&
1574
+ configOptions.stats !== 'none' &&
1575
+ configOptions.stats !== 'verbose' &&
1576
+ configOptions.stats !== 'detailed' &&
1577
+ configOptions.stats !== 'minimal' &&
1578
+ configOptions.stats !== 'errors-only' &&
1579
+ configOptions.stats !== 'errors-warnings'
1580
+ ) {
1581
+ return configOptions;
1582
+ }
1583
+
1584
+ configOptions.stats = this.webpack.Stats.presetToOptions(configOptions.stats);
1585
+ }
1586
+ } else {
1587
+ if (typeof configOptions.stats === 'undefined') {
1588
+ configOptions.stats = { preset: 'normal' };
1589
+ } else if (typeof configOptions.stats === 'boolean') {
1590
+ configOptions.stats = configOptions.stats ? { preset: 'normal' } : { preset: 'none' };
1591
+ } else if (typeof configOptions.stats === 'string') {
1592
+ configOptions.stats = { preset: configOptions.stats };
1593
+ }
1594
+ }
1595
+
1596
+ let colors;
1597
+
1598
+ // From arguments
1599
+ if (typeof this.utils.colors.options.changed !== 'undefined') {
1600
+ colors = Boolean(this.utils.colors.options.enabled);
1601
+ }
1602
+ // From stats
1603
+ else if (typeof configOptions.stats.colors !== 'undefined') {
1604
+ colors = configOptions.stats.colors;
1605
+ }
1606
+ // Default
1607
+ else {
1608
+ colors = Boolean(this.utils.colors.options.enabled);
1609
+ }
1610
+
1611
+ configOptions.stats.colors = colors;
1612
+
1613
+ return configOptions;
1614
+ };
1615
+
1616
+ config.options = Array.isArray(config.options)
1617
+ ? config.options.map((options) => applyStatsColors(options))
1618
+ : applyStatsColors(config.options);
1619
+
1620
+ return config;
1621
+ }
1622
+
1623
+ async applyCLIPlugin(config, cliOptions) {
1624
+ const addCLIPlugin = (configOptions) => {
1625
+ if (!configOptions.plugins) {
1626
+ configOptions.plugins = [];
1627
+ }
1628
+
1629
+ const CLIPlugin = require('./plugins/CLIPlugin');
1630
+
1631
+ configOptions.plugins.unshift(
1632
+ new CLIPlugin({
1633
+ configPath: config.path,
1634
+ helpfulOutput: !cliOptions.json,
1635
+ hot: cliOptions.hot,
1636
+ progress: cliOptions.progress,
1637
+ prefetch: cliOptions.prefetch,
1638
+ analyze: cliOptions.analyze,
1639
+ }),
1640
+ );
1641
+
1642
+ return configOptions;
1643
+ };
1644
+ config.options = Array.isArray(config.options)
1645
+ ? config.options.map((options) => addCLIPlugin(options))
1646
+ : addCLIPlugin(config.options);
1647
+
1648
+ return config;
1649
+ }
1650
+
1651
+ needWatchStdin(compiler) {
1652
+ if (compiler.compilers) {
1653
+ return compiler.compilers.some((compiler) => compiler.options.watchOptions && compiler.options.watchOptions.stdin);
1654
+ }
1655
+
1656
+ return compiler.options.watchOptions && compiler.options.watchOptions.stdin;
1657
+ }
1658
+
1659
+ isValidationError(error) {
1660
+ // https://github.com/webpack/webpack/blob/master/lib/index.js#L267
1661
+ // https://github.com/webpack/webpack/blob/v4.44.2/lib/webpack.js#L90
1662
+ const ValidationError = this.webpack.ValidationError || this.webpack.WebpackOptionsValidationError;
1663
+
1664
+ return error instanceof ValidationError || error.name === 'ValidationError';
1665
+ }
1666
+
1667
+ async createCompiler(options, callback) {
1668
+ this.applyNodeEnv(options);
1669
+
1670
+ let config = await this.resolveConfig(options);
1671
+
1672
+ config = await this.applyOptions(config, options);
1673
+ config = await this.applyCLIPlugin(config, options);
1674
+
1675
+ let compiler;
1676
+
1677
+ try {
1678
+ compiler = this.webpack(
1679
+ config.options,
1680
+ callback
1681
+ ? (error, stats) => {
1682
+ if (error && this.isValidationError(error)) {
1683
+ this.logger.error(error.message);
1684
+ process.exit(2);
1685
+ }
1686
+
1687
+ callback(error, stats);
1688
+ }
1689
+ : callback,
1690
+ );
1691
+ } catch (error) {
1692
+ if (this.isValidationError(error)) {
1693
+ this.logger.error(error.message);
1694
+ } else {
1695
+ this.logger.error(error);
1696
+ }
1697
+
1698
+ process.exit(2);
1699
+ }
1700
+
1701
+ // TODO webpack@4 return Watching and MultiWatching instead Compiler and MultiCompiler, remove this after drop webpack@4
1702
+ if (compiler && compiler.compiler) {
1703
+ compiler = compiler.compiler;
1704
+ }
1705
+
1706
+ return compiler;
1707
+ }
1708
+
1709
+ async buildCommand(options, isWatchCommand) {
1710
+ let compiler;
1711
+
1712
+ const callback = (error, stats) => {
1713
+ if (error) {
1714
+ this.logger.error(error);
1715
+ process.exit(2);
1716
+ }
1717
+
1718
+ if (stats.hasErrors()) {
1719
+ process.exitCode = 1;
1720
+ }
1721
+
1722
+ if (!compiler) {
1723
+ return;
1724
+ }
1725
+
1726
+ const statsOptions = compiler.compilers
1727
+ ? { children: compiler.compilers.map((compiler) => (compiler.options ? compiler.options.stats : undefined)) }
1728
+ : compiler.options
1729
+ ? compiler.options.stats
1730
+ : undefined;
1731
+
1732
+ // TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats
1733
+ const statsForWebpack4 = this.webpack.Stats && this.webpack.Stats.presetToOptions;
1734
+
1735
+ if (compiler.compilers && statsForWebpack4) {
1736
+ statsOptions.colors = statsOptions.children.some((child) => child.colors);
1737
+ }
1738
+
1739
+ if (options.json) {
1740
+ const { stringifyStream: createJsonStringifyStream } = require('@discoveryjs/json-ext');
1741
+ const handleWriteError = (error) => {
1742
+ this.logger.error(error);
1743
+ process.exit(2);
1744
+ };
1745
+
1746
+ if (options.json === true) {
1747
+ createJsonStringifyStream(stats.toJson(statsOptions))
1748
+ .on('error', handleWriteError)
1749
+ .pipe(process.stdout)
1750
+ .on('error', handleWriteError)
1751
+ .on('close', () => process.stdout.write('\n'));
1752
+ } else {
1753
+ createJsonStringifyStream(stats.toJson(statsOptions))
1754
+ .on('error', handleWriteError)
1755
+ .pipe(fs.createWriteStream(options.json))
1756
+ .on('error', handleWriteError)
1757
+ // Use stderr to logging
1758
+ .on('close', () =>
1759
+ process.stderr.write(
1760
+ `[webpack-cli] ${this.utils.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`,
1761
+ ),
1762
+ );
1763
+ }
1764
+ } else {
1765
+ const printedStats = stats.toString(statsOptions);
1766
+
1767
+ // Avoid extra empty line when `stats: 'none'`
1768
+ if (printedStats) {
1769
+ this.logger.raw(printedStats);
1770
+ }
1771
+ }
1772
+ };
1773
+
1774
+ const env =
1775
+ isWatchCommand || options.watch
1776
+ ? { WEBPACK_WATCH: true, ...options.env }
1777
+ : { WEBPACK_BUNDLE: true, WEBPACK_BUILD: true, ...options.env };
1778
+
1779
+ options.argv = { ...options, env };
1780
+
1781
+ if (isWatchCommand) {
1782
+ options.watch = true;
1783
+ }
1784
+
1785
+ compiler = await this.createCompiler(options, callback);
1786
+
1787
+ if (!compiler) {
1788
+ return;
1789
+ }
1790
+
1791
+ const isWatch = (compiler) =>
1792
+ compiler.compilers ? compiler.compilers.some((compiler) => compiler.options.watch) : compiler.options.watch;
1793
+
1794
+ if (isWatch(compiler) && this.needWatchStdin(compiler)) {
1795
+ process.stdin.on('end', () => {
1796
+ process.exit(0);
1797
+ });
1798
+ process.stdin.resume();
1799
+ }
1800
+ }
1801
+ }
1802
+
1803
+ module.exports = WebpackCLI;