Skip to content

Commit 29204c8

Browse files
committedJun 27, 2024
deps: @npmcli/package-json@5.2.0
1 parent ac937d4 commit 29204c8

File tree

6 files changed

+54
-20
lines changed

6 files changed

+54
-20
lines changed
 

‎node_modules/@npmcli/package-json/lib/index.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const { readFile, writeFile } = require('fs/promises')
2-
const { resolve } = require('path')
1+
const { readFile, writeFile } = require('node:fs/promises')
2+
const { resolve } = require('node:path')
3+
const parseJSON = require('json-parse-even-better-errors')
4+
35
const updateDeps = require('./update-dependencies.js')
46
const updateScripts = require('./update-scripts.js')
57
const updateWorkspaces = require('./update-workspaces.js')
68
const normalize = require('./normalize.js')
7-
8-
const parseJSON = require('json-parse-even-better-errors')
9+
const { read, parse } = require('./read-package.js')
910

1011
// a list of handy specialized helper functions that take
1112
// care of special cases that are handled by the npm cli
@@ -126,9 +127,8 @@ class PackageJson {
126127
this.#path = path
127128
let parseErr
128129
try {
129-
this.#readFileContent = await readFile(this.filename, 'utf8')
130+
this.#readFileContent = await read(this.filename)
130131
} catch (err) {
131-
err.message = `Could not read package.json: ${err}`
132132
if (!parseIndex) {
133133
throw err
134134
}
@@ -158,12 +158,7 @@ class PackageJson {
158158

159159
// Load data from a JSON string/buffer
160160
fromJSON (data) {
161-
try {
162-
this.#manifest = parseJSON(data)
163-
} catch (err) {
164-
err.message = `Invalid package.json: ${err}`
165-
throw err
166-
}
161+
this.#manifest = parse(data)
167162
return this
168163
}
169164

‎node_modules/@npmcli/package-json/lib/normalize.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const valid = require('semver/functions/valid')
22
const clean = require('semver/functions/clean')
3-
const fs = require('fs/promises')
4-
const path = require('path')
3+
const fs = require('node:fs/promises')
4+
const path = require('node:path')
55
const { log } = require('proc-log')
66

77
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This is JUST the code needed to open a package.json file and parse it.
2+
// It's isolated out so that code needing to parse a package.json file can do so in the same way as this module does, without needing to require the whole module, or needing to require the underlying parsing library.
3+
4+
const { readFile } = require('fs/promises')
5+
const parseJSON = require('json-parse-even-better-errors')
6+
7+
async function read (filename) {
8+
try {
9+
const data = await readFile(filename, 'utf8')
10+
return data
11+
} catch (err) {
12+
err.message = `Could not read package.json: ${err}`
13+
throw err
14+
}
15+
}
16+
17+
function parse (data) {
18+
try {
19+
const content = parseJSON(data)
20+
return content
21+
} catch (err) {
22+
err.message = `Invalid package.json: ${err}`
23+
throw err
24+
}
25+
}
26+
27+
// This is what most external libs will use.
28+
// PackageJson will call read and parse separately
29+
async function readPackage (filename) {
30+
const data = await read(filename)
31+
const content = parse(data)
32+
return content
33+
}
34+
35+
module.exports = {
36+
read,
37+
parse,
38+
readPackage,
39+
}

‎node_modules/@npmcli/package-json/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/package-json",
3-
"version": "5.1.1",
3+
"version": "5.2.0",
44
"description": "Programmatic API to update package.json",
55
"main": "lib/index.js",
66
"files": [

‎package-lock.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@npmcli/config": "^8.3.3",
9292
"@npmcli/fs": "^3.1.1",
9393
"@npmcli/map-workspaces": "^3.0.6",
94-
"@npmcli/package-json": "^5.1.1",
94+
"@npmcli/package-json": "^5.2.0",
9595
"@npmcli/promise-spawn": "^7.0.2",
9696
"@npmcli/redact": "^2.0.0",
9797
"@npmcli/run-script": "^8.1.0",
@@ -1716,9 +1716,9 @@
17161716
}
17171717
},
17181718
"node_modules/@npmcli/package-json": {
1719-
"version": "5.1.1",
1720-
"resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-5.1.1.tgz",
1721-
"integrity": "sha512-uTq5j/UqUzbOaOxVy+osfOhpqOiLfUZ0Ut33UbcyyAPJbZcJsf4Mrsyb8r58FoIFlofw0iOFsuCA/oDK14VDJQ==",
1719+
"version": "5.2.0",
1720+
"resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-5.2.0.tgz",
1721+
"integrity": "sha512-qe/kiqqkW0AGtvBjL8TJKZk/eBBSpnJkUWvHdQ9jM2lKHXRYYJuyNpJPlJw3c8QjC2ow6NZYiLExhUaeJelbxQ==",
17221722
"inBundle": true,
17231723
"license": "ISC",
17241724
"dependencies": {

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@npmcli/config": "^8.3.3",
5757
"@npmcli/fs": "^3.1.1",
5858
"@npmcli/map-workspaces": "^3.0.6",
59-
"@npmcli/package-json": "^5.1.1",
59+
"@npmcli/package-json": "^5.2.0",
6060
"@npmcli/promise-spawn": "^7.0.2",
6161
"@npmcli/redact": "^2.0.0",
6262
"@npmcli/run-script": "^8.1.0",

0 commit comments

Comments
 (0)
Please sign in to comment.