From 5b097fd7e5224db6de65847a604f5c60a93667a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 3 Oct 2022 19:10:53 +0200 Subject: fix(npm): better error is version is specified after subpath (#16131) --- ext/node/errors.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'ext/node/errors.rs') diff --git a/ext/node/errors.rs b/ext/node/errors.rs index 4b55d1982..929f51e1b 100644 --- a/ext/node/errors.rs +++ b/ext/node/errors.rs @@ -81,23 +81,36 @@ pub fn err_invalid_package_target( } pub fn err_package_path_not_exported( - pkg_path: String, + mut pkg_path: String, subpath: String, maybe_referrer: Option, ) -> AnyError { let mut msg = "[ERR_PACKAGE_PATH_NOT_EXPORTED]".to_string(); + #[cfg(windows)] + { + if !pkg_path.ends_with('\\') { + pkg_path.push('\\'); + } + } + #[cfg(not(windows))] + { + if !pkg_path.ends_with('/') { + pkg_path.push('/'); + } + } + if subpath == "." { msg = format!( - "{} No \"exports\" main defined in {}package.json", + "{} No \"exports\" main defined in '{}package.json'", msg, pkg_path ); } else { - msg = format!("{} Package subpath \'{}\' is not defined by \"exports\" in {}package.json", msg, subpath, pkg_path); + msg = format!("{} Package subpath '{}' is not defined by \"exports\" in '{}package.json'", msg, subpath, pkg_path); }; if let Some(referrer) = maybe_referrer { - msg = format!("{} imported from {}", msg, referrer); + msg = format!("{} imported from '{}'", msg, referrer); } generic_error(msg) -- cgit v1.2.3