UNPKG

16.1 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.serializeToYaml = serializeToYaml;
7exports.removePassword = removePassword;
8exports.exec = exec;
9exports.doSpawn = doSpawn;
10exports.spawnAndWrite = spawnAndWrite;
11exports.spawn = spawn;
12exports.use = use;
13exports.isEmptyOrSpaces = isEmptyOrSpaces;
14exports.isTokenCharValid = isTokenCharValid;
15exports.addValue = addValue;
16exports.replaceDefault = replaceDefault;
17exports.getPlatformIconFileName = getPlatformIconFileName;
18exports.isPullRequest = isPullRequest;
19exports.isEnvTrue = isEnvTrue;
20exports.executeAppBuilder = executeAppBuilder;
21Object.defineProperty(exports, "safeStringifyJson", {
22 enumerable: true,
23 get: function () {
24 return _builderUtilRuntime().safeStringifyJson;
25 }
26});
27Object.defineProperty(exports, "asArray", {
28 enumerable: true,
29 get: function () {
30 return _builderUtilRuntime().asArray;
31 }
32});
33Object.defineProperty(exports, "log", {
34 enumerable: true,
35 get: function () {
36 return _log().log;
37 }
38});
39Object.defineProperty(exports, "debug", {
40 enumerable: true,
41 get: function () {
42 return _log().debug;
43 }
44});
45Object.defineProperty(exports, "TmpDir", {
46 enumerable: true,
47 get: function () {
48 return _tempFile().TmpDir;
49 }
50});
51Object.defineProperty(exports, "Arch", {
52 enumerable: true,
53 get: function () {
54 return _arch().Arch;
55 }
56});
57Object.defineProperty(exports, "getArchCliNames", {
58 enumerable: true,
59 get: function () {
60 return _arch().getArchCliNames;
61 }
62});
63Object.defineProperty(exports, "toLinuxArchString", {
64 enumerable: true,
65 get: function () {
66 return _arch().toLinuxArchString;
67 }
68});
69Object.defineProperty(exports, "getArchSuffix", {
70 enumerable: true,
71 get: function () {
72 return _arch().getArchSuffix;
73 }
74});
75Object.defineProperty(exports, "archFromString", {
76 enumerable: true,
77 get: function () {
78 return _arch().archFromString;
79 }
80});
81Object.defineProperty(exports, "AsyncTaskManager", {
82 enumerable: true,
83 get: function () {
84 return _asyncTaskManager().AsyncTaskManager;
85 }
86});
87Object.defineProperty(exports, "DebugLogger", {
88 enumerable: true,
89 get: function () {
90 return _DebugLogger().DebugLogger;
91 }
92});
93Object.defineProperty(exports, "copyFile", {
94 enumerable: true,
95 get: function () {
96 return _fs().copyFile;
97 }
98});
99Object.defineProperty(exports, "exists", {
100 enumerable: true,
101 get: function () {
102 return _fs().exists;
103 }
104});
105Object.defineProperty(exports, "deepAssign", {
106 enumerable: true,
107 get: function () {
108 return _deepAssign().deepAssign;
109 }
110});
111exports.InvalidConfigurationError = exports.ExecError = exports.debug7z = void 0;
112
113function _zipBin() {
114 const data = require("7zip-bin");
115
116 _zipBin = function () {
117 return data;
118 };
119
120 return data;
121}
122
123function _appBuilderBin() {
124 const data = require("app-builder-bin");
125
126 _appBuilderBin = function () {
127 return data;
128 };
129
130 return data;
131}
132
133function _builderUtilRuntime() {
134 const data = require("builder-util-runtime");
135
136 _builderUtilRuntime = function () {
137 return data;
138 };
139
140 return data;
141}
142
143function _chalk() {
144 const data = _interopRequireDefault(require("chalk"));
145
146 _chalk = function () {
147 return data;
148 };
149
150 return data;
151}
152
153function _child_process() {
154 const data = require("child_process");
155
156 _child_process = function () {
157 return data;
158 };
159
160 return data;
161}
162
163function _crypto() {
164 const data = require("crypto");
165
166 _crypto = function () {
167 return data;
168 };
169
170 return data;
171}
172
173var _debug2 = _interopRequireDefault(require("debug"));
174
175function _jsYaml() {
176 const data = require("js-yaml");
177
178 _jsYaml = function () {
179 return data;
180 };
181
182 return data;
183}
184
185var path = _interopRequireWildcard(require("path"));
186
187function _sourceMapSupport() {
188 const data = _interopRequireDefault(require("source-map-support"));
189
190 _sourceMapSupport = function () {
191 return data;
192 };
193
194 return data;
195}
196
197function _log() {
198 const data = require("./log");
199
200 _log = function () {
201 return data;
202 };
203
204 return data;
205}
206
207function _tempFile() {
208 const data = require("temp-file");
209
210 _tempFile = function () {
211 return data;
212 };
213
214 return data;
215}
216
217function _arch() {
218 const data = require("./arch");
219
220 _arch = function () {
221 return data;
222 };
223
224 return data;
225}
226
227function _asyncTaskManager() {
228 const data = require("./asyncTaskManager");
229
230 _asyncTaskManager = function () {
231 return data;
232 };
233
234 return data;
235}
236
237function _DebugLogger() {
238 const data = require("./DebugLogger");
239
240 _DebugLogger = function () {
241 return data;
242 };
243
244 return data;
245}
246
247function _fs() {
248 const data = require("./fs");
249
250 _fs = function () {
251 return data;
252 };
253
254 return data;
255}
256
257function _deepAssign() {
258 const data = require("./deepAssign");
259
260 _deepAssign = function () {
261 return data;
262 };
263
264 return data;
265}
266
267function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
268
269function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
270
271function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
272
273if (process.env.JEST_WORKER_ID == null) {
274 _sourceMapSupport().default.install();
275}
276
277const debug7z = (0, _debug2.default)("electron-builder:7z");
278exports.debug7z = debug7z;
279
280function serializeToYaml(object, skipInvalid = false, noRefs = false) {
281 return (0, _jsYaml().safeDump)(object, {
282 lineWidth: 8000,
283 skipInvalid,
284 noRefs
285 });
286}
287
288function removePassword(input) {
289 return input.replace(/(-String |-P |pass:| \/p |-pass |--secretKey |--accessKey |-p )([^ ]+)/g, (match, p1, p2) => {
290 if (p1.trim() === "/p" && p2.startsWith("\\\\Mac\\Host\\\\")) {
291 // appx /p
292 return `${p1}${p2}`;
293 }
294
295 return `${p1}${(0, _crypto().createHash)("sha256").update(p2).digest("hex")} (sha256 hash)`;
296 });
297}
298
299function getProcessEnv(env) {
300 if (process.platform === "win32") {
301 return env == null ? undefined : env;
302 }
303
304 const finalEnv = { ...(env || process.env)
305 }; // without LC_CTYPE dpkg can returns encoded unicode symbols
306 // set LC_CTYPE to avoid crash https://github.com/electron-userland/electron-builder/issues/503 Even "en_DE.UTF-8" leads to error.
307
308 const locale = process.platform === "linux" ? process.env.LANG || "C.UTF-8" : "en_US.UTF-8";
309 finalEnv.LANG = locale;
310 finalEnv.LC_CTYPE = locale;
311 finalEnv.LC_ALL = locale;
312 return finalEnv;
313}
314
315function exec(file, args, options, isLogOutIfDebug = true) {
316 if (_log().log.isDebugEnabled) {
317 const logFields = {
318 file,
319 args: args == null ? "" : removePassword(args.join(" "))
320 };
321
322 if (options != null) {
323 if (options.cwd != null) {
324 logFields.cwd = options.cwd;
325 }
326
327 if (options.env != null) {
328 const diffEnv = { ...options.env
329 };
330
331 for (const name of Object.keys(process.env)) {
332 if (process.env[name] === options.env[name]) {
333 delete diffEnv[name];
334 }
335 }
336
337 logFields.env = (0, _builderUtilRuntime().safeStringifyJson)(diffEnv);
338 }
339 }
340
341 _log().log.debug(logFields, "executing");
342 }
343
344 return new Promise((resolve, reject) => {
345 (0, _child_process().execFile)(file, args, { ...options,
346 maxBuffer: 1000 * 1024 * 1024,
347 env: getProcessEnv(options == null ? null : options.env)
348 }, (error, stdout, stderr) => {
349 if (error == null) {
350 if (isLogOutIfDebug && _log().log.isDebugEnabled) {
351 const logFields = {
352 file
353 };
354
355 if (stdout.length > 0) {
356 logFields.stdout = stdout;
357 }
358
359 if (stderr.length > 0) {
360 logFields.stderr = stderr;
361 }
362
363 _log().log.debug(logFields, "executed");
364 }
365
366 resolve(stdout.toString());
367 } else {
368 let message = _chalk().default.red(removePassword(`Exit code: ${error.code}. ${error.message}`));
369
370 if (stdout.length !== 0) {
371 if (file.endsWith("wine")) {
372 stdout = stdout.toString();
373 }
374
375 message += `\n${_chalk().default.yellow(stdout.toString())}`;
376 }
377
378 if (stderr.length !== 0) {
379 if (file.endsWith("wine")) {
380 stderr = stderr.toString();
381 }
382
383 message += `\n${_chalk().default.red(stderr.toString())}`;
384 }
385
386 reject(new Error(message));
387 }
388 });
389 });
390}
391
392function logSpawn(command, args, options) {
393 // use general debug.enabled to log spawn, because it doesn't produce a lot of output (the only line), but important in any case
394 if (!_log().log.isDebugEnabled) {
395 return;
396 }
397
398 const argsString = removePassword(args.join(" "));
399 const logFields = {
400 command: command + " " + (command === "docker" ? argsString : removePassword(argsString))
401 };
402
403 if (options != null && options.cwd != null) {
404 logFields.cwd = options.cwd;
405 }
406
407 _log().log.debug(logFields, "spawning");
408}
409
410function doSpawn(command, args, options, extraOptions) {
411 if (options == null) {
412 options = {};
413 }
414
415 options.env = getProcessEnv(options.env);
416
417 if (options.stdio == null) {
418 const isDebugEnabled = _log().debug.enabled; // do not ignore stdout/stderr if not debug, because in this case we will read into buffer and print on error
419
420
421 options.stdio = [extraOptions != null && extraOptions.isPipeInput ? "pipe" : "ignore", isDebugEnabled ? "inherit" : "pipe", isDebugEnabled ? "inherit" : "pipe"];
422 }
423
424 logSpawn(command, args, options);
425
426 try {
427 return (0, _child_process().spawn)(command, args, options);
428 } catch (e) {
429 throw new Error(`Cannot spawn ${command}: ${e.stack || e}`);
430 }
431}
432
433function spawnAndWrite(command, args, data, options) {
434 const childProcess = doSpawn(command, args, options, {
435 isPipeInput: true
436 });
437 const timeout = setTimeout(() => childProcess.kill(), 4 * 60 * 1000);
438 return new Promise((resolve, reject) => {
439 handleProcess("close", childProcess, command, () => {
440 try {
441 clearTimeout(timeout);
442 } finally {
443 resolve(undefined);
444 }
445 }, error => {
446 try {
447 clearTimeout(timeout);
448 } finally {
449 reject(error);
450 }
451 });
452 childProcess.stdin.end(data);
453 });
454}
455
456function spawn(command, args, options, extraOptions) {
457 return new Promise((resolve, reject) => {
458 handleProcess("close", doSpawn(command, args || [], options, extraOptions), command, resolve, reject);
459 });
460}
461
462function handleProcess(event, childProcess, command, resolve, reject) {
463 childProcess.on("error", reject);
464 let out = "";
465
466 if (childProcess.stdout != null) {
467 childProcess.stdout.on("data", data => {
468 out += data;
469 });
470 }
471
472 let errorOut = "";
473
474 if (childProcess.stderr != null) {
475 childProcess.stderr.on("data", data => {
476 errorOut += data;
477 });
478 }
479
480 childProcess.once(event, code => {
481 if (_log().log.isDebugEnabled) {
482 const fields = {
483 command: path.basename(command),
484 code,
485 pid: childProcess.pid
486 };
487
488 if (out.length > 0) {
489 fields.out = out;
490 }
491
492 _log().log.debug(fields, "exited");
493 }
494
495 if (code === 0) {
496 if (resolve != null) {
497 resolve(out);
498 }
499 } else {
500 reject(new ExecError(command, code, formatOut(out, "Output"), formatOut(errorOut, "Error output")));
501 }
502 });
503}
504
505function formatOut(text, title) {
506 return text.length === 0 ? "" : `\n${title}:\n${text}`;
507}
508
509class ExecError extends Error {
510 constructor(command, exitCode, out, errorOut, code = "ERR_ELECTRON_BUILDER_CANNOT_EXECUTE") {
511 super(`${command} exited with code ${code}${formatOut(out, "Output")}${formatOut(errorOut, "Error output")}`);
512 this.exitCode = exitCode;
513 this.alreadyLogged = false;
514 this.code = code;
515 }
516
517}
518
519exports.ExecError = ExecError;
520
521function use(value, task) {
522 return value == null ? null : task(value);
523}
524
525function isEmptyOrSpaces(s) {
526 return s == null || s.trim().length === 0;
527}
528
529function isTokenCharValid(token) {
530 return /^[.\w/=+-]+$/.test(token);
531}
532
533function addValue(map, key, value) {
534 const list = map.get(key);
535
536 if (list == null) {
537 map.set(key, [value]);
538 } else if (!list.includes(value)) {
539 list.push(value);
540 }
541}
542
543function replaceDefault(inList, defaultList) {
544 if (inList == null || inList.length === 1 && inList[0] === "default") {
545 return defaultList;
546 }
547
548 const index = inList.indexOf("default");
549
550 if (index >= 0) {
551 const list = inList.slice(0, index);
552 list.push(...defaultList);
553
554 if (index !== inList.length - 1) {
555 list.push(...inList.slice(index + 1));
556 }
557
558 inList = list;
559 }
560
561 return inList;
562}
563
564function getPlatformIconFileName(value, isMac) {
565 if (value === undefined) {
566 return undefined;
567 }
568
569 if (value === null) {
570 return null;
571 }
572
573 if (!value.includes(".")) {
574 return `${value}.${isMac ? "icns" : "ico"}`;
575 }
576
577 return value.replace(isMac ? ".ico" : ".icns", isMac ? ".icns" : ".ico");
578}
579
580function isPullRequest() {
581 // TRAVIS_PULL_REQUEST is set to the pull request number if the current job is a pull request build, or false if it’s not.
582 function isSet(value) {
583 // value can be or null, or empty string
584 return value && value !== "false";
585 }
586
587 return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CIRCLE_PULL_REQUEST) || isSet(process.env.BITRISE_PULL_REQUEST) || isSet(process.env.APPVEYOR_PULL_REQUEST_NUMBER);
588}
589
590function isEnvTrue(value) {
591 if (value != null) {
592 value = value.trim();
593 }
594
595 return value === "true" || value === "" || value === "1";
596}
597
598class InvalidConfigurationError extends Error {
599 constructor(message, code = "ERR_ELECTRON_BUILDER_INVALID_CONFIGURATION") {
600 super(message);
601 this.code = code;
602 }
603
604}
605
606exports.InvalidConfigurationError = InvalidConfigurationError;
607
608function executeAppBuilder(args, childProcessConsumer, extraOptions = {}, maxRetries = 0) {
609 const command = _appBuilderBin().appBuilderPath;
610
611 const env = { ...process.env,
612 SZA_PATH: _zipBin().path7za,
613 FORCE_COLOR: _chalk().default.level === 0 ? "0" : "1"
614 };
615 const cacheEnv = process.env.ELECTRON_BUILDER_CACHE;
616
617 if (cacheEnv != null && cacheEnv.length > 0) {
618 env.ELECTRON_BUILDER_CACHE = path.resolve(cacheEnv);
619 }
620
621 if (extraOptions.env != null) {
622 Object.assign(env, extraOptions.env);
623 }
624
625 function runCommand() {
626 return new Promise((resolve, reject) => {
627 const childProcess = doSpawn(command, args, {
628 env,
629 stdio: ["ignore", "pipe", process.stdout],
630 ...extraOptions
631 });
632
633 if (childProcessConsumer != null) {
634 childProcessConsumer(childProcess);
635 }
636
637 handleProcess("close", childProcess, command, resolve, error => {
638 if (error instanceof ExecError && error.exitCode === 2) {
639 error.alreadyLogged = true;
640 }
641
642 reject(error);
643 });
644 });
645 }
646
647 if (maxRetries === 0) {
648 return runCommand();
649 } else {
650 return retry(runCommand, maxRetries, 1000);
651 }
652}
653
654async function retry(task, retriesLeft, interval) {
655 try {
656 return await task();
657 } catch (error) {
658 _log().log.info(`Above command failed, retrying ${retriesLeft} more times`);
659
660 if (retriesLeft > 0) {
661 await new Promise(resolve => setTimeout(resolve, interval));
662 return await retry(task, retriesLeft - 1, interval);
663 } else {
664 throw error;
665 }
666 }
667}
668// __ts-babel@6.0.4
669//# sourceMappingURL=util.js.map
\No newline at end of file