From dfa6492bf8205b24cf970fba460d90ee1e30cf7c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 10:22:10 -0400 Subject: [PATCH 1/9] remove sander dependency --- .babelrc | 3 ++- browser/fs.js | 13 +++++++++++++ browser/promise.js | 1 + browser/sander.js | 17 ----------------- gobblefile.js | 11 +++++++---- package.json | 2 +- src/Bundle.js | 2 +- src/rollup.js | 2 +- src/utils/fs.js | 17 +++++++++++++++++ src/utils/load.js | 4 ++-- src/utils/resolveId.js | 4 ++-- 11 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 browser/fs.js create mode 100644 browser/promise.js delete mode 100644 browser/sander.js create mode 100644 src/utils/fs.js 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/browser/fs.js b/browser/fs.js new file mode 100644 index 0000000..09bdf18 --- /dev/null +++ b/browser/fs.js @@ -0,0 +1,13 @@ +export function readdirSync () { + throw new Error( 'Cannot use fs.readdirSync inside browser' ); +} + +export function readFileSync () { + throw new Error( 'Cannot use fs.readFileSync inside browser' ); +} + +export function writeFile () { + throw new Error( 'Cannot use fs.writeFile inside browser' ); +} + +export const Promise = window.Promise; 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..8e5f63f 100644 --- a/gobblefile.js +++ b/gobblefile.js @@ -8,13 +8,14 @@ var node = src entry: 'rollup.js', dest: 'rollup.js', format: 'cjs', - external: [ 'sander', 'acorn' ], + external: [ 'fs', 'acorn' ], 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 @@ -23,7 +24,8 @@ var browser = src dest: 'rollup.browser.js', format: 'cjs', load: function ( id ) { - if ( ~id.indexOf( 'sander.js' ) ) return browserPlaceholders.sander; + if ( ~id.indexOf( 'utils/fs' ) ) return browserPlaceholders.fs; + if ( ~id.indexOf( 'es6-promise' ) ) return browserPlaceholders.promise; return fs.readFileSync( id ).toString(); }, external: [ 'acorn' ] @@ -31,7 +33,8 @@ var browser = src .transform( 'browserify', { entries: [ './rollup.browser' ], dest: 'rollup.browser.js', - standalone: 'rollup' + standalone: 'rollup', + builtins: false }); module.exports = gobble([ node, browser ]); diff --git a/package.json b/package.json index 64a2ac8..d171bf2 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "gobble-cli": "^0.4.2", "gobble-esperanto-bundle": "^0.2.0", "gobble-rollup": "^0.8.0", - "gobble-rollup-babel": "^0.1.0", + "gobble-rollup-babel": "^0.3.0", "istanbul": "^0.3.20", "mocha": "^2.2.4", "remap-istanbul": "^0.2.0", 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/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..9a45157 --- /dev/null +++ b/src/utils/fs.js @@ -0,0 +1,17 @@ +import Promise from 'es6-promise/lib/es6-promise/promise'; +import * as fs from 'fs'; + +export function writeFile ( dest, data ) { + return new Promise( ( fulfil, reject ) => { + 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}` ); } From 4ac7fe8486162ba55267a0ca41801d2532c07c60 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 10:38:29 -0400 Subject: [PATCH 2/9] move deps to devDeps as applicable --- package.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index d171bf2..86afe74 100644 --- a/package.json +++ b/package.json @@ -39,32 +39,32 @@ }, "homepage": "https://github.com/rollup/rollup", "devDependencies": { + "acorn": "^2.3.0", "babel": "^5.8.21", "babel-core": "^5.5.8", + "chalk": "^1.0.0", "codecov.io": "^0.1.6", "console-group": "^0.1.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.3.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", From c46afb57c178dab06a643056db3870043604cc75 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 10:39:28 -0400 Subject: [PATCH 3/9] roll up acorn --- gobblefile.js | 14 ++++---------- src/Module.js | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/gobblefile.js b/gobblefile.js index 8e5f63f..21b9460 100644 --- a/gobblefile.js +++ b/gobblefile.js @@ -8,7 +8,7 @@ var node = src entry: 'rollup.js', dest: 'rollup.js', format: 'cjs', - external: [ 'fs', 'acorn' ], + external: [ 'fs' ], sourceMap: true }) .transform( 'babel' ); @@ -22,19 +22,13 @@ 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( 'utils/fs' ) ) 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', - builtins: false + } }); module.exports = gobble([ node, browser ]); 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'; From 10e63875ddc7a316ce354a94413eb2a71957848c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 10:39:37 -0400 Subject: [PATCH 4/9] remove unused deps --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index 86afe74..809bd14 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "homepage": "https://github.com/rollup/rollup", "devDependencies": { "acorn": "^2.3.0", - "babel": "^5.8.21", "babel-core": "^5.5.8", "chalk": "^1.0.0", "codecov.io": "^0.1.6", @@ -49,9 +48,7 @@ "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.10.0", "gobble-rollup-babel": "^0.4.0", "istanbul": "^0.3.20", From 4eeb082e7920746497200422501b0de333693c5d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 10:50:16 -0400 Subject: [PATCH 5/9] include es6-promise --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 809bd14..c9fb57b 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "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", From 90e7a8d435600ae26d526bc03d0706a146f565e1 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 10:52:53 -0400 Subject: [PATCH 6/9] -> 0.18.1 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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/package.json b/package.json index c9fb57b..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", From 7a1eeabc2c51b58aecd385da06e7694b09fff724 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 11:24:35 -0400 Subject: [PATCH 7/9] fix travis error, hopefully --- browser/fs.js | 16 ++++------------ src/utils/fs.js | 3 ++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/browser/fs.js b/browser/fs.js index 09bdf18..654315f 100644 --- a/browser/fs.js +++ b/browser/fs.js @@ -1,13 +1,5 @@ -export function readdirSync () { - throw new Error( 'Cannot use fs.readdirSync inside browser' ); -} +const nope = method => `Cannot use fs.${method} inside browser`; -export function readFileSync () { - throw new Error( 'Cannot use fs.readFileSync inside browser' ); -} - -export function writeFile () { - throw new Error( 'Cannot use fs.writeFile inside browser' ); -} - -export const Promise = window.Promise; +export const readdirSync = nope( 'readdirSync' ); +export const readFileSync = nope( 'readFileSync' ); +export const writeFile = nope( 'writeFile' ); diff --git a/src/utils/fs.js b/src/utils/fs.js index 9a45157..59c51fd 100644 --- a/src/utils/fs.js +++ b/src/utils/fs.js @@ -1,9 +1,10 @@ import Promise from 'es6-promise/lib/es6-promise/promise'; import * as fs from 'fs'; +import { resolve } from './path'; export function writeFile ( dest, data ) { return new Promise( ( fulfil, reject ) => { - fs.writeFile( dest, data, err => { + fs.writeFile( resolve( process.cwd(), dest ), data, err => { if ( err ) { reject( err ); } else { From e8fe0d10806c89e4526b367ee9f616517bb5a06b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 11:51:56 -0400 Subject: [PATCH 8/9] make intermediate dirs in writeFile helper --- src/utils/fs.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/fs.js b/src/utils/fs.js index 59c51fd..fc3ee77 100644 --- a/src/utils/fs.js +++ b/src/utils/fs.js @@ -1,10 +1,22 @@ import Promise from 'es6-promise/lib/es6-promise/promise'; import * as fs from 'fs'; -import { resolve } from './path'; +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 ) => { - fs.writeFile( resolve( process.cwd(), dest ), data, err => { + mkdirpath( dest ); + + fs.writeFile( dest, data, err => { if ( err ) { reject( err ); } else { From 693913016f76b8d455798bd53554cdafd4b1d485 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Oct 2015 11:57:34 -0400 Subject: [PATCH 9/9] argh windows --- gobblefile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gobblefile.js b/gobblefile.js index 21b9460..b4870ca 100644 --- a/gobblefile.js +++ b/gobblefile.js @@ -25,7 +25,7 @@ var browser = src format: 'umd', moduleName: 'rollup', load: function ( id ) { - if ( ~id.indexOf( 'utils/fs' ) ) return browserPlaceholders.fs; + if ( ~id.indexOf( 'fs.js' ) ) return browserPlaceholders.fs; if ( ~id.indexOf( 'es6-promise' ) ) return browserPlaceholders.promise; return fs.readFileSync( id ).toString(); }