@deot/dev-shared 1.1.0 → 2.0.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.js CHANGED
@@ -1,273 +1,265 @@
1
1
  'use strict';
2
2
 
3
- var os = require('node:os');
4
- var path = require('node:path');
5
- var childProcess = require('node:child_process');
6
- var util = require('node:util');
7
- var fs = require('node:fs');
8
- var node_module = require('node:module');
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const os = require('node:os');
6
+ const path = require('node:path');
7
+ const childProcess = require('node:child_process');
8
+ const util = require('node:util');
9
+ const fs = require('node:fs');
10
+ const node_module = require('node:module');
9
11
 
10
12
  function _interopNamespaceDefault(e) {
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n.default = e;
24
- return Object.freeze(n);
13
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
14
+ if (e) {
15
+ for (const k in e) {
16
+ if (k !== 'default') {
17
+ const d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: () => e[k]
21
+ });
22
+ }
23
+ }
24
+ }
25
+ n.default = e;
26
+ return Object.freeze(n);
25
27
  }
26
28
 
27
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
28
- var childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
29
- var util__namespace = /*#__PURE__*/_interopNamespaceDefault(util);
30
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
29
+ const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
30
+ const childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
31
+ const util__namespace = /*#__PURE__*/_interopNamespaceDefault(util);
32
+ const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
31
33
 
32
34
  const getHost = () => {
33
- const ips = [];
34
- const ntwk = os.networkInterfaces();
35
- for (const k in ntwk) {
36
- for (let i = 0; i < ntwk[k].length; i++) {
37
- const _add = ntwk[k][i].address;
38
- if (_add && _add.split('.').length == 4 && !ntwk[k][i].internal && ntwk[k][i].family == 'IPv4') {
39
- ips.push(_add);
40
- }
41
- }
35
+ const ips = [];
36
+ const ntwk = os.networkInterfaces();
37
+ for (const k in ntwk) {
38
+ for (let i = 0; i < ntwk[k].length; i++) {
39
+ const _add = ntwk[k][i].address;
40
+ if (_add && _add.split(".").length == 4 && !ntwk[k][i].internal && ntwk[k][i].family == "IPv4") {
41
+ ips.push(_add);
42
+ }
42
43
  }
43
- return ips[0];
44
+ }
45
+ return ips[0];
44
46
  };
45
47
  const formatBytes = (size, suffix = 2) => {
46
- if (!size)
47
- return "0B";
48
- const base = 1024;
49
- const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
50
- const index = Math.floor(Math.log(size) / Math.log(base));
51
- const value = parseFloat((size / (base ** index)).toFixed(suffix));
52
- return value + units[index];
48
+ if (!size)
49
+ return "0B";
50
+ const base = 1024;
51
+ const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
52
+ const index = Math.floor(Math.log(size) / Math.log(base));
53
+ const value = parseFloat((size / base ** index).toFixed(suffix));
54
+ return value + units[index];
53
55
  };
54
56
  const autoCatch = async (impl, options = {}) => {
55
- const { onError = console.error } = options;
56
- let target = impl;
57
- typeof target === 'function' && (target = target());
58
- try {
59
- const e = await target;
60
- return e;
61
- }
62
- catch (e) {
63
- onError(e);
64
- }
57
+ const { onError = console.error } = options;
58
+ let target = impl;
59
+ typeof target === "function" && (target = target());
60
+ try {
61
+ const e = await target;
62
+ return e;
63
+ } catch (e) {
64
+ onError(e);
65
+ }
65
66
  };
66
67
 
67
- var utils = /*#__PURE__*/Object.freeze({
68
- __proto__: null,
69
- autoCatch: autoCatch,
70
- formatBytes: formatBytes,
71
- getHost: getHost
72
- });
68
+ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
69
+ __proto__: null,
70
+ autoCatch,
71
+ formatBytes,
72
+ getHost
73
+ }, Symbol.toStringTag, { value: 'Module' }));
73
74
 
74
75
  const log = console.log;
75
76
  const error = console.error;
76
77
  const info = console.info;
77
78
 
78
- var logger = /*#__PURE__*/Object.freeze({
79
- __proto__: null,
80
- error: error,
81
- info: info,
82
- log: log
83
- });
79
+ const logger = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
80
+ __proto__: null,
81
+ error,
82
+ info,
83
+ log
84
+ }, Symbol.toStringTag, { value: 'Module' }));
84
85
 
