-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add package-manager option #618
Merged
+170
−54
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
const child = require('child_process') | ||
const debug = require('debug')('electron-packager') | ||
|
||
const knownPackageManagers = ['npm', 'cnpm', 'yarn'] | ||
|
||
function pruneCommand (packageManager) { | ||
switch (packageManager) { | ||
case 'npm': | ||
case 'cnpm': | ||
return `${packageManager} prune --production` | ||
case 'yarn': | ||
return `${packageManager} install --production` | ||
} | ||
} | ||
|
||
function pruneModules (opts, appPath, cb) { | ||
const packageManager = opts.packageManager || 'npm' | ||
|
||
if (packageManager === 'cnpm' && process.platform === 'win32') { | ||
return cb(new Error('cnpm support does not currently work with Windows, see: https://github.com/electron-userland/electron-packager/issues/515#issuecomment-297604044')) | ||
} | ||
|
||
const command = pruneCommand(packageManager) | ||
|
||
if (command) { | ||
debug(`Pruning modules via: ${command}`) | ||
child.exec(command, { cwd: appPath }, cb) | ||
} else { | ||
cb(new Error(`Unknown package manager "${packageManager}". Known package managers: ${knownPackageManagers.join(', ')}`)) | ||
} | ||
} | ||
|
||
module.exports = { | ||
pruneCommand: pruneCommand, | ||
pruneModules: pruneModules | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
'use strict' | ||
|
||
const config = require('./config.json') | ||
const fs = require('fs-extra') | ||
const packager = require('..') | ||
const path = require('path') | ||
const prune = require('../prune') | ||
const test = require('tape') | ||
const util = require('./util') | ||
const waterfall = require('run-waterfall') | ||
const which = require('which') | ||
|
||
function createPruneOptionTest (baseOpts, prune, testMessage) { | ||
return (t) => { | ||
t.timeoutAfter(config.timeout) | ||
|
||
let opts = Object.create(baseOpts) | ||
opts.name = 'basicTest' | ||
opts.dir = path.join(__dirname, 'fixtures', 'basic') | ||
opts.prune = prune | ||
|
||
let finalPath | ||
let resourcesPath | ||
|
||
waterfall([ | ||
(cb) => { | ||
packager(opts, cb) | ||
}, (paths, cb) => { | ||
finalPath = paths[0] | ||
fs.stat(finalPath, cb) | ||
}, (stats, cb) => { | ||
t.true(stats.isDirectory(), 'The expected output directory should exist') | ||
resourcesPath = path.join(finalPath, util.generateResourcesPath(opts)) | ||
fs.stat(resourcesPath, cb) | ||
}, (stats, cb) => { | ||
t.true(stats.isDirectory(), 'The output directory should contain the expected resources subdirectory') | ||
fs.stat(path.join(resourcesPath, 'app', 'node_modules', 'run-series'), cb) | ||
}, (stats, cb) => { | ||
t.true(stats.isDirectory(), 'package.json dependency should exist under app/node_modules') | ||
fs.exists(path.join(resourcesPath, 'app', 'node_modules', 'run-waterfall'), (exists) => { | ||
t.equal(!prune, exists, testMessage) | ||
cb() | ||
}) | ||
} | ||
], (err) => { | ||
t.end(err) | ||
}) | ||
} | ||
} | ||
|
||
test('pruneCommand returns the correct command when passing a known package manager', (t) => { | ||
t.equal(prune.pruneCommand('npm'), 'npm prune --production', 'passing npm gives the npm prune command') | ||
t.equal(prune.pruneCommand('cnpm'), 'cnpm prune --production', 'passing cnpm gives the cnpm prune command') | ||
t.equal(prune.pruneCommand('yarn'), 'yarn install --production', 'passing yarn gives the yarn "prune command"') | ||
t.end() | ||
}) | ||
|
||
test('pruneCommand returns null when the package manager is unknown', (t) => { | ||
t.notOk(prune.pruneCommand('unknown-package-manager')) | ||
t.end() | ||
}) | ||
|
||
test('pruneModules returns an error when the package manager is unknown', (t) => { | ||
prune.pruneModules({packageManager: 'unknown-package-manager'}, '/tmp/app-path', (err) => { | ||
t.ok(err, 'error returned') | ||
t.end() | ||
}) | ||
}) | ||
|
||
if (process.platform === 'win32') { | ||
test('pruneModules returns an error when trying to use cnpm on Windows', (t) => { | ||
prune.pruneModules({packageManager: 'cnpm'}, '/tmp/app-path', (err) => { | ||
t.ok(err, 'error returned') | ||
t.end() | ||
}) | ||
}) | ||
} | ||
|
||
// This is not in the below loop so that it tests the default packageManager option. | ||
util.testSinglePlatform('prune test with npm', (baseOpts) => { | ||
return createPruneOptionTest(baseOpts, true, 'package.json devDependency should NOT exist under app/node_modules') | ||
}) | ||
|
||
for (const packageManager of ['cnpm', 'yarn']) { | ||
which(packageManager, (err, resolvedPath) => { | ||
if (err) return | ||
|
||
util.testSinglePlatform(`prune test with ${packageManager}`, (baseOpts) => { | ||
const opts = Object.assign({packageManager: packageManager}, baseOpts) | ||
return createPruneOptionTest(opts, true, 'package.json devDependency should NOT exist under app/node_modules') | ||
}) | ||
}) | ||
} | ||
|
||
util.testSinglePlatform('prune=false test', (baseOpts) => { | ||
return createPruneOptionTest(baseOpts, false, 'npm devDependency should exist under app/node_modules') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should come back in some form or another. We need to be able to see when the prune operation occurs and with what package manager. It's pretty helpful for debugging user problems.