@coderich/sandman 0.0.17 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coderich/sandman",
3
- "version": "0.0.17",
3
+ "version": "0.1.0",
4
4
  "main": "index.js",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,12 +15,12 @@
15
15
  "dev": "coderich-dev"
16
16
  },
17
17
  "dependencies": {
18
- "@coderich/config": "2.2.7",
19
- "@coderich/util": "2.1.5",
18
+ "@coderich/config": "2.3.0",
19
+ "@coderich/util": "2.2.3",
20
20
  "chokidar": "4.0.3"
21
21
  },
22
22
  "devDependencies": {
23
- "@coderich/dev": "0.6.1"
23
+ "@coderich/dev": "0.6.4"
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
@@ -70,7 +70,7 @@ exports.toCURL = function toCURL(request, { pretty = true, redactAuth = false }
70
70
 
71
71
  if (Array.isArray(hdrs)) {
72
72
  for (const item of hdrs) {
73
- if (!item) continue;
73
+ if (!item) continue; // eslint-disable-line no-continue
74
74
  if (Array.isArray(item) && item.length >= 2) push(item[0], item[1]);
75
75
  else if (typeof item === 'object') {
76
76
  for (const [k, v] of Object.entries(item)) push(k, v);
@@ -1,5 +1,5 @@
1
- const FS = require('fs');
2
- const Path = require('path');
1
+ const FS = require('node:fs');
2
+ const Path = require('node:path');
3
3
  const Chokidar = require('chokidar');
4
4
  const Config = require('@coderich/config');
5
5
  const Util = require('@coderich/util');
@@ -1,4 +1,4 @@
1
- const Readline = require('readline');
1
+ const Readline = require('node:readline');
2
2
  const Util = require('@coderich/util');
3
3
  const UtilService = require('./UtilService');
4
4
 
package/src/Sandman.js CHANGED
@@ -1,6 +1,6 @@
1
- const Path = require('path');
2
- const EventEmitter = require('events');
3
- const { spawn } = require('child_process');
1
+ const Path = require('node:path');
2
+ const EventEmitter = require('node:events');
3
+ const { spawn } = require('node:child_process');
4
4
  const ReadlineService = require('./ReadlineService');
5
5
  const UtilService = require('./UtilService');
6
6
  const CURLService = require('./CURLService');
@@ -21,15 +21,21 @@ module.exports = class Sandman extends EventEmitter {
21
21
  this.#readline = ReadlineService.createInterface(this.#cli, this.#configClient);
22
22
  this.#configClient.watch(this.#configDir, event => this.emit('save', event));
23
23
 
24
- this.#readline.on('line', async (line) => {
24
+ this.#readline.on('line', (line) => {
25
25
  if (!line) return this.prompt();
26
26
  const [cmd, key, ...args] = UtilService.parseArgs(line.trim());
27
27
  const $cmd = Object.keys(this.#cli).includes(cmd) ? cmd : cmdNotFound;
28
- const value = await Promise.resolve(this.#cli[$cmd](key, ...args)).catch(e => e);
29
- return this.emit($cmd, value);
28
+ return this.#cli[$cmd](key, ...args)
29
+ .then(value => this.emit($cmd, value))
30
+ .catch(error => this.emit('error', { key: $cmd, error }));
30
31
  });
31
32
  }
32
33
 
34
+ emit(event, ...args) {
35
+ if (event === 'error' && !this.listenerCount('error')) return false;
36
+ return super.emit(event, ...args);
37
+ }
38
+
33
39
  cli() {
34
40
  return this.#cli;
35
41
  }
@@ -86,10 +92,13 @@ module.exports = class Sandman extends EventEmitter {
86
92
 
87
93
  if (typeof value === 'function') {
88
94
  return (...args) => {
95
+ const result = new Promise((resolve) => { resolve(value.apply(this, args)); });
96
+
97
+ if (self.#cliCounter > 0) return result;
98
+
89
99
  self.#cliCounter++;
90
100
  self.#readline.pause();
91
- const result = value.apply(this, args);
92
- Promise.resolve(result).catch(() => null).finally(() => setImmediate(() => {
101
+ result.catch(() => null).finally(() => setImmediate(() => {
93
102
  if (--self.#cliCounter === 0) self.prompt();
94
103
  }));
95
104
  return result;
@@ -3,6 +3,7 @@ exports.parseArgs = (line) => {
3
3
  const args = [];
4
4
  let match;
5
5
 
6
+ // eslint-disable-next-line no-cond-assign
6
7
  while ((match = regex.exec(line)) !== null) {
7
8
  if (match[1] !== undefined) {
8
9
  args.push(match[1]); // double-quoted