mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: inline ndjson parse with updated deps (#10054)
* chore: inline ndjson parse with updated deps * docs: add changeset * refactor: implement CR suggestion --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/small-gifts-wonder.md
Normal file
6
.changeset/small-gifts-wonder.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/logger": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Replace ndjson with split2. Reduce the bundle size of pnpm CLI [#10054](https://github.com/pnpm/pnpm/pull/10054).
|
||||
2
__typings__/local.d.ts
vendored
2
__typings__/local.d.ts
vendored
@@ -4,7 +4,7 @@ declare module 'bole' {
|
||||
export = anything
|
||||
}
|
||||
|
||||
declare module 'ndjson' {
|
||||
declare module 'split2' {
|
||||
const anything: any
|
||||
export = anything
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"bole": "catalog:",
|
||||
"ndjson": "catalog:"
|
||||
"split2": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@pnpm/logger": "workspace:*"
|
||||
|
||||
21
packages/logger/src/ndjsonParse.ts
Normal file
21
packages/logger/src/ndjsonParse.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
// From https://www.npmjs.com/package/ndjson, but with updated deps, only parse and hardcoded options
|
||||
|
||||
import type { Transform } from 'stream'
|
||||
|
||||
import split from 'split2'
|
||||
|
||||
const opts = { strict: true }
|
||||
|
||||
export function parse (): Transform {
|
||||
function parseRow (this: Transform, row: string) {
|
||||
try {
|
||||
if (row) return JSON.parse(row)
|
||||
} catch (e) {
|
||||
if (opts.strict) {
|
||||
this.emit('error', new Error(`Could not parse row "${row.length > 50 ? `${row.slice(0, 50)}...` : row}"`))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return split(parseRow, opts)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import bole from 'bole'
|
||||
import ndjson from 'ndjson'
|
||||
import { type LogBase } from './LogBase.js'
|
||||
import * as ndjson from './ndjsonParse.js'
|
||||
|
||||
export type Reporter<LogObj extends LogBase> = (logObj: LogObj) => void
|
||||
|
||||
|
||||
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
@@ -510,9 +510,6 @@ catalogs:
|
||||
micromatch:
|
||||
specifier: ^4.0.8
|
||||
version: 4.0.8
|
||||
ndjson:
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0
|
||||
nock:
|
||||
specifier: 13.3.4
|
||||
version: 13.3.4
|
||||
@@ -684,6 +681,9 @@ catalogs:
|
||||
split-cmd:
|
||||
specifier: ^1.1.0
|
||||
version: 1.1.0
|
||||
split2:
|
||||
specifier: ^4.2.0
|
||||
version: 4.2.0
|
||||
ssri:
|
||||
specifier: 10.0.5
|
||||
version: 10.0.5
|
||||
@@ -4325,9 +4325,9 @@ importers:
|
||||
bole:
|
||||
specifier: 'catalog:'
|
||||
version: 5.0.17
|
||||
ndjson:
|
||||
split2:
|
||||
specifier: 'catalog:'
|
||||
version: 2.0.0
|
||||
version: 4.2.0
|
||||
devDependencies:
|
||||
'@pnpm/logger':
|
||||
specifier: workspace:*
|
||||
@@ -15060,6 +15060,10 @@ packages:
|
||||
split2@3.2.2:
|
||||
resolution: {integrity: sha512-9NThjpgZnifTkJpzTZ7Eue85S49QwpNhZTq6GRJwObb6jnLFNGB7Qm73V5HewTROPyxD0C29xqmaI68bQtV+hg==}
|
||||
|
||||
split2@4.2.0:
|
||||
resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==}
|
||||
engines: {node: '>= 10.x'}
|
||||
|
||||
sprintf-js@1.0.3:
|
||||
resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==}
|
||||
|
||||
@@ -23818,6 +23822,8 @@ snapshots:
|
||||
dependencies:
|
||||
readable-stream: 3.6.2
|
||||
|
||||
split2@4.2.0: {}
|
||||
|
||||
sprintf-js@1.0.3: {}
|
||||
|
||||
sprintf-js@1.1.3: {}
|
||||
|
||||
@@ -217,7 +217,6 @@ catalog:
|
||||
mdast-util-to-string: ^2.0.0
|
||||
mem: ^8.1.1
|
||||
micromatch: ^4.0.8
|
||||
ndjson: ^2.0.0
|
||||
nock: 13.3.4
|
||||
node-fetch: npm:@pnpm/node-fetch@1.0.0
|
||||
normalize-newline: 3.0.0
|
||||
@@ -275,6 +274,7 @@ catalog:
|
||||
sinon: ^16.1.3
|
||||
sort-keys: ^4.2.0
|
||||
split-cmd: ^1.1.0
|
||||
split2: ^4.2.0
|
||||
ssri: 10.0.5
|
||||
stacktracey: ^2.1.8
|
||||
string-length: ^4.0.2
|
||||
|
||||
Reference in New Issue
Block a user