@preventive/deptree 1.0.0-alpha.6 → 1.0.0-alpha.7

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/npm.d.ts CHANGED
@@ -251,8 +251,8 @@ export interface NpmTree {
251
251
  // from npm's through @preventive/upstream.
252
252
  //
253
253
  // Ranges and versions are read with npm's own semver, borrowed from the
254
- // npm beside node as @preventive/upstream borrows it, without which this
255
- // throws.
254
+ // npm beside node as @preventive/upstream borrows it, or with its semver
255
+ // peer where there is no npm, without either of which this throws.
256
256
  //
257
257
  // Nothing is left to a guess: a lockfile the lockfile reader refuses, a
258
258
  // setting this does not know or does not build for, a package from
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@preventive/deptree",
3
- "version": "1.0.0-alpha.6",
4
- "description": "A dependency tree in memory, as a package manager would install it: pnpm 9, 10, 11 or 12, yarn 1.22, or npm 10 or 11, from its lockfile, tarballs fetched and checked, patches applied; or Soldeer 0.12, its zips fetched, checked and extracted",
3
+ "version": "1.0.0-alpha.7",
4
+ "description": "A dependency tree in memory, as a package manager would install it",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./pnpm.js": {
@@ -61,11 +61,14 @@
61
61
  "src/pnpm/glob.js",
62
62
  "src/pnpm/graph.js",
63
63
  "src/pnpm/hoist.js",
64
+ "src/pnpm/hoisted.js",
64
65
  "src/pnpm/hook.js",
65
66
  "src/pnpm/inputs.js",
66
67
  "src/pnpm/install.js",
67
68
  "src/pnpm/local.js",
68
69
  "src/pnpm/minimatch.js",
70
+ "src/pnpm/nm-hoist-graph.js",
71
+ "src/pnpm/nm-hoist.js",
69
72
  "src/pnpm/npm-packlist.js",
70
73
  "src/pnpm/overrides.js",
71
74
  "src/pnpm/package.js",
@@ -121,10 +124,10 @@
121
124
  },
122
125
  "dependencies": {
123
126
  "@chalker/queue": "^1.0.1",
124
- "@preventive/archive": "1.0.0-beta.3",
125
- "@preventive/diff": "^1.0.0",
126
- "@preventive/lockfile": "1.0.0-alpha.5",
127
- "@preventive/upstream": "1.0.0-alpha.4",
128
- "@preventive/vfs": "1.0.0-beta.3"
127
+ "@preventive/archive": "1.0.0-beta.4",
128
+ "@preventive/diff": "^1.0.1",
129
+ "@preventive/lockfile": "1.0.0-alpha.6",
130
+ "@preventive/upstream": "1.0.0-alpha.7",
131
+ "@preventive/vfs": "1.0.0-beta.4"
129
132
  }
130
133
  }
