@preventive/deptree 1.5.0 → 1.5.2

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": "@preventive/deptree",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "In-memory dependency tree, as a package manager installs it",
5
5
  "type": "module",
6
6
  "exports": {
@@ -171,9 +171,9 @@
171
171
  "@exodus/bytes": "^1.16.0",
172
172
  "@preventive/archive": "^1.4.0",
173
173
  "@preventive/compare": "^1.2.11",
174
- "@preventive/diff": "^1.1.0",
174
+ "@preventive/diff": "^1.1.1",
175
175
  "@preventive/lockfile": "^1.3.0",
176
- "@preventive/upstream": "^1.6.0",
176
+ "@preventive/upstream": "^1.8.0",
177
177
  "@preventive/vfs": "^1.1.0"
178
178
  }
179
179
  }
package/src/patch.js CHANGED
@@ -74,14 +74,25 @@ function readHunks(lines, where) {
74
74
  return { hunks, blocks: files[0].blocks }
75
75
  }
76
76
 
77
+ // git writes no carriage return in a header or an `@@` line. One in a hunk's
78
+ // other lines is the file's own, as a CRLF file's lines end in one.
79
+ function checkReturns(lines, where) {
80
+ let inHunks = false
81
+ for (const line of lines) {
82
+ inHunks ||= line.startsWith('@@ ')
83
+ if (line.includes('\r') && (!inHunks || line.startsWith('@@ '))) throw new DeptreeError('a carriage return is not supported', `${where}: ${quote(line)}`)
84
+ }
85
+ }
86
+
77
87
  export function parsePatch(text, where) {
78
- if (text.includes('\r')) throw new DeptreeError('a carriage return is not supported', where)
79
88
  if (!text.startsWith(HEADER)) throw new DeptreeError(`expected ${quote(HEADER)} first`, where)
80
89
  return text.split(/\n(?=diff --git )/u).map((section) => {
81
90
  const lines = section.split('\n')
82
91
  if (lines.at(-1) === '') lines.pop()
92
+ checkReturns(lines.slice(0, 1), where)
83
93
  const path = checkPath(pathOf(lines[0]), `${where}: ${quote(lines[0])}`)
84
94
  const here = `${where}: ${quote(path)}`
95
+ checkReturns(lines.slice(1), here)
85
96
  const { change, mode, body } = readHeader(lines, path, here)
86
97
  return { path, change, mode, ...readHunks(lines.slice(body), here), where: here }
87
98
  })
@@ -15,6 +15,8 @@ const outdated = (name, detail) => new DeptreeError(`${detail}, which a frozen i
15
15
  const SIDES = ['the lockfile', 'the settings']
16
16
 
17
17
  // `hashes` is { hash, path } by selector, `byHash` { text, path } by hash.
18
+ // pnpm hashes CRLF as LF but applies each selector's own file, so two texts
19
+ // of one hash are refused: a carriage return in a hunk line is content.
18
20
  async function hashPatches(configured, given) {
19
21
  const texts = new Map()
20
22
  for (const [key, text] of given) {
@@ -34,7 +36,9 @@ async function hashPatches(configured, given) {
34
36
  const where = `patches[${quote(path)}]`
35
37
  const hash = await sha256Hex(normalized, where)
36
38
  hashes[selector] = { hash, path }
37
- if (!byHash.has(hash)) byHash.set(hash, { text, path })
39
+ const first = byHash.get(hash)
40
+ if (first === undefined) byHash.set(hash, { text, path })
41
+ else if (first.text !== text) throw new DeptreeError(`it differs from ${quote(first.path)} in line endings alone, so the two have one hash, and two texts under one hash are not supported`, where)
38
42
  }
39
43
  for (const path of texts.keys()) {
40
44
  if (!named.has(path)) throw new DeptreeError('no patchedDependencies setting names this patch', `patches[${quote(path)}]`)