1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.serializeToYaml = serializeToYaml;
|
7 | exports.removePassword = removePassword;
|
8 | exports.exec = exec;
|
9 | exports.doSpawn = doSpawn;
|
10 | exports.spawnAndWrite = spawnAndWrite;
|
11 | exports.spawn = spawn;
|
12 | exports.use = use;
|
13 | exports.isEmptyOrSpaces = isEmptyOrSpaces;
|
14 | exports.isTokenCharValid = isTokenCharValid;
|
15 | exports.addValue = addValue;
|
16 | exports.replaceDefault = replaceDefault;
|
17 | exports.getPlatformIconFileName = getPlatformIconFileName;
|
18 | exports.isPullRequest = isPullRequest;
|
19 | exports.isEnvTrue = isEnvTrue;
|
20 | exports.executeAppBuilder = executeAppBuilder;
|
21 | Object.defineProperty(exports, "safeStringifyJson", {
|
22 | enumerable: true,
|
23 | get: function () {
|
24 | return _builderUtilRuntime().safeStringifyJson;
|
25 | }
|
26 | });
|
27 | Object.defineProperty(exports, "asArray", {
|
28 | enumerable: true,
|
29 | get: function () {
|
30 | return _builderUtilRuntime().asArray;
|
31 | }
|
32 | });
|
33 | Object.defineProperty(exports, "log", {
|
34 | enumerable: true,
|
35 | get: function () {
|
36 | return _log().log;
|
37 | }
|
38 | });
|
39 | Object.defineProperty(exports, "debug", {
|
40 | enumerable: true,
|
41 | get: function () {
|
42 | return _log().debug;
|
43 | }
|
44 | });
|
45 | Object.defineProperty(exports, "TmpDir", {
|
46 | enumerable: true,
|
47 | get: function () {
|
48 | return _tempFile().TmpDir;
|
49 | }
|
50 | });
|
51 | Object.defineProperty(exports, "Arch", {
|
52 | enumerable: true,
|
53 | get: function () {
|
54 | return _arch().Arch;
|
55 | }
|
56 | });
|
57 | Object.defineProperty(exports, "getArchCliNames", {
|
58 | enumerable: true,
|
59 | get: function () {
|
60 | return _arch().getArchCliNames;
|
61 | }
|
62 | });
|
63 | Object.defineProperty(exports, "toLinuxArchString", {
|
64 | enumerable: true,
|
65 | get: function () {
|
66 | return _arch().toLinuxArchString;
|
67 | }
|
68 | });
|
69 | Object.defineProperty(exports, "getArchSuffix", {
|
70 | enumerable: true,
|
71 | get: function () {
|
72 | return _arch().getArchSuffix;
|
73 | }
|
74 | });
|
75 | Object.defineProperty(exports, "archFromString", {
|
76 | enumerable: true,
|
77 | get: function () {
|
78 | return _arch().archFromString;
|
79 | }
|
80 | });
|
81 | Object.defineProperty(exports, "AsyncTaskManager", {
|
82 | enumerable: true,
|
83 | get: function () {
|
84 | return _asyncTaskManager().AsyncTaskManager;
|
85 | }
|
86 | });
|
87 | Object.defineProperty(exports, "DebugLogger", {
|
88 | enumerable: true,
|
89 | get: function () {
|
90 | return _DebugLogger().DebugLogger;
|
91 | }
|
92 | });
|
93 | Object.defineProperty(exports, "copyFile", {
|
94 | enumerable: true,
|
95 | get: function () {
|
96 | return _fs().copyFile;
|
97 | }
|
98 | });
|
99 | Object.defineProperty(exports, "exists", {
|
100 | enumerable: true,
|
101 | get: function () {
|
102 | return _fs().exists;
|
103 | }
|
104 | });
|
105 | Object.defineProperty(exports, "deepAssign", {
|
106 | enumerable: true,
|
107 | get: function () {
|
108 | return _deepAssign().deepAssign;
|
109 | }
|
110 | });
|
111 | exports.InvalidConfigurationError = exports.ExecError = exports.debug7z = void 0;
|
112 |
|
113 | function _zipBin() {
|
114 | const data = require("7zip-bin");
|
115 |
|
116 | _zipBin = function () {
|
117 | return data;
|
118 | };
|
119 |
|
120 | return data;
|
121 | }
|
122 |
|
123 | function _appBuilderBin() {
|
124 | const data = require("app-builder-bin");
|
125 |
|
126 | _appBuilderBin = function () {
|
127 | return data;
|
128 | };
|
129 |
|
130 | return data;
|
131 | }
|
132 |
|
133 | function _builderUtilRuntime() {
|
134 | const data = require("builder-util-runtime");
|
135 |
|
136 | _builderUtilRuntime = function () {
|
137 | return data;
|
138 | };
|
139 |
|
140 | return data;
|
141 | }
|
142 |
|
143 | function _chalk() {
|
144 | const data = _interopRequireDefault(require("chalk"));
|
145 |
|
146 | _chalk = function () {
|
147 | return data;
|
148 | };
|
149 |
|
150 | return data;
|
151 | }
|
152 |
|
153 | function _child_process() {
|
154 | const data = require("child_process");
|
155 |
|
156 | _child_process = function () {
|
157 | return data;
|
158 | };
|
159 |
|
160 | return data;
|
161 | }
|
162 |
|
163 | function _crypto() {
|
164 | const data = require("crypto");
|
165 |
|
166 | _crypto = function () {
|
167 | return data;
|
168 | };
|
169 |
|
170 | return data;
|
171 | }
|
172 |
|
173 | var _debug2 = _interopRequireDefault(require("debug"));
|
174 |
|
175 | function _jsYaml() {
|
176 | const data = require("js-yaml");
|
177 |
|
178 | _jsYaml = function () {
|
179 | return data;
|
180 | };
|
181 |
|
182 | return data;
|
183 | }
|
184 |
|
185 | var path = _interopRequireWildcard(require("path"));
|
186 |
|
187 | function _sourceMapSupport() {
|
188 | const data = _interopRequireDefault(require("source-map-support"));
|
189 |
|
190 | _sourceMapSupport = function () {
|
191 | return data;
|
192 | };
|
193 |
|
194 | return data;
|
195 | }
|
196 |
|
197 | function _log() {
|
198 | const data = require("./log");
|
199 |
|
200 | _log = function () {
|
201 | return data;
|
202 | };
|
203 |
|
204 | return data;
|
205 | }
|
206 |
|
207 | function _tempFile() {
|
208 | const data = require("temp-file");
|
209 |
|
210 | _tempFile = function () {
|
211 | return data;
|
212 | };
|
213 |
|
214 | return data;
|
215 | }
|
216 |
|
217 | function _arch() {
|
218 | const data = require("./arch");
|
219 |
|
220 | _arch = function () {
|
221 | return data;
|
222 | };
|
223 |
|
224 | return data;
|
225 | }
|
226 |
|
227 | function _asyncTaskManager() {
|
228 | const data = require("./asyncTaskManager");
|
229 |
|
230 | _asyncTaskManager = function () {
|
231 | return data;
|
232 | };
|
233 |
|
234 | return data;
|
235 | }
|
236 |
|
237 | function _DebugLogger() {
|
238 | const data = require("./DebugLogger");
|
239 |
|
240 | _DebugLogger = function () {
|
241 | return data;
|
242 | };
|
243 |
|
244 | return data;
|
245 | }
|
246 |
|
247 | function _fs() {
|
248 | const data = require("./fs");
|
249 |
|
250 | _fs = function () {
|
251 | return data;
|
252 | };
|
253 |
|
254 | return data;
|
255 | }
|
256 |
|
257 | function _deepAssign() {
|
258 | const data = require("./deepAssign");
|
259 |
|
260 | _deepAssign = function () {
|
261 | return data;
|
262 | };
|
263 |
|
264 | return data;
|
265 | }
|
266 |
|
267 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
268 |
|
269 | function _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 |
|
271 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
272 |
|
273 | if (process.env.JEST_WORKER_ID == null) {
|
274 | _sourceMapSupport().default.install();
|
275 | }
|
276 |
|
277 | const debug7z = (0, _debug2.default)("electron-builder:7z");
|
278 | exports.debug7z = debug7z;
|
279 |
|
280 | function serializeToYaml(object, skipInvalid = false, noRefs = false) {
|
281 | return (0, _jsYaml().safeDump)(object, {
|
282 | lineWidth: 8000,
|
283 | skipInvalid,
|
284 | noRefs
|
285 | });
|
286 | }
|
287 |
|
288 | function 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 |
|
292 | return `${p1}${p2}`;
|
293 | }
|
294 |
|
295 | return `${p1}${(0, _crypto().createHash)("sha256").update(p2).digest("hex")} (sha256 hash)`;
|
296 | });
|
297 | }
|
298 |
|
299 | function getProcessEnv(env) {
|
300 | if (process.platform === "win32") {
|
301 | return env == null ? undefined : env;
|
302 | }
|
303 |
|
304 | const finalEnv = { ...(env || process.env)
|
305 | };
|
306 |
|
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 |
|
315 | function 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 |
|
392 | function logSpawn(command, args, options) {
|
393 |
|
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 |
|
410 | function 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;
|
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 |
|
433 | function 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 |
|
456 | function 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 |
|
462 | function 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 |
|
505 | function formatOut(text, title) {
|
506 | return text.length === 0 ? "" : `\n${title}:\n${text}`;
|
507 | }
|
508 |
|
509 | class 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 |
|
519 | exports.ExecError = ExecError;
|
520 |
|
521 | function use(value, task) {
|
522 | return value == null ? null : task(value);
|
523 | }
|
524 |
|
525 | function isEmptyOrSpaces(s) {
|
526 | return s == null || s.trim().length === 0;
|
527 | }
|
528 |
|
529 | function isTokenCharValid(token) {
|
530 | return /^[.\w/=+-]+$/.test(token);
|
531 | }
|
532 |
|
533 | function 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 |
|
543 | function 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 |
|
564 | function 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 |
|
580 | function isPullRequest() {
|
581 |
|
582 | function isSet(value) {
|
583 |
|
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 |
|
590 | function isEnvTrue(value) {
|
591 | if (value != null) {
|
592 | value = value.trim();
|
593 | }
|
594 |
|
595 | return value === "true" || value === "" || value === "1";
|
596 | }
|
597 |
|
598 | class InvalidConfigurationError extends Error {
|
599 | constructor(message, code = "ERR_ELECTRON_BUILDER_INVALID_CONFIGURATION") {
|
600 | super(message);
|
601 | this.code = code;
|
602 | }
|
603 |
|
604 | }
|
605 |
|
606 | exports.InvalidConfigurationError = InvalidConfigurationError;
|
607 |
|
608 | function 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 |
|
654 | async 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 |
|
669 |
|
\ | No newline at end of file |