diff --git a/packages/core/parcel-bundler/src/Bundler.js b/packages/core/parcel-bundler/src/Bundler.js index 97064a08b9e..8151670533a 100644 --- a/packages/core/parcel-bundler/src/Bundler.js +++ b/packages/core/parcel-bundler/src/Bundler.js @@ -135,7 +135,8 @@ class Bundler extends EventEmitter { detailedReport: options.detailedReport || false, global: options.global, autoinstall: - typeof options.autoinstall === 'boolean' + typeof options.autoinstall === 'boolean' && + process.env.PARCEL_AUTOINSTALL !== 'false' ? options.autoinstall : !isProduction, scopeHoist: scopeHoist, diff --git a/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/.env b/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/.env new file mode 100644 index 00000000000..ae52a618025 --- /dev/null +++ b/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/.env @@ -0,0 +1 @@ +PARCEL_AUTOINSTALL=false diff --git a/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/index.js b/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/index.js new file mode 100644 index 00000000000..0eb870aa590 --- /dev/null +++ b/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/index.js @@ -0,0 +1,4 @@ +const _ = require('lodash'); +module.exports = function() { + return 'hello world'; +} diff --git a/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/package.json b/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/package.json new file mode 100644 index 00000000000..70f7cadc900 --- /dev/null +++ b/packages/core/parcel-bundler/test/integration/dont-autoinstall-if-env-var-is-false/package.json @@ -0,0 +1,4 @@ +{ + "name": "dont-autoinstall-if-env-var-is-false", + "dependencies": {} +} diff --git a/packages/core/parcel-bundler/test/javascript.js b/packages/core/parcel-bundler/test/javascript.js index d620fc634f6..3daa2805a93 100644 --- a/packages/core/parcel-bundler/test/javascript.js +++ b/packages/core/parcel-bundler/test/javascript.js @@ -42,6 +42,26 @@ describe('javascript', function() { assert.equal(output.default(), 3); }); + it('should not autoinstall if PARCEL_AUTOINSTALL is set to false', async function() { + const inputDir = path.join( + __dirname, + '/integration/dont-autoinstall-if-env-var-is-false/' + ); + try { + let a = await bundle(path.resolve(inputDir, './index.js')); + await run(a); + } catch (e) { + let pkg = await fs.readFile( + path.resolve(inputDir, 'package.json'), + 'utf8' + ); + const pkgName = 'lodash'; + pkg = JSON.parse(pkg); + assert(pkgName in pkg.dependencies === false); + assert(e.message.includes("Cannot resolve dependency 'lodash'")); + } + }); + it('should auto install babel-core v6', async function() { let originalPkg = await fs.readFile( __dirname + '/integration/babel-6-autoinstall/package.json'