UNPKG

6.75 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.compute7zCompressArgs = compute7zCompressArgs;
7exports.archive = exports.tar = void 0;
8
9function _bluebirdLst() {
10 const data = require("bluebird-lst");
11
12 _bluebirdLst = function () {
13 return data;
14 };
15
16 return data;
17}
18
19function _zipBin() {
20 const data = require("7zip-bin");
21
22 _zipBin = function () {
23 return data;
24 };
25
26 return data;
27}
28
29function _builderUtil() {
30 const data = require("builder-util");
31
32 _builderUtil = function () {
33 return data;
34 };
35
36 return data;
37}
38
39function _fs() {
40 const data = require("builder-util/out/fs");
41
42 _fs = function () {
43 return data;
44 };
45
46 return data;
47}
48
49function _fsExtraP() {
50 const data = require("fs-extra-p");
51
52 _fsExtraP = function () {
53 return data;
54 };
55
56 return data;
57}
58
59var path = _interopRequireWildcard(require("path"));
60
61function _tools() {
62 const data = require("./tools");
63
64 _tools = function () {
65 return data;
66 };
67
68 return data;
69}
70
71function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
72
73/** @internal */
74let tar = (() => {
75 var _ref = (0, _bluebirdLst().coroutine)(function* (compression, format, outFile, dirToArchive, isMacApp, tempDirManager) {
76 const tarFile = yield tempDirManager.getTempFile({
77 suffix: ".tar"
78 });
79 const tarArgs = (0, _builderUtil().debug7zArgs)("a");
80 tarArgs.push(tarFile);
81 tarArgs.push(path.basename(dirToArchive));
82 yield Promise.all([(0, _builderUtil().exec)(_zipBin().path7za, tarArgs, {
83 cwd: path.dirname(dirToArchive)
84 }), // remove file before - 7z doesn't overwrite file, but update
85 (0, _fs().unlinkIfExists)(outFile)]);
86
87 if (!isMacApp) {
88 yield (0, _builderUtil().exec)(_zipBin().path7za, ["rn", tarFile, path.basename(dirToArchive), path.basename(outFile, `.${format}`)]);
89 }
90
91 if (format === "tar.lz") {
92 // noinspection SpellCheckingInspection
93 let lzipPath = "lzip";
94
95 if (process.platform === "darwin") {
96 lzipPath = path.join((yield (0, _tools().getLinuxToolsPath)()), "bin", lzipPath);
97 }
98
99 yield (0, _builderUtil().exec)(lzipPath, [compression === "store" ? "-1" : "-9", "--keep"
100 /* keep (don't delete) input files */
101 , tarFile]); // bloody lzip creates file in the same dir where input file with postfix `.lz`, option --output doesn't work
102
103 yield (0, _fsExtraP().move)(`${tarFile}.lz`, outFile);
104 return;
105 }
106
107 const args = compute7zCompressArgs(format === "tar.xz" ? "xz" : format === "tar.bz2" ? "bzip2" : "gzip", {
108 isRegularFile: true,
109 method: "DEFAULT",
110 compression
111 });
112 args.push(outFile, tarFile);
113 yield (0, _builderUtil().exec)(_zipBin().path7za, args, {
114 cwd: path.dirname(dirToArchive)
115 }, _builderUtil().debug7z.enabled);
116 });
117
118 return function tar(_x, _x2, _x3, _x4, _x5, _x6) {
119 return _ref.apply(this, arguments);
120 };
121})();
122
123exports.tar = tar;
124
125function compute7zCompressArgs(format, options = {}) {
126 let storeOnly = options.compression === "store";
127 const args = (0, _builderUtil().debug7zArgs)("a");
128 let isLevelSet = false;
129
130 if (process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL != null) {
131 storeOnly = false;
132 args.push(`-mx=${process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL}`);
133 isLevelSet = true;
134 }
135
136 const isZip = format === "zip";
137
138 if (!storeOnly) {
139 if (isZip && options.compression === "maximum") {
140 // http://superuser.com/a/742034
141 args.push("-mfb=258", "-mpass=15");
142 }
143
144 if (!isLevelSet) {
145 // https://github.com/electron-userland/electron-builder/pull/3032
146 args.push("-mx=" + (!isZip || options.compression === "maximum" ? "9" : "7"));
147 }
148 }
149
150 if (options.dictSize != null) {
151 args.push(`-md=${options.dictSize}m`);
152 } // https://sevenzip.osdn.jp/chm/cmdline/switches/method.htm#7Z
153 // https://stackoverflow.com/questions/27136783/7zip-produces-different-output-from-identical-input
154 // tc and ta are off by default, but to be sure, we explicitly set it to off
155 // disable "Stores NTFS timestamps for files: Modification time, Creation time, Last access time." to produce the same archive for the same data
156
157
158 if (!options.isRegularFile) {
159 args.push("-mtc=off");
160 }
161
162 if (format === "7z" || format.endsWith(".7z")) {
163 if (options.solid === false) {
164 args.push("-ms=off");
165 }
166
167 if (options.isArchiveHeaderCompressed === false) {
168 args.push("-mhc=off");
169 } // args valid only for 7z
170 // -mtm=off disable "Stores last Modified timestamps for files."
171
172
173 args.push("-mtm=off", "-mta=off");
174 }
175
176 if (options.method != null) {
177 if (options.method !== "DEFAULT") {
178 args.push(`-mm=${options.method}`);
179 }
180 } else if (isZip || storeOnly) {
181 args.push(`-mm=${storeOnly ? "Copy" : "Deflate"}`);
182 }
183
184 if (isZip) {
185 // -mcu switch: 7-Zip uses UTF-8, if there are non-ASCII symbols.
186 // because default mode: 7-Zip uses UTF-8, if the local code page doesn't contain required symbols.
187 // but archive should be the same regardless where produced
188 args.push("-mcu");
189 }
190
191 return args;
192} // 7z is very fast, so, use ultra compression
193
194/** @internal */
195
196
197let archive = (() => {
198 var _ref2 = (0, _bluebirdLst().coroutine)(function* (format, outFile, dirToArchive, options = {}) {
199 const args = compute7zCompressArgs(format, options); // remove file before - 7z doesn't overwrite file, but update
200
201 yield (0, _fs().unlinkIfExists)(outFile);
202 args.push(outFile, options.listFile == null ? options.withoutDir ? "." : path.basename(dirToArchive) : `@${options.listFile}`);
203
204 if (options.excluded != null) {
205 for (const mask of options.excluded) {
206 args.push(`-xr!${mask}`);
207 }
208 }
209
210 try {
211 yield (0, _builderUtil().exec)(_zipBin().path7za, args, {
212 cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive)
213 }, _builderUtil().debug7z.enabled);
214 } catch (e) {
215 if (e.code === "ENOENT" && !(yield (0, _fs().exists)(dirToArchive))) {
216 throw new Error(`Cannot create archive: "${dirToArchive}" doesn't exist`);
217 } else {
218 throw e;
219 }
220 }
221
222 return outFile;
223 });
224
225 return function archive(_x7, _x8, _x9) {
226 return _ref2.apply(this, arguments);
227 };
228})(); exports.archive = archive;
229//# sourceMappingURL=archive.js.map
\No newline at end of file