diff --git a/lib/install.js b/lib/install.js index 7b48ef4..99f37cd 100644 --- a/lib/install.js +++ b/lib/install.js @@ -48,17 +48,38 @@ const installGlobal = function (packageName, registry, namespace, cluster, optio exports.installGlobal = installGlobal; +/** + * Get package.json object from path + * @param path + * @returns {Object} + */ +const getPackageObject = function (path) { + const packageJSONFilePath = `${path}/package.json`; + const packageObject = JSON.parse(fs.readFileSync(packageJSONFilePath, "utf-8")); + return packageObject; +}; + /** * Get Package name from path * @param path * @returns {string} */ const packageNameFromPath = function (path) { - const packageJSONFilePath = `${path}/package.json`; - const packageObject = JSON.parse(fs.readFileSync(packageJSONFilePath, "utf-8")); + const packageObject = getPackageObject(path); return `${packageObject.name}@${packageObject.version}`; }; +/** + * Get Package namespace from path + * @param path + * @returns {string} + */ +const packageNamespaceFromPath = function (path) { + const packageObject = getPackageObject(path); + if (!packageObject.config || !packageObject.config.namespace) return null; + return packageObject.config.namespace; +}; + /** * Install a package * @@ -85,6 +106,8 @@ const install = function (packageName, registry, namespace, save, cluster, optio } } + namespace = packageNamespaceFromPath(dirPath) || namespace; + let parentPackageName = packageName; return npmInstall(dirPath, packageName, registry, npmSaveParam) .then((_) => {