@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.
- package/LICENSE-APACHE +202 -0
- package/npm.d.ts +288 -0
- package/npm.js +7 -0
- package/package.json +41 -12
- package/pnpm.d.ts +158 -25
- package/pnpm.js +2 -10
- package/soldeer.d.ts +13 -0
- package/soldeer.js +1 -7
- package/src/concurrent.js +16 -17
- package/src/error.js +5 -9
- package/src/glob.js +55 -0
- package/src/hash.js +60 -13
- package/src/manifest.js +52 -0
- package/src/matcher.js +60 -10
- package/src/mount.js +104 -44
- package/src/npm/bins.js +54 -0
- package/src/npm/compat.js +97 -0
- package/src/npm/dev-engines.js +52 -0
- package/src/npm/graph.js +68 -0
- package/src/npm/inputs.js +75 -0
- package/src/npm/manifests.js +130 -0
- package/src/npm/package.js +57 -0
- package/src/npm/ratio.js +34 -0
- package/src/npm/settings.js +67 -0
- package/src/npm/tree.js +136 -0
- package/src/npm/versions.js +20 -0
- package/src/npmrc.js +24 -0
- package/src/patch.js +22 -41
- package/src/pnpm/bins.js +152 -131
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +53 -96
- package/src/pnpm/filename.js +10 -21
- package/src/pnpm/frozen.js +29 -75
- package/src/pnpm/gitignore.js +139 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +15 -43
- package/src/pnpm/hoist.js +68 -61
- package/src/pnpm/hoisted.js +234 -0
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +73 -56
- package/src/pnpm/install.js +85 -131
- package/src/pnpm/local.js +21 -40
- package/src/pnpm/minimatch.js +319 -0
- package/src/pnpm/nm-hoist-graph.js +299 -0
- package/src/pnpm/nm-hoist.js +149 -0
- package/src/pnpm/npm-packlist.js +217 -0
- package/src/pnpm/overrides.js +11 -51
- package/src/pnpm/package.js +121 -0
- package/src/pnpm/packlist.js +169 -109
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +63 -107
- package/src/pnpm/readers.js +63 -83
- package/src/pnpm/settings.js +64 -100
- package/src/pnpm/tree.js +197 -169
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +124 -133
- package/src/project.js +57 -0
- package/src/soldeer/config.js +8 -24
- package/src/soldeer/inputs.js +5 -15
- package/src/soldeer/tree.js +22 -60
- package/src/soldeer/zip.js +17 -36
- package/src/tarball.js +55 -140
- package/src/yarn1/bins.js +9 -19
- package/src/yarn1/compat.js +9 -28
- package/src/yarn1/hoist.js +53 -68
- package/src/yarn1/inputs.js +19 -61
- package/src/yarn1/manifest.js +8 -23
- package/src/yarn1/package.js +24 -63
- package/src/yarn1/peers.js +8 -15
- package/src/yarn1/requests.js +19 -37
- package/src/yarn1/resolve.js +36 -113
- package/src/yarn1/settings.js +15 -43
- package/src/yarn1/tree.js +67 -91
- package/yarn1.d.ts +34 -5
- package/yarn1.js +1 -8
- package/src/pnpm/npmrc.js +0 -31
- package/src/pnpm/project.js +0 -97
- package/src/yarn1/glob.js +0 -52
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/src/pnpm/workspace.js
CHANGED
|
@@ -1,45 +1,25 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// bower_components. Without `packages`, or without pnpm-workspace.yaml,
|
|
7
|
-
// the root is the only project. pnpm finds them on disk: findProjects
|
|
8
|
-
// finds them so in the directories it is given, and checkWorkspace holds
|
|
9
|
-
// the lockfile's importers to them.
|
|
10
|
-
//
|
|
11
|
-
// A glob is read as tinyglobby reads it, normalized as a path first, as
|
|
12
|
-
// far as `*` and `**` go: `*` any run of characters in one directory's
|
|
13
|
-
// name, `**` a whole name for any number of directories, neither taking a
|
|
14
|
-
// name that starts with a dot, which only a glob that spells it takes; `!`
|
|
15
|
-
// in front leaves out what it takes, wherever it is in the list. Anything
|
|
16
|
-
// else a glob can say — `?`, a class, a brace, an extglob, an escape — is
|
|
17
|
-
// refused, and so is a glob reaching outside the workspace's directory.
|
|
18
|
-
// pnpm 11 leaves out what a `!` glob takes with micromatch too, a name
|
|
19
|
-
// starting with a dot and all.
|
|
20
|
-
//
|
|
21
|
-
// pnpm 12 finds them its own way (its projects walk, with wax), and the
|
|
22
|
-
// same but in four places: a `**` may take no name before one a glob
|
|
23
|
-
// spells with a leading dot; nothing under a node_modules or a
|
|
24
|
-
// bower_components is walked into or taken, wherever it is; where a glob
|
|
25
|
-
// with a `*` takes a directory, the first of its manifests that is there
|
|
26
|
-
// is read, which fails where it is not a file; and the projects come in
|
|
27
|
-
// the order of their paths by name.
|
|
1
|
+
// The directories pnpm takes for a workspace's projects: the root, and each
|
|
2
|
+
// whose package.json a glob of pnpm-workspace.yaml's `packages` takes, as
|
|
3
|
+
// @pnpm/fs.find-packages globs for them with tinyglobby (pnpm 9: fast-glob), or
|
|
4
|
+
// as pnpm 12 walks (wax). pnpm 11 matches `!` globs with micromatch, dotted
|
|
5
|
+
// names and all.
|
|
28
6
|
|
|
29
7
|
import { compareNames, normalize } from '@preventive/vfs/path.js'
|
|
30
8
|
import { DeptreeError, quote } from '../error.js'
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
9
|
+
import { reach, wildcard } from '../matcher.js'
|
|
10
|
+
import { UNSAFE, isInside } from '../mount.js'
|
|
11
|
+
import { typeOf } from '../project.js'
|
|
33
12
|
|
|
34
13
|
const UNSUPPORTED = /[?[\]{}()\\]/u
|
|
35
14
|
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
const
|
|
15
|
+
// `*` takes line terminators too, and a leading dot only with `dot`.
|
|
16
|
+
function compileName(name, dot) {
|
|
17
|
+
const matches = wildcard(name)
|
|
18
|
+
const undotted = name.startsWith('*') && !dot
|
|
19
|
+
return { test: (entry) => !(undotted && entry.startsWith('.')) && matches(entry) }
|
|
20
|
+
}
|
|
39
21
|
|
|
40
|
-
// A glob as
|
|
41
|
-
// does: each `**`, or the pattern of one name; `dot` whether `**` takes a
|
|
42
|
-
// name with a leading dot.
|
|
22
|
+
// A glob normalized as tinyglobby does, as `**` or a pattern per name.
|
|
43
23
|
function compile(glob, where, dot) {
|
|
44
24
|
const path = normalize(`./${glob}/package.json`)
|
|
45
25
|
if (path.startsWith('../')) throw new DeptreeError(`${quote(glob)} reaches outside the workspace's directory, which is not supported`, where)
|
|
@@ -47,40 +27,12 @@ function compile(glob, where, dot) {
|
|
|
47
27
|
if (glob === '' || glob.startsWith('/') || UNSUPPORTED.test(glob) || glob.includes('!') || names.some((name) => name !== '**' && name.includes('**'))) {
|
|
48
28
|
throw new DeptreeError(`${quote(glob)} is not supported: only \`*\`, \`**\` as a whole name and a leading \`!\` are`, where)
|
|
49
29
|
}
|
|
50
|
-
return { names: names.map((name) => (name === '**' ? name :
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Which places in a glob the path of `names` leads to: for each index,
|
|
54
|
-
// whether the glob's names before it take the path, a name at a time, in
|
|
55
|
-
// time the glob's length for each and with no recursion, however many
|
|
56
|
-
// `**` it has. A `**` may take no name, so reaching one reaches the next.
|
|
57
|
-
function reach({ names: glob, dot }, names) {
|
|
58
|
-
let here = Array.from({ length: glob.length + 1 }, (_, g) => g === 0)
|
|
59
|
-
let next = Array.from({ length: glob.length + 1 }, () => false)
|
|
60
|
-
const onward = (places) => {
|
|
61
|
-
for (let g = 0; g < glob.length; g++) if (places[g] && glob[g] === '**') places[g + 1] = true
|
|
62
|
-
}
|
|
63
|
-
onward(here)
|
|
64
|
-
for (const name of names) {
|
|
65
|
-
next.fill(false)
|
|
66
|
-
for (let g = 0; g < glob.length; g++) {
|
|
67
|
-
if (!here[g]) continue
|
|
68
|
-
if (glob[g] !== '**') next[g + 1] ||= glob[g].test(name)
|
|
69
|
-
else if (dot || !name.startsWith('.')) next[g] = true
|
|
70
|
-
}
|
|
71
|
-
onward(next)
|
|
72
|
-
;[here, next] = [next, here]
|
|
73
|
-
}
|
|
74
|
-
return here
|
|
30
|
+
return { names: names.map((name) => (name === '**' ? name : compileName(name, dot))), dot, raw: names }
|
|
75
31
|
}
|
|
76
32
|
|
|
77
|
-
|
|
78
|
-
const takes = (glob, names) => reach(glob, names)[glob.names.length]
|
|
33
|
+
const takes = (glob, names) => reach(glob.names, names, glob.dot).at(-1)
|
|
79
34
|
|
|
80
|
-
//
|
|
81
|
-
// its partial matcher has it: name by name, each has to be taken by the
|
|
82
|
-
// glob's name in the same place, until a `**` there takes one, which
|
|
83
|
-
// takes whatever is below it. A `**` that takes none is not tried, so a
|
|
35
|
+
// tinyglobby's partial matcher: a `**` that takes no name is not tried, so a
|
|
84
36
|
// name with a leading dot a `**` stands before is never walked into.
|
|
85
37
|
function enters({ names: glob, dot }, names) {
|
|
86
38
|
for (const [i, name] of names.entries()) {
|
|
@@ -91,33 +43,100 @@ function enters({ names: glob, dot }, names) {
|
|
|
91
43
|
return true
|
|
92
44
|
}
|
|
93
45
|
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
// whatever the globs say. pnpm 12 reads the manifest of a directory a
|
|
98
|
-
// glob with a `*` takes, which is `wild`, whatever it is.
|
|
46
|
+
// A manifest in a directory tinyglobby walks into is not ignored for what
|
|
47
|
+
// find-packages ignores; pnpm 12 drops it whatever the globs say. `wild` is
|
|
48
|
+
// whether a glob with a `*` takes it (manifestOf).
|
|
99
49
|
function compileAll(packages, major) {
|
|
50
|
+
if (major < 10) return compile9(packages)
|
|
100
51
|
const twelve = major >= 12
|
|
101
|
-
const
|
|
52
|
+
const [enters_, ignored_, dropped] = twelve ? [enters12, underLeftOut, underLeftOut] : [enters, ignored, () => false]
|
|
53
|
+
const include = []
|
|
54
|
+
const exclude = []
|
|
102
55
|
for (const glob of packages ?? []) {
|
|
103
|
-
const
|
|
104
|
-
const compiled = compile(
|
|
105
|
-
|
|
56
|
+
const negative = glob.startsWith('!')
|
|
57
|
+
const compiled = compile(negative ? glob.slice(1) : glob, 'pnpm-workspace.yaml: packages', negative && major >= 11)
|
|
58
|
+
;(negative ? exclude : include).push({ ...compiled, wild: twelve && glob.includes('*') })
|
|
106
59
|
}
|
|
107
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
walked: (names) => include.some((glob) => enters_(glob, names)) && !ignored_(names),
|
|
62
|
+
taken: takenBy(include, exclude, dropped),
|
|
63
|
+
wild: (names) => include.some((glob) => glob.wild && takes(glob, names)),
|
|
64
|
+
manifests: MANIFESTS,
|
|
65
|
+
through: [],
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const takenBy = (include, exclude, dropped) => (names) => include.some((glob) => takes(glob, names)) && !exclude.some((glob) => takes(glob, names)) && !dropped(names)
|
|
70
|
+
|
|
71
|
+
const startsWith = (names, start) => start.length <= names.length && start.every((name, i) => names[i] === name)
|
|
72
|
+
|
|
73
|
+
// fast-glob's partial matcher: past the names before its first `**`, any.
|
|
74
|
+
function partial({ names: glob, raw }, names) {
|
|
75
|
+
const star = raw.indexOf('**')
|
|
76
|
+
if (star === -1 && glob.length <= names.length) return false
|
|
77
|
+
if (star !== -1 && names.length > star) return true
|
|
78
|
+
return names.every((name, i) => glob[i].test(name))
|
|
108
79
|
}
|
|
109
80
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
//
|
|
113
|
-
//
|
|
81
|
+
const isDynamic = (glob) => glob.raw.some((name) => name.includes('*'))
|
|
82
|
+
|
|
83
|
+
// pnpm 9 globs with fast-glob 3: a glob with no `*` it looks up where it
|
|
84
|
+
// leads, and one with a `*` it walks for from the names before that
|
|
85
|
+
// (`base`), from the top for all of them where one has none there. Under
|
|
86
|
+
// a base it walks into every directory its globs may reach (`partial`),
|
|
87
|
+
// those with a leading dot among them, but where the ignore globs take it
|
|
88
|
+
// with `**` taking no leading dot, or where a `!` glob takes it whole;
|
|
89
|
+
// and takes a manifest a glob takes and no `!` glob, nor an ignore glob,
|
|
90
|
+
// with `**` and `*` taking leading dots. It reads every manifest a
|
|
91
|
+
// directory has, so one but package.json is the one refused (MANIFESTS_9),
|
|
92
|
+
// and fails on a glob that leads through a file (`through`).
|
|
93
|
+
function compile9(packages) {
|
|
94
|
+
const where = 'pnpm-workspace.yaml: packages'
|
|
95
|
+
const include = []
|
|
96
|
+
const exclude = []
|
|
97
|
+
const excludeWhole = []
|
|
98
|
+
for (const glob of packages ?? []) {
|
|
99
|
+
if (glob.startsWith('!')) {
|
|
100
|
+
exclude.push(compile(glob.slice(1), where, true))
|
|
101
|
+
excludeWhole.push(compile(glob.slice(1), where, false))
|
|
102
|
+
} else include.push(compile(glob, where, false))
|
|
103
|
+
}
|
|
104
|
+
const dynamic = include.filter(isDynamic)
|
|
105
|
+
const baseOf = (glob) => glob.raw.slice(0, glob.raw.findIndex((name) => name.includes('*')))
|
|
106
|
+
const groups = Map.groupBy(dynamic, (glob) => baseOf(glob).join('/'))
|
|
107
|
+
const tasks = groups.has('') ? [{ base: [], globs: dynamic }] : [...groups.values()].map((globs) => ({ base: baseOf(globs[0]), globs }))
|
|
108
|
+
const skipped = (names) => ignored(names) || (MANIFESTS.includes(names.at(-1)) && excludeWhole.some((glob) => takes(glob, [...names.slice(0, -1), 'package.json'])))
|
|
109
|
+
// A task walks into a directory only where it walked into its parent; each
|
|
110
|
+
// answer is kept for the walk.
|
|
111
|
+
const reacher = ({ base, globs }) => {
|
|
112
|
+
const known = new Map()
|
|
113
|
+
const reaches = (names) => {
|
|
114
|
+
if (names.length <= base.length) return names.length === base.length && startsWith(names, base)
|
|
115
|
+
const key = names.join('/')
|
|
116
|
+
if (!known.has(key)) known.set(key, reaches(names.slice(0, -1)) && globs.some((glob) => partial(glob, names)) && !skipped(names))
|
|
117
|
+
return known.get(key)
|
|
118
|
+
}
|
|
119
|
+
return reaches
|
|
120
|
+
}
|
|
121
|
+
const reachers = tasks.map(reacher)
|
|
122
|
+
const through = [...tasks.map((task) => task.base), ...include.filter((glob) => !isDynamic(glob)).map((glob) => glob.raw.slice(0, -1))]
|
|
123
|
+
return {
|
|
124
|
+
walked: (names) => through.some((path) => startsWith(path, names)) || reachers.some((reaches) => reaches(names)),
|
|
125
|
+
taken: takenBy(include, exclude, underLeftOut),
|
|
126
|
+
wild: () => false,
|
|
127
|
+
manifests: MANIFESTS_9,
|
|
128
|
+
through,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// The first of `globs.manifests` that is a file; pnpm 12 reads the first there
|
|
133
|
+
// where a `wild` glob takes the directory, failing where it is not a file.
|
|
114
134
|
function manifestOf(project, globs, names, entries) {
|
|
115
|
-
const
|
|
116
|
-
for (const name of MANIFESTS) {
|
|
135
|
+
for (const name of globs.manifests) {
|
|
117
136
|
if (!entries.includes(name)) continue
|
|
118
137
|
const type = typeOf(project, `/${[...names, name].join('/')}`)
|
|
119
138
|
if (type === 'file') return name
|
|
120
|
-
if (type !== undefined && wild()) throw new DeptreeError(`pnpm 12 reads this as a manifest, and fails on it as a ${type}`, quote([...names, name].join('/')))
|
|
139
|
+
if (type !== undefined && globs.wild([...names, 'package.json'])) throw new DeptreeError(`pnpm 12 reads this as a manifest, and fails on it as a ${type}`, quote([...names, name].join('/')))
|
|
121
140
|
}
|
|
122
141
|
return undefined
|
|
123
142
|
}
|
|
@@ -130,87 +149,59 @@ function byNames(a, b) {
|
|
|
130
149
|
return x.length - y.length
|
|
131
150
|
}
|
|
132
151
|
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
152
|
+
// find-packages leaves out what is under these, by globs whose `**`, as
|
|
153
|
+
// tinyglobby reads them, takes no name with a leading dot; as fast-glob
|
|
154
|
+
// reads them for a manifest, any (underLeftOut).
|
|
136
155
|
const LEFT_OUT = ['node_modules', 'bower_components']
|
|
137
|
-
const IGNORED = LEFT_OUT.map((name) => ({ names: ['**',
|
|
156
|
+
const IGNORED = LEFT_OUT.map((name) => ({ names: ['**', compileName(name, false), '**'], dot: false }))
|
|
138
157
|
const ignored = (names) => IGNORED.some((glob) => takes(glob, names))
|
|
139
158
|
|
|
140
|
-
|
|
141
|
-
// its path.
|
|
142
|
-
const ignored12 = (names) => names.some((name) => LEFT_OUT.includes(name))
|
|
143
|
-
|
|
144
|
-
// Whether pnpm 12 walks into the directory at `names` for a glob: where
|
|
145
|
-
// the glob's names before its last may take it.
|
|
146
|
-
const enters12 = (glob, names) => reach(glob, names).slice(0, glob.names.length).some(Boolean)
|
|
159
|
+
const underLeftOut = (names) => names.some((name) => LEFT_OUT.includes(name))
|
|
147
160
|
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
const taken = ({ include, exclude, dropped }, names) => include.some((glob) => takes(glob, names)) && !exclude.some((glob) => takes(glob, names)) && !dropped(names)
|
|
161
|
+
// pnpm 12 walks into a directory a glob's names before its last may take.
|
|
162
|
+
const enters12 = (glob, names) => reach(glob.names, names, glob.dot).slice(0, -1).some(Boolean)
|
|
151
163
|
|
|
152
|
-
// Whether tinyglobby walks into the directory at `names`, which it does
|
|
153
|
-
// through a link to one too; or pnpm 12.
|
|
154
|
-
const walked = (globs, names) => globs.include.some((glob) => globs.enters(glob, names)) && !globs.ignored(names)
|
|
155
|
-
|
|
156
|
-
// `ids` are the projects' directories, `.` the root; `packages` the globs,
|
|
157
|
-
// or undefined; `major` pnpm's major version. pnpm finds a project where
|
|
158
|
-
// tinyglobby walks into each directory down to it, and the globs take its
|
|
159
|
-
// manifest.
|
|
160
164
|
export function checkWorkspace(ids, packages, major = 10) {
|
|
161
165
|
const globs = compileAll(packages, major)
|
|
162
166
|
for (const id of ids) {
|
|
163
167
|
if (id === '.') continue
|
|
164
168
|
const names = id.split('/')
|
|
165
|
-
if (!names.every((_, i) => walked(
|
|
169
|
+
if (!names.every((_, i) => globs.walked(names.slice(0, i + 1))) || !globs.taken([...names, 'package.json'])) {
|
|
166
170
|
throw new DeptreeError(`pnpm-workspace.yaml's packages ${packages === undefined ? 'are not set' : 'do not take this directory'}, so pnpm would not install it as a project`, `importers[${quote(id)}]`)
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
|
|
171
|
-
//
|
|
172
|
-
// under the lockfile's directory has to be: its path from there, in normal
|
|
173
|
-
// form, with no drive letter, and no control, bidirectional or backslash
|
|
174
|
-
// character, which the lockfile could not name it by.
|
|
175
|
-
const UNSAFE = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\\]/u
|
|
175
|
+
// The importer keys @preventive/lockfile takes for a project.
|
|
176
176
|
export function checkProjectId(id, where) {
|
|
177
|
-
if (id
|
|
177
|
+
if (!isInside(id) || UNSAFE.test(id) || /^[A-Za-z]:/u.test(id)) {
|
|
178
178
|
throw new DeptreeError('expected a directory under the lockfile\'s, by its path from there in normal form, as a lockfile can key an importer', where)
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
// A manifest pnpm would read through a link, the root's among them, is
|
|
183
|
-
// refused before it is read.
|
|
184
182
|
export const linkedManifest = (file) => new DeptreeError('a link pnpm would read a project\'s manifest through is not supported', quote(file))
|
|
185
183
|
|
|
186
|
-
//
|
|
187
|
-
//
|
|
184
|
+
// pnpm reads the first of these a project has; pnpm 9 each, so one but
|
|
185
|
+
// package.json is named first.
|
|
188
186
|
const MANIFESTS = ['package.json', 'package.json5', 'package.yaml']
|
|
187
|
+
const MANIFESTS_9 = ['package.json5', 'package.yaml', 'package.json']
|
|
189
188
|
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
//
|
|
193
|
-
// link to one followed as it follows it. A manifest is a file, or a link
|
|
194
|
-
// to one; a link that leads nowhere, or to a directory, is none.
|
|
195
|
-
// Refused, as not read here: a root with no manifest, which pnpm takes
|
|
196
|
-
// for no project; a project, the root among them, whose manifest is
|
|
197
|
-
// package.json5, package.yaml or a link; a project found
|
|
198
|
-
// through a link, and a link to a directory in one followed, which is not
|
|
199
|
-
// followed; a project in a directory a lockfile could not key its
|
|
200
|
-
// importer by; and a node_modules tinyglobby walks into, which it does
|
|
201
|
-
// only under a directory with a leading dot, as what is installed there
|
|
202
|
-
// is no project buildPnpmTree builds.
|
|
189
|
+
// Every directory tinyglobby walks into is read, and no other. It walks into
|
|
190
|
+
// a node_modules only under a directory with a leading dot, which is
|
|
191
|
+
// refused, as what is installed there is no project buildPnpmTree builds.
|
|
203
192
|
export function findProjects(project, packages, major = 10) {
|
|
204
193
|
const globs = compileAll(packages, major)
|
|
194
|
+
for (const path of globs.through) {
|
|
195
|
+
const end = path.findIndex((_, i) => typeOf(project, `/${path.slice(0, i + 1).join('/')}`) === 'file')
|
|
196
|
+
if (end !== -1) throw new DeptreeError('a glob leads through this file, which pnpm 9 fails on', quote(path.slice(0, end + 1).join('/')))
|
|
197
|
+
}
|
|
205
198
|
const ids = []
|
|
206
|
-
// The directories left to read, by their names, and the link each is
|
|
207
|
-
// reached through, if any: a stack, not recursion, however deep the tree.
|
|
208
199
|
const pending = [{ names: [] }]
|
|
209
200
|
while (pending.length > 0) {
|
|
210
201
|
const { names, link } = pending.pop()
|
|
211
202
|
const dir = names.join('/')
|
|
212
203
|
const entries = project.readdir(`/${dir}`)
|
|
213
|
-
const found = names.length === 0 || taken(
|
|
204
|
+
const found = names.length === 0 || globs.taken([...names, 'package.json']) ? manifestOf(project, globs, names, entries) : undefined
|
|
214
205
|
if (names.length === 0 && found === undefined) throw new DeptreeError('pnpm takes a workspace with no manifest at its root for one with no root project, which is not supported', quote('package.json'))
|
|
215
206
|
if (found !== undefined) {
|
|
216
207
|
const file = [...names, found].join('/')
|
|
@@ -224,7 +215,7 @@ export function findProjects(project, packages, major = 10) {
|
|
|
224
215
|
}
|
|
225
216
|
for (const entry of entries) {
|
|
226
217
|
const at = [...names, entry]
|
|
227
|
-
if (!walked(
|
|
218
|
+
if (!globs.walked(at)) continue
|
|
228
219
|
const path = at.join('/')
|
|
229
220
|
const { type } = project.lstat(`/${path}`)
|
|
230
221
|
const linked = type === 'symlink' && typeOf(project, `/${path}`) === 'directory'
|
package/src/project.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The project, the lockfile's directory, as a Vfs or anything with its
|
|
2
|
+
// methods, by paths from `/`; it is only read, and only where a builder says.
|
|
3
|
+
|
|
4
|
+
import { DeptreeError, quote } from './error.js'
|
|
5
|
+
|
|
6
|
+
export function checkProject(project) {
|
|
7
|
+
if (['readdir', 'lstat', 'stat', 'readFile'].some((name) => typeof project?.[name] !== 'function')) {
|
|
8
|
+
throw new TypeError('project must be a Vfs, or have its readdir, lstat, stat and readFile')
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const NOWHERE = new Set(['ENOENT', 'ENOTDIR', 'ELOOP'])
|
|
13
|
+
export function typeOf(project, path, follow = true) {
|
|
14
|
+
try {
|
|
15
|
+
return (follow ? project.stat(path) : project.lstat(path)).type
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (NOWHERE.has(error?.code)) return undefined
|
|
18
|
+
throw error
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// A BOM is kept, as in text handed in, for the reader to drop as pnpm does.
|
|
23
|
+
const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })
|
|
24
|
+
|
|
25
|
+
// `bytes` as text, refused with `detail` where they are not UTF-8.
|
|
26
|
+
export function decodeUtf8(bytes, detail, where) {
|
|
27
|
+
try {
|
|
28
|
+
return decoder.decode(bytes)
|
|
29
|
+
} catch {
|
|
30
|
+
throw new DeptreeError(detail, where)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function readBytes(project, path) {
|
|
35
|
+
const bytes = project.readFile(path)
|
|
36
|
+
if (!(bytes instanceof Uint8Array)) throw new TypeError('project.readFile must give back bytes')
|
|
37
|
+
return bytes
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function readText(project, path, where) {
|
|
41
|
+
const type = typeOf(project, path)
|
|
42
|
+
if (type === undefined) return undefined
|
|
43
|
+
if (type !== 'file') throw new DeptreeError(`${quote(path.slice(1))} is a ${type}, not a file`, where)
|
|
44
|
+
return decodeUtf8(readBytes(project, path), `${quote(path.slice(1))} is not UTF-8`, where)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The checks each manager's checkHost and inputsOf make alike.
|
|
48
|
+
export function checkHostKeys(host, keys, wanted) {
|
|
49
|
+
if (host === null || typeof host !== 'object') throw new TypeError(`host must be an object with ${wanted}`)
|
|
50
|
+
for (const key of keys) if (typeof host[key] !== 'string' || host[key] === '') throw new TypeError(`host.${key} must be a non-empty string`)
|
|
51
|
+
}
|
|
52
|
+
export function checkLeftOut(values, all = 'both') {
|
|
53
|
+
for (const [name, value] of Object.entries(values)) if (value !== undefined) throw new TypeError(`${name} must be left out where lockfile is: ${all} are read from project`)
|
|
54
|
+
}
|
|
55
|
+
export function checkTexts(values) {
|
|
56
|
+
for (const [name, value] of Object.entries(values)) if (value !== undefined && typeof value !== 'string') throw new TypeError(`${name} must be a string, or left out`)
|
|
57
|
+
}
|
package/src/soldeer/config.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
// The config
|
|
2
|
-
//
|
|
3
|
-
// where there is no foundry.toml. Where neither holds, Soldeer asks which
|
|
4
|
-
// one to make its config, which is refused. Of foundry.toml, what Soldeer
|
|
5
|
-
// would fail on as it adds `dependencies` to the default profile's libs is
|
|
6
|
-
// refused; of the config, its [soldeer] settings where Soldeer would fail
|
|
7
|
-
// on them, and recursive_deps.
|
|
1
|
+
// The config Soldeer 0.12 reads: foundry.toml where it has a [dependencies]
|
|
2
|
+
// table, else soldeer.toml where there is no foundry.toml.
|
|
8
3
|
|
|
9
4
|
import { TomlError, isInlineTable, parseToml } from '@preventive/lockfile/toml.js'
|
|
10
5
|
import { DeptreeError } from '../error.js'
|
|
11
6
|
|
|
12
7
|
const isTable = (value) => typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === null
|
|
13
|
-
// A table toml_edit gives as one,
|
|
14
|
-
//
|
|
15
|
-
// dependencies from, and fails on for a profile.
|
|
8
|
+
// A table toml_edit gives as one, from a header or a dotted key, not inline:
|
|
9
|
+
// Soldeer reads no dependencies from that, and fails on it for a profile.
|
|
16
10
|
const isTableItem = (value) => isTable(value) && !isInlineTable(value)
|
|
17
11
|
|
|
18
12
|
function parse(text, file) {
|
|
@@ -37,16 +31,9 @@ function checkLibs(doc) {
|
|
|
37
31
|
if (libs !== undefined && (!Array.isArray(libs) || isTableItem(libs[0]))) throw new DeptreeError('not an array, which Soldeer fails on', 'foundry.toml: profile.default.libs')
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
function checkDependencies(doc, file) {
|
|
41
|
-
if (doc.dependencies !== undefined && !isTableItem(doc.dependencies)) {
|
|
42
|
-
throw new DeptreeError('not a table, which Soldeer reads no dependencies from, is not supported', `${file}: dependencies`)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
34
|
const BOOLEANS = ['remappings_generate', 'remappings_regenerate', 'remappings_version', 'recursive_deps']
|
|
47
35
|
|
|
48
|
-
// read_soldeer_config's SoldeerConfig, by serde
|
|
49
|
-
// any other passed over.
|
|
36
|
+
// read_soldeer_config's SoldeerConfig, by serde; unknown fields passed over.
|
|
50
37
|
function checkSettings(settings, file) {
|
|
51
38
|
if (settings === undefined) return
|
|
52
39
|
const where = `${file}: soldeer`
|
|
@@ -55,25 +42,22 @@ function checkSettings(settings, file) {
|
|
|
55
42
|
if (settings[key] !== undefined && typeof settings[key] !== 'boolean') throw new DeptreeError('not true or false, which Soldeer fails on', `${where}.${key}`)
|
|
56
43
|
}
|
|
57
44
|
if (settings.remappings_prefix !== undefined && typeof settings.remappings_prefix !== 'string') throw new DeptreeError('not a string, which Soldeer fails on', `${where}.remappings_prefix`)
|
|
58
|
-
if (
|
|
59
|
-
throw new DeptreeError('not "txt" or "config", which Soldeer fails on', `${where}.remappings_location`)
|
|
60
|
-
}
|
|
45
|
+
if (![undefined, 'txt', 'config'].includes(settings.remappings_location)) throw new DeptreeError('not "txt" or "config", which Soldeer fails on', `${where}.remappings_location`)
|
|
61
46
|
if (settings.recursive_deps === true) throw new DeptreeError('has Soldeer install what each dependency depends on too, which is not supported', `${where}.recursive_deps`)
|
|
62
47
|
}
|
|
63
48
|
|
|
64
49
|
const ASKS = 'Soldeer asks which file to make its config, which is not supported'
|
|
65
50
|
|
|
66
|
-
// The file Soldeer reads its config from, and that config, parsed.
|
|
67
51
|
export function configOf({ foundry, soldeer }) {
|
|
68
52
|
if (foundry === undefined && soldeer === undefined) throw new DeptreeError(`neither foundry.toml nor soldeer.toml is there, so ${ASKS}`)
|
|
69
53
|
const file = foundry === undefined ? 'soldeer.toml' : 'foundry.toml'
|
|
70
54
|
const config = parse(foundry ?? soldeer, file)
|
|
71
55
|
if (foundry === undefined) {
|
|
72
|
-
|
|
56
|
+
if (config.dependencies !== undefined && !isTableItem(config.dependencies)) throw new DeptreeError('not a table, which Soldeer reads no dependencies from, is not supported', 'soldeer.toml: dependencies')
|
|
73
57
|
} else {
|
|
74
58
|
if (!isTableItem(config.dependencies)) throw new DeptreeError(`no [dependencies] table, so ${ASKS}`, file)
|
|
75
59
|
checkLibs(config)
|
|
76
60
|
}
|
|
77
61
|
checkSettings(config.soldeer, file)
|
|
78
|
-
return
|
|
62
|
+
return config
|
|
79
63
|
}
|
package/src/soldeer/inputs.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
// What buildSoldeerTree takes,
|
|
2
|
-
// files `soldeer install` reads — given as text, or read from the project
|
|
3
|
-
// (../pnpm/project.js) as Soldeer reads them at the project's root.
|
|
1
|
+
// What buildSoldeerTree takes, as text or read from the project's root.
|
|
4
2
|
|
|
5
3
|
import { DeptreeError, quote } from '../error.js'
|
|
6
|
-
import { checkProject, readText } from '../
|
|
4
|
+
import { checkHostKeys, checkLeftOut, checkProject, checkTexts, readText } from '../project.js'
|
|
7
5
|
|
|
8
6
|
export function checkHost(host) {
|
|
9
|
-
|
|
10
|
-
for (const key of ['soldeer', 'os']) {
|
|
11
|
-
if (typeof host[key] !== 'string' || host[key] === '') throw new TypeError(`host.${key} must be a non-empty string`)
|
|
12
|
-
}
|
|
7
|
+
checkHostKeys(host, ['soldeer', 'os'], 'soldeer and os')
|
|
13
8
|
if (host.soldeer !== '0.12.0') throw new DeptreeError(`Soldeer ${quote(host.soldeer)} is not supported: only Soldeer 0.12.0 is`, 'host.soldeer')
|
|
14
9
|
if (host.os === 'win32') throw new DeptreeError('Windows is not supported: Soldeer names folders otherwise there', 'host.os')
|
|
15
10
|
return { soldeer: host.soldeer, os: host.os }
|
|
@@ -22,19 +17,14 @@ export function inputsOf(options) {
|
|
|
22
17
|
if (lockfile === undefined) {
|
|
23
18
|
if (project === undefined) throw new TypeError(LOCKFILE)
|
|
24
19
|
checkProject(project)
|
|
25
|
-
|
|
26
|
-
if (value !== undefined) throw new TypeError(`${name} must be left out where lockfile is: all are read from project`)
|
|
27
|
-
}
|
|
20
|
+
checkLeftOut({ foundry, soldeer }, 'all')
|
|
28
21
|
const lock = readText(project, '/soldeer.lock', 'soldeer.lock')
|
|
29
22
|
if (lock === undefined) throw new DeptreeError('the project has no soldeer.lock, without which Soldeer resolves each dependency anew')
|
|
30
|
-
// Soldeer reads soldeer.toml only where it cannot read foundry.toml.
|
|
31
23
|
const foundryText = readText(project, '/foundry.toml', 'foundry.toml')
|
|
32
24
|
return { lockfile: lock, foundry: foundryText, soldeer: foundryText === undefined ? readText(project, '/soldeer.toml', 'soldeer.toml') : undefined }
|
|
33
25
|
}
|
|
34
26
|
if (typeof lockfile !== 'string') throw new TypeError(LOCKFILE)
|
|
35
27
|
if (project !== undefined) throw new TypeError('project must be left out where lockfile is given')
|
|
36
|
-
|
|
37
|
-
if (value !== undefined && typeof value !== 'string') throw new TypeError(`${name} must be a string, or left out`)
|
|
38
|
-
}
|
|
28
|
+
checkTexts({ foundry, soldeer })
|
|
39
29
|
return { lockfile, foundry, soldeer }
|
|
40
30
|
}
|