1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.once = once;
|
9 | exports.trimDotSlash = trimDotSlash;
|
10 | exports.pathRelativeBase = pathRelativeBase;
|
11 | exports.pathRelativeBaseMatch = pathRelativeBaseMatch;
|
12 | exports.trimExtension = trimExtension;
|
13 | exports.bufferToArrayBuffer = bufferToArrayBuffer;
|
14 | exports.launcher = launcher;
|
15 |
|
16 | var _zlib = _interopRequireDefault(require("zlib"));
|
17 |
|
18 | var _launchers = require("./launchers");
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function once(create) {
|
27 | let called = false;
|
28 | let value;
|
29 | return () => {
|
30 | if (!called) {
|
31 | value = create();
|
32 | called = true;
|
33 | }
|
34 |
|
35 | return value;
|
36 | };
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | function trimDotSlash(path) {
|
47 | return path.replace(/^(\.\/)+/, '');
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | function pathRelativeBase(path, start, nocase = false) {
|
60 | const p = trimDotSlash(nocase ? path.toLowerCase() : path);
|
61 | const s = trimDotSlash(nocase ? start.toLowerCase() : start);
|
62 |
|
63 | if (p === s) {
|
64 | return '';
|
65 | }
|
66 |
|
67 | if (p.startsWith(`${s}/`)) {
|
68 | return path.substr(s.length + 1);
|
69 | }
|
70 |
|
71 | return null;
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | function pathRelativeBaseMatch(path, start, nocase = false) {
|
84 | return pathRelativeBase(path, start, nocase) !== null;
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | function trimExtension(path, ext, nocase = false) {
|
97 | const p = nocase ? path.toLowerCase() : path;
|
98 | const e = nocase ? ext.toLowerCase() : ext;
|
99 | return p.endsWith(e) ? path.substr(0, p.length - e.length) : path;
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | function bufferToArrayBuffer(buffer) {
|
110 | const {
|
111 | byteOffset,
|
112 | byteLength
|
113 | } = buffer;
|
114 | return buffer.buffer.slice(byteOffset, byteOffset + byteLength);
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | async function launcher(id) {
|
125 | const b64 = (0, _launchers.launchers)()[id];
|
126 |
|
127 | if (typeof b64 !== 'string') {
|
128 | throw new Error(`Invalid launcher id: ${id}`);
|
129 | }
|
130 |
|
131 | return new Promise((resolve, reject) => {
|
132 | _zlib.default.inflateRaw(Buffer.from(b64, 'base64'), (err, data) => {
|
133 | if (err) {
|
134 | reject(err);
|
135 | return;
|
136 | }
|
137 |
|
138 | resolve(data);
|
139 | });
|
140 | });
|
141 | }
|
142 |
|