@inquirer/core 3.1.1 → 3.1.2

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.
package/dist/cjs/index.js CHANGED
@@ -56,12 +56,6 @@ function resetHookState() {
56
56
  handleChange = () => { };
57
57
  sessionRl = undefined;
58
58
  }
59
- function cleanupHook(index) {
60
- const cleanFn = hooksCleanup[index];
61
- if (typeof cleanFn === 'function') {
62
- cleanFn();
63
- }
64
- }
65
59
  function mergeStateUpdates(fn) {
66
60
  const wrapped = (...args) => {
67
61
  let shouldUpdate = false;
@@ -78,6 +72,17 @@ function mergeStateUpdates(fn) {
78
72
  };
79
73
  return wrapped;
80
74
  }
75
+ function cleanupHook(index) {
76
+ const cleanFn = hooksCleanup[index];
77
+ if (typeof cleanFn === 'function') {
78
+ cleanFn();
79
+ }
80
+ }
81
+ const runEffects = mergeStateUpdates(() => {
82
+ for (const effect of hooksEffect) {
83
+ effect();
84
+ }
85
+ });
81
86
  function useState(defaultValue) {
82
87
  const _idx = index;
83
88
  index++;
@@ -115,14 +120,14 @@ function useEffect(cb, depArray) {
115
120
  hasChanged = depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
116
121
  }
117
122
  if (hasChanged) {
118
- hooksEffect.push(mergeStateUpdates(() => {
123
+ hooksEffect.push(() => {
119
124
  cleanupHook(_idx);
120
125
  const cleanFn = cb(rl);
121
126
  if (cleanFn != null && typeof cleanFn !== 'function') {
122
127
  throw new Error('useEffect return value must be a cleanup function or nothing.');
123
128
  }
124
129
  hooksCleanup[_idx] = cleanFn;
125
- }));
130
+ });
126
131
  }
127
132
  hooks[_idx] = depArray;
128
133
  }
@@ -247,11 +252,9 @@ function createPrompt(view) {
247
252
  handleChange = () => workLoop(resolvedConfig);
248
253
  try {
249
254
  const nextView = view(resolvedConfig, done);
250
- for (const effect of hooksEffect) {
251
- effect();
252
- }
253
255
  const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
254
256
  screen.render(content, bottomContent);
257
+ runEffects();
255
258
  }
256
259
  catch (err) {
257
260
  onExit();
@@ -23,12 +23,6 @@ function resetHookState() {
23
23
  handleChange = () => { };
24
24
  sessionRl = undefined;
25
25
  }
26
- function cleanupHook(index) {
27
- const cleanFn = hooksCleanup[index];
28
- if (typeof cleanFn === 'function') {
29
- cleanFn();
30
- }
31
- }
32
26
  function mergeStateUpdates(fn) {
33
27
  const wrapped = (...args) => {
34
28
  let shouldUpdate = false;
@@ -45,6 +39,17 @@ function mergeStateUpdates(fn) {
45
39
  };
46
40
  return wrapped;
47
41
  }
42
+ function cleanupHook(index) {
43
+ const cleanFn = hooksCleanup[index];
44
+ if (typeof cleanFn === 'function') {
45
+ cleanFn();
46
+ }
47
+ }
48
+ const runEffects = mergeStateUpdates(() => {
49
+ for (const effect of hooksEffect) {
50
+ effect();
51
+ }
52
+ });
48
53
  export function useState(defaultValue) {
49
54
  const _idx = index;
50
55
  index++;
@@ -81,14 +86,14 @@ export function useEffect(cb, depArray) {
81
86
  hasChanged = depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
82
87
  }
83
88
  if (hasChanged) {
84
- hooksEffect.push(mergeStateUpdates(() => {
89
+ hooksEffect.push(() => {
85
90
  cleanupHook(_idx);
86
91
  const cleanFn = cb(rl);
87
92
  if (cleanFn != null && typeof cleanFn !== 'function') {
88
93
  throw new Error('useEffect return value must be a cleanup function or nothing.');
89
94
  }
90
95
  hooksCleanup[_idx] = cleanFn;
91
- }));
96
+ });
92
97
  }
93
98
  hooks[_idx] = depArray;
94
99
  }
@@ -208,11 +213,9 @@ export function createPrompt(view) {
208
213
  handleChange = () => workLoop(resolvedConfig);
209
214
  try {
210
215
  const nextView = view(resolvedConfig, done);
211
- for (const effect of hooksEffect) {
212
- effect();
213
- }
214
216
  const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
215
217
  screen.render(content, bottomContent);
218
+ runEffects();
216
219
  }
217
220
  catch (err) {
218
221
  onExit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "engines": {
5
5
  "node": ">=14.18.0"
6
6
  },
@@ -57,7 +57,7 @@
57
57
  "license": "MIT",
58
58
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/README.md",
59
59
  "dependencies": {
60
- "@inquirer/type": "^1.1.1",
60
+ "@inquirer/type": "^1.1.2",
61
61
  "@types/mute-stream": "^0.0.1",
62
62
  "@types/node": "^20.4.8",
63
63
  "@types/wrap-ansi": "^3.0.0",
@@ -72,14 +72,13 @@
72
72
  "wrap-ansi": "^6.2.0"
73
73
  },
74
74
  "devDependencies": {
75
- "@inquirer/testing": "^2.1.2"
75
+ "@inquirer/testing": "^2.1.3"
76
76
  },
77
77
  "scripts": {
78
78
  "tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
79
79
  "clean": "rm -rf dist",
80
80
  "tsc:esm": "tsc -p ./tsconfig.json",
81
- "tsc:cjs": "tsc -p ./tsconfig.cjs.json && yarn run fix-ext",
82
- "fix-ext": "node --no-warnings=ExperimentalWarning --loader=ts-node/esm ../../tools/fix-ext.mts"
81
+ "tsc:cjs": "tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs"
83
82
  },
84
83
  "publishConfig": {
85
84
  "access": "public"
@@ -96,5 +95,5 @@
96
95
  }
97
96
  }
98
97
  },
99
- "gitHead": "dd31d57ed3b1d0771e24cc34bc72e5bedb63a1d7"
98
+ "gitHead": "2b29f261c4c7d85a00c1a2305d97ee10e3c15b68"
100
99
  }