Skip to content

Commit b2ce937

Browse files
eugirdorDavid Rodrigue
authored and
David Rodrigue
committed
add tmpdir option to allow specifying a custom temp directory for the build
1 parent 593f847 commit b2ce937

File tree

5 files changed

+57
-25
lines changed

5 files changed

+57
-25
lines changed

common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = {
6060
// * Prunes non-production node_modules (if opts.prune is set)
6161
// * Creates an asar (if opts.asar is set)
6262

63-
var tempParent = path.join(os.tmpdir(), 'electron-packager', opts.platform + '-' + opts.arch)
63+
var tempParent = path.join(opts.tmpdir || os.tmpdir(), 'electron-packager', opts.platform + '-' + opts.arch)
6464
var tempPath = path.join(tempParent, generateFinalBasename(opts))
6565
// Path to `app` directory
6666
var appPath = path.join(tempPath, appRelativePath)

index.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,6 @@ var supportedPlatforms = {
2323
win32: './win32'
2424
}
2525

26-
var tempBase = path.join(os.tmpdir(), 'electron-packager')
27-
28-
function testSymlink (cb) {
29-
var testPath = path.join(tempBase, 'symlink-test')
30-
var testFile = path.join(testPath, 'test')
31-
var testLink = path.join(testPath, 'testlink')
32-
series([
33-
function (cb) {
34-
mkdirp(testPath, cb)
35-
},
36-
function (cb) {
37-
fs.writeFile(testFile, '', cb)
38-
},
39-
function (cb) {
40-
fs.symlink(testFile, testLink, cb)
41-
}
42-
], function (err) {
43-
var result = !err
44-
rimraf(testPath, function () {
45-
cb(result) // ignore errors on cleanup
46-
})
47-
})
48-
}
49-
5026
function validateList (list, supported, name) {
5127
// Validates list of architectures or platforms.
5228
// Returns a normalized array if successful, or an error message string otherwise.
@@ -91,6 +67,30 @@ function getNameAndVersion (opts, dir, cb) {
9167
}
9268

9369
function createSeries (opts, archs, platforms) {
70+
var tempBase = path.join(opts.tmpdir || os.tmpdir(), 'electron-packager')
71+
72+
function testSymlink (cb) {
73+
var testPath = path.join(tempBase, 'symlink-test')
74+
var testFile = path.join(testPath, 'test')
75+
var testLink = path.join(testPath, 'testlink')
76+
series([
77+
function (cb) {
78+
mkdirp(testPath, cb)
79+
},
80+
function (cb) {
81+
fs.writeFile(testFile, '', cb)
82+
},
83+
function (cb) {
84+
fs.symlink(testFile, testLink, cb)
85+
}
86+
], function (err) {
87+
var result = !err
88+
rimraf(testPath, function () {
89+
cb(result) // ignore errors on cleanup
90+
})
91+
})
92+
}
93+
9494
var combinations = []
9595
archs.forEach(function (arch) {
9696
platforms.forEach(function (platform) {

readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ If the file extension is omitted, it is auto-completed to the correct extension
204204

205205
Whether SSL certificates are required to be valid when downloading Electron. **Defaults to `true`**.
206206

207+
`tmpdir` - *String*
208+
209+
The base directory to use as a temp directory. Defaults to the system temp directory.
210+
207211
`version` - *String*
208212

209213
The Electron version with which the app is built (without the leading 'v') - for example, [`0.33.9`](https://github.com/atom/electron/releases/tag/v0.33.9). See [Electron releases](https://github.com/atom/electron/releases) for valid versions. If omitted, it will use the version of the nearest local installation of electron-prebuilt.

test/basic.js

+27
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,32 @@ function createInferTest (combination) {
312312
}
313313
}
314314

315+
function createTmpdirTest (combination) {
316+
return function (t) {
317+
t.timeoutAfter(config.timeout)
318+
319+
var opts = Object.create(combination)
320+
opts.name = 'basicTest'
321+
opts.dir = path.join(__dirname, 'fixtures', 'basic')
322+
opts.out = 'dist'
323+
opts.tmpdir = path.join(util.getWorkCwd(), 'tmp')
324+
325+
waterfall([
326+
function (cb) {
327+
packager(opts, cb)
328+
}, function (paths, cb) {
329+
fs.stat(path.join(opts.tmpdir, 'electron-packager'), cb)
330+
},
331+
function (stats, cb) {
332+
t.true(stats.isDirectory(), 'The expected temp directory should exist')
333+
cb()
334+
}
335+
], function (err) {
336+
t.end(err)
337+
})
338+
}
339+
}
340+
315341
util.testAllPlatforms('infer test', createInferTest)
316342
util.testAllPlatforms('defaults test', createDefaultsTest)
317343
util.testAllPlatforms('out test', createOutTest)
@@ -325,3 +351,4 @@ util.testAllPlatforms('ignore test: string with slash', createIgnoreTest, 'ignor
325351
util.testAllPlatforms('ignore test: only match subfolder of app', createIgnoreTest, 'electron-packager',
326352
path.join('electron-packager', 'readme.txt'))
327353
util.testAllPlatforms('overwrite test', createOverwriteTest)
354+
util.testAllPlatforms('tmpdir test', createTmpdirTest)

usage.txt

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ prune runs `npm prune --production` on the app
3030
sign should contain the identity to be used when running `codesign` (only for building for the darwin platform, on OS X)
3131
strict-ssl whether SSL certificates are required to be valid when downloading Electron.
3232
It defaults to true, use --strict-ssl=false to disable checks.
33+
tmpdir temp directory. Defaults to system temp directory.
3334
version-string should contain a hash of the application metadata to be embedded into the executable (win32 platform only).
3435
These can be specified on the command line via dot notation,
3536
e.g. --version-string.CompanyName="Company Inc." --version-string.ProductName="Product"

0 commit comments

Comments
 (0)