iobroker.javascript 9.3.1 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/README.md +5 -5
  2. package/admin/assets/AiChatPanel-p0KAg6Cs.js +237 -0
  3. package/admin/assets/AiDatapointProvider-DzFpUKkT.js +2 -0
  4. package/admin/assets/AiDiffView-BPTLnNx1.js +1 -0
  5. package/admin/assets/AiInlineProvider-CaHd2G2Q.js +5 -0
  6. package/admin/assets/AiScriptAnalyzer--BHML2rN.js +9 -0
  7. package/admin/assets/BlocklyEditor-CAjVMhYT.js +81 -0
  8. package/admin/assets/ContextWrapper-BVc8wTK_.css +1 -0
  9. package/admin/assets/ContextWrapper-D9CrnNKs.js +127 -0
  10. package/admin/assets/Debugger-SjROokFI.js +15 -0
  11. package/admin/assets/Error-DDfrxAt2.js +1 -0
  12. package/admin/assets/Import-DpTg1Jow.js +1 -0
  13. package/admin/assets/RulesEditor-BSRFWpEm.css +1 -0
  14. package/admin/assets/RulesEditor-D0hgrcBc.js +1 -0
  15. package/admin/assets/ScriptEditor-BGIuoNei.js +2 -0
  16. package/admin/assets/ScriptEditorVanillaMonaco-DyMQtoTQ.js +3 -0
  17. package/admin/assets/_virtual_mf-localSharedImportMap___mfe_internal__iobroker_javascript__mf_owner__1-DWJotR1B.js +1 -0
  18. package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-CxICLr5Z.js +1243 -0
  19. package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-BBAXJaqI.js +9 -0
  20. package/admin/assets/aiCodeLensProvider-hyAmut0e.js +4 -0
  21. package/admin/assets/aiPromptBuilder-Bs27qOHT.js +7 -0
  22. package/admin/assets/applyCodeEdit-D3nb7erO.js +1 -0
  23. package/admin/assets/blocklyDarkTheme-DEiAX5DT.js +1 -0
  24. package/admin/assets/cronHoverProvider-pKJkSevo.js +2 -0
  25. package/admin/assets/dist-uw5orDgd.js +4 -0
  26. package/admin/assets/{docs-compact-CKNGiYh2.js → docs-compact-D7rpMc7r.js} +2 -2
  27. package/admin/assets/hostInit-BFg5u9hY.js +1 -0
  28. package/admin/assets/index-B1gICjdq.js +192 -0
  29. package/admin/assets/index-BHhhebRG.css +1 -0
  30. package/admin/assets/inlineChatWidget-ZaisTOLh.js +2 -0
  31. package/admin/assets/inlineDiffController-hTwHHqcc.js +16 -0
  32. package/admin/assets/mf-entry-bootstrap-0-d6052b31.js +36 -0
  33. package/admin/assets/mjs-DWqivHEk.js +90 -0
  34. package/admin/assets/rolldown-runtime-C0FnF6B9.js +1 -0
  35. package/admin/assets/stateHoverProvider-C7DawIs-.js +9 -0
  36. package/admin/assets/virtualExposes-Ed0lGq7k.js +1 -0
  37. package/admin/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__iobroker_javascript__remoteEntry_js-BYs71IQF.js +1 -0
  38. package/admin/assets/virtual_mf-exposes___mfe_internal__iobroker_javascript__remoteEntry_js-DnnXQRkG.js +1 -0
  39. package/admin/assets/vite-preload-helper-B7qeedMF.js +1 -0
  40. package/admin/custom/assets/Components-BrDyDHXh.js +1 -0
  41. package/admin/custom/assets/Components-DftM8alF.css +1 -0
  42. package/admin/custom/assets/_virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1-CyYJM2-v.js +1 -0
  43. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_react__loadShare__.js-BdzCssLn.js +1 -0
  44. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_styled__loadShare__.js-CGb5Cofy.js +1 -0
  45. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-BVCIAgbo.js +1243 -0
  46. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_json_mf_2_config__loadShare__.js-BkB0anQX.js +1494 -0
  47. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__leaflet__loadShare__.js-h-rCw3iz.js +1 -0
  48. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-BotqDuw-.js +9 -0
  49. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__date_mf_2_fns__prebuild__-Cb5TR7FB.js +1 -0
  50. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__leaflet__prebuild__-DARUoA03.js +1 -0
  51. package/admin/custom/assets/hostInit-DJx2uXXy.js +1 -0
  52. package/admin/custom/assets/index-uEKAoVT7.js +1 -0
  53. package/admin/custom/assets/lib-Yj8cfN0A.js +3 -0
  54. package/admin/custom/assets/mf-entry-bootstrap-0-77793feb.js +36 -0
  55. package/admin/custom/assets/rolldown-runtime-BcKkbAw3.js +1 -0
  56. package/admin/custom/assets/setYear-DJ9FbdkO.js +1 -0
  57. package/admin/custom/assets/virtualExposes-CxDjLoYu.js +1 -0
  58. package/admin/custom/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-BU-ugy_7.js +1 -0
  59. package/admin/custom/assets/virtual_mf-exposes-ssr___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-BEfZbrf7.js +2 -0
  60. package/admin/custom/assets/virtual_mf-exposes___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-CTeZ0Jpm.js +2 -0
  61. package/admin/custom/assets/vite-preload-helper-B7qeedMF.js +1 -0
  62. package/admin/custom/customComponents.js +1 -1
  63. package/admin/jsonConfig.json +1 -1
  64. package/admin/mf-manifest.json +1 -1
  65. package/admin/mf-stats.json +1 -0
  66. package/admin/remoteEntry.js +1 -1
  67. package/admin/tab.html +12 -17
  68. package/build/lib/debugger.js +1 -1
  69. package/build/lib/debugger.js.map +1 -1
  70. package/build/lib/eventObj.js.map +1 -1
  71. package/build/lib/inspect.js.map +1 -1
  72. package/build/lib/javascript.d.ts +18 -19
  73. package/build/lib/nodeModulesManagement.js +3 -1
  74. package/build/lib/nodeModulesManagement.js.map +1 -1
  75. package/build/lib/protectFs.js.map +1 -1
  76. package/build/lib/sandbox.js +84 -31
  77. package/build/lib/sandbox.js.map +1 -1
  78. package/build/lib/scheduler.js.map +1 -1
  79. package/build/lib/tools.js +1 -1
  80. package/build/lib/tools.js.map +1 -1
  81. package/build/lib/typescriptSettings.js +16 -10
  82. package/build/lib/typescriptSettings.js.map +1 -1
  83. package/build/lib/typescriptTools.js +2 -2
  84. package/build/lib/typescriptTools.js.map +1 -1
  85. package/build/main.js +7 -4
  86. package/build/main.js.map +1 -1
  87. package/build/src/lib/aiProviderResolver.js +107 -0
  88. package/build/src/lib/aiProviderResolver.js.map +1 -0
  89. package/build/src/lib/anthropicAdapter.js +175 -0
  90. package/build/src/lib/anthropicAdapter.js.map +1 -0
  91. package/build/src/lib/consts.js +346 -0
  92. package/build/src/lib/consts.js.map +1 -0
  93. package/build/src/lib/convert.js +121 -0
  94. package/build/src/lib/convert.js.map +1 -0
  95. package/build/src/lib/crypto.js +32 -0
  96. package/build/src/lib/crypto.js.map +1 -0
  97. package/build/src/lib/debug.js +163 -0
  98. package/build/src/lib/debug.js.map +1 -0
  99. package/build/src/lib/debugger.js +1135 -0
  100. package/build/src/lib/debugger.js.map +1 -0
  101. package/build/src/lib/eventObj.js +194 -0
  102. package/build/src/lib/eventObj.js.map +1 -0
  103. package/build/src/lib/inspect.js +728 -0
  104. package/build/src/lib/inspect.js.map +1 -0
  105. package/build/src/lib/mirror.js +634 -0
  106. package/build/src/lib/mirror.js.map +1 -0
  107. package/build/src/lib/nodeModulesManagement.js +26 -0
  108. package/build/src/lib/nodeModulesManagement.js.map +1 -0
  109. package/build/src/lib/patternCompareFunctions.js +293 -0
  110. package/build/src/lib/patternCompareFunctions.js.map +1 -0
  111. package/build/src/lib/protectFs.js +554 -0
  112. package/build/src/lib/protectFs.js.map +1 -0
  113. package/build/src/lib/sandbox.js +4897 -0
  114. package/build/src/lib/sandbox.js.map +1 -0
  115. package/build/src/lib/scheduler.js +555 -0
  116. package/build/src/lib/scheduler.js.map +1 -0
  117. package/build/src/lib/tools.js +188 -0
  118. package/build/src/lib/tools.js.map +1 -0
  119. package/build/src/lib/typescriptSettings.js +39 -0
  120. package/build/src/lib/typescriptSettings.js.map +1 -0
  121. package/build/src/lib/typescriptTools.js +435 -0
  122. package/build/src/lib/typescriptTools.js.map +1 -0
  123. package/build/src/lib/utils.js +66 -0
  124. package/build/src/lib/utils.js.map +1 -0
  125. package/build/src/lib/words.js +76 -0
  126. package/build/src/lib/words.js.map +1 -0
  127. package/build/src/main.js +3414 -0
  128. package/build/src/main.js.map +1 -0
  129. package/build/types.d.ts +2 -10
  130. package/io-package.json +15 -15
  131. package/package.json +15 -16
  132. package/admin/assets/AiChatPanel-C3bIw_D5.js +0 -317
  133. package/admin/assets/AiDatapointProvider-B0i3I5Fm.js +0 -2
  134. package/admin/assets/AiDiffView-RPozjjHf.js +0 -1
  135. package/admin/assets/AiInlineProvider-DkgjVSFQ.js +0 -7
  136. package/admin/assets/Save-CkuNSiWL.js +0 -1
  137. package/admin/assets/ScriptEditor-8UU88tT5.js +0 -2
  138. package/admin/assets/ScriptEditorVanillaMonaco-Bn8xJ3LV.js +0 -3
  139. package/admin/assets/applyCodeEdit-BdRnbz2g.js +0 -1
  140. package/admin/assets/createSvgIcon-DYs_tNrE.js +0 -8
  141. package/admin/assets/cronHoverProvider-Bg0Vz-1E.js +0 -2
  142. package/admin/assets/hostInit-LzITLWDa.js +0 -1
  143. package/admin/assets/index-45IwpC7_.js +0 -1
  144. package/admin/assets/index-BCK6q-N6.css +0 -1
  145. package/admin/assets/index-BTsjunTt.css +0 -1
  146. package/admin/assets/index-BkyLyaYT.js +0 -8
  147. package/admin/assets/index-C0ZnUCQf.js +0 -990
  148. package/admin/assets/index-CO9RA-Wq.js +0 -1267
  149. package/admin/assets/index-CRGWWpGb.js +0 -1
  150. package/admin/assets/index-CVZSzCXy.js +0 -1
  151. package/admin/assets/index-CsyuIWlD.js +0 -16
  152. package/admin/assets/index-Dsh1HfIY.js +0 -1
  153. package/admin/assets/index-dN73sbyQ.js +0 -193
  154. package/admin/assets/index-wHNMOf-c.js +0 -5
  155. package/admin/assets/inheritsLoose-CIXm_zPk.js +0 -29
  156. package/admin/assets/inlineChatWidget-Cu6rb4Ar.js +0 -2
  157. package/admin/assets/inlineDiffController-DBLpPOe2.js +0 -16
  158. package/admin/assets/iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js +0 -1
  159. package/admin/assets/iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-CV1_X-Lf.js +0 -1
  160. package/admin/assets/iobroker_javascript__loadShare__prop_mf_2_types__loadShare__.mjs-BCtSFofY.js +0 -1
  161. package/admin/assets/iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js +0 -1
  162. package/admin/assets/iobroker_javascript__loadShare__react__loadShare__.mjs_commonjs-proxy-CE9lvhW8.js +0 -1
  163. package/admin/assets/iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs-DeVAS-oa.js +0 -1
  164. package/admin/assets/iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-RQRRZMX5.js +0 -1
  165. package/admin/assets/localSharedImportMap-Db5DxDmY.js +0 -1
  166. package/admin/assets/preload-helper-BDBacUwf.js +0 -1
  167. package/admin/assets/stateHoverProvider-C82xsI7Q.js +0 -9
  168. package/admin/assets/useTheme-DuTJsNQ-.js +0 -1
  169. package/admin/assets/virtualExposes-BPsCufin.js +0 -1
  170. package/admin/assets/virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-Bw22wl4W.js +0 -8
  171. package/admin/custom/assets/Components-BOms95_F.css +0 -1
  172. package/admin/custom/assets/Components-CGiJE5Zh.js +0 -1
  173. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare___mf_0_emotion_mf_1_react__loadShare__.mjs-sg07E3QA.js +0 -1
  174. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare___mf_0_emotion_mf_1_styled__loadShare__.mjs-CwjI4A-J.js +0 -1
  175. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-B7D2xOvV.js +0 -1
  176. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare___mf_0_iobroker_mf_1_json_mf_2_config__loadShare__.mjs-ClsgYnEX.js +0 -1
  177. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare___mf_0_mui_mf_1_icons_mf_2_material__loadShare__.mjs-B551AMx-.js +0 -1
  178. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-KsT5vKjV.js +0 -1
  179. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare___mf_0_mui_mf_1_x_mf_2_date_mf_2_pickers__loadShare__.mjs-DgHZUNxn.js +0 -1
  180. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare__leaflet__loadShare__.mjs-BYONkEgA.js +0 -1
  181. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare__react__loadShare__.mjs-BW9Qbxx5.js +0 -1
  182. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare__react__loadShare__.mjs_commonjs-proxy-2W2BYT2K.js +0 -1
  183. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare__react_mf_2_dom__loadShare__.mjs-CL--xmjC.js +0 -1
  184. package/admin/custom/assets/ConfigCustomJavascriptSet__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-D8zcZsJo.js +0 -1
  185. package/admin/custom/assets/DefaultPropsProvider-CfKHPa-G.js +0 -1
  186. package/admin/custom/assets/TextField-CxPfV5Sr.js +0 -139
  187. package/admin/custom/assets/ThemeProvider-DSTCckLJ.js +0 -29
  188. package/admin/custom/assets/blue-CagzI6CQ.js +0 -1
  189. package/admin/custom/assets/createSvgIcon-b2B2NI3g.js +0 -1
  190. package/admin/custom/assets/createTheme-MsdB8zt7.js +0 -8
  191. package/admin/custom/assets/defaultTheme-CmVP-QNF.js +0 -1
  192. package/admin/custom/assets/emotion-cache.browser.esm-BgJfNZJN.js +0 -1
  193. package/admin/custom/assets/emotion-react.browser.esm-chZAeh_-.js +0 -1
  194. package/admin/custom/assets/emotion-serialize.esm-BUa21YfQ.js +0 -1
  195. package/admin/custom/assets/emotion-styled.browser.esm-Yi13plpH.js +0 -1
  196. package/admin/custom/assets/emotion-use-insertion-effect-with-fallbacks.browser.esm-CEPeBbh9.js +0 -1
  197. package/admin/custom/assets/extends-CF3RwP-h.js +0 -1
  198. package/admin/custom/assets/hostInit-iUL-wyj1.js +0 -1
  199. package/admin/custom/assets/index-17vbGv00.js +0 -1
  200. package/admin/custom/assets/index-B5DqCD_a.js +0 -1
  201. package/admin/custom/assets/index-Bvwv5H7k.js +0 -1
  202. package/admin/custom/assets/index-CMsuyEZj.js +0 -964
  203. package/admin/custom/assets/index-CuAhFQ4L.js +0 -1523
  204. package/admin/custom/assets/index-CzRngQHl.js +0 -31
  205. package/admin/custom/assets/index-DLNtxshy.js +0 -1
  206. package/admin/custom/assets/index-DV76KW3-.js +0 -7
  207. package/admin/custom/assets/index-D_5kZmfw.js +0 -1
  208. package/admin/custom/assets/index-DlQbqHom.js +0 -8
  209. package/admin/custom/assets/index-DpJ18x6R.js +0 -1
  210. package/admin/custom/assets/index-FTmk0JJx.js +0 -55
  211. package/admin/custom/assets/index-mkhHeJ3Q.js +0 -1
  212. package/admin/custom/assets/isSameWeek-DDsSIa_t.js +0 -1
  213. package/admin/custom/assets/jsx-runtime-BplTyRFk.js +0 -1
  214. package/admin/custom/assets/leaflet-src-B472P7Y1.js +0 -1
  215. package/admin/custom/assets/localSharedImportMap-BsMINYMr.js +0 -1
  216. package/admin/custom/assets/preload-helper-BDBacUwf.js +0 -1
  217. package/admin/custom/assets/useTheme-BV4xOYIL.js +0 -1
  218. package/admin/custom/assets/useTheme-ldICnlmf.js +0 -1
  219. package/admin/custom/assets/virtualExposes-D402kVGY.js +0 -2
  220. package/admin/custom/assets/virtual_mf-REMOTE_ENTRY_ID_ConfigCustomJavascriptSet__customComponents_js-BzLNCazi.js +0 -8
