@deot/dev-shared 2.3.0 → 2.5.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.
@@ -5,7 +5,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  const os = require('node:os');
6
6
  const path = require('node:path');
7
7
  const childProcess = require('node:child_process');
8
- const util = require('node:util');
9
8
  const fs = require('node:fs');
10
9
  const node_module = require('node:module');
11
10
 
@@ -28,7 +27,6 @@ function _interopNamespaceDefault(e) {
28
27
 
29
28
  const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
30
29
  const childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
31
- const util__namespace = /*#__PURE__*/_interopNamespaceDefault(util);
32
30
  const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
33
31
 
34
32
  const getHost = () => {
@@ -85,6 +83,14 @@ const logger = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
85
83
 
86
84
  const SPACE = " ";
87
85
  const binDirectory = path__namespace.resolve(process.cwd(), "./node_modules/.bin");
86
+ const toPromise = (target, promise) => {
87
+ let instance = target;
88
+ instance.then = (resolve, reject) => promise.then(resolve, reject);
89
+ instance.catch = (callback) => promise.catch(callback);
90
+ instance.finally = (callback) => promise.finally(callback);
91
+ return instance;
92
+ };
93
+ /* istanbul ignore next -- @preserve */
88
94
  const LOCAL_COMMAND_MAP = fs__namespace.existsSync(binDirectory) ? fs__namespace.readdirSync(binDirectory).reduce((pre, file) => {
89
95
  const fullpath = path__namespace.resolve(binDirectory, file);
90
96
  const stat = fs__namespace.statSync(fullpath);
@@ -97,33 +103,68 @@ const command = (command$, args) => {
97
103
  const v = (command$ + SPACE + (args || []).join(SPACE)).match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
98
104
  return v || [];
99
105
  };
100
- const exec = (command$, args) => {
101
- return util__namespace.promisify(childProcess__namespace.exec)(command(command$, args).join(SPACE));
106
+ const exec = (command$, args, options) => {
107
+ let command$$ = command(command$, args).join(SPACE);
108
+ let reject;
109
+ let resolve;
110
+ const promise = new Promise((resolve$, reject$) => {
111
+ reject = reject$;
112
+ resolve = resolve$;
113
+ });
114
+ const subprocess = childProcess__namespace.exec(command$$, options, (error, stdout, stderr) => {
115
+ process.off("beforeExit", handler);
116
+ if (error) {
117
+ reject(error);
118
+ return;
119
+ }
120
+ resolve({
121
+ stderr: stderr.toString(),
122
+ stdout: stdout.toString()
123
+ });
124
+ });
125
+ const handler = (
126
+ /* istanbul ignore next */
127
+ () => {
128
+ !subprocess.killed && subprocess.kill("SIGHUP");
129
+ }
130
+ );
131
+ process.on("beforeExit", handler);
132
+ return toPromise(subprocess, promise);
102
133
  };
103
134
  const spawn = (command$, args, options) => {
104
135
  let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
105
136
  args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ""));
106
- return new Promise((resolve, reject) => {
107
- const emit = childProcess__namespace.spawn(
108
- command$$,
109
- args$,
110
- {
111
- stdio: "inherit",
112
- ...options
113
- }
114
- );
115
- emit.on("close", (code) => {
137
+ const subprocess = childProcess__namespace.spawn(
138
+ command$$,
139
+ args$,
140
+ {
141
+ stdio: "inherit",
142
+ ...options
143
+ }
144
+ );
145
+ const promise = new Promise((resolve, reject) => {
146
+ subprocess.on("close", (code) => {
147
+ process.off("beforeExit", handler);
116
148
  if (code === 0) {
117
149
  resolve(code);
118
150
  } else {
119
151
  reject(code);
120
152
  }
121
153
  });
122
- emit.on("error", (error) => {
154
+ subprocess.on("error", (error) => {
155
+ process.off("beforeExit", handler);
123
156
  !process.exitCode && (process.exitCode = 1);
124
157
  reject(error);
125
158
  });
126
159
  });
160
+ const handler = (
161
+ /* istanbul ignore next */
162
+ () => {
163
+ !subprocess.killed && subprocess.kill("SIGHUP");
164
+ }
165
+ );
166
+ process.on("beforeExit", handler);
167
+ return toPromise(subprocess, promise);
127
168
  };
128
169
 
129
170
  const shell = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
@@ -161,6 +202,7 @@ const getNormalizePackage = (dataMap) => {
161
202
  const result = [];
162
203
  while (queue.length > 0) {
163
204
  const node = queue.shift();
205
+ /* istanbul ignore next -- @preserve */
164
206
  if (!node)
165
207
  return [];
166
208
  result.push(node);
@@ -185,6 +227,7 @@ const getPackageName = (packageFolderName$) => {
185
227
  };
186
228
  const getPackageFolderName = (packageName$) => {
187
229
  const { workspace, packageFolderName, packageName } = impl();
230
+ /* istanbul ignore next -- @preserve */
188
231
  if (!workspace)
189
232
  return "";
190
233
  if (packageName$ === packageName)
@@ -230,6 +273,18 @@ const impl = (cwd) => {
230
273
  pre[packagesOptions.name] = Object.keys(deps).filter((i) => new RegExp(`${packageName}`).test(i));
231
274
  return pre;
232
275
  }, {});
276
+ const subpackagesMap = packageFolderNames.reduce((pre, packageFolderName$) => {
277
+ let dir = path__namespace.resolve(packageDir, packageFolderName$);
278
+ pre[packageFolderName$] = workspace && fs__namespace.existsSync(`${dir}/index.ts`) && !fs__namespace.existsSync(`${dir}/src`) ? fs__namespace.readdirSync(dir).filter((file) => {
279
+ const fullpath = path__namespace.join(dir, file);
280
+ const stat = fs__namespace.statSync(fullpath);
281
+ if (stat.isDirectory()) {
282
+ return fs__namespace.existsSync(`${fullpath}/__tests__`);
283
+ }
284
+ return false;
285
+ }) : [];
286
+ return pre;
287
+ }, {});
233
288
  const normalizePackageNames = getNormalizePackage(packageRelation);
234
289
  const normalizePackageFolderNames = normalizePackageNames.map((i) => i.replace(new RegExp(`${packageName}-?`), "") || packageFolderName);
235
290
  const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || "";
@@ -248,7 +303,8 @@ const impl = (cwd) => {
248
303
  packageDirsMap,
249
304
  packageRelation,
250
305
  normalizePackageNames,
251
- normalizePackageFolderNames
306
+ normalizePackageFolderNames,
307
+ subpackagesMap
252
308
  };
253
309
  configMap[cwd] = config;
254
310
  return config;
package/dist/index.d.ts CHANGED
@@ -17,10 +17,10 @@ declare const error: {
17
17
  (message?: any, ...optionalParams: any[]): void;
18
18
  };
19
19
 
20
- declare const exec: (command$: string, args?: string[]) => childProcess.PromiseWithChild<{
21
- stdout: string;
20
+ declare const exec: (command$: string, args?: string[], options?: any) => childProcess.ChildProcess & IPromise<{
22
21
  stderr: string;
23
- }>;
22
+ stdout: string;
23
+ }, any>;
24
24
 
25
25
  declare const formatBytes: (size: number, suffix?: number) => string;
26
26
 
@@ -50,6 +50,7 @@ declare const impl: (cwd?: string) => {
50
50
  packageRelation: {};
51
51
  normalizePackageNames: string[];
52
52
  normalizePackageFolderNames: string[];
53
+ subpackagesMap: {};
53
54
  };
54
55
 
55
56
  export declare type Indexable<T = any> = {
@@ -61,6 +62,12 @@ declare const info: {
61
62
  (message?: any, ...optionalParams: any[]): void;
62
63
  };
63
64
 
65
+ declare interface IPromise<T = any, K = any> {
66
+ then: (resolve: (a: T) => void, reject: (b: K) => void) => Promise<any>;
67
+ catch: (callback?: (b: K) => void) => Promise<any>;
68
+ finally: (callback?: () => void) => Promise<any>;
69
+ }
70
+
64
71
  declare const LOCAL_COMMAND_MAP: any;
65
72
 
66
73
  declare namespace Locals {
@@ -101,7 +108,7 @@ declare namespace Shell {
101
108
  }
102
109
  export { Shell }
103
110
 
104
- declare const spawn: (command$: string, args?: string[], options?: any) => Promise<unknown>;
111
+ declare const spawn: (command$: string, args?: string[], options?: any) => childProcess.ChildProcessWithoutNullStreams & IPromise<unknown, any>;
105
112
 
106
113
  export declare type TimeoutHandle = ReturnType<typeof global.setTimeout>;
107
114
 
package/dist/index.es.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import os from 'node:os';
2
2
  import * as path from 'node:path';
3
3
  import * as childProcess from 'node:child_process';
4
- import * as util from 'node:util';
5
4
  import * as fs from 'node:fs';
6
5
  import { createRequire } from 'node:module';
7
6
 
@@ -59,6 +58,14 @@ const logger = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
59
58
 
60
59
  const SPACE = " ";
61
60
  const binDirectory = path.resolve(process.cwd(), "./node_modules/.bin");
61
+ const toPromise = (target, promise) => {
62
+ let instance = target;
63
+ instance.then = (resolve, reject) => promise.then(resolve, reject);
64
+ instance.catch = (callback) => promise.catch(callback);
65
+ instance.finally = (callback) => promise.finally(callback);
66
+ return instance;
67
+ };
68
+ /* istanbul ignore next -- @preserve */
62
69
  const LOCAL_COMMAND_MAP = fs.existsSync(binDirectory) ? fs.readdirSync(binDirectory).reduce((pre, file) => {
63
70
  const fullpath = path.resolve(binDirectory, file);
64
71
  const stat = fs.statSync(fullpath);
@@ -71,33 +78,68 @@ const command = (command$, args) => {
71
78
  const v = (command$ + SPACE + (args || []).join(SPACE)).match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
72
79
  return v || [];
73
80
  };
74
- const exec = (command$, args) => {
75
- return util.promisify(childProcess.exec)(command(command$, args).join(SPACE));
81
+ const exec = (command$, args, options) => {
82
+ let command$$ = command(command$, args).join(SPACE);
83
+ let reject;
84
+ let resolve;
85
+ const promise = new Promise((resolve$, reject$) => {
86
+ reject = reject$;
87
+ resolve = resolve$;
88
+ });
89
+ const subprocess = childProcess.exec(command$$, options, (error, stdout, stderr) => {
90
+ process.off("beforeExit", handler);
91
+ if (error) {
92
+ reject(error);
93
+ return;
94
+ }
95
+ resolve({
96
+ stderr: stderr.toString(),
97
+ stdout: stdout.toString()
98
+ });
99
+ });
100
+ const handler = (
101
+ /* istanbul ignore next */
102
+ () => {
103
+ !subprocess.killed && subprocess.kill("SIGHUP");
104
+ }
105
+ );
106
+ process.on("beforeExit", handler);
107
+ return toPromise(subprocess, promise);
76
108
  };
77
109
  const spawn = (command$, args, options) => {
78
110
  let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
79
111
  args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ""));
80
- return new Promise((resolve, reject) => {
81
- const emit = childProcess.spawn(
82
- command$$,
83
- args$,
84
- {
85
- stdio: "inherit",
86
- ...options
87
- }
88
- );
89
- emit.on("close", (code) => {
112
+ const subprocess = childProcess.spawn(
113
+ command$$,
114
+ args$,
115
+ {
116
+ stdio: "inherit",
117
+ ...options
118
+ }
119
+ );
120
+ const promise = new Promise((resolve, reject) => {
121
+ subprocess.on("close", (code) => {
122
+ process.off("beforeExit", handler);
90
123
  if (code === 0) {
91
124
  resolve(code);
92
125
  } else {
93
126
  reject(code);
94
127
  }
95
128
  });
96
- emit.on("error", (error) => {
129
+ subprocess.on("error", (error) => {
130
+ process.off("beforeExit", handler);
97
131
  !process.exitCode && (process.exitCode = 1);
98
132
  reject(error);
99
133
  });
100
134
  });
135
+ const handler = (
136
+ /* istanbul ignore next */
137
+ () => {
138
+ !subprocess.killed && subprocess.kill("SIGHUP");
139
+ }
140
+ );
141
+ process.on("beforeExit", handler);
142
+ return toPromise(subprocess, promise);
101
143
  };
102
144
 
103
145
  const shell = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
@@ -135,6 +177,7 @@ const getNormalizePackage = (dataMap) => {
135
177
  const result = [];
136
178
  while (queue.length > 0) {
137
179
  const node = queue.shift();
180
+ /* istanbul ignore next -- @preserve */
138
181
  if (!node)
139
182
  return [];
140
183
  result.push(node);
@@ -159,6 +202,7 @@ const getPackageName = (packageFolderName$) => {
159
202
  };
160
203
  const getPackageFolderName = (packageName$) => {
161
204
  const { workspace, packageFolderName, packageName } = impl();
205
+ /* istanbul ignore next -- @preserve */
162
206
  if (!workspace)
163
207
  return "";
164
208
  if (packageName$ === packageName)
@@ -204,6 +248,18 @@ const impl = (cwd) => {
204
248
  pre[packagesOptions.name] = Object.keys(deps).filter((i) => new RegExp(`${packageName}`).test(i));
205
249
  return pre;
206
250
  }, {});
251
+ const subpackagesMap = packageFolderNames.reduce((pre, packageFolderName$) => {
252
+ let dir = path.resolve(packageDir, packageFolderName$);
253
+ pre[packageFolderName$] = workspace && fs.existsSync(`${dir}/index.ts`) && !fs.existsSync(`${dir}/src`) ? fs.readdirSync(dir).filter((file) => {
254
+ const fullpath = path.join(dir, file);
255
+ const stat = fs.statSync(fullpath);
256
+ if (stat.isDirectory()) {
257
+ return fs.existsSync(`${fullpath}/__tests__`);
258
+ }
259
+ return false;
260
+ }) : [];
261
+ return pre;
262
+ }, {});
207
263
  const normalizePackageNames = getNormalizePackage(packageRelation);
208
264
  const normalizePackageFolderNames = normalizePackageNames.map((i) => i.replace(new RegExp(`${packageName}-?`), "") || packageFolderName);
209
265
  const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || "";
@@ -222,7 +278,8 @@ const impl = (cwd) => {
222
278
  packageDirsMap,
223
279
  packageRelation,
224
280
  normalizePackageNames,
225
- normalizePackageFolderNames
281
+ normalizePackageFolderNames,
282
+ subpackagesMap
226
283
  };
227
284
  configMap[cwd] = config;
228
285
  return config;
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@deot/dev-shared",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
+ "type": "module",
4
5
  "main": "dist/index.es.js",
5
6
  "types": "dist/index.d.ts",
6
- "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.es.js",
10
+ "require": "./dist/index.cjs",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
7
14
  "files": [
8
15
  "dist"
9
16
  ],