@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 +216 -224
- package/dist/index.es.js +190 -200
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,273 +1,265 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
44
|
+
}
|
|
45
|
+
return ips[0];
|
|
44
46
|
};
|
|
45
47
|
const formatBytes = (size, suffix = 2) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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(),
|
|
87
|
-
const LOCAL_COMMAND_MAP = fs__namespace.existsSync(binDirectory)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
101
|
-
|
|
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
|
-
|
|
101
|
+
return util__namespace.promisify(childProcess__namespace.exec)(command(command$, args).join(SPACE));
|
|
106
102
|
};
|
|
107
103
|
const spawn = (command$, args, options) => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
175
|
+
}
|
|
176
|
+
return result.reverse();
|
|
178
177
|
};
|
|
179
178
|
const getPackageName = (packageFolderName$) => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
261
|
-
return
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
18
|
+
}
|
|
19
|
+
return ips[0];
|
|
20
20
|
};
|
|
21
21
|
const formatBytes = (size, suffix = 2) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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(),
|
|
63
|
-
const LOCAL_COMMAND_MAP = fs.existsSync(binDirectory)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
75
|
+
return util.promisify(childProcess.exec)(command(command$, args).join(SPACE));
|
|
82
76
|
};
|
|
83
77
|
const spawn = (command$, args, options) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
149
|
+
}
|
|
150
|
+
return result.reverse();
|
|
154
151
|
};
|
|
155
152
|
const getPackageName = (packageFolderName$) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
237
|
-
return
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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 };
|