Skip to content

Commit c04dd20

Browse files
committed
fix: do not copy electronDist using hard links
Close #1670
1 parent 157c730 commit c04dd20

File tree

22 files changed

+84
-48
lines changed

22 files changed

+84
-48
lines changed

.idea/electron-builder.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A complete solution to package and build a ready for distribution Electron app f
2222
| Question | Answer |
2323
|--------|-------|
2424
| “I want to configure electron-builder” | [See options](https://github.com/electron-userland/electron-builder/wiki/Options) |
25-
| “I have a question” | [Open an issue](https://github.com/electron-userland/electron-builder/issues) or [join the chat](http://electron-builder-slack.herokuapp.com) |
25+
| “I have a question” | [Open an issue](https://github.com/electron-userland/electron-builder/issues) or [join the chat](https://slackin.electron.build) |
2626
| “I found a bug” | [Open an issue](https://github.com/electron-userland/electron-builder/issues/new) |
2727
| “I want to donate” | [Donate with Donorbox](https://donorbox.org/electron-builder) or [Paypal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W6V79R2RGCCHL) |
2828

@@ -172,7 +172,7 @@ and other distributable formats.
172172

173173
## Community
174174

175-
[electron-builder](http://electron-builder-slack.herokuapp.com) on Slack (please use [threads](https://get.slack.help/hc/en-us/articles/115000769927-Message-threads)).
175+
[electron-builder](https://slackin.electron.build) on Slack (please use [threads](https://get.slack.help/hc/en-us/articles/115000769927-Message-threads)).
176176
Public [archive](http://electron-builder.slackarchive.io) without registration.
177177

178178
## Further Reading

docs/api/electron-builder-util.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494

9595
### FileCopier
9696
**Kind**: class of [<code>electron-builder-util/out/fs</code>](#module_electron-builder-util/out/fs)
97+
**Properties**
98+
99+
| Name | Type |
100+
| --- | --- |
101+
| **isUseHardLink**| <code>Boolean</code> |
102+
97103
<a name="module_electron-builder-util/out/fs.FileCopier+copy"></a>
98104

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

124130
<a name="module_electron-builder-util/out/fs.copyFile"></a>

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"update-deps": "node ./packages/update-deps.js",
1919
"set-versions": "node test/out/helpers/setVersions.js",
2020
"npm-publish": "yarn set-versions && yarn compile && ./packages/npm-publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
21-
"schema": "typescript-json-schema packages/electron-builder/tsconfig.json Config --out packages/electron-builder/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --titles",
21+
"schema": "typescript-json-schema packages/electron-builder/tsconfig.json Config --out packages/electron-builder/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --titles --required",
2222
"jsdoc": "ts2jsdoc packages/electron-builder-http packages/electron-updater packages/electron-builder-util packages/electron-builder packages/electron-builder-core packages/electron-publish",
2323
"jsdoc2md": "node packages/jsdoc2md.js",
2424
"api": "node ./test/vendor/yarn.js jsdoc && node ./test/vendor/yarn.js jsdoc2md"
@@ -58,7 +58,7 @@
5858
"sanitize-filename": "^1.6.1",
5959
"semver": "^5.3.0",
6060
"stat-mode": "^0.2.2",
61-
"ts-jsdoc": "^2.0.0",
61+
"ts-jsdoc": "^2.0.2",
6262
"tunnel-agent": "^0.6.0",
6363
"update-notifier": "^2.2.0",
6464
"uuid-1345": "^0.99.6",
@@ -81,7 +81,7 @@
8181
"convert-source-map": "^1.5.0",
8282
"decompress-zip": "^0.3.0",
8383
"depcheck": "^0.6.7",
84-
"develar-typescript-json-schema": "0.11.0",
84+
"develar-typescript-json-schema": "0.13.3",
8585
"env-paths": "^1.0.0",
8686
"globby": "^6.1.0",
8787
"jest-cli": "^20.0.4",

packages/electron-builder-util/src/fs.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ export function copyOrLinkFile(src: string, dest: string, stats?: Stats | null,
159159
}
160160

161161
export class FileCopier {
162-
private isUseHardLink = _isUseHardLink
162+
isUseHardLink: boolean
163163

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

167168
async copy(src: string, dest: string, stat: Stats | undefined) {
@@ -203,13 +204,14 @@ export class FileCopier {
203204
* Empty directories is never created.
204205
* Hard links is used if supported and allowed.
205206
*/
206-
export function copyDir(src: string, destination: string, filter?: Filter, transformer?: FileTransformer, isUseHardLink?: (file: string) => boolean): Promise<any> {
207+
export function copyDir(src: string, destination: string, filter?: Filter | null, transformer?: FileTransformer | null, isUseHardLink?: (file: string) => boolean): Promise<any> {
208+
const fileCopier = new FileCopier(isUseHardLink, transformer)
209+
207210
if (debug.enabled) {
208-
debug(`Copying ${src} to ${destination}${_isUseHardLink ? " using hard links" : ""}`)
211+
debug(`Copying ${src} to ${destination}${fileCopier.isUseHardLink ? " using hard links" : ""}`)
209212
}
210213

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

237+
export const DO_NOT_USE_HARD_LINKS = (file: string) => false
238+
235239
interface Link {
236240
readonly link: string,
237241
readonly file: string

packages/electron-builder/src/asar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path"
44

55
const UINT64 = require("cuint").UINT64
66

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

22+
/** @internal */
2123
export class AsarFilesystem {
2224
private offset = UINT64(0)
2325

packages/electron-builder/src/asarUtil.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function writeUnpackedFiles(filesToUnpack: Array<UnpackedFileTask>, fileCopier:
4343
})
4444
}
4545

46+
/** @internal */
4647
export class AsarPackager {
4748
private readonly fs = new AsarFilesystem(this.src)
4849
private readonly outFile: string
@@ -391,6 +392,7 @@ export class AsarPackager {
391392
}
392393
}
393394

395+
/** @internal */
394396
export async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {
395397
function error(text: string) {
396398
return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`)

packages/electron-builder/src/cli/install-app-deps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import { installOrRebuild } from "../yarn"
1010

1111
declare const PACKAGE_VERSION: string
1212

13-
// https://github.com/yargs/yargs/issues/760
14-
// demandOption is required to be set
1513
/** @internal */
1614
export function configureInstallAppDepsCommand(yargs: yargs.Yargs): yargs.Yargs {
15+
// https://github.com/yargs/yargs/issues/760
16+
// demandOption is required to be set
1717
return yargs
1818
.option("platform", {
1919
choices: ["linux", "darwin", "win32"],

packages/electron-builder/src/fileMatcher.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Config, FilePattern, PlatformSpecificBuildOptions } from "./metadata"
99
import { BuildInfo } from "./packagerApi"
1010
import { createFilter, hasMagic } from "./util/filter"
1111

12+
/** @internal */
1213
export class FileMatcher {
1314
readonly from: string
1415
readonly to: string
@@ -85,6 +86,7 @@ export class FileMatcher {
8586
}
8687
}
8788

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

127+
/** @internal */
125128
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 {
126129
const globalPatterns: Array<string | FilePattern> | string | n | FilePattern = (<any>config)[name]
127130
const platformSpecificPatterns: Array<string | FilePattern> | string | n = (<any>customBuildOptions)[name]
@@ -168,6 +171,7 @@ export function getFileMatchers(config: Config, name: "files" | "extraFiles" | "
168171
return fileMatchers.length === 0 ? null : fileMatchers
169172
}
170173

174+
/** @internal */
171175
export function copyFiles(patterns: Array<FileMatcher> | null): Promise<any> {
172176
if (patterns == null || patterns.length === 0) {
173177
return BluebirdPromise.resolve()

packages/electron-builder/src/fileTransformer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { readJson } from "fs-extra-p"
66
import * as path from "path"
77
import { BuildInfo } from "./packagerApi"
88

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

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

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

39+
/** @internal */
3740
export interface CompilerHost {
3841
compile(file: string): any
3942

4043
saveConfiguration(): Promise<any>
4144
}
4245

46+
/** @internal */
4347
export function createElectronCompilerHost(projectDir: string, cacheDir: string): Promise<CompilerHost> {
4448
const electronCompilePath = path.join(projectDir, "node_modules", "electron-compile", "lib")
4549
return require(path.join(electronCompilePath, "config-parser")).createCompilerHostFromProjectRoot(projectDir, cacheDir)

0 commit comments

Comments
 (0)