@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,56 +1,17 @@
1
- // The settings a pnpm 10 install reads from the .npmrc beside the lockfile,
2
- // from pnpm-workspace.yaml, and from the root package.json's `pnpm` field,
3
- // each over the one before: `pnpm install` spreads what the package.json
4
- // sets over the config it read the others into, so there the package.json
5
- // wins, whatever pnpm's config alone would say.
6
- // In pnpm-workspace.yaml and the package.json, every key is one of three
7
- // things (readers.js): a setting read here, and held to the values this
8
- // package builds a tree for; a setting that leaves the tree as it is,
9
- // whether because a frozen lockfile already says what it would have
10
- // changed, because it is about the network, the store, a cache, a script
11
- // or a bin — no script is ever run, whatever a setting allows — or because
12
- // it is a credential; or anything else, which is refused by name, as is a
13
- // value read here that this package does not build for.
14
- //
15
- // An .npmrc is read as pnpm reads one: by the kebab-case names of its
16
- // settings alone, and of those only the ones it has types for, which are
17
- // npm's and its own. Every one of those that can change the tree is read
18
- // here as above; anything else in the file — npm's settings pnpm has no
19
- // use for, publishing's, credentials, any other spelling — pnpm passes
20
- // over for an install, and so does this. A value pnpm would take from the
21
- // environment is not known here: pnpm drops the whole file where one such
22
- // variable is unset, so one in a line passed over is taken only where the
23
- // file sets nothing that dropping it would change.
24
- //
25
- // Only these files are read. Settings from anywhere else pnpm looks — a
26
- // user or global .npmrc, `npm_config_*` in the environment, the command
27
- // line — are not seen, and a tree built here is the one those leave at
28
- // their defaults. Of the package.json, pnpm 10 reads only the keys of
29
- // `pnpm` below (MANIFEST_KEYS) and Yarn's `resolutions`, and so does this.
30
- //
31
- // pnpm 11 reads its settings from pnpm-workspace.yaml alone: an .npmrc
32
- // for credentials and registries, and the package.json for none but the
33
- // Node its engines.runtime pins, runtimeNodeVersion, which it takes where
34
- // nodeVersion is not set. Of the
35
- // yaml it passes over a key not in camelCase, and one about the machine,
36
- // the run or a login; it has settings pnpm 10 has not (READ_11, IGNORED_11),
37
- // and reads linkWorkspacePackages for a frozen install too.
38
- //
39
- // pnpm 12 reads them as pnpm 11 does, and has settings of its own (READ_12,
40
- // IGNORED_12); where the root package.json pins the pnpm that runs, it
41
- // fails on a key of pnpm-workspace.yaml with a value it does not know,
42
- // pnpm 11's that it has not among them (UNRECOGNIZED_12), which it drops
43
- // otherwise.
1
+ // The settings an install reads. pnpm 10 reads the .npmrc beside the
2
+ // lockfile, pnpm-workspace.yaml and the root package.json's `pnpm` field,
3
+ // each over the one before; pnpm 9 reads only `packages` and the catalogs of
4
+ // pnpm-workspace.yaml, and pnpm 11 and 12 read pnpm-workspace.yaml alone.
5
+ // Settings from anywhere else (a user or global .npmrc, `npm_config_*`, the
6
+ // command line) are taken to be at their defaults.
44
7
 
45
8
  import { valid, validRange } from '@preventive/upstream/semver.js'
46
9
  import { DeptreeError, quote } from '../error.js'
47
- import { parseNpmrc } from './npmrc.js'
10
+ import { parseNpmrc } from '../npmrc.js'
48
11
  import { replaceReferences } from './overrides.js'
49
- import { IGNORED, MANIFEST_KEYS, READ, checkRegistry, known12, readerOf, readers, unrecognized12 } from './readers.js'
12
+ import { MANIFEST_KEYS, MANIFEST_KEYS_9, READ, checkRegistry, known12, npmrcReader, readerOf, readers, unrecognized12 } from './readers.js'
50
13
 
