@deot/dev-shared 2.4.0 → 2.6.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/dist/index.cjs CHANGED
@@ -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,13 @@ 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
+ };
88
93
  /* istanbul ignore next -- @preserve */
89
94
  const LOCAL_COMMAND_MAP = fs__namespace.existsSync(binDirectory) ? fs__namespace.readdirSync(binDirectory).reduce((pre, file) => {
90
95
  const fullpath = path__namespace.resolve(binDirectory, file);
@@ -98,33 +103,68 @@ const command = (command$, args) => {
98
103
  const v = (command$ + SPACE + (args || []).join(SPACE)).match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
99
104
  return v || [];
100
105
  };
101
- const exec = (command$, args) => {
102
- 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);
103
133
  };
104
134
  const spawn = (command$, args, options) => {
105
135
  let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
106
136
  args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ""));
107
- return new Promise((resolve, reject) => {
108
- const emit = childProcess__namespace.spawn(
109
- command$$,
110
- args$,
111
- {
112
- stdio: "inherit",
113
- ...options
114
- }
115
- );
116
- 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);
117
148
  if (code === 0) {
118
149
  resolve(code);
119
150
  } else {
120
151
  reject(code);
121
152
  }
122
153
  });
123
- emit.on("error", (error) => {
154
+ subprocess.on("error", (error) => {
155
+ process.off("beforeExit", handler);
124
156
  !process.exitCode && (process.exitCode = 1);
125
157
  reject(error);
126
158
  });
127
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);
128
168
  };
129
169
 
130
170
  const shell = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
@@ -233,6 +273,18 @@ const impl = (cwd) => {
233
273
  pre[packagesOptions.name] = Object.keys(deps).filter((i) => new RegExp(`${packageName}`).test(i));
234
274
  return pre;
235
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
+ }, {});
236
288
  const normalizePackageNames = getNormalizePackage(packageRelation);
237
289
  const normalizePackageFolderNames = normalizePackageNames.map((i) => i.replace(new RegExp(`${packageName}-?`), "") || packageFolderName);
238
290
  const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || "";
@@ -251,7 +303,8 @@ const impl = (cwd) => {
251
303
  packageDirsMap,
252
304
  packageRelation,
253
305
  normalizePackageNames,
254
- normalizePackageFolderNames
306
+ normalizePackageFolderNames,
307
+ subpackagesMap
255
308
  };
256
309
  configMap[cwd] = config;
257
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
 
@@ -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,13 @@ 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
+ };
62
68
  /* istanbul ignore next -- @preserve */
63
69
  const LOCAL_COMMAND_MAP = fs.existsSync(binDirectory) ? fs.readdirSync(binDirectory).reduce((pre, file) => {
64
70
  const fullpath = path.resolve(binDirectory, file);
@@ -72,33 +78,68 @@ const command = (command$, args) => {
72
78
  const v = (command$ + SPACE + (args || []).join(SPACE)).match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
73
79
  return v || [];
74
80
  };
75
- const exec = (command$, args) => {
76
- 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);
77
108
  };
78
109
  const spawn = (command$, args, options) => {
79
110
  let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
80
111
  args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ""));
81
- return new Promise((resolve, reject) => {
82
- const emit = childProcess.spawn(
83
- command$$,
84
- args$,
85
- {
86
- stdio: "inherit",
87
- ...options
88
- }
89
- );
90
- 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);
91
123
  if (code === 0) {
92
124
  resolve(code);
93
125
  } else {
94
126
  reject(code);
95
127
  }
96
128
  });
97
- emit.on("error", (error) => {
129
+ subprocess.on("error", (error) => {
130
+ process.off("beforeExit", handler);
98
131
  !process.exitCode && (process.exitCode = 1);
99
132
  reject(error);
100
133
  });
101
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);
102
143
  };
103
144
 
104
145
  const shell = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
@@ -207,6 +248,18 @@ const impl = (cwd) => {
207
248
  pre[packagesOptions.name] = Object.keys(deps).filter((i) => new RegExp(`${packageName}`).test(i));
208
249
  return pre;
209
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
+ }, {});
210
263
  const normalizePackageNames = getNormalizePackage(packageRelation);
211
264
  const normalizePackageFolderNames = normalizePackageNames.map((i) => i.replace(new RegExp(`${packageName}-?`), "") || packageFolderName);
212
265
  const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || "";
@@ -225,7 +278,8 @@ const impl = (cwd) => {
225
278
  packageDirsMap,
226
279
  packageRelation,
227
280
  normalizePackageNames,
228
- normalizePackageFolderNames
281
+ normalizePackageFolderNames,
282
+ subpackagesMap
229
283
  };
230
284
  configMap[cwd] = config;
231
285
  return config;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@deot/dev-shared",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "type": "module",
5
- "main": "dist/index.es.js",
5
+ "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./dist/index.es.js",
9
+ "import": "./dist/index.js",
10
10
  "require": "./dist/index.cjs",
11
11
  "types": "./dist/index.d.ts"
12
12
  }