@@ -0,0 +1,1135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = createRepl;
4
+ /*
5
+ * Copyright Node.js contributors. All rights reserved.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to
9
+ * deal in the Software without restriction, including without limitation the
10
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11
+ * sell copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
+ * IN THE SOFTWARE.
24
+ */
25
+ const node_path_1 = require("node:path");
26
+ const node_repl_1 = require("node:repl");
27
+ const node_util_1 = require("node:util");
28
+ const node_vm_1 = require("node:vm");
29
+ const node_url_1 = require("node:url");
30
+ const node_module_1 = require("node:module");
31
+ const debuglog = (0, node_util_1.debuglog)('inspect');
32
+ /*const SHORTCUTS = {
33
+ cont: 'c',
34
+ next: 'n',
35
+ step: 's',
36
+ out: 'o',
37
+ backtrace: 'bt',
38
+ setBreakpoint: 'sb',
39
+ clearBreakpoint: 'cb',
40
+ run: 'r',
41
+ };
42
+
43
+ const HELP = `
44
+ run, restart, r Run the application or reconnect
45
+ kill Kill a running application or disconnect
46
+
47
+ cont, c Resume execution
48
+ next, n Continue to next line in current file
49
+ step, s Step into, potentially entering a function
50
+ out, o Step out, leaving the current function
51
+ backtrace, bt Print the current backtrace
52
+ list Print the source around the current line where execution
53
+ is currently paused
54
+
55
+ setBreakpoint, sb Set a breakpoint
56
+ clearBreakpoint, cb Clear a breakpoint
57
+ breakpoints List all known breakpoints
58
+ breakOnException Pause execution whenever an exception is thrown
59
+ breakOnUncaught Pause execution whenever an exception isn't caught
60
+ breakOnNone Don't pause on exceptions (this is the default)
61
+
62
+ watch(expr) Start watching the given expression
63
+ unwatch(expr) Stop watching an expression
64
+ watchers Print all watched expressions and their current values
65
+
66
+ exec(expr) Evaluate the expression and print the value
67
+ repl Enter a debug repl that works like exec
68
+
69
+ scripts List application scripts that are currently loaded
70
+ scripts(true) List all scripts (including node-internals)
71
+
72
+ profile Start CPU profiling session.
73
+ profileEnd Stop current CPU profiling session.
74
+ profiles Array of completed CPU profiling sessions.
75
+ profiles[n].save(filepath = 'node.cpuprofile')
76
+ Save CPU profiling session to disk as JSON.
77
+
78
+ takeHeapSnapshot(filepath = 'node.heapsnapshot')
79
+ Take a heap snapshot and save to disk as JSON.
80
+ `.trim();*/
81
+ const FUNCTION_NAME_PATTERN = /^(?:function\*? )?([^(\s]+)\(/;
82
+ function extractFunctionName(description) {
83
+ const fnNameMatch = description?.match(FUNCTION_NAME_PATTERN);
84
+ return fnNameMatch ? `: ${fnNameMatch[1]}` : '';
85
+ }
86
+ // process.binding is a method available on the process object, which allows you to load internal modules written in C++
87
+ // @ts-expect-error binding is internal function
88
+ const NATIVES = node_module_1.builtinModules ? process.binding('natives') : {};
89
+ function isNativeUrl(url) {
90
+ url = url.replace(/\.js$/, '');
91
+ if (node_module_1.builtinModules) {
92
+ if (url.startsWith('internal/') || node_module_1.builtinModules.includes(url)) {
93
+ return true;
94
+ }
95
+ }
96
+ return url in NATIVES || url === 'bootstrap_node';
97
+ }
98
+ function getRelativePath(filenameOrURL) {
99
+ const dir = (0, node_path_1.join)((0, node_path_1.resolve)(), 'x').slice(0, -1);
100
+ const filename = filenameOrURL.startsWith('file://') ? (0, node_url_1.fileURLToPath)(filenameOrURL) : filenameOrURL;
101
+ // Change a path to relative, if possible
102
+ if (filename.indexOf(dir) === 0) {
103
+ return filename.slice(dir.length);
104
+ }
105
+ return filename;
106
+ }
107
+ function toCallback(promise, callback) {
108
+ function forward(...args) {
109
+ process.nextTick(() => callback(...args));
110
+ }
111
+ promise.then(forward.bind(null, null), forward);
112
+ }
113
+ // Adds spaces and prefix to number
114
+ // maxN is a maximum number we should have space for
115
+ function leftPad(n, prefix, maxN) {
116
+ const s = n.toString();
117
+ const nchars = Math.max(2, String(maxN).length) + 1;
118
+ const nspaces = nchars - s.length - 1;
119
+ return prefix + ' '.repeat(nspaces) + s;
120
+ }
121
+ function markSourceColumn(sourceText, position, useColors) {
122
+ if (!sourceText) {
123
+ return '';
124
+ }
125
+ const head = sourceText.slice(0, position);
126
+ let tail = sourceText.slice(position);
127
+ // Colorize char if stdout supports colours
128
+ if (useColors) {
129
+ tail = tail.replace(/(.+?)([^\w]|$)/, '\u001b[32m$1\u001b[39m$2');
130
+ }
131
+ // Return source line with coloured char at `position`
132
+ return [head, tail].join('');
133
+ }
134
+ function extractErrorMessage(stack) {
135
+ if (!stack) {
136
+ return '<unknown>';
137
+ }
138
+ const m = stack.match(/^\w+: ([^\n]+)/);
139
+ return m ? m[1] : stack;
140
+ }
141
+ function convertResultToError(result) {
142
+ const { className, description } = result;
143
+ const err = new Error(extractErrorMessage(description));
144
+ err.stack = description;
145
+ Object.defineProperty(err, 'name', { value: className });
146
+ return err;
147
+ }
148
+ class RemoteObject {
149
+ type;
150
+ subtype;
151
+ className;
152
+ value;
153
+ unserializableValue;
154
+ description;
155
+ objectId;
156
+ preview;
157
+ customPreview;
158
+ constructor(attributes) {
159
+ this.type = 'undefined';
160
+ Object.assign(this, attributes);
161
+ if (this.type === 'number') {
162
+ this.value = this.unserializableValue ? +this.unserializableValue : +this.value;
163
+ }
164
+ }
165
+ [node_util_1.inspect.custom](_depth, opts) {
166
+ function formatProperty(prop) {
167
+ switch (prop.type) {
168
+ case 'string':
169
+ case 'undefined':
170
+ return (0, node_util_1.inspect)(prop.value, opts);
171
+ case 'number':
172
+ case 'boolean':
173
+ return opts.stylize(prop.value, prop.type);
174
+ case 'object':
175
+ case 'symbol':
176
+ if (prop.subtype === 'date') {
177
+ return (0, node_util_1.inspect)(new Date(prop.value), opts);
178
+ }
179
+ if (prop.subtype === 'array') {
180
+ return opts.stylize(prop.value, 'special');
181
+ }
182
+ return opts.stylize(prop.value, prop.subtype || 'special');
183
+ default:
184
+ return prop.value;
185
+ }
186
+ }
187
+ switch (this.type) {
188
+ case 'boolean':
189
+ case 'number':
190
+ case 'string':
191
+ case 'undefined':
192
+ return (0, node_util_1.inspect)(this.value, opts);
193
+ case 'symbol':
194
+ return opts.stylize(this.description, 'special');
195
+ case 'function': {
196
+ const fnName = extractFunctionName(this.description);
197
+ const formatted = `[${this.className}${fnName}]`;
198
+ return opts.stylize(formatted, 'special');
199
+ }
200
+ case 'object':
201
+ switch (this.subtype) {
202
+ case 'date':
203
+ return (0, node_util_1.inspect)(new Date(this.description), opts);
204
+ case 'null':
205
+ return (0, node_util_1.inspect)(null, opts);
206
+ case 'regexp':
207
+ return opts.stylize(this.description, 'regexp');
208
+ default:
209
+ break;
210
+ }
211
+ if (this.preview) {
212
+ const props = this.preview.properties.map((prop, idx) => {
213
+ const value = formatProperty(prop);
214
+ if (prop.name === `${idx}`) {
215
+ return value;
216
+ }
217
+ return `${prop.name}: ${value}`;
218
+ });
219
+ if (this.preview.overflow) {
220
+ props.push('...');
221
+ }
222
+ const singleLine = props.join(', ');
223
+ const propString = singleLine.length > 60 ? props.join(',\n ') : singleLine;
224
+ return this.subtype === 'array' ? `[ ${propString} ]` : `{ ${propString} }`;
225
+ }
226
+ return this.description || '';
227
+ default:
228
+ return this.description || '';
229
+ }
230
+ }
231
+ static fromEvalResult({ result, wasThrown }) {
232
+ if (wasThrown) {
233
+ return convertResultToError(result);
234
+ }
235
+ return new RemoteObject(result);
236
+ }
237
+ }
238
+ class ScopeSnapshot {
239
+ /**
240
+ * Scope type.
241
+ */
242
+ type;
243
+ /**
244
+ * Object representing the scope. For <code>global</code> and <code>with</code> scopes it represents the actual object; for the rest of the scopes, it is artificial transient object enumerating scope variables as its properties.
245
+ */
246
+ object;
247
+ name;
248
+ /**
249
+ * Location in the source code where scope starts
250
+ */
251
+ startLocation;
252
+ /**
253
+ * Location in the source code where scope ends
254
+ */
255
+ endLocation;
256
+ properties;
257
+ completionGroup;
258
+ constructor(scope, properties) {
259
+ this.type = scope.type;
260
+ this.object = scope.object;
261
+ Object.assign(this, scope);
262
+ this.properties = new Map(properties.map(prop => {
263
+ const value = new RemoteObject(prop.value);
264
+ return [prop.name, value];
265
+ }));
266
+ this.completionGroup = properties.map(prop => prop.name);
267
+ }
268
+ [node_util_1.inspect.custom](_depth, opts) {
269
+ const type = `${this.type[0].toUpperCase()}${this.type.slice(1)}`;
270
+ const name = this.name ? `<${this.name}>` : '';
271
+ const prefix = `${type}${name} `;
272
+ return (0, node_util_1.inspect)(this.properties, opts).replace(/^Map /, prefix);
273
+ }
274
+ }
275
+ /*
276
+ function copyOwnProperties(target: any, source: any): void {
277
+ Object.getOwnPropertyNames(source).forEach(prop => {
278
+ const descriptor = Object.getOwnPropertyDescriptor(source, prop);
279
+ if (descriptor) {
280
+ Object.defineProperty(target, prop, descriptor);
281
+ }
282
+ });
283
+ }
284
+
285
+ function aliasProperties(target, mapping) {
286
+ Object.keys(mapping).forEach((key) => {
287
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
288
+ Object.defineProperty(target, mapping[key], descriptor);
289
+ });
290
+ }
291
+ */
292
+ function createRepl(inspector) {
293
+ const { Debugger, /*HeapProfiler, Profiler,*/ Runtime } = inspector;
294
+ let repl;
295
+ // Things we want to keep around
296
+ // const history = { control: [], debug: [] };
297
+ // const watchedExpressions = [];
298
+ // const knownBreakpoints = [];
299
+ // let pauseOnExceptionState = 'none';
300
+ let lastCommand;
301
+ // Things we need to reset when the app restarts
302
+ let knownScripts = {};
303
+ let currentBacktrace;
304
+ let selectedFrame;
305
+ let exitDebugRepl;
306
+ function resetOnStart() {
307
+ knownScripts = {};
308
+ currentBacktrace = undefined;
309
+ selectedFrame = undefined;
310
+ if (exitDebugRepl) {
311
+ exitDebugRepl();
312
+ }
313
+ exitDebugRepl = undefined;
314
+ }
315
+ resetOnStart();
316
+ const INSPECT_OPTIONS = { colors: inspector.stdout.isTTY };
317
+ function inspect(value) {
318
+ return (0, node_util_1.inspect)(value, INSPECT_OPTIONS);
319
+ }
320
+ function print(value, oneline = false) {
321
+ const text = typeof value === 'string' ? value : inspect(value);
322
+ return inspector.print(text, oneline);
323
+ }
324
+ function getCurrentLocation() {
325
+ if (!selectedFrame) {
326
+ throw new Error('Requires execution to be paused');
327
+ }
328
+ return selectedFrame.location;
329
+ }
330
+ function isCurrentScript(script) {
331
+ return !!selectedFrame && getCurrentLocation().scriptId === script.scriptId;
332
+ }
333
+ function formatScripts(displayNatives = false) {
334
+ function isVisible(script) {
335
+ if (displayNatives) {
336
+ return true;
337
+ }
338
+ return !script.isNative || isCurrentScript(script);
339
+ }
340
+ return Object.keys(knownScripts)
341
+ .map(scriptId => knownScripts[scriptId])
342
+ .filter(isVisible)
343
+ .map(script => {
344
+ const isCurrent = isCurrentScript(script);
345
+ const { isNative, url } = script;
346
+ const name = `${getRelativePath(url)}${isNative ? ' <native>' : ''}`;
347
+ return `${isCurrent ? '*' : ' '} ${script.scriptId}: ${name}`;
348
+ })
349
+ .join('\n');
350
+ }
351
+ function listScripts(displayNatives = false) {
352
+ print(formatScripts(displayNatives));
353
+ }
354
+ // @ts-expect-error no idea what this is
355
+ listScripts[node_util_1.inspect.custom] = function listWithoutInternal() {
356
+ return formatScripts();
357
+ };
358
+ /*
359
+ const profiles = [];
360
+ class Profile {
361
+ constructor(data) {
362
+ this.data = data;
363
+ }
364
+
365
+ static createAndRegister({ profile }) {
366
+ const p = new Profile(profile);
367
+ profiles.push(p);
368
+ return p;
369
+ }
370
+
371
+ [util.inspect.custom](depth, { stylize }) {
372
+ const { startTime, endTime } = this.data;
373
+ return stylize(`[Profile ${endTime - startTime}μs]`, 'special');
374
+ }
375
+
376
+ save(filename = 'node.cpuprofile') {
377
+ const absoluteFile = Path.resolve(filename);
378
+ const json = JSON.stringify(this.data);
379
+ FS.writeFileSync(absoluteFile, json);
380
+ print(`Saved profile to ${absoluteFile}`);
381
+ }
382
+ }
383
+ */
384
+ class SourceSnippet {
385
+ scriptSource;
386
+ /**
387
+ * Script identifier as reported in the <code>Debugger.scriptParsed</code>.
388
+ */
389
+ scriptId;
390
+ /**
391
+ * Line number in the script (0-based).
392
+ */
393
+ lineNumber;
394
+ /**
395
+ * Column number in the script (0-based).
396
+ */
397
+ columnNumber;
398
+ delta;
399
+ constructor(location, delta, scriptSource) {
400
+ this.lineNumber = location.lineNumber;
401
+ this.columnNumber = location.columnNumber || 0;
402
+ this.scriptId = location.scriptId;
403
+ this.scriptSource = scriptSource;
404
+ this.delta = delta;
405
+ Object.assign(this, location);
406
+ }
407
+ [node_util_1.inspect.custom](_depth, options) {
408
+ const { /* scriptId, */ lineNumber, columnNumber, delta, scriptSource } = this;
409
+ const start = Math.max(1, lineNumber - delta + 1);
410
+ const end = lineNumber + delta + 1;
411
+ const lines = scriptSource.split('\n');
412
+ return lines
413
+ .slice(start - 1, end)
414
+ .map((lineText, offset) => {
415
+ const i = start + offset;
416
+ const isCurrent = i === lineNumber + 1;
417
+ const markedLine = isCurrent ? markSourceColumn(lineText, columnNumber, options.colors) : lineText;
418
+ /*
419
+ let isBreakpoint = false;
420
+ knownBreakpoints.forEach(({ location }) => {
421
+ if (!location) return;
422
+ if (scriptId === location.scriptId &&
423
+ i === (location.lineNumber + 1)) {
424
+ isBreakpoint = true;
425
+ }
426
+ });
427
+ */
428
+ let prefixChar = ' ';
429
+ if (isCurrent) {
430
+ prefixChar = '>';
431
+ } /*else if (isBreakpoint) {
432
+ prefixChar = '*';
433
+ }*/
434
+ return `${leftPad(i, prefixChar, end)} ${markedLine}`;
435
+ })
436
+ .join('\n');
437
+ }
438
+ }
439
+ function getSourceSnippet(location, delta = 5) {
440
+ const { scriptId } = location;
441
+ return Debugger.getScriptSource({ scriptId }).then(({ scriptSource }) => new SourceSnippet(location, delta, scriptSource));
442
+ }
443
+ class CallFrame {
444
+ /**
445
+ * Call frame identifier. This identifier is only valid while the virtual machine is paused.
446
+ */
447
+ callFrameId;
448
+ /**
449
+ * Name of the JavaScript function called on this call frame.
450
+ */
451
+ functionName;
452
+ /**
453
+ * Location in the source code.
454
+ */
455
+ functionLocation;
456
+ /**
457
+ * Location in the source code.
458
+ */
459
+ location;
460
+ /**
461
+ * JavaScript script name or url.
462
+ */
463
+ url;
464
+ /**
465
+ * Scope chain for this call frame.
466
+ */
467
+ scopeChain;
468
+ /**
469
+ * <code>this</code> object for this call frame.
470
+ */
471
+ this;
472
+ /**
473
+ * The value being returned if the function is at return point.
474
+ */
475
+ returnValue;
476
+ constructor(callFrame) {
477
+ this.functionName = callFrame.functionName;
478
+ this.url = callFrame.url;
479
+ this.scopeChain = callFrame.scopeChain;
480
+ this.this = callFrame.this;
481
+ this.returnValue = callFrame.returnValue;
482
+ this.location = callFrame.location;
483
+ this.callFrameId = callFrame.callFrameId;
484
+ Object.assign(this, callFrame);
485
+ }
486
+ loadScopes() {
487
+ return Promise.all(this.scopeChain
488
+ .filter(scope => scope.type !== 'global')
489
+ .map(scope => {
490
+ const { objectId } = scope.object;
491
+ return Runtime.getProperties({
492
+ objectId,
493
+ generatePreview: true,
494
+ }).then(({ result }) => {
495
+ return new ScopeSnapshot(scope, result);
496
+ });
497
+ }));
498
+ }
499
+ list(delta = 5) {
500
+ return getSourceSnippet(this.location, delta);
501
+ }
502
+ }
503
+ class Backtrace extends Array {
504
+ [node_util_1.inspect.custom]() {
505
+ return this.map((callFrame, idx) => {
506
+ const { location: { scriptId, lineNumber, columnNumber }, functionName, } = callFrame;
507
+ const name = functionName || '(anonymous)';
508
+ const script = knownScripts[scriptId];
509
+ const relativeUrl = (script && getRelativePath(script.url)) || '<unknown>';
510
+ const frameLocation = `${relativeUrl}:${lineNumber + 1}:${columnNumber}`;
511
+ return `#${idx} ${name} ${frameLocation}`;
512
+ }).join('\n');
513
+ }
514
+ static from(callFrames) {
515
+ return super.from(Array.from(callFrames).map(callFrame => {
516
+ if (callFrame instanceof CallFrame) {
517
+ return callFrame;
518
+ }
519
+ return new CallFrame(callFrame);
520
+ }));
521
+ }
522
+ }
523
+ function prepareControlCode(input) {
524
+ if (input === '\n') {
525
+ return lastCommand;
526
+ }
527
+ // exec process.title => exec("process.title");
528
+ const match = input.match(/^\s*exec\s+([^\n]*)/);
529
+ if (match) {
530
+ lastCommand = `exec(${JSON.stringify(match[1])})`;
531
+ }
532
+ else {
533
+ lastCommand = input;
534
+ }
535
+ return lastCommand;
536
+ }
537
+ // function evalInCurrentContext(code) {
538
+ // // Repl asked for scope variables
539
+ // if (code === '.scope') {
540
+ // if (!selectedFrame) {
541
+ // return Promise.reject(new Error('Requires execution to be paused'));
542
+ // }
543
+ // return selectedFrame.loadScopes().then((scopes) => {
544
+ // return scopes.map((scope) => scope.completionGroup);
545
+ // });
546
+ // }
547
+ //
548
+ // if (selectedFrame) {
549
+ // return Debugger.evaluateOnCallFrame({
550
+ // callFrameId: selectedFrame.callFrameId,
551
+ // expression: code,
552
+ // objectGroup: 'node-inspect',
553
+ // generatePreview: true,
554
+ // }).then(RemoteObject.fromEvalResult);
555
+ // }
556
+ // return Runtime.evaluate({
557
+ // expression: code,
558
+ // objectGroup: 'node-inspect',
559
+ // generatePreview: true,
560
+ // }).then(RemoteObject.fromEvalResult);
561
+ // }
562
+ function controlEval(input, context, filename, callback) {
563
+ debuglog('eval:', input);
564
+ function returnToCallback(error, result) {
565
+ debuglog('end-eval:', input, error);
566
+ callback(error, result);
567
+ }
568
+ try {
569
+ const code = prepareControlCode(input);
570
+ const result = (0, node_vm_1.runInContext)(code, context, filename);
571
+ if (result && typeof result.then === 'function') {
572
+ toCallback(result, returnToCallback);
573
+ return;
574
+ }
575
+ returnToCallback(null, result);
576
+ }
577
+ catch (e) {
578
+ returnToCallback(e);
579
+ }
580
+ }
581
+ // function debugEval(input, context, filename, callback) {
582
+ // debuglog('eval:', input);
583
+ // function returnToCallback(error, result) {
584
+ // debuglog('end-eval:', input, error);
585
+ // callback(error, result);
586
+ // }
587
+ //
588
+ // try {
589
+ // const result = evalInCurrentContext(input);
590
+ //
591
+ // if (result && typeof result.then === 'function') {
592
+ // toCallback(result, returnToCallback);
593
+ // return;
594
+ // }
595
+ // returnToCallback(null, result);
596
+ // } catch (e) {
597
+ // returnToCallback(e);
598
+ // }
599
+ // }
600
+ /*function formatWatchers(verbose = false) {
601
+ if (!watchedExpressions.length) {
602
+ return Promise.resolve('');
603
+ }
604
+
605
+ const inspectValue = (expr) =>
606
+ evalInCurrentContext(expr)
607
+ // .then(formatValue)
608
+ .catch((error) => `<${error.message}>`);
609
+ const lastIndex = watchedExpressions.length - 1;
610
+
611
+ return Promise.all(watchedExpressions.map(inspectValue))
612
+ .then((values) => {
613
+ const lines = watchedExpressions
614
+ .map((expr, idx) => {
615
+ const prefix = `${leftPad(idx, ' ', lastIndex)}: ${expr} =`;
616
+ const value = inspect(values[idx], { colors: true });
617
+ if (value.indexOf('\n') === -1) {
618
+ return `${prefix} ${value}`;
619
+ }
620
+ return `${prefix}\n ${value.split('\n').join('\n ')}`;
621
+ });
622
+ return lines.join('\n');
623
+ })
624
+ .then((valueList) => {
625
+ return verbose ? `Watchers:\n${valueList}\n` : valueList;
626
+ });
627
+ }*/
628
+ //function watchers(verbose = false) {
629
+ // return formatWatchers(verbose).then(print);
630
+ //}
631
+ // List source code
632
+ // function list(delta = 5) {
633
+ // return selectedFrame.list(delta)
634
+ // .then(null, (error) => {
635
+ // print('You can\'t list source code right now');
636
+ // throw error;
637
+ // });
638
+ // }
639
+ //function handleBreakpointResolved({ breakpointId, location }) {
640
+ // const script = knownScripts[location.scriptId];
641
+ // const scriptUrl = script && script.url;
642
+ // if (scriptUrl) {
643
+ // Object.assign(location, { scriptUrl });
644
+ // }
645
+ // const isExisting = knownBreakpoints.some((bp) => {
646
+ // if (bp.breakpointId === breakpointId) {
647
+ // Object.assign(bp, { location });
648
+ // return true;
649
+ // }
650
+ // return false;
651
+ // });
652
+ // if (!isExisting) {
653
+ // knownBreakpoints.push({ breakpointId, location });
654
+ // }
655
+ //}
656
+ // function listBreakpoints() {
657
+ // if (!knownBreakpoints.length) {
658
+ // print('No breakpoints yet');
659
+ // return;
660
+ // }
661
+ //
662
+ // function formatLocation(location) {
663
+ // if (!location) return '<unknown location>';
664
+ // const script = knownScripts[location.scriptId];
665
+ // const scriptUrl = script ? script.url : location.scriptUrl;
666
+ // return `${getRelativePath(scriptUrl)}:${location.lineNumber + 1}`;
667
+ // }
668
+ // const breaklist = knownBreakpoints
669
+ // .map((bp, idx) => `#${idx} ${formatLocation(bp.location)}`)
670
+ // .join('\n');
671
+ // print(breaklist);
672
+ // }
673
+ // function setBreakpoint(script, line, condition, silent) {
674
+ // function registerBreakpoint({ breakpointId, actualLocation }) {
675
+ // handleBreakpointResolved({ breakpointId, location: actualLocation });
676
+ // if (actualLocation && actualLocation.scriptId) {
677
+ // if (!silent) return getSourceSnippet(actualLocation, 5);
678
+ // } else {
679
+ // print(`Warning: script '${script}' was not loaded yet.`);
680
+ // }
681
+ // return undefined;
682
+ // }
683
+ //
684
+ // // setBreakpoint(): set breakpoint at current location
685
+ // if (script === undefined) {
686
+ // return Debugger
687
+ // .setBreakpoint({ location: getCurrentLocation(), condition })
688
+ // .then(registerBreakpoint);
689
+ // }
690
+ //
691
+ // // setBreakpoint(line): set breakpoint in current script at specific line
692
+ // if (line === undefined && typeof script === 'number') {
693
+ // const location = {
694
+ // scriptId: getCurrentLocation().scriptId,
695
+ // lineNumber: script - 1,
696
+ // };
697
+ // return Debugger.setBreakpoint({ location, condition })
698
+ // .then(registerBreakpoint);
699
+ // }
700
+ //
701
+ // if (typeof script !== 'string') {
702
+ // throw new TypeError(`setBreakpoint() expects a string, got ${script}`);
703
+ // }
704
+ //
705
+ // // setBreakpoint('fn()'): Break when a function is called
706
+ // if (script.endsWith('()')) {
707
+ // const debugExpr = `debug(${script.slice(0, -2)})`;
708
+ // const debugCall = selectedFrame
709
+ // ? Debugger.evaluateOnCallFrame({
710
+ // callFrameId: selectedFrame.callFrameId,
711
+ // expression: debugExpr,
712
+ // includeCommandLineAPI: true,
713
+ // })
714
+ // : Runtime.evaluate({
715
+ // expression: debugExpr,
716
+ // includeCommandLineAPI: true,
717
+ // });
718
+ // return debugCall.then(({ result, wasThrown }) => {
719
+ // if (wasThrown) return convertResultToError(result);
720
+ // return undefined; // This breakpoint can't be removed the same way
721
+ // });
722
+ // }
723
+ //
724
+ // // setBreakpoint('scriptname')
725
+ // let scriptId = null;
726
+ // let ambiguous = false;
727
+ // if (knownScripts[script]) {
728
+ // scriptId = script;
729
+ // } else {
730
+ // for (const id of Object.keys(knownScripts)) {
731
+ // const scriptUrl = knownScripts[id].url;
732
+ // if (scriptUrl && scriptUrl.indexOf(script) !== -1) {
733
+ // if (scriptId !== null) {
734
+ // ambiguous = true;
735
+ // }
736
+ // scriptId = id;
737
+ // }
738
+ // }
739
+ // }
740
+ //
741
+ // if (ambiguous) {
742
+ // print('Script name is ambiguous');
743
+ // return undefined;
744
+ // }
745
+ // if (line <= 0) {
746
+ // print('Line should be a positive value');
747
+ // return undefined;
748
+ // }
749
+ //
750
+ // if (scriptId !== null) {
751
+ // const location = { scriptId, lineNumber: line - 1 };
752
+ // return Debugger.setBreakpoint({ location, condition })
753
+ // .then(registerBreakpoint);
754
+ // }
755
+ //
756
+ // const escapedPath = script.replace(/([/\\.?*()^${}|[\]])/g, '\\$1');
757
+ // const urlRegex = `^(.*[\\/\\\\])?${escapedPath}$`;
758
+ //
759
+ // return Debugger
760
+ // .setBreakpointByUrl({ urlRegex, lineNumber: line - 1, condition })
761
+ // .then((bp) => {
762
+ // // TODO: handle bp.locations in case the regex matches existing files
763
+ // if (!bp.location) { // Fake it for now.
764
+ // Object.assign(bp, {
765
+ // actualLocation: {
766
+ // scriptUrl: `.*/${script}$`,
767
+ // lineNumber: line - 1,
768
+ // },
769
+ // });
770
+ // }
771
+ // return registerBreakpoint(bp);
772
+ // });
773
+ // }
774
+ //
775
+ // function clearBreakpoint(url, line) {
776
+ // const breakpoint = knownBreakpoints.find(({ location }) => {
777
+ // if (!location) return false;
778
+ // const script = knownScripts[location.scriptId];
779
+ // if (!script) return false;
780
+ // return (
781
+ // script.url.indexOf(url) !== -1 && (location.lineNumber + 1) === line
782
+ // );
783
+ // });
784
+ // if (!breakpoint) {
785
+ // print(`Could not find breakpoint at ${url}:${line}`);
786
+ // return Promise.resolve();
787
+ // }
788
+ // return Debugger.removeBreakpoint({ breakpointId: breakpoint.breakpointId })
789
+ // .then(() => {
790
+ // const idx = knownBreakpoints.indexOf(breakpoint);
791
+ // knownBreakpoints.splice(idx, 1);
792
+ // });
793
+ // }
794
+ //
795
+ // function restoreBreakpoints() {
796
+ // const lastBreakpoints = knownBreakpoints.slice();
797
+ // knownBreakpoints.length = 0;
798
+ // const newBreakpoints = lastBreakpoints
799
+ // .filter(({ location }) => !!location.scriptUrl)
800
+ // .map(({ location }) =>
801
+ // setBreakpoint(location.scriptUrl, location.lineNumber + 1));
802
+ // if (!newBreakpoints.length) return Promise.resolve();
803
+ // return Promise.all(newBreakpoints).then((results) => {
804
+ // print(`${results.length} breakpoints restored.`);
805
+ // });
806
+ // }
807
+ // function setPauseOnExceptions(state) {
808
+ // return Debugger.setPauseOnExceptions({ state })
809
+ // .then(() => {
810
+ // pauseOnExceptionState = state;
811
+ // });
812
+ // }
813
+ Debugger.on('paused', (data) => {
814
+ const callFrames = data.callFrames;
815
+ const reason = data.reason;
816
+ if (process.env.NODE_INSPECT_RESUME_ON_START === '1' && reason === 'Break on start') {
817
+ debuglog('Paused on start, but NODE_INSPECT_RESUME_ON_START environment variable is set to 1, resuming');
818
+ inspector.client.callMethod('Debugger.resume');
819
+ return;
820
+ }
821
+ // Save execution context's data
822
+ currentBacktrace = Backtrace.from(callFrames);
823
+ selectedFrame = currentBacktrace[0];
824
+ // const { scriptId, lineNumber } = selectedFrame.location;
825
+ // const breakType = reason === 'other' ? 'break' : reason;
826
+ // const script = knownScripts[scriptId];
827
+ // const scriptUrl = script ? getRelativePath(script.url) : '[unknown]';
828
+ // const header = `${breakType} in ${scriptUrl}:${lineNumber + 1}`;
829
+ void inspector.suspendReplWhile(() => {
830
+ const context = selectedFrame?.list(3);
831
+ inspect(context);
832
+ });
833
+ });
834
+ function handleResumed() {
835
+ currentBacktrace = undefined;
836
+ selectedFrame = undefined;
837
+ }
838
+ Debugger.on('resumed', handleResumed);
839
+ //Debugger.on('breakpointResolved', handleBreakpointResolved);
840
+ Debugger.on('scriptParsed', (script) => {
841
+ const { scriptId, url } = script;
842
+ if (url) {
843
+ knownScripts[scriptId] = Object.assign({
844
+ isNative: isNativeUrl(url),
845
+ }, script);
846
+ }
847
+ });
848
+ /*Profiler.on('consoleProfileFinished', ({ profile }) => {
849
+ Profile.createAndRegister({ profile });
850
+ print([
851
+ 'Captured new CPU profile.',
852
+ `Access it with profiles[${profiles.length - 1}]`
853
+ ].join('\n'));
854
+ });*/
855
+ function initializeContext(context) {
856
+ Object.defineProperty(context, 'Debugger', {
857
+ value: inspector.Debugger,
858
+ enumerable: true,
859
+ configurable: true,
860
+ // @ts-expect-error fix later
861
+ writeable: false,
862
+ });
863
+ Object.defineProperty(context, 'HeapProfiler', {
864
+ value: inspector.HeapProfiler,
865
+ enumerable: true,
866
+ configurable: true,
867
+ // @ts-expect-error fix later
868
+ writeable: false,
869
+ });
870
+ Object.defineProperty(context, 'Profiler', {
871
+ value: inspector.Profiler,
872
+ enumerable: true,
873
+ configurable: true,
874
+ // @ts-expect-error fix later
875
+ writeable: false,
876
+ });
877
+ Object.defineProperty(context, 'Runtime', {
878
+ value: inspector.Runtime,
879
+ enumerable: true,
880
+ configurable: true,
881
+ // @ts-expect-error fix later
882
+ writeable: false,
883
+ });
884
+ /*copyOwnProperties(context, {
885
+ get help() {
886
+ print(HELP);
887
+ },
888
+
889
+ get run() {
890
+ return inspector.run();
891
+ },
892
+
893
+ get kill() {
894
+ return inspector.killChild();
895
+ },
896
+
897
+ get restart() {
898
+ return inspector.run();
899
+ },
900
+
901
+ get cont() {
902
+ handleResumed();
903
+ return Debugger.resume();
904
+ },
905
+
906
+ get next() {
907
+ handleResumed();
908
+ return Debugger.stepOver();
909
+ },
910
+
911
+ get step() {
912
+ handleResumed();
913
+ return Debugger.stepInto();
914
+ },
915
+
916
+ get out() {
917
+ handleResumed();
918
+ return Debugger.stepOut();
919
+ },
920
+
921
+ get pause() {
922
+ return Debugger.pause();
923
+ },
924
+
925
+ get backtrace() {
926
+ return currentBacktrace;
927
+ },
928
+
929
+ get breakpoints() {
930
+ return listBreakpoints();
931
+ },
932
+
933
+ exec(expr) {
934
+ return evalInCurrentContext(expr);
935
+ },
936
+
937
+ get profile() {
938
+ return Profiler.start();
939
+ },
940
+
941
+ get profileEnd() {
942
+ return Profiler.stop()
943
+ .then(Profile.createAndRegister);
944
+ },
945
+
946
+ get profiles() {
947
+ return profiles;
948
+ },
949
+
950
+ takeHeapSnapshot(filename = 'node.heapsnapshot') {
951
+ return new Promise((resolve, reject) => {
952
+ const absoluteFile = Path.resolve(filename);
953
+ const writer = FS.createWriteStream(absoluteFile);
954
+ let sizeWritten = 0;
955
+ function onProgress({ done, total, finished }) {
956
+ if (finished) {
957
+ print('Heap snaphost prepared.');
958
+ } else {
959
+ print(`Heap snapshot: ${done}/${total}`, true);
960
+ }
961
+ }
962
+ function onChunk({ chunk }) {
963
+ sizeWritten += chunk.length;
964
+ writer.write(chunk);
965
+ print(`Writing snapshot: ${sizeWritten}`, true);
966
+ }
967
+ function onResolve() {
968
+ writer.end(() => {
969
+ teardown();
970
+ print(`Wrote snapshot: ${absoluteFile}`);
971
+ resolve();
972
+ });
973
+ }
974
+ function onReject(error) {
975
+ teardown();
976
+ reject(error);
977
+ }
978
+ function teardown() {
979
+ HeapProfiler.removeListener(
980
+ 'reportHeapSnapshotProgress', onProgress);
981
+ HeapProfiler.removeListener('addHeapSnapshotChunk', onChunk);
982
+ }
983
+
984
+ HeapProfiler.on('reportHeapSnapshotProgress', onProgress);
985
+ HeapProfiler.on('addHeapSnapshotChunk', onChunk);
986
+
987
+ print('Heap snapshot: 0/0', true);
988
+ HeapProfiler.takeHeapSnapshot({ reportProgress: true })
989
+ .then(onResolve, onReject);
990
+ });
991
+ },
992
+
993
+ get watchers() {
994
+ return watchers();
995
+ },
996
+
997
+ watch(expr) {
998
+ watchedExpressions.push(expr);
999
+ },
1000
+
1001
+ unwatch(expr) {
1002
+ const index = watchedExpressions.indexOf(expr);
1003
+
1004
+ // Unwatch by expression
1005
+ // or
1006
+ // Unwatch by watcher number
1007
+ watchedExpressions.splice(index !== -1 ? index : +expr, 1);
1008
+ },
1009
+
1010
+ get repl() {
1011
+ // Don't display any default messages
1012
+ const listeners = repl.listeners('SIGINT').slice(0);
1013
+ repl.removeAllListeners('SIGINT');
1014
+
1015
+ const oldContext = repl.context;
1016
+
1017
+ exitDebugRepl = () => {
1018
+ // Restore all listeners
1019
+ process.nextTick(() => {
1020
+ listeners.forEach((listener) => {
1021
+ repl.on('SIGINT', listener);
1022
+ });
1023
+ });
1024
+
1025
+ // Exit debug repl
1026
+ repl.eval = controlEval;
1027
+
1028
+ // Swap history
1029
+ history.debug = repl.history;
1030
+ repl.history = history.control;
1031
+
1032
+ repl.context = oldContext;
1033
+ repl.setPrompt('debug> ');
1034
+ repl.displayPrompt();
1035
+
1036
+ repl.removeListener('SIGINT', exitDebugRepl);
1037
+ repl.removeListener('exit', exitDebugRepl);
1038
+
1039
+ exitDebugRepl = null;
1040
+ };
1041
+
1042
+ // Exit debug repl on SIGINT
1043
+ repl.on('SIGINT', exitDebugRepl);
1044
+
1045
+ // Exit debug repl on repl exit
1046
+ repl.on('exit', exitDebugRepl);
1047
+
1048
+ // Set new
1049
+ repl.eval = debugEval;
1050
+ repl.context = {};
1051
+
1052
+ // Swap history
1053
+ history.control = repl.history;
1054
+ repl.history = history.debug;
1055
+
1056
+ repl.setPrompt('> ');
1057
+
1058
+ print('Press Ctrl + C to leave debug repl');
1059
+ repl.displayPrompt();
1060
+ },
1061
+
1062
+ get version() {
1063
+ return Runtime.evaluate({
1064
+ expression: 'process.versions.v8',
1065
+ contextId: 1,
1066
+ returnByValue: true,
1067
+ }).then(({ result }) => {
1068
+ print(result.value);
1069
+ });
1070
+ },
1071
+
1072
+ scripts: listScripts,
1073
+
1074
+ //setBreakpoint,
1075
+ //clearBreakpoint,
1076
+ setPauseOnExceptions,
1077
+ get breakOnException() {
1078
+ return setPauseOnExceptions('all');
1079
+ },
1080
+ get breakOnUncaught() {
1081
+ return setPauseOnExceptions('uncaught');
1082
+ },
1083
+ get breakOnNone() {
1084
+ return setPauseOnExceptions('none');
1085
+ },
1086
+
1087
+ list,
1088
+ });*/
1089
+ //aliasProperties(context, SHORTCUTS);
1090
+ }
1091
+ function initAfterStart() {
1092
+ const setupTasks = [
1093
+ Runtime.enable(),
1094
+ //Profiler.enable(),
1095
+ //Profiler.setSamplingInterval({ interval: 100 }),
1096
+ Debugger.enable(),
1097
+ Debugger.setPauseOnExceptions({ state: 'none' }),
1098
+ Debugger.setAsyncCallStackDepth({ maxDepth: 1 }),
1099
+ Debugger.setBlackboxPatterns({ patterns: [] }),
1100
+ // Debugger.setPauseOnExceptions({ state: 'all' }),
1101
+ //restoreBreakpoints(),
1102
+ Runtime.runIfWaitingForDebugger(),
1103
+ ];
1104
+ return Promise.all(setupTasks);
1105
+ }
1106
+ return function startRepl() {
1107
+ inspector.client.on('close', () => resetOnStart());
1108
+ inspector.client.on('ready', () => {
1109
+ initAfterStart().catch(err => {
1110
+ print(`Error starting inspector: ${err.message}`);
1111
+ });
1112
+ });
1113
+ const replOptions = {
1114
+ prompt: 'debug> ',
1115
+ input: inspector.stdin,
1116
+ output: inspector.stdout,
1117
+ eval: controlEval,
1118
+ useGlobal: false,
1119
+ ignoreUndefined: true,
1120
+ };
1121
+ repl = (0, node_repl_1.start)(replOptions);
1122
+ initializeContext(repl.context);
1123
+ repl.on('reset', initializeContext);
1124
+ repl.defineCommand('interrupt', () => {
1125
+ // We want this for testing purposes where sending CTRL-C can be tricky.
1126
+ repl.emit('SIGINT');
1127
+ });
1128
+ // Init once for the initial connection
1129
+ initAfterStart().catch(err => {
1130
+ print(`Error starting inspector: ${err.message}`);
1131
+ });
1132
+ return repl;
1133
+ };
1134
+ }
1135
+ //# sourceMappingURL=debugger.js.map