mongodb-memory-server-core 8.14.0 → 9.0.0-beta.1
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/lib/MongoMemoryReplSet.d.ts +3 -19
- package/lib/MongoMemoryReplSet.d.ts.map +1 -1
- package/lib/MongoMemoryReplSet.js +283 -294
- package/lib/MongoMemoryReplSet.js.map +1 -1
- package/lib/MongoMemoryServer.d.ts +13 -26
- package/lib/MongoMemoryServer.d.ts.map +1 -1
- package/lib/MongoMemoryServer.js +323 -333
- package/lib/MongoMemoryServer.js.map +1 -1
- package/lib/util/DryMongoBinary.d.ts +1 -1
- package/lib/util/DryMongoBinary.d.ts.map +1 -1
- package/lib/util/DryMongoBinary.js +158 -172
- package/lib/util/DryMongoBinary.js.map +1 -1
- package/lib/util/MongoBinary.js +85 -85
- package/lib/util/MongoBinary.js.map +1 -1
- package/lib/util/MongoBinaryDownload.d.ts +3 -12
- package/lib/util/MongoBinaryDownload.d.ts.map +1 -1
- package/lib/util/MongoBinaryDownload.js +210 -262
- package/lib/util/MongoBinaryDownload.js.map +1 -1
- package/lib/util/MongoBinaryDownloadUrl.d.ts +7 -5
- package/lib/util/MongoBinaryDownloadUrl.d.ts.map +1 -1
- package/lib/util/MongoBinaryDownloadUrl.js +90 -91
- package/lib/util/MongoBinaryDownloadUrl.js.map +1 -1
- package/lib/util/MongoInstance.d.ts +3 -1
- package/lib/util/MongoInstance.d.ts.map +1 -1
- package/lib/util/MongoInstance.js +125 -126
- package/lib/util/MongoInstance.js.map +1 -1
- package/lib/util/errors.d.ts +10 -9
- package/lib/util/errors.d.ts.map +1 -1
- package/lib/util/errors.js +16 -27
- package/lib/util/errors.js.map +1 -1
- package/lib/util/getos/index.d.ts +1 -1
- package/lib/util/getos/index.d.ts.map +1 -1
- package/lib/util/getos/index.js +53 -59
- package/lib/util/getos/index.js.map +1 -1
- package/lib/util/getport/index.d.ts +34 -0
- package/lib/util/getport/index.d.ts.map +1 -0
- package/lib/util/getport/index.js +108 -0
- package/lib/util/getport/index.js.map +1 -0
- package/lib/util/lockfile.d.ts.map +1 -1
- package/lib/util/lockfile.js +155 -169
- package/lib/util/lockfile.js.map +1 -1
- package/lib/util/postinstallHelper.js +15 -18
- package/lib/util/postinstallHelper.js.map +1 -1
- package/lib/util/resolveConfig.d.ts +2 -1
- package/lib/util/resolveConfig.d.ts.map +1 -1
- package/lib/util/resolveConfig.js +10 -8
- package/lib/util/resolveConfig.js.map +1 -1
- package/lib/util/utils.d.ts +20 -4
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +135 -118
- package/lib/util/utils.js.map +1 -1
- package/package.json +8 -12
package/lib/util/getos/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseOS = exports.parseLSB = exports.isValidOs = exports.getOS = exports.isLinuxOS = exports.UNKNOWN = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const os_1 = require("os");
|
|
6
|
-
const debug_1 =
|
|
6
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const log = (0, debug_1.default)('MongoMS:getos');
|
|
9
9
|
/** Collection of Regexes for "lsb_release -a" parsing */
|
|
@@ -35,59 +35,55 @@ exports.isLinuxOS = isLinuxOS;
|
|
|
35
35
|
*/
|
|
36
36
|
let cachedOs;
|
|
37
37
|
/** Get an OS object */
|
|
38
|
-
function getOS() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
cachedOs = yield getLinuxInformation();
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
cachedOs = { os: osName };
|
|
49
|
-
}
|
|
38
|
+
async function getOS() {
|
|
39
|
+
if (!cachedOs) {
|
|
40
|
+
/** Node builtin function for first determinations */
|
|
41
|
+
const osName = (0, os_1.platform)();
|
|
42
|
+
// Linux is a special case.
|
|
43
|
+
if (osName === 'linux') {
|
|
44
|
+
cachedOs = await getLinuxInformation();
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
else {
|
|
47
|
+
cachedOs = { os: osName };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return cachedOs;
|
|
53
51
|
}
|
|
54
52
|
exports.getOS = getOS;
|
|
55
53
|
/** Function to outsource Linux Information Parsing */
|
|
56
|
-
function getLinuxInformation() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
});
|
|
54
|
+
async function getLinuxInformation() {
|
|
55
|
+
// Structure of this function:
|
|
56
|
+
// 1. get upstream release, if possible
|
|
57
|
+
// 2. get os release (etc) because it has an "id_like"
|
|
58
|
+
// 3. get os release (usr) because it has an "id_like"
|
|
59
|
+
// 4. get lsb-release (etc) as fallback
|
|
60
|
+
const upstreamLSB = await (0, utils_1.tryReleaseFile)('/etc/upstream-release/lsb-release', parseLSB);
|
|
61
|
+
if (isValidOs(upstreamLSB)) {
|
|
62
|
+
log('getLinuxInformation: Using UpstreamLSB');
|
|
63
|
+
return upstreamLSB;
|
|
64
|
+
}
|
|
65
|
+
const etcOsRelease = await (0, utils_1.tryReleaseFile)('/etc/os-release', parseOS);
|
|
66
|
+
if (isValidOs(etcOsRelease)) {
|
|
67
|
+
log('getLinuxInformation: Using etcOsRelease');
|
|
68
|
+
return etcOsRelease;
|
|
69
|
+
}
|
|
70
|
+
const usrOsRelease = await (0, utils_1.tryReleaseFile)('/usr/lib/os-release', parseOS);
|
|
71
|
+
if (isValidOs(usrOsRelease)) {
|
|
72
|
+
log('getLinuxInformation: Using usrOsRelease');
|
|
73
|
+
return usrOsRelease;
|
|
74
|
+
}
|
|
75
|
+
const etcLSBRelease = await (0, utils_1.tryReleaseFile)('/etc/lsb-release', parseLSB);
|
|
76
|
+
if (isValidOs(etcLSBRelease)) {
|
|
77
|
+
log('getLinuxInformation: Using etcLSBRelease');
|
|
78
|
+
return etcLSBRelease;
|
|
79
|
+
}
|
|
80
|
+
console.warn('Could not find any valid Release File, using fallback information');
|
|
81
|
+
// if none has worked, return unknown
|
|
82
|
+
return {
|
|
83
|
+
os: 'linux',
|
|
84
|
+
dist: exports.UNKNOWN,
|
|
85
|
+
release: '',
|
|
86
|
+
};
|
|
91
87
|
}
|
|
92
88
|
/**
|
|
93
89
|
* Helper function to check if the input os is valid
|
|
@@ -106,12 +102,11 @@ exports.isValidOs = isValidOs;
|
|
|
106
102
|
* Parse LSB-like output (either command or file)
|
|
107
103
|
*/
|
|
108
104
|
function parseLSB(input) {
|
|
109
|
-
var _a, _b, _c, _d, _e;
|
|
110
105
|
return {
|
|
111
106
|
os: 'linux',
|
|
112
|
-
dist:
|
|
113
|
-
codename:
|
|
114
|
-
release:
|
|
107
|
+
dist: input.match(LSBRegex.name)?.[1].toLocaleLowerCase() ?? exports.UNKNOWN,
|
|
108
|
+
codename: input.match(LSBRegex.codename)?.[1].toLocaleLowerCase(),
|
|
109
|
+
release: input.match(LSBRegex.release)?.[1].toLocaleLowerCase() ?? '',
|
|
115
110
|
};
|
|
116
111
|
}
|
|
117
112
|
exports.parseLSB = parseLSB;
|
|
@@ -119,13 +114,12 @@ exports.parseLSB = parseLSB;
|
|
|
119
114
|
* Parse OSRelease-like output
|
|
120
115
|
*/
|
|
121
116
|
function parseOS(input) {
|
|
122
|
-
var _a, _b, _c, _d, _e, _f;
|
|
123
117
|
return {
|
|
124
118
|
os: 'linux',
|
|
125
|
-
dist:
|
|
126
|
-
codename:
|
|
127
|
-
release:
|
|
128
|
-
id_like:
|
|
119
|
+
dist: input.match(OSRegex.name)?.[1].toLocaleLowerCase() ?? exports.UNKNOWN,
|
|
120
|
+
codename: input.match(OSRegex.codename)?.[1].toLocaleLowerCase(),
|
|
121
|
+
release: input.match(OSRegex.release)?.[1].toLocaleLowerCase() ?? '',
|
|
122
|
+
id_like: input.match(OSRegex.id_like)?.[1].toLocaleLowerCase().split(' '),
|
|
129
123
|
};
|
|
130
124
|
}
|
|
131
125
|
exports.parseOS = parseOS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/getos/index.ts"],"names":[],"mappings":";;;;AAAA,2BAA8B;AAC9B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/getos/index.ts"],"names":[],"mappings":";;;;AAAA,2BAA8B;AAC9B,0DAA0B;AAC1B,oCAA6D;AAE7D,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,eAAe,CAAC,CAAC;AAEnC,yDAAyD;AACzD,MAAM,QAAQ,GAAG;IACf,sFAAsF;IACtF,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,4CAA4C;IACtD,OAAO,EAAE,0CAA0C;CACpD,CAAC;AAEF,0DAA0D;AAC1D,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,wBAAwB;IAC9B,QAAQ,EAAE,iCAAiC;IAC3C,OAAO,EAAE,0CAA0C;IACnD,OAAO,EAAE,iCAAiC;CAC3C,CAAC;AAEF,+DAA+D;AAClD,QAAA,OAAO,GAAG,SAAS,CAAC;AAgBjC;;;GAGG;AACH,SAAgB,SAAS,CAAC,EAAS;IACjC,OAAO,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC;AAC3B,CAAC;AAFD,8BAEC;AAED;;GA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AC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE;QAChE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,IAAI,EAAE;QACpE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;KAC1E,CAAC;AACJ,CAAC;AARD,0BAQC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Linux min port that does not require root permissions */
|
|
2
|
+
export declare const MIN_PORT = 1024;
|
|
3
|
+
/** u16 max number */
|
|
4
|
+
export declare const MAX_PORT = 65535;
|
|
5
|
+
/**
|
|
6
|
+
* Try to get a free port
|
|
7
|
+
* @param firstPort The first port to try or empty for semi-random port
|
|
8
|
+
* @param max_tries maximum amount of tries to get a port, default to {@link MAX_DEFAULT_TRIES}
|
|
9
|
+
* @returns A valid free port
|
|
10
|
+
* @throws if "max_tries" is exceeded
|
|
11
|
+
*/
|
|
12
|
+
export declare function getFreePort(firstPort?: number, max_tries?: number): Promise<number>;
|
|
13
|
+
export default getFreePort;
|
|
14
|
+
/**
|
|
15
|
+
* Check that input number is within range of {@link MIN_PORT} and {@link MAX_PORT}
|
|
16
|
+
* If more than {@link MAX_PORT}, wrap around, if less than {@link MIN_PORT} use {@link MIN_PORT}
|
|
17
|
+
* @param port The Number to check
|
|
18
|
+
* @returns A Valid number in port range
|
|
19
|
+
*/
|
|
20
|
+
export declare function validPort(port: number): number;
|
|
21
|
+
/**
|
|
22
|
+
* Try a given port
|
|
23
|
+
* @param port The port to try
|
|
24
|
+
* @returns "true" if the port is not in use, "false" if in use
|
|
25
|
+
* @throws The error given if the code is not "EADDRINUSE"
|
|
26
|
+
*/
|
|
27
|
+
export declare function tryPort(port: number): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Reset the {@link PORTS_CACHE} to its initial state
|
|
30
|
+
*
|
|
31
|
+
* This function is meant for debugging and testing purposes only
|
|
32
|
+
*/
|
|
33
|
+
export declare function resetPortsCache(): void;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/getport/index.ts"],"names":[],"mappings":"AAEA,4DAA4D;AAC5D,eAAO,MAAM,QAAQ,OAAO,CAAC;AAC7B,qBAAqB;AACrB,eAAO,MAAM,QAAQ,QAAQ,CAAC;AA8B9B;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,GAAE,MAA0B,GACpC,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED,eAAe,WAAW,CAAC;AAE3B;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAkBtD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,SAI9B"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetPortsCache = exports.tryPort = exports.validPort = exports.getFreePort = exports.MAX_PORT = exports.MIN_PORT = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const http = tslib_1.__importStar(require("node:http"));
|
|
6
|
+
/** Linux min port that does not require root permissions */
|
|
7
|
+
exports.MIN_PORT = 1024;
|
|
8
|
+
/** u16 max number */
|
|
9
|
+
exports.MAX_PORT = 65535;
|
|
10
|
+
/**
|
|
11
|
+
* Time before {@link PORTS_CACHE} gets cleared
|
|
12
|
+
* 10 seconds
|
|
13
|
+
*/
|
|
14
|
+
const PORTS_CACHE_CLEAN_TIME = 1000 * 10;
|
|
15
|
+
/**
|
|
16
|
+
* Ports cache, so that locked ports are quickly ignored and hoping for less port stealing
|
|
17
|
+
*/
|
|
18
|
+
const PORTS_CACHE = {
|
|
19
|
+
timeSet: undefined,
|
|
20
|
+
ports: new Set(),
|
|
21
|
+
lastNumber: exports.MIN_PORT,
|
|
22
|
+
};
|
|
23
|
+
/** Max default tries before giving up */
|
|
24
|
+
const MAX_DEFAULT_TRIES = 10;
|
|
25
|
+
/**
|
|
26
|
+
* Try to get a free port
|
|
27
|
+
* @param firstPort The first port to try or empty for semi-random port
|
|
28
|
+
* @param max_tries maximum amount of tries to get a port, default to {@link MAX_DEFAULT_TRIES}
|
|
29
|
+
* @returns A valid free port
|
|
30
|
+
* @throws if "max_tries" is exceeded
|
|
31
|
+
*/
|
|
32
|
+
async function getFreePort(firstPort, max_tries = MAX_DEFAULT_TRIES) {
|
|
33
|
+
// use "Date" as a semi-random value to lessen conflicts between simultaneous tests
|
|
34
|
+
firstPort = firstPort || validPort(Date.now());
|
|
35
|
+
// clear ports cache after some time, but not on a interval
|
|
36
|
+
if (PORTS_CACHE.timeSet && Date.now() - PORTS_CACHE.timeSet > PORTS_CACHE_CLEAN_TIME) {
|
|
37
|
+
PORTS_CACHE.ports.clear();
|
|
38
|
+
PORTS_CACHE.timeSet = Date.now();
|
|
39
|
+
}
|
|
40
|
+
else if (!PORTS_CACHE.timeSet) {
|
|
41
|
+
PORTS_CACHE.timeSet = Date.now();
|
|
42
|
+
}
|
|
43
|
+
let tries = 0;
|
|
44
|
+
while (tries <= max_tries) {
|
|
45
|
+
tries += 1;
|
|
46
|
+
// use "startPort" at first try, otherwise increase from last number
|
|
47
|
+
const nextPort = tries === 1 ? firstPort : validPort(PORTS_CACHE.lastNumber + tries);
|
|
48
|
+
// try next port, because it is already in the cache
|
|
49
|
+
if (PORTS_CACHE.ports.has(nextPort)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
PORTS_CACHE.ports.add(nextPort);
|
|
53
|
+
// only set "lastNumber" if the "nextPort" was not in the cache
|
|
54
|
+
PORTS_CACHE.lastNumber = nextPort;
|
|
55
|
+
if (await tryPort(nextPort)) {
|
|
56
|
+
return nextPort;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw new Error('Max port tries exceeded');
|
|
60
|
+
}
|
|
61
|
+
exports.getFreePort = getFreePort;
|
|
62
|
+
exports.default = getFreePort;
|
|
63
|
+
/**
|
|
64
|
+
* Check that input number is within range of {@link MIN_PORT} and {@link MAX_PORT}
|
|
65
|
+
* If more than {@link MAX_PORT}, wrap around, if less than {@link MIN_PORT} use {@link MIN_PORT}
|
|
66
|
+
* @param port The Number to check
|
|
67
|
+
* @returns A Valid number in port range
|
|
68
|
+
*/
|
|
69
|
+
function validPort(port) {
|
|
70
|
+
const mod = port % exports.MAX_PORT;
|
|
71
|
+
return mod < exports.MIN_PORT ? exports.MIN_PORT : mod;
|
|
72
|
+
}
|
|
73
|
+
exports.validPort = validPort;
|
|
74
|
+
/**
|
|
75
|
+
* Try a given port
|
|
76
|
+
* @param port The port to try
|
|
77
|
+
* @returns "true" if the port is not in use, "false" if in use
|
|
78
|
+
* @throws The error given if the code is not "EADDRINUSE"
|
|
79
|
+
*/
|
|
80
|
+
function tryPort(port) {
|
|
81
|
+
return new Promise((res, rej) => {
|
|
82
|
+
const server = http.createServer();
|
|
83
|
+
server.unref(); // dont keep this server from exiting the application
|
|
84
|
+
server.on('error', (err) => {
|
|
85
|
+
if (err?.code !== 'EADDRINUSE') {
|
|
86
|
+
rej(err);
|
|
87
|
+
}
|
|
88
|
+
res(false);
|
|
89
|
+
});
|
|
90
|
+
server.listen(port, () => {
|
|
91
|
+
server.close();
|
|
92
|
+
res(true);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
exports.tryPort = tryPort;
|
|
97
|
+
/**
|
|
98
|
+
* Reset the {@link PORTS_CACHE} to its initial state
|
|
99
|
+
*
|
|
100
|
+
* This function is meant for debugging and testing purposes only
|
|
101
|
+
*/
|
|
102
|
+
function resetPortsCache() {
|
|
103
|
+
PORTS_CACHE.lastNumber = exports.MIN_PORT;
|
|
104
|
+
PORTS_CACHE.timeSet = undefined;
|
|
105
|
+
PORTS_CACHE.ports.clear();
|
|
106
|
+
}
|
|
107
|
+
exports.resetPortsCache = resetPortsCache;
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/getport/index.ts"],"names":[],"mappings":";;;;AAAA,wDAAkC;AAElC,4DAA4D;AAC/C,QAAA,QAAQ,GAAG,IAAI,CAAC;AAC7B,qBAAqB;AACR,QAAA,QAAQ,GAAG,KAAK,CAAC;AAY9B;;;GAGG;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAE,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,GAAgB;IAC/B,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,IAAI,GAAG,EAAE;IAChB,UAAU,EAAE,gBAAQ;CACrB,CAAC;AAEF,yCAAyC;AACzC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAC/B,SAAkB,EAClB,YAAoB,iBAAiB;IAErC,mFAAmF;IACnF,SAAS,GAAG,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAE/C,2DAA2D;IAC3D,IAAI,WAAW,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,OAAO,GAAG,sBAAsB,EAAE;QACpF,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAC1B,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;KAClC;SAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;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AAK,GAAW,EAAE,IAAI,KAAK,YAAY,EAAE;gBACvC,GAAG,CAAC,GAAG,CAAC,CAAC;aACV;YAED,GAAG,CAAC,KAAK,CAAC,CAAC;QACb,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACvB,MAAM,CAAC,KAAK,EAAE,CAAC;YAEf,GAAG,CAAC,IAAI,CAAC,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAlBD,0BAkBC;AAED;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,WAAW,CAAC,UAAU,GAAG,gBAAQ,CAAC;IAClC,WAAW,CAAC,OAAO,GAAG,SAAS,CAAC;IAChC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;AAC5B,CAAC;AAJD,0CAIC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockfile.d.ts","sourceRoot":"","sources":["../../src/util/lockfile.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"lockfile.d.ts","sourceRoot":"","sources":["../../src/util/lockfile.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAcpC,oBAAY,cAAc;IACxB;;OAEG;IACH,SAAS,IAAA;IACT;;OAEG;IACH,iBAAiB,IAAA;IACjB;;OAEG;IACH,UAAU,IAAA;IACV;;OAEG;IACH,eAAe,IAAA;CAChB;AAED,oBAAY,cAAc;IACxB,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;AAED,UAAU,mBAAoB,SAAQ,YAAY;IAEhD,IAAI,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,EAA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