21 lines
477 B
JavaScript
21 lines
477 B
JavaScript
import path from 'path';
|
|
const rootDir = process.cwd();
|
|
|
|
function resolveImportPath(importPath, fileBase) {
|
|
const fileDir = path.dirname(fileBase);
|
|
|
|
if (!importPath) return null;
|
|
|
|
if (importPath.startsWith('.') || importPath.startsWith('/')) {
|
|
return path.relative(rootDir, path.resolve(fileDir, importPath));
|
|
}
|
|
|
|
return importPath;
|
|
}
|
|
|
|
function toRelative(file) {
|
|
return path.relative(rootDir, file);
|
|
}
|
|
|
|
export { resolveImportPath, toRelative };
|