51
- // An .npmrc value read only where it can mean one thing: not quoted, not
52
- // escaped, with no `;` or `#` that ini would cut it at. Neither file's
53
- // value is read where pnpm would fill it in from the environment.
14
+ // An .npmrc value can mean one thing only with no quote, escape, `;` or `#`.
54
15
  const PLAIN = /^[^"'`;#\\]*$/u
55
16
  function plain(value, where) {
56
17
  if (!PLAIN.test(value)) throw new DeptreeError(`${quote(value)} is quoted, escaped or commented, which is not read here`, where)
@@ -68,9 +29,8 @@ function noEnvironment(value, where) {
68
29
  const KEBAB = /^[a-z][\da-z]*(?:-[\da-z]+)*$/u
69
30
  const camelCase = (key) => key.replace(/-+([a-z\d])/gu, (_, char) => char.toUpperCase())
70
31
 
71
- // pnpm 11 reads an .npmrc for credentials and registries alone: each
72
- // registry has to be the public one, but one of a project's .npmrc that
73
- // names a variable is passed over.
32
+ // pnpm 11 reads an .npmrc for credentials and registries alone; a registry
33
+ // that names a variable is passed over.
74
34
  function checkNpmrcRegistries(text) {
75
35
  for (const { key, value, line } of parseNpmrc(text)) {
76
36
  if ((key !== 'registry' && !/^@[^:]+:registry$/u.test(key)) || fromEnvironment(value)) continue
@@ -79,10 +39,11 @@ function checkNpmrcRegistries(text) {
79
39
  }
80
40
  }
81
41
 
82
- // An .npmrc's settings by name, each written once, or once with `[]` each
83
- // time, and whether any line takes something from the environment. A
84
- // registry for a scope has to be the public one.
85
- function fromNpmrc(text) {
42
+ // The registry's token as a project's .npmrc commonly gives it is taken to
43
+ // be set, as @preventive/upstream reads it too: pnpm reads the file then.
44
+ const isNpmToken = (key, value) => key === '//registry.npmjs.org/:_authToken' && value === '${NPM_TOKEN}'
45
+
46
+ function fromNpmrc(text, major) {
86
47
  const settings = new Map()
87
48
  let environment = false
88
49
  for (const { key, value, list, line } of parseNpmrc(text)) {
@@ -92,46 +53,43 @@ function fromNpmrc(text) {
92
53
  continue
93
54
  }
94
55
  const name = KEBAB.test(key) ? camelCase(key) : undefined
95
- if (!(name in READ) || READ[name].rc === false || IGNORED.has(name)) {
96
- environment ||= fromEnvironment(key) || fromEnvironment(value)
56
+ const read = name === undefined ? undefined : npmrcReader(name, major)
57
+ if (read === undefined) {
58
+ if (!isNpmToken(key, value)) environment ||= fromEnvironment(key) || fromEnvironment(value)
97
59
  continue
98
60
  }
99
61
  noEnvironment(value, where)
100
62
  const earlier = settings.get(name)
101
63
  if (earlier !== undefined && !(list && earlier.list)) throw new DeptreeError('set more than once', where)
102
- if (list && READ[name].kind !== 'texts') throw new DeptreeError('not a list', where)
64
+ if (list && read.kind !== 'texts') throw new DeptreeError('not a list', where)
103
65
  const next = list ? [...(earlier?.value ?? []), plain(value, where)] : plain(value, where)
104
- settings.set(name, { value: next, list, where, read: READ[name] })
66
+ settings.set(name, { value: next, list, where, read })
105
67
  }
106
68
  return { settings, environment }
107
69
  }
108
70
 
109
- // The root package.json's settings: the keys of `pnpm` pnpm reads, and
110
- // overrides of `resolutions` and `pnpm.overrides` both, the second over the
111
- // first.
112
- function fromManifest(manifest) {
71
+ // pnpm 10 takes Yarn's `resolutions` as overrides, under `pnpm.overrides`.
72
+ function fromManifest(manifest, major) {
113
73
  const pnpm = manifest.pnpm === undefined ? {} : readers.mapping(manifest.pnpm, 'package.json: pnpm')
114
74
  const settings = new Map()
115
- for (const name of MANIFEST_KEYS) {
75
+ for (const name of major < 10 ? MANIFEST_KEYS_9 : MANIFEST_KEYS) {
116
76
  if (!Object.hasOwn(pnpm, name) || name === 'overrides') continue
117
77
  const where = `package.json: pnpm.${name}`
118
78
  noEnvironment(pnpm[name], where)
119
- const read = readerOf(name, where, 10)
79
+ const read = readerOf(name, where, major)
120
80
  if (read !== undefined) settings.set(name, { value: pnpm[name], where, read })
121
81
  }
122
82
  const { resolutions } = manifest
123
83
  if (resolutions !== undefined || Object.hasOwn(pnpm, 'overrides')) {
124
- const where = 'package.json: resolutions and pnpm.overrides'
125
84
  const value = { ...(resolutions === undefined ? {} : readers.mapping(resolutions, 'package.json: resolutions')), ...(Object.hasOwn(pnpm, 'overrides') ? readers.mapping(pnpm.overrides, 'package.json: pnpm.overrides') : {}) }
126
- settings.set('overrides', { value, where, read: READ.overrides })
85
+ settings.set('overrides', { value, where: 'package.json: resolutions and pnpm.overrides', read: READ.overrides })
127
86
  }
128
87
  return settings
129
88
  }
130
89
 
131
- // pnpm 11 passes over a key not in camelCase.
132
90
  const CAMEL = /^[a-z][\dA-Za-z]*$/u
133
91
 
134
- // pnpm 12 passes over a key with no value. `pinned` is readerOf's.
92
+ // pnpm 12 passes over a key with no value.
135
93
  function fromWorkspace(workspace, major, pinned) {
136
94
  if (workspace === null || typeof workspace !== 'object' || Array.isArray(workspace)) throw new DeptreeError('expected a mapping', 'pnpm-workspace.yaml')
137
95
  const settings = new Map()
@@ -149,14 +107,21 @@ function fromWorkspace(workspace, major, pinned) {
149
107
  return settings
150
108
  }
151
109
 
152
- // The settings as pnpm 10 derives what it installs by: `hoist: false`
153
- // drops the private pattern, `shamefullyHoist` sets or drops the public
154
- // one, and an empty public pattern is none. A pattern left undefined is
155
- // not hoisted to at all. virtualStoreDirMaxLength is 60 by default on
156
- // Windows alone, which is refused (tree.js's checkHost).
157
- function derive(get) {
110
+ // pnpm 9 passes over the rest of pnpm-workspace.yaml unread, a catalog of null
111
+ // among it.
112
+ function fromWorkspace9(workspace) {
113
+ readers.mapping(workspace, 'pnpm-workspace.yaml')
114
+ const names = ['packages', 'catalog', 'catalogs'].filter((name) => workspace[name] != null)
115
+ return new Map(names.map((name) => [name, { value: workspace[name], where: `pnpm-workspace.yaml: ${name}`, read: READ[name] }]))
116
+ }
117
+
118
+ const PUBLIC_9 = ['*eslint*', '*prettier*']
119
+
120
+ // A hoist pattern left undefined is not hoisted to at all. Only on Windows,
121
+ // which checkHost refuses, is virtualStoreDirMaxLength 60 by default.
122
+ function derive(get, major) {
158
123
  const shamefullyHoist = get('shamefullyHoist')
159
- let publicHoistPattern = get('publicHoistPattern') ?? []
124
+ let publicHoistPattern = get('publicHoistPattern') ?? (major < 10 ? PUBLIC_9 : [])
160
125
  if (shamefullyHoist === true) publicHoistPattern = ['*']
161
126
  else if (shamefullyHoist === false || (publicHoistPattern.length === 1 && publicHoistPattern[0] === '')) publicHoistPattern = undefined
162
127
  return {
@@ -181,11 +146,17 @@ function derive(get) {
181
146
  pmOnFail: get('pmOnFail'),
182
147
  runtimeOnFail: get('runtimeOnFail'),
183
148
  packageImportMethod: get('packageImportMethod') ?? 'auto',
149
+ nodeLinker: get('nodeLinker') ?? 'isolated',
150
+ ...major < 10 ? {
151
+ packageManagerChecks: {
152
+ manage: get('managePackageManagerVersions') ?? false,
153
+ strict: get('packageManagerStrict') ?? true,
154
+ strictVersion: get('packageManagerStrictVersion') ?? false,
155
+ },
156
+ } : {},
184
157
  }
185
158
  }
186
159
 
187
- // The catalogs by name, `catalog` being `default`, as pnpm has them, which
188
- // refuses the default one written both ways.
189
160
  function catalogsOf(catalog, catalogs = {}) {
190
161
  if (catalog !== undefined && Object.hasOwn(catalogs, 'default')) {
191
162
  throw new DeptreeError('the default catalog is defined twice, as catalog and as catalogs.default', 'pnpm-workspace.yaml: catalog')
@@ -193,8 +164,7 @@ function catalogsOf(catalog, catalogs = {}) {
193
164
  return Object.assign(Object.create(null), catalog === undefined ? {} : { default: catalog }, catalogs)
194
165
  }
195
166
 
196
- // Each layer over the one before, as `derive` has them.
197
- function settle(layers, manifest) {
167
+ function settle(layers, manifest, major) {
198
168
  const values = new Map()
199
169
  for (const layer of layers) {
200
170
  for (const [name, { value, where, read: { kind, check } }] of layer) {
@@ -207,39 +177,33 @@ function settle(layers, manifest) {
207
177
  values.set(name, read)
208
178
  }
209
179
  }
210
- return derive((name) => values.get(name))
180
+ return derive((name) => values.get(name), major)
211
181
  }
212
182
 
213
- // `workspace` is pnpm-workspace.yaml as parsed and `npmrc` the text of the
214
- // .npmrc, either of which may be undefined; `manifest` the root
215
- // package.json as parsed; `pinned` whether it pins the pnpm that runs,
216
- // which pnpm 12 holds pnpm-workspace.yaml's keys to. Overrides that name nothing are none, and leave
217
- // those below them.
183
+ // Overrides that name nothing are none, and leave those below them.
218
184
  export function readSettings({ workspace, npmrc, manifest, major = 10, pinned = false }) {
219
- const fromYaml = () => (workspace === undefined ? new Map() : fromWorkspace(workspace, major, pinned))
220
- // pnpm 11 reads its settings from pnpm-workspace.yaml alone, and none
221
- // from the package.json, its `resolutions` none.
185
+ const fromYaml = () => {
186
+ if (workspace === undefined) return new Map()
187
+ return major < 10 ? fromWorkspace9(workspace) : fromWorkspace(workspace, major, pinned)
188
+ }
222
189
  if (major >= 11) {
223
190
  if (npmrc !== undefined) checkNpmrcRegistries(npmrc)
224
- const settings = settle([fromYaml()], manifest)
191
+ const settings = settle([fromYaml()], manifest, major)
225
192
  settings.runtimeNodeVersion = runtimeNode(manifest, settings.runtimeOnFail)
226
193
  return settings
227
194
  }
228
- const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc)
229
- const rest = [fromYaml(), fromManifest(manifest)]
230
- const settings = settle([rc.settings, ...rest], manifest)
231
- if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest))) {
195
+ const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc, major)
196
+ const rest = [fromYaml(), fromManifest(manifest, major)]
197
+ const settings = settle([rc.settings, ...rest], manifest, major)
198
+ if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest, major))) {
232
199
  throw new DeptreeError('a line takes a value from the environment, which pnpm drops the whole file for where it is unset, and the file sets what would change the tree', '.npmrc')
233
200
  }
234
201
  return settings
235
202
  }
236
203
 
237
- // The Node the root package.json's devEngines.runtime or engines.runtime
238
- // pins, which pnpm 11 takes for nodeVersion where none is set, and so does
239
- // pnpm 12 but for a patched package's engines (install.js): the first
240
- // that names a range for Node decides, and gives its version where that is
241
- // exact. One to download, which gives the range's lowest, is refused;
242
- // runtimeOnFail stands for each one's onFail.
204
+ // The Node the root's runtime pins, for nodeVersion where none is set: the
205
+ // first naming a range for Node decides, with its version where exact. One
206
+ // to download, which gives the range's lowest, is refused.
243
207
  function runtimeNode(manifest, onFail) {
244
208
  for (const field of ['devEngines', 'engines']) {
245
209
  const runtime = manifest[field]?.runtime