diff --git a/.babelrc b/.babelrc index ed25dc0..27617a4 100644 --- a/.babelrc +++ b/.babelrc @@ -14,5 +14,6 @@ "loose": [ "es6.classes", "es6.destructuring" - ] + ], + "compact": false } diff --git a/CHANGELOG.md b/CHANGELOG.md index 1baceb3..eafec5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # rollup changelog +## 0.18.1 + +* Include `acorn.parse` in bundle, remove `sander` from dependencies, simplify build + ## 0.18.0 * Internal rewrite diff --git a/browser/fs.js b/browser/fs.js new file mode 100644 index 0000000..654315f --- /dev/null +++ b/browser/fs.js @@ -0,0 +1,5 @@ +const nope = method => `Cannot use fs.${method} inside browser`; + +export const readdirSync = nope( 'readdirSync' ); +export const readFileSync = nope( 'readFileSync' ); +export const writeFile = nope( 'writeFile' ); diff --git a/browser/promise.js b/browser/promise.js new file mode 100644 index 0000000..06b8309 --- /dev/null +++ b/browser/promise.js @@ -0,0 +1 @@ +export default window.Promise; diff --git a/browser/sander.js b/browser/sander.js deleted file mode 100644 index 5dbe4fc..0000000 --- a/browser/sander.js +++ /dev/null @@ -1,17 +0,0 @@ -export function readdirSync () { - throw new Error( 'Cannot use sander.readdirSync inside browser' ); -} - -export function readFile () { - throw new Error( 'Cannot use sander.readFile inside browser' ); -} - -export function readFileSync () { - throw new Error( 'Cannot use sander.readFileSync inside browser' ); -} - -export function writeFile () { - throw new Error( 'Cannot use sander.writeFile inside browser' ); -} - -export const Promise = window.Promise; diff --git a/gobblefile.js b/gobblefile.js index 4042dd7..b4870ca 100644 --- a/gobblefile.js +++ b/gobblefile.js @@ -8,30 +8,27 @@ var node = src entry: 'rollup.js', dest: 'rollup.js', format: 'cjs', - external: [ 'sander', 'acorn' ], + external: [ 'fs' ], sourceMap: true }) .transform( 'babel' ); var browserPlaceholders = { - sander: fs.readFileSync( 'browser/sander.js' ).toString() + fs: fs.readFileSync( 'browser/fs.js' ).toString(), + promise: fs.readFileSync( 'browser/promise.js' ).toString() }; var browser = src .transform( 'rollup-babel', { entry: 'rollup.js', dest: 'rollup.browser.js', - format: 'cjs', + format: 'umd', + moduleName: 'rollup', load: function ( id ) { - if ( ~id.indexOf( 'sander.js' ) ) return browserPlaceholders.sander; + if ( ~id.indexOf( 'fs.js' ) ) return browserPlaceholders.fs; + if ( ~id.indexOf( 'es6-promise' ) ) return browserPlaceholders.promise; return fs.readFileSync( id ).toString(); - }, - external: [ 'acorn' ] - }) - .transform( 'browserify', { - entries: [ './rollup.browser' ], - dest: 'rollup.browser.js', - standalone: 'rollup' + } }); module.exports = gobble([ node, browser ]); diff --git a/package.json b/package.json index 64a2ac8..b9f46c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "0.18.0", + "version": "0.18.1", "description": "Next-generation ES6 module bundler", "main": "dist/rollup.js", "jsnext:main": "src/rollup.js", @@ -39,32 +39,30 @@ }, "homepage": "https://github.com/rollup/rollup", "devDependencies": { - "babel": "^5.8.21", + "acorn": "^2.3.0", "babel-core": "^5.5.8", + "chalk": "^1.0.0", "codecov.io": "^0.1.6", "console-group": "^0.1.2", + "es6-promise": "^3.0.2", "eslint": "^1.1.0", + "estree-walker": "^0.1.3", "gobble": "^0.10.1", "gobble-babel": "^5.5.8", - "gobble-browserify": "^0.6.1", "gobble-cli": "^0.4.2", - "gobble-esperanto-bundle": "^0.2.0", - "gobble-rollup": "^0.8.0", - "gobble-rollup-babel": "^0.1.0", + "gobble-rollup": "^0.10.0", + "gobble-rollup-babel": "^0.4.0", "istanbul": "^0.3.20", + "magic-string": "^0.7.0", "mocha": "^2.2.4", "remap-istanbul": "^0.2.0", - "source-map": "^0.4.4" - }, - "dependencies": { - "acorn": "^2.3.0", - "chalk": "^1.0.0", - "estree-walker": "^0.1.3", - "magic-string": "^0.7.0", - "minimist": "^1.1.1", "sander": "^0.3.3", + "source-map": "^0.4.4", "source-map-support": "^0.3.1" }, + "dependencies": { + "minimist": "^1.1.1" + }, "files": [ "src", "dist", diff --git a/src/Bundle.js b/src/Bundle.js index 65a381b..5a4b522 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -1,4 +1,4 @@ -import { Promise } from 'sander'; +import Promise from 'es6-promise/lib/es6-promise/promise'; import MagicString from 'magic-string'; import { blank, keys } from './utils/object'; import Module from './Module'; diff --git a/src/Module.js b/src/Module.js index 646d1ee..911d604 100644 --- a/src/Module.js +++ b/src/Module.js @@ -1,4 +1,4 @@ -import { parse } from 'acorn'; +import { parse } from 'acorn/src/index'; import MagicString from 'magic-string'; import { walk } from 'estree-walker'; import Statement from './Statement'; diff --git a/src/rollup.js b/src/rollup.js index 94722e7..9fd126e 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -1,5 +1,5 @@ import { basename } from './utils/path'; -import { writeFile } from 'sander'; +import { writeFile } from './utils/fs'; import { keys } from './utils/object'; import SOURCEMAPPING_URL from './utils/sourceMappingURL'; import Bundle from './Bundle'; diff --git a/src/utils/fs.js b/src/utils/fs.js new file mode 100644 index 0000000..fc3ee77 --- /dev/null +++ b/src/utils/fs.js @@ -0,0 +1,30 @@ +import Promise from 'es6-promise/lib/es6-promise/promise'; +import * as fs from 'fs'; +import { dirname } from './path'; + +function mkdirpath ( path ) { + const dir = dirname( path ); + try { + fs.readdirSync( dir ); + } catch ( err ) { + mkdirpath( dir ); + fs.mkdirSync( dir ); + } +} + +export function writeFile ( dest, data ) { + return new Promise( ( fulfil, reject ) => { + mkdirpath( dest ); + + fs.writeFile( dest, data, err => { + if ( err ) { + reject( err ); + } else { + fulfil(); + } + }); + }); +} + +export const readdirSync = fs.readdirSync; +export const readFileSync = fs.readFileSync; diff --git a/src/utils/load.js b/src/utils/load.js index 60b7566..6cd87bc 100644 --- a/src/utils/load.js +++ b/src/utils/load.js @@ -1,8 +1,8 @@ -import { readFileSync } from 'sander'; +import { readFileSync } from './fs'; export function defaultLoader ( id, options ) { // TODO support plugins e.g. !css and !json? - const source = readFileSync( id, { encoding: 'utf-8' }); + const source = readFileSync( id, 'utf-8' ); return options.transform.reduce( ( source, transformer ) => { return transformer( source, id ); diff --git a/src/utils/resolveId.js b/src/utils/resolveId.js index 7cbed09..2ce7ad0 100644 --- a/src/utils/resolveId.js +++ b/src/utils/resolveId.js @@ -1,5 +1,5 @@ import { absolutePath, dirname, isAbsolute, resolve } from './path'; -import { readdirSync, readFileSync } from 'sander'; +import { readdirSync, readFileSync } from './fs'; function dirExists ( dir ) { try { @@ -58,7 +58,7 @@ export function defaultExternalResolver ( id, importer ) { let pkg; try { - pkg = JSON.parse( readFileSync( pkgPath ).toString() ); + pkg = JSON.parse( readFileSync( pkgPath, 'utf-8' ) ); } catch ( err ) { throw new Error( `Missing or malformed package.json: ${modulePath}` ); }