-
-
Notifications
You must be signed in to change notification settings - Fork 57
Add buildManagerOptions config option (supports opting out of --ignore-lockfile)
#409
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,16 @@ module.exports = CoreObject.extend({ | |
| }, | ||
| useYarnCommand: false, | ||
| yarnLock: 'yarn.lock', | ||
| yarnLockBackupFileName: 'yarn.lock.ember-try', | ||
| configKey: 'npm', | ||
| packageJSON: 'package.json', | ||
| packageJSONBackupFileName: 'package.json.ember-try', | ||
| nodeModules: 'node_modules', | ||
| nodeModulesBackupLocation: '.node_modules.ember-try', | ||
| npmShrinkWrap: 'npm-shrinkwrap.json', | ||
| npmShrinkWrapBackupFileName: 'npm-shrinkwrap.json.ember-try', | ||
| packageLock: 'package-lock.json', | ||
| packageLockBackupFileName: 'package-lock.json.ember-try', | ||
| setup(options) { | ||
| if (!options) { | ||
| options = {}; | ||
|
|
@@ -33,7 +38,7 @@ module.exports = CoreObject.extend({ | |
|
|
||
| adapter.applyDependencySet(depSet); | ||
|
|
||
| return adapter._install().then(() => { | ||
| return adapter._install(depSet).then(() => { | ||
| let deps = extend({}, depSet.dependencies || {}, depSet.devDependencies || {}); | ||
| let currentDeps = Object.keys(deps).map((dep) => { | ||
| return { | ||
|
|
@@ -58,6 +63,18 @@ module.exports = CoreObject.extend({ | |
| let cleanupTasks = [rimraf(path.join(adapter.cwd, adapter.packageJSONBackupFileName)), | ||
| rimraf(path.join(adapter.cwd, adapter.nodeModulesBackupLocation))]; | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.yarnLockBackupFileName))) { | ||
| cleanupTasks.push(rimraf(path.join(adapter.cwd, adapter.yarnLockBackupFileName))); | ||
| } | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrapBackupFileName))) { | ||
| cleanupTasks.push(rimraf(path.join(adapter.cwd, adapter.npmShrinkWrapBackupFileName))); | ||
| } | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.packageLockBackupFileName))) { | ||
| cleanupTasks.push(rimraf(path.join(adapter.cwd, adapter.packageLockBackupFileName))); | ||
| } | ||
|
|
||
| return RSVP.all(cleanupTasks); | ||
| }).catch((e) => { | ||
| console.log('Error cleaning up npm scenario:', e); // eslint-disable-line no-console | ||
|
|
@@ -82,26 +99,35 @@ module.exports = CoreObject.extend({ | |
| return null; | ||
| } | ||
| }, | ||
| _install() { | ||
| _install(depSet) { | ||
| let adapter = this; | ||
| let mgrOptions = this.managerOptions || []; | ||
| let cmd = this.useYarnCommand ? 'yarn' : 'npm'; | ||
|
|
||
| debug('Run npm install with options %s', mgrOptions); | ||
| // buildManagerOptions overrides all default | ||
| if (typeof this.buildManagerOptions === 'function') { | ||
| mgrOptions = this.buildManagerOptions(depSet); | ||
|
|
||
| let cmd = this.useYarnCommand ? 'yarn' : 'npm'; | ||
| if (this.useYarnCommand) { | ||
| if (mgrOptions.indexOf('--no-lockfile') === -1) { | ||
| mgrOptions = mgrOptions.concat(['--no-lockfile']); | ||
| if (!Array.isArray(mgrOptions)) { | ||
| throw new Error('buildManagerOptions must return an array of options'); | ||
| } | ||
| // npm warns on incompatible engines | ||
| // yarn errors, not a good experience | ||
| if (mgrOptions.indexOf('--ignore-engines') === -1) { | ||
| mgrOptions = mgrOptions.concat(['--ignore-engines']); | ||
| } else { | ||
| if (this.useYarnCommand) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we intend to mandate the buildManagerOptions in the future? If so, we can add a deprecation here that encourages to use the manager options for these defaults.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, I believe that it will always be a "power user" option. I would expect that most users would use whatever our default command line options are, and you'd only specify
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree; it is backward compatible and users do not need to use it if there isn't a need. |
||
| if (mgrOptions.indexOf('--no-lockfile') === -1) { | ||
| mgrOptions = mgrOptions.concat(['--no-lockfile']); | ||
| } | ||
| // npm warns on incompatible engines | ||
| // yarn errors, not a good experience | ||
| if (mgrOptions.indexOf('--ignore-engines') === -1) { | ||
| mgrOptions = mgrOptions.concat(['--ignore-engines']); | ||
| } | ||
| } else if (mgrOptions.indexOf('--no-shrinkwrap') === -1) { | ||
| mgrOptions = mgrOptions.concat(['--no-shrinkwrap']); | ||
| } | ||
| } else if (mgrOptions.indexOf('--no-shrinkwrap') === -1) { | ||
| mgrOptions = mgrOptions.concat(['--no-shrinkwrap']); | ||
| } | ||
|
|
||
| debug('Run npm/yarn install with options %s', mgrOptions); | ||
|
|
||
| return this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd }).then(() => { | ||
| if (!adapter.useYarnCommand) { | ||
| return adapter.run('npm', ['--version'], { cwd: this.cwd, stdio: 'pipe' }).then((res) => { | ||
|
|
@@ -171,6 +197,21 @@ module.exports = CoreObject.extend({ | |
| path.join(this.cwd, this.nodeModules), { clobber: true }), | ||
| ]; | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.yarnLockBackupFileName))) { | ||
| restoreTasks.push(copy(path.join(this.cwd, this.yarnLockBackupFileName), | ||
| path.join(this.cwd, this.yarnLock))); | ||
| } | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrapBackupFileName))) { | ||
| restoreTasks.push(copy(path.join(this.cwd, this.npmShrinkWrapBackupFileName), | ||
| path.join(this.cwd, this.npmShrinkWrap))); | ||
| } | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.packageLockBackupFileName))) { | ||
| restoreTasks.push(copy(path.join(this.cwd, this.packageLockBackupFileName), | ||
| path.join(this.cwd, this.packageLock))); | ||
| } | ||
|
|
||
| return RSVP.all(restoreTasks); | ||
| }, | ||
| _backupOriginalDependencies() { | ||
|
|
@@ -184,6 +225,21 @@ module.exports = CoreObject.extend({ | |
| copy(path.join(this.cwd, this.nodeModules), | ||
| path.join(this.cwd, this.nodeModulesBackupLocation), { clobber: true })]; | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.yarnLock))) { | ||
| backupTasks.push(copy(path.join(this.cwd, this.yarnLock), | ||
| path.join(this.cwd, this.yarnLockBackupFileName))); | ||
| } | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrap))) { | ||
| backupTasks.push(copy(path.join(this.cwd, this.npmShrinkWrap), | ||
| path.join(this.cwd, this.npmShrinkWrapBackupFileName))); | ||
| } | ||
|
|
||
| if (fs.existsSync(path.join(this.cwd, this.packageLock))) { | ||
| backupTasks.push(copy(path.join(this.cwd, this.packageLock), | ||
| path.join(this.cwd, this.packageLockBackupFileName))); | ||
| } | ||
|
|
||
| return RSVP.all(backupTasks); | ||
| }, | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.