Skip to content

Commit

Permalink
feat: exclude **/node_modules/*/{README.md,README,readme.md,readme,te…
Browse files Browse the repository at this point in the history
…st} by default

Close #591 #606
  • Loading branch information
develar committed Jul 22, 2016
1 parent ec0bda5 commit 5895583
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 61 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/asarUtil.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsarOptions } from "asar"
import { AsarOptions } from "@develar/asar"
import { ElectronPackagerOptions } from "./packager/dirPackager"

export interface Metadata {
Expand Down
100 changes: 50 additions & 50 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -156,61 +156,61 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

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 = (<any>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 = (<any>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)
Expand Down
7 changes: 1 addition & 6 deletions src/targets/squirrelWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ export default class SquirrelWindowsTarget extends Target {
extraMetadataSpecs: projectUrl == null ? null : `\n <projectUrl>${projectUrl}</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)

Expand Down
2 changes: 1 addition & 1 deletion typings/asar.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "asar" {
declare module "@develar/asar" {
import { Stats } from "fs"

interface AsarFileInfo {
Expand Down

0 comments on commit 5895583

Please sign in to comment.