Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!t.isIdentifier(callee, {name: 'define'})) {
return;
}
const {arguments: args} = expression;
const {dependencies: depsIndex, name: nameIndex} = getDefineIndices(
t,
args
);
// Namespace module name
if (namespaces.module && nameIndex !== undefined) {
const moduleName = args[nameIndex].value;
args[nameIndex].value = ns.addNamespace(
moduleName,
namespaces.module
);
state.namesCount++;
}
// Namespace dependencies
if (depsIndex !== undefined) {
const deps = args[depsIndex].elements;
deps.forEach((dep, i) => {
const {value: moduleName} = dep;
if (
!t.isStringLiteral(dep) ||
Object.keys(pkgJson.dependencies).forEach(pkgName => {
const namespacedPkgName = ns.addNamespace(pkgName, rootPkgJson);
const version = pkgJson.dependencies[pkgName];
pkgJson.dependencies[namespacedPkgName] = version;
delete pkgJson.dependencies[pkgName];
});
function addDependencyNamespace(moduleName, namespacePkg, unrolledImports) {
const {pkgName, scope} = mod.splitModuleName(moduleName);
const fullPkgName = mod.joinModuleName(scope, pkgName);
const pkg = unrolledImports[fullPkgName] || namespacePkg;
return pkg.name === '' ? moduleName : ns.addNamespace(moduleName, pkg);
}
export default function({log, pkg, rootPkgJson}, {pkgJson}) {
if (!pkg.isRoot) {
pkgJson.name = ns.addNamespace(pkgJson.name, rootPkgJson);
log.info('namespace-packages', 'Namespaced package');
}
pkgJson.dependencies = pkgJson.dependencies || {};
Object.keys(pkgJson.dependencies).forEach(pkgName => {
const namespacedPkgName = ns.addNamespace(pkgName, rootPkgJson);
const version = pkgJson.dependencies[pkgName];
pkgJson.dependencies[namespacedPkgName] = version;
delete pkgJson.dependencies[pkgName];
});
log.info(
Object.keys(imports[namespace]).forEach(pkgName => {
const localName = ns.addNamespace(pkgName, rootPkgJson);
const importVersion = imports[namespace][pkgName];
const importName =
namespace === ''
? pkgName
: ns.addNamespace(pkgName, {name: namespace});
pkgJson.dependencies[importName] = importVersion;
if (
pkgJson.dependencies[localName] !== undefined &&
pkgJson.dependencies[localName] !== importVersion
) {
log.info(
'inject-imports-dependencies',
'Injected dependency',
Object.keys(imports[namespace]).forEach(pkgName => {
const localName = ns.addNamespace(pkgName, rootPkgJson);
const importVersion = imports[namespace][pkgName];
const importName =
namespace === ''
? pkgName
: ns.addNamespace(pkgName, {name: namespace});
pkgJson.dependencies[importName] = importVersion;
if (
pkgJson.dependencies[localName] !== undefined &&
pkgJson.dependencies[localName] !== importVersion
) {
log.info(
'inject-imports-dependencies',
'Injected dependency',
`${importName}@${importVersion}`,
'(however, note that the same dependency in package.json',
'has different constraints:',
`${localName}@${pkgJson.dependencies[localName]})`
);
} else {