Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function loadConfig() {
npmbuildrc = safeReadJsonSync(project.dir.join('.npmbuildrc').asNative);
npmbundlerrc = project._npmbundlerrc;
// Normalize configurations
normalize(npmbuildrc, 'supportedLocales', []);
normalize(npmbuildrc, 'webpack.mainModule', 'index.js');
normalize(npmbuildrc, 'webpack.rules', []);
normalize(npmbuildrc, 'webpack.extensions', ['.js']);
normalize(npmbuildrc, 'webpack.port', null);
normalize(
npmbundlerrc,
'create-jar.features.localization',
'features/localization/Language'
);
}
export default function(context, config) {
const {content, filePath, log, sourceMap} = context;
const babelConfig = {
filename: project.dir.join(filePath).asNative,
filenameRelative: filePath,
inputSourceMap: sourceMap,
...config,
};
// Tune babel config
babelConfig.babelrc = false;
babelConfig.only = '**/*';
if (babelConfig.sourceMaps === undefined) {
babelConfig.sourceMaps = true;
}
// Intercept presets and plugins to load them from project
babelConfig.plugins = loadBabelPlugins(
babelConfig.presets || [],
babelConfig.plugins || []
return new Promise(resolve => {
const logger = new PluginLogger();
babelIpc.set(project.dir.join(prjRelPath).asNative, {
log: logger,
manifest,
rootPkgJson: clone(project.pkgJson),
globalConfig: clone(project.globalConfig),
});
const fileAbsPath = project.dir.join(prjRelPath).asNative;
const filePkgRelPath = project.dir
.join(destPkg.dir)
.relative(fileAbsPath).asNative;
babel.transformFile(
fileAbsPath,
{
filename: fileAbsPath,
filenameRelative: prjRelPath,
inputSourceMap: loadSourceMap(fileAbsPath),
...babelConfig,
},
(err, result) => {
// Generate and/or log results
if (err) {
logger.error('babel', err);
export default function(
params: BundlerPluginParams,
{}: BundlerTransformPluginState
): void {
const {log, pkg} = params;
const absRootDir = project.dir.join(pkg.dir);
const aliasesMap = readAliases(params, absRootDir);
const unrolledAliasesMap = unrollAliasesMap(aliasesMap);
reportAndResolveCollisions(log, absRootDir, unrolledAliasesMap);
processAliases(log, absRootDir, unrolledAliasesMap);
}
return new Promise(resolve => {
const logger = new PluginLogger();
babelIpc.set(project.dir.join(prjRelPath).asNative, {
log: logger,
manifest,
rootPkgJson: clone(project.pkgJson),
globalConfig: clone(project.globalConfig),
});
const fileAbsPath = project.dir.join(prjRelPath).asNative;
const filePkgRelPath = project.dir
.join(destPkg.dir)
.relative(fileAbsPath).asNative;
babel.transformFile(
fileAbsPath,
{
filename: fileAbsPath,
filenameRelative: prjRelPath,
function copyFile(srcPkg, destPkg, srcPkgRelPath) {
const absSrcFilePath = project.dir.join(srcPkg.dir, srcPkgRelPath).asNative;
const absDestFilePath = project.dir.join(destPkg.dir, srcPkgRelPath)
.asNative;
return fs
.mkdirp(path.dirname(absDestFilePath))
.then(() => fs.copyFile(absSrcFilePath, absDestFilePath));
}
([extraPrjRelPath, content]) => {
if (content == undefined) {
return;
}
writeRuleFile(
destPkg,
srcPkg.dir.relative(project.dir.join(extraPrjRelPath)).asNative,
content
);
context.log.info(
'liferay-npm-bundler',
`Rules generated extra artifact: ${extraPrjRelPath}`
);
}
);
import {
AliasToValue,
getAliasFields,
getAliasToType,
loadAliases,
AliasToType,
} from 'liferay-npm-build-tools-common/lib/alias';
import {BabelIpcObject} from 'liferay-npm-build-tools-common/lib/api/plugins';
import * as babelIpc from 'liferay-npm-build-tools-common/lib/babel-ipc';
import FilePath from 'liferay-npm-build-tools-common/lib/file-path';
import * as mod from 'liferay-npm-build-tools-common/lib/modules';
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger';
import project from 'liferay-npm-build-tools-common/lib/project';
const absPrjDirPath = project.dir.asNative;
const absBuildDirPath = project.dir.join(project.buildDir).asNative;
let t;
/**
* @return {object} a babel visitor
*/
export default function({types}) {
t = types;
return {
visitor: {
CallExpression(bpath, state) {
state.visitor.CallExpression(bpath);
},
Program(bpath, state) {
new Visitor(state);
export function addPackageDependencies(
collectedDependencies,
basedirPath,
extraDependencies = []
) {
const packageJson = readJsonSync(path.join(basedirPath, '/package.json'));
const pkg = new PkgDesc(
packageJson.name,
packageJson.version,
path.resolve(basedirPath) == path.resolve(project.dir.asNative)
? null
: basedirPath
);
if (collectedDependencies[pkg.id]) {
return;
}
collectedDependencies[pkg.id] = pkg;
let dependencies = packageJson.dependencies || {};
dependencies = Object.keys(dependencies);
dependencies = dependencies.concat(extraDependencies);
const dependencyDirs = dependencies
.map(dependency => {