Skip to content

Commit

Permalink
feat(autoinstall): Add disabling of autoinstall globally via environm… (
Browse files Browse the repository at this point in the history
  • Loading branch information
cacheflow authored and devongovett committed Mar 6, 2019
1 parent bec96be commit 011bfa9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
@@ -0,0 +1 @@
PARCEL_AUTOINSTALL=false
@@ -0,0 +1,4 @@
const _ = require('lodash');
module.exports = function() {
return 'hello world';
}
@@ -0,0 +1,4 @@
{
"name": "dont-autoinstall-if-env-var-is-false",
"dependencies": {}
}
22 changes: 22 additions & 0 deletions packages/core/integration-tests/test/javascript.js
Expand Up @@ -50,6 +50,28 @@ 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'"));
}

delete process.env.PARCEL_AUTOINSTALL;
});

it('should auto install babel-core v6', async function() {
let originalPkg = await fs.readFile(
__dirname + '/integration/babel-6-autoinstall/package.json'
Expand Down
8 changes: 5 additions & 3 deletions packages/core/parcel-bundler/src/Bundler.js
Expand Up @@ -142,9 +142,11 @@ class Bundler extends EventEmitter {
detailedReport: options.detailedReport || false,
global: options.global,
autoinstall:
typeof options.autoinstall === 'boolean'
? options.autoinstall
: !isProduction,
typeof options.autoInstall === 'boolean'
? options.autoInstall
: process.env.PARCEL_AUTOINSTALL === 'false'
? false
: !isProduction,
scopeHoist: scopeHoist,
contentHash:
typeof options.contentHash === 'boolean'
Expand Down

0 comments on commit 011bfa9

Please sign in to comment.