app-builder-lib 26.0.0-alpha.5 → 26.0.0-alpha.7
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/out/asar/asarUtil.js +58 -43
- package/out/asar/asarUtil.js.map +1 -1
- package/out/asar/unpackDetector.js +7 -52
- package/out/asar/unpackDetector.js.map +1 -1
- package/out/electron/electronWin.js +2 -1
- package/out/electron/electronWin.js.map +1 -1
- package/out/macPackager.d.ts +1 -1
- package/out/macPackager.js +5 -4
- package/out/macPackager.js.map +1 -1
- package/out/options/linuxOptions.d.ts +16 -2
- package/out/options/linuxOptions.js.map +1 -1
- package/out/platformPackager.js +2 -2
- package/out/platformPackager.js.map +1 -1
- package/out/targets/FpmTarget.d.ts +2 -0
- package/out/targets/FpmTarget.js +47 -8
- package/out/targets/FpmTarget.js.map +1 -1
- package/out/util/NodeModuleCopyHelper.js +4 -2
- package/out/util/NodeModuleCopyHelper.js.map +1 -1
- package/out/util/appFileCopier.js +1 -1
- package/out/util/appFileCopier.js.map +1 -1
- package/out/util/filter.js +1 -1
- package/out/util/filter.js.map +1 -1
- package/out/version.d.ts +1 -1
- package/out/version.js +1 -1
- package/out/version.js.map +1 -1
- package/package.json +8 -8
- package/scheme.json +35 -3
- package/templates/linux/after-install.tpl +27 -0
- package/templates/linux/after-remove.tpl +7 -0
- package/templates/linux/apparmor-profile.tpl +9 -0
package/out/asar/asarUtil.js
CHANGED
|
@@ -3,33 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AsarPackager = void 0;
|
|
4
4
|
const asar_1 = require("@electron/asar");
|
|
5
5
|
const builder_util_1 = require("builder-util");
|
|
6
|
-
const builder_util_runtime_1 = require("builder-util-runtime");
|
|
7
6
|
const fs_1 = require("builder-util/out/fs");
|
|
8
|
-
const fsNode = require("fs");
|
|
9
7
|
const fs = require("fs-extra");
|
|
8
|
+
const fs_extra_1 = require("fs-extra");
|
|
9
|
+
const os_1 = require("os");
|
|
10
10
|
const path = require("path");
|
|
11
|
-
const tempFile = require("temp-file");
|
|
12
11
|
const appFileCopier_1 = require("../util/appFileCopier");
|
|
13
12
|
const unpackDetector_1 = require("./unpackDetector");
|
|
14
13
|
/** @internal */
|
|
15
14
|
class AsarPackager {
|
|
16
|
-
constructor(config) {
|
|
15
|
+
constructor(packager, config) {
|
|
16
|
+
this.packager = packager;
|
|
17
17
|
this.config = config;
|
|
18
|
-
this.
|
|
18
|
+
this.fileCopier = new fs_1.FileCopier();
|
|
19
19
|
this.outFile = path.join(config.resourcePath, `app.asar`);
|
|
20
|
+
this.tmpDir = packager.info.tempDirManager;
|
|
21
|
+
this.cancellationToken = packager.info.cancellationToken;
|
|
20
22
|
}
|
|
21
|
-
async pack(fileSets
|
|
23
|
+
async pack(fileSets) {
|
|
22
24
|
this.rootForAppFilesWithoutAsar = await this.tmpDir.getTempDir({ prefix: "asar-app" });
|
|
23
|
-
const cancellationToken = new builder_util_runtime_1.CancellationToken();
|
|
24
|
-
cancellationToken.on("cancel", () => this.tmpDir.cleanupSync());
|
|
25
25
|
const orderedFileSets = [
|
|
26
26
|
// Write dependencies first to minimize offset changes to asar header
|
|
27
27
|
...fileSets.slice(1),
|
|
28
28
|
// Finish with the app files that change most often
|
|
29
29
|
fileSets[0],
|
|
30
30
|
].map(orderFileSet);
|
|
31
|
-
const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets
|
|
31
|
+
const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets);
|
|
32
32
|
const unpackGlob = unpackedPaths.length > 1 ? `{${unpackedPaths.join(",")}}` : unpackedPaths.pop();
|
|
33
|
+
await this.executeElectronAsar(copiedFiles, unpackGlob);
|
|
34
|
+
}
|
|
35
|
+
async executeElectronAsar(copiedFiles, unpackGlob) {
|
|
33
36
|
let ordering = this.config.options.ordering || undefined;
|
|
34
37
|
if (!ordering) {
|
|
35
38
|
// `copiedFiles` are already ordered due to `orderedFileSets` input, so we just map to their relative paths (via substring) within the asar.
|
|
@@ -53,13 +56,15 @@ class AsarPackager {
|
|
|
53
56
|
};
|
|
54
57
|
await (0, asar_1.createPackageWithOptions)(this.rootForAppFilesWithoutAsar, this.outFile, options);
|
|
55
58
|
console.log = consoleLogger;
|
|
56
|
-
await this.tmpDir.cleanup();
|
|
57
59
|
}
|
|
58
|
-
async detectAndCopy(fileSets
|
|
60
|
+
async detectAndCopy(fileSets) {
|
|
59
61
|
var _a;
|
|
60
|
-
const taskManager = new builder_util_1.AsyncTaskManager(cancellationToken);
|
|
62
|
+
const taskManager = new builder_util_1.AsyncTaskManager(this.cancellationToken);
|
|
61
63
|
const unpackedPaths = new Set();
|
|
62
64
|
const copiedFiles = new Set();
|
|
65
|
+
const createdSourceDirs = new Set();
|
|
66
|
+
const links = [];
|
|
67
|
+
const symlinkType = (0, os_1.platform)() === "win32" ? "junction" : "file";
|
|
63
68
|
const matchUnpacker = (file, dest, stat) => {
|
|
64
69
|
var _a, _b;
|
|
65
70
|
if ((_b = (_a = this.config).unpackPattern) === null || _b === void 0 ? void 0 : _b.call(_a, file, stat)) {
|
|
@@ -68,61 +73,71 @@ class AsarPackager {
|
|
|
68
73
|
return;
|
|
69
74
|
}
|
|
70
75
|
};
|
|
71
|
-
const
|
|
72
|
-
const { transformedData, file
|
|
76
|
+
const writeFileOrProcessSymlink = async (options) => {
|
|
77
|
+
const { transformedData, file, destination, stat, fileSet } = options;
|
|
78
|
+
if (!stat.isFile() && !stat.isSymbolicLink()) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
73
81
|
copiedFiles.add(destination);
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
82
|
+
const dir = path.dirname(destination);
|
|
83
|
+
if (!createdSourceDirs.has(dir)) {
|
|
84
|
+
await (0, fs_extra_1.mkdir)(dir, { recursive: true });
|
|
85
|
+
createdSourceDirs.add(dir);
|
|
77
86
|
}
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
return
|
|
87
|
+
// write any data if provided, skip symlink check
|
|
88
|
+
if (transformedData != null) {
|
|
89
|
+
return fs.writeFile(destination, transformedData, { mode: stat.mode });
|
|
81
90
|
}
|
|
82
|
-
const
|
|
91
|
+
const realPathFile = await fs.realpath(file);
|
|
92
|
+
const realPathRelative = path.relative(fileSet.src, realPathFile);
|
|
83
93
|
const isOutsidePackage = realPathRelative.startsWith("..");
|
|
84
94
|
if (isOutsidePackage) {
|
|
85
|
-
builder_util_1.log.error({ source: builder_util_1.log.filePath(
|
|
86
|
-
throw new Error(`Cannot copy file (${path.basename(
|
|
95
|
+
builder_util_1.log.error({ source: builder_util_1.log.filePath(file), realPathFile: builder_util_1.log.filePath(realPathFile) }, `unable to copy, file is symlinked outside the package`);
|
|
96
|
+
throw new Error(`Cannot copy file (${path.basename(file)}) symlinked to file (${path.basename(realPathFile)}) outside the package as that violates asar security integrity`);
|
|
87
97
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
// not a symlink, copy directly
|
|
99
|
+
if (file === realPathFile) {
|
|
100
|
+
return this.fileCopier.copy(file, destination, stat);
|
|
101
|
+
}
|
|
102
|
+
// okay, it must be a symlink. evaluate link to be relative to source file in asar
|
|
103
|
+
let link = await (0, fs_extra_1.readlink)(file);
|
|
104
|
+
if (path.isAbsolute(link)) {
|
|
105
|
+
link = path.relative(path.dirname(file), link);
|
|
106
|
+
}
|
|
107
|
+
links.push({ file: destination, link });
|
|
93
108
|
};
|
|
94
|
-
for
|
|
109
|
+
for (const fileSet of fileSets) {
|
|
95
110
|
if (this.config.options.smartUnpack !== false) {
|
|
96
|
-
(0, unpackDetector_1.detectUnpackedDirs)(fileSet, unpackedPaths
|
|
111
|
+
(0, unpackDetector_1.detectUnpackedDirs)(fileSet, unpackedPaths);
|
|
97
112
|
}
|
|
113
|
+
// Don't use BluebirdPromise, we need to retain order of execution/iteration through the ordered fileset
|
|
98
114
|
for (let i = 0; i < fileSet.files.length; i++) {
|
|
99
115
|
const file = fileSet.files[i];
|
|
100
116
|
const transformedData = (_a = fileSet.transformedFiles) === null || _a === void 0 ? void 0 : _a.get(i);
|
|
101
|
-
const
|
|
117
|
+
const stat = fileSet.metadata.get(file);
|
|
102
118
|
const relative = path.relative(this.config.defaultDestination, (0, appFileCopier_1.getDestinationPath)(file, fileSet));
|
|
103
|
-
const
|
|
104
|
-
matchUnpacker(file,
|
|
105
|
-
taskManager.addTask(
|
|
119
|
+
const destination = path.resolve(this.rootForAppFilesWithoutAsar, relative);
|
|
120
|
+
matchUnpacker(file, destination, stat);
|
|
121
|
+
taskManager.addTask(writeFileOrProcessSymlink({ transformedData, file, destination, stat, fileSet }));
|
|
106
122
|
if (taskManager.tasks.length > fs_1.MAX_FILE_REQUESTS) {
|
|
107
123
|
await taskManager.awaitTasks();
|
|
108
124
|
}
|
|
109
125
|
}
|
|
110
126
|
}
|
|
127
|
+
// finish copy then set up all symlinks
|
|
128
|
+
await taskManager.awaitTasks();
|
|
129
|
+
for (const it of links) {
|
|
130
|
+
taskManager.addTask((0, fs_extra_1.symlink)(it.link, it.file, symlinkType));
|
|
131
|
+
if (taskManager.tasks.length > fs_1.MAX_FILE_REQUESTS) {
|
|
132
|
+
await taskManager.awaitTasks();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
111
135
|
await taskManager.awaitTasks();
|
|
112
136
|
return {
|
|
113
137
|
unpackedPaths: Array.from(unpackedPaths),
|
|
114
138
|
copiedFiles: Array.from(copiedFiles),
|
|
115
139
|
};
|
|
116
140
|
}
|
|
117
|
-
async copyFileOrData(data, source, destination, stat) {
|
|
118
|
-
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
119
|
-
if (data) {
|
|
120
|
-
await fs.writeFile(destination, data, { mode: stat.mode });
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
await fs.copyFile(source, destination);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
141
|
}
|
|
127
142
|
exports.AsarPackager = AsarPackager;
|
|
128
143
|
function orderFileSet(fileSet) {
|
package/out/asar/asarUtil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asarUtil.js","sourceRoot":"","sources":["../../src/asar/asarUtil.ts"],"names":[],"mappings":";;;AAAA,yCAAwE;AACxE,+CAAoD;AACpD,+DAAwD;AACxD,4CAA+D;AAC/D,6BAA4B;AAC5B,+BAA8B;AAC9B,6BAA4B;AAC5B,sCAAqC;AAGrC,yDAA2E;AAC3E,qDAAqD;AAErD,gBAAgB;AAChB,MAAa,YAAY;IAKvB,YACmB,MAKhB;QALgB,WAAM,GAAN,MAAM,CAKtB;QARc,WAAM,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAA;QAU7C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAgC,EAAE,SAAgC;QAC3E,IAAI,CAAC,0BAA0B,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;QAEtF,MAAM,iBAAiB,GAAG,IAAI,wCAAiB,EAAE,CAAA;QACjD,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;QAE/D,MAAM,eAAe,GAAG;YACtB,qEAAqE;YACrE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YAEpB,mDAAmD;YACnD,QAAQ,CAAC,CAAC,CAAC;SACZ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAEnB,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAA;QACnG,MAAM,UAAU,GAAG,aAAa,CA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AI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC7B,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAA;QAE5B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;QAC1C,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,iBAAiB,CAAC,OAAO,EAAE,EAAE,CAAC;YACjE,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAClC,CAAC;QAED,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YACzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;gBACpC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,+BAA+B,CAAC,CAAA;YACzE,CAAC;YAED,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;IAED,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAE9C,OAAO;QACL,GAAG;QACH,WAAW;QACX,QAAQ;QACR,KAAK,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;QAChD,gBAAgB;KACjB,CAAA;AACH,CAAC","sourcesContent":["import { CreateOptions, createPackageWithOptions } from \"@electron/asar\"\nimport { AsyncTaskManager, log } from \"builder-util\"\nimport { CancellationToken } from \"builder-util-runtime\"\nimport { Filter, MAX_FILE_REQUESTS } from \"builder-util/out/fs\"\nimport * as fsNode from \"fs\"\nimport * as fs from \"fs-extra\"\nimport * as path from \"path\"\nimport * as tempFile from \"temp-file\"\nimport { AsarOptions } from \"../options/PlatformSpecificBuildOptions\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { ResolvedFileSet, getDestinationPath } from \"../util/appFileCopier\"\nimport { detectUnpackedDirs } from \"./unpackDetector\"\n\n/** @internal */\nexport class AsarPackager {\n private readonly outFile: string\n private rootForAppFilesWithoutAsar!: string\n private readonly tmpDir = new tempFile.TmpDir()\n\n constructor(\n private readonly config: {\n defaultDestination: string\n resourcePath: string\n options: AsarOptions\n unpackPattern: Filter | undefined\n }\n ) {\n this.outFile = path.join(config.resourcePath, `app.asar`)\n }\n\n async pack(fileSets: Array<ResolvedFileSet>, _packager: PlatformPackager<any>) {\n this.rootForAppFilesWithoutAsar = await this.tmpDir.getTempDir({ prefix: \"asar-app\" })\n\n const cancellationToken = new CancellationToken()\n cancellationToken.on(\"cancel\", () => this.tmpDir.cleanupSync())\n\n const orderedFileSets = [\n // Write dependencies first to minimize offset changes to asar header\n ...fileSets.slice(1),\n\n // Finish with the app files that change most often\n fileSets[0],\n ].map(orderFileSet)\n\n const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets, cancellationToken)\n const unpackGlob = unpackedPaths.length > 1 ? `{${unpackedPaths.join(\",\")}}` : unpackedPaths.pop()\n\n let ordering = this.config.options.ordering || undefined\n if (!ordering) {\n // `copiedFiles` are already ordered due to `orderedFileSets` input, so we just map to their relative paths (via substring) within the asar.\n const filesSorted = copiedFiles.map(file => file.substring(this.rootForAppFilesWithoutAsar.length))\n ordering = await this.tmpDir.getTempFile({ prefix: \"asar-ordering\", suffix: \".txt\" })\n await fs.writeFile(ordering, filesSorted.join(\"\\n\"))\n }\n\n const options: CreateOptions = {\n unpack: unpackGlob,\n unpackDir: unpackGlob,\n ordering,\n dot: true,\n }\n // override logger temporarily to clean up console (electron/asar does some internal logging that blogs up the default electron-builder logs)\n const consoleLogger = console.log\n console.log = (...args) => {\n if (args[0] === \"Ordering file has 100% coverage.\") {\n return // no need to log, this means our ordering logic is working correctly\n }\n log.info({ args }, \"logging @electron/asar\")\n }\n await createPackageWithOptions(this.rootForAppFilesWithoutAsar, this.outFile, options)\n console.log = consoleLogger\n\n await this.tmpDir.cleanup()\n }\n\n private async detectAndCopy(fileSets: ResolvedFileSet[], cancellationToken: CancellationToken) {\n const taskManager = new AsyncTaskManager(cancellationToken)\n const unpackedPaths = new Set<string>()\n const copiedFiles = new Set<string>()\n\n const matchUnpacker = (file: string, dest: string, stat: fs.Stats) => {\n if (this.config.unpackPattern?.(file, stat)) {\n log.debug({ file }, \"unpacking\")\n unpackedPaths.add(dest)\n return\n }\n }\n const writeFileOrSymlink = async (options: { transformedData: string | Buffer | undefined; file: string; destination: string; stat: fs.Stats; fileSet: ResolvedFileSet }) => {\n const {\n transformedData,\n file: source,\n destination,\n stat,\n fileSet: { src: sourceDir },\n } = options\n copiedFiles.add(destination)\n\n // If transformed data, skip symlink logic\n if (transformedData) {\n return this.copyFileOrData(transformedData, source, destination, stat)\n }\n\n const realPathFile = await fs.realpath(source)\n\n if (source === realPathFile) {\n return this.copyFileOrData(undefined, source, destination, stat)\n }\n\n const realPathRelative = path.relative(sourceDir, realPathFile)\n const isOutsidePackage = realPathRelative.startsWith(\"..\")\n if (isOutsidePackage) {\n log.error({ source: log.filePath(source), realPathFile: log.filePath(realPathFile) }, `unable to copy, file is symlinked outside the package`)\n throw new Error(\n `Cannot copy file (${path.basename(source)}) symlinked to file (${path.basename(realPathFile)}) outside the package as that violates asar security integrity`\n )\n }\n\n const symlinkTarget = path.resolve(this.rootForAppFilesWithoutAsar, realPathRelative)\n await this.copyFileOrData(undefined, source, symlinkTarget, stat)\n const target = path.relative(path.dirname(destination), symlinkTarget)\n fsNode.symlinkSync(target, destination)\n\n copiedFiles.add(symlinkTarget)\n }\n\n for await (const fileSet of fileSets) {\n if (this.config.options.smartUnpack !== false) {\n detectUnpackedDirs(fileSet, unpackedPaths, this.config.defaultDestination)\n }\n for (let i = 0; i < fileSet.files.length; i++) {\n const file = fileSet.files[i]\n const transformedData = fileSet.transformedFiles?.get(i)\n const metadata = fileSet.metadata.get(file) || (await fs.lstat(file))\n\n const relative = path.relative(this.config.defaultDestination, getDestinationPath(file, fileSet))\n const dest = path.resolve(this.rootForAppFilesWithoutAsar, relative)\n\n matchUnpacker(file, dest, metadata)\n taskManager.addTask(writeFileOrSymlink({ transformedData, file, destination: dest, stat: metadata, fileSet }))\n\n if (taskManager.tasks.length > MAX_FILE_REQUESTS) {\n await taskManager.awaitTasks()\n }\n }\n }\n await taskManager.awaitTasks()\n return {\n unpackedPaths: Array.from(unpackedPaths),\n copiedFiles: Array.from(copiedFiles),\n }\n }\n\n private async copyFileOrData(data: string | Buffer | undefined, source: string, destination: string, stat: fs.Stats) {\n await fs.mkdir(path.dirname(destination), { recursive: true })\n if (data) {\n await fs.writeFile(destination, data, { mode: stat.mode })\n } else {\n await fs.copyFile(source, destination)\n }\n }\n}\n\nfunction orderFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {\n const sortedFileEntries = Array.from(fileSet.files.entries())\n\n sortedFileEntries.sort(([, a], [, b]) => {\n if (a === b) {\n return 0\n }\n\n // Place addons last because their signature changes per build\n const isAAddon = a.endsWith(\".node\")\n const isBAddon = b.endsWith(\".node\")\n if (isAAddon && !isBAddon) {\n return 1\n }\n if (isBAddon && !isAAddon) {\n return -1\n }\n\n // Otherwise order by name\n return a < b ? -1 : 1\n })\n\n let transformedFiles: Map<number, string | Buffer> | undefined\n if (fileSet.transformedFiles) {\n transformedFiles = new Map()\n\n const indexMap = new Map<number, number>()\n for (const [newIndex, [oldIndex]] of sortedFileEntries.entries()) {\n indexMap.set(oldIndex, newIndex)\n }\n\n for (const [oldIndex, value] of fileSet.transformedFiles) {\n const newIndex = indexMap.get(oldIndex)\n if (newIndex === undefined) {\n const file = fileSet.files[oldIndex]\n throw new Error(`Internal error: ${file} was lost while ordering asar`)\n }\n\n transformedFiles.set(newIndex, value)\n }\n }\n\n const { src, destination, metadata } = fileSet\n\n return {\n src,\n destination,\n metadata,\n files: sortedFileEntries.map(([, file]) => file),\n transformedFiles,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"asarUtil.js","sourceRoot":"","sources":["../../src/asar/asarUtil.ts"],"names":[],"mappings":";;;AAAA,yCAAwE;AACxE,+CAAoD;AAEpD,4CAAiF;AACjF,+BAA8B;AAC9B,uCAAmD;AACnD,2BAA6B;AAC7B,6BAA4B;AAI5B,yDAA2E;AAC3E,qDAAqD;AAErD,gBAAgB;AAChB,MAAa,YAAY;IAOvB,YACW,QAA+B,EACvB,MAKhB;QANQ,aAAQ,GAAR,QAAQ,CAAuB;QACvB,WAAM,GAAN,MAAM,CAKtB;QAXc,eAAU,GAAG,IAAI,eAAU,EAAE,CAAA;QAa5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;QACzD,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAA;QAC1C,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAA;IAC1D,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAgC;QACzC,IAAI,CAAC,0BAA0B,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;QAEtF,MAAM,eAAe,GAAG;YACtB,qEAAqE;YACrE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YAEpB,mDAAmD;YACnD,QAAQ,CAAC,CAAC,CAAC;SACZ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAEnB,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAA;QAChF,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,aAAa,CA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QACR,KAAK,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;QAChD,gBAAgB;KACjB,CAAA;AACH,CAAC","sourcesContent":["import { CreateOptions, createPackageWithOptions } from \"@electron/asar\"\nimport { AsyncTaskManager, log } from \"builder-util\"\nimport { CancellationToken } from \"builder-util-runtime\"\nimport { FileCopier, Filter, Link, MAX_FILE_REQUESTS } from \"builder-util/out/fs\"\nimport * as fs from \"fs-extra\"\nimport { mkdir, readlink, symlink } from \"fs-extra\"\nimport { platform } from \"os\"\nimport * as path from \"path\"\nimport * as tempFile from \"temp-file\"\nimport { AsarOptions } from \"../options/PlatformSpecificBuildOptions\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { ResolvedFileSet, getDestinationPath } from \"../util/appFileCopier\"\nimport { detectUnpackedDirs } from \"./unpackDetector\"\n\n/** @internal */\nexport class AsarPackager {\n private readonly outFile: string\n private rootForAppFilesWithoutAsar!: string\n private readonly fileCopier = new FileCopier()\n private readonly tmpDir: tempFile.TmpDir\n private readonly cancellationToken: CancellationToken\n\n constructor(\n readonly packager: PlatformPackager<any>,\n private readonly config: {\n defaultDestination: string\n resourcePath: string\n options: AsarOptions\n unpackPattern: Filter | undefined\n }\n ) {\n this.outFile = path.join(config.resourcePath, `app.asar`)\n this.tmpDir = packager.info.tempDirManager\n this.cancellationToken = packager.info.cancellationToken\n }\n\n async pack(fileSets: Array<ResolvedFileSet>) {\n this.rootForAppFilesWithoutAsar = await this.tmpDir.getTempDir({ prefix: \"asar-app\" })\n\n const orderedFileSets = [\n // Write dependencies first to minimize offset changes to asar header\n ...fileSets.slice(1),\n\n // Finish with the app files that change most often\n fileSets[0],\n ].map(orderFileSet)\n\n const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets)\n const unpackGlob = unpackedPaths.length > 1 ? `{${unpackedPaths.join(\",\")}}` : unpackedPaths.pop()\n\n await this.executeElectronAsar(copiedFiles, unpackGlob)\n }\n\n private async executeElectronAsar(copiedFiles: string[], unpackGlob: string | undefined) {\n let ordering = this.config.options.ordering || undefined\n if (!ordering) {\n // `copiedFiles` are already ordered due to `orderedFileSets` input, so we just map to their relative paths (via substring) within the asar.\n const filesSorted = copiedFiles.map(file => file.substring(this.rootForAppFilesWithoutAsar.length))\n ordering = await this.tmpDir.getTempFile({ prefix: \"asar-ordering\", suffix: \".txt\" })\n await fs.writeFile(ordering, filesSorted.join(\"\\n\"))\n }\n\n const options: CreateOptions = {\n unpack: unpackGlob,\n unpackDir: unpackGlob,\n ordering,\n dot: true,\n }\n // override logger temporarily to clean up console (electron/asar does some internal logging that blogs up the default electron-builder logs)\n const consoleLogger = console.log\n console.log = (...args) => {\n if (args[0] === \"Ordering file has 100% coverage.\") {\n return // no need to log, this means our ordering logic is working correctly\n }\n log.info({ args }, \"logging @electron/asar\")\n }\n await createPackageWithOptions(this.rootForAppFilesWithoutAsar, this.outFile, options)\n console.log = consoleLogger\n }\n\n private async detectAndCopy(fileSets: ResolvedFileSet[]) {\n const taskManager = new AsyncTaskManager(this.cancellationToken)\n const unpackedPaths = new Set<string>()\n const copiedFiles = new Set<string>()\n\n const createdSourceDirs = new Set<string>()\n const links: Array<Link> = []\n const symlinkType = platform() === \"win32\" ? \"junction\" : \"file\"\n\n const matchUnpacker = (file: string, dest: string, stat: fs.Stats) => {\n if (this.config.unpackPattern?.(file, stat)) {\n log.debug({ file }, \"unpacking\")\n unpackedPaths.add(dest)\n return\n }\n }\n const writeFileOrProcessSymlink = async (options: {\n file: string\n destination: string\n stat: fs.Stats\n fileSet: ResolvedFileSet\n transformedData: string | Buffer | undefined\n }) => {\n const { transformedData, file, destination, stat, fileSet } = options\n if (!stat.isFile() && !stat.isSymbolicLink()) {\n return\n }\n copiedFiles.add(destination)\n\n const dir = path.dirname(destination)\n if (!createdSourceDirs.has(dir)) {\n await mkdir(dir, { recursive: true })\n createdSourceDirs.add(dir)\n }\n\n // write any data if provided, skip symlink check\n if (transformedData != null) {\n return fs.writeFile(destination, transformedData, { mode: stat.mode })\n }\n\n const realPathFile = await fs.realpath(file)\n const realPathRelative = path.relative(fileSet.src, realPathFile)\n const isOutsidePackage = realPathRelative.startsWith(\"..\")\n if (isOutsidePackage) {\n log.error({ source: log.filePath(file), realPathFile: log.filePath(realPathFile) }, `unable to copy, file is symlinked outside the package`)\n throw new Error(`Cannot copy file (${path.basename(file)}) symlinked to file (${path.basename(realPathFile)}) outside the package as that violates asar security integrity`)\n }\n\n // not a symlink, copy directly\n if (file === realPathFile) {\n return this.fileCopier.copy(file, destination, stat)\n }\n\n // okay, it must be a symlink. evaluate link to be relative to source file in asar\n let link = await readlink(file)\n if (path.isAbsolute(link)) {\n link = path.relative(path.dirname(file), link)\n }\n links.push({ file: destination, link })\n }\n\n for (const fileSet of fileSets) {\n if (this.config.options.smartUnpack !== false) {\n detectUnpackedDirs(fileSet, unpackedPaths)\n }\n\n // Don't use BluebirdPromise, we need to retain order of execution/iteration through the ordered fileset\n for (let i = 0; i < fileSet.files.length; i++) {\n const file = fileSet.files[i]\n const transformedData = fileSet.transformedFiles?.get(i)\n const stat = fileSet.metadata.get(file)!\n\n const relative = path.relative(this.config.defaultDestination, getDestinationPath(file, fileSet))\n const destination = path.resolve(this.rootForAppFilesWithoutAsar, relative)\n\n matchUnpacker(file, destination, stat)\n taskManager.addTask(writeFileOrProcessSymlink({ transformedData, file, destination, stat, fileSet }))\n\n if (taskManager.tasks.length > MAX_FILE_REQUESTS) {\n await taskManager.awaitTasks()\n }\n }\n }\n // finish copy then set up all symlinks\n await taskManager.awaitTasks()\n for (const it of links) {\n taskManager.addTask(symlink(it.link, it.file, symlinkType))\n\n if (taskManager.tasks.length > MAX_FILE_REQUESTS) {\n await taskManager.awaitTasks()\n }\n }\n await taskManager.awaitTasks()\n return {\n unpackedPaths: Array.from(unpackedPaths),\n copiedFiles: Array.from(copiedFiles),\n }\n }\n}\n\nfunction orderFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {\n const sortedFileEntries = Array.from(fileSet.files.entries())\n\n sortedFileEntries.sort(([, a], [, b]) => {\n if (a === b) {\n return 0\n }\n\n // Place addons last because their signature changes per build\n const isAAddon = a.endsWith(\".node\")\n const isBAddon = b.endsWith(\".node\")\n if (isAAddon && !isBAddon) {\n return 1\n }\n if (isBAddon && !isAAddon) {\n return -1\n }\n\n // Otherwise order by name\n return a < b ? -1 : 1\n })\n\n let transformedFiles: Map<number, string | Buffer> | undefined\n if (fileSet.transformedFiles) {\n transformedFiles = new Map()\n\n const indexMap = new Map<number, number>()\n for (const [newIndex, [oldIndex]] of sortedFileEntries.entries()) {\n indexMap.set(oldIndex, newIndex)\n }\n\n for (const [oldIndex, value] of fileSet.transformedFiles) {\n const newIndex = indexMap.get(oldIndex)\n if (newIndex === undefined) {\n const file = fileSet.files[oldIndex]\n throw new Error(`Internal error: ${file} was lost while ordering asar`)\n }\n\n transformedFiles.set(newIndex, value)\n }\n }\n\n const { src, destination, metadata } = fileSet\n\n return {\n src,\n destination,\n metadata,\n files: sortedFileEntries.map(([, file]) => file),\n transformedFiles,\n }\n}\n"]}
|
|
@@ -5,71 +5,26 @@ exports.detectUnpackedDirs = detectUnpackedDirs;
|
|
|
5
5
|
const builder_util_1 = require("builder-util");
|
|
6
6
|
const isbinaryfile_1 = require("isbinaryfile");
|
|
7
7
|
const path = require("path");
|
|
8
|
-
const fileTransformer_1 = require("../fileTransformer");
|
|
9
|
-
const appFileCopier_1 = require("../util/appFileCopier");
|
|
10
|
-
function addValue(map, key, value) {
|
|
11
|
-
let list = map.get(key);
|
|
12
|
-
if (list == null) {
|
|
13
|
-
list = [value];
|
|
14
|
-
map.set(key, list);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
list.push(value);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
8
|
function isLibOrExe(file) {
|
|
21
9
|
// https://github.com/electron-userland/electron-builder/issues/3038
|
|
22
10
|
return file.endsWith(".dll") || file.endsWith(".exe") || file.endsWith(".dylib") || file.endsWith(".so") || file.endsWith(".node");
|
|
23
11
|
}
|
|
24
12
|
/** @internal */
|
|
25
|
-
function detectUnpackedDirs(fileSet, autoUnpackDirs
|
|
26
|
-
const dirToCreate = new Map();
|
|
13
|
+
function detectUnpackedDirs(fileSet, autoUnpackDirs) {
|
|
27
14
|
const metadata = fileSet.metadata;
|
|
28
|
-
function addParents(child, root) {
|
|
29
|
-
child = path.dirname(child);
|
|
30
|
-
if (autoUnpackDirs.has(child)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
do {
|
|
34
|
-
autoUnpackDirs.add(child);
|
|
35
|
-
const p = path.dirname(child);
|
|
36
|
-
// create parent dir to be able to copy file later without directory existence check
|
|
37
|
-
addValue(dirToCreate, p, path.basename(child));
|
|
38
|
-
if (child === root || p === root || autoUnpackDirs.has(p)) {
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
child = p;
|
|
42
|
-
} while (true);
|
|
43
|
-
autoUnpackDirs.add(root);
|
|
44
|
-
}
|
|
45
15
|
for (let i = 0, n = fileSet.files.length; i < n; i++) {
|
|
46
16
|
const file = fileSet.files[i];
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
let nextSlashIndex = file.indexOf(path.sep, index + fileTransformer_1.NODE_MODULES_PATTERN.length + 1);
|
|
52
|
-
if (nextSlashIndex < 0) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (file[index + fileTransformer_1.NODE_MODULES_PATTERN.length] === "@") {
|
|
56
|
-
nextSlashIndex = file.indexOf(path.sep, nextSlashIndex + 1);
|
|
57
|
-
}
|
|
58
|
-
if (!metadata.get(file).isFile()) {
|
|
17
|
+
const stat = metadata.get(file);
|
|
18
|
+
if (!stat.moduleRootPath || autoUnpackDirs.has(stat.moduleRootPath)) {
|
|
59
19
|
continue;
|
|
60
20
|
}
|
|
61
|
-
|
|
62
|
-
const packageDirPathInArchive = path.relative(defaultDestination, (0, appFileCopier_1.getDestinationPath)(packageDir, fileSet));
|
|
63
|
-
const pathInArchive = path.relative(defaultDestination, (0, appFileCopier_1.getDestinationPath)(file, fileSet));
|
|
64
|
-
if (autoUnpackDirs.has(packageDirPathInArchive)) {
|
|
65
|
-
// if package dir is unpacked, any file also unpacked
|
|
66
|
-
addParents(pathInArchive, packageDirPathInArchive);
|
|
21
|
+
if (!stat.isFile()) {
|
|
67
22
|
continue;
|
|
68
23
|
}
|
|
69
24
|
// https://github.com/electron-userland/electron-builder/issues/2679
|
|
70
25
|
let shouldUnpack = false;
|
|
71
26
|
// ffprobe-static and ffmpeg-static are known packages to always unpack
|
|
72
|
-
const moduleName =
|
|
27
|
+
const moduleName = stat.moduleName;
|
|
73
28
|
const fileBaseName = path.basename(file);
|
|
74
29
|
const hasExtension = path.extname(fileBaseName);
|
|
75
30
|
if (moduleName === "ffprobe-static" || moduleName === "ffmpeg-static" || isLibOrExe(file)) {
|
|
@@ -82,9 +37,9 @@ function detectUnpackedDirs(fileSet, autoUnpackDirs, defaultDestination) {
|
|
|
82
37
|
continue;
|
|
83
38
|
}
|
|
84
39
|
if (builder_util_1.log.isDebugEnabled) {
|
|
85
|
-
builder_util_1.log.debug({ file:
|
|
40
|
+
builder_util_1.log.debug({ file: stat.moduleFullFilePath, reason: "contains executable code" }, "not packed into asar archive");
|
|
86
41
|
}
|
|
87
|
-
|
|
42
|
+
autoUnpackDirs.add(stat.moduleRootPath);
|
|
88
43
|
}
|
|
89
44
|
}
|
|
90
45
|
//# sourceMappingURL=unpackDetector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unpackDetector.js","sourceRoot":"","sources":["../../src/asar/unpackDetector.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"unpackDetector.js","sourceRoot":"","sources":["../../src/asar/unpackDetector.ts"],"names":[],"mappings":";;AAKA,gCAGC;AAGD,gDAmCC;AA9CD,+CAA+C;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,IAAI,CAAC,EAAE,CAAC;YAC1F,YAAY,GAAG,IAAI,CAAA;QACrB,CAAC;aAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YACzB,YAAY,GAAG,CAAC,CAAC,IAAA,+BAAgB,EAAC,IAAI,CAAC,CAAA;QACzC,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,SAAQ;QACV,CAAC;QAED,IAAI,kBAAG,CAAC,cAAc,EAAE,CAAC;YACvB,kBAAG,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,EAAE,0BAA0B,EAAE,EAAE,8BAA8B,CAAC,CAAA;QAClH,CAAC;QACD,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IACzC,CAAC;AACH,CAAC","sourcesContent":["import { log, FilterStats } from \"builder-util\"\nimport { isBinaryFileSync } from \"isbinaryfile\"\nimport * as path from \"path\"\nimport { ResolvedFileSet } from \"../util/appFileCopier\"\n\nexport function isLibOrExe(file: string): boolean {\n // https://github.com/electron-userland/electron-builder/issues/3038\n return file.endsWith(\".dll\") || file.endsWith(\".exe\") || file.endsWith(\".dylib\") || file.endsWith(\".so\") || file.endsWith(\".node\")\n}\n\n/** @internal */\nexport function detectUnpackedDirs(fileSet: ResolvedFileSet, autoUnpackDirs: Set<string>) {\n const metadata = fileSet.metadata\n\n for (let i = 0, n = fileSet.files.length; i < n; i++) {\n const file = fileSet.files[i]\n const stat: FilterStats = metadata.get(file)!\n if (!stat.moduleRootPath || autoUnpackDirs.has(stat.moduleRootPath)) {\n continue\n }\n\n if (!stat.isFile()) {\n continue\n }\n\n // https://github.com/electron-userland/electron-builder/issues/2679\n let shouldUnpack = false\n // ffprobe-static and ffmpeg-static are known packages to always unpack\n const moduleName = stat.moduleName\n const fileBaseName = path.basename(file)\n const hasExtension = path.extname(fileBaseName)\n if (moduleName === \"ffprobe-static\" || moduleName === \"ffmpeg-static\" || isLibOrExe(file)) {\n shouldUnpack = true\n } else if (!hasExtension) {\n shouldUnpack = !!isBinaryFileSync(file)\n }\n\n if (!shouldUnpack) {\n continue\n }\n\n if (log.isDebugEnabled) {\n log.debug({ file: stat.moduleFullFilePath, reason: \"contains executable code\" }, \"not packed into asar archive\")\n }\n autoUnpackDirs.add(stat.moduleRootPath)\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ exports.addWinAsarIntegrity = addWinAsarIntegrity;
|
|
|
4
4
|
const promises_1 = require("fs/promises");
|
|
5
5
|
const builder_util_1 = require("builder-util");
|
|
6
6
|
const resedit_1 = require("resedit");
|
|
7
|
+
const path = require("path");
|
|
7
8
|
/** @internal */
|
|
8
9
|
async function addWinAsarIntegrity(executablePath, asarIntegrity) {
|
|
9
10
|
const buffer = await (0, promises_1.readFile)(executablePath);
|
|
@@ -19,7 +20,7 @@ async function addWinAsarIntegrity(executablePath, asarIntegrity) {
|
|
|
19
20
|
}
|
|
20
21
|
// See: https://github.com/electron/packager/blob/00d20b99cf4aa4621103dbbd09ff7de7d2f7f539/src/resedit.ts#L124
|
|
21
22
|
const integrityList = Array.from(Object.entries(asarIntegrity)).map(([file, { algorithm: alg, hash: value }]) => ({
|
|
22
|
-
file,
|
|
23
|
+
file: path.win32.normalize(file),
|
|
23
24
|
alg,
|
|
24
25
|
value,
|
|
25
26
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electronWin.js","sourceRoot":"","sources":["../../src/electron/electronWin.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"electronWin.js","sourceRoot":"","sources":["../../src/electron/electronWin.ts"],"names":[],"mappings":";;AAOA,kDAkCC;AAzCD,0CAAiD;AACjD,+CAAkC;AAClC,qCAAsE;AACtE,6BAA4B;AAG5B,gBAAgB;AACT,KAAK,UAAU,mBAAmB,CAAC,cAAsB,EAAE,aAA4B;IAC5F,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAQ,EAAC,cAAc,CAAC,CAAA;IAC7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AAc,CAAC,UAAU,CAAC,CAAA;IAEnC,MAAM,IAAA,oBAAS,EAAC,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;IACnE,kBAAG,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,kBAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,EAAE,6CAA6C,CAAC,CAAA;AAC3G,CAAC","sourcesContent":["import { readFile, writeFile } from \"fs/promises\"\nimport { log } from \"builder-util\"\nimport { NtExecutable, NtExecutableResource, Resource } from \"resedit\"\nimport * as path from \"path\"\nimport { AsarIntegrity } from \"../asar/integrity\"\n\n/** @internal */\nexport async function addWinAsarIntegrity(executablePath: string, asarIntegrity: AsarIntegrity) {\n const buffer = await readFile(executablePath)\n const executable = NtExecutable.from(buffer)\n const resource = NtExecutableResource.from(executable)\n\n const versionInfo = Resource.VersionInfo.fromEntries(resource.entries)\n if (versionInfo.length !== 1) {\n throw new Error(`Failed to parse version info in ${executablePath}`)\n }\n\n const languages = versionInfo[0].getAllLanguagesForStringValues()\n if (languages.length !== 1) {\n throw new Error(`Failed to locate languages in ${executablePath}`)\n }\n\n // See: https://github.com/electron/packager/blob/00d20b99cf4aa4621103dbbd09ff7de7d2f7f539/src/resedit.ts#L124\n const integrityList = Array.from(Object.entries(asarIntegrity)).map(([file, { algorithm: alg, hash: value }]) => ({\n file: path.win32.normalize(file),\n alg,\n value,\n }))\n\n resource.entries.push({\n type: \"INTEGRITY\",\n id: \"ELECTRONASAR\",\n bin: Buffer.from(JSON.stringify(integrityList)),\n lang: languages[0].lang,\n codepage: languages[0].codepage,\n })\n\n resource.outputResource(executable)\n\n await writeFile(executablePath, Buffer.from(executable.generate()))\n log.info({ executablePath: log.filePath(executablePath) }, \"updating asar integrity executable resource\")\n}\n"]}
|
package/out/macPackager.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare class MacPackager extends PlatformPackager<MacConfiguration> {
|
|
|
22
22
|
pack(outDir: string, arch: Arch, targets: Array<Target>, taskManager: AsyncTaskManager): Promise<void>;
|
|
23
23
|
private sign;
|
|
24
24
|
private getOptionsForFile;
|
|
25
|
-
protected doSign(opts: SignOptions, customSignOptions: MacConfiguration): Promise<void>;
|
|
25
|
+
protected doSign(opts: SignOptions, customSignOptions: MacConfiguration, identity: Identity | null): Promise<void>;
|
|
26
26
|
protected doFlat(appPath: string, outFile: string, identity: Identity, keychain: string | null | undefined): Promise<any>;
|
|
27
27
|
getElectronSrcDir(dist: string): string;
|
|
28
28
|
getElectronDestinationDir(appOutDir: string): string;
|
package/out/macPackager.js
CHANGED
|
@@ -271,7 +271,7 @@ class MacPackager extends platformPackager_1.PlatformPackager {
|
|
|
271
271
|
optionsForFile: await this.getOptionsForFile(appPath, isMas, customSignOptions),
|
|
272
272
|
provisioningProfile: customSignOptions.provisioningProfile || undefined,
|
|
273
273
|
};
|
|
274
|
-
await this.doSign(signOptions, customSignOptions);
|
|
274
|
+
await this.doSign(signOptions, customSignOptions, identity);
|
|
275
275
|
// https://github.com/electron-userland/electron-builder/issues/1196#issuecomment-312310209
|
|
276
276
|
if (masOptions != null && !isDevelopment) {
|
|
277
277
|
const certType = isDevelopment ? "Mac Developer" : "3rd Party Mac Developer Installer";
|
|
@@ -341,14 +341,15 @@ class MacPackager extends platformPackager_1.PlatformPackager {
|
|
|
341
341
|
return optionsForFile;
|
|
342
342
|
}
|
|
343
343
|
//noinspection JSMethodCanBeStatic
|
|
344
|
-
async doSign(opts, customSignOptions) {
|
|
344
|
+
async doSign(opts, customSignOptions, identity) {
|
|
345
345
|
const customSign = await (0, resolve_1.resolveFunction)(this.appInfo.type, customSignOptions.sign, "sign");
|
|
346
|
-
const { app, platform, type,
|
|
346
|
+
const { app, platform, type, provisioningProfile } = opts;
|
|
347
347
|
builder_util_1.log.info({
|
|
348
348
|
file: builder_util_1.log.filePath(app),
|
|
349
349
|
platform,
|
|
350
350
|
type,
|
|
351
|
-
identity: identity || "none",
|
|
351
|
+
identityName: (identity === null || identity === void 0 ? void 0 : identity.name) || "none",
|
|
352
|
+
identityHash: (identity === null || identity === void 0 ? void 0 : identity.hash) || "none",
|
|
352
353
|
provisioningProfile: provisioningProfile || "none",
|
|
353
354
|
}, customSign ? "executing custom sign" : "signing");
|
|
354
355
|
return customSign ? Promise.resolve(customSign(opts, this)) : (0, macCodeSign_1.sign)(opts);
|