@layerzerolabs/lz-utilities 2.0.6 → 2.0.8
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 +70 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +31 -5
- package/dist/index.d.ts +31 -5
- package/dist/index.mjs +68 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -7
- package/dist/account.d.ts +0 -12
- package/dist/account.js +0 -119
- package/dist/account.test.d.ts +0 -1
- package/dist/account.test.js +0 -102
- package/dist/deployment.d.ts +0 -17
- package/dist/deployment.js +0 -2
- package/dist/index.js +0 -231
- package/dist/logger.d.ts +0 -8
- package/dist/logger.js +0 -134
- package/dist/logger.test.d.ts +0 -1
- package/dist/logger.test.js +0 -55
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/account.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
exports.__esModule = true;
|
|
26
|
-
exports.getKeypairFromMnemonic = exports.getSolanaAccountFromMnemonic = exports.getAptosAccountFromMnemonic = exports.getEvmAccountFromMnemonic = exports.getBIP044Path = void 0;
|
|
27
|
-
var utils_1 = require("@noble/hashes/utils");
|
|
28
|
-
var web3_js_1 = require("@solana/web3.js");
|
|
29
|
-
var aptos = __importStar(require("aptos"));
|
|
30
|
-
var bip39 = __importStar(require("bip39"));
|
|
31
|
-
var ed25519HdKey = __importStar(require("ed25519-hd-key"));
|
|
32
|
-
var ethers_1 = require("ethers");
|
|
33
|
-
var lz_definitions_1 = require("@layerzerolabs/lz-definitions");
|
|
34
|
-
function getBIP044Path(chainType, account, change, index) {
|
|
35
|
-
// CAUTION: the path format is different for each chain
|
|
36
|
-
// https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
|
|
37
|
-
//
|
|
38
|
-
// The "m/44'/637'/0'/0'/0'" path is known as a hardened derivation path, while the "m/44'/637'/0'/0/0" path is a non-hardened derivation path.
|
|
39
|
-
// The technical benefit of using a hardened derivation path is enhanced security.
|
|
40
|
-
// In BIP32, a hardened derivation is denoted by an apostrophe ('), which indicates that the child private key should be derived in a way
|
|
41
|
-
// that makes it computationally infeasible to derive the parent private key from it. This additional level of security
|
|
42
|
-
// protects the mnemonic phrase and its derived private keys even if one of the derived private keys is compromised.
|
|
43
|
-
// By using a hardened derivation path, like "m/44'/637'/0'/0'/0'", each level of the path requires a unique private key derivation,
|
|
44
|
-
// making it more difficult to infer the parent private key from the child private key. This is particularly important when dealing with
|
|
45
|
-
// hierarchical deterministic wallets, as it helps protect funds across multiple accounts or purposes.
|
|
46
|
-
switch (chainType) {
|
|
47
|
-
case lz_definitions_1.ChainType.EVM:
|
|
48
|
-
// https://github.com/ethers-io/ethers.js/blob/main/src.ts/wallet/hdwallet.ts
|
|
49
|
-
return "m/44'/60'/".concat(account, "'/").concat(change, "/").concat(index);
|
|
50
|
-
case lz_definitions_1.ChainType.APTOS:
|
|
51
|
-
// https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/aptos_account.ts
|
|
52
|
-
return "m/44'/637'/".concat(account, "'/").concat(change, "'/").concat(index, "'");
|
|
53
|
-
case lz_definitions_1.ChainType.SOLANA:
|
|
54
|
-
// https://github.com/solana-labs/solana/blob/master/sdk/src/derivation_path.rs
|
|
55
|
-
return "m/44'/501'/".concat(account, "'/").concat(change, "'");
|
|
56
|
-
default:
|
|
57
|
-
throw new Error("Unsupported chain: ".concat(chainType));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.getBIP044Path = getBIP044Path;
|
|
61
|
-
function getEvmAccountFromMnemonic(mnemonic, path) {
|
|
62
|
-
if (path === void 0) { path = "m/44'/60'/0'/0/0"; }
|
|
63
|
-
var wallet = ethers_1.ethers.Wallet.fromMnemonic(mnemonic, path);
|
|
64
|
-
return {
|
|
65
|
-
mnemonic: mnemonic,
|
|
66
|
-
path: path,
|
|
67
|
-
privateKey: wallet.privateKey,
|
|
68
|
-
address: wallet.address
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
exports.getEvmAccountFromMnemonic = getEvmAccountFromMnemonic;
|
|
72
|
-
function getAptosAccountFromMnemonic(mnemonic, path) {
|
|
73
|
-
if (path === void 0) { path = "m/44'/637'/0'/0'/0'"; }
|
|
74
|
-
//https://aptos.dev/guides/building-your-own-wallet/#creating-an-aptos-account
|
|
75
|
-
if (!aptos.AptosAccount.isValidPath(path)) {
|
|
76
|
-
throw new Error("Invalid derivation path: ".concat(path));
|
|
77
|
-
}
|
|
78
|
-
var normalizeMnemonics = mnemonic
|
|
79
|
-
.trim()
|
|
80
|
-
.split(/\s+/)
|
|
81
|
-
.map(function (part) { return part.toLowerCase(); })
|
|
82
|
-
.join(' ');
|
|
83
|
-
{
|
|
84
|
-
var key = aptos.derivePath(path, (0, utils_1.bytesToHex)(bip39.mnemonicToSeedSync(normalizeMnemonics))).key;
|
|
85
|
-
var account = new aptos.AptosAccount(new Uint8Array(key)).toPrivateKeyObject();
|
|
86
|
-
return {
|
|
87
|
-
mnemonic: mnemonic,
|
|
88
|
-
path: path,
|
|
89
|
-
privateKey: account.privateKeyHex,
|
|
90
|
-
address: account.address
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.getAptosAccountFromMnemonic = getAptosAccountFromMnemonic;
|
|
95
|
-
function getSolanaAccountFromMnemonic(mnemonic, path) {
|
|
96
|
-
if (path === void 0) { path = "m/44'/501'/0'/0'"; }
|
|
97
|
-
var seed = bip39.mnemonicToSeedSync(mnemonic, ''); // (mnemonic, password)
|
|
98
|
-
var keyPair = web3_js_1.Keypair.fromSeed(ed25519HdKey.derivePath(path, seed.toString('hex')).key);
|
|
99
|
-
return {
|
|
100
|
-
mnemonic: mnemonic,
|
|
101
|
-
path: path,
|
|
102
|
-
privateKey: ethers_1.ethers.utils.hexlify(keyPair.secretKey),
|
|
103
|
-
address: keyPair.publicKey.toBase58()
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
exports.getSolanaAccountFromMnemonic = getSolanaAccountFromMnemonic;
|
|
107
|
-
function getKeypairFromMnemonic(chainType, mnemonic, path) {
|
|
108
|
-
switch (chainType) {
|
|
109
|
-
case lz_definitions_1.ChainType.EVM:
|
|
110
|
-
return getEvmAccountFromMnemonic(mnemonic, path);
|
|
111
|
-
case lz_definitions_1.ChainType.APTOS:
|
|
112
|
-
return getAptosAccountFromMnemonic(mnemonic, path);
|
|
113
|
-
case lz_definitions_1.ChainType.SOLANA:
|
|
114
|
-
return getSolanaAccountFromMnemonic(mnemonic, path);
|
|
115
|
-
default:
|
|
116
|
-
throw new Error("Unsupported chain: ".concat(chainType));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.getKeypairFromMnemonic = getKeypairFromMnemonic;
|
package/dist/account.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/account.test.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
var globals_1 = require("@jest/globals");
|
|
4
|
-
var lz_definitions_1 = require("@layerzerolabs/lz-definitions");
|
|
5
|
-
var account_1 = require("./account");
|
|
6
|
-
(0, globals_1.describe)('utils', function () {
|
|
7
|
-
(0, globals_1.describe)('getEvmAccountFromMnemonic', function () {
|
|
8
|
-
// https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/aptos_account.test.ts
|
|
9
|
-
globals_1.test.each([
|
|
10
|
-
// mnemonic, privateKey, address
|
|
11
|
-
[
|
|
12
|
-
'law profit arrive pass movie swim ankle entry extra number clown reveal crane way junior',
|
|
13
|
-
'0x76d9ed877b92368969f6f7a344d3797c2b2310a9a0b1fb0df497b7eee84159cc',
|
|
14
|
-
'0xCe3AE1AFE15a75B89ce4E6F043A84Dd245f0362A',
|
|
15
|
-
],
|
|
16
|
-
])('', function (mnemonic, privateKey, address) {
|
|
17
|
-
var _path = (0, account_1.getBIP044Path)(lz_definitions_1.ChainType.EVM, 0, 0, 0);
|
|
18
|
-
var keypair1 = (0, account_1.getEvmAccountFromMnemonic)(mnemonic);
|
|
19
|
-
var keypair2 = (0, account_1.getEvmAccountFromMnemonic)(mnemonic, _path);
|
|
20
|
-
(0, globals_1.expect)(keypair1).toEqual(keypair2);
|
|
21
|
-
(0, globals_1.expect)(keypair1.privateKey).toEqual(privateKey);
|
|
22
|
-
(0, globals_1.expect)(keypair1.address).toEqual(address);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
(0, globals_1.describe)('getAptosAccountFromMnemonic', function () {
|
|
26
|
-
// https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/aptos_account.test.ts
|
|
27
|
-
globals_1.test.each([
|
|
28
|
-
// mnemonic, privateKey, address
|
|
29
|
-
[
|
|
30
|
-
'shoot island position soft burden budget tooth cruel issue economy destroy above',
|
|
31
|
-
'0x5d996aa76b3212142792d9130796cd2e11e3c445a93118c08414df4f66bc60ec',
|
|
32
|
-
'0x07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f30',
|
|
33
|
-
],
|
|
34
|
-
])('', function (mnemonic, privateKey, address) {
|
|
35
|
-
var _path = (0, account_1.getBIP044Path)(lz_definitions_1.ChainType.APTOS, 0, 0, 0);
|
|
36
|
-
var keypair1 = (0, account_1.getAptosAccountFromMnemonic)(mnemonic);
|
|
37
|
-
var keypair2 = (0, account_1.getAptosAccountFromMnemonic)(mnemonic, _path);
|
|
38
|
-
(0, globals_1.expect)(keypair1).toEqual(keypair2);
|
|
39
|
-
(0, globals_1.expect)(keypair1.privateKey).toEqual(privateKey);
|
|
40
|
-
(0, globals_1.expect)(keypair1.address).toEqual(address);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
(0, globals_1.describe)('getSolanaAccountFromMnemonic', function () {
|
|
44
|
-
// https://solanacookbook.com/references/keypairs-and-wallets.html#how-to-restore-a-keypair-from-a-mnemonic-phrase
|
|
45
|
-
globals_1.test.each([
|
|
46
|
-
// mnemonic, privateKey, address
|
|
47
|
-
[
|
|
48
|
-
'neither lonely flavor argue grass remind eye tag avocado spot unusual intact',
|
|
49
|
-
'0x95756468025e5f69cf191815b443d5aedf7f6d613ef729b3e2a3031fd7aa4f31492e7fa00d302220c584be142f776d1a59317ab2b6f04c9f02bc3f7e931da253',
|
|
50
|
-
'5vftMkHL72JaJG6ExQfGAsT2uGVHpRR7oTNUPMs68Y2N',
|
|
51
|
-
],
|
|
52
|
-
])('', function (mnemonic, privateKey, address) {
|
|
53
|
-
var _path = (0, account_1.getBIP044Path)(lz_definitions_1.ChainType.SOLANA, 0, 0, 0);
|
|
54
|
-
var keypair1 = (0, account_1.getSolanaAccountFromMnemonic)(mnemonic);
|
|
55
|
-
var keypair2 = (0, account_1.getSolanaAccountFromMnemonic)(mnemonic, _path);
|
|
56
|
-
(0, globals_1.expect)(keypair1).toEqual(keypair2);
|
|
57
|
-
(0, globals_1.expect)(keypair1.privateKey).toEqual(privateKey);
|
|
58
|
-
(0, globals_1.expect)(keypair1.address).toEqual(address);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
(0, globals_1.describe)('getKeypairFromMnemonic', function () {
|
|
62
|
-
globals_1.test.each([
|
|
63
|
-
// mnemonic, chainType, account, change, index, path, privateKey, address
|
|
64
|
-
[
|
|
65
|
-
'law profit arrive pass movie swim ankle entry extra number clown reveal crane way junior',
|
|
66
|
-
lz_definitions_1.ChainType.EVM,
|
|
67
|
-
0,
|
|
68
|
-
0,
|
|
69
|
-
0,
|
|
70
|
-
"m/44'/60'/0'/0/0",
|
|
71
|
-
'0x76d9ed877b92368969f6f7a344d3797c2b2310a9a0b1fb0df497b7eee84159cc',
|
|
72
|
-
'0xCe3AE1AFE15a75B89ce4E6F043A84Dd245f0362A',
|
|
73
|
-
],
|
|
74
|
-
[
|
|
75
|
-
'shoot island position soft burden budget tooth cruel issue economy destroy above',
|
|
76
|
-
lz_definitions_1.ChainType.APTOS,
|
|
77
|
-
0,
|
|
78
|
-
0,
|
|
79
|
-
0,
|
|
80
|
-
"m/44'/637'/0'/0'/0'",
|
|
81
|
-
'0x5d996aa76b3212142792d9130796cd2e11e3c445a93118c08414df4f66bc60ec',
|
|
82
|
-
'0x07968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f30',
|
|
83
|
-
],
|
|
84
|
-
[
|
|
85
|
-
'neither lonely flavor argue grass remind eye tag avocado spot unusual intact',
|
|
86
|
-
lz_definitions_1.ChainType.SOLANA,
|
|
87
|
-
0,
|
|
88
|
-
0,
|
|
89
|
-
0,
|
|
90
|
-
"m/44'/501'/0'/0'",
|
|
91
|
-
'0x95756468025e5f69cf191815b443d5aedf7f6d613ef729b3e2a3031fd7aa4f31492e7fa00d302220c584be142f776d1a59317ab2b6f04c9f02bc3f7e931da253',
|
|
92
|
-
'5vftMkHL72JaJG6ExQfGAsT2uGVHpRR7oTNUPMs68Y2N',
|
|
93
|
-
],
|
|
94
|
-
])('', function (mnemonic, chainType, account, change, index, path, privateKey, address) {
|
|
95
|
-
var _path = (0, account_1.getBIP044Path)(chainType, account, change, index);
|
|
96
|
-
(0, globals_1.expect)(_path).toEqual(path);
|
|
97
|
-
var keypair = (0, account_1.getKeypairFromMnemonic)(chainType, mnemonic, path);
|
|
98
|
-
(0, globals_1.expect)(keypair.privateKey).toEqual(privateKey);
|
|
99
|
-
(0, globals_1.expect)(keypair.address).toEqual(address);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
package/dist/deployment.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { EndpointVersion, Network } from '@layerzerolabs/lz-definitions';
|
|
2
|
-
export interface Deployment {
|
|
3
|
-
/** Name of the contract deployment. */
|
|
4
|
-
name: string;
|
|
5
|
-
/** Optional endpoint identifier. */
|
|
6
|
-
compatibleVersions: EndpointVersion[];
|
|
7
|
-
/** Network of deployment. */
|
|
8
|
-
network: Network;
|
|
9
|
-
/** Optional contract source. */
|
|
10
|
-
source?: string;
|
|
11
|
-
/** Address of deployed contract. */
|
|
12
|
-
address: string;
|
|
13
|
-
/** Optional contract ABI. */
|
|
14
|
-
abi?: string;
|
|
15
|
-
/** Optional contract bytecode. */
|
|
16
|
-
bytecode?: string;
|
|
17
|
-
}
|
package/dist/deployment.js
DELETED
package/dist/index.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
-
function step(op) {
|
|
30
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
-
while (_) try {
|
|
32
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
-
switch (op[0]) {
|
|
35
|
-
case 0: case 1: t = op; break;
|
|
36
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
-
default:
|
|
40
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
-
if (t[2]) _.ops.pop();
|
|
45
|
-
_.trys.pop(); continue;
|
|
46
|
-
}
|
|
47
|
-
op = body.call(thisArg, _);
|
|
48
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
53
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
54
|
-
};
|
|
55
|
-
exports.__esModule = true;
|
|
56
|
-
exports.CmdExecutor = exports.extractUrlInfo = exports.isHttpServiceReachable = exports.packageRoot = exports.getProjectRootDir = exports.getProjectPackageManager = exports.sleep = void 0;
|
|
57
|
-
var child_process_1 = require("child_process");
|
|
58
|
-
var http_1 = __importDefault(require("http"));
|
|
59
|
-
var path_1 = __importDefault(require("path"));
|
|
60
|
-
__exportStar(require("./account"), exports);
|
|
61
|
-
__exportStar(require("./logger"), exports);
|
|
62
|
-
__exportStar(require("./deployment"), exports);
|
|
63
|
-
var find_up_1 = require("find-up");
|
|
64
|
-
var tree_kill_1 = __importDefault(require("tree-kill"));
|
|
65
|
-
function sleep(timeout) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
return __generator(this, function (_a) {
|
|
68
|
-
switch (_a.label) {
|
|
69
|
-
case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, timeout); })];
|
|
70
|
-
case 1:
|
|
71
|
-
_a.sent();
|
|
72
|
-
return [2 /*return*/];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
exports.sleep = sleep;
|
|
78
|
-
function getProjectPackageManager(cwd) {
|
|
79
|
-
var yarn = (0, find_up_1.sync)('yarn.lock', { cwd: cwd });
|
|
80
|
-
if (yarn)
|
|
81
|
-
return 'yarn';
|
|
82
|
-
var npm = (0, find_up_1.sync)('package-lock.json', { cwd: cwd });
|
|
83
|
-
if (npm)
|
|
84
|
-
return 'npm';
|
|
85
|
-
// pnpm
|
|
86
|
-
var pnpm = (0, find_up_1.sync)('pnpm-lock.yaml', { cwd: cwd });
|
|
87
|
-
if (pnpm)
|
|
88
|
-
return 'pnpm';
|
|
89
|
-
throw new Error('Cannot find package.json or yarn.lock');
|
|
90
|
-
}
|
|
91
|
-
exports.getProjectPackageManager = getProjectPackageManager;
|
|
92
|
-
function getProjectRootDir(cwd) {
|
|
93
|
-
var yarn = (0, find_up_1.sync)('yarn.lock', { cwd: cwd });
|
|
94
|
-
if (yarn)
|
|
95
|
-
return path_1["default"].dirname(yarn);
|
|
96
|
-
var npm = (0, find_up_1.sync)('package-lock.json', { cwd: cwd });
|
|
97
|
-
if (npm)
|
|
98
|
-
return path_1["default"].dirname(npm);
|
|
99
|
-
var pnpm = (0, find_up_1.sync)('pnpm-lock.yaml', { cwd: cwd });
|
|
100
|
-
if (pnpm)
|
|
101
|
-
return path_1["default"].dirname(pnpm);
|
|
102
|
-
throw new Error('Cannot find yarn.lock or package-lock.json or pnpm-lock.yaml');
|
|
103
|
-
}
|
|
104
|
-
exports.getProjectRootDir = getProjectRootDir;
|
|
105
|
-
function packageRoot(packageName, resolvePackage // Nodejs.RequireResolve / require.resolve
|
|
106
|
-
) {
|
|
107
|
-
return path_1["default"].dirname(resolvePackage("".concat(packageName, "/package.json")));
|
|
108
|
-
}
|
|
109
|
-
exports.packageRoot = packageRoot;
|
|
110
|
-
function isHttpServiceReachable(host, port, timeout) {
|
|
111
|
-
return new Promise(function (resolve, reject) {
|
|
112
|
-
var options = {
|
|
113
|
-
host: host,
|
|
114
|
-
port: port,
|
|
115
|
-
timeout: timeout,
|
|
116
|
-
method: 'HEAD'
|
|
117
|
-
};
|
|
118
|
-
var request = http_1["default"].request(options, function (response) {
|
|
119
|
-
resolve(true);
|
|
120
|
-
});
|
|
121
|
-
request.on('error', function (err) {
|
|
122
|
-
resolve(false);
|
|
123
|
-
});
|
|
124
|
-
request.end();
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
exports.isHttpServiceReachable = isHttpServiceReachable;
|
|
128
|
-
function extractUrlInfo(url) {
|
|
129
|
-
//TODO: handle the default port for http and https(443, 80)
|
|
130
|
-
var m = url.match(/(?<schema>http|https):\/\/(?<host>.*):(?<port>\d+)/);
|
|
131
|
-
if (!m || !m.groups || !m.groups.host || !m.groups.schema || !m.groups.port) {
|
|
132
|
-
throw new Error("Invalid url ".concat(url));
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
schema: m.groups.schema,
|
|
136
|
-
host: m.groups.host,
|
|
137
|
-
port: m.groups.port
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
exports.extractUrlInfo = extractUrlInfo;
|
|
141
|
-
var CmdExecutor = /** @class */ (function () {
|
|
142
|
-
function CmdExecutor() {
|
|
143
|
-
this.currentProcess = null;
|
|
144
|
-
this.onFinish = null;
|
|
145
|
-
}
|
|
146
|
-
CmdExecutor.prototype.executeCmd = function (command, args, options, verbose, runningCheck, logger) {
|
|
147
|
-
var _this = this;
|
|
148
|
-
var _a, _b;
|
|
149
|
-
if (verbose === void 0) { verbose = false; }
|
|
150
|
-
if (logger) {
|
|
151
|
-
logger.info("Running command: ".concat(command, " ").concat((_a = args === null || args === void 0 ? void 0 : args.join(' ')) !== null && _a !== void 0 ? _a : ''));
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
console.log("Running command: ".concat(command, " ").concat((_b = args === null || args === void 0 ? void 0 : args.join(' ')) !== null && _b !== void 0 ? _b : ''));
|
|
155
|
-
}
|
|
156
|
-
return new Promise(function (resolve, reject) {
|
|
157
|
-
var _a, _b, _c;
|
|
158
|
-
var notified = false;
|
|
159
|
-
_this.currentProcess = (0, child_process_1.spawn)(command, args, options);
|
|
160
|
-
if (!_this.currentProcess) {
|
|
161
|
-
throw new Error("Failed to spawn command: ".concat(command, " ").concat((_a = args === null || args === void 0 ? void 0 : args.join(' ')) !== null && _a !== void 0 ? _a : ''));
|
|
162
|
-
}
|
|
163
|
-
// Listen for standard output from the child process and print it to the console
|
|
164
|
-
(_b = _this.currentProcess.stdout) === null || _b === void 0 ? void 0 : _b.on('data', function (data) {
|
|
165
|
-
if (runningCheck && !notified && data.toString().includes(runningCheck.key)) {
|
|
166
|
-
runningCheck.runningNotify(true);
|
|
167
|
-
notified = true;
|
|
168
|
-
}
|
|
169
|
-
if (verbose && logger) {
|
|
170
|
-
logger.info(data.toString());
|
|
171
|
-
}
|
|
172
|
-
else if (verbose) {
|
|
173
|
-
process.stdout.write(data);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
// Listen for errors from the child process and print them to the console
|
|
177
|
-
(_c = _this.currentProcess.stderr) === null || _c === void 0 ? void 0 : _c.on('data', function (data) {
|
|
178
|
-
if (logger) {
|
|
179
|
-
logger.error(data.toString());
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
console.error(data.toString());
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
// Listen for the exit event of the child process and resolve the promise
|
|
186
|
-
// if the child process exits normally (with code 0)
|
|
187
|
-
_this.currentProcess.on('exit', function (code) {
|
|
188
|
-
if (code && code !== 0) {
|
|
189
|
-
if (logger) {
|
|
190
|
-
logger.info("Command ".concat(command, " exited with code ").concat(code, "."));
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
console.info("Command ".concat(command, " exited with code ").concat(code, "."));
|
|
194
|
-
}
|
|
195
|
-
reject({ command: "".concat(command, " ").concat(args.join(' ')) });
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
resolve();
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
CmdExecutor.prototype.interrupt = function (killDescendents) {
|
|
203
|
-
if (killDescendents === void 0) { killDescendents = true; }
|
|
204
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
-
return __generator(this, function (_a) {
|
|
206
|
-
switch (_a.label) {
|
|
207
|
-
case 0:
|
|
208
|
-
if (!this.currentProcess) return [3 /*break*/, 4];
|
|
209
|
-
console.log('Killing process:', this.currentProcess.pid);
|
|
210
|
-
if (!killDescendents) return [3 /*break*/, 2];
|
|
211
|
-
(0, tree_kill_1["default"])(this.currentProcess.pid);
|
|
212
|
-
// the implementation of tree-kill is using spawn, which is async. So we need to wait for a while
|
|
213
|
-
return [4 /*yield*/, sleep(2000)];
|
|
214
|
-
case 1:
|
|
215
|
-
// the implementation of tree-kill is using spawn, which is async. So we need to wait for a while
|
|
216
|
-
_a.sent();
|
|
217
|
-
return [3 /*break*/, 3];
|
|
218
|
-
case 2:
|
|
219
|
-
this.currentProcess.kill();
|
|
220
|
-
_a.label = 3;
|
|
221
|
-
case 3:
|
|
222
|
-
this.currentProcess = null;
|
|
223
|
-
_a.label = 4;
|
|
224
|
-
case 4: return [2 /*return*/];
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
return CmdExecutor;
|
|
230
|
-
}());
|
|
231
|
-
exports.CmdExecutor = CmdExecutor;
|
package/dist/logger.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'winston';
|
|
2
|
-
export { Logger };
|
|
3
|
-
export declare function getCircularReplacer(): (key: any, value: any) => any;
|
|
4
|
-
export declare function initLogger(level: string): void;
|
|
5
|
-
export declare function createLogger(level: string): Logger;
|
|
6
|
-
export declare function getLogger(): Logger;
|
|
7
|
-
declare const exportsObject: {};
|
|
8
|
-
export default exportsObject;
|
package/dist/logger.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
26
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
27
|
-
if (ar || !(i in from)) {
|
|
28
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
29
|
-
ar[i] = from[i];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
|
-
};
|
|
34
|
-
exports.__esModule = true;
|
|
35
|
-
exports.getLogger = exports.createLogger = exports.initLogger = exports.getCircularReplacer = exports.Logger = void 0;
|
|
36
|
-
var winston = __importStar(require("winston"));
|
|
37
|
-
var winston_1 = require("winston");
|
|
38
|
-
exports.Logger = winston_1.Logger;
|
|
39
|
-
var logger;
|
|
40
|
-
function getStackTrace() {
|
|
41
|
-
var oldLimit = Error.stackTraceLimit;
|
|
42
|
-
Error.stackTraceLimit = Infinity;
|
|
43
|
-
var retval = new Error().stack;
|
|
44
|
-
Error.stackTraceLimit = oldLimit;
|
|
45
|
-
return retval;
|
|
46
|
-
}
|
|
47
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
|
|
48
|
-
function getCircularReplacer() {
|
|
49
|
-
var ancestors = [];
|
|
50
|
-
return function (key, value) {
|
|
51
|
-
if (typeof value !== 'object' || value === null) {
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
// `this` is the object that value is contained in,
|
|
55
|
-
// i.e., its direct parent.
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
58
|
-
ancestors.pop();
|
|
59
|
-
}
|
|
60
|
-
if (ancestors.includes(value)) {
|
|
61
|
-
return '[Circular]';
|
|
62
|
-
}
|
|
63
|
-
ancestors.push(value);
|
|
64
|
-
return value;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
exports.getCircularReplacer = getCircularReplacer;
|
|
68
|
-
function extractCallerInfo(line) {
|
|
69
|
-
for (var _i = 0, _a = [/\((.*?:\d+:\d+)\)$/, /at (.*?:\d+:\d+)$/]; _i < _a.length; _i++) {
|
|
70
|
-
var pattern = _a[_i];
|
|
71
|
-
var m = line.match(pattern);
|
|
72
|
-
if (m === undefined || m === null) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
var fileInfoLine = m[1];
|
|
76
|
-
return fileInfoLine;
|
|
77
|
-
}
|
|
78
|
-
return '<unknown>';
|
|
79
|
-
}
|
|
80
|
-
var logFormat = winston_1.format.printf(function (info) {
|
|
81
|
-
var _a, _b;
|
|
82
|
-
if (info.level.toUpperCase() !== 'ERROR' && info.level.toUpperCase() !== 'WARN') {
|
|
83
|
-
return "".concat(info.timestamp, " ").concat(info.level.toUpperCase(), ": ").concat(info.message);
|
|
84
|
-
}
|
|
85
|
-
var stack = getStackTrace() || '';
|
|
86
|
-
var stackLines = stack.split('\n');
|
|
87
|
-
var index = stackLines.findIndex(function (line) {
|
|
88
|
-
return line.match(/create-logger.js/);
|
|
89
|
-
}) + 1;
|
|
90
|
-
var fileInfo = '<unknown>';
|
|
91
|
-
if (stackLines.length > index) {
|
|
92
|
-
var line = stackLines[index];
|
|
93
|
-
fileInfo = extractCallerInfo(line);
|
|
94
|
-
}
|
|
95
|
-
var formats = [];
|
|
96
|
-
if (fileInfo !== '<unknown>') {
|
|
97
|
-
formats.push(fileInfo);
|
|
98
|
-
}
|
|
99
|
-
var spaces = ((_a = info.metadata) === null || _a === void 0 ? void 0 : _a.pretty) === true ? 2 : undefined;
|
|
100
|
-
var value = typeof info.message === 'string' ? info.message : JSON.stringify(info.message, getCircularReplacer(), spaces);
|
|
101
|
-
var format = (_b = info.metadata) === null || _b === void 0 ? void 0 : _b.format;
|
|
102
|
-
var message = format ? format.replace(/%s/g, value) : value;
|
|
103
|
-
return __spreadArray(__spreadArray([], formats, true), [message], false).map(function (x) { return "".concat(info.timestamp, " ").concat(info.level.toUpperCase(), ": ").concat(x); }).join('\n');
|
|
104
|
-
});
|
|
105
|
-
var loggerFormat = winston_1.format.combine(winston_1.format.timestamp({ format: 'YY-MM-DD HH:mm:ss' }), winston_1.format.splat(), winston_1.format.metadata({ fillExcept: ['level', 'timestamp', 'message'] }), logFormat, winston_1.format.colorize({
|
|
106
|
-
all: true
|
|
107
|
-
}));
|
|
108
|
-
function initLogger(level) {
|
|
109
|
-
if (!logger) {
|
|
110
|
-
logger = createLogger(level);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.initLogger = initLogger;
|
|
114
|
-
function createLogger(level) {
|
|
115
|
-
var logger = winston.createLogger({
|
|
116
|
-
level: level,
|
|
117
|
-
format: loggerFormat,
|
|
118
|
-
transports: [new winston.transports.Console()]
|
|
119
|
-
});
|
|
120
|
-
return logger;
|
|
121
|
-
}
|
|
122
|
-
exports.createLogger = createLogger;
|
|
123
|
-
function getLogger() {
|
|
124
|
-
var _a;
|
|
125
|
-
initLogger((_a = process.env.LZ_LOG) !== null && _a !== void 0 ? _a : 'info');
|
|
126
|
-
return logger;
|
|
127
|
-
}
|
|
128
|
-
exports.getLogger = getLogger;
|
|
129
|
-
var exportsObject = {};
|
|
130
|
-
if (process.env['NODE_ENV'] === 'test') {
|
|
131
|
-
// @ts-ignore
|
|
132
|
-
exportsObject.getCircularReplacer = getCircularReplacer;
|
|
133
|
-
}
|
|
134
|
-
exports["default"] = exportsObject;
|
package/dist/logger.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|