@preventive/deptree 1.0.0-alpha.5 → 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.
Files changed (79) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/npm.d.ts +288 -0
  3. package/npm.js +7 -0
  4. package/package.json +41 -12
  5. package/pnpm.d.ts +158 -25
  6. package/pnpm.js +2 -10
  7. package/soldeer.d.ts +13 -0
  8. package/soldeer.js +1 -7
  9. package/src/concurrent.js +16 -17
  10. package/src/error.js +5 -9
  11. package/src/glob.js +55 -0
  12. package/src/hash.js +60 -13
  13. package/src/manifest.js +52 -0
  14. package/src/matcher.js +60 -10
  15. package/src/mount.js +104 -44
  16. package/src/npm/bins.js +54 -0
  17. package/src/npm/compat.js +97 -0
  18. package/src/npm/dev-engines.js +52 -0
  19. package/src/npm/graph.js +68 -0
  20. package/src/npm/inputs.js +75 -0
  21. package/src/npm/manifests.js +130 -0
  22. package/src/npm/package.js +57 -0
  23. package/src/npm/ratio.js +34 -0
  24. package/src/npm/settings.js +67 -0
  25. package/src/npm/tree.js +136 -0
  26. package/src/npm/versions.js +20 -0
  27. package/src/npmrc.js +24 -0
  28. package/src/patch.js +22 -41
  29. package/src/pnpm/bins.js +152 -131
  30. package/src/pnpm/checks.js +8 -35
  31. package/src/pnpm/commands.js +53 -96
  32. package/src/pnpm/filename.js +10 -21
  33. package/src/pnpm/frozen.js +29 -75
  34. package/src/pnpm/gitignore.js +139 -0
  35. package/src/pnpm/glob.js +65 -0
  36. package/src/pnpm/graph.js +15 -43
  37. package/src/pnpm/hoist.js +68 -61
  38. package/src/pnpm/hoisted.js +234 -0
  39. package/src/pnpm/hook.js +26 -31
  40. package/src/pnpm/inputs.js +73 -56
  41. package/src/pnpm/install.js +85 -131
  42. package/src/pnpm/local.js +21 -40
  43. package/src/pnpm/minimatch.js +319 -0
  44. package/src/pnpm/nm-hoist-graph.js +299 -0
  45. package/src/pnpm/nm-hoist.js +149 -0
  46. package/src/pnpm/npm-packlist.js +217 -0
  47. package/src/pnpm/overrides.js +11 -51
  48. package/src/pnpm/package.js +121 -0
  49. package/src/pnpm/packlist.js +169 -109
  50. package/src/pnpm/patches.js +18 -25
  51. package/src/pnpm/projects.js +63 -107
  52. package/src/pnpm/readers.js +63 -83
  53. package/src/pnpm/settings.js +64 -100
  54. package/src/pnpm/tree.js +197 -169
  55. package/src/pnpm/uptodate.js +16 -28
  56. package/src/pnpm/workspace.js +124 -133
  57. package/src/project.js +57 -0
  58. package/src/soldeer/config.js +8 -24
  59. package/src/soldeer/inputs.js +5 -15
  60. package/src/soldeer/tree.js +22 -60
  61. package/src/soldeer/zip.js +17 -36
  62. package/src/tarball.js +55 -140
  63. package/src/yarn1/bins.js +9 -19
  64. package/src/yarn1/compat.js +9 -28
  65. package/src/yarn1/hoist.js +53 -68
  66. package/src/yarn1/inputs.js +19 -61
  67. package/src/yarn1/manifest.js +8 -23
  68. package/src/yarn1/package.js +24 -63
  69. package/src/yarn1/peers.js +8 -15
  70. package/src/yarn1/requests.js +19 -37
  71. package/src/yarn1/resolve.js +36 -113
  72. package/src/yarn1/settings.js +15 -43
  73. package/src/yarn1/tree.js +67 -91
  74. package/yarn1.d.ts +34 -5
  75. package/yarn1.js +1 -8
  76. package/src/pnpm/npmrc.js +0 -31
  77. package/src/pnpm/project.js +0 -97
  78. package/src/yarn1/glob.js +0 -52
  79. /package/{LICENSE → LICENSE-MIT} +0 -0
