@preventive/deptree 1.0.0-alpha.1 → 1.0.0-alpha.10

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 (89) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/bin/compare.js +132 -0
  3. package/bin/deptree.js +211 -0
  4. package/bin/npmrc.js +21 -0
  5. package/cargo.d.ts +223 -0
  6. package/cargo.js +6 -0
  7. package/npm.d.ts +321 -0
  8. package/npm.js +7 -0
  9. package/package.json +92 -11
  10. package/pnpm.d.ts +401 -81
  11. package/pnpm.js +4 -9
  12. package/soldeer.d.ts +235 -0
  13. package/soldeer.js +6 -0
  14. package/src/cargo/crate.js +183 -0
  15. package/src/cargo/inputs.js +81 -0
  16. package/src/cargo/members.js +90 -0
  17. package/src/cargo/registry.js +65 -0
  18. package/src/cargo/tree.js +125 -0
  19. package/src/cargo/workspace.js +177 -0
  20. package/src/concurrent.js +32 -0
  21. package/src/error.js +8 -10
  22. package/src/glob.js +55 -0
  23. package/src/hash.js +51 -16
  24. package/src/manifest.js +52 -0
  25. package/src/matcher.js +60 -10
  26. package/src/mount.js +124 -42
  27. package/src/npm/bins.js +54 -0
  28. package/src/npm/compat.js +97 -0
  29. package/src/npm/dev-engines.js +52 -0
  30. package/src/npm/graph.js +68 -0
  31. package/src/npm/inputs.js +75 -0
  32. package/src/npm/manifests.js +130 -0
  33. package/src/npm/package.js +57 -0
  34. package/src/npm/ratio.js +34 -0
  35. package/src/npm/settings.js +67 -0
  36. package/src/npm/tree.js +139 -0
  37. package/src/npm/versions.js +20 -0
  38. package/src/npmrc.js +24 -0
  39. package/src/patch.js +26 -45
  40. package/src/pnpm/bins.js +202 -322
  41. package/src/pnpm/checks.js +8 -35
  42. package/src/pnpm/commands.js +230 -0
  43. package/src/pnpm/filename.js +19 -16
  44. package/src/pnpm/frozen.js +29 -73
  45. package/src/pnpm/gitignore.js +138 -0
  46. package/src/pnpm/glob.js +65 -0
  47. package/src/pnpm/graph.js +26 -34
  48. package/src/pnpm/hoist.js +96 -59
  49. package/src/pnpm/hoisted.js +234 -0
  50. package/src/pnpm/hook.js +26 -31
  51. package/src/pnpm/inputs.js +177 -0
  52. package/src/pnpm/install.js +123 -124
  53. package/src/pnpm/local.js +95 -40
  54. package/src/pnpm/minimatch.js +319 -0
  55. package/src/pnpm/nm-hoist-graph.js +299 -0
  56. package/src/pnpm/nm-hoist.js +149 -0
  57. package/src/pnpm/npm-packlist.js +217 -0
  58. package/src/pnpm/overrides.js +11 -51
  59. package/src/pnpm/package.js +123 -0
  60. package/src/pnpm/packlist.js +176 -81
  61. package/src/pnpm/patches.js +18 -25
  62. package/src/pnpm/projects.js +132 -89
  63. package/src/pnpm/readers.js +122 -77
  64. package/src/pnpm/settings.js +74 -95
  65. package/src/pnpm/tree.js +216 -237
  66. package/src/pnpm/uptodate.js +16 -28
  67. package/src/pnpm/workspace.js +152 -126
  68. package/src/project.js +56 -0
  69. package/src/soldeer/config.js +63 -0
  70. package/src/soldeer/git.js +52 -0
  71. package/src/soldeer/inputs.js +30 -0
  72. package/src/soldeer/tree.js +83 -0
  73. package/src/soldeer/zip.js +121 -0
  74. package/src/tarball.js +123 -131
  75. package/src/yarn1/bins.js +28 -0
  76. package/src/yarn1/compat.js +67 -0
  77. package/src/yarn1/hoist.js +249 -0
  78. package/src/yarn1/inputs.js +83 -0
  79. package/src/yarn1/manifest.js +64 -0
  80. package/src/yarn1/package.js +206 -0
  81. package/src/yarn1/peers.js +51 -0
  82. package/src/yarn1/requests.js +74 -0
  83. package/src/yarn1/resolve.js +289 -0
  84. package/src/yarn1/settings.js +95 -0
  85. package/src/yarn1/tree.js +219 -0
  86. package/yarn1.d.ts +368 -0
  87. package/yarn1.js +7 -0
  88. package/src/pnpm/npmrc.js +0 -31
  89. /package/{LICENSE → LICENSE-MIT} +0 -0
