ee-core 2.1.0 → 2.1.1-beta.2

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.
@@ -1,77 +1,77 @@
1
- /*!
2
- * depd
3
- * Copyright(c) 2015 Douglas Christopher Wilson
4
- * MIT Licensed
5
- */
6
-
7
- 'use strict'
8
-
9
- /**
10
- * Module exports.
11
- * @public
12
- */
13
-
14
- module.exports = depd
15
-
16
- /**
17
- * Create deprecate for namespace in caller.
18
- */
19
-
20
- function depd (namespace) {
21
- if (!namespace) {
22
- throw new TypeError('argument namespace is required')
23
- }
24
-
25
- function deprecate (message) {
26
- // no-op in browser
27
- }
28
-
29
- deprecate._file = undefined
30
- deprecate._ignored = true
31
- deprecate._namespace = namespace
32
- deprecate._traced = false
33
- deprecate._warned = Object.create(null)
34
-
35
- deprecate.function = wrapfunction
36
- deprecate.property = wrapproperty
37
-
38
- return deprecate
39
- }
40
-
41
- /**
42
- * Return a wrapped function in a deprecation message.
43
- *
44
- * This is a no-op version of the wrapper, which does nothing but call
45
- * validation.
46
- */
47
-
48
- function wrapfunction (fn, message) {
49
- if (typeof fn !== 'function') {
50
- throw new TypeError('argument fn must be a function')
51
- }
52
-
53
- return fn
54
- }
55
-
56
- /**
57
- * Wrap property in a deprecation message.
58
- *
59
- * This is a no-op version of the wrapper, which does nothing but call
60
- * validation.
61
- */
62
-
63
- function wrapproperty (obj, prop, message) {
64
- if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
65
- throw new TypeError('argument obj must be object')
66
- }
67
-
68
- var descriptor = Object.getOwnPropertyDescriptor(obj, prop)
69
-
70
- if (!descriptor) {
71
- throw new TypeError('must call property on owner object')
72
- }
73
-
74
- if (!descriptor.configurable) {
75
- throw new TypeError('property must be configurable')
76
- }
77
- }
1
+ /*!
2
+ * depd
3
+ * Copyright(c) 2015 Douglas Christopher Wilson
4
+ * MIT Licensed
5
+ */
6
+
7
+ 'use strict'
8
+
9
+ /**
10
+ * Module exports.
11
+ * @public
12
+ */
13
+
14
+ module.exports = depd
15
+
16
+ /**
17
+ * Create deprecate for namespace in caller.
18
+ */
19
+
20
+ function depd (namespace) {
21
+ if (!namespace) {
22
+ throw new TypeError('argument namespace is required')
23
+ }
24
+
25
+ function deprecate (message) {
26
+ // no-op in browser
27
+ }
28
+
29
+ deprecate._file = undefined
30
+ deprecate._ignored = true
31
+ deprecate._namespace = namespace
32
+ deprecate._traced = false
33
+ deprecate._warned = Object.create(null)
34
+
35
+ deprecate.function = wrapfunction
36
+ deprecate.property = wrapproperty
37
+
38
+ return deprecate
39
+ }
40
+
41
+ /**
42
+ * Return a wrapped function in a deprecation message.
43
+ *
44
+ * This is a no-op version of the wrapper, which does nothing but call
45
+ * validation.
46
+ */
47
+
48
+ function wrapfunction (fn, message) {
49
+ if (typeof fn !== 'function') {
50
+ throw new TypeError('argument fn must be a function')
51
+ }
52
+
53
+ return fn
54
+ }
55
+
56
+ /**
57
+ * Wrap property in a deprecation message.
58
+ *
59
+ * This is a no-op version of the wrapper, which does nothing but call
60
+ * validation.
61
+ */
62
+
63
+ function wrapproperty (obj, prop, message) {
64
+ if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
65
+ throw new TypeError('argument obj must be object')
66
+ }
67
+
68
+ var descriptor = Object.getOwnPropertyDescriptor(obj, prop)
69
+
70
+ if (!descriptor) {
71
+ throw new TypeError('must call property on owner object')
72
+ }
73
+
74
+ if (!descriptor.configurable) {
75
+ throw new TypeError('property must be configurable')
76
+ }
77
+ }
@@ -1,64 +1,64 @@
1
- /// <reference types="node"/>
2
- import {ListenOptions} from 'net';
3
-
4
- declare namespace getPort {
5
- interface Options extends Omit<ListenOptions, 'port'> {
6
- /**
7
- A preferred port or an iterable of preferred ports to use.
8
- */
9
- readonly port?: number | Iterable<number>;
10
-
11
- /**
12
- The host on which port resolution should be performed. Can be either an IPv4 or IPv6 address.
13
- */
14
- readonly host?: string;
15
- }
16
- }
17
-
18
- declare const getPort: {
19
- /**
20
- Get an available TCP port number.
21
-
22
- @returns Port number.
23
-
24
- @example
25
- ```
26
- import getPort = require('get-port');
27
-
28
- (async () => {
29
- console.log(await getPort());
30
- //=> 51402
31
-
32
- // Pass in a preferred port
33
- console.log(await getPort({port: 3000}));
34
- // Will use 3000 if available, otherwise fall back to a random port
35
-
36
- // Pass in an array of preferred ports
37
- console.log(await getPort({port: [3000, 3001, 3002]}));
38
- // Will use any element in the preferred ports array if available, otherwise fall back to a random port
39
- })();
40
- ```
41
- */
42
- (options?: getPort.Options): Promise<number>;
43
-
44
- /**
45
- Make a range of ports `from`...`to`.
46
-
47
- @param from - First port of the range. Must be in the range `1024`...`65535`.
48
- @param to - Last port of the range. Must be in the range `1024`...`65535` and must be greater than `from`.
49
- @returns The ports in the range.
50
-
51
- @example
52
- ```
53
- import getPort = require('get-port');
54
-
55
- (async () => {
56
- console.log(await getPort({port: getPort.makeRange(3000, 3100)}));
57
- // Will use any port from 3000 to 3100, otherwise fall back to a random port
58
- })();
59
- ```
60
- */
61
- makeRange(from: number, to: number): Iterable<number>;
62
- };
63
-
64
- export = getPort;
1
+ /// <reference types="node"/>
2
+ import {ListenOptions} from 'net';
3
+
4
+ declare namespace getPort {
5
+ interface Options extends Omit<ListenOptions, 'port'> {
6
+ /**
7
+ A preferred port or an iterable of preferred ports to use.
8
+ */
9
+ readonly port?: number | Iterable<number>;
10
+
11
+ /**
12
+ The host on which port resolution should be performed. Can be either an IPv4 or IPv6 address.
13
+ */
14
+ readonly host?: string;
15
+ }
16
+ }
17
+
18
+ declare const getPort: {
19
+ /**
20
+ Get an available TCP port number.
21
+
22
+ @returns Port number.
23
+
24
+ @example
25
+ ```
26
+ import getPort = require('get-port');
27
+
28
+ (async () => {
29
+ console.log(await getPort());
30
+ //=> 51402
31
+
32
+ // Pass in a preferred port
33
+ console.log(await getPort({port: 3000}));
34
+ // Will use 3000 if available, otherwise fall back to a random port
35
+
36
+ // Pass in an array of preferred ports
37
+ console.log(await getPort({port: [3000, 3001, 3002]}));
38
+ // Will use any element in the preferred ports array if available, otherwise fall back to a random port
39
+ })();
40
+ ```
41
+ */
42
+ (options?: getPort.Options): Promise<number>;
43
+
44
+ /**
45
+ Make a range of ports `from`...`to`.
46
+
47
+ @param from - First port of the range. Must be in the range `1024`...`65535`.
48
+ @param to - Last port of the range. Must be in the range `1024`...`65535` and must be greater than `from`.
49
+ @returns The ports in the range.
50
+
51
+ @example
52
+ ```
53
+ import getPort = require('get-port');
54
+
55
+ (async () => {
56
+ console.log(await getPort({port: getPort.makeRange(3000, 3100)}));
57
+ // Will use any port from 3000 to 3100, otherwise fall back to a random port
58
+ })();
59
+ ```
60
+ */
61
+ makeRange(from: number, to: number): Iterable<number>;
62
+ };
63
+
64
+ export = getPort;
@@ -1,109 +1,109 @@
1
- 'use strict';
2
- const net = require('net');
3
-
4
- class Locked extends Error {
5
- constructor(port) {
6
- super(`${port} is locked`);
7
- }
8
- }
9
-
10
- const lockedPorts = {
11
- old: new Set(),
12
- young: new Set()
13
- };
14
-
15
- // On this interval, the old locked ports are discarded,
16
- // the young locked ports are moved to old locked ports,
17
- // and a new young set for locked ports are created.
18
- const releaseOldLockedPortsIntervalMs = 1000 * 15;
19
-
20
- // Lazily create interval on first use
21
- let interval;
22
-
23
- const getAvailablePort = options => new Promise((resolve, reject) => {
24
- const server = net.createServer();
25
- server.unref();
26
- server.on('error', reject);
27
- server.listen(options, () => {
28
- const {port} = server.address();
29
- server.close(() => {
30
- resolve(port);
31
- });
32
- });
33
- });
34
-
35
- const portCheckSequence = function * (ports) {
36
- if (ports) {
37
- yield * ports;
38
- }
39
-
40
- yield 0; // Fall back to 0 if anything else failed
41
- };
42
-
43
- module.exports = async options => {
44
- let ports;
45
-
46
- if (options) {
47
- ports = typeof options.port === 'number' ? [options.port] : options.port;
48
- }
49
-
50
- if (interval === undefined) {
51
- interval = setInterval(() => {
52
- lockedPorts.old = lockedPorts.young;
53
- lockedPorts.young = new Set();
54
- }, releaseOldLockedPortsIntervalMs);
55
-
56
- // Does not exist in some environments (Electron, Jest jsdom env, browser, etc).
57
- if (interval.unref) {
58
- interval.unref();
59
- }
60
- }
61
-
62
- for (const port of portCheckSequence(ports)) {
63
- try {
64
- let availablePort = await getAvailablePort({...options, port}); // eslint-disable-line no-await-in-loop
65
- while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
66
- if (port !== 0) {
67
- throw new Locked(port);
68
- }
69
-
70
- availablePort = await getAvailablePort({...options, port}); // eslint-disable-line no-await-in-loop
71
- }
72
-
73
- lockedPorts.young.add(availablePort);
74
- return availablePort;
75
- } catch (error) {
76
- if (!['EADDRINUSE', 'EACCES'].includes(error.code) && !(error instanceof Locked)) {
77
- throw error;
78
- }
79
- }
80
- }
81
-
82
- throw new Error('No available ports found');
83
- };
84
-
85
- module.exports.makeRange = (from, to) => {
86
- if (!Number.isInteger(from) || !Number.isInteger(to)) {
87
- throw new TypeError('`from` and `to` must be integer numbers');
88
- }
89
-
90
- if (from < 1024 || from > 65535) {
91
- throw new RangeError('`from` must be between 1024 and 65535');
92
- }
93
-
94
- if (to < 1024 || to > 65536) {
95
- throw new RangeError('`to` must be between 1024 and 65536');
96
- }
97
-
98
- if (to < from) {
99
- throw new RangeError('`to` must be greater than or equal to `from`');
100
- }
101
-
102
- const generator = function * (from, to) {
103
- for (let port = from; port <= to; port++) {
104
- yield port;
105
- }
106
- };
107
-
108
- return generator(from, to);
109
- };
1
+ 'use strict';
2
+ const net = require('net');
3
+
4
+ class Locked extends Error {
5
+ constructor(port) {
6
+ super(`${port} is locked`);
7
+ }
8
+ }
9
+
10
+ const lockedPorts = {
11
+ old: new Set(),
12
+ young: new Set()
13
+ };
14
+
15
+ // On this interval, the old locked ports are discarded,
16
+ // the young locked ports are moved to old locked ports,
17
+ // and a new young set for locked ports are created.
18
+ const releaseOldLockedPortsIntervalMs = 1000 * 15;
19
+
20
+ // Lazily create interval on first use
21
+ let interval;
22
+
23
+ const getAvailablePort = options => new Promise((resolve, reject) => {
24
+ const server = net.createServer();
25
+ server.unref();
26
+ server.on('error', reject);
27
+ server.listen(options, () => {
28
+ const {port} = server.address();
29
+ server.close(() => {
30
+ resolve(port);
31
+ });
32
+ });
33
+ });
34
+
35
+ const portCheckSequence = function * (ports) {
36
+ if (ports) {
37
+ yield * ports;
38
+ }
39
+
40
+ yield 0; // Fall back to 0 if anything else failed
41
+ };
42
+
43
+ module.exports = async options => {
44
+ let ports;
45
+
46
+ if (options) {
47
+ ports = typeof options.port === 'number' ? [options.port] : options.port;
48
+ }
49
+
50
+ if (interval === undefined) {
51
+ interval = setInterval(() => {
52
+ lockedPorts.old = lockedPorts.young;
53
+ lockedPorts.young = new Set();
54
+ }, releaseOldLockedPortsIntervalMs);
55
+
56
+ // Does not exist in some environments (Electron, Jest jsdom env, browser, etc).
57
+ if (interval.unref) {
58
+ interval.unref();
59
+ }
60
+ }
61
+
62
+ for (const port of portCheckSequence(ports)) {
63
+ try {
64
+ let availablePort = await getAvailablePort({...options, port}); // eslint-disable-line no-await-in-loop
65
+ while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
66
+ if (port !== 0) {
67
+ throw new Locked(port);
68
+ }
69
+
70
+ availablePort = await getAvailablePort({...options, port}); // eslint-disable-line no-await-in-loop
71
+ }
72
+
73
+ lockedPorts.young.add(availablePort);
74
+ return availablePort;
75
+ } catch (error) {
76
+ if (!['EADDRINUSE', 'EACCES'].includes(error.code) && !(error instanceof Locked)) {
77
+ throw error;
78
+ }
79
+ }
80
+ }
81
+
82
+ throw new Error('No available ports found');
83
+ };
84
+
85
+ module.exports.makeRange = (from, to) => {
86
+ if (!Number.isInteger(from) || !Number.isInteger(to)) {
87
+ throw new TypeError('`from` and `to` must be integer numbers');
88
+ }
89
+
90
+ if (from < 1024 || from > 65535) {
91
+ throw new RangeError('`from` must be between 1024 and 65535');
92
+ }
93
+
94
+ if (to < 1024 || to > 65536) {
95
+ throw new RangeError('`to` must be between 1024 and 65536');
96
+ }
97
+
98
+ if (to < from) {
99
+ throw new RangeError('`to` must be greater than or equal to `from`');
100
+ }
101
+
102
+ const generator = function * (from, to) {
103
+ for (let port = from; port <= to; port++) {
104
+ yield port;
105
+ }
106
+ };
107
+
108
+ return generator(from, to);
109
+ };
package/utils/index.js CHANGED
@@ -3,9 +3,26 @@
3
3
  const os = require("os");
