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
…ent variable

-Closes #2130.
  • Loading branch information
cacheflow committed Oct 18, 2018
1 parent 75310e1 commit caa6a36
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/core/parcel-bundler/src/Bundler.js
Expand Up @@ -103,6 +103,10 @@ class Bundler extends EventEmitter {
: watch;
const scopeHoist =
options.scopeHoist !== undefined ? options.scopeHoist : false;
const autoInstall = typeof options.autoinstall === 'boolean'
? options.autoinstall
: typeof process.env.PARCEL_AUTOINSTALL !== 'boolean' ? process.env.PARCEL_AUTOINSTALL :
!isProduction;
return {
production: isProduction,
outDir: Path.resolve(options.outDir || 'dist'),
Expand Down Expand Up @@ -134,10 +138,7 @@ class Bundler extends EventEmitter {
(options.target === 'electron' ? 'localhost' : ''),
detailedReport: options.detailedReport || false,
global: options.global,
autoinstall:
typeof options.autoinstall === 'boolean'
? options.autoinstall
: !isProduction,
autoinstall: autoInstall,
scopeHoist: scopeHoist,
contentHash:
typeof options.contentHash === 'boolean'
Expand Down
@@ -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": {}
}
20 changes: 20 additions & 0 deletions packages/core/parcel-bundler/test/javascript.js
Expand Up @@ -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'
Expand Down

0 comments on commit caa6a36

Please sign in to comment.