Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override namespace from package config #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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((_) => {
Expand Down