mirror of https://github.com/lukechilds/rollup.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
891 B
32 lines
891 B
import { isFile, readFileSync } from './fs.js';
|
|
import { dirname, extname, isAbsolute, resolve } from './path.js';
|
|
|
|
export function load ( id ) {
|
|
return readFileSync( id, 'utf-8' );
|
|
}
|
|
|
|
function addJsExtensionIfNecessary ( file ) {
|
|
if ( isFile( file ) ) return file;
|
|
|
|
file += '.js';
|
|
if ( isFile( file ) ) return file;
|
|
|
|
return null;
|
|
}
|
|
|
|
export function resolveId ( importee, importer ) {
|
|
// absolute paths are left untouched
|
|
if ( isAbsolute( importee ) ) return addJsExtensionIfNecessary( importee );
|
|
|
|
// if this is the entry point, resolve against cwd
|
|
if ( importer === undefined ) return addJsExtensionIfNecessary( resolve( process.cwd(), importee ) );
|
|
|
|
// external modules are skipped at this stage
|
|
if ( importee[0] !== '.' ) return null;
|
|
|
|
return addJsExtensionIfNecessary( resolve( dirname( importer ), importee ) );
|
|
}
|
|
|
|
export function onwarn ( msg ) {
|
|
console.error( msg );
|
|
}
|
|
|