4
4
  const path = require('path');
5
5
  const fs = require('fs');
6
+ const { exec, execSync } = require('child_process');
7
+ const { createHash } = require('crypto');
6
8
  const Ps = require('../ps');
7
9
  const UtilsJson = require('./json');
8
10
 
11
+ // machine id
12
+ const { platform } = process;
13
+ const win32RegBinPath = {
14
+ native: '%windir%\\System32',
15
+ mixed: '%windir%\\sysnative\\cmd.exe /c %windir%\\System32'
16
+ };
17
+ const MachineGuid = {
18
+ darwin: 'ioreg -rd1 -c IOPlatformExpertDevice',
19
+ win32: `${win32RegBinPath[isWindowsProcessMixedOrNativeArchitecture()]}\\REG.exe ` +
20
+ 'QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography ' +
21
+ '/v MachineGuid',
22
+ linux: '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :',
23
+ freebsd: 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid'
24
+ };
25
+
9
26
  /**
10
27
  * 获取项目根目录package.json
11
28
  */
@@ -69,4 +86,75 @@ exports.isEncrypt = function(basePath) {
69
86
  return false;
70
87
  }
71
88
 
89
+ /**
90
+ * get machine id
91
+ */
92
+ exports.machineIdSync = function(original) {
93
+ let id = expose(execSync(MachineGuid[platform]).toString());
94
+ return original ? id : hash(id);
95
+ }
96
+
97
+ /**
98
+ * get machine id (promise)
99
+ * original <Boolean>, If true return original value of machine id, otherwise return hashed value (sha-256), default: false
100
+ */
101
+ exports.machineId = function(original) {
102
+ return new Promise((resolve, reject) => {
103
+ return exec(MachineGuid[platform], {}, (err, stdout, stderr) => {
104
+ if (err) {
105
+ return reject(
106
+ new Error(`Error while obtaining machine id: ${err.stack}`)
107
+ );
108
+ }
109
+ let id = expose(stdout.toString());
110
+ return resolve(original ? id : hash(id));
111
+ });
112
+ });
113
+ }
114
+
115
+ function isWindowsProcessMixedOrNativeArchitecture() {
116
+ // detect if the node binary is the same arch as the Windows OS.
117
+ // or if this is 32 bit node on 64 bit windows.
118
+ if(process.platform !== 'win32') {
119
+ return '';
120
+ }
121
+ if( process.arch === 'ia32' && process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432') ) {
122
+ return 'mixed';
123
+ }
124
+ return 'native';
125
+ }
126
+
127
+ function hash(guid) {
128
+ return createHash('sha256').update(guid).digest('hex');
129
+ }
130
+
131
+ function expose(result) {
132
+ switch (platform) {
133
+ case 'darwin':
134
+ return result
135
+ .split('IOPlatformUUID')[1]
136
+ .split('\n')[0].replace(/\=|\s+|\"/ig, '')
137
+ .toLowerCase();
138
+ case 'win32':
139
+ return result
140
+ .toString()
141
+ .split('REG_SZ')[1]
142
+ .replace(/\r+|\n+|\s+/ig, '')
143
+ .toLowerCase();
144
+ case 'linux':
145
+ return result
146
+ .toString()
147
+ .replace(/\r+|\n+|\s+/ig, '')
148
+ .toLowerCase();
149
+ case 'freebsd':
150
+ return result
151
+ .toString()
152
+ .replace(/\r+|\n+|\s+/ig, '')
153
+ .toLowerCase();
154
+ default:
155
+ throw new Error(`Unsupported platform: ${process.platform}`);
156
+ }
157
+ }
158
+
159
+
72
160