Skip to content
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

feat(autoinstall): Add disabling of autoinstall globally via environm… #2152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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