From 5fc0f9dfdac3f95fd2eb6855beb2020941b2a361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Louren=C3=A7o?= <12551007+H4ad@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:37:51 -0300 Subject: [PATCH] fix: lazy load validate npm package name on error message (#7347) ![image](https://github.com/npm/cli/assets/12551007/0a573258-858d-406c-bbf5-926f62fde964) This package takes 5ms to load even if we didn't use it. --- lib/utils/error-message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index fc7be8301662e..348bb63e2d5ab 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -1,6 +1,5 @@ const { format } = require('util') const { resolve } = require('path') -const nameValidator = require('validate-npm-package-name') const { redactLog: replaceInfo } = require('@npmcli/redact') const { report } = require('./explain-eresolve.js') const log = require('./log-shim') @@ -215,6 +214,7 @@ const errorMessage = (er, npm) => { detail.push(['404', '']) detail.push(['404', '', `'${replaceInfo(er.pkgid)}' is not in this registry.`]) + const nameValidator = require('validate-npm-package-name') const valResult = nameValidator(pkg) if (!valResult.validForNewPackages) {