diff --git a/package.json b/package.json index f435f5e59a2..ffff1d96482 100644 --- a/package.json +++ b/package.json @@ -60,14 +60,14 @@ "dependencies": { "7zip-bin": "^1.0.5", "ansi-escapes": "^1.4.0", - "asar": "^0.12.0", + "@develar/asar": "^0.13.1", "bluebird": "^3.4.1", "chalk": "^1.1.3", "cli-cursor": "^1.0.2", "debug": "^2.2.0", "electron-download": "^2.1.2", "electron-osx-sign": "^0.4.0-beta4", - "electron-winstaller-fixed": "~3.0.0", + "electron-winstaller-fixed": "~3.1.0", "extract-zip": "^1.5.0", "fs-extra-p": "^1.0.5", "hosted-git-info": "^2.1.5", @@ -103,6 +103,7 @@ ] }, "devDependencies": { + "@develar/asar": "^0.13.1", "@develar/semantic-release": "^6.3.1", "@types/debug": "0.0.28", "@types/mime": "0.0.28", diff --git a/src/asarUtil.ts b/src/asarUtil.ts index 5d671563820..590035a4dc5 100644 --- a/src/asarUtil.ts +++ b/src/asarUtil.ts @@ -1,4 +1,4 @@ -import { AsarFileInfo, listPackage, statFile, AsarOptions, AsarFileMetadata, createPackageFromFiles } from "asar" +import { AsarFileInfo, listPackage, statFile, AsarOptions, AsarFileMetadata, createPackageFromFiles } from "@develar/asar" import { statOrNull } from "./util/util" import { lstat, readdir } from "fs-extra-p" import { Promise as BluebirdPromise } from "bluebird" diff --git a/src/metadata.ts b/src/metadata.ts index 2891d53b83f..a7497a561da 100755 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -1,4 +1,4 @@ -import { AsarOptions } from "asar" +import { AsarOptions } from "@develar/asar" import { ElectronPackagerOptions } from "./packager/dirPackager" export interface Metadata { diff --git a/src/platformPackager.ts b/src/platformPackager.ts index 4e33a001855..4ddd11ebd38 100644 --- a/src/platformPackager.ts +++ b/src/platformPackager.ts @@ -5,7 +5,7 @@ import * as path from "path" import { readdir, remove, realpath } from "fs-extra-p" import { statOrNull, use, unlinkIfExists, isEmptyOrSpaces } from "./util/util" import { Packager } from "./packager" -import { AsarOptions } from "asar" +import { AsarOptions } from "@develar/asar" import { archiveApp } from "./targets/archive" import { Minimatch } from "minimatch" import { checkFileInPackage, createAsarArchive } from "./asarUtil" @@ -156,61 +156,61 @@ export abstract class PlatformPackager protected async doPack(options: ElectronPackagerOptions, outDir: string, appOutDir: string, platformName: string, arch: Arch, platformSpecificBuildOptions: DC) { const asarOptions = this.computeAsarOptions(platformSpecificBuildOptions) - await task(`Packaging for platform ${platformName} ${Arch[arch]} using electron ${this.info.electronVersion} to ${path.relative(this.projectDir, appOutDir)}`, - pack(options, appOutDir, platformName, Arch[arch], this.info.electronVersion, async () => { - const ignoreFiles = new Set([path.relative(this.info.appDir, outDir), path.relative(this.info.appDir, this.buildResourcesDir)]) - if (!this.info.isTwoPackageJsonProjectLayoutUsed) { - const result = await BluebirdPromise.all([listDependencies(this.info.appDir, false), listDependencies(this.info.appDir, true)]) - const productionDepsSet = new Set(result[1]) - - // npm returns real path, so, we should use relative path to avoid any mismatch - const realAppDirPath = await realpath(this.info.appDir) - - for (let it of result[0]) { - if (!productionDepsSet.has(it)) { - if (it.startsWith(realAppDirPath)) { - it = it.substring(realAppDirPath.length + 1) - } - else if (it.startsWith(this.info.appDir)) { - it = it.substring(this.info.appDir.length + 1) - } - ignoreFiles.add(it) - } - } + const p = pack(options, appOutDir, platformName, Arch[arch], this.info.electronVersion, async() => { + const ignoreFiles = new Set([path.relative(this.info.appDir, outDir), path.relative(this.info.appDir, this.buildResourcesDir)]) + if (!this.info.isTwoPackageJsonProjectLayoutUsed) { + const result = await BluebirdPromise.all([listDependencies(this.info.appDir, false), listDependencies(this.info.appDir, true)]) + const productionDepsSet = new Set(result[1]) + + // npm returns real path, so, we should use relative path to avoid any mismatch + const realAppDirPath = await realpath(this.info.appDir) + + for (let it of result[0]) { + if (!productionDepsSet.has(it)) { + if (it.startsWith(realAppDirPath)) { + it = it.substring(realAppDirPath.length + 1) } - - let patterns = this.getFilePatterns("files", platformSpecificBuildOptions) - if (patterns == null || patterns.length === 0) { - patterns = ["**/*"] + else if (it.startsWith(this.info.appDir)) { + it = it.substring(this.info.appDir.length + 1) } + ignoreFiles.add(it) + } + } + } - let rawFilter: any = null - const deprecatedIgnore = (this.devMetadata.build).ignore - if (deprecatedIgnore) { - if (typeof deprecatedIgnore === "function") { - log(`"ignore is specified as function, may be new "files" option will be suit your needs? Please see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`) - } - else { - warn(`"ignore is deprecated, please use "files", see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`) - } - rawFilter = deprecatedUserIgnoreFilter(options, this.info.appDir) - } + let patterns = this.getFilePatterns("files", platformSpecificBuildOptions) + if (patterns == null || patterns.length === 0) { + patterns = ["**/*"] + } + patterns.push("!**/node_modules/*/{README.md,README,readme.md,readme,test}") + + let rawFilter: any = null + const deprecatedIgnore = (this.devMetadata.build).ignore + if (deprecatedIgnore) { + if (typeof deprecatedIgnore === "function") { + log(`"ignore is specified as function, may be new "files" option will be suit your needs? Please see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`) + } + else { + warn(`"ignore is deprecated, please use "files", see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`) + } + rawFilter = deprecatedUserIgnoreFilter(options, this.info.appDir) + } - const resourcesPath = this.platform === Platform.MAC ? path.join(appOutDir, "Electron.app", "Contents", "Resources") : path.join(appOutDir, "resources") - const filter = createFilter(this.info.appDir, this.getParsedPatterns(patterns, arch), ignoreFiles, rawFilter) - const promise = asarOptions == null ? - copyFiltered(this.info.appDir, path.join(resourcesPath, "app"), filter, this.platform === Platform.WINDOWS) - : createAsarArchive(this.info.appDir, resourcesPath, asarOptions, filter) + const resourcesPath = this.platform === Platform.MAC ? path.join(appOutDir, "Electron.app", "Contents", "Resources") : path.join(appOutDir, "resources") + const filter = createFilter(this.info.appDir, this.getParsedPatterns(patterns, arch), ignoreFiles, rawFilter) + const promise = asarOptions == null ? + copyFiltered(this.info.appDir, path.join(resourcesPath, "app"), filter, this.platform === Platform.WINDOWS) + : createAsarArchive(this.info.appDir, resourcesPath, asarOptions, filter) - const promises = [promise, unlinkIfExists(path.join(resourcesPath, "default_app.asar")), unlinkIfExists(path.join(appOutDir, "version"))] - if (this.info.electronVersion[0] === "0") { - // electron release >= 0.37.4 - the default_app/ folder is a default_app.asar file - promises.push(remove(path.join(resourcesPath, "default_app"))) - } + const promises = [promise, unlinkIfExists(path.join(resourcesPath, "default_app.asar")), unlinkIfExists(path.join(appOutDir, "version"))] + if (this.info.electronVersion[0] === "0") { + // electron release >= 0.37.4 - the default_app/ folder is a default_app.asar file + promises.push(remove(path.join(resourcesPath, "default_app"))) + } - await BluebirdPromise.all(promises) - } - )) + await BluebirdPromise.all(promises) + }) + await task(`Packaging for platform ${platformName} ${Arch[arch]} using electron ${this.info.electronVersion} to ${path.relative(this.projectDir, appOutDir)}`, p) await this.doCopyExtraFiles(true, appOutDir, arch, platformSpecificBuildOptions) await this.doCopyExtraFiles(false, appOutDir, arch, platformSpecificBuildOptions) diff --git a/src/targets/squirrelWindows.ts b/src/targets/squirrelWindows.ts index e3508eb430d..6826a1e01e5 100644 --- a/src/targets/squirrelWindows.ts +++ b/src/targets/squirrelWindows.ts @@ -86,12 +86,7 @@ export default class SquirrelWindowsTarget extends Target { extraMetadataSpecs: projectUrl == null ? null : `\n ${projectUrl}`, copyright: appInfo.copyright, packageCompressionLevel: packager.devMetadata.build.compression === "store" ? 0 : 9, - sign: { - name: appInfo.productName, - site: projectUrl, - overwrite: true, - hash: packager.platformSpecificBuildOptions.signingHashAlgorithms, - }, + sign: this.packager.sign.bind(this.packager), rcedit: rceditOptions, }, packager.platformSpecificBuildOptions) diff --git a/typings/asar.d.ts b/typings/asar.d.ts index 0d21ccb9e66..f752c7f4f88 100644 --- a/typings/asar.d.ts +++ b/typings/asar.d.ts @@ -1,4 +1,4 @@ -declare module "asar" { +declare module "@develar/asar" { import { Stats } from "fs" interface AsarFileInfo {