Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getModuleName(prjRelfilePath: string, removePrefix: string): string {
const absFile = new FilePath(prjRelfilePath);
const pkgDir = new FilePath(babelUtil.getPackageDir(prjRelfilePath));
let moduleName: string = pkgDir.relative(absFile).asPosix;
if (moduleName.toLowerCase().endsWith('.js')) {
moduleName = moduleName.substring(0, moduleName.length - 3);
}
if (moduleName.startsWith(removePrefix)) {
moduleName = moduleName.substring(removePrefix.length);
}
const pkgJson = readJsonSync(pkgDir.join('package.json').asNative);
return `${pkgJson.name}@${pkgJson.version}/${moduleName}`;
}
function addEsModuleFlag(state) {
if (state.esModuleFlagAdded) {
return;
}
const {filename} = state.file.opts;
const pkgDir = babelUtil.getPackageDir(filename);
const pkgJson = readJsonSync(npath.join(pkgDir, 'package.json'));
const {rootPkgJson} = babelIpc.get(state);
const pkgId =
pkgJson.name === rootPkgJson.name
? '/'
: `${pkgJson.name}@${pkgJson.version}`;
const {manifest} = babelIpc.get(state);
manifest.addModuleFlags(pkgId, npath.relative(pkgDir, filename), {
esModule: true,
});
state.esModuleFlagAdded = true;