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 4baea1e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 26 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
4 changes: 2 additions & 2 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 @@ -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
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
1 change: 0 additions & 1 deletion packages/jsdoc2md.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ async function main() {

const developerFiles = (await globby([
"builder/**/*.js",
"!**/*-dirPackager.js",
"!***/*-asarUtil.js",
"!***/*-fileMatcher.js",
"!***/*-fileTransformer.js",
Expand Down
2 changes: 1 addition & 1 deletion typings/yargs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ declare namespace yargs {

completion(cmd: string, fn?: SyncCompletionFunction): Yargs;

completion(cmd: string, description?: string, fn?: AsyncCompletionFunction): Yargs;
completion(cmd: string | undefined, description?: string, fn?: AsyncCompletionFunction): Yargs;

completion(cmd: string, description?: string, fn?: SyncCompletionFunction): Yargs;

Expand Down
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1013,14 +1013,14 @@ detect-newline@^1.0.3:
get-stdin "^4.0.1"
minimist "^1.1.0"

develar-typescript-json-schema@0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/develar-typescript-json-schema/-/develar-typescript-json-schema-0.11.0.tgz#d73580cae2fb0b8f9a7cee3d10aff6caae751cca"
develar-typescript-json-schema@0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/develar-typescript-json-schema/-/develar-typescript-json-schema-0.13.3.tgz#c3accb60ebdcdf4ee711adbd6c194167debf5939"
dependencies:
glob "~7.1.1"
glob "~7.1.2"
json-stable-stringify "^1.0.1"
typescript "~2.1.5"
yargs "^7.0.2"
typescript "~2.3.0"
yargs "^8.0.1"

diff@^3.2.0:
version "3.2.0"
Expand Down Expand Up @@ -1368,7 +1368,7 @@ glob-parent@^2.0.0:
dependencies:
is-glob "^2.0.0"

glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.0, glob@^7.1.1, glob@~7.1.1:
glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.0, glob@^7.1.1, glob@~7.1.2:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
Expand Down Expand Up @@ -3353,9 +3353,9 @@ typescript@next:
version "2.5.0-dev.20170614"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.0-dev.20170614.tgz#eb77ed212a5e49ebc8392ba0a95713ef87d9f6f1"

typescript@~2.1.5:
version "2.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.6.tgz#40c7e6e9e5da7961b7718b55505f9cac9487a607"
typescript@~2.3.0:
version "2.3.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.4.tgz#3d38321828231e434f287514959c37a82b629f42"

typical@^2.4.2, typical@^2.6.0, typical@^2.6.1:
version "2.6.1"
Expand Down Expand Up @@ -3715,7 +3715,7 @@ yargs@^7.0.2:
y18n "^3.2.1"
yargs-parser "^5.0.0"

yargs@^8.0.2:
yargs@^8.0.1, yargs@^8.0.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-8.0.2.tgz#6299a9055b1cefc969ff7e79c1d918dceb22c360"
dependencies:
Expand Down

0 comments on commit 4baea1e

Please sign in to comment.