@@ -1,24 +1,18 @@
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.
1
+ // What yarn 1 asks for at the top (install.js's fetchRequestFromCwd).
5
2
 
6
3
  import { clean, validRange } from '@preventive/upstream/semver.js'
7
4
  import { DeptreeError, quote } from '../error.js'
8
- import { matchesGlob } from './glob.js'
5
+ import { matchesGlob } from '../glob.js'
9
6
  import { cleanDependencies, globsOf } from './manifest.js'
10
7
 
11
- // The name yarn gives the workspace aggregator is random; this stands for
12
- // it, and sorts where a name starting so sorts.
8
+ // yarn names the workspace aggregator at random; this stands for it, and
9
+ // sorts where a name starting so sorts.
13
10
  export const AGGREGATOR = 'workspace-aggregator-00000000-0000-0000-0000-000000000000'
14
11
 
15
12
  const KINDS = ['dependencies', 'devDependencies', 'optionalDependencies']
16
13
 
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.
14
+ // In the order yarn's resolveWorkspaces finds them, glob by glob, matches as
15
+ // node-glob sorts them; the lockfile reader has held `manifests` to the globs.
22
16
  export function workspacesOf(manifests) {
23
17
  const root = manifests.get('.')
24
18
  const workspaces = new Map()
@@ -36,9 +30,7 @@ export function workspacesOf(manifests) {
36
30
  return workspaces
37
31
  }
38
32
 
39
- // The aggregator yarn makes of the workspaces: the root's dependencies
40
- // and each workspace at its version, its devDependencies and
41
- // optionalDependencies.
33
+ // The virtual manifest yarn makes of the root and the workspaces.
42
34
  export function aggregatorOf(root, workspaces) {
43
35
  const dependencies = { ...root.dependencies }
44
36
  for (const workspace of workspaces.values()) dependencies[workspace.name] = workspace.version
@@ -46,36 +38,26 @@ export function aggregatorOf(root, workspaces) {
46
38
  return { name: AGGREGATOR, dir: '.', version: '1.0.0', manifest: cleanDependencies(manifest), aggregator: true }
47
39
  }
48
40
 
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.
41
+ // The resolutions as resolution-map.js reads them. One to neither a range
42
+ // nor another source, which yarn passes over, the lockfile reader refuses.
53
43
  export function rulesOf(root) {
54
- const byName = new Map()
55
- for (const [path, range] of Object.entries(root.resolutions ?? {})) {
44
+ const rules = Object.entries(root.resolutions ?? {}).map(([path, range]) => {
56
45
  const names = path.match(/(?:@[^/]+\/)?[^/]+/gu) ?? [path]
57
46
  const name = names.at(-1)
58
47
  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()
48
+ return { path, name, glob: names.length === 1 ? `**/${path}` : path, pattern: `${name}@${range}` }
49
+ })
50
+ return [...Map.groupBy(rules, ({ name }) => name).values()].flat()
64
51
  }
65
52
 
66
- // The top-level requests, as yarn makes them and in its order.
53
+ // The top-level requests in yarn's order; `asked`, all but the resolutions'.
67
54
  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
- }
55
+ const asked = []
56
+ const push = (deps, optional, dev = false) => {
57
+ for (const [name, range] of Object.entries(deps ?? {})) asked.push({ pattern: `${name}@${range}`, optional, dev })
76
58
  }
77
59
  push(root.dependencies, false)
78
- push(root.devDependencies, false)
60
+ push(root.devDependencies, false, true)
79
61
  push(root.optionalDependencies, true)
80
62
  if (workspaces.size > 0) {
81
63
  push({ [AGGREGATOR]: '1.0.0' }, false)
@@ -86,5 +68,5 @@ export function topRequests(root, workspaces, rules) {
86
68
  }
87
69
  push(implicit, false)
88
70
  }
89
- return { requests, patterns }
71
+ return { requests: [...rules.map((rule) => ({ pattern: rule.pattern, optional: false })), ...asked], asked }
90
72
  }
@@ -1,59 +1,25 @@
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.
1
+ // yarn 1's resolver (package-resolver.js, package-request.js) on a frozen
2
+ // lockfile. Which request makes a reference, and so whose names its requests
3
+ // carry, turns on yarn's order: top-level requests run one after another.
30
4
 
31
5
  import { satisfies, validRange } from '@preventive/upstream/semver.js'
32
6
  import { DeptreeError, quote } from '../error.js'
33
- import { matchesGlob } from './glob.js'
7
+ import { matchesGlob } from '../glob.js'
34
8
 
35
- // The turns of the microtask queue a request takes before its check, by
36
- // its resolver.
9
+ // Beneath a top-level request, all run at once, each taking these microtask
10
+ // turns, by its resolver, before it checks for a package of its version.
37
11
  const TURNS = { registry: 5, workspace: 3 }
38
12
 
39
13
  // yarn's normalizePattern.
40
14
  export function splitPattern(pattern) {
41
15
  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 }
16
+ const [name, ...parts] = (scoped ? pattern.slice(1) : pattern).split('@')
17
+ const version = parts.join('@')
18
+ return { name: scoped ? `@${name}` : name, range: parts.length === 0 ? 'latest' : version || '*', hasVersion: version !== '' }
49
19
  }
