mirror of https://github.com/lukechilds/rollup.git
511 changed files with 3847 additions and 1089 deletions
@ -0,0 +1,2 @@ |
|||
test/* |
|||
!test/test.js |
@ -1,23 +1,35 @@ |
|||
{ |
|||
"root": true, |
|||
"rules": { |
|||
"indent": [ 2, "tab", { "SwitchCase": 1 } ], |
|||
"quotes": [ 2, "single" ], |
|||
"semi": [ 2, "always" ], |
|||
"space-after-keywords": [ 2, "always" ], |
|||
"space-before-blocks": [ 2, "always" ], |
|||
"space-before-function-paren": [ 2, "always" ], |
|||
"no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ], |
|||
"no-cond-assign": [ 0 ] |
|||
}, |
|||
"env": { |
|||
"es6": true, |
|||
"browser": true, |
|||
"mocha": true, |
|||
"node": true |
|||
}, |
|||
"extends": "eslint:recommended", |
|||
"ecmaFeatures": { |
|||
"modules": true |
|||
} |
|||
"root": true, |
|||
"rules": { |
|||
"indent": [ 2, "tab", { "SwitchCase": 1 } ], |
|||
"semi": [ 2, "always" ], |
|||
"keyword-spacing": [ 2, { "before": true, "after": true } ], |
|||
"space-before-blocks": [ 2, "always" ], |
|||
"space-before-function-paren": [ 2, "always" ], |
|||
"no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ], |
|||
"no-cond-assign": 0, |
|||
"no-unused-vars": 2, |
|||
"object-shorthand": [ 2, "always" ], |
|||
"no-const-assign": 2, |
|||
"no-class-assign": 2, |
|||
"no-this-before-super": 2, |
|||
"no-var": 2, |
|||
"no-unreachable": 2, |
|||
"valid-typeof": 2, |
|||
"quote-props": [ 2, "as-needed" ], |
|||
"one-var": [ 2, "never" ], |
|||
"prefer-arrow-callback": 2, |
|||
"prefer-const": [ 2, { "destructuring": "all" } ], |
|||
"arrow-spacing": 2 |
|||
}, |
|||
"env": { |
|||
"es6": true, |
|||
"browser": true, |
|||
"node": true |
|||
}, |
|||
"extends": "eslint:recommended", |
|||
"parserOptions": { |
|||
"ecmaVersion": 6, |
|||
"sourceType": "module" |
|||
} |
|||
} |
|||
|
@ -1,9 +1,9 @@ |
|||
.DS_Store |
|||
node_modules |
|||
!test/node_modules |
|||
/node_modules |
|||
.gobble* |
|||
dist |
|||
_actual |
|||
coverage |
|||
.commithash |
|||
.idea |
|||
bin/rollup |
|||
|
@ -1,49 +0,0 @@ |
|||
var chalk = require( 'chalk' ); |
|||
|
|||
var handlers = { |
|||
MISSING_CONFIG: function () { |
|||
console.error( chalk.red( 'Config file must export an options object. See https://github.com/rollup/rollup/wiki/Command-Line-Interface#using-a-config-file' ) ); |
|||
}, |
|||
|
|||
MISSING_INPUT_OPTION: function () { |
|||
console.error( chalk.red( 'You must specify an --input (-i) option' ) ); |
|||
}, |
|||
|
|||
MISSING_OUTPUT_OPTION: function () { |
|||
console.error( chalk.red( 'You must specify an --output (-o) option when creating a file with a sourcemap' ) ); |
|||
}, |
|||
|
|||
MISSING_NAME: function ( err ) { |
|||
console.error( chalk.red( 'You must supply a name for UMD exports (e.g. `--name myModule`)' ) ); |
|||
}, |
|||
|
|||
PARSE_ERROR: function ( err ) { |
|||
console.error( chalk.red( 'Error parsing ' + err.file + ': ' + err.message ) ); |
|||
}, |
|||
|
|||
ONE_AT_A_TIME: function ( err ) { |
|||
console.error( chalk.red( 'rollup can only bundle one file at a time' ) ); |
|||
}, |
|||
|
|||
DUPLICATE_IMPORT_OPTIONS: function ( err ) { |
|||
console.error( chalk.red( 'use --input, or pass input path as argument' ) ); |
|||
} |
|||
}; |
|||
|
|||
module.exports = function handleError ( err ) { |
|||
var handler; |
|||
|
|||
if ( handler = handlers[ err && err.code ] ) { |
|||
handler( err ); |
|||
} else { |
|||
console.error( chalk.red( err.message || err ) ); |
|||
|
|||
if ( err.stack ) { |
|||
console.error( chalk.grey( err.stack ) ); |
|||
} |
|||
} |
|||
|
|||
console.error( 'Type ' + chalk.cyan( 'rollup --help' ) + ' for help, or visit https://github.com/rollup/rollup/wiki' ); |
|||
|
|||
process.exit( 1 ); |
|||
}; |
@ -1,37 +0,0 @@ |
|||
#!/usr/bin/env node |
|||
|
|||
var minimist = require( 'minimist' ), |
|||
command; |
|||
|
|||
command = minimist( process.argv.slice( 2 ), { |
|||
alias: { |
|||
// Aliases |
|||
strict: 'useStrict', |
|||
|
|||
// Short options |
|||
c: 'config', |
|||
d: 'indent', |
|||
e: 'external', |
|||
f: 'format', |
|||
g: 'globals', |
|||
h: 'help', |
|||
i: 'input', |
|||
m: 'sourcemap', |
|||
n: 'name', |
|||
o: 'output', |
|||
u: 'id', |
|||
v: 'version' |
|||
} |
|||
}); |
|||
|
|||
if ( command.help || ( process.argv.length <= 2 && process.stdin.isTTY ) ) { |
|||
require( './showHelp' )(); |
|||
} |
|||
|
|||
else if ( command.version ) { |
|||
console.log( 'rollup version ' + require( '../package.json' ).version ); |
|||
} |
|||
|
|||
else { |
|||
require( './runRollup' )( command ); |
|||
} |
@ -1,161 +0,0 @@ |
|||
require( 'source-map-support' ).install(); |
|||
|
|||
var path = require( 'path' ); |
|||
var handleError = require( './handleError' ); |
|||
var rollup = require( '../' ); |
|||
|
|||
// log to stderr to keep `rollup main.js > bundle.js` from breaking
|
|||
var log = console.error.bind(console); |
|||
|
|||
module.exports = function ( command ) { |
|||
if ( command._.length > 1 ) { |
|||
handleError({ code: 'ONE_AT_A_TIME' }); |
|||
} |
|||
|
|||
if ( command._.length === 1 ) { |
|||
if ( command.input ) { |
|||
handleError({ code: 'DUPLICATE_IMPORT_OPTIONS' }); |
|||
} |
|||
|
|||
command.input = command._[0]; |
|||
} |
|||
|
|||
if ( command.environment ) { |
|||
command.environment.split( ',' ).forEach( function ( pair ) { |
|||
var index = pair.indexOf( ':' ); |
|||
if ( ~index ) { |
|||
process.env[ pair.slice( 0, index ) ] = pair.slice( index + 1 ); |
|||
} else { |
|||
process.env[ pair ] = true; |
|||
} |
|||
}); |
|||
} |
|||
|
|||
var config = command.config === true ? 'rollup.config.js' : command.config; |
|||
|
|||
if ( config ) { |
|||
config = path.resolve( config ); |
|||
|
|||
rollup.rollup({ |
|||
entry: config, |
|||
onwarn: function ( message ) { |
|||
if ( /Treating .+ as external dependency/.test( message ) ) return; |
|||
log( message ); |
|||
} |
|||
}).then( function ( bundle ) { |
|||
var code = bundle.generate({ |
|||
format: 'cjs' |
|||
}).code; |
|||
|
|||
// temporarily override require
|
|||
var defaultLoader = require.extensions[ '.js' ]; |
|||
require.extensions[ '.js' ] = function ( m, filename ) { |
|||
if ( filename === config ) { |
|||
m._compile( code, filename ); |
|||
} else { |
|||
defaultLoader( m, filename ); |
|||
} |
|||
}; |
|||
|
|||
try { |
|||
var options = require( path.resolve( config ) ); |
|||
if ( Object.keys( options ).length === 0 ) { |
|||
handleError({ code: 'MISSING_CONFIG' }); |
|||
} |
|||
} catch ( err ) { |
|||
handleError( err ); |
|||
} |
|||
|
|||
execute( options, command ); |
|||
|
|||
require.extensions[ '.js' ] = defaultLoader; |
|||
}) |
|||
.catch(log); |
|||
} else { |
|||
execute( {}, command ); |
|||
} |
|||
}; |
|||
|
|||
var equivalents = { |
|||
banner: 'banner', |
|||
footer: 'footer', |
|||
format: 'format', |
|||
globals: 'globals', |
|||
id: 'moduleId', |
|||
indent: 'indent', |
|||
input: 'entry', |
|||
intro: 'intro', |
|||
name: 'moduleName', |
|||
output: 'dest', |
|||
outro: 'outro', |
|||
sourcemap: 'sourceMap', |
|||
treeshake: 'treeshake' |
|||
}; |
|||
|
|||
function execute ( options, command ) { |
|||
var external = ( options.external || [] ) |
|||
.concat( command.external ? command.external.split( ',' ) : [] ); |
|||
|
|||
if ( command.globals ) { |
|||
var globals = Object.create( null ); |
|||
|
|||
command.globals.split( ',' ).forEach(function ( str ) { |
|||
var names = str.split( ':' ); |
|||
globals[ names[0] ] = names[1]; |
|||
|
|||
// Add missing Module IDs to external.
|
|||
if ( external.indexOf( names[0] ) === -1 ) { |
|||
external.push( names[0] ); |
|||
} |
|||
}); |
|||
|
|||
command.globals = globals; |
|||
} |
|||
|
|||
options.onwarn = options.onwarn || log; |
|||
|
|||
options.external = external; |
|||
|
|||
options.noConflict = command.conflict === false; |
|||
delete command.conflict; |
|||
|
|||
// Use any options passed through the CLI as overrides.
|
|||
Object.keys( equivalents ).forEach( function ( cliOption ) { |
|||
if ( command.hasOwnProperty( cliOption ) ) { |
|||
options[ equivalents[ cliOption ] ] = command[ cliOption ]; |
|||
} |
|||
}); |
|||
|
|||
try { |
|||
bundle( options ).catch( handleError ); |
|||
} catch ( err ) { |
|||
handleError( err ); |
|||
} |
|||
} |
|||
|
|||
function bundle ( options ) { |
|||
if ( !options.entry ) { |
|||
handleError({ code: 'MISSING_INPUT_OPTION' }); |
|||
} |
|||
|
|||
return rollup.rollup( options ).then( function ( bundle ) { |
|||
if ( options.dest ) { |
|||
return bundle.write( options ); |
|||
} |
|||
|
|||
if ( options.sourceMap && options.sourceMap !== 'inline' ) { |
|||
handleError({ code: 'MISSING_OUTPUT_OPTION' }); |
|||
} |
|||
|
|||
var result = bundle.generate( options ); |
|||
|
|||
var code = result.code, |
|||
map = result.map; |
|||
|
|||
if ( options.sourceMap === 'inline' ) { |
|||
code += '\n//# sourceMappingURL=' + map.toUrl(); |
|||
} |
|||
|
|||
process.stdout.write( code ); |
|||
}); |
|||
} |
@ -1,13 +0,0 @@ |
|||
var fs = require( 'fs' ); |
|||
var path = require( 'path' ); |
|||
|
|||
module.exports = function () { |
|||
fs.readFile( path.join( __dirname, 'help.md' ), function ( err, result ) { |
|||
var help; |
|||
|
|||
if ( err ) throw err; |
|||
|
|||
help = result.toString().replace( '<%= version %>', require( '../package.json' ).version ); |
|||
console.log( '\n' + help + '\n' ); |
|||
}); |
|||
}; |
@ -0,0 +1,65 @@ |
|||
import * as chalk from 'chalk'; |
|||
|
|||
function stderr ( msg ) { |
|||
console.error( msg ); // eslint-disable-line no-console
|
|||
} |
|||
|
|||
const handlers = { |
|||
MISSING_CONFIG: () => { |
|||
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' ) ); |
|||
}, |
|||
|
|||
MISSING_OUTPUT_OPTION: () => { |
|||
stderr( chalk.red( 'You must specify an --output (-o) option when creating a file with a sourcemap' ) ); |
|||
}, |
|||
|
|||
MISSING_NAME: () => { |
|||
stderr( chalk.red( 'You must supply a name for UMD exports (e.g. `--name myModule`)' ) ); |
|||
}, |
|||
|
|||
PARSE_ERROR: err => { |
|||
stderr( chalk.red( `Error parsing ${err.file}: ${err.message}` ) ); |
|||
}, |
|||
|
|||
ONE_AT_A_TIME: () => { |
|||
stderr( chalk.red( 'rollup can only bundle one file at a time' ) ); |
|||
}, |
|||
|
|||
DUPLICATE_IMPORT_OPTIONS: () => { |
|||
stderr( chalk.red( 'use --input, or pass input path as argument' ) ); |
|||
}, |
|||
|
|||
ROLLUP_WATCH_NOT_INSTALLED: () => { |
|||
stderr( chalk.red( 'rollup --watch depends on the rollup-watch package, which could not be found. You can install it globally (recommended) with ' ) + chalk.cyan( 'npm install -g rollup-watch' ) ); |
|||
}, |
|||
|
|||
WATCHER_MISSING_INPUT_OR_OUTPUT: () => { |
|||
stderr( chalk.red( 'must specify --input and --output when using rollup --watch' ) ); |
|||
} |
|||
}; |
|||
|
|||
export default function handleError ( err, recover ) { |
|||
const handler = handlers[ err && err.code ]; |
|||
|
|||
if ( handler ) { |
|||
handler( err ); |
|||
} else { |
|||
stderr( chalk.red( err.message || err ) ); |
|||
|
|||
if ( err.stack ) { |
|||
stderr( chalk.grey( err.stack ) ); |
|||
} |
|||
} |
|||
|
|||
stderr( `Type ${chalk.cyan( 'rollup --help' )} for help, or visit https://github.com/rollup/rollup/wiki` ); |
|||
|
|||
if ( !recover ) process.exit( 1 ); |
|||
} |
@ -0,0 +1,38 @@ |
|||
import minimist from 'minimist'; |
|||
import help from './help.md'; |
|||
import { version } from '../../package.json'; |
|||
import runRollup from './runRollup'; |
|||
|
|||
const command = minimist( process.argv.slice( 2 ), { |
|||
alias: { |
|||
// Aliases
|
|||
strict: 'useStrict', |
|||
|
|||
// Short options
|
|||
c: 'config', |
|||
d: 'indent', |
|||
e: 'external', |
|||
f: 'format', |
|||
g: 'globals', |
|||
h: 'help', |
|||
i: 'input', |
|||
m: 'sourcemap', |
|||
n: 'name', |
|||
o: 'output', |
|||
u: 'id', |
|||
v: 'version', |
|||
w: 'watch' |
|||
} |
|||
}); |
|||
|
|||
if ( command.help || ( process.argv.length <= 2 && process.stdin.isTTY ) ) { |
|||
console.log( `\n${help.replace('__VERSION__', version)}\n` ); // eslint-disable-line no-console
|
|||
} |
|||
|
|||
else if ( command.version ) { |
|||
console.log( `rollup version ${version}` ); // eslint-disable-line no-console
|
|||
} |
|||
|
|||
else { |
|||
runRollup( command ); |
|||
} |
@ -0,0 +1,246 @@ |
|||
import { realpathSync } from 'fs'; |
|||
import { rollup } from 'rollup'; |
|||
import relative from 'require-relative'; |
|||
import handleError from './handleError'; |
|||
import SOURCEMAPPING_URL from './sourceMappingUrl.js'; |
|||
|
|||
import { install as installSourcemapSupport } from 'source-map-support'; |
|||
installSourcemapSupport(); |
|||
|
|||
// stderr to stderr to keep `rollup main.js > bundle.js` from breaking
|
|||
const stderr = console.error.bind( console ); // eslint-disable-line no-console
|
|||
|
|||
export default function runRollup ( command ) { |
|||
if ( command._.length > 1 ) { |
|||
handleError({ code: 'ONE_AT_A_TIME' }); |
|||
} |
|||
|
|||
if ( command._.length === 1 ) { |
|||
if ( command.input ) { |
|||
handleError({ code: 'DUPLICATE_IMPORT_OPTIONS' }); |
|||
} |
|||
|
|||
command.input = command._[0]; |
|||
} |
|||
|
|||
if ( command.environment ) { |
|||
command.environment.split( ',' ).forEach( pair => { |
|||
const index = pair.indexOf( ':' ); |
|||
if ( ~index ) { |
|||
process.env[ pair.slice( 0, index ) ] = pair.slice( index + 1 ); |
|||
} else { |
|||
process.env[ pair ] = true; |
|||
} |
|||
}); |
|||
} |
|||
|
|||
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( `rollup-config-${pkgName}`, process.cwd() ); |
|||
} catch ( err ) { |
|||
try { |
|||
config = relative.resolve( pkgName, process.cwd() ); |
|||
} catch ( err ) { |
|||
if ( err.code === 'MODULE_NOT_FOUND' ) { |
|||
handleError({ code: 'MISSING_EXTERNAL_CONFIG', config }); |
|||
} |
|||
|
|||
throw err; |
|||
} |
|||
} |
|||
} else { |
|||
// find real path of config so it matches what Node provides to callbacks in require.extensions
|
|||
config = realpathSync( config ); |
|||
} |
|||
|
|||
rollup({ |
|||
entry: config, |
|||
onwarn: message => { |
|||
if ( /Treating .+ as external dependency/.test( message ) ) return; |
|||
stderr( message ); |
|||
} |
|||
}).then( bundle => { |
|||
const { code } = bundle.generate({ |
|||
format: 'cjs' |
|||
}); |
|||
|
|||
// temporarily override require
|
|||
const defaultLoader = require.extensions[ '.js' ]; |
|||
require.extensions[ '.js' ] = ( m, filename ) => { |
|||
if ( filename === config ) { |
|||
m._compile( code, filename ); |
|||
} else { |
|||
defaultLoader( m, filename ); |
|||
} |
|||
}; |
|||
|
|||
try { |
|||
const options = require( config ); |
|||
if ( Object.keys( options ).length === 0 ) { |
|||
handleError({ code: 'MISSING_CONFIG' }); |
|||
} |
|||
execute( options, command ); |
|||
require.extensions[ '.js' ] = defaultLoader; |
|||
} catch ( err ) { |
|||
handleError( err ); |
|||
} |
|||
}) |
|||
.catch( stderr ); |
|||
} else { |
|||
execute( {}, command ); |
|||
} |
|||
} |
|||
|
|||
const equivalents = { |
|||
useStrict: 'useStrict', |
|||
banner: 'banner', |
|||
footer: 'footer', |
|||
format: 'format', |
|||
globals: 'globals', |
|||
id: 'moduleId', |
|||
indent: 'indent', |
|||
input: 'entry', |
|||
intro: 'intro', |
|||
name: 'moduleName', |
|||
output: 'dest', |
|||
outro: 'outro', |
|||
sourcemap: 'sourceMap', |
|||
treeshake: 'treeshake' |
|||
}; |
|||
|
|||
function execute ( options, command ) { |
|||
let external; |
|||
|
|||
const commandExternal = ( command.external || '' ).split( ',' ); |
|||
const optionsExternal = options.external; |
|||
|
|||
if ( command.globals ) { |
|||
let globals = Object.create( null ); |
|||
|
|||
command.globals.split( ',' ).forEach( str => { |
|||
const names = str.split( ':' ); |
|||
globals[ names[0] ] = names[1]; |
|||
|
|||
// Add missing Module IDs to external.
|
|||
if ( commandExternal.indexOf( names[0] ) === -1 ) { |
|||
commandExternal.push( names[0] ); |
|||
} |
|||
}); |
|||
|
|||
command.globals = globals; |
|||
} |
|||
|
|||
if ( typeof optionsExternal === 'function' ) { |
|||
external = id => { |
|||
return optionsExternal( id ) || ~commandExternal.indexOf( id ); |
|||
}; |
|||
} else { |
|||
external = ( optionsExternal || [] ).concat( commandExternal ); |
|||
} |
|||
|
|||
options.onwarn = options.onwarn || stderr; |
|||
|
|||
options.external = external; |
|||
|
|||
// Use any options passed through the CLI as overrides.
|
|||
Object.keys( equivalents ).forEach( cliOption => { |
|||
if ( command.hasOwnProperty( cliOption ) ) { |
|||
options[ equivalents[ cliOption ] ] = command[ cliOption ]; |
|||
} |
|||
}); |
|||
|
|||
try { |
|||
if ( command.watch ) { |
|||
if ( !options.entry || ( !options.dest && !options.targets ) ) { |
|||
handleError({ code: 'WATCHER_MISSING_INPUT_OR_OUTPUT' }); |
|||
} |
|||
|
|||
try { |
|||
const watch = relative( 'rollup-watch', process.cwd() ); |
|||
const watcher = watch( rollup, options ); |
|||
|
|||
watcher.on( 'event', event => { |
|||
switch ( event.code ) { |
|||
case 'STARTING': |
|||
stderr( 'checking rollup-watch version...' ); |
|||
break; |
|||
|
|||
case 'BUILD_START': |
|||
stderr( 'bundling...' ); |
|||
break; |
|||
|
|||
case 'BUILD_END': |
|||
stderr( 'bundled in ' + event.duration + 'ms. Watching for changes...' ); |
|||
break; |
|||
|
|||
case 'ERROR': |
|||
handleError( event.error, true ); |
|||
break; |
|||
|
|||
default: |
|||
stderr( 'unknown event', event ); |
|||
} |
|||
}); |
|||
} catch ( err ) { |
|||
if ( err.code === 'MODULE_NOT_FOUND' ) { |
|||
err.code = 'ROLLUP_WATCH_NOT_INSTALLED'; |
|||
} |
|||
|
|||
handleError( err ); |
|||
} |
|||
} else { |
|||
bundle( options ).catch( handleError ); |
|||
} |
|||
} catch ( err ) { |
|||
handleError( err ); |
|||
} |
|||
} |
|||
|
|||
function clone ( object ) { |
|||
return assign( {}, object ); |
|||
} |
|||
|
|||
function assign ( target, source ) { |
|||
Object.keys( source ).forEach( key => { |
|||
target[ key ] = source[ key ]; |
|||
}); |
|||
return target; |
|||
} |
|||
|
|||
function bundle ( options ) { |
|||
if ( !options.entry ) { |
|||
handleError({ code: 'MISSING_INPUT_OPTION' }); |
|||
} |
|||
|
|||
return rollup( options ).then( bundle => { |
|||
if ( options.dest ) { |
|||
return bundle.write( options ); |
|||
} |
|||
|
|||
if ( options.targets ) { |
|||
let result = null; |
|||
|
|||
options.targets.forEach( target => { |
|||
result = bundle.write( assign( clone( options ), target ) ); |
|||
}); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
if ( options.sourceMap && options.sourceMap !== 'inline' ) { |
|||
handleError({ code: 'MISSING_OUTPUT_OPTION' }); |
|||
} |
|||
|
|||
let { code, map } = bundle.generate( options ); |
|||
|
|||
if ( options.sourceMap === 'inline' ) { |
|||
code += `\n//# ${SOURCEMAPPING_URL}=${map.toUrl()}\n`; |
|||
} |
|||
|
|||
process.stdout.write( code ); |
|||
}); |
|||
} |
@ -0,0 +1,4 @@ |
|||
let SOURCEMAPPING_URL = 'sourceMa'; |
|||
SOURCEMAPPING_URL += 'ppingURL'; |
|||
|
|||
export default SOURCEMAPPING_URL; |
@ -0,0 +1,80 @@ |
|||
export const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|\/])/; |
|||
export const relativePath = /^\.?\.\//; |
|||
|
|||
export function isAbsolute ( path ) { |
|||
return absolutePath.test( path ); |
|||
} |
|||
|
|||
export function isRelative ( path ) { |
|||
return relativePath.test( path ); |
|||
} |
|||
|
|||
export function normalize ( path ) { |
|||
return path.replace( /\\/g, '/' ); |
|||
} |
|||
|
|||
export function basename ( path ) { |
|||
return path.split( /(\/|\\)/ ).pop(); |
|||
} |
|||
|
|||
export function dirname ( path ) { |
|||
const match = /(\/|\\)[^\/\\]*$/.exec( path ); |
|||
if ( !match ) return '.'; |
|||
|
|||
const dir = path.slice( 0, -match[0].length ); |
|||
|
|||
// If `dir` is the empty string, we're at root.
|
|||
return dir ? dir : '/'; |
|||
} |
|||
|
|||
export function extname ( path ) { |
|||
const match = /\.[^\.]+$/.exec( basename( path ) ); |
|||
if ( !match ) return ''; |
|||
return match[0]; |
|||
} |
|||
|
|||
export function relative ( from, to ) { |
|||
const fromParts = from.split( /[\/\\]/ ).filter( Boolean ); |
|||
const toParts = to.split( /[\/\\]/ ).filter( Boolean ); |
|||
|
|||
while ( fromParts[0] && toParts[0] && fromParts[0] === toParts[0] ) { |
|||
fromParts.shift(); |
|||
toParts.shift(); |
|||
} |
|||
|
|||
while ( toParts[0] === '.' || toParts[0] === '..' ) { |
|||
const toPart = toParts.shift(); |
|||
if ( toPart === '..' ) { |
|||
fromParts.pop(); |
|||
} |
|||
} |
|||
|
|||
while ( fromParts.pop() ) { |
|||
toParts.unshift( '..' ); |
|||
} |
|||
|
|||
return toParts.join( '/' ); |
|||
} |
|||
|
|||
export function resolve ( ...paths ) { |
|||
let resolvedParts = paths.shift().split( /[\/\\]/ ); |
|||
|
|||
paths.forEach( path => { |
|||
if ( isAbsolute( path ) ) { |
|||
resolvedParts = path.split( /[\/\\]/ ); |
|||
} else { |
|||
const parts = path.split( /[\/\\]/ ); |
|||
|
|||
while ( parts[0] === '.' || parts[0] === '..' ) { |
|||
const part = parts.shift(); |
|||
if ( part === '..' ) { |
|||
resolvedParts.pop(); |
|||
} |
|||
} |
|||
|
|||
resolvedParts.push.apply( resolvedParts, parts ); |
|||
} |
|||
}); |
|||
|
|||
return resolvedParts.join( '/' ); // TODO windows...
|
|||
} |
@ -1 +0,0 @@ |
|||
export default window.Promise; |
@ -0,0 +1,34 @@ |
|||
import buble from 'rollup-plugin-buble'; |
|||
import json from 'rollup-plugin-json'; |
|||
import string from 'rollup-plugin-string'; |
|||
import nodeResolve from 'rollup-plugin-node-resolve'; |
|||
import commonjs from 'rollup-plugin-commonjs'; |
|||
|
|||
export default { |
|||
entry: 'bin/src/index.js', |
|||
dest: 'bin/rollup', |
|||
format: 'cjs', |
|||
banner: '#!/usr/bin/env node', |
|||
plugins: [ |
|||
string({ include: '**/*.md' }), |
|||
json(), |
|||
buble(), |
|||
commonjs({ |
|||
include: 'node_modules/**', |
|||
namedExports: { chalk: [ 'red', 'cyan', 'grey' ] } |
|||
}), |
|||
nodeResolve({ |
|||
main: true |
|||
}) |
|||
], |
|||
external: [ |
|||
'fs', |
|||
'path', |
|||
'module', |
|||
'source-map-support', |
|||
'rollup' |
|||
], |
|||
paths: { |
|||
rollup: '../dist/rollup.js' |
|||
} |
|||
}; |
@ -1,7 +1,7 @@ |
|||
import amd from './amd.js'; |
|||
import cjs from './cjs.js'; |
|||
import es6 from './es6.js'; |
|||
import es from './es.js'; |
|||
import iife from './iife.js'; |
|||
import umd from './umd.js'; |
|||
|
|||
export default { amd, cjs, es6, iife, umd }; |
|||
export default { amd, cjs, es, iife, umd }; |
|||
|
@ -0,0 +1 @@ |
|||
export default `Object.defineProperty(exports, '__esModule', { value: true });`; |
@ -0,0 +1,7 @@ |
|||
export function find ( array, fn ) { |
|||
for ( let i = 0; i < array.length; i += 1 ) { |
|||
if ( fn( array[i], i ) ) return array[i]; |
|||
} |
|||
|
|||
return null; |
|||
} |
@ -1,3 +0,0 @@ |
|||
export function unixizePath ( path ) { |
|||
return path.split( /[\/\\]/ ).join( '/' ); |
|||
} |
@ -1,20 +0,0 @@ |
|||
{ |
|||
"whitelist": [ |
|||
"es6.arrowFunctions", |
|||
"es6.blockScoping", |
|||
"es6.classes", |
|||
"es6.constants", |
|||
"es6.destructuring", |
|||
"es6.modules", |
|||
"es6.parameters", |
|||
"es6.properties.shorthand", |
|||
"es6.spread", |
|||
"es6.templateLiterals" |
|||
], |
|||
"loose": [ |
|||
"es6.classes", |
|||
"es6.destructuring" |
|||
], |
|||
"compact": false, |
|||
"sourceMap": true |
|||
} |
@ -0,0 +1,9 @@ |
|||
{ |
|||
"rules": { |
|||
"no-console": [ 0 ], |
|||
"no-unused-vars": [ "error", { "vars": "all", "args": "none" } ] |
|||
}, |
|||
"env": { |
|||
"mocha": true |
|||
} |
|||
} |
@ -1,4 +1,4 @@ |
|||
module.exports = { |
|||
description: 'adds banner/intro/outro/footer', |
|||
command: 'rollup -i main.js -f iife --banner "// banner" --intro "// intro" --outro "// outro" --footer "// footer"' |
|||
command: 'rollup -i main.js -f iife --indent --banner "// banner" --intro "// intro" --outro "// outro" --footer "// footer"' |
|||
}; |
|||
|
@ -0,0 +1,13 @@ |
|||
var os = require( 'os' ); |
|||
|
|||
function toggleCase ( s ) { |
|||
return ( s == s.toLowerCase() ) ? s.toUpperCase() : s.toLowerCase(); |
|||
} |
|||
|
|||
module.exports = { |
|||
skip: os.platform() !== 'win32', |
|||
description: "can load config with cwd that doesn't match realpath", |
|||
command: 'rollup -c', |
|||
cwd: __dirname.replace( /^[A-Z]:\\/i, toggleCase ), |
|||
execute: true |
|||
}; |
@ -0,0 +1 @@ |
|||
assert.equal( ANSWER, 42 ); |
@ -0,0 +1,9 @@ |
|||
var replace = require( 'rollup-plugin-replace' ); |
|||
|
|||
module.exports = { |
|||
entry: 'main.js', |
|||
format: 'cjs', |
|||
plugins: [ |
|||
replace({ 'ANSWER': 42 }) |
|||
] |
|||
}; |
@ -0,0 +1,4 @@ |
|||
module.exports = { |
|||
description: 'external option gets passed from config', |
|||
command: 'rollup -c -e assert,external-module' |
|||
}; |
@ -0,0 +1,8 @@ |
|||
'use strict'; |
|||
|
|||
var ___config_js = require('./_config.js'); |
|||
var assert = require('assert'); |
|||
var externalModule = require('external-module'); |
|||
|
|||
assert.ok( ___config_js.execute ); |
|||
externalModule.method(); |
@ -0,0 +1,6 @@ |
|||
import { execute } from './_config.js'; |
|||
import { ok } from 'assert'; |
|||
import { method } from 'external-module'; |
|||
|
|||
ok( execute ); |
|||
method(); |
@ -0,0 +1,21 @@ |
|||
import assert from 'assert'; |
|||
import { resolve } from 'path'; |
|||
|
|||
var config = resolve( './_config.js' ); |
|||
|
|||
export default { |
|||
entry: 'main.js', |
|||
format: 'cjs', |
|||
|
|||
external: function ( id ) { |
|||
return id === config; |
|||
}, |
|||
|
|||
plugins: [ |
|||
{ |
|||
load: function ( id ) { |
|||
assert.notEqual( id, config ); |
|||
} |
|||
} |
|||
] |
|||
}; |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'populates options.external with --global keys', |
|||
command: 'rollup main.js --format iife --globals mathematics:Math', |
|||
execute: true |
|||
}; |
@ -0,0 +1,3 @@ |
|||
import { max } from 'mathematics'; |
|||
|
|||
assert.equal( max( 1, 2, 3 ), 3 ); |
@ -1,4 +1,4 @@ |
|||
module.exports = { |
|||
description: 'generates UMD export with correct moduleName', |
|||
command: 'rollup main.js --format umd --name myBundle' |
|||
command: 'rollup main.js --format umd --name myBundle --indent' |
|||
}; |
|||
|
@ -0,0 +1,4 @@ |
|||
module.exports = { |
|||
description: 'uses shared config for each target', |
|||
command: 'rollup -c' |
|||
}; |
@ -0,0 +1,6 @@ |
|||
'use strict'; |
|||
|
|||
var main = 0; |
|||
|
|||
module.exports = main; |
|||
//# sourceMappingURL=cjs.js.map
|
@ -0,0 +1 @@ |
|||
{"version":3,"file":"cjs.js","sources":["../main.js"],"sourcesContent":["export default 0;\n"],"names":[],"mappings":";;AAAA,WAAe,CAAC,CAAC,;;"} |
@ -0,0 +1,4 @@ |
|||
var main = 0; |
|||
|
|||
export default main; |
|||
//# sourceMappingURL=es.js.map
|
@ -0,0 +1 @@ |
|||
{"version":3,"file":"es.js","sources":["../main.js"],"sourcesContent":["export default 0;\n"],"names":[],"mappings":"AAAA,WAAe,CAAC,CAAC,;;"} |
@ -0,0 +1 @@ |
|||
export default 0; |
@ -0,0 +1,14 @@ |
|||
export default { |
|||
entry: 'main.js', |
|||
sourceMap: true, |
|||
targets: [ |
|||
{ |
|||
format: 'cjs', |
|||
dest: '_actual/cjs.js' |
|||
}, |
|||
{ |
|||
format: 'es', |
|||
dest: '_actual/es.js' |
|||
} |
|||
] |
|||
}; |
@ -0,0 +1,4 @@ |
|||
module.exports = { |
|||
description: 'generates multiple output files when multiple targets are specified', |
|||
command: 'rollup -c' |
|||
}; |
@ -0,0 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
var main = 0; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,3 @@ |
|||
var main = 0; |
|||
|
|||
export default main; |
@ -0,0 +1 @@ |
|||
export default 0; |
@ -0,0 +1,13 @@ |
|||
export default { |
|||
entry: 'main.js', |
|||
targets: [ |
|||
{ |
|||
format: 'cjs', |
|||
dest: '_actual/cjs.js' |
|||
}, |
|||
{ |
|||
format: 'es', |
|||
dest: '_actual/es.js' |
|||
} |
|||
] |
|||
}; |
@ -0,0 +1,4 @@ |
|||
module.exports = { |
|||
description: 'respects noConflict option', |
|||
command: 'rollup --config rollup.config.js' |
|||
}; |
@ -0,0 +1,16 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
(function() { |
|||
var current = global.conflictyName; |
|||
var exports = factory(); |
|||
global.conflictyName = exports; |
|||
exports.noConflict = function() { global.conflictyName = current; return exports; }; |
|||
})(); |
|||
}(this, (function () { 'use strict'; |
|||
|
|||
var main = {}; |
|||
|
|||
return main; |
|||
|
|||
}))); |
@ -0,0 +1 @@ |
|||
export default {}; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
entry: 'main.js', |
|||
format: 'umd', |
|||
moduleName: 'conflictyName', |
|||
noConflict: true |
|||
}; |
@ -0,0 +1,4 @@ |
|||
module.exports = { |
|||
description: 'use no strict option', |
|||
command: 'rollup -i main.js -f iife --no-strict --indent' |
|||
}; |
@ -0,0 +1,4 @@ |
|||
(function () { |
|||
console.log( 42 ); |
|||
|
|||
}()); |
@ -0,0 +1 @@ |
|||
console.log( 42 ); |
@ -1,4 +1,4 @@ |
|||
module.exports = { |
|||
description: 'generates IIFE export with all code', |
|||
command: 'rollup main.js --format iife --name shakeless --no-treeshake' |
|||
command: 'rollup main.js --format iife --name shakeless --no-treeshake --indent' |
|||
}; |
|||
|
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'uses config file installed from npm', |
|||
command: 'rollup --config node:foo', |
|||
execute: true |
|||
}; |
@ -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; |
|||
|
|||
})); |
@ -0,0 +1 @@ |
|||
assert.equal( ANSWER, 42 ); |
@ -0,0 +1,9 @@ |
|||
var replace = require( 'rollup-plugin-replace' ); |
|||
|
|||
module.exports = { |
|||
entry: 'main.js', |
|||
format: 'cjs', |
|||
plugins: [ |
|||
replace({ 'ANSWER': 42 }) |
|||
] |
|||
}; |
@ -0,0 +1,3 @@ |
|||
{ |
|||
"main": "lib/config.js" |
|||
} |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'uses config file installed from npm', |
|||
command: 'rollup --config node:foo', |
|||
execute: true |
|||
}; |
@ -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; |
|||
|
|||
})); |
@ -0,0 +1 @@ |
|||
assert.equal( ANSWER, 42 ); |
@ -0,0 +1,9 @@ |
|||
var replace = require( 'rollup-plugin-replace' ); |
|||
|
|||
module.exports = { |
|||
entry: 'main.js', |
|||
format: 'cjs', |
|||
plugins: [ |
|||
replace({ 'ANSWER': 42 }) |
|||
] |
|||
}; |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue