Urara-Blog/node_modules/.pnpm-store/v3/files/d7/d82327ccfb7fc570aee9edec124508ab7cc79c4f296daffc041c0eca505058d393bc6ef6ff10a2dc8e69152f2cc68ff9b62157408acb0a0c027aaf3814f619
2022-08-14 01:14:53 +08:00

38 lines
1.1 KiB
Text

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