85
- const SPACE = ' ';
86
- const binDirectory = path__namespace.resolve(process.cwd(), './node_modules/.bin');
87
- const LOCAL_COMMAND_MAP = fs__namespace.existsSync(binDirectory)
88
- ? fs__namespace
89
- .readdirSync(binDirectory)
90
- .reduce((pre, file) => {
91
- const fullpath = path__namespace.resolve(binDirectory, file);
92
- const stat = fs__namespace.statSync(fullpath);
93
- if (stat.isFile()) {
94
- pre[file] = `./node_modules/.bin/${file}`;
95
- }
96
- return pre;
97
- }, {})
98
- : {};
86
+ const SPACE = " ";
87
+ const binDirectory = path__namespace.resolve(process.cwd(), "./node_modules/.bin");
88
+ const LOCAL_COMMAND_MAP = fs__namespace.existsSync(binDirectory) ? fs__namespace.readdirSync(binDirectory).reduce((pre, file) => {
89
+ const fullpath = path__namespace.resolve(binDirectory, file);
90
+ const stat = fs__namespace.statSync(fullpath);
91
+ if (stat.isFile()) {
92
+ pre[file] = `./node_modules/.bin/${file}`;
93
+ }
94
+ return pre;
95
+ }, {}) : {};
99
96
  const command = (command$, args) => {
100
- const v = (command$ + SPACE + (args || []).join(SPACE))
101
- .match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
102
- return v || [];
97
+ const v = (command$ + SPACE + (args || []).join(SPACE)).match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
98
+ return v || [];
103
99
  };
104
100
  const exec = (command$, args) => {
105
- return util__namespace.promisify(childProcess__namespace.exec)(command(command$, args).join(SPACE));
101
+ return util__namespace.promisify(childProcess__namespace.exec)(command(command$, args).join(SPACE));
106
102
  };
107
103
  const spawn = (command$, args, options) => {
108
- let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
109
- args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ''));
110
- return new Promise((resolve, reject) => {
111
- const emit = childProcess__namespace.spawn(command$$, args$, {
112
- stdio: 'inherit',
113
- ...options
114
- });
115
- emit.on('close', (code) => {
116
- if (code === 0) {
117
- resolve(code);
118
- }
119
- else {
120
- reject(code);
121
- }
122
- });
123
- emit.on('error', (error) => {
124
- !process.exitCode && (process.exitCode = 1);
125
- reject(error);
126
- });
104
+ let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
105
+ 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) => {
116
+ if (code === 0) {
117
+ resolve(code);
118
+ } else {
119
+ reject(code);
120
+ }
121
+ });
122
+ emit.on("error", (error) => {
123
+ !process.exitCode && (process.exitCode = 1);
124
+ reject(error);
127
125
  });
126
+ });
128
127
  };
129
128
 
130
- var shell = /*#__PURE__*/Object.freeze({
131
- __proto__: null,
132
- LOCAL_COMMAND_MAP: LOCAL_COMMAND_MAP,
133
- command: command,
134
- exec: exec,
135
- spawn: spawn
136
- });
129
+ const shell = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
130
+ __proto__: null,
131
+ LOCAL_COMMAND_MAP,
132
+ command,
133
+ exec,
134
+ spawn
135
+ }, Symbol.toStringTag, { value: 'Module' }));
137
136
 
138
137
  const cwd$ = process.cwd();
139
138
  const require$ = node_module.createRequire(cwd$);
