@deot/dev-shared 1.0.0 → 1.0.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/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export declare interface AnyFunction<T = void> {
8
8
 
9
9
  declare const autoCatch: (impl: any, options?: Options) => Promise<any>;
10
10
 
11
+ declare const command: (command$: string, args?: string[]) => RegExpMatchArray | [];
12
+
11
13
  export declare type Customized<Origin = any, Extend = any> = Origin & Extend;
12
14
 
13
15
  declare const error: {
@@ -15,7 +17,10 @@ declare const error: {
15
17
  (message?: any, ...optionalParams: any[]): void;
16
18
  };
17
19
 
18
- declare const exec: typeof childProcess.exec.__promisify__;
20
+ declare const exec: (command$: string, args?: string[]) => childProcess.PromiseWithChild<{
21
+ stdout: string;
22
+ stderr: string;
23
+ }>;
19
24
 
20
25
  declare const formatBytes: (size: number, suffix?: number) => string;
21
26
 
@@ -55,13 +60,14 @@ export declare type Options<T = {}> = Indexable & T;
55
60
  declare namespace Shell {
56
61
  export {
57
62
  LOCAL_COMMAND_MAP,
63
+ command,
58
64
  exec,
59
65
  spawn
60
66
  }
61
67
  }
62
68
  export { Shell }
63
69
 
64
- declare const spawn: (command: string, args?: string[]) => Promise<unknown>;
70
+ declare const spawn: (command$: string, args?: string[], options?: any) => Promise<unknown>;
65
71
 
66
72
  export declare type TimeoutHandle = ReturnType<typeof global.setTimeout>;
67
73
 
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import os from 'node:os';
2
- import path from 'node:path';
2
+ import * as path from 'node:path';
3
3
  import * as childProcess from 'node:child_process';
4
- import util from 'node:util';
5
- import fs from 'node:fs';
4
+ import * as util from 'node:util';
5
+ import * as fs from 'node:fs';
6
6
 
7
7
  const getHost = () => {
8
8
  const ips = [];
@@ -71,16 +71,21 @@ const LOCAL_COMMAND_MAP = fs.existsSync(binDirectory)
71
71
  return pre;
72
72
  }, {})
73
73
  : {};
74
- const exec = util.promisify(childProcess.exec);
75
- const spawn = (command, args = []) => {
76
- const [command$, ...args$] = (command + SPACE + args.join(SPACE))
77
- .replace(/\s+/g, SPACE)
78
- .split(SPACE)
79
- .filter(i => !!i)
80
- .map(i => LOCAL_COMMAND_MAP[i] || i);
74
+ const command = (command$, args) => {
75
+ const v = (command$ + SPACE + (args || []).join(SPACE))
76
+ .match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
77
+ return v || [];
78
+ };
79
+ const exec = (command$, args) => {
80
+ return util.promisify(childProcess.exec)(command(command$, args).join(SPACE));
81
+ };
82
+ const spawn = (command$, args, options) => {
83
+ let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
84
+ args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ''));
81
85
  return new Promise((resolve, reject) => {
82
- const emit = childProcess.spawn(command$, args$, {
83
- stdio: 'inherit'
86
+ const emit = childProcess.spawn(command$$, args$, {
87
+ stdio: 'inherit',
88
+ ...options
84
89
  });
85
90
  emit.on('close', (code) => {
86
91
  if (code === 0) {
@@ -100,6 +105,7 @@ const spawn = (command, args = []) => {
100
105
  var shell = /*#__PURE__*/Object.freeze({
101
106
  __proto__: null,
102
107
  LOCAL_COMMAND_MAP: LOCAL_COMMAND_MAP,
108
+ command: command,
103
109
  exec: exec,
104
110
  spawn: spawn
105
111
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-shared",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -10,6 +10,5 @@
10
10
  "license": "MIT",
11
11
  "publishConfig": {
12
12
  "access": "public"
13
- },
14
- "gitHead": "f960c31945e60a492e50e835cbf0c987a9fc3d5c"
15
- }
13
+ }
14
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 deot
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.