How to use the liferay-npm-build-tools-common/lib/babel-util.getPackageDir function in liferay-npm-build-tools-common

To help you get started, we’ve selected a few liferay-npm-build-tools-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liferay / liferay-js-toolkit / packages / liferay-npm-build-support / src / loader / wrap-webpack-bundle.ts View on Github external
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}`;
}
github liferay / liferay-js-toolkit / packages / babel-plugin-add-module-metadata / src / index.js View on Github external
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;