diff --git a/cli/run/index.ts b/cli/run/index.ts index 190ff1efd21..dc6616ce064 100644 --- a/cli/run/index.ts +++ b/cli/run/index.ts @@ -16,7 +16,7 @@ export default function runRollup(command: any) { if (command.input) { handleError({ code: 'DUPLICATE_IMPORT_OPTIONS', - message: 'use --input, or pass input path as argument' + message: 'Either use --input, or pass input path as argument' }); } inputSource = command._; diff --git a/src/utils/parseOptions.ts b/src/utils/parseOptions.ts index 69af1fafb97..c683f06a325 100644 --- a/src/utils/parseOptions.ts +++ b/src/utils/parseOptions.ts @@ -43,7 +43,7 @@ const getObjectOption = ( const commandOption = normalizeObjectOptionValue(overrides[name]); const configOption = normalizeObjectOptionValue(config[name]); if (commandOption !== undefined) { - return commandOption && configOption ? { ...configOption, ...commandOption } : commandOption; + return commandOption && { ...configOption, ...commandOption }; } return configOption; }; diff --git a/test/cli/node_modules/rollup-config-foo/lib/config.js b/test/cli/node_modules/rollup-config-foo/lib/config.js deleted file mode 100644 index db00f465db4..00000000000 --- a/test/cli/node_modules/rollup-config-foo/lib/config.js +++ /dev/null @@ -1,11 +0,0 @@ -var replace = require( 'rollup-plugin-replace' ); - -module.exports = { - input: 'main.js', - output: { - format: 'cjs' - }, - plugins: [ - replace( { 'ANSWER': 42 } ) - ] -}; diff --git a/test/cli/node_modules/rollup-config-foo/package.json b/test/cli/node_modules/rollup-config-foo/package.json deleted file mode 100644 index fbd490130d0..00000000000 --- a/test/cli/node_modules/rollup-config-foo/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "main": "lib/config.js" -} diff --git a/test/cli/node_modules/foo/lib/config.js b/test/cli/node_modules_rename_me/bar/lib/config.js similarity index 100% rename from test/cli/node_modules/foo/lib/config.js rename to test/cli/node_modules_rename_me/bar/lib/config.js diff --git a/test/cli/node_modules/foo/package.json b/test/cli/node_modules_rename_me/bar/package.json similarity index 100% rename from test/cli/node_modules/foo/package.json rename to test/cli/node_modules_rename_me/bar/package.json diff --git a/test/cli/node_modules_rename_me/foo/lib/config.js b/test/cli/node_modules_rename_me/foo/lib/config.js deleted file mode 100644 index db00f465db4..00000000000 --- a/test/cli/node_modules_rename_me/foo/lib/config.js +++ /dev/null @@ -1,11 +0,0 @@ -var replace = require( 'rollup-plugin-replace' ); - -module.exports = { - input: 'main.js', - output: { - format: 'cjs' - }, - plugins: [ - replace( { 'ANSWER': 42 } ) - ] -}; diff --git a/test/cli/node_modules_rename_me/foo/package.json b/test/cli/node_modules_rename_me/foo/package.json deleted file mode 100644 index fbd490130d0..00000000000 --- a/test/cli/node_modules_rename_me/foo/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "main": "lib/config.js" -} diff --git a/test/cli/samples/duplicate-import-options/_config.js b/test/cli/samples/duplicate-import-options/_config.js new file mode 100644 index 00000000000..00eded60316 --- /dev/null +++ b/test/cli/samples/duplicate-import-options/_config.js @@ -0,0 +1,10 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'throws if different types of entries are combined', + command: 'rollup main.js --format es --input main.js', + error: () => true, + stderr(stderr) { + assertStderrIncludes(stderr, '[!] Either use --input, or pass input path as argument'); + } +}; diff --git a/test/cli/samples/duplicate-import-options/main.js b/test/cli/samples/duplicate-import-options/main.js new file mode 100644 index 00000000000..17eee8f1f7e --- /dev/null +++ b/test/cli/samples/duplicate-import-options/main.js @@ -0,0 +1 @@ +assert.equal( 1 + 1, 2 ); diff --git a/test/cli/samples/external-modules-auto-global/_config.js b/test/cli/samples/external-modules-auto-global/_config.js index 9f3e784156f..8163c5ad414 100644 --- a/test/cli/samples/external-modules-auto-global/_config.js +++ b/test/cli/samples/external-modules-auto-global/_config.js @@ -1,5 +1,11 @@ +const assert = require('assert'); + module.exports = { description: 'populates options.external with --global keys', - command: 'rollup main.js --format iife --globals mathematics:Math', - execute: true + command: + 'rollup main.js --format iife --globals mathematics:Math,promises:Promise --external promises', + execute: true, + stderr(stderr) { + assert.strictEqual(stderr.indexOf('(!)'), -1); + } }; diff --git a/test/cli/samples/external-modules-auto-global/main.js b/test/cli/samples/external-modules-auto-global/main.js index dcd8569f77f..ad436c33986 100644 --- a/test/cli/samples/external-modules-auto-global/main.js +++ b/test/cli/samples/external-modules-auto-global/main.js @@ -1,3 +1,5 @@ import { max } from 'mathematics'; +import { resolve } from 'promises'; assert.equal( max( 1, 2, 3 ), 3 ); +assert.ok( resolve().then ); diff --git a/test/cli/samples/external-modules/_config.js b/test/cli/samples/external-modules/_config.js index 8117a61be71..dbae8e93f67 100644 --- a/test/cli/samples/external-modules/_config.js +++ b/test/cli/samples/external-modules/_config.js @@ -1,5 +1,10 @@ +const assert = require('assert'); + module.exports = { description: 'allows external modules to be specified with --external=foo,bar,baz', - command: 'rollup main.js --format cjs --external path,util', - execute: true + command: 'rollup main.js --format cjs --external=path,util', + execute: true, + stderr(stderr) { + assert.strictEqual(stderr.indexOf('(!)'), -1); + } }; diff --git a/test/cli/samples/node-config-auto-prefix/_config.js b/test/cli/samples/node-config-auto-prefix/_config.js index 88b1368e750..084ade901da 100644 --- a/test/cli/samples/node-config-auto-prefix/_config.js +++ b/test/cli/samples/node-config-auto-prefix/_config.js @@ -1,5 +1,5 @@ module.exports = { - description: 'uses config file installed from npm', + description: 'uses config file installed from npm, automatically adding a rollup-config- prefix', command: 'rollup --config node:foo', execute: true }; diff --git a/test/cli/samples/node-config-not-found/_config.js b/test/cli/samples/node-config-not-found/_config.js new file mode 100644 index 00000000000..cf53bf19d71 --- /dev/null +++ b/test/cli/samples/node-config-not-found/_config.js @@ -0,0 +1,10 @@ +const { assertStderrIncludes } = require('../../../utils.js'); + +module.exports = { + description: 'throws if a config in node_modules cannot be found', + command: 'rollup --config node:baz', + error: () => true, + stderr(stderr) { + assertStderrIncludes(stderr, '[!] Could not resolve config file node:baz'); + } +}; diff --git a/test/cli/samples/node-config-not-found/_expected.js b/test/cli/samples/node-config-not-found/_expected.js new file mode 100644 index 00000000000..b5aa08a6ad6 --- /dev/null +++ b/test/cli/samples/node-config-not-found/_expected.js @@ -0,0 +1,11 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + global.myBundle = factory(); +}(this, function () { 'use strict'; + + var main = 42; + + return main; + +})); diff --git a/test/cli/samples/node-config-not-found/main.js b/test/cli/samples/node-config-not-found/main.js new file mode 100644 index 00000000000..df16c1b06b9 --- /dev/null +++ b/test/cli/samples/node-config-not-found/main.js @@ -0,0 +1 @@ +assert.equal( ANSWER, 42 ); diff --git a/test/cli/samples/node-config/_config.js b/test/cli/samples/node-config/_config.js index c17da4b1e3a..fdd13b0cc98 100644 --- a/test/cli/samples/node-config/_config.js +++ b/test/cli/samples/node-config/_config.js @@ -1,6 +1,6 @@ module.exports = { description: 'uses config file installed from npm', - command: 'rollup --config node:foo', + command: 'rollup --config node:bar', cwd: __dirname, execute: true };