-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow local .npmrc to override internal env variables set by the runn…
…ing npm process, fixes #81
- Loading branch information
Showing
15 changed files
with
198 additions
and
26 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*global describe, it, beforeEach, afterEach, require, it, expect */ | ||
var underTest = require('../src/tasks/clean-up-package'), | ||
shell = require('shelljs'), | ||
fs = require('fs'), | ||
ArrayLogger = require('../src/util/array-logger'), | ||
tmppath = require('../src/util/tmppath'), | ||
runNpm = require('../src/util/run-npm'), | ||
path = require('path'); | ||
describe('cleanUpPackage', function () { | ||
'use strict'; | ||
var sourcedir, pwd, | ||
logger, | ||
configurePackage = function (packageConf) { | ||
fs.writeFileSync(path.join(sourcedir, 'package.json'), JSON.stringify(packageConf), 'utf8'); | ||
}; | ||
beforeEach(function (done) { | ||
sourcedir = tmppath(); | ||
shell.mkdir(sourcedir); | ||
logger = new ArrayLogger(); | ||
pwd = shell.pwd(); | ||
configurePackage({ | ||
dependencies: { | ||
'uuid': '^2.0.0' | ||
}, | ||
optionalDependencies: { | ||
'minimist': '^1.2.0' | ||
} | ||
}); | ||
runNpm(sourcedir, 'install', logger).then(done, done.fail); | ||
}); | ||
afterEach(function () { | ||
shell.cd(pwd); | ||
if (sourcedir) { | ||
shell.rm('-rf', sourcedir); | ||
} | ||
}); | ||
it('returns the directory path', function (done) { | ||
underTest(sourcedir, {}, logger).then(function (result) { | ||
expect(result).toEqual(sourcedir); | ||
}).then(done, done.fail); | ||
}); | ||
it('does not clean up optional dependencies if not requested', function (done) { | ||
underTest(sourcedir, {}, logger).then(function (result) { | ||
expect(result).toEqual(sourcedir); | ||
expect(shell.test('-e', path.join(sourcedir, 'node_modules', 'uuid'))).toBeTruthy(); | ||
expect(shell.test('-e', path.join(sourcedir, 'node_modules', 'minimist'))).toBeTruthy(); | ||
}).then(done, done.fail); | ||
}); | ||
it('cleans up optional dependencies if requested', function (done) { | ||
underTest(sourcedir, {'optional-dependencies': false}, logger).then(function (result) { | ||
expect(result).toEqual(sourcedir); | ||
expect(shell.test('-e', path.join(sourcedir, 'node_modules', 'uuid'))).toBeTruthy(); | ||
expect(shell.test('-e', path.join(sourcedir, 'node_modules', 'minimist'))).toBeFalsy(); | ||
}).then(done, done.fail); | ||
}); | ||
it('removes .npmrc if exists', function (done) { | ||
fs.writeFileSync(path.join(sourcedir, '.npmrc'), 'optional = false', 'utf8'); | ||
underTest(sourcedir, {}, logger).then(function (result) { | ||
expect(result).toEqual(sourcedir); | ||
expect(shell.test('-e', path.join(sourcedir, '.npmrc'))).toBeFalsy(); | ||
}).then(done, done.fail); | ||
|
||
}); | ||
it('fails if npm install fails', function (done) { | ||
configurePackage({ | ||
files: ['root.txt'], | ||
dependencies: { | ||
'non-existing-package': '2.0.0' | ||
} | ||
}); | ||
underTest(sourcedir, {'optional-dependencies': false}, logger).then(done.fail, function (reason) { | ||
expect(reason).toMatch(/npm install --production --no-optional failed/); | ||
done(); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
optional = false |
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,8 @@ | ||
/*global exports, require*/ | ||
var fs = require('fs'); | ||
exports.handler = function (event, context) { | ||
'use strict'; | ||
context.succeed({ | ||
files: fs.readdirSync('.') | ||
}); | ||
}; |
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,8 @@ | ||
{ | ||
"name": "echo", | ||
"version": "1.0.0", | ||
"private": true, | ||
"files": [ | ||
"main.js" | ||
] | ||
} |
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 was deleted.
Oops, something went wrong.
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,20 @@ | ||
/*global module, require, Promise */ | ||
var shell = require('shelljs'), | ||
path = require('path'), | ||
runNpm = require('../util/run-npm'); | ||
module.exports = function cleanUpPackage(packageDir, options, logger) { | ||
'use strict'; | ||
var cleanUpDependencies = function () { | ||
if (options['optional-dependencies'] === false) { | ||
logger.logApiCall('removing optional dependencies'); | ||
shell.rm('-rf', path.join(packageDir, 'node_modules')); | ||
return runNpm(packageDir, 'install --production --no-optional', logger); | ||
} else { | ||
return Promise.resolve(); | ||
} | ||
}; | ||
return cleanUpDependencies().then(function () { | ||
shell.rm('-rf', path.join(packageDir, '.npmrc')); | ||
return packageDir; | ||
}); | ||
}; |
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