140
139
  const getNormalizePackage = (dataMap) => {
141
- Object.keys(dataMap).forEach(packageName => {
142
- const relations = dataMap[packageName];
143
- relations.forEach((packageName$) => {
144
- if (dataMap[packageName$].includes(packageName)) {
145
- throw new Error(`${packageName} ${packageName$} deps loop`);
146
- }
147
- });
140
+ Object.keys(dataMap).forEach((packageName) => {
141
+ const relations = dataMap[packageName];
142
+ relations.forEach((packageName$) => {
143
+ if (dataMap[packageName$].includes(packageName)) {
144
+ throw new Error(`${packageName} ${packageName$} deps loop`);
145
+ }
148
146
  });
149
- const needUseMap = Object.keys(dataMap).reduce((pre, key) => (pre[key] = 0, pre), {});
150
- const queue = [];
151
- for (let key in dataMap) {
152
- const dependencies = dataMap[key];
153
- dependencies.forEach((dependency) => {
154
- needUseMap[dependency] += 1;
155
- });
156
- }
157
- for (let key in needUseMap) {
158
- if (needUseMap[key] === 0) {
159
- queue.push(key);
160
- }
147
+ });
148
+ const needUseMap = Object.keys(dataMap).reduce((pre, key) => (pre[key] = 0, pre), {});
149
+ const queue = [];
150
+ for (let key in dataMap) {
151
+ const dependencies = dataMap[key];
152
+ dependencies.forEach((dependency) => {
153
+ needUseMap[dependency] += 1;
154
+ });
155
+ }
156
+ for (let key in needUseMap) {
157
+ if (needUseMap[key] === 0) {
158
+ queue.push(key);
161
159
  }
162
- const result = [];
163
- while (queue.length > 0) {
164
- const node = queue.shift();
165
- if (!node)
166
- return [];
167
- result.push(node);
168
- const dependencies = dataMap[node];
169
- for (let i = 0; i < dependencies.length; i++) {
170
- const dependency = dependencies[i];
171
- needUseMap[dependency] -= 1;
172
- if (needUseMap[dependency] === 0) {
173
- queue.push(dependency);
174
- }
175
- }
160
+ }
161
+ const result = [];
162
+ while (queue.length > 0) {
163
+ const node = queue.shift();
164
+ if (!node)
165
+ return [];
166
+ result.push(node);
167
+ const dependencies = dataMap[node];
168
+ for (let i = 0; i < dependencies.length; i++) {
169
+ const dependency = dependencies[i];
170
+ needUseMap[dependency] -= 1;
171
+ if (needUseMap[dependency] === 0) {
172
+ queue.push(dependency);
173
+ }
176
174
  }
177
- return result.reverse();
175
+ }
176
+ return result.reverse();
178
177
  };
179
178
  const getPackageName = (packageFolderName$) => {
180
- const { workspace, packageFolderName, packageName } = impl();
181
- if (!workspace
182
- || !packageFolderName$
183
- || packageFolderName$ === packageFolderName) {
184
- return packageName;
185
- }
186
- else {
187
- return `${packageName}-${packageFolderName$.replace(new RegExp(`${packageName}-?`), '')}`;
188
- }
179
+ const { workspace, packageFolderName, packageName } = impl();
180
+ if (!workspace || !packageFolderName$ || packageFolderName$ === packageFolderName) {
181
+ return packageName;
182
+ } else {
183
+ return `${packageName}-${packageFolderName$.replace(new RegExp(`${packageName}-?`), "")}`;
184
+ }
189
185
  };
190
186
  const getPackageFolderName = (packageName$) => {
191
- const { workspace, packageFolderName, packageName } = impl();
192
- if (!workspace)
193
- return '';
194
- if (packageName$ === packageName)
195
- return packageFolderName;
196
- return packageName$?.replace(new RegExp(`${packageName}-?`), '');
187
+ const { workspace, packageFolderName, packageName } = impl();
188
+ if (!workspace)
189
+ return "";
190
+ if (packageName$ === packageName)
191
+ return packageFolderName;
192
+ return packageName$?.replace(new RegExp(`${packageName}-?`), "");
197
193
  };
198
194
  let configMap = {};
199
195
  const impl = (cwd) => {
200
- cwd = cwd || cwd$;
201
- if (configMap[cwd])
202
- return configMap[cwd];
203
- const rootPackageOptions = require$(`${cwd}/package.json`);
204
- let workspace = 'packages';
205
- let isMonorepo = fs__namespace.existsSync(path__namespace.resolve(cwd, workspace));
206
- workspace = isMonorepo ? workspace : '';
207
- const packageFolderName = isMonorepo ? 'index' : '';
208
- const packageDir = path__namespace.resolve(cwd, workspace);
209
- const packageOptions = require$(path__namespace.resolve(packageDir, packageFolderName, 'package.json'));
210
- const packageName = packageOptions.name;
211
- const packageVersion = packageOptions.version;
212
- const packageFolderNames = !isMonorepo ? [] : fs__namespace
213
- .readdirSync(packageDir)
214
- .reduce((pre, file) => {
215
- const fullpath = path__namespace.resolve(packageDir, file);
216
- const stat = fs__namespace.statSync(fullpath);
217
- if (!(/(^_|tpl)/.test(file))
218
- && stat.isDirectory()) {
219
- pre.push(file);
220
- }
221
- return pre;
222
- }, []);
223
- const packageOptionsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
224
- pre[packageFolderName$] = require$(path__namespace.resolve(packageDir, packageFolderName$, 'package.json'));
225
- return pre;
226
- }, {});
227
- const packageDirsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
228
- pre[packageFolderName$] = path__namespace.resolve(packageDir, packageFolderName$);
229
- return pre;
230
- }, {});
231
- const packageRelation = packageFolderNames.reduce((pre, packageFolderName$) => {
232
- let packagesOptions = packageOptionsMap[packageFolderName$];
233
- let deps = {
234
- ...(packagesOptions.dependencies || {}),
235
- ...(packagesOptions.devDependencies || {}),
236
- };
237
- pre[packagesOptions.name] = Object.keys(deps).filter(i => new RegExp(`${packageName}`).test(i));
238
- return pre;
239
- }, {});
240
- const normalizePackageNames = getNormalizePackage(packageRelation);
241
- const normalizePackageFolderNames = normalizePackageNames
242
- .map(i => i.replace(new RegExp(`${packageName}-?`), '') || packageFolderName);
243
- const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || '';
244
- const config = {
245
- cwd,
246
- workspace,
247
- homepage: homepage.replace(/(.*)(https?:\/\/.*)(#|\.git)/, '$2'),
248
- packageFolderName,
249
- packageDir,
250
- packageOptions,
251
- packageName,
252
- packageVersion,
253
- packageFolderNames,
254
- packageOptionsMap,
255
- packageDirsMap,
256
- packageRelation,
257
- normalizePackageNames,
258
- normalizePackageFolderNames
196
+ cwd = cwd || cwd$;
197
+ if (configMap[cwd])
198
+ return configMap[cwd];
199
+ const rootPackageOptions = require$(`${cwd}/package.json`);
200
+ let workspace = "packages";
201
+ let isMonorepo = fs__namespace.existsSync(path__namespace.resolve(cwd, workspace));
202
+ workspace = isMonorepo ? workspace : "";
203
+ const packageFolderName = isMonorepo ? "index" : "";
204
+ const packageDir = path__namespace.resolve(cwd, workspace);
205
+ const packageOptions = require$(path__namespace.resolve(packageDir, packageFolderName, "package.json"));
206
+ const packageName = packageOptions.name;
207
+ const packageVersion = packageOptions.version;
208
+ const packageFolderNames = !isMonorepo ? [] : fs__namespace.readdirSync(packageDir).reduce((pre, file) => {
209
+ const fullpath = path__namespace.resolve(packageDir, file);
210
+ const stat = fs__namespace.statSync(fullpath);
211
+ if (!/(^_|tpl)/.test(file) && stat.isDirectory()) {
212
+ pre.push(file);
213
+ }
214
+ return pre;
215
+ }, []);
216
+ const packageOptionsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
217
+ pre[packageFolderName$] = require$(path__namespace.resolve(packageDir, packageFolderName$, "package.json"));
218
+ return pre;
219
+ }, {});
220
+ const packageDirsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
221
+ pre[packageFolderName$] = path__namespace.resolve(packageDir, packageFolderName$);
222
+ return pre;
223
+ }, {});
224
+ const packageRelation = packageFolderNames.reduce((pre, packageFolderName$) => {
225
+ let packagesOptions = packageOptionsMap[packageFolderName$];
226
+ let deps = {
227
+ ...packagesOptions.dependencies || {},
228
+ ...packagesOptions.devDependencies || {}
259
229
  };
260
- configMap[cwd] = config;
261
- return config;
230
+ pre[packagesOptions.name] = Object.keys(deps).filter((i) => new RegExp(`${packageName}`).test(i));
231
+ return pre;
232
+ }, {});
233
+ const normalizePackageNames = getNormalizePackage(packageRelation);
234
+ const normalizePackageFolderNames = normalizePackageNames.map((i) => i.replace(new RegExp(`${packageName}-?`), "") || packageFolderName);
235
+ const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || "";
236
+ const config = {
237
+ cwd,
238
+ workspace,
239
+ homepage: homepage.replace(/(.*)(https?:\/\/.*)(#|\.git)/, "$2"),
240
+ packageFolderName,
241
+ packageDir,
242
+ packageOptions,
243
+ packageName,
244
+ packageVersion,
245
+ packageFolderNames,
246
+ packageOptionsMap,
247
+ packageDirsMap,
248
+ packageRelation,
249
+ normalizePackageNames,
250
+ normalizePackageFolderNames
251
+ };
252
+ configMap[cwd] = config;
253
+ return config;
262
254
  };
263
255
 
264
- var locals = /*#__PURE__*/Object.freeze({
265
- __proto__: null,
266
- getNormalizePackage: getNormalizePackage,
267
- getPackageFolderName: getPackageFolderName,
268
- getPackageName: getPackageName,
269
- impl: impl
270
- });
256
+ const locals = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
257
+ __proto__: null,
258
+ getNormalizePackage,
259
+ getPackageFolderName,
260
+ getPackageName,
261
+ impl
262
+ }, Symbol.toStringTag, { value: 'Module' }));
271
263
 