50
20
 
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.
21
+ // yarn's normalizeRange: any range but a semver range or one with a `:`,
22
+ // such as an `npm:` alias, is a tag.
57
23
  const TAG = /^[\w~-][\w.~-]*$/u
58
24
  function kindOf(range, where) {
59
25
  if (validRange(range)) return 'range'
@@ -62,24 +28,16 @@ function kindOf(range, where) {
62
28
  throw new DeptreeError('only a semver range, an npm: alias or a tag is supported', where)
63
29
  }
64
30
 
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.
31
+ // What a package asks for, in yarn's order. A lockfile entry's are patterns;
32
+ // one the lockfile reader links to a workspace has lost its range.
71
33
  function asked(info, where) {
72
34
  const workspace = info.kind === 'workspace'
73
35
  const lists = workspace ? info.workspace.manifest : info.entry
74
36
  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
37
+ return kinds.flatMap(([kind, optional, dev]) => Object.entries(lists[kind] ?? {}).map(([name, value]) => {
38
+ if (!workspace && value.startsWith('link:')) throw new DeptreeError(`its dependency on ${quote(name)} is a workspace, which is not supported`, where)
39
+ return { pattern: workspace ? `${name}@${value}` : value, optional, dev }
40
+ }))
83
41
  }
84
42
 
85
43
  // Where yarn's cache keeps a package (generateModuleCachePath), which is
@@ -92,7 +50,6 @@ function locOf({ kind, name, version, entry }) {
92
50
  return `npm\n${name}\n${version}\n${uid !== undefined && uid !== version ? uid : sha1 ?? ''}\n${integrity ? 'integrity' : ''}`
93
51
  }
94
52
 
95
- // The requests yarn resolves, and what they make of the lockfile.
96
53
  class Resolver {
97
54
  constructor({ lockfile, workspaces, rules, isDirectory }) {
98
55
  Object.assign(this, { lockfile, workspaces, rules, isDirectory })
@@ -102,7 +59,6 @@ class Resolver {
102
59
  this.diverted = []
103
60
  }
104
61
 
105
- // A pattern named for a reference.
106
62
  addPattern(pattern, ref) {
107
63
  ref.patterns.push(pattern)
108
64
  this.patterns.set(pattern, ref)
@@ -111,23 +67,13 @@ class Resolver {
111
67
  if (!list.includes(pattern)) list.push(pattern)
112
68
  }
113
69
 
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.
70
+ // isLockfileEntryOutdated: yarn resolves anew an entry out of its pattern's
71
+ // range, which --frozen-lockfile fails on only at the top level.
126
72
  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
73
  const { name, range, hasVersion } = splitPattern(request.pattern)
74
+ const workspace = this.workspaces.get(name)
75
+ if (workspace !== undefined && satisfies(workspace.version, range, { loose: true })) return { kind: 'workspace', name: workspace.name, version: workspace.version, workspace }
76
+ const where = quote(request.pattern)
131
77
  const tag = kindOf(range, where) === 'tag'
132
78
  const entry = this.lockfile.packages[request.pattern]
133
79
  if (entry === undefined) throw new DeptreeError('yarn would resolve this pattern anew: the lockfile has no entry for it', where)
@@ -137,8 +83,7 @@ class Resolver {
137
83
  return { kind: 'registry', name, version: entry.version, entry, tag }
138
84
  }
139
85
 
140
- // The resolution that applies to a request, by its path; undefined
141
- // where none does, or for a top-level request.
86
+ // No resolution applies to a top-level request.
142
87
  ruleOf({ pattern, parentNames }) {
143
88
  if (parentNames === undefined) return undefined
144
89
  const { name } = splitPattern(pattern)
@@ -147,19 +92,16 @@ class Resolver {
147
92
  }
148
93
 
149
94
  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
95
+ return this.byName.get(name)?.map((pattern) => this.patterns.get(pattern)).find((ref) => ref.version === version)
155
96
  }
156
97
 
157
- // A request's check: given the package of its name and version, or made
158
- // the reference, its own requests handed back.
98
+ // Waits where a package of its name and version is resolved already; else
99
+ // makes the reference and hands back its own requests. A tag or an alias
100
+ // never finds one, so each request of one makes a reference of its own,
101
+ // the last of which its pattern names.
159
102
  check(request, info) {
160
103
  const { name, range } = splitPattern(request.pattern)
161
- const solved = validRange(range) ? info.version : range
162
- if (this.exactMatch(name, solved) !== undefined) {
104
+ if (this.exactMatch(name, validRange(range) ? info.version : range) !== undefined) {
163
105
  this.delayed.push(request)
164
106
  return []
165
107
  }
@@ -172,29 +114,22 @@ class Resolver {
172
114
  workspace: info.workspace,
173
115
  patterns: [],
174
116
  requests: [request],
175
- dependencies: [],
117
+ asked: asked(info, quote(request.pattern)),
176
118
  optional: request.optional,
177
119
  }
178
120
  this.addPattern(request.pattern, ref)
179
121
  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
122
+ return ref.asked.map((dep) => ({ pattern: dep.pattern, parentNames, optional: dep.optional || (!dep.dev && request.optional) }))
186
123
  }
187
124
 
188
- // A request a resolution applies to, given the resolution's package.
189
125
  divert(request, rule) {
190
126
  const target = this.patterns.get(rule.pattern)
191
127
  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
128
  this.addPattern(request.pattern, target)
193
129
  }
194
130
 
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.
131
+ // Given the resolution's package where one applies, or else timed for its
132
+ // check; a tag's request waits, never counting down, for answer().
198
133
  start(request) {
199
134
  const rule = this.ruleOf(request)
200
135
  if (rule !== undefined) {
@@ -206,8 +141,6 @@ class Resolver {
206
141
  return { request, info, left: info.tag ? Infinity : TURNS[info.kind] }
207
142
  }
208
143
 
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
144
  answer(waiting) {
212
145
  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
146
  const [strand] = waiting
@@ -220,8 +153,7 @@ class Resolver {
220
153
  return [strand]
221
154
  }
222
155
 
223
- // A turn of the microtask queue: each request whose turn it is checked,
224
- // the requests it makes started where it stood.
156
+ // A microtask turn: the requests a check makes start where it stood.
225
157
  turn(strands) {
226
158
  const next = []
227
159
  for (const strand of strands) {
@@ -231,7 +163,6 @@ class Resolver {
231
163
  return next
232
164
  }
233
165
 
234
- // A top-level request, and all it leads to.
235
166
  run(request) {
236
167
  let strands = [this.start(request)].filter(Boolean)
237
168
  while (strands.length > 0) {
@@ -240,8 +171,7 @@ class Resolver {
240
171
  }
241
172
  }
242
173
 
243
- // resolveToExistingVersion: each waiting request, in turn, added to the
244
- // package of its version; then each a resolution applies to that waited.
174
+ // yarn's resolveToExistingVersion for the delayed, then the diverted.
245
175
  settle() {
246
176
  for (const request of this.delayed) {
247
177
  const { name } = splitPattern(request.pattern)
@@ -254,16 +184,9 @@ class Resolver {
254
184
  }
255
185
  }
256
186
 
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
187
  export function resolve({ top, ...options }) {
264
188
  const resolver = new Resolver(options)
265
189
  for (const request of top) resolver.run(request)
266
190
  resolver.settle()
267
- const { patterns, byName } = resolver
268
- return { patterns, byName }
191
+ return { patterns: resolver.patterns, byName: resolver.byName }
269
192
  }
@@ -1,31 +1,14 @@
1
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.
2
+ // install, the .yarnrc's options over the .npmrc's. ignore-platform is
3
+ // followed only as a flag, as yarn reads the option and does not act on it.
4
+ // Options that change the tree are refused; the rest are for where and how
5
+ // yarn fetches, and the tree is held to the lockfile's integrities. A `--`
6
+ // line of .yarnrc is a flag yarn adds to its command line.
23
7
 
24
8
  import { DeptreeError, quote } from '../error.js'
25
- import { parseNpmrc } from '../pnpm/npmrc.js'
9
+ import { parseNpmrc } from '../npmrc.js'
26
10
 
27
- // Flags passed over, by name: of those yarn 1.22 takes, the ones that do
28
- // not change the tree.
11
+ // yarn 1.22's flags that do not change the tree.
29
12
  const PASSED = new Set([
30
13
  'verbose', 'silent', 'json', 'har', 'emoji', 'no-emoji', 'progress', 'no-progress', 'non-interactive', 'no-node-version-check',
31
14
  'offline', 'prefer-offline', 'registry', 'proxy', 'https-proxy', 'network-concurrency', 'network-timeout', 'otp', 'mutex',
@@ -33,39 +16,31 @@ const PASSED = new Set([
33
16
  'check-files', 'pure-lockfile', 'frozen-lockfile', 'audit', 'disable-pnp',
34
17
  ])
35
18
 
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.
19
+ // Of the options yarn 1.22 reads by config.getOption, those that change the
20
+ // tree, and yarn-path, which runs another yarn. global-folder may be the
21
+ // project's directory, where yarn reads no package.json with validate(),
22
+ // which drops a name listed twice from all but one of its lists.
41
23
  const REFUSED = new Set([
42
24
  'ignore-optional', 'production', 'bin-links', 'workspaces-experimental', 'workspaces-nohoist-experimental', 'plugnplay-override',
43
25
  'yarn-link-file-dependencies', 'enable-meta-folder', 'experimental-pack-script-packages-in-mirror', 'global-folder', 'yarn-path',
44
26
  'yarnPath',
45
27
  ])
46
28
 
47
- // Settings followed, by name.
48
29
  const FOLLOWED = new Set(['ignore-engines', 'ignore-platform'])
49
30
 
50
- // A flag's command, `*` for every one, and its name; undefined for an
51
- // option.
52
31
  function flagOf(key) {
53
32
  const match = /^--(?:(.*?)\.)?(.*)$/u.exec(key)
54
33
  return match === null ? undefined : { command: match[1] ?? '*', name: match[2] }
55
34
  }
56
35
 
57
- // A setting, flag or option, that is not followed: refused where it may
58
- // change the tree.
59
36
  function check(key, where) {
60
37
  const flag = flagOf(key)
61
38
  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
39
  }
63
40
 
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.
41
+ // .yarnrc as yarn's parser reads it, as far as a key and a value per line
42
+ // go, each bare or quoted as JSON writes it. The last line of a key wins; a
43
+ // bare value but true or false, or none, is undefined.
69
44
  const TOKEN = /"(?:[^"\\]|\\.)*"|[^\s"]+/gu
70
45
 
71
46
  function unquote(token, what, where) {
@@ -88,14 +63,11 @@ function readYarnrc(text) {
88
63
  const tokens = line.match(TOKEN) ?? []
89
64
  if (tokens.join(' ') !== line.replace(/\s+/gu, ' ') || tokens.length > 2) throw new DeptreeError('expected a setting and its value', where)
90
65
  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 })
66
+ settings.set(key, { value: tokens[1]?.startsWith('"') === false ? BARE.get(value) : value, where })
93
67
  }
94
68
  return settings
95
69
  }
96
70
 
97
- // What the install follows of the .yarnrc and the .npmrc, either of them
98
- // left out where there is none: { ignoreEngines, ignorePlatform }.
99
71
  export function readSettings({ yarnrc, npmrc }) {
100
72
  const flags = new Set()
101
73
  let option