@preventive/deptree 1.0.0-alpha.4 → 1.0.0-alpha.6
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 +36 -10
- package/pnpm.d.ts +116 -22
- 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 +64 -13
- package/src/manifest.js +52 -0
- package/src/matcher.js +59 -10
- package/src/mount.js +95 -44
- package/src/npm/bins.js +71 -0
- package/src/npm/compat.js +92 -0
- package/src/npm/dev-engines.js +52 -0
- package/src/npm/graph.js +68 -0
- package/src/npm/inputs.js +80 -0
- package/src/npm/manifests.js +138 -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/{pnpm/npmrc.js → npmrc.js} +5 -11
- package/src/patch.js +21 -31
- package/src/pnpm/bins.js +32 -103
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +49 -86
- package/src/pnpm/filename.js +10 -21
- package/src/pnpm/frozen.js +27 -70
- package/src/pnpm/gitignore.js +137 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +15 -43
- package/src/pnpm/hoist.js +65 -55
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +67 -40
- package/src/pnpm/install.js +72 -115
- package/src/pnpm/local.js +21 -40
- package/src/pnpm/minimatch.js +328 -0
- package/src/pnpm/npm-packlist.js +221 -0
- package/src/pnpm/overrides.js +10 -49
- package/src/pnpm/package.js +120 -0
- package/src/pnpm/packlist.js +168 -109
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +63 -107
- package/src/pnpm/readers.js +46 -55
- package/src/pnpm/settings.js +60 -97
- package/src/pnpm/tree.js +134 -149
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +122 -131
- package/src/project.js +41 -0
- package/src/soldeer/config.js +8 -24
- package/src/soldeer/inputs.js +2 -5
- package/src/soldeer/tree.js +20 -56
- package/src/soldeer/zip.js +17 -36
- package/src/tarball.js +38 -142
- 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 +16 -51
- 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 +35 -111
- package/src/yarn1/settings.js +14 -41
- package/src/yarn1/tree.js +67 -91
- package/yarn1.d.ts +30 -2
- package/yarn1.js +1 -8
- package/src/pnpm/project.js +0 -97
- package/src/yarn1/glob.js +0 -52
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/yarn1.d.ts
CHANGED
|
@@ -60,7 +60,8 @@ export interface Yarn1Project {
|
|
|
60
60
|
//
|
|
61
61
|
// With `lockfile`, they are given as text: `manifests` by the project's
|
|
62
62
|
// directory relative to the lockfile's (`.` for the root, then each
|
|
63
|
-
// workspace's, as findYarn1Workspaces lists them
|
|
63
|
+
// workspace's, as findYarn1Workspaces lists them: a directory under the
|
|
64
|
+
// lockfile's, with no `.`, `..` or empty segment). Every workspace yarn
|
|
64
65
|
// would find has to be given, which buildYarn1Tree cannot check where it
|
|
65
66
|
// is given them, as it is not given the directories; and the lockfile
|
|
66
67
|
// reader refuses a manifest of any directory the root's `workspaces` do
|
|
@@ -163,10 +164,36 @@ export interface Yarn1TreeStats {
|
|
|
163
164
|
links: number
|
|
164
165
|
}
|
|
165
166
|
|
|
167
|
+
// A copy of a registry package in the tree, as an SBOM would list it:
|
|
168
|
+
// `path` is where its files really are, from the lockfile's directory,
|
|
169
|
+
// which is `/` of the Vfs — node_modules/<alias>, or beneath a workspace,
|
|
170
|
+
// in that workspace's own node_modules. `name` and `version` are the
|
|
171
|
+
// package's own, which its package.json is held to, whatever alias it is
|
|
172
|
+
// installed as; `integrity` the sha512 its tarball is held to. `dev` is
|
|
173
|
+
// whether dev dependencies alone reach this copy, the root's and the
|
|
174
|
+
// workspaces' devDependencies: nothing else does, each dependency, and
|
|
175
|
+
// each peer yarn finds, looked for from where what asks for it is, as Node
|
|
176
|
+
// finds it and yarn marks what an install requires, past what the host
|
|
177
|
+
// cannot run. Two copies of one package may differ: one beneath a
|
|
178
|
+
// devDependency that only it needs is dev. `optional` is whether optional
|
|
179
|
+
// dependencies alone reach this copy, so.
|
|
180
|
+
export interface Yarn1Installed {
|
|
181
|
+
path: string
|
|
182
|
+
name: string
|
|
183
|
+
version: string
|
|
184
|
+
integrity: string
|
|
185
|
+
dev: boolean
|
|
186
|
+
optional: boolean
|
|
187
|
+
}
|
|
188
|
+
|
|
166
189
|
// `vfs` is the one given, the tree mounted into it, or a new one.
|
|
190
|
+
// `installed` is each copy in the tree, once for each path, by path in
|
|
191
|
+
// the order of its code points, whatever the locale; a workspace, whose
|
|
192
|
+
// files the tree does not hold, is not among them.
|
|
167
193
|
export interface Yarn1Tree {
|
|
168
194
|
vfs: Vfs
|
|
169
195
|
stats: Yarn1TreeStats
|
|
196
|
+
installed: Yarn1Installed[]
|
|
170
197
|
}
|
|
171
198
|
|
|
172
199
|
// The node_modules tree `yarn install --frozen-lockfile --ignore-scripts`
|
|
@@ -214,7 +241,8 @@ export interface Yarn1Tree {
|
|
|
214
241
|
// file under one directory, none in the package's own node_modules, where
|
|
215
242
|
// yarn installs its dependencies, no link or device in it, and a
|
|
216
243
|
// package.json for exactly its name and version; each with the sha512
|
|
217
|
-
// integrity and the sha1
|
|
244
|
+
// integrity the lockfile records, and the sha1 each of its entries does,
|
|
245
|
+
// fetched or not. On macOS, two names in one
|
|
218
246
|
// directory that differ only in case or normalization are refused, as
|
|
219
247
|
// they would be one name there.
|
|
220
248
|
//
|
package/yarn1.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
// A node_modules tree built in memory from a yarn.lock, as yarn 1.22
|
|
2
|
-
// installs it with its node_modules linker
|
|
3
|
-
// and what comes back. The project is read through the view given, and
|
|
4
|
-
// the tree built in a Vfs; the one filesystem touched is that of the
|
|
5
|
-
// tarball caches @preventive/upstream reads, and writes where it keeps its
|
|
6
|
-
// own.
|
|
2
|
+
// installs it with its node_modules linker; see yarn1.d.ts.
|
|
7
3
|
export { buildYarn1Tree } from './src/yarn1/tree.js'
|
|
8
4
|
export { findYarn1Workspaces } from './src/yarn1/inputs.js'
|
|
9
5
|
export { DeptreeError } from './src/error.js'
|
|
10
|
-
// Where @preventive/upstream caches what it fetches, tarballs among it;
|
|
11
|
-
// unset, it keeps no cache of its own, and writes nothing.
|
|
12
6
|
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
13
|
-
// What the lockfile, and the manifests read with it, are refused with.
|
|
14
7
|
export { LockfileError } from '@preventive/lockfile/yarn1.js'
|
package/src/pnpm/project.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
// The project a tree is built for: a view of the lockfile's directory, by
|
|
2
|
-
// paths from `/` — a Vfs, or anything with its readdir, lstat, stat and
|
|
3
|
-
// readFile, such as one of a directory on disk. It is only read, and only
|
|
4
|
-
// where these say: the files pnpm reads at the root for an install, the
|
|
5
|
-
// package.json of each project and the patches the settings name, where
|
|
6
|
-
// buildPnpmTree is not handed them; the directories findProjects walks;
|
|
7
|
-
// and those a `link:` or `file:` leads to (local.js).
|
|
8
|
-
|
|
9
|
-
import { normalize } from '@preventive/vfs/path.js'
|
|
10
|
-
import { DeptreeError, quote } from '../error.js'
|
|
11
|
-
|
|
12
|
-
export function checkProject(project) {
|
|
13
|
-
if (['readdir', 'lstat', 'stat', 'readFile'].some((name) => typeof project?.[name] !== 'function')) {
|
|
14
|
-
throw new TypeError('project must be a Vfs, or have its readdir, lstat, stat and readFile')
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// What `path` leads to, links followed, or where `follow` is false, what
|
|
19
|
-
// it is; nothing, where it leads nowhere: to no entry, through a file, or
|
|
20
|
-
// round a loop of links. Any other failure is thrown.
|
|
21
|
-
const NOWHERE = new Set(['ENOENT', 'ENOTDIR', 'ELOOP'])
|
|
22
|
-
export function typeOf(project, path, follow = true) {
|
|
23
|
-
try {
|
|
24
|
-
return (follow ? project.stat(path) : project.lstat(path)).type
|
|
25
|
-
} catch (error) {
|
|
26
|
-
if (NOWHERE.has(error?.code)) return undefined
|
|
27
|
-
throw error
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// As text handed in would be: a byte order mark kept, for what reads it
|
|
32
|
-
// to drop as pnpm does.
|
|
33
|
-
const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })
|
|
34
|
-
|
|
35
|
-
// The bytes of the file at `path`, as a Vfs gives them back.
|
|
36
|
-
export function readBytes(project, path) {
|
|
37
|
-
const bytes = project.readFile(path)
|
|
38
|
-
if (!(bytes instanceof Uint8Array)) throw new TypeError('project.readFile must give back bytes')
|
|
39
|
-
return bytes
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// The text of the file at `path`, or undefined where nothing is.
|
|
43
|
-
export function readText(project, path, where) {
|
|
44
|
-
const type = typeOf(project, path)
|
|
45
|
-
if (type === undefined) return undefined
|
|
46
|
-
if (type !== 'file') throw new DeptreeError(`${quote(path.slice(1))} is a ${type}, not a file`, where)
|
|
47
|
-
const bytes = readBytes(project, path)
|
|
48
|
-
try {
|
|
49
|
-
return decoder.decode(bytes)
|
|
50
|
-
} catch {
|
|
51
|
-
throw new DeptreeError(`${quote(path.slice(1))} is not UTF-8`, where)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// pnpm-workspace.yaml, where it is. pnpm looks for it under other names
|
|
56
|
-
// too, and refuses one it finds so.
|
|
57
|
-
const MISNAMED = ['pnpm-workspaces.yaml', 'pnpm-workspaces.yml', 'pnpm-workspace.yml', '.pnpm-workspace.yaml', '.pnpm-workspace.yml', '.pnpm-workspaces.yaml', '.pnpm-workspaces.yml']
|
|
58
|
-
export function readWorkspaceText(project) {
|
|
59
|
-
const text = readText(project, '/pnpm-workspace.yaml')
|
|
60
|
-
const misnamed = text === undefined ? MISNAMED.find((name) => typeOf(project, `/${name}`) === 'file') : undefined
|
|
61
|
-
if (misnamed !== undefined) throw new DeptreeError('pnpm refuses a workspace manifest not named pnpm-workspace.yaml', quote(misnamed))
|
|
62
|
-
return text
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// What pnpm reads at the root for an install besides the package.json:
|
|
66
|
-
// pnpm-lock.yaml, which a frozen install cannot do without, and
|
|
67
|
-
// pnpm-workspace.yaml and the .npmrc, where they are.
|
|
68
|
-
export function readRootFiles(project) {
|
|
69
|
-
const lockfile = readText(project, '/pnpm-lock.yaml')
|
|
70
|
-
if (lockfile === undefined) throw new DeptreeError('the project has no pnpm-lock.yaml, which a frozen install cannot do without')
|
|
71
|
-
return { lockfile, workspace: readWorkspaceText(project), npmrc: readText(project, '/.npmrc') }
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// The text of the package.json of each of `ids`, the projects'
|
|
75
|
-
// directories, by directory.
|
|
76
|
-
export function readManifestTexts(project, ids) {
|
|
77
|
-
const texts = new Map()
|
|
78
|
-
for (const id of ids) {
|
|
79
|
-
texts.set(id, readText(project, id === '.' ? '/package.json' : `/${id}/package.json`, `manifests[${quote(id)}]`))
|
|
80
|
-
}
|
|
81
|
-
return texts
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// The text of each patch `configured`, patchedDependencies, names, by its
|
|
85
|
-
// path from the lockfile's directory; one that is not there left out.
|
|
86
|
-
// One outside that directory, or absolute, is not in the project, and is
|
|
87
|
-
// refused.
|
|
88
|
-
export function readPatches(project, configured) {
|
|
89
|
-
const texts = new Map()
|
|
90
|
-
for (const [selector, spec] of Object.entries(configured ?? {})) {
|
|
91
|
-
const path = normalize(spec)
|
|
92
|
-
if (path === '..' || path.startsWith('../') || path.startsWith('/')) throw new DeptreeError(`the patch ${quote(spec)} is not in the project: it is outside the lockfile's directory`, `patchedDependencies[${quote(selector)}]`)
|
|
93
|
-
const text = readText(project, `/${path}`, `patches[${quote(path)}]`)
|
|
94
|
-
if (text !== undefined) texts.set(path, text)
|
|
95
|
-
}
|
|
96
|
-
return texts
|
|
97
|
-
}
|
package/src/yarn1/glob.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// The globs yarn matches with minimatch's defaults, as far as the lockfile
|
|
2
|
-
// reader lets them through: a segment at a time, `**` as any number of
|
|
3
|
-
// whole segments, `*` and `?` within one, and no segment that starts with
|
|
4
|
-
// a dot taken by a wildcard.
|
|
5
|
-
|
|
6
|
-
import { escape } from '../matcher.js'
|
|
7
|
-
|
|
8
|
-
const compiled = new Map()
|
|
9
|
-
|
|
10
|
-
function compile(glob) {
|
|
11
|
-
return glob.split('/').map((segment) => {
|
|
12
|
-
if (segment === '**') return null
|
|
13
|
-
const dot = segment.startsWith('.') || !/[*?]/u.test(segment) ? '' : '(?!\\.)'
|
|
14
|
-
return new RegExp(`^${dot}${segment.split(/([*?])/u).map((part) => (part === '*' ? '[^/]*' : part === '?' ? '[^/]' : escape(part))).join('')}$`, 'u')
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// The places in `glob` that `path` reaches, a name at a time, a `**`
|
|
19
|
-
// taking none or more, in time linear in both: a place is the index of the
|
|
20
|
-
// glob's next segment, its length where all are taken.
|
|
21
|
-
function placesOf(glob, path) {
|
|
22
|
-
if (!compiled.has(glob)) compiled.set(glob, compile(glob))
|
|
23
|
-
const tests = compiled.get(glob)
|
|
24
|
-
const close = (places) => {
|
|
25
|
-
for (let i = 0; i < tests.length; i++) if (places.has(i) && tests[i] === null) places.add(i + 1)
|
|
26
|
-
return places
|
|
27
|
-
}
|
|
28
|
-
let places = close(new Set([0]))
|
|
29
|
-
for (const segment of path === '' ? [] : path.split('/')) {
|
|
30
|
-
const next = new Set()
|
|
31
|
-
for (const i of places) {
|
|
32
|
-
if (i === tests.length) continue
|
|
33
|
-
if (tests[i] === null) {
|
|
34
|
-
if (!segment.startsWith('.')) next.add(i)
|
|
35
|
-
} else if (tests[i].test(segment)) next.add(i + 1)
|
|
36
|
-
}
|
|
37
|
-
places = close(next)
|
|
38
|
-
}
|
|
39
|
-
return { places, length: tests.length }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Whether `glob` takes `path`.
|
|
43
|
-
export function matchesGlob(glob, path) {
|
|
44
|
-
const { places, length } = placesOf(glob, path)
|
|
45
|
-
return places.has(length)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Whether `glob` may take a path below `dir`: some of it left to take.
|
|
49
|
-
export function reachesBelow(glob, dir) {
|
|
50
|
-
const { places, length } = placesOf(glob, dir)
|
|
51
|
-
return [...places].some((place) => place < length)
|
|
52
|
-
}
|
/package/{LICENSE → LICENSE-MIT}
RENAMED
|
File without changes
|