summaryrefslogtreecommitdiff
path: root/ext/node/package_json.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-03-21 11:35:51 -0700
committerGitHub <noreply@github.com>2024-03-21 11:35:51 -0700
commit9abc722cc3a998b4f73103c4394b53cccdb5c83b (patch)
tree228a9eb9665439e52b9588830a80dd6c8ef1499e /ext/node/package_json.rs
parenta90a6f3b291d2a30750c2578fc3763246a182dea (diff)
feat(node): load ES modules defined as CJS (#22945)
Changes the behaviour in Deno to just always load ES modules in npm packages even if they're defined as CJS. Closes #22818
Diffstat (limited to 'ext/node/package_json.rs')
-rw-r--r--ext/node/package_json.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/ext/node/package_json.rs b/ext/node/package_json.rs
index 7fcfb6917..9d6a491b5 100644
--- a/ext/node/package_json.rs
+++ b/ext/node/package_json.rs
@@ -93,10 +93,6 @@ impl PackageJson {
),
};
- if source.trim().is_empty() {
- return Ok(PackageJson::empty(path));
- }
-
let package_json = Self::load_from_string(path, source)?;
CACHE.with(|cache| {
cache
@@ -110,6 +106,10 @@ impl PackageJson {
path: PathBuf,
source: String,
) -> Result<PackageJson, AnyError> {
+ if source.trim().is_empty() {
+ return Ok(PackageJson::empty(path));
+ }
+
let package_json: Value = serde_json::from_str(&source).map_err(|err| {
anyhow::anyhow!(
"malformed package.json: {}\n at {}",