Browse Source

remove sander dependency

better-aggressive
Rich Harris 9 years ago
parent
commit
dfa6492bf8
  1. 3
      .babelrc
  2. 13
      browser/fs.js
  3. 1
      browser/promise.js
  4. 17
      browser/sander.js
  5. 11
      gobblefile.js
  6. 2
      package.json
  7. 2
      src/Bundle.js
  8. 2
      src/rollup.js
  9. 17
      src/utils/fs.js
  10. 4
      src/utils/load.js
  11. 4
      src/utils/resolveId.js

3
.babelrc

@ -14,5 +14,6 @@
"loose": [
"es6.classes",
"es6.destructuring"
]
],
"compact": false
}

13
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;

1
browser/promise.js

@ -0,0 +1 @@
export default window.Promise;

17
browser/sander.js

@ -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;

11
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 ]);

2
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",

2
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';

2
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';

17
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;

4
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 );

4
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}` );
}

Loading…
Cancel
Save