Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignore system junk files by default #1005

Merged
merged 1 commit into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,19 @@ described after the list*):

Alternatively, this can be a predicate function that, given an absolute file path, returns `true` if
the file should be ignored, or `false` if the file should be kept. *This does not use any of the
default ignored directories listed above.*
default ignored files/directories listed above.*

**Note:** `ignore` will have no effect if [`prebuiltAsar`](#prebuiltasar) is set.

##### `junk`

*Boolean* (default: `true`)

Ignores [system junk files](https://github.com/sindresorhus/junk) when copying the Electron app,
regardless of the [`ignore`](#ignore) option.

**Note:** `junk` will have no effect if [`prebuiltAsar`](#prebuiltasar) is set.

##### `name`

*String*
Expand Down Expand Up @@ -359,6 +368,7 @@ gets skipped over:
* [`afterPrune`](#afterprune)
* [`derefSymlinks`](#derefsymlinks)
* [`ignore`](#ignore)
* [`junk`](#junk)
* [`prune`](#prune)

##### `prune`
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"fs-extra": "^7.0.0",
"galactus": "^0.2.1",
"get-package-info": "^1.0.0",
"junk": "^3.1.0",
"parse-author": "^2.0.0",
"plist": "^3.0.0",
"rcedit": "^2.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ module.exports = {
'all',
'deref-symlinks',
'download.strictSSL',
'junk',
'overwrite',
'prune',
'quiet'
],
default: {
'deref-symlinks': true,
'download.strictSSL': true,
junk: true,
prune: true
},
string: [
Expand Down
7 changes: 7 additions & 0 deletions src/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const common = require('./common')
const debug = require('debug')('electron-packager')
const junk = require('junk')
const path = require('path')
const prune = require('./prune')
const targets = require('./targets')
Expand Down Expand Up @@ -74,6 +75,12 @@ function userIgnoreFilter (opts) {
return false
}

if (opts.junk !== false) { // defaults to true
if (junk.is(path.basename(fullPath))) {
return false
}
}

let name = fullPath.split(path.resolve(opts.dir))[1]

if (path.sep === '\\') {
Expand Down
Empty file.
Empty file.
37 changes: 31 additions & 6 deletions test/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,30 @@ async function assertOutDirIgnored (t, opts, existingDirectoryPath, pathToIgnore
await util.assertPathNotExists(t, path.join(resourcesPath, 'app', ignoredBasenameToCheck), 'Out dir must not exist in output app directory')
}

async function copyDirToTempDirWithIgnores (t, opts) {
ignore.generateIgnores(opts)
const targetDir = path.join(t.context.tempDir, 'result')
await fs.copy(opts.dir, targetDir, { dereference: false, filter: ignore.userIgnoreFilter(opts) })
return targetDir
}

async function assertFileIgnored (t, targetDir, ignoredFile) {
await util.assertPathNotExists(t, path.join(targetDir, ignoredFile), `Ignored file '${ignoredFile}' should not exist in copied directory`)
}

async function assertFileNotIgnored (t, targetDir, notIgnoredFile) {
await util.assertPathExists(t, path.join(targetDir, notIgnoredFile), `The expected output directory should exist and contain ${notIgnoredFile}`)
}

async function ignoreTest (t, opts, ignorePattern, ignoredFile) {
opts.dir = util.fixtureSubdir('basic')
if (ignorePattern) {
opts.ignore = ignorePattern
}

const targetDir = path.join(t.context.tempDir, 'result')
ignore.generateIgnores(opts)

await fs.copy(opts.dir, targetDir, { dereference: false, filter: ignore.userIgnoreFilter(opts) })
await util.assertPathExists(t, path.join(targetDir, 'package.json'), 'The expected output directory should exist and contain files')
await util.assertPathNotExists(t, path.join(targetDir, ignoredFile), `Ignored file '${ignoredFile}' should not exist in copied directory`)
const targetDir = await copyDirToTempDirWithIgnores(t, opts)
await assertFileIgnored(t, targetDir, ignoredFile)
await assertFileNotIgnored(t, targetDir, 'package.json')
}

async function ignoreOutDirTest (t, opts, distPath) {
Expand Down Expand Up @@ -72,6 +84,19 @@ test('ignore: RegExp', util.testSinglePlatform(ignoreTest, /ignorethis/, 'ignore
test('ignore: Function', util.testSinglePlatform(ignoreTest, file => file.match(/ignorethis/), 'ignorethis.txt'))
test('ignore: string with slash', util.testSinglePlatform(ignoreTest, 'ignore/this', path.join('ignore', 'this.txt')))
test('ignore: only match subfolder of app', util.testSinglePlatform(ignoreTest, 'electron-packager', path.join('electron-packager', 'readme.txt')))

test('ignore: junk by default', util.testSinglePlatform(async (t, opts) => {
opts.dir = util.fixtureSubdir('ignore-junk')
const targetDir = await copyDirToTempDirWithIgnores(t, opts)
await assertFileIgnored(t, targetDir, 'subfolder/Thumbs.db')
}))
test('ignore: not junk when junk: false', util.testSinglePlatform(async (t, opts) => {
opts.dir = util.fixtureSubdir('ignore-junk')
opts.junk = false
const targetDir = await copyDirToTempDirWithIgnores(t, opts)
await assertFileNotIgnored(t, targetDir, 'subfolder/Thumbs.db')
}))

test.serial('ignore out dir', util.testSinglePlatform(ignoreOutDirTest, 'ignoredOutDir'))
test.serial('ignore out dir: unnormalized path', util.testSinglePlatform(ignoreOutDirTest, './ignoredOutDir'))
test.serial('ignore out dir: implicit path', util.testSinglePlatform(async (t, opts) => {
Expand Down
1 change: 1 addition & 0 deletions usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ignore do not copy files into app whose filenames RegExp.match this
https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#ignore
and --no-prune. Can be specified multiple times
no-deref-symlinks make sure symlinks are not dereferenced within the app source
no-junk do not ignore system junk files from the packaged app
no-prune do not prune devDependencies from the packaged app
out the dir to put the app into at the end. Defaults to current working dir
overwrite if output directory for a platform already exists, replaces it rather than
Expand Down