@preventive/deptree 1.0.0-alpha.1 → 1.0.0-alpha.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.
@@ -0,0 +1,90 @@
1
+ // What yarn 1 asks for at the top of an install (install.js's
2
+ // fetchRequestFromCwd): the workspaces, in the order it finds them; the
3
+ // aggregator it makes of them; the root's resolutions, as resolution-map.js
4
+ // reads them; and the top-level requests, in order.
5
+
6
+ import { clean, validRange } from '@preventive/upstream/semver.js'
7
+ import { DeptreeError, quote } from '../error.js'
8
+ import { matchesGlob } from './glob.js'
9
+ import { cleanDependencies, globsOf } from './manifest.js'
10
+
11
+ // The name yarn gives the workspace aggregator is random; this stands for
12
+ // it, and sorts where a name starting so sorts.
13
+ export const AGGREGATOR = 'workspace-aggregator-00000000-0000-0000-0000-000000000000'
14
+
15
+ const KINDS = ['dependencies', 'devDependencies', 'optionalDependencies']
16
+
17
+ // The workspaces by name, in the order yarn's resolveWorkspaces finds
18
+ // them: each glob in turn, its matches as node-glob sorts them; each with
19
+ // its directory, its version as yarn cleans it, and its manifest.
20
+ // `manifests` by directory, the root's `.` among them, as the lockfile
21
+ // reader has held them to the globs.
22
+ export function workspacesOf(manifests) {
23
+ const root = manifests.get('.')
24
+ const workspaces = new Map()
25
+ const found = new Set()
26
+ for (const glob of globsOf(root)) {
27
+ const dirs = [...manifests.keys()].filter((dir) => dir !== '.' && !found.has(dir) && matchesGlob(glob, dir))
28
+ dirs.sort((a, b) => `${a}/package.json`.localeCompare(`${b}/package.json`, 'en'))
29
+ for (const dir of dirs) {
30
+ found.add(dir)
31
+ const manifest = manifests.get(dir)
32
+ const version = clean(manifest.version, { loose: true }) || manifest.version
33
+ workspaces.set(manifest.name, { name: manifest.name, dir, version, manifest })
34
+ }
35
+ }
36
+ return workspaces
37
+ }
38
+
39
+ // The aggregator yarn makes of the workspaces: the root's dependencies
40
+ // and each workspace at its version, its devDependencies and
41
+ // optionalDependencies.
42
+ export function aggregatorOf(root, workspaces) {
43
+ const dependencies = { ...root.dependencies }
44
+ for (const workspace of workspaces.values()) dependencies[workspace.name] = workspace.version
45
+ const manifest = { name: AGGREGATOR, version: '1.0.0', dependencies, devDependencies: { ...root.devDependencies }, optionalDependencies: { ...root.optionalDependencies } }
46
+ return { name: AGGREGATOR, dir: '.', version: '1.0.0', manifest: cleanDependencies(manifest), aggregator: true }
47
+ }
48
+
49
+ // The resolutions yarn reads: a path of package names, the last the one
50
+ // resolved, to a range or another source. One to another source is
51
+ // refused here, as no source but the registry is supported; one to what
52
+ // is neither, which yarn passes over, the lockfile reader has refused.
53
+ export function rulesOf(root) {
54
+ const byName = new Map()
55
+ for (const [path, range] of Object.entries(root.resolutions ?? {})) {
56
+ const names = path.match(/(?:@[^/]+\/)?[^/]+/gu) ?? [path]
57
+ const name = names.at(-1)
58
+ if (validRange(range) === null) throw new DeptreeError(`a resolution to ${quote(range)}, no semver range, is not supported`, `manifests["."].resolutions[${quote(path)}]`)
59
+ const glob = names.length === 1 ? `**/${path}` : path
60
+ if (!byName.has(name)) byName.set(name, [])
61
+ byName.get(name).push({ path, name, range, glob, pattern: `${name}@${range}` })
62
+ }
63
+ return [...byName.values()].flat()
64
+ }
65
+
66
+ // The top-level requests, as yarn makes them and in its order.
67
+ export function topRequests(root, workspaces, rules) {
68
+ const requests = rules.map((rule) => ({ pattern: rule.pattern, optional: false }))
69
+ const patterns = []
70
+ const push = (deps, optional) => {
71
+ for (const [name, range] of Object.entries(deps ?? {})) {
72
+ const pattern = `${name}@${range}`
73
+ patterns.push(pattern)
74
+ requests.push({ pattern, optional })
75
+ }
76
+ }
77
+ push(root.dependencies, false)
78
+ push(root.devDependencies, false)
79
+ push(root.optionalDependencies, true)
80
+ if (workspaces.size > 0) {
81
+ push({ [AGGREGATOR]: '1.0.0' }, false)
82
+ const implicit = {}
83
+ for (const workspace of workspaces.values()) {
84
+ if (workspace.aggregator || KINDS.some((kind) => Object.hasOwn(root[kind] ?? {}, workspace.name))) continue
85
+ implicit[workspace.name] = workspace.version
86
+ }
87
+ push(implicit, false)
88
+ }
89
+ return { requests, patterns }
90
+ }
@@ -0,0 +1,269 @@
1
+ // What yarn 1's resolver makes of a lockfile it installs frozen
2
+ // (package-resolver.js, package-request.js): a reference for each package,
3
+ // with the requests that led to it and the patterns that name it, and its
4
+ // dependencies as the patterns it asks for. Which request makes a package's
5
+ // reference, and so whose names its own requests carry, turns on the order
6
+ // yarn resolves requests in, which this follows as yarn runs them:
7
+ //
8
+ // - the top-level requests one after another, each with all it leads to
9
+ // before the next: resolutions' patterns, then the root's dependencies,
10
+ // devDependencies and optionalDependencies, then the workspace
11
+ // aggregator, then the workspaces the root does not depend on;
12
+ // - beneath one, every request at once, each taking as many turns of the
13
+ // microtask queue as its resolver does before it checks for a package
14
+ // of its name and version already resolved, by its resolver, as
15
+ // TURNS has them; one that finds none makes
16
+ // the reference and starts its own requests, in its place in the queue;
17
+ // one that finds one waits, and is added to it once all are resolved;
18
+ // - a request a resolution applies to is given the resolution's package,
19
+ // as no request at all, or once all are resolved, where the
20
+ // resolution's own pattern is not yet;
21
+ // - a request of a tag first asks the filesystem whether the tag is a
22
+ // directory of the project, which yarn would install instead, and so
23
+ // waits for every other request to be done: one alone is checked then,
24
+ // and two at once, which the filesystem answers in no set order, are
25
+ // refused.
26
+ //
27
+ // A range that is no semver range, a dist-tag or an `npm:` alias, never
28
+ // finds a package of its version, so each request of one makes a reference
29
+ // of its own, the last of which its pattern names.
30
+
31
+ import { satisfies, validRange } from '@preventive/upstream/semver.js'
32
+ import { DeptreeError, quote } from '../error.js'
33
+ import { matchesGlob } from './glob.js'
34
+
35
+ // The turns of the microtask queue a request takes before its check, by
36
+ // its resolver.
37
+ const TURNS = { registry: 5, workspace: 3 }
38
+
39
+ // yarn's normalizePattern.
40
+ export function splitPattern(pattern) {
41
+ const scoped = pattern.startsWith('@')
42
+ const parts = (scoped ? pattern.slice(1) : pattern).split('@')
43
+ let name = parts.shift()
44
+ let range = 'latest'
45
+ const hasVersion = parts.length > 0 && parts.join('@') !== ''
46
+ if (parts.length > 0) range = parts.join('@') || '*'
47
+ if (scoped) name = `@${name}`
48
+ return { name, range, hasVersion }
49
+ }
50
+
51
+ // How yarn's registry resolver reads a range before it looks the pattern
52
+ // up (normalizeRange): a semver range, and one with a `:`, an `npm:` alias
53
+ // among them, as it is; a tag, any other, as a directory first. One that
54
+ // names another source, a URL, a path or a git host, goes to another of
55
+ // yarn's resolvers, which are not followed; it is refused, as is any other
56
+ // with a `:` or an `@`, and a tag that is not a plain name.
57
+ const TAG = /^[\w~-][\w.~-]*$/u
58
+ function kindOf(range, where) {
59
+ if (validRange(range)) return 'range'
60
+ if (range.startsWith('npm:')) return 'alias'
61
+ if (TAG.test(range) && !/\.(?:tgz|tar\.gz)$/u.test(range)) return 'tag'
62
+ throw new DeptreeError('only a semver range, an npm: alias or a tag is supported', where)
63
+ }
64
+
65
+ // What a request's package asks for, as yarn asks, in its order: its
66
+ // dependencies, then its optional ones, then, a workspace's, its dev ones;
67
+ // each by its pattern, `name@range`, optional or not, dev or not. A
68
+ // lockfile entry's are the lockfile reader's targets, which are their
69
+ // patterns; one it links to a workspace has lost its range, and is
70
+ // refused.
71
+ function asked(info, where) {
72
+ const workspace = info.kind === 'workspace'
73
+ const lists = workspace ? info.workspace.manifest : info.entry
74
+ const kinds = [['dependencies', false, false], ['optionalDependencies', true, false], ...workspace ? [['devDependencies', false, true]] : []]
75
+ const out = []
76
+ for (const [kind, optional, dev] of kinds) {
77
+ for (const [name, value] of Object.entries(lists[kind] ?? {})) {
78
+ if (!workspace && value.startsWith('link:')) throw new DeptreeError(`its dependency on ${quote(name)} is a workspace, which is not supported`, where)
79
+ out.push({ pattern: workspace ? `${name}@${value}` : value, optional, dev })
80
+ }
81
+ }
82
+ return out
83
+ }
84
+
85
+ // Where yarn's cache keeps a package (generateModuleCachePath), which is
86
+ // what its hoister tells two references apart by: two of one package, as
87
+ // a tag or an alias asked for twice makes, are one there.
88
+ function locOf({ kind, name, version, entry }) {
89
+ if (kind === 'workspace') return `workspace\n${name}`
90
+ const { uid } = entry
91
+ const { sha1, integrity } = entry.resolution ?? {}
92
+ return `npm\n${name}\n${version}\n${uid !== undefined && uid !== version ? uid : sha1 ?? ''}\n${integrity ? 'integrity' : ''}`
93
+ }
94
+
95
+ // The requests yarn resolves, and what they make of the lockfile.
96
+ class Resolver {
97
+ constructor({ lockfile, workspaces, rules, isDirectory }) {
98
+ Object.assign(this, { lockfile, workspaces, rules, isDirectory })
99
+ this.patterns = new Map()
100
+ this.byName = new Map()
101
+ this.delayed = []
102
+ this.diverted = []
103
+ }
104
+
105
+ // A pattern named for a reference.
106
+ addPattern(pattern, ref) {
107
+ ref.patterns.push(pattern)
108
+ this.patterns.set(pattern, ref)
109
+ if (!this.byName.has(ref.name)) this.byName.set(ref.name, [])
110
+ const list = this.byName.get(ref.name)
111
+ if (!list.includes(pattern)) list.push(pattern)
112
+ }
113
+
114
+ // The workspace a pattern names, where its version is in the range.
115
+ workspaceOf(pattern) {
116
+ const { name, range } = splitPattern(pattern)
117
+ const workspace = this.workspaces.get(name)
118
+ return workspace !== undefined && satisfies(workspace.version, range, { loose: true }) ? workspace : undefined
119
+ }
120
+
121
+ // What a request finds before it checks: a workspace's manifest, or the
122
+ // lockfile's entry for the pattern. yarn drops an entry whose version a
123
+ // semver range of its pattern does not take (isLockfileEntryOutdated),
124
+ // and resolves the pattern anew, which --frozen-lockfile fails on only
125
+ // for a top-level one.
126
+ infoOf(request) {
127
+ const workspace = this.workspaceOf(request.pattern)
128
+ if (workspace !== undefined) return { kind: 'workspace', name: workspace.name, version: workspace.version, workspace }
129
+ const where = quote(request.pattern)
130
+ const { name, range, hasVersion } = splitPattern(request.pattern)
131
+ const tag = kindOf(range, where) === 'tag'
132
+ const entry = this.lockfile.packages[request.pattern]
133
+ if (entry === undefined) throw new DeptreeError('yarn would resolve this pattern anew: the lockfile has no entry for it', where)
134
+ if (hasVersion && validRange(range) && !satisfies(entry.version, range)) {
135
+ throw new DeptreeError(`yarn would resolve this pattern anew: the lockfile has ${entry.version}, which the range does not take`, where)
136
+ }
137
+ return { kind: 'registry', name, version: entry.version, entry, tag }
138
+ }
139
+
140
+ // The resolution that applies to a request, by its path; undefined
141
+ // where none does, or for a top-level request.
142
+ ruleOf({ pattern, parentNames }) {
143
+ if (parentNames === undefined) return undefined
144
+ const { name } = splitPattern(pattern)
145
+ const path = [...parentNames, name].join('/')
146
+ return this.rules.find((rule) => rule.name === name && matchesGlob(rule.glob, path))
147
+ }
148
+
149
+ exactMatch(name, version) {
150
+ for (const pattern of this.byName.get(name) ?? []) {
151
+ const ref = this.patterns.get(pattern)
152
+ if (ref.version === version) return ref
153
+ }
154
+ return undefined
155
+ }
156
+
157
+ // A request's check: given the package of its name and version, or made
158
+ // the reference, its own requests handed back.
159
+ check(request, info) {
160
+ const { name, range } = splitPattern(request.pattern)
161
+ const solved = validRange(range) ? info.version : range
162
+ if (this.exactMatch(name, solved) !== undefined) {
163
+ this.delayed.push(request)
164
+ return []
165
+ }
166
+ const ref = {
167
+ name: info.name,
168
+ version: info.version,
169
+ loc: locOf(info),
170
+ kind: info.kind,
171
+ entry: info.entry,
172
+ workspace: info.workspace,
173
+ patterns: [],
174
+ requests: [request],
175
+ dependencies: [],
176
+ optional: request.optional,
177
+ }
178
+ this.addPattern(request.pattern, ref)
179
+ const parentNames = [...request.parentNames ?? [], name]
180
+ const children = []
181
+ for (const dep of asked(info, quote(request.pattern))) {
182
+ ref.dependencies.push(dep.pattern)
183
+ children.push({ pattern: dep.pattern, parentNames, optional: dep.optional || (!dep.dev && request.optional) })
184
+ }
185
+ return children
186
+ }
187
+
188
+ // A request a resolution applies to, given the resolution's package.
189
+ divert(request, rule) {
190
+ const target = this.patterns.get(rule.pattern)
191
+ if (target === undefined) throw new DeptreeError(`the resolution ${quote(rule.path)} applies to it, and yarn never resolves ${quote(rule.pattern)}`, quote(request.pattern))
192
+ this.addPattern(request.pattern, target)
193
+ }
194
+
195
+ // A request about to start: given the resolution's package where one
196
+ // applies, or else timed for its check. Where yarn has not resolved the
197
+ // resolution's own pattern yet, the request waits until all else is.
198
+ start(request) {
199
+ const rule = this.ruleOf(request)
200
+ if (rule !== undefined) {
201
+ if (this.patterns.has(rule.pattern)) this.divert(request, rule)
202
+ else this.diverted.push([request, rule])
203
+ return undefined
204
+ }
205
+ const info = this.infoOf(request)
206
+ return { request, info, left: info.tag ? Infinity : TURNS[info.kind] }
207
+ }
208
+
209
+ // The one request of a tag left waiting, once every other is done, let
210
+ // on to its check; refused where the tag is a directory, or might be.
211
+ answer(waiting) {
212
+ if (waiting.length > 1) throw new DeptreeError(`yarn resolves these in the order the filesystem answers it, which is not set: ${waiting.map(({ request }) => quote(request.pattern)).join(', ')}`)
213
+ const [strand] = waiting
214
+ const where = quote(strand.request.pattern)
215
+ const { range } = splitPattern(strand.request.pattern)
216
+ const found = this.isDirectory(range)
217
+ if (found === undefined) throw new DeptreeError(`yarn installs the directory ${quote(range)} for it where the project has one, which is known only with the project read`, where)
218
+ if (found) throw new DeptreeError(`yarn installs the directory ${quote(range)} for it, which is not supported`, where)
219
+ strand.left = 1
220
+ return [strand]
221
+ }
222
+
223
+ // A turn of the microtask queue: each request whose turn it is checked,
224
+ // the requests it makes started where it stood.
225
+ turn(strands) {
226
+ const next = []
227
+ for (const strand of strands) {
228
+ if (--strand.left > 0) next.push(strand)
229
+ else next.push(...this.check(strand.request, strand.info).map((child) => this.start(child)).filter(Boolean))
230
+ }
231
+ return next
232
+ }
233
+
234
+ // A top-level request, and all it leads to.
235
+ run(request) {
236
+ let strands = [this.start(request)].filter(Boolean)
237
+ while (strands.length > 0) {
238
+ if (strands.every((strand) => strand.left === Infinity)) strands = this.answer(strands)
239
+ strands = this.turn(strands)
240
+ }
241
+ }
242
+
243
+ // resolveToExistingVersion: each waiting request, in turn, added to the
244
+ // package of its version; then each a resolution applies to that waited.
245
+ settle() {
246
+ for (const request of this.delayed) {
247
+ const { name } = splitPattern(request.pattern)
248
+ const ref = this.exactMatch(name, this.infoOf(request).version)
249
+ ref.requests.push(request)
250
+ this.addPattern(request.pattern, ref)
251
+ if (!request.optional) ref.optional = false
252
+ }
253
+ for (const [request, rule] of this.diverted) this.divert(request, rule)
254
+ }
255
+ }
256
+
257
+ // `lockfile` as @preventive/lockfile's parseYarn1Lockfile reads it;
258
+ // `workspaces` by name, in the order yarn finds them, each with its
259
+ // directory, cleaned version and manifest, the aggregator among them;
260
+ // `rules` the root's resolutions; `top` the top-level requests in order;
261
+ // `isDirectory(tag)` whether the project has a `<tag>/package.json`, or
262
+ // undefined where that is not known.
263
+ export function resolve({ top, ...options }) {
264
+ const resolver = new Resolver(options)
265
+ for (const request of top) resolver.run(request)
266
+ resolver.settle()
267
+ const { patterns, byName } = resolver
268
+ return { patterns, byName }
269
+ }
@@ -0,0 +1,123 @@
1
+ // The project's .yarnrc and .npmrc, as far as yarn 1 reads them for an
2
+ // install. Two settings are followed as yarn follows them:
3
+ //
4
+ // - ignore-engines: by a flag, `--ignore-engines` or
5
+ // `--install.ignore-engines`, where its value is true; or as an option,
6
+ // the .yarnrc's where it has one, else the .npmrc's, where its value is
7
+ // truthy, as yarn reads it: a quoted "false" is;
8
+ // - ignore-platform: by a flag alone; yarn reads the option, and does not
9
+ // act on it.
10
+ //
11
+ // Of the options, yarn reads each by its name from the .yarnrc, or else
12
+ // the .npmrc (config.getOption): those that change the tree are refused
13
+ // rather than followed — ignore-optional, production, bin-links, the
14
+ // workspaces' switches and the like — and so is yarn-path, which has
15
+ // another yarn run, and global-folder, which, where it is the project's
16
+ // own directory, has yarn read its package.json files otherwise; one yarn reads only for where it fetches from, how,
17
+ // and what it keeps, or reads for no install at all, as most of npm's,
18
+ // is passed over, as the tree is held to the lockfile's integrities
19
+ // whatever serves it. A `--` line of .yarnrc is a flag yarn adds to its
20
+ // command line, for every command or, with one before a dot, for that one:
21
+ // one that does not change the tree is passed over, and any other is
22
+ // refused, whichever command it is for.
23
+
24
+ import { DeptreeError, quote } from '../error.js'
25
+ import { parseNpmrc } from '../pnpm/npmrc.js'
26
+
27
+ // Flags passed over, by name: of those yarn 1.22 takes, the ones that do
28
+ // not change the tree.
29
+ const PASSED = new Set([
30
+ 'verbose', 'silent', 'json', 'har', 'emoji', 'no-emoji', 'progress', 'no-progress', 'non-interactive', 'no-node-version-check',
31
+ 'offline', 'prefer-offline', 'registry', 'proxy', 'https-proxy', 'network-concurrency', 'network-timeout', 'otp', 'mutex',
32
+ 'cache-folder', 'preferred-cache-folder', 'ignore-scripts', 'scripts-prepend-node-path', 'force', 'skip-integrity-check',
33
+ 'check-files', 'pure-lockfile', 'frozen-lockfile', 'audit', 'disable-pnp',
34
+ ])
35
+
36
+ // Options yarn reads that change the tree, by name: of all yarn 1.22
37
+ // reads by config.getOption, and yarn-path, which it reads first. Where
38
+ // global-folder is the project's directory, as a relative one in its
39
+ // .yarnrc may be, yarn reads no package.json with validate(), which drops
40
+ // a name listed twice from all but one of its lists.
41
+ const REFUSED = new Set([
42
+ 'ignore-optional', 'production', 'bin-links', 'workspaces-experimental', 'workspaces-nohoist-experimental', 'plugnplay-override',
43
+ 'yarn-link-file-dependencies', 'enable-meta-folder', 'experimental-pack-script-packages-in-mirror', 'global-folder', 'yarn-path',
44
+ 'yarnPath',
45
+ ])
46
+
47
+ // Settings followed, by name.
48
+ const FOLLOWED = new Set(['ignore-engines', 'ignore-platform'])
49
+
50
+ // A flag's command, `*` for every one, and its name; undefined for an
51
+ // option.
52
+ function flagOf(key) {
53
+ const match = /^--(?:(.*?)\.)?(.*)$/u.exec(key)
54
+ return match === null ? undefined : { command: match[1] ?? '*', name: match[2] }
55
+ }
56
+
57
+ // A setting, flag or option, that is not followed: refused where it may
58
+ // change the tree.
59
+ function check(key, where) {
60
+ const flag = flagOf(key)
61
+ if (flag === undefined ? REFUSED.has(key) : !PASSED.has(flag.name)) throw new DeptreeError(`${quote(key)} is a setting not supported here: it may change what yarn installs`, where)
62
+ }
63
+
64
+ // .yarnrc as yarn's parser reads it, as far as a line of a key and a value
65
+ // goes, each bare or quoted as JSON writes it; anything else is refused.
66
+ // Each setting by its key, the last line of a key the one yarn keeps, with
67
+ // its value where it is a bare true or false, or a quoted string, as yarn
68
+ // reads those; undefined for any other, or none.
69
+ const TOKEN = /"(?:[^"\\]|\\.)*"|[^\s"]+/gu
70
+
71
+ function unquote(token, what, where) {
72
+ try {
73
+ return JSON.parse(token)
74
+ } catch {
75
+ throw new DeptreeError(`${what} is not a string as JSON writes it`, where)
76
+ }
77
+ }
78
+
79
+ const BARE = new Map([['true', true], ['false', false]])
80
+
81
+ function readYarnrc(text) {
82
+ const settings = new Map()
83
+ for (const [index, raw] of text.split(/\r?\n/u).entries()) {
84
+ const where = `.yarnrc:${index + 1}`
85
+ const line = raw.trim()
86
+ if (line === '' || line.startsWith('#')) continue
87
+ if (/^\s/u.test(raw)) throw new DeptreeError('an indented line, which yarn reads into the setting above it, is not supported', where)
88
+ const tokens = line.match(TOKEN) ?? []
89
+ if (tokens.join(' ') !== line.replace(/\s+/gu, ' ') || tokens.length > 2) throw new DeptreeError('expected a setting and its value', where)
90
+ const [key, value] = tokens.map((token) => (token.startsWith('"') ? unquote(token, 'a setting', where) : token))
91
+ const bare = tokens[1]?.startsWith('"') === false
92
+ settings.set(key, { value: bare ? BARE.get(value) : value, where })
93
+ }
94
+ return settings
95
+ }
96
+
97
+ // What the install follows of the .yarnrc and the .npmrc, either of them
98
+ // left out where there is none: { ignoreEngines, ignorePlatform }.
99
+ export function readSettings({ yarnrc, npmrc }) {
100
+ const flags = new Set()
101
+ let option
102
+ for (const [key, setting] of yarnrc === undefined ? [] : readYarnrc(yarnrc)) {
103
+ const flag = flagOf(key)
104
+ const name = flag?.name ?? key
105
+ if (!FOLLOWED.has(name)) check(key, setting.where)
106
+ else if (flag === undefined) {
107
+ // yarn reads the option as truthy or not, a quoted "false" as true.
108
+ if (setting.value === undefined) throw new DeptreeError(`expected true, false or a quoted string for ${quote(key)}`, setting.where)
109
+ if (name === 'ignore-engines') option = Boolean(setting.value)
110
+ } else {
111
+ if (typeof setting.value !== 'boolean') throw new DeptreeError(`expected true or false for ${quote(key)}`, setting.where)
112
+ if (setting.value && (flag.command === '*' || flag.command === 'install')) flags.add(name)
113
+ }
114
+ }
115
+ let npmOption
116
+ for (const { key, value, list, line } of npmrc === undefined ? [] : parseNpmrc(npmrc)) {
117
+ const where = `.npmrc:${line}`
118
+ if (!FOLLOWED.has(key)) check(key, where)
119
+ else if (list || (value !== 'true' && value !== 'false')) throw new DeptreeError(`expected true or false for ${quote(key)}`, where)
120
+ else if (key === 'ignore-engines') npmOption = value === 'true'
121
+ }
122
+ return { ignoreEngines: flags.has('ignore-engines') || (option ?? npmOption ?? false), ignorePlatform: flags.has('ignore-platform') }
123
+ }