File size: 1,146 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import { resolve } from 'path';
import Node from './Node.js';
import Chain from './Chain.js';
export function load ( file, options ) {
const { node, sourcesContentByPath, sourceMapByPath } = init( file, options );
return node.load( sourcesContentByPath, sourceMapByPath )
.then( () => node.isOriginalSource ? null : new Chain( node, sourcesContentByPath ) );
}
export function loadSync ( file, options = {} ) {
const { node, sourcesContentByPath, sourceMapByPath } = init( file, options );
node.loadSync( sourcesContentByPath, sourceMapByPath );
return node.isOriginalSource ? null : new Chain( node, sourcesContentByPath );
}
function init ( file, options = {} ) {
const node = new Node({ file });
let sourcesContentByPath = {};
let sourceMapByPath = {};
if ( options.content ) {
Object.keys( options.content ).forEach( key => {
sourcesContentByPath[ resolve( key ) ] = options.content[ key ];
});
}
if ( options.sourcemaps ) {
Object.keys( options.sourcemaps ).forEach( key => {
sourceMapByPath[ resolve( key ) ] = options.sourcemaps[ key ];
});
}
return { node, sourcesContentByPath, sourceMapByPath };
}
|