Skip to content

Commit

Permalink
Override namespace from package config
Browse files Browse the repository at this point in the history
  • Loading branch information
louisnow committed Dec 17, 2021
1 parent b1f578e commit 00b898d
Showing 1 changed file with 25 additions and 2 deletions.
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

0 comments on commit 00b898d

Please sign in to comment.