Browse Source

Merge pull request #739 from rollup/gh-736

Use config files installed in `node_modules`
semi-dynamic-namespace-imports
Rich Harris 9 years ago
committed by GitHub
parent
commit
f5fdedc72e
  1. 3
      .gitignore
  2. 4
      bin/src/handleError.js
  3. 17
      bin/src/runRollup.js
  4. 5
      test/cli/node-config-auto-prefix/_config.js
  5. 11
      test/cli/node-config-auto-prefix/_expected.js
  6. 1
      test/cli/node-config-auto-prefix/main.js
  7. 9
      test/cli/node-config-auto-prefix/node_modules/rollup-config-foo/lib/config.js
  8. 3
      test/cli/node-config-auto-prefix/node_modules/rollup-config-foo/package.json
  9. 5
      test/cli/node-config/_config.js
  10. 11
      test/cli/node-config/_expected.js
  11. 1
      test/cli/node-config/main.js
  12. 9
      test/cli/node-config/node_modules/foo/lib/config.js
  13. 3
      test/cli/node-config/node_modules/foo/package.json

3
.gitignore

@ -1,6 +1,5 @@
.DS_Store
node_modules
!test/node_modules
/node_modules
.gobble*
dist
_actual

4
bin/src/handleError.js

@ -9,6 +9,10 @@ const handlers = {
stderr( chalk.red( 'Config file must export an options object. See https://github.com/rollup/rollup/wiki/Command-Line-Interface#using-a-config-file' ) );
},
MISSING_EXTERNAL_CONFIG: err => {
stderr( chalk.red( `Could not resolve config file ${err.config}` ) );
},
MISSING_INPUT_OPTION: () => {
stderr( chalk.red( 'You must specify an --input (-i) option' ) );
},

17
bin/src/runRollup.js

@ -38,7 +38,24 @@ export default function runRollup ( command ) {
let config = command.config === true ? 'rollup.config.js' : command.config;
if ( config ) {
if ( config.slice( 0, 5 ) === 'node:' ) {
const pkgName = config.slice( 5 );
try {
config = relative.resolve( pkgName, process.cwd() );
} catch ( err ) {
try {
config = relative.resolve( `rollup-config-${pkgName}`, process.cwd() );
} catch ( err ) {
if ( err.code === 'MODULE_NOT_FOUND' ) {
handleError({ code: 'MISSING_EXTERNAL_CONFIG', config });
}
throw err;
}
}
} else {
config = resolve( config );
}
rollup.rollup({
entry: config,

5
test/cli/node-config-auto-prefix/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'uses config file installed from npm',
command: 'rollup --config node:foo',
execute: true
};

11
test/cli/node-config-auto-prefix/_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;
}));

1
test/cli/node-config-auto-prefix/main.js

@ -0,0 +1 @@
assert.equal( ANSWER, 42 );

9
test/cli/node-config-auto-prefix/node_modules/rollup-config-foo/lib/config.js

@ -0,0 +1,9 @@
var replace = require( 'rollup-plugin-replace' );
module.exports = {
entry: 'main.js',
format: 'cjs',
plugins: [
replace({ 'ANSWER': 42 })
]
};

3
test/cli/node-config-auto-prefix/node_modules/rollup-config-foo/package.json

@ -0,0 +1,3 @@
{
"main": "lib/config.js"
}

5
test/cli/node-config/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'uses config file installed from npm',
command: 'rollup --config node:foo',
execute: true
};

11
test/cli/node-config/_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;
}));

1
test/cli/node-config/main.js

@ -0,0 +1 @@
assert.equal( ANSWER, 42 );

9
test/cli/node-config/node_modules/foo/lib/config.js

@ -0,0 +1,9 @@
var replace = require( 'rollup-plugin-replace' );
module.exports = {
entry: 'main.js',
format: 'cjs',
plugins: [
replace({ 'ANSWER': 42 })
]
};

3
test/cli/node-config/node_modules/foo/package.json

@ -0,0 +1,3 @@
{
"main": "lib/config.js"
}
Loading…
Cancel
Save