272
264
  exports.Locals = locals;
273
265
  exports.Logger = logger;
package/dist/index.es.js CHANGED
@@ -6,243 +6,233 @@ import * as fs from 'node:fs';
6
6
  import { createRequire } from 'node:module';
7
7
 
8
8
  const getHost = () => {
9
- const ips = [];
10
- const ntwk = os.networkInterfaces();
11
- for (const k in ntwk) {
12
- for (let i = 0; i < ntwk[k].length; i++) {
13
- const _add = ntwk[k][i].address;
14
- if (_add && _add.split('.').length == 4 && !ntwk[k][i].internal && ntwk[k][i].family == 'IPv4') {
15
- ips.push(_add);
16
- }
17
- }
9
+ const ips = [];
10
+ const ntwk = os.networkInterfaces();
11
+ for (const k in ntwk) {
12
+ for (let i = 0; i < ntwk[k].length; i++) {
13
+ const _add = ntwk[k][i].address;
14
+ if (_add && _add.split(".").length == 4 && !ntwk[k][i].internal && ntwk[k][i].family == "IPv4") {
15
+ ips.push(_add);
16
+ }
18
17
  }
19
- return ips[0];
18
+ }
19
+ return ips[0];
20
20
  };
21
21
  const formatBytes = (size, suffix = 2) => {
22
- if (!size)
23
- return "0B";
24
- const base = 1024;
25
- const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
26
- const index = Math.floor(Math.log(size) / Math.log(base));
27
- const value = parseFloat((size / (base ** index)).toFixed(suffix));
28
- return value + units[index];
22
+ if (!size)
23
+ return "0B";
24
+ const base = 1024;
25
+ const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
26
+ const index = Math.floor(Math.log(size) / Math.log(base));
27
+ const value = parseFloat((size / base ** index).toFixed(suffix));
28
+ return value + units[index];
29
29
  };
30
30
  const autoCatch = async (impl, options = {}) => {
31
- const { onError = console.error } = options;
32
- let target = impl;
33
- typeof target === 'function' && (target = target());
34
- try {
35
- const e = await target;
36
- return e;
37
- }
38
- catch (e) {
39
- onError(e);
40
- }
31
+ const { onError = console.error } = options;
32
+ let target = impl;
33
+ typeof target === "function" && (target = target());
34
+ try {
35
+ const e = await target;
36
+ return e;
37
+ } catch (e) {
38
+ onError(e);
39
+ }
41
40
  };
42
41
 
43
- var utils = /*#__PURE__*/Object.freeze({
44
- __proto__: null,
45
- autoCatch: autoCatch,
46
- formatBytes: formatBytes,
47
- getHost: getHost
48
- });
42
+ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
43
+ __proto__: null,
44
+ autoCatch,
45
+ formatBytes,
46
+ getHost
47
+ }, Symbol.toStringTag, { value: 'Module' }));
49
48
 