@@ -1,49 +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, which it takes for nodeVersion. Of the
34
- // yaml it passes over a key not in camelCase, and one about the machine,
35
- // the run or a login; it has settings pnpm 10 has not (READ_11, IGNORED_11),
36
- // and reads linkWorkspacePackages for a frozen install too.
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.
37
7
 
38
8
  import { valid, validRange } from '@preventive/upstream/semver.js'
39
9
  import { DeptreeError, quote } from '../error.js'
40
- import { parseNpmrc } from './npmrc.js'
10
+ import { parseNpmrc } from '../npmrc.js'
41
11
  import { replaceReferences } from './overrides.js'
42
- import { IGNORED, MANIFEST_KEYS, READ, checkRegistry, readerOf, readers } from './readers.js'
12
+ import { MANIFEST_KEYS, MANIFEST_KEYS_9, READ, checkRegistry, known12, npmrcReader, readerOf, readers, unrecognized12 } from './readers.js'
43
13
 
44
- // An .npmrc value read only where it can mean one thing: not quoted, not
45
- // escaped, with no `;` or `#` that ini would cut it at. Neither file's
46
- // 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 `#`.
47
15
  const PLAIN = /^[^"'`;#\\]*$/u
48
16
  function plain(value, where) {
49
17
  if (!PLAIN.test(value)) throw new DeptreeError(`${quote(value)} is quoted, escaped or commented, which is not read here`, where)
@@ -61,9 +29,8 @@ function noEnvironment(value, where) {
61
29
  const KEBAB = /^[a-z][\da-z]*(?:-[\da-z]+)*$/u
62
30
  const camelCase = (key) => key.replace(/-+([a-z\d])/gu, (_, char) => char.toUpperCase())
63
31
 
64
- // pnpm 11 reads an .npmrc for credentials and registries alone: each
65
- // registry has to be the public one, but one of a project's .npmrc that
66
- // 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.
67
34
  function checkNpmrcRegistries(text) {
68
35
  for (const { key, value, line } of parseNpmrc(text)) {
69
36
  if ((key !== 'registry' && !/^@[^:]+:registry$/u.test(key)) || fromEnvironment(value)) continue
@@ -72,10 +39,11 @@ function checkNpmrcRegistries(text) {
72
39
  }
73
40
  }
74
41
 
75
- // An .npmrc's settings by name, each written once, or once with `[]` each
76
- // time, and whether any line takes something from the environment. A
77
- // registry for a scope has to be the public one.
78
- 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) {
79
47
  const settings = new Map()
80
48
  let environment = false
81
49
  for (const { key, value, list, line } of parseNpmrc(text)) {
@@ -85,67 +53,75 @@ function fromNpmrc(text) {
85
53
  continue
86
54
  }
87
55
  const name = KEBAB.test(key) ? camelCase(key) : undefined
88
- if (!(name in READ) || READ[name].rc === false || IGNORED.has(name)) {
89
- 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)
90
59
  continue
91
60
  }
92
61
  noEnvironment(value, where)
93
62
  const earlier = settings.get(name)
94
63
  if (earlier !== undefined && !(list && earlier.list)) throw new DeptreeError('set more than once', where)
95
- 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)
96
65
  const next = list ? [...(earlier?.value ?? []), plain(value, where)] : plain(value, where)
97
- settings.set(name, { value: next, list, where, read: READ[name] })
66
+ settings.set(name, { value: next, list, where, read })
98
67
  }
99
68
  return { settings, environment }
100
69
  }
101
70
 
102
- // The root package.json's settings: the keys of `pnpm` pnpm reads, and
103
- // overrides of `resolutions` and `pnpm.overrides` both, the second over the
104
- // first.
105
- function fromManifest(manifest) {
71
+ // pnpm 10 takes Yarn's `resolutions` as overrides, under `pnpm.overrides`.
72
+ function fromManifest(manifest, major) {
106
73
  const pnpm = manifest.pnpm === undefined ? {} : readers.mapping(manifest.pnpm, 'package.json: pnpm')
107
74
  const settings = new Map()
108
- for (const name of MANIFEST_KEYS) {
75
+ for (const name of major < 10 ? MANIFEST_KEYS_9 : MANIFEST_KEYS) {
109
76
  if (!Object.hasOwn(pnpm, name) || name === 'overrides') continue
110
77
  const where = `package.json: pnpm.${name}`
111
78
  noEnvironment(pnpm[name], where)
112
- const read = readerOf(name, where, 10)
79
+ const read = readerOf(name, where, major)
113
80
  if (read !== undefined) settings.set(name, { value: pnpm[name], where, read })
114
81
  }
115
82
  const { resolutions } = manifest
116
83
  if (resolutions !== undefined || Object.hasOwn(pnpm, 'overrides')) {
117
- const where = 'package.json: resolutions and pnpm.overrides'
118
84
  const value = { ...(resolutions === undefined ? {} : readers.mapping(resolutions, 'package.json: resolutions')), ...(Object.hasOwn(pnpm, 'overrides') ? readers.mapping(pnpm.overrides, 'package.json: pnpm.overrides') : {}) }
119
- settings.set('overrides', { value, where, read: READ.overrides })
85
+ settings.set('overrides', { value, where: 'package.json: resolutions and pnpm.overrides', read: READ.overrides })
120
86
  }
121
87
  return settings
122
88
  }
123
89
 
124
- // pnpm 11 passes over a key not in camelCase.
125
90
  const CAMEL = /^[a-z][\dA-Za-z]*$/u
126
91
 
127
- function fromWorkspace(workspace, major) {
92
+ // pnpm 12 passes over a key with no value.
93
+ function fromWorkspace(workspace, major, pinned) {
128
94
  if (workspace === null || typeof workspace !== 'object' || Array.isArray(workspace)) throw new DeptreeError('expected a mapping', 'pnpm-workspace.yaml')
129
95
  const settings = new Map()
130
96
  for (const [name, value] of Object.entries(workspace)) {
131
97
  const where = `pnpm-workspace.yaml: ${name}`
132
98
  noEnvironment(name, where)
133
99
  noEnvironment(value, where)
134
- if (major >= 11 && !CAMEL.test(name)) continue
135
- const read = readerOf(name, where, major)
100
+ if (major >= 11 && !CAMEL.test(name)) {
101
+ if (major >= 12 && pinned && value !== null && !known12(camelCase(name))) throw unrecognized12(where)
102
+ continue
103
+ }
104
+ const read = readerOf(name, where, major, pinned && value !== null)
136
105
  if (read !== undefined) settings.set(name, { value, where, read })
137
106
  }
138
107
  return settings
139
108
  }
140
109
 
141
- // The settings as pnpm 10 derives what it installs by: `hoist: false`
142
- // drops the private pattern, `shamefullyHoist` sets or drops the public
143
- // one, and an empty public pattern is none. A pattern left undefined is
144
- // not hoisted to at all. virtualStoreDirMaxLength is 60 by default on
145
- // Windows alone, which is refused (tree.js's checkHost).
146
- 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) {
147
123
  const shamefullyHoist = get('shamefullyHoist')
148
- let publicHoistPattern = get('publicHoistPattern') ?? []
124
+ let publicHoistPattern = get('publicHoistPattern') ?? (major < 10 ? PUBLIC_9 : [])
149
125
  if (shamefullyHoist === true) publicHoistPattern = ['*']
150
126
  else if (shamefullyHoist === false || (publicHoistPattern.length === 1 && publicHoistPattern[0] === '')) publicHoistPattern = undefined
151
127
  return {
@@ -155,6 +131,7 @@ function derive(get) {
155
131
  hoistWorkspacePackages: get('hoistWorkspacePackages') ?? true,
156
132
  engineStrict: get('engineStrict') ?? false,
157
133
  nodeVersion: get('nodeVersion'),
134
+ runtimeNodeVersion: undefined,
158
135
  supportedArchitectures: get('supportedArchitectures'),
159
136
  patchedDependencies: get('patchedDependencies'),
160
137
  overrides: get('overrides'),
@@ -168,11 +145,18 @@ function derive(get) {
168
145
  linkWorkspacePackages: get('linkWorkspacePackages') ?? false,
169
146
  pmOnFail: get('pmOnFail'),
170
147
  runtimeOnFail: get('runtimeOnFail'),
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
+ } : {},
171
157
  }
172
158
  }
173
159
 
174
- // The catalogs by name, `catalog` being `default`, as pnpm has them, which
175
- // refuses the default one written both ways.
176
160
  function catalogsOf(catalog, catalogs = {}) {
177
161
  if (catalog !== undefined && Object.hasOwn(catalogs, 'default')) {
178
162
  throw new DeptreeError('the default catalog is defined twice, as catalog and as catalogs.default', 'pnpm-workspace.yaml: catalog')
@@ -180,8 +164,7 @@ function catalogsOf(catalog, catalogs = {}) {
180
164
  return Object.assign(Object.create(null), catalog === undefined ? {} : { default: catalog }, catalogs)
181
165
  }
182
166
 
183
- // Each layer over the one before, as `derive` has them.
184
- function settle(layers, manifest) {
167
+ function settle(layers, manifest, major) {
185
168
  const values = new Map()
186
169
  for (const layer of layers) {
187
170
  for (const [name, { value, where, read: { kind, check } }] of layer) {
@@ -194,37 +177,33 @@ function settle(layers, manifest) {
194
177
  values.set(name, read)
195
178
  }
196
179
  }
197
- return derive((name) => values.get(name))
180
+ return derive((name) => values.get(name), major)
198
181
  }
199
182
 
200
- // `workspace` is pnpm-workspace.yaml as parsed and `npmrc` the text of the
201
- // .npmrc, either of which may be undefined; `manifest` the root
202
- // package.json as parsed. Overrides that name nothing are none, and leave
203
- // those below them.
204
- export function readSettings({ workspace, npmrc, manifest, major = 10 }) {
205
- const fromYaml = () => (workspace === undefined ? new Map() : fromWorkspace(workspace, major))
206
- // pnpm 11 reads its settings from pnpm-workspace.yaml alone, and none
207
- // from the package.json, its `resolutions` none.
183
+ // Overrides that name nothing are none, and leave those below them.
184
+ export function readSettings({ workspace, npmrc, manifest, major = 10, pinned = false }) {
185
+ const fromYaml = () => {
186
+ if (workspace === undefined) return new Map()
187
+ return major < 10 ? fromWorkspace9(workspace) : fromWorkspace(workspace, major, pinned)
188
+ }
208
189
  if (major >= 11) {
209
190
  if (npmrc !== undefined) checkNpmrcRegistries(npmrc)
210
- const settings = settle([fromYaml()], manifest)
211
- settings.nodeVersion ??= runtimeNode(manifest, settings.runtimeOnFail)
191
+ const settings = settle([fromYaml()], manifest, major)
192
+ settings.runtimeNodeVersion = runtimeNode(manifest, settings.runtimeOnFail)
212
193
  return settings
213
194
  }
214
- const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc)
215
- const rest = [fromYaml(), fromManifest(manifest)]
216
- const settings = settle([rc.settings, ...rest], manifest)
217
- 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))) {
218
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')
219
200
  }
220
201
  return settings
221
202
  }
222
203
 
223
- // The Node the root package.json's devEngines.runtime or engines.runtime
224
- // pins, which pnpm 11 takes for nodeVersion where none is set: the first
225
- // that names a range for Node decides, and gives its version where that is
226
- // exact. One to download, which gives the range's lowest, is refused;
227
- // 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.
228
207
  function runtimeNode(manifest, onFail) {
229
208
  for (const field of ['devEngines', 'engines']) {
230
209
  const runtime = manifest[field]?.runtime