mirror of https://github.com/lukechilds/rollup.git
Rich Harris
10 years ago
10 changed files with 136 additions and 39 deletions
@ -0,0 +1,13 @@ |
|||
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; |
@ -1,20 +1,38 @@ |
|||
var gobble = require( 'gobble' ); |
|||
var fs = require( 'fs' ); |
|||
|
|||
var selfhost = 1; |
|||
var src = gobble( 'src' ); |
|||
|
|||
module.exports = selfhost ? |
|||
gobble( 'src' ) |
|||
.transform( 'babel' ) |
|||
.transform( 'rollup', { |
|||
entry: 'rollup.js', |
|||
format: 'cjs', |
|||
external: [ 'sander', 'path', 'acorn', 'magic-string' ] |
|||
}) : |
|||
var node = src |
|||
.transform( 'rollup', { |
|||
entry: 'rollup.js', |
|||
dest: 'rollup.js', |
|||
format: 'cjs', |
|||
external: [ 'sander', 'path', 'acorn', 'magic-string' ] |
|||
}) |
|||
.transform( 'babel' ); |
|||
|
|||
gobble( 'src' ) |
|||
.transform( 'babel' ) |
|||
.transform( 'esperanto-bundle', { |
|||
entry: 'rollup', |
|||
type: 'cjs', |
|||
strict: true |
|||
}); |
|||
var absolutePath = /^(?:\/|(?:[A-Za-z]:)?\\)/; |
|||
|
|||
var browserPlaceholders = { |
|||
sander: fs.readFileSync( 'browser/sander.js' ).toString() |
|||
}; |
|||
|
|||
var browser = src |
|||
.transform( 'rollup-babel', { |
|||
entry: 'rollup.js', |
|||
dest: 'rollup.browser.js', |
|||
format: 'cjs', |
|||
load: function ( id ) { |
|||
if ( ~id.indexOf( 'sander.js' ) ) return browserPlaceholders.sander; |
|||
return fs.readFileSync( id ).toString(); |
|||
}, |
|||
external: [ 'acorn', 'magic-string' ] |
|||
}) |
|||
.transform( 'browserify', { |
|||
entries: [ './rollup.browser' ], |
|||
dest: 'rollup.browser.js', |
|||
standalone: 'rollup' |
|||
}); |
|||
|
|||
module.exports = gobble([ node, browser ]); |
|||
|
@ -1,6 +1,3 @@ |
|||
import { sep } from "path"; |
|||
|
|||
export function unixizePath(path) { |
|||
if (sep==="/") return path; |
|||
return path.split(sep).join("/"); |
|||
export function unixizePath( path ) { |
|||
return path.split( /[\/\\]/ ).join( '/' ); |
|||
} |
|||
|
@ -0,0 +1,73 @@ |
|||
// TODO does this all work on windows?
|
|||
|
|||
export const absolutePath = /^(?:\/|(?:[A-Za-z]:)?\\)/; |
|||
|
|||
export function isAbsolute ( path ) { |
|||
return absolutePath.test( path ); |
|||
} |
|||
|
|||
export function basename ( path ) { |
|||
return path.split( /(\/|\\)/ ).pop(); |
|||
} |
|||
|
|||
export function dirname ( path ) { |
|||
const match = /(\/|\\)[^\/\\]+$/.exec( path ); |
|||
if ( !match ) return '.'; |
|||
return path.slice( 0, -match[0].length ); |
|||
} |
|||
|
|||
export function extname ( path ) { |
|||
const match = /\.[^\.]+$/.exec( 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][0] === '.' ) { |
|||
const toPart = toParts.shift(); |
|||
if ( toPart === '..' ) { |
|||
fromParts.pop(); |
|||
} else if ( toPart !== '.' ) { |
|||
throw new Error( `Unexpected path part (${toPart})` ); |
|||
} |
|||
} |
|||
|
|||
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][0] === '.' ) { |
|||
const part = parts.shift(); |
|||
if ( part === '..' ) { |
|||
resolvedParts.pop(); |
|||
} else if ( part !== '.' ) { |
|||
throw new Error( `Unexpected path part (${part})` ); |
|||
} |
|||
} |
|||
|
|||
resolvedParts.push.apply( resolvedParts, parts ); |
|||
} |
|||
}); |
|||
|
|||
return resolvedParts.join( '/' ); // TODO windows...
|
|||
} |
Loading…
Reference in new issue