Skip to content

Commit

Permalink
fix: do not copy electronDist using hard links
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 14, 2017
1 parent 157c730 commit 9cfb09a
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 48 deletions.
1 change: 1 addition & 0 deletions .idea/electron-builder.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions docs/api/electron-builder-util.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@

### FileCopier
**Kind**: class of [<code>electron-builder-util/out/fs</code>](#module_electron-builder-util/out/fs)
**Properties**

| Name | Type |
| --- | --- |
| **isUseHardLink**| <code>Boolean</code> |

<a name="module_electron-builder-util/out/fs.FileCopier+copy"></a>

#### `fileCopier.copy(src, dest, stat)` ⇒ <code>Promise&lt;void&gt;</code>
Expand All @@ -117,8 +123,8 @@ Hard links is used if supported and allowed.
| --- | --- |
| src | <code>String</code> |
| destination | <code>String</code> |
| filter | <code>module:electron-builder-util/out/fs.__type</code> |
| transformer | <code>module:electron-builder-util/out/fs.__type</code> |
| filter | <code>module:electron-builder-util/out/fs.__type</code> \| <code>null</code> |
| transformer | <code>module:electron-builder-util/out/fs.__type</code> \| <code>null</code> |
| isUseHardLink | <code>callback</code> |

<a name="module_electron-builder-util/out/fs.copyFile"></a>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"update-deps": "node ./packages/update-deps.js",
"set-versions": "node test/out/helpers/setVersions.js",
"npm-publish": "yarn set-versions && yarn compile && ./packages/npm-publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
"schema": "typescript-json-schema packages/electron-builder/tsconfig.json Config --out packages/electron-builder/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --titles",
"schema": "typescript-json-schema packages/electron-builder/tsconfig.json Config --out packages/electron-builder/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --titles --required",
"jsdoc": "ts2jsdoc packages/electron-builder-http packages/electron-updater packages/electron-builder-util packages/electron-builder packages/electron-builder-core packages/electron-publish",
"jsdoc2md": "node packages/jsdoc2md.js",
"api": "node ./test/vendor/yarn.js jsdoc && node ./test/vendor/yarn.js jsdoc2md"
Expand Down Expand Up @@ -58,7 +58,7 @@
"sanitize-filename": "^1.6.1",
"semver": "^5.3.0",
"stat-mode": "^0.2.2",
"ts-jsdoc": "^2.0.0",
"ts-jsdoc": "^2.0.2",
"tunnel-agent": "^0.6.0",
"update-notifier": "^2.2.0",
"uuid-1345": "^0.99.6",
Expand All @@ -81,7 +81,7 @@
"convert-source-map": "^1.5.0",
"decompress-zip": "^0.3.0",
"depcheck": "^0.6.7",
"develar-typescript-json-schema": "0.11.0",
"develar-typescript-json-schema": "0.13.3",
"env-paths": "^1.0.0",
"globby": "^6.1.0",
"jest-cli": "^20.0.4",
Expand Down
14 changes: 9 additions & 5 deletions packages/electron-builder-util/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ export function copyOrLinkFile(src: string, dest: string, stats?: Stats | null,
}

export class FileCopier {
private isUseHardLink = _isUseHardLink
isUseHardLink: boolean

constructor(private readonly isUseHardLinkFunction?: (file: string) => boolean, private readonly transformer?: FileTransformer) {
constructor(private readonly isUseHardLinkFunction?: (file: string) => boolean, private readonly transformer?: FileTransformer | null) {
this.isUseHardLink = _isUseHardLink && isUseHardLinkFunction !== DO_NOT_USE_HARD_LINKS
}

async copy(src: string, dest: string, stat: Stats | undefined) {
Expand Down Expand Up @@ -203,13 +204,14 @@ export class FileCopier {
* Empty directories is never created.
* Hard links is used if supported and allowed.
*/
export function copyDir(src: string, destination: string, filter?: Filter, transformer?: FileTransformer, isUseHardLink?: (file: string) => boolean): Promise<any> {
export function copyDir(src: string, destination: string, filter?: Filter | null, transformer?: FileTransformer | null, isUseHardLink?: (file: string) => boolean): Promise<any> {
const fileCopier = new FileCopier(isUseHardLink, transformer)

if (debug.enabled) {
debug(`Copying ${src} to ${destination}${_isUseHardLink ? " using hard links" : ""}`)
debug(`Copying ${src} to ${destination}${fileCopier.isUseHardLink ? " using hard links" : ""}`)
}

const createdSourceDirs = new Set<string>()
const fileCopier = new FileCopier(isUseHardLink, transformer)
const links: Array<Link> = []
return walk(src, filter, async(file, stat, parent) => {
if (!stat.isFile() && !stat.isSymbolicLink()) {
Expand All @@ -232,6 +234,8 @@ export function copyDir(src: string, destination: string, filter?: Filter, trans
.then(() => BluebirdPromise.map(links, it => symlink(it.link, it.file), CONCURRENCY))
}

export const DO_NOT_USE_HARD_LINKS = (file: string) => false

interface Link {
readonly link: string,
readonly file: string
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-builder/src/asar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from "path"

const UINT64 = require("cuint").UINT64

/** @internal */
export class Node {
// we don't use Map because later it will be stringified
files?: { [key: string]: Node }
Expand All @@ -18,6 +19,7 @@ export class Node {
link?: string
}

/** @internal */
export class AsarFilesystem {
private offset = UINT64(0)

Expand Down Expand Up @@ -98,6 +100,7 @@ export class AsarFilesystem {
}
}

/** @internal */
export async function readAsar(archive: string): Promise<AsarFilesystem> {
const fd = await open(archive, "r")
let size
Expand All @@ -124,6 +127,7 @@ export async function readAsar(archive: string): Promise<AsarFilesystem> {
return new AsarFilesystem(archive, JSON.parse(header), size)
}

/** @internal */
export async function readAsarJson(archive: string, file: string): Promise<any> {
const fs = await readAsar(archive)
return await fs.readJson(file)
Expand Down
2 changes: 2 additions & 0 deletions packages/electron-builder/src/asarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function writeUnpackedFiles(filesToUnpack: Array<UnpackedFileTask>, fileCopier:
})
}

/** @internal */
export class AsarPackager {
private readonly fs = new AsarFilesystem(this.src)
private readonly outFile: string
Expand Down Expand Up @@ -391,6 +392,7 @@ export class AsarPackager {
}
}

/** @internal */
export async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {
function error(text: string) {
return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/cli/install-app-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { installOrRebuild } from "../yarn"

declare const PACKAGE_VERSION: string

// https://github.com/yargs/yargs/issues/760
// demandOption is required to be set
/** @internal */
export function configureInstallAppDepsCommand(yargs: yargs.Yargs): yargs.Yargs {
// https://github.com/yargs/yargs/issues/760
// demandOption is required to be set
return yargs
.option("platform", {
choices: ["linux", "darwin", "win32"],
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-builder/src/fileMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Config, FilePattern, PlatformSpecificBuildOptions } from "./metadata"
import { BuildInfo } from "./packagerApi"
import { createFilter, hasMagic } from "./util/filter"

/** @internal */
export class FileMatcher {
readonly from: string
readonly to: string
Expand Down Expand Up @@ -85,6 +86,7 @@ export class FileMatcher {
}
}

/** @internal */
export function createFileMatcher(info: BuildInfo, appDir: string, resourcesPath: string, macroExpander: (pattern: string) => string, platformSpecificBuildOptions: PlatformSpecificBuildOptions, buildResourceDir: string) {
const patterns = info.isPrepackedAppAsar ? null : getFileMatchers(info.config, "files", appDir, path.join(resourcesPath, "app"), false, macroExpander, platformSpecificBuildOptions)
const matcher = patterns == null ? new FileMatcher(appDir, path.join(resourcesPath, "app"), macroExpander) : patterns[0]
Expand Down Expand Up @@ -122,6 +124,7 @@ export function createFileMatcher(info: BuildInfo, appDir: string, resourcesPath
return matcher
}

/** @internal */
export function getFileMatchers(config: Config, name: "files" | "extraFiles" | "extraResources" | "asarUnpack", defaultSrc: string, defaultDest: string, allowAdvancedMatching: boolean, macroExpander: (pattern: string) => string, customBuildOptions: PlatformSpecificBuildOptions): Array<FileMatcher> | null {
const globalPatterns: Array<string | FilePattern> | string | n | FilePattern = (<any>config)[name]
const platformSpecificPatterns: Array<string | FilePattern> | string | n = (<any>customBuildOptions)[name]
Expand Down Expand Up @@ -168,6 +171,7 @@ export function getFileMatchers(config: Config, name: "files" | "extraFiles" | "
return fileMatchers.length === 0 ? null : fileMatchers
}

/** @internal */
export function copyFiles(patterns: Array<FileMatcher> | null): Promise<any> {
if (patterns == null || patterns.length === 0) {
return BluebirdPromise.resolve()
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-builder/src/fileTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { readJson } from "fs-extra-p"
import * as path from "path"
import { BuildInfo } from "./packagerApi"

/** @internal */
export function isElectronCompileUsed(info: BuildInfo): boolean {
if (info.config.electronCompile != null) {
return info.config.electronCompile
Expand All @@ -16,6 +17,7 @@ export function isElectronCompileUsed(info: BuildInfo): boolean {
return deps != null && "electron-compile" in deps
}

/** @internal */
export async function createTransformer(srcDir: string, extraMetadata: any): Promise<FileTransformer> {
const mainPackageJson = path.join(srcDir, "package.json")

Expand All @@ -34,12 +36,14 @@ export async function createTransformer(srcDir: string, extraMetadata: any): Pro
}
}

/** @internal */
export interface CompilerHost {
compile(file: string): any

saveConfiguration(): Promise<any>
}

/** @internal */
export function createElectronCompilerHost(projectDir: string, cacheDir: string): Promise<CompilerHost> {
const electronCompilePath = path.join(projectDir, "node_modules", "electron-compile", "lib")
return require(path.join(electronCompilePath, "config-parser")).createCompilerHostFromProjectRoot(projectDir, cacheDir)
Expand Down
8 changes: 6 additions & 2 deletions packages/electron-builder/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,12 @@ export class Packager implements BuildInfo {
const targetList = createTargets(nameToTarget, targetNames.length === 0 ? packager.defaultTarget : targetNames, outDir, packager, cleanupTasks)
const ourDirs = new Set<string>()
for (const target of targetList) {
const outDir = target.outDir
if (!createdOutDirs.has(outDir) && !(target instanceof NoOpTarget)) {
if (target instanceof NoOpTarget) {
continue
}

const outDir = (<Target>target).outDir
if (createdOutDirs.has(outDir)) {
ourDirs.add(outDir)
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/packager/dirPackager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { path7za } from "7zip-bin"
import BluebirdPromise from "bluebird-lst"
import { debug7zArgs, spawn } from "electron-builder-util"
import { copyDir } from "electron-builder-util/out/fs"
import { copyDir, DO_NOT_USE_HARD_LINKS } from "electron-builder-util/out/fs"
import { log, warn } from "electron-builder-util/out/log"
import { chmod, emptyDir } from "fs-extra-p"
import * as path from "path"
Expand Down Expand Up @@ -61,7 +61,7 @@ async function unpack(packager: PlatformPackager<any>, out: string, platform: st
const destination = packager.getElectronDestDir(out)
log(`Copying Electron from "${source}" to "${destination}"`)
await emptyDir(out)
await copyDir(source, destination)
await copyDir(source, destination, null, null, DO_NOT_USE_HARD_LINKS)
}

if (platform === "linux") {
Expand Down
3 changes: 3 additions & 0 deletions packages/electron-builder/src/readInstalled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import BluebirdPromise from "bluebird-lst"
import { lstat, readdir, readJson, realpath } from "fs-extra-p"
import * as path from "path"

/** @internal */
export interface Dependency {
name: string
path: string
Expand All @@ -11,6 +12,7 @@ export interface Dependency {
dependencies: { [name: string]: Dependency }
}

/** @internal */
export async function readInstalled(folder: string): Promise<Map<string, Dependency>> {
const opts = {
depth: Infinity,
Expand Down Expand Up @@ -180,6 +182,7 @@ async function readScopedDir(dir: string) {
return result
}

/** @internal */
export async function dependencies(dir: string, result: Set<string>): Promise<void> {
const pathToDep = await readInstalled(dir)
for (const dep of pathToDep.values()) {
Expand Down
1 change: 1 addition & 0 deletions packages/electron-builder/src/repositoryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fromUrl as parseRepositoryUrl } from "hosted-git-info"
import * as path from "path"
import { Metadata, RepositoryInfo } from "./metadata"

/** @internal */
export function getRepositoryInfo(projectDir: string, metadata?: Metadata, devMetadata?: Metadata): Promise<SourceRepositoryInfo | null> {
return _getInfo(projectDir, (devMetadata == null ? null : devMetadata.repository) || (metadata == null ? null : metadata.repository))
}
Expand Down
2 changes: 2 additions & 0 deletions packages/electron-builder/src/targets/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const extToCompressionDescriptor: { [key: string]: CompressionDescriptor; } = {
"tar.bz2": new CompressionDescriptor("--bzip2", "BZIP2", "-1"),
}

/** @internal */
export async function tar(compression: CompressionLevel | n, format: string, outFile: string, dirToArchive: string, isMacApp: boolean = false) {
// we don't use 7z here - develar: I spent a lot of time making pipe working - but it works on MacOS and often hangs on Linux (even if use pipe-io lib)
// and in any case it is better to use system tools (in the light of docker - it is not problem for user because we provide complete docker image).
Expand All @@ -43,6 +44,7 @@ export async function tar(compression: CompressionLevel | n, format: string, out
return outFile
}

/** @internal */
export async function archive(compression: CompressionLevel | n, format: string, outFile: string, dirToArchive: string, withoutDir: boolean = false): Promise<string> {
let storeOnly = compression === "store"
const args = debug7zArgs("a")
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-builder/src/targets/dmgLicense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import * as path from "path"
import { PlatformPackager } from "../platformPackager"
import { getLicenseFiles } from "./license"

// http://www.owsiak.org/?p=700
/** @internal */
export async function addLicenseToDmg(packager: PlatformPackager<any>, dmgPath: string) {
// http://www.owsiak.org/?p=700
const licenseFiles = await getLicenseFiles(packager)
if (licenseFiles.length === 0) {
return
Expand Down
6 changes: 6 additions & 0 deletions packages/electron-builder/src/targets/license.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import * as path from "path"
import { PlatformPackager } from "../platformPackager"

/** @internal */
export const bundledLanguages = ["en_US", "de_DE", "fr_FR", "es_ES", "zh_CN", "zh_TW", "ja_JP", "it_IT", "nl_NL", "ru_RU", "pl_PL", "uk_UA", "cs_CZ", "sv_SE", "nb_NO", "da_DK", "pt_PT", "hu_HU", "ko_KR", "fi_FI", "sk_SK"]

const langToLangWithRegion = new Map<string, string>()
for (const id of bundledLanguages) {
langToLangWithRegion.set(id.substring(0, id.indexOf("_")), id)
}

/** @internal */
export function toLangWithRegion(lang: string): string {
let langWithRegion = langToLangWithRegion.get(lang)
if (langWithRegion == null) {
Expand All @@ -15,6 +18,7 @@ export function toLangWithRegion(lang: string): string {
return langWithRegion
}

/** @internal */
export async function getLicenseFiles(packager: PlatformPackager<any>): Promise<Array<LicenseFile>> {
const files = (await packager.resourceList)
.filter(it => {
Expand All @@ -41,6 +45,7 @@ export async function getLicenseFiles(packager: PlatformPackager<any>): Promise<
})
}

/** @internal */
export const lcid: any = {
"af_ZA": 1078,
"am_ET": 1118,
Expand Down Expand Up @@ -245,6 +250,7 @@ export const lcid: any = {
"zu_ZA": 1077
}

/** @internal */
export interface LicenseFile {
file: string
lang: string
Expand Down
2 changes: 2 additions & 0 deletions packages/electron-builder/src/util/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Stats } from "fs-extra-p"
import { Minimatch } from "minimatch"
import * as path from "path"

/** @internal */
export function hasMagic(pattern: Minimatch) {
const set = pattern.set
if (set.length > 1) {
Expand All @@ -18,6 +19,7 @@ export function hasMagic(pattern: Minimatch) {
return false
}

/** @internal */
export function createFilter(src: string, patterns: Array<Minimatch>, ignoreFiles?: Set<string>, rawFilter?: (file: string) => boolean, excludePatterns?: Array<Minimatch> | null): Filter {
return function (it, stat) {
if (src === it) {
Expand Down
Loading

0 comments on commit 9cfb09a

Please sign in to comment.