Skip to content

Commit

Permalink
fix: ignore dev deps if ignore func specified
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 17, 2016
1 parent e1e6d67 commit 0944985
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"debug": "^2.2.0",
"deep-assign": "^2.0.0",
"electron-osx-sign-tf": "0.6.0",
"electron-packager-tf": "~7.3.3",
"electron-packager-tf": "~7.4.0",
"electron-winstaller-fixed": "~2.10.1",
"fs-extra-p": "^1.0.2",
"glob": "^7.0.3",
Expand Down
66 changes: 35 additions & 31 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,33 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
const appPath = path.join(buildDir, appRelativePath)
const resourcesPath = path.dirname(appPath)

let promise: Promise<any> | null = null
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)
}
}
}

let patterns = this.getFilePatterns("files", customBuildOptions)
if (patterns == null || patterns.length === 0) {
patterns = ["**/*"]
}

let rawFilter: any = null
const deprecatedIgnore = (<any>this.devMetadata.build).ignore
if (deprecatedIgnore) {
if (typeof deprecatedIgnore === "function") {
Expand All @@ -162,37 +188,10 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
else {
warn(`"ignore is deprecated, please use "files", see https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-files`)
}

promise = copy(this.info.appDir, appPath, {filter: userIgnoreFilter(opts), dereference: true})
rawFilter = userIgnoreFilter(opts)
}
else {
const ignoreFiles = new Set([path.relative(this.info.appDir, opts.out!), 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)
}
}
}

let patterns = this.getFilePatterns("files", customBuildOptions)
if (patterns == null || patterns.length === 0) {
patterns = ["**/*"]
}
promise = copyFiltered(this.info.appDir, appPath, this.getParsedPatterns(patterns, arch), true, ignoreFiles)
}
const promise = copyFiltered(this.info.appDir, appPath, this.getParsedPatterns(patterns, arch), true, ignoreFiles, rawFilter)

const promises = [promise]
if (this.info.electronVersion[0] === "0") {
Expand Down Expand Up @@ -452,13 +451,18 @@ function minimatchAll(path: string, patterns: Array<Minimatch>): boolean {
}

// we use relative path to avoid canonical path issue - e.g. /tmp vs /private/tmp
function copyFiltered(src: string, destination: string, patterns: Array<Minimatch>, dereference: boolean = false, ignoreFiles?: Set<string>): Promise<any> {
function copyFiltered(src: string, destination: string, patterns: Array<Minimatch>, dereference: boolean = false, ignoreFiles?: Set<string>, rawFilter?: (file: string) => boolean): Promise<any> {
return copy(src, destination, {
dereference: dereference,
filter: it => {
if (src === it) {
return true
}

if (rawFilter != null && !rawFilter(it)) {
return false
}

let relative = it.substring(src.length + 1)

// yes, check before path sep normalization
Expand Down
20 changes: 15 additions & 5 deletions test/src/globTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ test.ifDevOrLinuxCi("files", () => {
})
})

test.ifDevOrLinuxCi("ignore node_modules known dev dep", () => {
// skip on OS X because we want test only / and \
test.ifNotCiOsx("ignore node_modules known dev dep", () => {
const build: any = {
asar: false,
ignore: (file: string) => {
return file === "/ignoreMe"
}
}

return assertPack("test-app-one", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
devMetadata: {
build: {
asar: false,
}
build: build
}
}, {
tempDirCreated: projectDir => {
Expand All @@ -65,10 +71,14 @@ test.ifDevOrLinuxCi("ignore node_modules known dev dep", () => {
}, data.devDependencies)
}),
outputFile(path.join(projectDir, "node_modules", "electron-osx-sign", "package.json"), "{}"),
outputFile(path.join(projectDir, "ignoreMe"), ""),
])
},
packed: projectDir => {
return assertThat(path.join(projectDir, outDirName, "linux", "resources", "app", "node_modules", "electron-osx-sign")).doesNotExist()
return BluebirdPromise.all([
assertThat(path.join(projectDir, outDirName, "linux", "resources", "app", "node_modules", "electron-osx-sign")).doesNotExist(),
assertThat(path.join(projectDir, outDirName, "linux", "resources", "app", "ignoreMe")).doesNotExist(),
])
},
})
})
Expand Down

0 comments on commit 0944985

Please sign in to comment.