Skip to content

Commit

Permalink
feat: ✨ added support for using current npm registry
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Oct 6, 2021
1 parent ccb4bd2 commit 25025bb
Show file tree
Hide file tree
Showing 4 changed files with 22,574 additions and 170 deletions.
4 changes: 3 additions & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const log = require('loglevel');
const Arborist = require('@npmcli/arborist');
const { validateTemplateConfig } = require('./templateConfigValidator');
const {
getCurrentNpmRegistry,
convertMapToObject,
isFileSystemPath,
readFile,
Expand Down Expand Up @@ -386,7 +387,8 @@ class Generator {
if (isFileSystemPath(this.templateName)) log.debug(logMessage.NPM_INSTALL_TRIGGER);

const arb = new Arborist({
path: ROOT_DIR
path: ROOT_DIR,
registry: getCurrentNpmRegistry()
});

try {
Expand Down
18 changes: 18 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const npmConfigReader = require('libnpmconfig');
const fs = require('fs');
const util = require('util');
const path = require('path');
Expand Down Expand Up @@ -243,3 +244,20 @@ utils.getMapBaseUrlToFolderResolver = (urlToFolder) => {
}
};
};

/**
* Get the current NPM registry
* @private
* @returns {string} The NPM registry currently used.
*/
utils.getCurrentNpmRegistry = () => {
let npmRegistry;
try {
// We aren't returning here as the `get` can return empty string
npmRegistry = npmConfigReader.read().get('registry');
} catch (err) {
// We ignore the error as we just gonna use the default
}

return npmRegistry || 'https://registry.npmjs.org/';
};
Loading

0 comments on commit 25025bb

Please sign in to comment.