Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exit(path, state) {
// We must traverse the AST again because the third party
// transform-es2015-modules-amd emits its define() call after
// Program exit :-(
firstDefineNamespaced = false;
extraNamespaceCount = 0;
path.traverse(namespaceVisitor, {opts: state.opts});
if (extraNamespaceCount > 0) {
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
if (firstDefineNamespaced) {
log.info(
'namespace-amd-define',
'Namespaced first AMD define in file'
);
}
if (extraNamespaceCount) {
log.warn(
'namespace-amd-define',
'Found',
extraNamespaceCount,
'define() calls inside the module definition',
exit(path, state) {
// We must traverse the AST again because the
// transform-es2015-modules-amd plugin emits its define()
// call after exiting Program node :-(
path.traverse(amdDefineVisitor, state);
// Dump final report statistics
if (
state.namesCount > 0 ||
state.depsCount > 0 ||
state.requiresCount > 0
) {
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
log.info(
'namespace-modules',
'Namespaced',
state.namesCount,
'define() names,',
state.depsCount,
'define() dependencies,',
'and',
state.requiresCount,
'require() names'
);
}
},
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);
if (absSearchDir.is(_absRootDir)) {
return undefined;
}
// Look up in hierachy
alias = this._getAliasForExternal(
absSearchDir.dirname(),
requiredModule
);
// Rebase to current folder
if (
alias !== undefined &&
getAliasToType(alias) === AliasToType.LOCAL
) {
alias = new FilePath(`../${alias}`, {posix: true}).normalize()
.asPosix;
}
return alias;
}
return;
}
const {npmbundlerrc} = new Project(pkgJsonDir);
if (npmbundlerrc.config && npmbundlerrc.config.imports) {
npmbundlerrc.config.imports = normalizeImportsConfig(
npmbundlerrc.config.imports,
true
);
}
projects[pkgJson.name] = {
name: pkgJson.name,
dir: new FilePath(pkgJsonDir),
pkgJson,
npmbundlerrc,
};
_msg(1, pkgJsonDir);
} catch (err) {
// Swallow.
}
});
`/* redirected by alias field(s) in ${rootRelAbsDirPosixPath} */`,
`module.exports = require('${alias.to}');`
);
log.info(
'replace-browser-modules',
`Redirected file '${rootRelFilePosixPath}' to ` +
`'${alias.to}' as configured in ` +
`'${rootRelAbsDirPosixPath}'`
).linkToCode(2);
break;
}
case AliasToType.LOCAL: {
const absToFile = alias.absDir.join(
new FilePath(alias.to as string, {posix: true})
);
const fromRelToFile = absFromFile
.dirname()
.relative(absToFile);
rewriteFile(
absFromFile,
`/* redirected by alias field(s) in ${rootRelAbsDirPosixPath} */`,
`module.exports = require('./${fromRelToFile.asPosix}');`
);
log.info(
'replace-browser-modules',
`Redirected file '${rootRelFilePosixPath}' to ` +
`'./${fromRelToFile.asPosix}' as configured in ` +
`'${rootRelAbsDirPosixPath}'`
presetFile = require.resolve('liferay-npm-bundler-preset-standard');
} else if (config.preset === '' || config.preset === false) {
// don't load preset
} else {
presetFile = resolveModule.sync(config.preset, {
basedir: '.',
});
}
if (presetFile) {
const originalConfig = Object.assign({}, config);
Object.assign(
config,
merge.recursive(readJsonSync(presetFile), originalConfig)
);
config.pluginsBaseDir = getPackageDir(presetFile);
}
// Normalize
config['/'] = config['/'] || {};
config['config'] = config['config'] || {};
config.packages = config.packages || {};
}
config = readJsonSync('.npmbundlerrc');
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
// Apply preset if necessary
if (config.preset) {
const presetFile = resolveModule.sync(config.preset, {
basedir: '.',
});
// Merge preset with base configuration
config = Object.assign(readJsonSync(presetFile), config);
pluginsBaseDir = getPackageDir(presetFile);
}
// Normalize
config.packages = config.packages || {};
return config;
}