50
49
  const log = console.log;
51
50
  const error = console.error;
52
51
  const info = console.info;
53
52
 
54
- var logger = /*#__PURE__*/Object.freeze({
55
- __proto__: null,
56
- error: error,
57
- info: info,
58
- log: log
59
- });
53
+ const logger = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
54
+ __proto__: null,
55
+ error,
56
+ info,
57
+ log
58
+ }, Symbol.toStringTag, { value: 'Module' }));
60
59
 
61
- const SPACE = ' ';
62
- const binDirectory = path.resolve(process.cwd(), './node_modules/.bin');
63
- const LOCAL_COMMAND_MAP = fs.existsSync(binDirectory)
64
- ? fs
65
- .readdirSync(binDirectory)
66
- .reduce((pre, file) => {
67
- const fullpath = path.resolve(binDirectory, file);
68
- const stat = fs.statSync(fullpath);
69
- if (stat.isFile()) {
70
- pre[file] = `./node_modules/.bin/${file}`;
71
- }
72
- return pre;
73
- }, {})
74
- : {};
60
+ const SPACE = " ";
61
+ const binDirectory = path.resolve(process.cwd(), "./node_modules/.bin");
62
+ const LOCAL_COMMAND_MAP = fs.existsSync(binDirectory) ? fs.readdirSync(binDirectory).reduce((pre, file) => {
63
+ const fullpath = path.resolve(binDirectory, file);
64
+ const stat = fs.statSync(fullpath);
65
+ if (stat.isFile()) {
66
+ pre[file] = `./node_modules/.bin/${file}`;
67
+ }
68
+ return pre;
69
+ }, {}) : {};
75
70
  const command = (command$, args) => {
76
- const v = (command$ + SPACE + (args || []).join(SPACE))
77
- .match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
78
- return v || [];
71
+ const v = (command$ + SPACE + (args || []).join(SPACE)).match(/[^\s'"]+|'[^']*'|"[^"]*"/g);
72
+ return v || [];
79
73
  };
80
74
  const exec = (command$, args) => {
81
- return util.promisify(childProcess.exec)(command(command$, args).join(SPACE));
75
+ return util.promisify(childProcess.exec)(command(command$, args).join(SPACE));
82
76
  };
83
77
  const spawn = (command$, args, options) => {
84
- let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
85
- args$ = args$.map((i) => i.replace(/^['"]|['"]$/g, ''));
86
- return new Promise((resolve, reject) => {
87
- const emit = childProcess.spawn(command$$, args$, {
88
- stdio: 'inherit',
89
- ...options
90
- });
91
- emit.on('close', (code) => {
92
- if (code === 0) {
93
- resolve(code);
94
- }
95
- else {
96
- reject(code);
97
- }
98
- });
99
- emit.on('error', (error) => {
100
- !process.exitCode && (process.exitCode = 1);
101
- reject(error);
102
- });
78
+ let [command$$, ...args$] = command(command$, args).map((i) => LOCAL_COMMAND_MAP[i] || i);
79
+ 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) => {
90
+ if (code === 0) {
91
+ resolve(code);
92
+ } else {
93
+ reject(code);
94
+ }
103
95
  });
96
+ emit.on("error", (error) => {
97
+ !process.exitCode && (process.exitCode = 1);
98
+ reject(error);
99
+ });
100
+ });
104
101
  };
105
102
 
106
- var shell = /*#__PURE__*/Object.freeze({
107
- __proto__: null,
108
- LOCAL_COMMAND_MAP: LOCAL_COMMAND_MAP,
109
- command: command,
110
- exec: exec,
111
- spawn: spawn
112
- });
103
+ const shell = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
104
+ __proto__: null,
105
+ LOCAL_COMMAND_MAP,
106
+ command,
107
+ exec,
108
+ spawn
109
+ }, Symbol.toStringTag, { value: 'Module' }));
113
110
 
