@jsenv/node-esm-resolution 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/node-esm-resolution",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/jsenv/core",
@@ -22,7 +22,7 @@
22
22
  "/main.js"
23
23
  ],
24
24
  "dependencies": {
25
- "@jsenv/filesystem": "4.15.6"
25
+ "@jsenv/filesystem": "4.15.8"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@jsenv/assert": "../assert",
@@ -1,12 +1,23 @@
1
1
  import { readFileSync } from "node:fs";
2
2
 
3
3
  export const defaultReadPackageJson = (packageUrl) => {
4
- const packageJsonUrl = new URL("package.json", packageUrl);
5
- const buffer = readFileSync(packageJsonUrl);
6
- const string = String(buffer);
4
+ const packageJsonFileUrl = new URL("./package.json", packageUrl);
5
+ let packageJsonFileContentBuffer;
7
6
  try {
8
- return JSON.parse(string);
7
+ packageJsonFileContentBuffer = readFileSync(packageJsonFileUrl, "utf8");
8
+ } catch (e) {
9
+ if (e.code === "ENOENT") {
10
+ return null;
11
+ }
12
+ throw e;
13
+ }
14
+ const packageJsonFileContentString = String(packageJsonFileContentBuffer);
15
+ try {
16
+ const packageJsonFileContentObject = JSON.parse(
17
+ packageJsonFileContentString,
18
+ );
19
+ return packageJsonFileContentObject;
9
20
  } catch {
10
- throw new Error(`Invalid package configuration`);
21
+ throw new Error(`Invalid package configuration at ${packageJsonFileUrl}`);
11
22
  }
12
23
  };