@deot/dev-shared 2.8.0 → 2.9.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
@@ -43,8 +43,7 @@ const getHost = () => {
43
43
  return ips[0];
44
44
  };
45
45
  const formatBytes = (size, suffix = 2) => {
46
- if (!size)
47
- return "0B";
46
+ if (!size) return "0B";
48
47
  const base = 1024;
49
48
  const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
50
49
  const index = Math.floor(Math.log(size) / Math.log(base));
@@ -114,7 +113,11 @@ const exec = (command$, args, options) => {
114
113
  const subprocess = childProcess__namespace.exec(command$$, options, (error, stdout, stderr) => {
115
114
  process.off("beforeExit", handler);
116
115
  if (error) {
117
- reject(error);
116
+ reject({
117
+ ...error,
118
+ stderr: stderr.toString(),
119
+ stdout: stdout.toString()
120
+ });
118
121
  return;
119
122
  }
120
123
  resolve({
@@ -145,7 +148,7 @@ const spawn = (command$, args, options) => {
145
148
  const promise = new Promise((resolve, reject) => {
146
149
  subprocess.on("close", (code) => {
147
150
  process.off("beforeExit", handler);
148
- if (code === 0) {
151
+ if (typeof code === "number" && (code === 0 || code >= 128)) {
149
152
  resolve(code);
150
153
  } else {
151
154
  reject(code);
@@ -203,8 +206,7 @@ const getNormalizePackage = (dataMap) => {
203
206
  while (queue.length > 0) {
204
207
  const node = queue.shift();
205
208
  /* istanbul ignore next -- @preserve */
206
- if (!node)
207
- return [];
209
+ if (!node) return [];
208
210
  result.push(node);
209
211
  const dependencies = dataMap[node];
210
212
  for (let i = 0; i < dependencies.length; i++) {
@@ -228,17 +230,14 @@ const getPackageName = (packageFolderName$, cwd) => {
228
230
  const getPackageFolderName = (packageName$, cwd) => {
229
231
  const { workspace, packageFolderName, packageName } = impl(cwd);
230
232
  /* istanbul ignore next -- @preserve */
231
- if (!workspace)
232
- return "";
233
- if (packageName$ === packageName)
234
- return packageFolderName;
235
- return packageName$?.replace(new RegExp(`${packageName}-?`), "");
233
+ if (!workspace) return "";
234
+ if (packageName$ === packageName) return packageFolderName;
235
+ return packageName$?.replace(new RegExp(`${packageName}-?`, "g"), "");
236
236
  };
237
237
  const getRealPackageName = (names, cwd) => {
238
238
  return names?.split(",").map((name) => {
239
239
  const { workspace, packageName, packageDir } = impl(cwd);
240
- if (!workspace || !name || name === "*")
241
- return name;
240
+ if (!workspace || !name || name === "*") return name;
242
241
  if (name.includes(packageName)) {
243
242
  name = getPackageFolderName(name);
244
243
  }
@@ -251,8 +250,7 @@ const getRealPackageName = (names, cwd) => {
251
250
  const configMap = {};
252
251
  const impl = (cwd) => {
253
252
  cwd = cwd || cwd$;
254
- if (configMap[cwd])
255
- return configMap[cwd];
253
+ if (configMap[cwd]) return configMap[cwd];
256
254
  const rootPackageOptions = require$(`${cwd}/package.json`);
257
255
  let workspace = "packages";
258
256
  const isMonorepo = fs__namespace.existsSync(path__namespace.resolve(cwd, workspace));
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
-
3
1
  import * as childProcess from 'node:child_process';
4
2
 
5
3
  export declare interface AnyFunction<T = void> {
package/dist/index.js CHANGED
@@ -18,8 +18,7 @@ const getHost = () => {
18
18
  return ips[0];
19
19
  };
20
20
  const formatBytes = (size, suffix = 2) => {
21
- if (!size)
22
- return "0B";
21
+ if (!size) return "0B";
23
22
  const base = 1024;
24
23
  const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
25
24
  const index = Math.floor(Math.log(size) / Math.log(base));
@@ -89,7 +88,11 @@ const exec = (command$, args, options) => {
89
88
  const subprocess = childProcess.exec(command$$, options, (error, stdout, stderr) => {
90
89
  process.off("beforeExit", handler);
91
90
  if (error) {
92
- reject(error);
91
+ reject({
92
+ ...error,
93
+ stderr: stderr.toString(),
94
+ stdout: stdout.toString()
95
+ });
93
96
  return;
94
97
  }
95
98
  resolve({
@@ -120,7 +123,7 @@ const spawn = (command$, args, options) => {
120
123
  const promise = new Promise((resolve, reject) => {
121
124
  subprocess.on("close", (code) => {
122
125
  process.off("beforeExit", handler);
123
- if (code === 0) {
126
+ if (typeof code === "number" && (code === 0 || code >= 128)) {
124
127
  resolve(code);
125
128
  } else {
126
129
  reject(code);
@@ -178,8 +181,7 @@ const getNormalizePackage = (dataMap) => {
178
181
  while (queue.length > 0) {
179
182
  const node = queue.shift();
180
183
  /* istanbul ignore next -- @preserve */
181
- if (!node)
182
- return [];
184
+ if (!node) return [];
183
185
  result.push(node);
184
186
  const dependencies = dataMap[node];
185
187
  for (let i = 0; i < dependencies.length; i++) {
@@ -203,17 +205,14 @@ const getPackageName = (packageFolderName$, cwd) => {
203
205
  const getPackageFolderName = (packageName$, cwd) => {
204
206
  const { workspace, packageFolderName, packageName } = impl(cwd);
205
207
  /* istanbul ignore next -- @preserve */
206
- if (!workspace)
207
- return "";
208
- if (packageName$ === packageName)
209
- return packageFolderName;
210
- return packageName$?.replace(new RegExp(`${packageName}-?`), "");
208
+ if (!workspace) return "";
209
+ if (packageName$ === packageName) return packageFolderName;
210
+ return packageName$?.replace(new RegExp(`${packageName}-?`, "g"), "");
211
211
  };
212
212
  const getRealPackageName = (names, cwd) => {
213
213
  return names?.split(",").map((name) => {
214
214
  const { workspace, packageName, packageDir } = impl(cwd);
215
- if (!workspace || !name || name === "*")
216
- return name;
215
+ if (!workspace || !name || name === "*") return name;
217
216
  if (name.includes(packageName)) {
218
217
  name = getPackageFolderName(name);
219
218
  }
@@ -226,8 +225,7 @@ const getRealPackageName = (names, cwd) => {
226
225
  const configMap = {};
227
226
  const impl = (cwd) => {
228
227
  cwd = cwd || cwd$;
229
- if (configMap[cwd])
230
- return configMap[cwd];
228
+ if (configMap[cwd]) return configMap[cwd];
231
229
  const rootPackageOptions = require$(`${cwd}/package.json`);
232
230
  let workspace = "packages";
233
231
  const isMonorepo = fs.existsSync(path.resolve(cwd, workspace));
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@deot/dev-shared",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
+ "types": "./dist/index.d.ts",
9
10
  "import": "./dist/index.js",
10
- "require": "./dist/index.cjs",
11
- "types": "./dist/index.d.ts"
11
+ "require": "./dist/index.cjs"
12
12
  }
13
13
  },
14
14
  "files": [