114
111
  const cwd$ = process.cwd();
115
112
  const require$ = createRequire(cwd$);
116
113
  const getNormalizePackage = (dataMap) => {
117
- Object.keys(dataMap).forEach(packageName => {
118
- const relations = dataMap[packageName];
119
- relations.forEach((packageName$) => {
120
- if (dataMap[packageName$].includes(packageName)) {
121
- throw new Error(`${packageName} ${packageName$} deps loop`);
122
- }
123
- });
114
+ Object.keys(dataMap).forEach((packageName) => {
115
+ const relations = dataMap[packageName];
116
+ relations.forEach((packageName$) => {
117
+ if (dataMap[packageName$].includes(packageName)) {
118
+ throw new Error(`${packageName} ${packageName$} deps loop`);
119
+ }
124
120
  });
125
- const needUseMap = Object.keys(dataMap).reduce((pre, key) => (pre[key] = 0, pre), {});
126
- const queue = [];
127
- for (let key in dataMap) {
128
- const dependencies = dataMap[key];
129
- dependencies.forEach((dependency) => {
130
- needUseMap[dependency] += 1;
131
- });
132
- }
133
- for (let key in needUseMap) {
134
- if (needUseMap[key] === 0) {
135
- queue.push(key);
136
- }
121
+ });
122
+ const needUseMap = Object.keys(dataMap).reduce((pre, key) => (pre[key] = 0, pre), {});
123
+ const queue = [];
124
+ for (let key in dataMap) {
125
+ const dependencies = dataMap[key];
126
+ dependencies.forEach((dependency) => {
127
+ needUseMap[dependency] += 1;
128
+ });
129
+ }
130
+ for (let key in needUseMap) {
131
+ if (needUseMap[key] === 0) {
132
+ queue.push(key);
137
133
  }
138
- const result = [];
139
- while (queue.length > 0) {
140
- const node = queue.shift();
141
- if (!node)
142
- return [];
143
- result.push(node);
144
- const dependencies = dataMap[node];
145
- for (let i = 0; i < dependencies.length; i++) {
146
- const dependency = dependencies[i];
147
- needUseMap[dependency] -= 1;
148
- if (needUseMap[dependency] === 0) {
149
- queue.push(dependency);
150
- }
151
- }
134
+ }
135
+ const result = [];
136
+ while (queue.length > 0) {
137
+ const node = queue.shift();
138
+ if (!node)
139
+ return [];
140
+ result.push(node);
141
+ const dependencies = dataMap[node];
142
+ for (let i = 0; i < dependencies.length; i++) {
143
+ const dependency = dependencies[i];
144
+ needUseMap[dependency] -= 1;
145
+ if (needUseMap[dependency] === 0) {
146
+ queue.push(dependency);
147
+ }
152
148
  }
153
- return result.reverse();
149
+ }
150
+ return result.reverse();
154
151
  };
155
152
  const getPackageName = (packageFolderName$) => {
156
- const { workspace, packageFolderName, packageName } = impl();
157
- if (!workspace
158
- || !packageFolderName$
159
- || packageFolderName$ === packageFolderName) {
160
- return packageName;
161
- }
162
- else {
163
- return `${packageName}-${packageFolderName$.replace(new RegExp(`${packageName}-?`), '')}`;
164
- }
153
+ const { workspace, packageFolderName, packageName } = impl();
154
+ if (!workspace || !packageFolderName$ || packageFolderName$ === packageFolderName) {
155
+ return packageName;
156
+ } else {
157
+ return `${packageName}-${packageFolderName$.replace(new RegExp(`${packageName}-?`), "")}`;
158
+ }
165
159
  };
166
160
  const getPackageFolderName = (packageName$) => {
167
- const { workspace, packageFolderName, packageName } = impl();
168
- if (!workspace)
169
- return '';
170
- if (packageName$ === packageName)
171
- return packageFolderName;
172
- return packageName$?.replace(new RegExp(`${packageName}-?`), '');
161
+ const { workspace, packageFolderName, packageName } = impl();
162
+ if (!workspace)
163
+ return "";
164
+ if (packageName$ === packageName)
165
+ return packageFolderName;
166
+ return packageName$?.replace(new RegExp(`${packageName}-?`), "");
173
167
  };
174
168
  let configMap = {};
175
169
  const impl = (cwd) => {
176
- cwd = cwd || cwd$;
177
- if (configMap[cwd])
178
- return configMap[cwd];
179
- const rootPackageOptions = require$(`${cwd}/package.json`);
180
- let workspace = 'packages';
181
- let isMonorepo = fs.existsSync(path.resolve(cwd, workspace));
182
- workspace = isMonorepo ? workspace : '';
183
- const packageFolderName = isMonorepo ? 'index' : '';
184
- const packageDir = path.resolve(cwd, workspace);
185
- const packageOptions = require$(path.resolve(packageDir, packageFolderName, 'package.json'));
186
- const packageName = packageOptions.name;
187
- const packageVersion = packageOptions.version;
188
- const packageFolderNames = !isMonorepo ? [] : fs
189
- .readdirSync(packageDir)
190
- .reduce((pre, file) => {
191
- const fullpath = path.resolve(packageDir, file);
192
- const stat = fs.statSync(fullpath);
193
- if (!(/(^_|tpl)/.test(file))
194
- && stat.isDirectory()) {
195
- pre.push(file);
196
- }
197
- return pre;
198
- }, []);
199
- const packageOptionsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
200
- pre[packageFolderName$] = require$(path.resolve(packageDir, packageFolderName$, 'package.json'));
201
- return pre;
202
- }, {});
203
- const packageDirsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
204
- pre[packageFolderName$] = path.resolve(packageDir, packageFolderName$);
205
- return pre;
206
- }, {});
207
- const packageRelation = packageFolderNames.reduce((pre, packageFolderName$) => {
208
- let packagesOptions = packageOptionsMap[packageFolderName$];
209
- let deps = {
210
- ...(packagesOptions.dependencies || {}),
211
- ...(packagesOptions.devDependencies || {}),
212
- };
213
- pre[packagesOptions.name] = Object.keys(deps).filter(i => new RegExp(`${packageName}`).test(i));
214
- return pre;
215
- }, {});
216
- const normalizePackageNames = getNormalizePackage(packageRelation);
217
- const normalizePackageFolderNames = normalizePackageNames
218
- .map(i => i.replace(new RegExp(`${packageName}-?`), '') || packageFolderName);
219
- const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || '';
220
- const config = {
221
- cwd,
222
- workspace,
223
- homepage: homepage.replace(/(.*)(https?:\/\/.*)(#|\.git)/, '$2'),
224
- packageFolderName,
225
- packageDir,
226
- packageOptions,
227
- packageName,
228
- packageVersion,
229
- packageFolderNames,
230
- packageOptionsMap,
231
- packageDirsMap,
232
- packageRelation,
233
- normalizePackageNames,
234
- normalizePackageFolderNames
170
+ cwd = cwd || cwd$;
171
+ if (configMap[cwd])
172
+ return configMap[cwd];
173
+ const rootPackageOptions = require$(`${cwd}/package.json`);
174
+ let workspace = "packages";
175
+ let isMonorepo = fs.existsSync(path.resolve(cwd, workspace));
176
+ workspace = isMonorepo ? workspace : "";
177
+ const packageFolderName = isMonorepo ? "index" : "";
178
+ const packageDir = path.resolve(cwd, workspace);
179
+ const packageOptions = require$(path.resolve(packageDir, packageFolderName, "package.json"));
180
+ const packageName = packageOptions.name;
181
+ const packageVersion = packageOptions.version;
182
+ const packageFolderNames = !isMonorepo ? [] : fs.readdirSync(packageDir).reduce((pre, file) => {
183
+ const fullpath = path.resolve(packageDir, file);
184
+ const stat = fs.statSync(fullpath);
185
+ if (!/(^_|tpl)/.test(file) && stat.isDirectory()) {
186
+ pre.push(file);
187
+ }
188
+ return pre;
189
+ }, []);
190
+ const packageOptionsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
191
+ pre[packageFolderName$] = require$(path.resolve(packageDir, packageFolderName$, "package.json"));
192
+ return pre;
193
+ }, {});
194
+ const packageDirsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
195
+ pre[packageFolderName$] = path.resolve(packageDir, packageFolderName$);
196
+ return pre;
197
+ }, {});
198
+ const packageRelation = packageFolderNames.reduce((pre, packageFolderName$) => {
199
+ let packagesOptions = packageOptionsMap[packageFolderName$];
200
+ let deps = {
201
+ ...packagesOptions.dependencies || {},
202
+ ...packagesOptions.devDependencies || {}
235
203
  };
236
- configMap[cwd] = config;
237
- return config;
204
+ pre[packagesOptions.name] = Object.keys(deps).filter((i) => new RegExp(`${packageName}`).test(i));
205
+ return pre;
206
+ }, {});
207
+ const normalizePackageNames = getNormalizePackage(packageRelation);
208
+ const normalizePackageFolderNames = normalizePackageNames.map((i) => i.replace(new RegExp(`${packageName}-?`), "") || packageFolderName);
209
+ const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || "";
210
+ const config = {
211
+ cwd,
212
+ workspace,
213
+ homepage: homepage.replace(/(.*)(https?:\/\/.*)(#|\.git)/, "$2"),
214
+ packageFolderName,
215
+ packageDir,
216
+ packageOptions,
217
+ packageName,
218
+ packageVersion,
219
+ packageFolderNames,
220
+ packageOptionsMap,
221
+ packageDirsMap,
222
+ packageRelation,
223
+ normalizePackageNames,
224
+ normalizePackageFolderNames
225
+ };
226
+ configMap[cwd] = config;
227
+ return config;
238
228
  };
239
229
 
240
- var locals = /*#__PURE__*/Object.freeze({
241
- __proto__: null,
242
- getNormalizePackage: getNormalizePackage,
243
- getPackageFolderName: getPackageFolderName,
244
- getPackageName: getPackageName,
245
- impl: impl
246
- });
230
+ const locals = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
231
+ __proto__: null,
232
+ getNormalizePackage,
233
+ getPackageFolderName,
234
+ getPackageName,
235
+ impl
236
+ }, Symbol.toStringTag, { value: 'Module' }));
247
237
 
248
238
  export { locals as Locals, logger as Logger, shell as Shell, utils as Utils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-shared",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.es.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",