Skip to content

Commit 68d6bc5

Browse files
authored
feat: ignore system junk files by default (#1005)
1 parent abf6bab commit 68d6bc5

File tree

8 files changed

+53
-7
lines changed

8 files changed

+53
-7
lines changed

docs/api.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,19 @@ described after the list*):
307307

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

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

314+
##### `junk`
315+
316+
*Boolean* (default: `true`)
317+
318+
Ignores [system junk files](https://github.com/sindresorhus/junk) when copying the Electron app,
319+
regardless of the [`ignore`](#ignore) option.
320+
321+
**Note:** `junk` will have no effect if [`prebuiltAsar`](#prebuiltasar) is set.
322+
314323
##### `name`
315324

316325
*String*
@@ -359,6 +368,7 @@ gets skipped over:
359368
* [`afterPrune`](#afterprune)
360369
* [`derefSymlinks`](#derefsymlinks)
361370
* [`ignore`](#ignore)
371+
* [`junk`](#junk)
362372
* [`prune`](#prune)
363373

364374
##### `prune`

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"fs-extra": "^7.0.0",
2727
"galactus": "^0.2.1",
2828
"get-package-info": "^1.0.0",
29+
"junk": "^3.1.0",
2930
"parse-author": "^2.0.0",
3031
"plist": "^3.0.0",
3132
"rcedit": "^2.0.0",

src/cli.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ module.exports = {
2121
'all',
2222
'deref-symlinks',
2323
'download.strictSSL',
24+
'junk',
2425
'overwrite',
2526
'prune',
2627
'quiet'
2728
],
2829
default: {
2930
'deref-symlinks': true,
3031
'download.strictSSL': true,
32+
junk: true,
3133
prune: true
3234
},
3335
string: [

src/ignore.js

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const common = require('./common')
44
const debug = require('debug')('electron-packager')
5+
const junk = require('junk')
56
const path = require('path')
67
const prune = require('./prune')
78
const targets = require('./targets')
@@ -74,6 +75,12 @@ function userIgnoreFilter (opts) {
7475
return false
7576
}
7677

78+
if (opts.junk !== false) { // defaults to true
79+
if (junk.is(path.basename(fullPath))) {
80+
return false
81+
}
82+
}
83+
7784
let name = fullPath.split(path.resolve(opts.dir))[1]
7885

7986
if (path.sep === '\\') {

test/fixtures/ignore-junk/package.json

Whitespace-only changes.

test/fixtures/ignore-junk/subfolder/Thumbs.db

Whitespace-only changes.

test/ignore.js

+31-6
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,30 @@ async function assertOutDirIgnored (t, opts, existingDirectoryPath, pathToIgnore
2020
await util.assertPathNotExists(t, path.join(resourcesPath, 'app', ignoredBasenameToCheck), 'Out dir must not exist in output app directory')
2121
}
2222

23+
async function copyDirToTempDirWithIgnores (t, opts) {
24+
ignore.generateIgnores(opts)
25+
const targetDir = path.join(t.context.tempDir, 'result')
26+
await fs.copy(opts.dir, targetDir, { dereference: false, filter: ignore.userIgnoreFilter(opts) })
27+
return targetDir
28+
}
29+
30+
async function assertFileIgnored (t, targetDir, ignoredFile) {
31+
await util.assertPathNotExists(t, path.join(targetDir, ignoredFile), `Ignored file '${ignoredFile}' should not exist in copied directory`)
32+
}
33+
34+
async function assertFileNotIgnored (t, targetDir, notIgnoredFile) {
35+
await util.assertPathExists(t, path.join(targetDir, notIgnoredFile), `The expected output directory should exist and contain ${notIgnoredFile}`)
36+
}
37+
2338
async function ignoreTest (t, opts, ignorePattern, ignoredFile) {
2439
opts.dir = util.fixtureSubdir('basic')
2540
if (ignorePattern) {
2641
opts.ignore = ignorePattern
2742
}
2843

29-
const targetDir = path.join(t.context.tempDir, 'result')
30-
ignore.generateIgnores(opts)
31-
32-
await fs.copy(opts.dir, targetDir, { dereference: false, filter: ignore.userIgnoreFilter(opts) })
33-
await util.assertPathExists(t, path.join(targetDir, 'package.json'), 'The expected output directory should exist and contain files')
34-
await util.assertPathNotExists(t, path.join(targetDir, ignoredFile), `Ignored file '${ignoredFile}' should not exist in copied directory`)
44+
const targetDir = await copyDirToTempDirWithIgnores(t, opts)
45+
await assertFileIgnored(t, targetDir, ignoredFile)
46+
await assertFileNotIgnored(t, targetDir, 'package.json')
3547
}
3648

3749
async function ignoreOutDirTest (t, opts, distPath) {
@@ -72,6 +84,19 @@ test('ignore: RegExp', util.testSinglePlatform(ignoreTest, /ignorethis/, 'ignore
7284
test('ignore: Function', util.testSinglePlatform(ignoreTest, file => file.match(/ignorethis/), 'ignorethis.txt'))
7385
test('ignore: string with slash', util.testSinglePlatform(ignoreTest, 'ignore/this', path.join('ignore', 'this.txt')))
7486
test('ignore: only match subfolder of app', util.testSinglePlatform(ignoreTest, 'electron-packager', path.join('electron-packager', 'readme.txt')))
87+
88+
test('ignore: junk by default', util.testSinglePlatform(async (t, opts) => {
89+
opts.dir = util.fixtureSubdir('ignore-junk')
90+
const targetDir = await copyDirToTempDirWithIgnores(t, opts)
91+
await assertFileIgnored(t, targetDir, 'subfolder/Thumbs.db')
92+
}))
93+
test('ignore: not junk when junk: false', util.testSinglePlatform(async (t, opts) => {
94+
opts.dir = util.fixtureSubdir('ignore-junk')
95+
opts.junk = false
96+
const targetDir = await copyDirToTempDirWithIgnores(t, opts)
97+
await assertFileNotIgnored(t, targetDir, 'subfolder/Thumbs.db')
98+
}))
99+
75100
test.serial('ignore out dir', util.testSinglePlatform(ignoreOutDirTest, 'ignoredOutDir'))
76101
test.serial('ignore out dir: unnormalized path', util.testSinglePlatform(ignoreOutDirTest, './ignoredOutDir'))
77102
test.serial('ignore out dir: implicit path', util.testSinglePlatform(async (t, opts) => {

usage.txt

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ ignore do not copy files into app whose filenames RegExp.match this
5353
https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#ignore
5454
and --no-prune. Can be specified multiple times
5555
no-deref-symlinks make sure symlinks are not dereferenced within the app source
56+
no-junk do not ignore system junk files from the packaged app
5657
no-prune do not prune devDependencies from the packaged app
5758
out the dir to put the app into at the end. Defaults to current working dir
5859
overwrite if output directory for a platform already exists, replaces it rather than

0 commit comments

Comments
 (0)