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

feat: ✨ added support for using current npm registry #673

Closed
Closed
Show file tree
Hide file tree
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
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