From b2ce937b3c775c541a406f9eb5bff4641188fbd2 Mon Sep 17 00:00:00 2001 From: David Rodrigue Date: Tue, 5 Jan 2016 12:02:53 -0600 Subject: [PATCH] add `tmpdir` option to allow specifying a custom temp directory for the build --- common.js | 2 +- index.js | 48 ++++++++++++++++++++++++------------------------ readme.md | 4 ++++ test/basic.js | 27 +++++++++++++++++++++++++++ usage.txt | 1 + 5 files changed, 57 insertions(+), 25 deletions(-) diff --git a/common.js b/common.js index 769c6a70..e2ac36df 100644 --- a/common.js +++ b/common.js @@ -60,7 +60,7 @@ module.exports = { // * Prunes non-production node_modules (if opts.prune is set) // * Creates an asar (if opts.asar is set) - var tempParent = path.join(os.tmpdir(), 'electron-packager', opts.platform + '-' + opts.arch) + var tempParent = path.join(opts.tmpdir || os.tmpdir(), 'electron-packager', opts.platform + '-' + opts.arch) var tempPath = path.join(tempParent, generateFinalBasename(opts)) // Path to `app` directory var appPath = path.join(tempPath, appRelativePath) diff --git a/index.js b/index.js index d304c0e4..c5e69300 100644 --- a/index.js +++ b/index.js @@ -23,30 +23,6 @@ var supportedPlatforms = { win32: './win32' } -var tempBase = path.join(os.tmpdir(), 'electron-packager') - -function testSymlink (cb) { - var testPath = path.join(tempBase, 'symlink-test') - var testFile = path.join(testPath, 'test') - var testLink = path.join(testPath, 'testlink') - series([ - function (cb) { - mkdirp(testPath, cb) - }, - function (cb) { - fs.writeFile(testFile, '', cb) - }, - function (cb) { - fs.symlink(testFile, testLink, cb) - } - ], function (err) { - var result = !err - rimraf(testPath, function () { - cb(result) // ignore errors on cleanup - }) - }) -} - function validateList (list, supported, name) { // Validates list of architectures or platforms. // Returns a normalized array if successful, or an error message string otherwise. @@ -91,6 +67,30 @@ function getNameAndVersion (opts, dir, cb) { } function createSeries (opts, archs, platforms) { + var tempBase = path.join(opts.tmpdir || os.tmpdir(), 'electron-packager') + + function testSymlink (cb) { + var testPath = path.join(tempBase, 'symlink-test') + var testFile = path.join(testPath, 'test') + var testLink = path.join(testPath, 'testlink') + series([ + function (cb) { + mkdirp(testPath, cb) + }, + function (cb) { + fs.writeFile(testFile, '', cb) + }, + function (cb) { + fs.symlink(testFile, testLink, cb) + } + ], function (err) { + var result = !err + rimraf(testPath, function () { + cb(result) // ignore errors on cleanup + }) + }) + } + var combinations = [] archs.forEach(function (arch) { platforms.forEach(function (platform) { diff --git a/readme.md b/readme.md index 6aef89c7..cea3ad3b 100644 --- a/readme.md +++ b/readme.md @@ -204,6 +204,10 @@ If the file extension is omitted, it is auto-completed to the correct extension Whether SSL certificates are required to be valid when downloading Electron. **Defaults to `true`**. +`tmpdir` - *String* + + The base directory to use as a temp directory. Defaults to the system temp directory. + `version` - *String* 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. diff --git a/test/basic.js b/test/basic.js index d37b6d61..cd41b768 100644 --- a/test/basic.js +++ b/test/basic.js @@ -312,6 +312,32 @@ function createInferTest (combination) { } } +function createTmpdirTest (combination) { + return function (t) { + t.timeoutAfter(config.timeout) + + var opts = Object.create(combination) + opts.name = 'basicTest' + opts.dir = path.join(__dirname, 'fixtures', 'basic') + opts.out = 'dist' + opts.tmpdir = path.join(util.getWorkCwd(), 'tmp') + + waterfall([ + function (cb) { + packager(opts, cb) + }, function (paths, cb) { + fs.stat(path.join(opts.tmpdir, 'electron-packager'), cb) + }, + function (stats, cb) { + t.true(stats.isDirectory(), 'The expected temp directory should exist') + cb() + } + ], function (err) { + t.end(err) + }) + } +} + util.testAllPlatforms('infer test', createInferTest) util.testAllPlatforms('defaults test', createDefaultsTest) util.testAllPlatforms('out test', createOutTest) @@ -325,3 +351,4 @@ util.testAllPlatforms('ignore test: string with slash', createIgnoreTest, 'ignor util.testAllPlatforms('ignore test: only match subfolder of app', createIgnoreTest, 'electron-packager', path.join('electron-packager', 'readme.txt')) util.testAllPlatforms('overwrite test', createOverwriteTest) +util.testAllPlatforms('tmpdir test', createTmpdirTest) diff --git a/usage.txt b/usage.txt index 1b330d11..520bf9ae 100644 --- a/usage.txt +++ b/usage.txt @@ -30,6 +30,7 @@ prune runs `npm prune --production` on the app sign should contain the identity to be used when running `codesign` (only for building for the darwin platform, on OS X) strict-ssl whether SSL certificates are required to be valid when downloading Electron. It defaults to true, use --strict-ssl=false to disable checks. +tmpdir temp directory. Defaults to system temp directory. version-string should contain a hash of the application metadata to be embedded into the executable (win32 platform only). These can be specified on the command line via dot notation, e.g. --version-string.CompanyName="Company Inc." --version-string.ProductName="Product"