@deot/dev-shared 2.7.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));
@@ -84,7 +83,7 @@ const logger = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
84
83
  const SPACE = " ";
85
84
  const binDirectory = path__namespace.resolve(process.cwd(), "./node_modules/.bin");
86
85
  const toPromise = (target, promise) => {
87
- let instance = target;
86
+ const instance = target;
88
87
  instance.then = (resolve, reject) => promise.then(resolve, reject);
89
88
  instance.catch = (callback) => promise.catch(callback);
90
89
  instance.finally = (callback) => promise.finally(callback);
@@ -104,7 +103,7 @@ const command = (command$, args) => {
104
103
  return v || [];
105
104
  };
106
105
  const exec = (command$, args, options) => {
107
- let command$$ = command(command$, args).join(SPACE);
106
+ const command$$ = command(command$, args).join(SPACE);
108
107
  let reject;
109
108
  let resolve;
110
109
  const promise = new Promise((resolve$, reject$) => {
@@ -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({
@@ -132,11 +135,11 @@ const exec = (command$, args, options) => {
132
135
  return toPromise(subprocess, promise);
133
136
  };
134
137
  const spawn = (command$, args, options) => {
135
- let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
136
- args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ""));
138
+ const [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
139
+ const args$$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ""));
137
140
  const subprocess = childProcess__namespace.spawn(
138
141
  command$$,
139
- args$,
142
+ args$$,
140
143
  {
141
144
  stdio: "inherit",
142
145
  ...options
@@ -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);
@@ -188,13 +191,13 @@ const getNormalizePackage = (dataMap) => {
188
191
  });
189
192
  const needUseMap = Object.keys(dataMap).reduce((pre, key) => (pre[key] = 0, pre), {});
190
193
  const queue = [];
191
- for (let key in dataMap) {
194
+ for (const key in dataMap) {
192
195
  const dependencies = dataMap[key];
193
196
  dependencies.forEach((dependency) => {
194
197
  needUseMap[dependency] += 1;
195
198
  });
196
199
  }
197
- for (let key in needUseMap) {
200
+ for (const key in needUseMap) {
198
201
  if (needUseMap[key] === 0) {
199
202
  queue.push(key);
200
203
  }
@@ -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
  }
@@ -248,14 +247,13 @@ const getRealPackageName = (names, cwd) => {
248
247
  return "";
249
248
  }).filter((i) => !!i).join(",");
250
249
  };
251
- let configMap = {};
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
- let isMonorepo = fs__namespace.existsSync(path__namespace.resolve(cwd, workspace));
256
+ const isMonorepo = fs__namespace.existsSync(path__namespace.resolve(cwd, workspace));
259
257
  workspace = isMonorepo ? workspace : "";
260
258
  const packageFolderName = isMonorepo ? "index" : "";
261
259
  const packageDir = path__namespace.resolve(cwd, workspace);
@@ -279,8 +277,8 @@ const impl = (cwd) => {
279
277
  return pre;
280
278
  }, {});
281
279
  const packageRelation = packageFolderNames.reduce((pre, packageFolderName$) => {
282
- let packagesOptions = packageOptionsMap[packageFolderName$];
283
- let deps = {
280
+ const packagesOptions = packageOptionsMap[packageFolderName$];
281
+ const deps = {
284
282
  ...packagesOptions.dependencies || {},
285
283
  ...packagesOptions.devDependencies || {}
286
284
  };
@@ -288,7 +286,7 @@ const impl = (cwd) => {
288
286
  return pre;
289
287
  }, {});
290
288
  const subpackagesMap = packageFolderNames.reduce((pre, packageFolderName$) => {
291
- let dir = path__namespace.resolve(packageDir, packageFolderName$);
289
+ const dir = path__namespace.resolve(packageDir, packageFolderName$);
292
290
  pre[packageFolderName$] = workspace && fs__namespace.existsSync(`${dir}/index.ts`) && !fs__namespace.existsSync(`${dir}/src`) ? fs__namespace.readdirSync(dir).filter((file) => {
293
291
  const fullpath = path__namespace.join(dir, file);
294
292
  const stat = fs__namespace.statSync(fullpath);
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));
@@ -59,7 +58,7 @@ const logger = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
59
58
  const SPACE = " ";
60
59
  const binDirectory = path.resolve(process.cwd(), "./node_modules/.bin");
61
60
  const toPromise = (target, promise) => {
62
- let instance = target;
61
+ const instance = target;
63
62
  instance.then = (resolve, reject) => promise.then(resolve, reject);
64
63
  instance.catch = (callback) => promise.catch(callback);
65
64
  instance.finally = (callback) => promise.finally(callback);
@@ -79,7 +78,7 @@ const command = (command$, args) => {
79
78
  return v || [];
80
79
  };
81
80
  const exec = (command$, args, options) => {
82
- let command$$ = command(command$, args).join(SPACE);
81
+ const command$$ = command(command$, args).join(SPACE);
83
82
  let reject;
84
83
  let resolve;
85
84
  const promise = new Promise((resolve$, reject$) => {
@@ -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({
@@ -107,11 +110,11 @@ const exec = (command$, args, options) => {
107
110
  return toPromise(subprocess, promise);
108
111
  };
109
112
  const spawn = (command$, args, options) => {
110
- let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
111
- args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ""));
113
+ const [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
114
+ const args$$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ""));
112
115
  const subprocess = childProcess.spawn(
113
116
  command$$,
114
- args$,
117
+ args$$,
115
118
  {
116
119
  stdio: "inherit",
117
120
  ...options
@@ -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);
@@ -163,13 +166,13 @@ const getNormalizePackage = (dataMap) => {
163
166
  });
164
167
  const needUseMap = Object.keys(dataMap).reduce((pre, key) => (pre[key] = 0, pre), {});
165
168
  const queue = [];
166
- for (let key in dataMap) {
169
+ for (const key in dataMap) {
167
170
  const dependencies = dataMap[key];
168
171
  dependencies.forEach((dependency) => {
169
172
  needUseMap[dependency] += 1;
170
173
  });
171
174
  }
172
- for (let key in needUseMap) {
175
+ for (const key in needUseMap) {
173
176
  if (needUseMap[key] === 0) {
174
177
  queue.push(key);
175
178
  }
@@ -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
  }
@@ -223,14 +222,13 @@ const getRealPackageName = (names, cwd) => {
223
222
  return "";
224
223
  }).filter((i) => !!i).join(",");
225
224
  };
226
- let configMap = {};
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
- let isMonorepo = fs.existsSync(path.resolve(cwd, workspace));
231
+ const isMonorepo = fs.existsSync(path.resolve(cwd, workspace));
234
232
  workspace = isMonorepo ? workspace : "";
235
233
  const packageFolderName = isMonorepo ? "index" : "";
236
234
  const packageDir = path.resolve(cwd, workspace);
@@ -254,8 +252,8 @@ const impl = (cwd) => {
254
252
  return pre;
255
253
  }, {});
256
254
  const packageRelation = packageFolderNames.reduce((pre, packageFolderName$) => {
257
- let packagesOptions = packageOptionsMap[packageFolderName$];
258
- let deps = {
255
+ const packagesOptions = packageOptionsMap[packageFolderName$];
256
+ const deps = {
259
257
  ...packagesOptions.dependencies || {},
260
258
  ...packagesOptions.devDependencies || {}
261
259
  };
@@ -263,7 +261,7 @@ const impl = (cwd) => {
263
261
  return pre;
264
262
  }, {});
265
263
  const subpackagesMap = packageFolderNames.reduce((pre, packageFolderName$) => {
266
- let dir = path.resolve(packageDir, packageFolderName$);
264
+ const dir = path.resolve(packageDir, packageFolderName$);
267
265
  pre[packageFolderName$] = workspace && fs.existsSync(`${dir}/index.ts`) && !fs.existsSync(`${dir}/src`) ? fs.readdirSync(dir).filter((file) => {
268
266
  const fullpath = path.join(dir, file);
269
267
  const stat = fs.statSync(fullpath);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@deot/dev-shared",
3
- "version": "2.7.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": [