package/pnpm.d.ts CHANGED
@@ -131,10 +131,12 @@ export interface PnpmProject {
131
131
  // with more than 100 `**` parts for pnpm 9 and 10, and a directory nested
132
132
  // more than 100 deep, for the time matching them takes. Matching takes
133
133
  // time linear in the path and the pattern. pnpm hardlinks those files from
134
- // the directory into each snapshot of the package, so a file linking a bin
135
- // makes executable is made so in every snapshot and in the directory, which
136
- // is not written here; a CRLF `#!` line it rewrites is rewritten as a file
137
- // of that snapshot's own. Where it builds the package — an install script, a
134
+ // the directory into each snapshot of the package, in their modes, which
135
+ // are refused but for a checkout's under umask 022 or 002: 0o644, 0o664,
136
+ // 0o755 and 0o775. So a file linking a bin makes executable — 0o755 for
137
+ // pnpm 9 and 10, its mode with 0o111 added for 11 and 12 — is made so in
138
+ // every snapshot and in the directory, which is not written here; a CRLF
139
+ // `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package — an install script, a
138
140
  // binding.gyp, which pnpm 11 and 12 pass over with `gypfile: false`, or a
139
141
  // .hooks directory — or, with pnpm 11 and 12, where packageImportMethod is
140
142
  // other than auto or hardlink, each snapshot has a copy of its own
@@ -156,9 +158,10 @@ export interface PnpmProject {
156
158
  // by their kebab-case names, those that can change the tree held to what
157
159
  // is built here, and all else — npm's own settings, publishing's,
158
160
  // credentials, other names — passed over. A `${VAR}` pnpm would fill in is
159
- // taken in a line passed over, such as `//registry.npmjs.org/:_authToken`,
160
- // where the rest of the file would not change the tree: pnpm drops the
161
- // whole file where the variable is unset.
161
+ // taken in a line passed over where the rest of the file would not change
162
+ // the tree, as pnpm drops the whole file where the variable is unset; but
163
+ // `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`, the registry's token as
164
+ // a project commonly gives it, is taken to be set, and the rest read.
162
165
  //
163
166
  // pnpm 11 reads its settings from pnpm-workspace.yaml alone, as this does
164
167
  // for it: of the .npmrc only its registries, and of the package.json no
@@ -285,7 +288,9 @@ export interface PnpmInstalled {
285
288
 
286
289
  // `vfs` is the one given, the tree mounted into it, or a new one.
287
290
  // `installed` is each snapshot in the tree, one for each `stats.installed`
288
- // counts, in the lockfile's order.
291
+ // counts, in the lockfile's order; with the hoisted linker, each copy, at
292
+ // node_modules/<alias> under where it landed, in the order pnpm makes them,
293
+ // each with the snapshot copied there.
289
294
  export interface PnpmTree {
290
295
  vfs: Vfs
291
296
  stats: PnpmTreeStats
@@ -293,8 +298,8 @@ export interface PnpmTree {
293
298
  }
294
299
 
295
300
  // The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts`
296
- // makes with the isolated linker of host.pnpm, 9, 10, 11 or 12, and no
297
- // other install: whatever the
301
+ // makes with the isolated linker of host.pnpm, 9, 10, 11 or 12, or the
302
+ // hoisted one of pnpm 10 or 11, and no other install: whatever the
298
303
  // settings say of frozen lockfiles, the install is frozen, which is also
299
304
  // the only one that hoists by the lockfile's graph alone. It is rooted at
300
305
  // the lockfile's directory: each package's
@@ -350,6 +355,40 @@ export interface PnpmTree {
350
355
  // patched package as pnpm 11 built it, which is not followed here: the
351
356
  // tree is the one a store of pnpm 12's own gives.
352
357
  //
358
+ // With nodeLinker: hoisted, for pnpm 10 and 11, the tree is the one the
359
+ // hoisted linker makes: each package copied to node_modules/<alias> as near
360
+ // the root as @yarnpkg/nm's hoist takes it, under what needs it where the
361
+ // name there is another's, and each project's dependencies the root has
362
+ // another of in its own node_modules; a project's `link:` dependencies
363
+ // linked there, and a package's refused, which pnpm links nowhere; and no
364
+ // node_modules/.pnpm, where pnpm keeps only its state. pnpm takes every
365
+ // snapshot of one name and version for the first it comes to, and every
366
+ // directory of one name for one, as is followed here; from pnpm 11.24, each
367
+ // snapshot of a directory for its own. From pnpm 11.28 it also links each
368
+ // named project into the root's node_modules by its name, as
369
+ // hoistWorkspacePackages has it, where a hoist pattern matches it and the
370
+ // root depends on nothing of that name and no package landed there by it,
371
+ // their case folded; and from 11.28.1 does not hoist a project's `link:`
372
+ // into itself (`link:<root>/`). Every copy has to be its own, so
373
+ // packageImportMethod has to be copy, clone or clone-or-copy: any other
374
+ // hardlinks from pnpm's store. Bins are fixed as pnpm links them: in each
375
+ // node_modules as it fills it, then in each project's again with its links
376
+ // in, a command of the project's own dependencies over another's. Where any
377
+ // patch is configured, pnpm builds each package patched or with an install
378
+ // script in one of its copies, which it finds through the dependencies of
379
+ // each, by snapshot or from pnpm 11.23 by package, linking its
380
+ // dependencies' bins and its own, and links that copy's files into the
381
+ // others: before pnpm 10.21 in place, which leaves the others unpatched;
382
+ // from 10.21 a copy of hardlinks put in place of each, with no
383
+ // node_modules, which drops the copy's own; and from 11.25 each file but
384
+ // those under a node_modules in place of the copy's own, keeping its
385
+ // node_modules and what the built copy has not, which leaves a file the
386
+ // patch deletes in the others. These are refused where they would change a
387
+ // copy, and so is a patched package no copy of which the build reaches,
388
+ // which pnpm leaves unpatched; which copy pnpm builds is not followed, and
389
+ // refused where it would change a bin. Hoisting is refused past 50,000,000
390
+ // steps, weighted by the work each does, or a tree of 100,000 packages.
391
+ //
353
392
  // The lockfile is held to what a frozen install holds it to, and refused
354
393
  // where pnpm would refuse it: the settings that shaped its resolution —
355
394
  // catalogs, overrides, package extensions, optional dependencies left out,
package/src/hash.js CHANGED
@@ -19,8 +19,7 @@ export const sha256Hex = async (text, where) => hex(await digest('SHA-256', utf8
19
19
  const SHIFTS = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21]
20
20
  const SINES = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 2 ** 32) >>> 0)
21
21
  function md5(input) {
22
- const blocks = Math.ceil((input.length + 9) / 64)
23
- const padded = new Uint8Array(blocks * 64)
22
+ const padded = new Uint8Array(Math.ceil((input.length + 9) / 64) * 64)
24
23
  padded.set(input)
25
24
  padded[input.length] = 0x80
26
25
  const view = new DataView(padded.buffer)
@@ -38,10 +37,7 @@ function md5(input) {
38
37
  ;[a, d, c] = [d, c, b]
39
38
  b = (b + ((sum << shift) | (sum >>> (32 - shift)))) >>> 0
40
39
  }
41
- state[0] = (state[0] + a) >>> 0
42
- state[1] = (state[1] + b) >>> 0
43
- state[2] = (state[2] + c) >>> 0
44
- state[3] = (state[3] + d) >>> 0
40
+ for (const [i, word] of [a, b, c, d].entries()) state[i] = (state[i] + word) >>> 0
45
41
  }
46
42
  const bytes = new Uint8Array(16)
47
43
  const out = new DataView(bytes.buffer)
package/src/matcher.js CHANGED
@@ -13,9 +13,10 @@ export function wildcard(pattern, { one = false, any = () => true } = {}) {
13
13
  const onward = (places) => {
14
14
  for (let i = 0; i < end; i++) if (places[i] === 1 && parts[i] === '*') places[i + 1] = 1
15
15
  }
16
+ let here = new Uint8Array(end + 1)
17
+ let next = new Uint8Array(end + 1)
16
18
  return (text) => {
17
- let here = new Uint8Array(end + 1)
18
- let next = new Uint8Array(end + 1)
19
+ here.fill(0)
19
20
  here[0] = 1
20
21
  onward(here)
21
22
  for (const char of text) {
package/src/mount.js CHANGED
@@ -29,6 +29,15 @@ function checkCollisions(vfs) {
29
29
  // A path within a directory: no segment of it empty, `.` or `..`.
30
30
  export const isInside = (path) => path !== '' && path.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..')
31
31
 
32
+ // Whether `child` is `parent` or under it, both paths from one directory in
33
+ // normal form, `.` being that one.
34
+ export const within = (parent, child) => child === parent || (parent === '.' ? child !== '..' && !child.startsWith('../') : child.startsWith(`${parent}/`))
35
+
36
+ // What the lockfile reader refuses in a path: a backslash, a separator on
37
+ // Windows, and what reads otherwise than it is written (a control character,
38
+ // a line or paragraph separator, a bidirectional control).
39
+ export const UNSAFE = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\\]/u
40
+
32
41
  const asRefusal = (error, what, path) => {
33
42
  if (error instanceof VfsError) return new DeptreeError(`cannot be ${what}: ${error.message}`, quote(path), { cause: error })
34
43
  return error
package/src/npm/bins.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { basename, dirname, join } from '@preventive/vfs/path.js'
8
8
  import { DeptreeError, quote } from '../error.js'
9
- import { isModules } from '../tarball.js'
9
+ import { fixShebang, isModules } from '../tarball.js'
10
10
 
11
11
  const collator = new Intl.Collator('en')
12
12
 
@@ -26,23 +26,6 @@ function modulesOf(location) {
26
26
  return basename(parent) === 'node_modules' ? parent : dirname(parent)
27
27
  }
28
28
 
29
- const decoder = new TextDecoder('utf-8', { fatal: true })
30
-
31
- // bin-links rewrites the file as UTF-8, which it has to be here.
32
- function fixed({ data }, where) {
33
- const newline = data.subarray(0, 2048).indexOf(0x0a)
34
- if (data[0] !== 0x23 || data[1] !== 0x21 || newline < 4 || data[newline - 1] !== 0x0d) return { data, mode: 0o755 }
35
- try {
36
- decoder.decode(data)
37
- } catch {
38
- throw new DeptreeError('a bin with a CRLF shebang that is not UTF-8, which npm rewrites with replacement characters, is not supported', where)
39
- }
40
- const unix = new Uint8Array(data.length - 1)
41
- unix.set(data.subarray(0, newline - 1))
42
- unix.set(data.subarray(newline), newline - 1)
43
- return { data: unix, mode: 0o755 }
44
- }
45
-
46
29
  // The files linking changes, by each package's location.
47
30
  export function fixBins(nodes, fetched) {
48
31
  const seen = new Set()
@@ -64,7 +47,7 @@ export function fixBins(nodes, fetched) {
64
47
  throw new DeptreeError(`${quote(path)} is a directory, which is not supported`, where)
65
48
  }
66
49
  if (!changed.has(location)) changed.set(location, new Map())
67
- changed.get(location).set(path, fixed(file, where))
50
+ changed.get(location).set(path, { data: fixShebang(file.data, 'a bin with a CRLF shebang that is not UTF-8, which npm rewrites with replacement characters, is not supported', where), mode: 0o755 })
68
51
  }
69
52
  }
70
53
  return changed
package/src/npm/compat.js CHANGED
@@ -20,7 +20,7 @@ function listOf(pkg, key, at) {
20
20
  }
21
21
 
22
22
  // A libc fails a host with none, whatever it names.
23
- export function checkPlatform(pkg, host, at) {
23
+ function checkPlatform(pkg, host, at) {
24
24
  for (const key of ['os', 'cpu', 'libc']) {
25
25
  const list = listOf(pkg, key, at)
26
26
  if (list !== undefined && (host[key] === undefined || !takes(host[key], list))) return `its ${key}, ${quote(JSON.stringify(list))}, is not the host's`
@@ -28,7 +28,7 @@ export function checkPlatform(pkg, host, at) {
28
28
  return undefined
29
29
  }
30
30
 
31
- export function checkEngine(pkg, host) {
31
+ function checkEngine(pkg, host) {
32
32
  const { engines } = pkg
33
33
  if (!engines) return undefined
34
34
  const options = { includePrerelease: true }
@@ -37,6 +37,14 @@ export function checkEngine(pkg, host) {
37
37
  return undefined
38
38
  }
39
39
 
40
+ // What npm fails on of a package it does not leave out, `and` said of it.
41
+ export function checkRuns(manifest, host, where, engineStrict, and = '') {
42
+ const platform = checkPlatform(manifest, host, where)
43
+ if (platform !== undefined) throw new DeptreeError(`${platform}${and}, which npm fails on`, where)
44
+ const engine = engineStrict ? checkEngine(manifest, host) : undefined
45
+ if (engine !== undefined) throw new DeptreeError(`${engine}${and}, which npm fails on with engine-strict`, where)
46
+ }
47
+
40
48
  // Arborist's gatherDepSet.
41
49
  function gatherDepSet(set, follow) {
42
50
  const deps = new Set(set)
@@ -74,10 +82,7 @@ export function skippedOf(nodes, host, settings) {
74
82
  if (node.kind !== 'package') continue
75
83
  const where = whereOf(node)
76
84
  if (!node.pkg.optional) {
77
- const platform = checkPlatform(node.manifest, host, where)
78
- if (platform !== undefined) throw new DeptreeError(`${platform}, and it is not optional, which npm fails on`, where)
79
- const engine = settings.engineStrict ? checkEngine(node.manifest, host) : undefined
80
- if (engine !== undefined) throw new DeptreeError(`${engine}, and it is not optional, which npm fails on with engine-strict`, where)
85
+ checkRuns(node.manifest, host, where, settings.engineStrict, ', and it is not optional')
81
86
  continue
82
87
  }
83
88
  if (!host.reuse && skipped.has(node)) continue
package/src/npm/inputs.js CHANGED
@@ -4,17 +4,14 @@ import { valid } from '@preventive/upstream/semver.js'
4
4
  import { DeptreeError, quote } from '../error.js'
5
5
  import { walkWorkspaces } from '../glob.js'
6
6
  import { readManifest, readManifests } from '../manifest.js'
7
- import { checkProject, readText, typeOf } from '../project.js'
7
+ import { checkHostKeys, checkLeftOut, checkProject, checkTexts, readText, typeOf } from '../project.js'
8
8
  import { readSettings } from './settings.js'
9
9
  import { profileOf } from './versions.js'
10
10
 
11
11
  const LIBCS = new Set(['glibc', 'musl'])
12
12
 
13
13
  export function checkHost(host) {
14
- if (host === null || typeof host !== 'object') throw new TypeError('host must be an object with npm, node, os and cpu, and libc on Linux')
15
- for (const key of ['npm', 'node', 'os', 'cpu']) {
16
- if (typeof host[key] !== 'string' || host[key] === '') throw new TypeError(`host.${key} must be a non-empty string`)
17
- }
14
+ checkHostKeys(host, ['npm', 'node', 'os', 'cpu'], 'npm, node, os and cpu, and libc on Linux')
18
15
  if (valid(host.node) !== host.node) throw new DeptreeError(`${quote(host.node)} is not an exact version`, 'host.node')
19
16
  if (host.os === 'win32') throw new DeptreeError('Windows is not supported: npm links bins there with shims, and workspaces with junctions', 'host.os')
20
17
  if (host.os === 'linux' ? !LIBCS.has(host.libc) : host.libc !== undefined) {
@@ -67,14 +64,12 @@ export function inputsOf(options, nocase) {
67
64
  if (lockfile === undefined) {
68
65
  if (project === undefined) throw new TypeError(LOCKFILE)
69
66
  checkProject(project)
70
- for (const [name, value] of Object.entries({ manifests, npmrc })) {
71
- if (value !== undefined) throw new TypeError(`${name} must be left out where lockfile is: both are read from project`)
72
- }
67
+ checkLeftOut({ manifests, npmrc })
73
68
  return readProject(project, nocase)
74
69
  }
75
70
  if (project !== undefined) throw new TypeError('project must be left out where lockfile is given')
76
71
  if (typeof lockfile !== 'string') throw new TypeError(LOCKFILE)
77
72
  if (manifests === null || typeof manifests !== 'object') throw new TypeError('manifests must map each project\'s directory to its package.json')
78
- if (npmrc !== undefined && typeof npmrc !== 'string') throw new TypeError('npmrc must be a string, or left out')
73
+ checkTexts({ npmrc })
79
74
  return { lockfile, manifests: readManifests(manifests), settings: readSettings(npmrc) }
80
75
  }
@@ -4,7 +4,7 @@
4
4
  import { join } from '@preventive/vfs/path.js'
5
5
  import { DeptreeError, quote } from '../error.js'
6
6
  import { own } from '../manifest.js'
7
- import { checkEngine, checkPlatform } from './compat.js'
7
+ import { checkRuns } from './compat.js'
8
8
  import { checkDevEngines } from './dev-engines.js'
9
9
 
10
10
  const where = (dir) => `manifests[${quote(dir)}]`
@@ -102,16 +102,6 @@ function checkWorkspace(dir, manifest, importer) {
102
102
  }
103
103
  }
104
104
 
105
- // The root and workspaces are never left out; npm skips the root's engines
106
- // where it has devEngines.
107
- function checkHostOf(dir, manifest, host, settings) {
108
- const reason = checkPlatform(manifest, host, where(dir))
109
- if (reason !== undefined) throw new DeptreeError(`${reason}, which npm fails on`, where(dir))
110
- if (!settings.engineStrict || (dir === '.' && manifest.devEngines)) return
111
- const engine = checkEngine(manifest, host)
112
- if (engine !== undefined) throw new DeptreeError(`${engine}, which npm fails on with engine-strict`, where(dir))
113
- }
114
-
115
105
  export function checkManifests({ lockfile, manifests, settings, host, rootEdges }) {
116
106
  const root = manifests.get('.')
117
107
  if (root.overrides != null && (typeof root.overrides !== 'object' || Object.keys(root.overrides).length > 0)) {
@@ -133,6 +123,8 @@ export function checkManifests({ lockfile, manifests, settings, host, rootEdges
133
123
  }
134
124
  compareEdges(dir === '.' ? rootEdges : edgesOf(manifest, where(dir), [], settings.legacyPeerDeps), importer, where(dir))
135
125
  if (host.reuse && dir !== '.' && manifest.scripts?.prepare) throw new DeptreeError('a workspace with a prepare script, which npm 10 runs even with --ignore-scripts, is not supported', `${where(dir)}.scripts.prepare`)
136
- checkHostOf(dir, manifest, host, settings)
126
+ // The root and workspaces are never left out; npm skips the root's engines
127
+ // where it has devEngines.
128
+ checkRuns(manifest, host, where(dir), settings.engineStrict && !(dir === '.' && manifest.devEngines))
137
129
  }
138
130
  }
package/src/npmrc.js CHANGED
@@ -7,8 +7,7 @@ import { DeptreeError } from './error.js'
7
7
 
8
8
  export function parseNpmrc(text) {
9
9
  const settings = []
10
- const lines = text.split(/\r\n|\r|\n/u)
11
- for (const [index, raw] of lines.entries()) {
10
+ for (const [index, raw] of text.split(/\r\n|\r|\n/u).entries()) {
12
11
  const line = raw.trim()
13
12
  const where = `.npmrc:${index + 1}`
14
13
  if (line === '' || line.startsWith('#') || line.startsWith(';')) continue
package/src/patch.js CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  import { applyChangeSet, parseDiff } from '@preventive/diff'
9
9
  import { DeptreeError, quote } from './error.js'
10
+ import { UNSAFE, isInside } from './mount.js'
11
+ import { decodeUtf8 } from './project.js'
10
12
 
11
13
  const HEADER = 'diff --git a/'
12
14
  const MODE = /^(?:new|deleted) file mode (100644|100755)$/u
@@ -24,10 +26,8 @@ function pathOf(header) {
24
26
  // separator on Windows, and what reads otherwise than it is written (a line
25
27
  // or paragraph separator, a bidirectional control) are refused, as the
26
28
  // lockfile reader refuses them in a path.
27
- const UNSAFE = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\\]/u
28
-
29
29
  function checkPath(path, where) {
30
- if (path === undefined || path.startsWith('"') || UNSAFE.test(path) || path.split('/').some((segment) => segment === '' || segment === '.' || segment === '..')) {
30
+ if (path === undefined || path.startsWith('"') || UNSAFE.test(path) || !isInside(path)) {
31
31
  throw new DeptreeError('expected a header naming one relative path on both sides', where)
32
32
  }
33
33
  return path
@@ -96,17 +96,8 @@ function applyTo(text, { hunks, blocks, where }) {
96
96
  return applyChangeSet(text, blocks)
97
97
  }
98
98
 
99
- const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })
100
99
  const encoder = new TextEncoder()
101
100
 
102
- function textOf(file, where) {
103
- try {
104
- return decoder.decode(file.data)
105
- } catch {
106
- throw new DeptreeError('changes a file that is not UTF-8', where)
107
- }
108
- }
109
-
110
101
  function bytesOf(text, where) {
111
102
  if (!text.isWellFormed()) throw new DeptreeError('makes a file that is not well-formed text', where)
112
103
  return encoder.encode(text)
@@ -130,7 +121,7 @@ export function applyPatch(files, patch, { createdMode } = {}) {
130
121
  if (current?.data === undefined) throw new DeptreeError('changes a file that is not there', file.where)
131
122
  // A deletion git writes with --irreversible-delete has no hunks, and
132
123
  // says nothing of what it deletes.
133
- const result = file.change === 'delete' && file.hunks.length === 0 ? '' : applyTo(textOf(current, file.where), file)
124
+ const result = file.change === 'delete' && file.hunks.length === 0 ? '' : applyTo(decodeUtf8(current.data, 'changes a file that is not UTF-8', file.where), file)
134
125
  if (file.change === 'delete') {
135
126
  if (result !== '') throw new DeptreeError('deletes a file it does not remove all of', file.where)
136
127
  next.delete(file.path)