@preventive/deptree 1.3.2 → 1.4.0
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/bin/compare.js +5 -2
- package/bin/deptree.js +66 -19
- package/cocoapods.d.ts +372 -0
- package/cocoapods.js +6 -0
- package/package.json +24 -6
- package/pnpm.d.ts +52 -75
- package/soldeer.d.ts +6 -3
- package/src/cargo/members.js +3 -2
- package/src/cargo/tree.js +2 -2
- package/src/cargo/workspace.js +3 -6
- package/src/cocoapods/archive.js +223 -0
- package/src/cocoapods/clean.js +186 -0
- package/src/cocoapods/fnmatch.js +198 -0
- package/src/cocoapods/inputs.js +80 -0
- package/src/cocoapods/install.js +61 -0
- package/src/cocoapods/podspec.js +203 -0
- package/src/cocoapods/podtree.js +131 -0
- package/src/cocoapods/source.js +90 -0
- package/src/cocoapods/tree.js +184 -0
- package/src/cocoapods/unicode.js +17 -0
- package/src/github.js +92 -0
- package/src/glob.js +2 -1
- package/src/hash.js +1 -34
- package/src/matcher.js +2 -4
- package/src/mount.js +3 -6
- package/src/npm/compat.js +3 -4
- package/src/npm/manifests.js +1 -1
- package/src/npm/tree.js +9 -8
- package/src/patch.js +9 -5
- package/src/pnpm/bins.js +12 -11
- package/src/pnpm/commands.js +5 -15
- package/src/pnpm/directories.js +250 -0
- package/src/pnpm/extensions.js +76 -0
- package/src/pnpm/filename.js +4 -4
- package/src/pnpm/frozen.js +3 -2
- package/src/pnpm/glob.js +1 -1
- package/src/pnpm/graph.js +7 -9
- package/src/pnpm/hoist.js +0 -36
- package/src/pnpm/hoisted.js +3 -3
- package/src/pnpm/hook.js +13 -21
- package/src/pnpm/inputs.js +7 -16
- package/src/pnpm/install.js +3 -4
- package/src/pnpm/lazy.js +18 -18
- package/src/pnpm/local.js +29 -15
- package/src/pnpm/minimatch.js +2 -2
- package/src/pnpm/nm-hoist.js +1 -1
- package/src/pnpm/npm-packlist.js +1 -1
- package/src/pnpm/overrides.js +3 -4
- package/src/pnpm/package.js +17 -9
- package/src/pnpm/packlist.js +1 -2
- package/src/pnpm/patches.js +15 -13
- package/src/pnpm/production.js +1 -1
- package/src/pnpm/projects.js +14 -40
- package/src/pnpm/readers.js +6 -29
- package/src/pnpm/settings.js +14 -37
- package/src/pnpm/tree.js +34 -24
- package/src/pnpm/uptodate.js +12 -13
- package/src/pnpm/workspace.js +8 -79
- package/src/pnpm/write.js +2 -1
- package/src/soldeer/tree.js +2 -2
- package/src/soldeer/zip.js +11 -42
- package/src/tarball.js +1 -3
- package/src/yarn1/hoist.js +4 -2
- package/src/yarn1/manifest.js +3 -2
- package/src/yarn1/requests.js +1 -1
- package/src/yarn1/resolve.js +16 -6
- package/src/yarn1/tree.js +12 -8
- package/src/soldeer/git.js +0 -67
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// What CocoaPods keeps of a pod it downloads, held in memory: its
|
|
2
|
+
// PodDirCleaner removes every file and directory of the download that no
|
|
3
|
+
// spec uses, by the file patterns of each spec on each platform, through a
|
|
4
|
+
// PathList of what is there and a FileAccessor per spec and platform; its
|
|
5
|
+
// lock_files! then takes the owner's write off each source file. Each is
|
|
6
|
+
// followed as CocoaPods 1.13 to 1.17 have it, in Ruby 2.6 to 3.4.
|
|
7
|
+
|
|
8
|
+
import { DeptreeError, quote } from '../error.js'
|
|
9
|
+
import { expandBraces, matcher } from './fnmatch.js'
|
|
10
|
+
|
|
11
|
+
// FileAccessor::GLOB_PATTERNS, and what a source file is: Xcodeproj's
|
|
12
|
+
// header extensions after CocoaPods' own.
|
|
13
|
+
const HEADERS = ['.h', '.hh', '.hpp', '.ipp', '.tpp', '.hxx', '.def', '.inl', '.inc']
|
|
14
|
+
const SOURCES = [...new Set(['.m', '.mm', '.i', '.c', '.cc', '.cxx', '.cpp', '.c++', '.swift', ...HEADERS])]
|
|
15
|
+
const SOURCE_FILES = `*{${SOURCES.join(',')}}`
|
|
16
|
+
const README = 'readme{*,.*}'
|
|
17
|
+
const LICENSE = 'licen{c,s}e{*,.*}'
|
|
18
|
+
// What PathList#relative_glob lays under a directory an exclusion names.
|
|
19
|
+
const EXCLUDED_DIR = '**/*'
|
|
20
|
+
// The paths matched against a pattern, each of a pattern's expansions
|
|
21
|
+
// counted, past which a pod is refused rather than cleaned.
|
|
22
|
+
export const MAX_MATCHES = 200_000_000
|
|
23
|
+
|
|
24
|
+
// Ruby's String#downcase and #upcase: Unicode's mappings, without the
|
|
25
|
+
// final sigma, which takes the letters around it into account and Ruby
|
|
26
|
+
// does not.
|
|
27
|
+
const downcase = (text) => text.replaceAll('\u03A3', '\u03C3').toLowerCase()
|
|
28
|
+
const encoder = new TextEncoder()
|
|
29
|
+
function compareBytes(a, b) {
|
|
30
|
+
for (let i = 0; i < a.length && i < b.length; i++) if (a[i] !== b[i]) return a[i] - b[i]
|
|
31
|
+
return a.length - b.length
|
|
32
|
+
}
|
|
33
|
+
// Ruby's sort_by(&:upcase), which compares bytes.
|
|
34
|
+
const byUpcase = (paths) => paths.map((path) => [path, encoder.encode(path.toUpperCase())]).sort(([, a], [, b]) => compareBytes(a, b)).map(([path]) => path)
|
|
35
|
+
|
|
36
|
+
// Sandbox::PathList: what `**/*` with FNM_DOTMATCH finds in the pod's
|
|
37
|
+
// directory, entering no link, each a directory where File.directory? says
|
|
38
|
+
// so and a file where it does not, a directory whose path ends in `.`
|
|
39
|
+
// passed over; each list sorted by sort_by(&:upcase).
|
|
40
|
+
class PathList {
|
|
41
|
+
constructor(tree, budget) {
|
|
42
|
+
this.tree = tree
|
|
43
|
+
this.budget = budget
|
|
44
|
+
const dirs = []
|
|
45
|
+
const files = []
|
|
46
|
+
for (const path of tree.paths) {
|
|
47
|
+
if (!tree.isDirectory(path)) files.push(path)
|
|
48
|
+
else if (!path.endsWith('.')) dirs.push(path)
|
|
49
|
+
}
|
|
50
|
+
this.files = byUpcase(files)
|
|
51
|
+
this.dirs = byUpcase(dirs)
|
|
52
|
+
this.lowerDirs = new Set(this.dirs.map(downcase))
|
|
53
|
+
this.cache = new Map()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// PathList#directory?, by downcase.
|
|
57
|
+
isDirectory(pattern) {
|
|
58
|
+
return this.lowerDirs.has(downcase(pattern).replace(/\/$/u, ''))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// PathList#relative_glob: each pattern a path of the list as it is, or
|
|
62
|
+
// else, where it names a directory and `dirPattern` is given, that laid
|
|
63
|
+
// under it; then its braces expanded, and every path of the list that
|
|
64
|
+
// one of them matches. Those `exclude` matches, under a directory it
|
|
65
|
+
// names too, are taken out. Paths come back in the order of the list,
|
|
66
|
+
// pattern by pattern, the same path more than once where two match it.
|
|
67
|
+
glob(patterns, { dirPattern, exclude = [], includeDirs = false } = {}) {
|
|
68
|
+
if (patterns.length === 0) return []
|
|
69
|
+
const key = JSON.stringify([patterns, dirPattern, exclude, includeDirs])
|
|
70
|
+
if (this.cache.has(key)) return this.cache.get(key)
|
|
71
|
+
const list = includeDirs ? [...this.files, ...this.dirs] : this.files
|
|
72
|
+
const exact = new Set(list)
|
|
73
|
+
let found = patterns.flatMap((pattern) => {
|
|
74
|
+
if (exact.has(pattern)) return [pattern]
|
|
75
|
+
const full = this.isDirectory(pattern) && dirPattern !== undefined ? `${pattern.endsWith('/') ? pattern : `${pattern}/`}${dirPattern}` : pattern
|
|
76
|
+
const expanded = expandBraces(full)
|
|
77
|
+
if (expanded === undefined) throw new DeptreeError(`the file pattern ${quote(pattern)} is too long, expands to too many, or has a backslash in braces`, this.tree.where)
|
|
78
|
+
this.budget.matches += expanded.length * list.length
|
|
79
|
+
if (this.budget.matches > MAX_MATCHES) throw new DeptreeError(`its file patterns take more than ${MAX_MATCHES} matches of a path to clean it, which is not followed`, this.tree.where)
|
|
80
|
+
const matchers = expanded.map(matcher)
|
|
81
|
+
return list.filter((path) => matchers.some((matches) => matches(path)))
|
|
82
|
+
})
|
|
83
|
+
if (exclude.length > 0) {
|
|
84
|
+
const excluded = new Set(this.glob(exclude, { dirPattern: EXCLUDED_DIR, includeDirs }))
|
|
85
|
+
found = found.filter((path) => !excluded.has(path))
|
|
86
|
+
}
|
|
87
|
+
this.cache.set(key, found)
|
|
88
|
+
return found
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// `glob([pattern]).first`, as readme and license take it: refused where
|
|
92
|
+
// two that sort_by(&:upcase) leaves in no set order could be first.
|
|
93
|
+
first(pattern) {
|
|
94
|
+
const [one, two] = this.glob([pattern])
|
|
95
|
+
if (two !== undefined && one.toUpperCase() === two.toUpperCase()) throw new DeptreeError(`${quote(one)} and ${quote(two)} differ in case alone, and CocoaPods takes either as the first ${pattern}`, this.tree.where)
|
|
96
|
+
return one
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// FileAccessor#source_files, of one spec on one platform: `values` are its
|
|
101
|
+
// consumerOf.
|
|
102
|
+
const sourceFiles = (list, values) => list.glob(values.source_files, { dirPattern: SOURCE_FILES, exclude: values.exclude_files })
|
|
103
|
+
|
|
104
|
+
// FileAccessor.all_files, of one spec on one platform: the paths of what it
|
|
105
|
+
// uses, from the pod's directory, as each accessor finds them; the prefix
|
|
106
|
+
// header's, the module map's and the license's as the podspec gives them.
|
|
107
|
+
function usedFiles(list, values, licenseFile) {
|
|
108
|
+
const exclude = values.exclude_files
|
|
109
|
+
const withDirs = (patterns) => list.glob(patterns, { exclude, includeDirs: true })
|
|
110
|
+
const license = licenseFile !== undefined && list.tree.exists(licenseFile) ? licenseFile : list.first(LICENSE)
|
|
111
|
+
return [
|
|
112
|
+
...withDirs(values.vendored_frameworks),
|
|
113
|
+
...list.glob(values.vendored_libraries, { exclude }),
|
|
114
|
+
...withDirs(values.resource_bundles),
|
|
115
|
+
license,
|
|
116
|
+
values.prefix_header_file,
|
|
117
|
+
...withDirs(values.preserve_paths),
|
|
118
|
+
list.first(README),
|
|
119
|
+
...withDirs(values.resources),
|
|
120
|
+
...withDirs(values.on_demand_resources),
|
|
121
|
+
...sourceFiles(list, values),
|
|
122
|
+
values.module_map,
|
|
123
|
+
].filter((path) => path !== undefined)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The index of the first of `sorted` at or after `text`.
|
|
127
|
+
function firstFrom(sorted, text) {
|
|
128
|
+
let low = 0
|
|
129
|
+
let high = sorted.length
|
|
130
|
+
while (low < high) {
|
|
131
|
+
const mid = (low + high) >>> 1
|
|
132
|
+
if (sorted[mid] < text) low = mid + 1
|
|
133
|
+
else high = mid
|
|
134
|
+
}
|
|
135
|
+
return low
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Whether one of `sorted` starts with `text`, or `text` with one of them.
|
|
139
|
+
// One `text` starts with is at or before it, and so is all that comes
|
|
140
|
+
// between the two: the last before it starts with that one too, so that
|
|
141
|
+
// where it is not one, the search goes on in what the two have in common.
|
|
142
|
+
function sharesStart(sorted, text) {
|
|
143
|
+
let at = firstFrom(sorted, text)
|
|
144
|
+
if (sorted[at]?.startsWith(text)) return true
|
|
145
|
+
for (let start = text; at > 0;) {
|
|
146
|
+
const before = sorted[at - 1]
|
|
147
|
+
if (start.startsWith(before)) return true
|
|
148
|
+
let common = 0
|
|
149
|
+
while (common < before.length && before[common] === start[common]) common++
|
|
150
|
+
if (common === 0) return false
|
|
151
|
+
start = start.slice(0, common)
|
|
152
|
+
at = firstFrom(sorted, start)
|
|
153
|
+
if (sorted[at] === start) return true
|
|
154
|
+
}
|
|
155
|
+
return false
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Each set of values once, as specs and platforms often share one.
|
|
159
|
+
const uniqueOf = (accessors) => [...new Map(accessors.map((one) => [JSON.stringify(one), one])).values()]
|
|
160
|
+
|
|
161
|
+
// PodDirCleaner#clean!, by the consumerOf values of each spec on each
|
|
162
|
+
// platform it is cleaned for: every path of the pod's directory removed,
|
|
163
|
+
// all under it with it, but what ends in `.`, and what is a used file's
|
|
164
|
+
// path or one of whose paths is in the other, downcased, as `include?`
|
|
165
|
+
// finds one string in another. The pod's directory has its own path in
|
|
166
|
+
// front of each, and is taken not to come again within one, so that one
|
|
167
|
+
// is in the other where it is at its start. `budget` counts the matches
|
|
168
|
+
// made, across every clean of the pod.
|
|
169
|
+
export function clean(tree, accessors, licenseFile, budget) {
|
|
170
|
+
const list = new PathList(tree, budget)
|
|
171
|
+
const used = [...new Set(uniqueOf(accessors).flatMap((values) => usedFiles(list, values, licenseFile)).map(downcase))].sort()
|
|
172
|
+
const kept = (path) => path.endsWith('.') || sharesStart(used, downcase(path))
|
|
173
|
+
tree.removeAll(new Set(tree.paths.filter((one) => !kept(one))))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// lock_files!: the owner's write taken off each source file, by the file
|
|
177
|
+
// that a link among them leads to, as chmod follows it. A link that leads
|
|
178
|
+
// to nothing CocoaPods fails on, as File.stat does.
|
|
179
|
+
export function lock(tree, accessors, budget) {
|
|
180
|
+
const list = new PathList(tree, budget)
|
|
181
|
+
for (const path of new Set(uniqueOf(accessors).flatMap((values) => sourceFiles(list, values)))) {
|
|
182
|
+
const resolved = tree.resolve(path)
|
|
183
|
+
if (resolved === undefined) throw new DeptreeError(`the source file ${quote(path)} links to nothing, and CocoaPods fails on it as it makes it read-only`, tree.where)
|
|
184
|
+
if (resolved.node.type === 'file') resolved.node.mode &= ~0o200
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// How CocoaPods matches a podspec's file patterns against a pod's files:
|
|
2
|
+
// PathList's dir_glob_equivalent_patterns, its own expansion of braces,
|
|
3
|
+
// then Ruby's File.fnmatch with FNM_CASEFOLD and FNM_PATHNAME, as dir.c
|
|
4
|
+
// has it in Ruby 2.6 to 3.4. Each is followed step for step, quirks and
|
|
5
|
+
// all: a `*` stops at a `/`; a leading `.` of a name is matched by a `.`
|
|
6
|
+
// alone, and `**/` enters no directory whose name starts with one; case
|
|
7
|
+
// is folded for ASCII letters alone; and in a bracket, a character that is
|
|
8
|
+
// not one of it byte for byte is folded against the one after it in the
|
|
9
|
+
// pattern, so that `[a]` does not take `A` where `[ba]` does.
|
|
10
|
+
|
|
11
|
+
const NOMATCH = 1
|
|
12
|
+
|
|
13
|
+
// A character of `chars`, or '' past the end, where C reads the NUL.
|
|
14
|
+
const at = (chars, i) => chars[i] ?? ''
|
|
15
|
+
const upper = (char) => (char >= 'a' && char <= 'z' ? String.fromCodePoint(char.codePointAt(0) - 32) : char)
|
|
16
|
+
const point = (char) => char.codePointAt(0)
|
|
17
|
+
|
|
18
|
+
// bracket(): `p` is next to the `[`; the index past the `]`, or -1 where
|
|
19
|
+
// the bracket does not take the character at `s`, or never closes.
|
|
20
|
+
function bracket(P, p, S, s) {
|
|
21
|
+
if (p >= P.length) return -1
|
|
22
|
+
let not = false
|
|
23
|
+
let ok = false
|
|
24
|
+
if (P[p] === '!' || P[p] === '^') {
|
|
25
|
+
not = true
|
|
26
|
+
p++
|
|
27
|
+
}
|
|
28
|
+
while (at(P, p) !== ']') {
|
|
29
|
+
let t1 = p
|
|
30
|
+
if (at(P, t1) === '\\') t1++
|
|
31
|
+
if (at(P, t1) === '') return -1
|
|
32
|
+
p = t1 + 1
|
|
33
|
+
if (p >= P.length) return -1
|
|
34
|
+
if (P[p] === '-' && at(P, p + 1) !== ']') {
|
|
35
|
+
let t2 = p + 1
|
|
36
|
+
if (at(P, t2) === '\\') t2++
|
|
37
|
+
if (at(P, t2) === '') return -1
|
|
38
|
+
p = t2 + 1
|
|
39
|
+
if (ok) continue
|
|
40
|
+
if (P[t1] === S[s] || P[t2] === S[s]) {
|
|
41
|
+
ok = true
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
const c1 = point(upper(S[s]))
|
|
45
|
+
if (c1 < point(upper(P[t1])) || c1 > point(upper(P[t2]))) continue
|
|
46
|
+
} else {
|
|
47
|
+
if (ok) continue
|
|
48
|
+
if (P[t1] === S[s]) {
|
|
49
|
+
ok = true
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
// Ruby's own: against P[p], the character after this one.
|
|
53
|
+
if (upper(S[s]) !== upper(P[p])) continue
|
|
54
|
+
}
|
|
55
|
+
ok = true
|
|
56
|
+
}
|
|
57
|
+
return ok === not ? -1 : p + 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// fnmatch_helper(): one name of the path, up to a `/` or the end of each.
|
|
61
|
+
function helper(P, p0, S, s0) {
|
|
62
|
+
let p = p0
|
|
63
|
+
let s = s0
|
|
64
|
+
const end = (chars, i) => at(chars, i) === '' || at(chars, i) === '/'
|
|
65
|
+
const unescape = (i) => (at(P, i) === '\\' ? i + 1 : i)
|
|
66
|
+
let ptmp = -1
|
|
67
|
+
let stmp = -1
|
|
68
|
+
if (at(S, s) === '.' && at(P, unescape(p)) !== '.') return { r: NOMATCH, p, s }
|
|
69
|
+
for (;;) {
|
|
70
|
+
const char = at(P, p)
|
|
71
|
+
let failed = false
|
|
72
|
+
if (char === '*') {
|
|
73
|
+
do p++
|
|
74
|
+
while (at(P, p) === '*')
|
|
75
|
+
if (end(P, unescape(p))) return { r: 0, p: unescape(p), s }
|
|
76
|
+
if (end(S, s)) return { r: NOMATCH, p, s }
|
|
77
|
+
ptmp = p
|
|
78
|
+
stmp = s
|
|
79
|
+
continue
|
|
80
|
+
}
|
|
81
|
+
if (char === '?') {
|
|
82
|
+
if (end(S, s)) return { r: NOMATCH, p, s }
|
|
83
|
+
p++
|
|
84
|
+
s++
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
if (char === '[') {
|
|
88
|
+
if (end(S, s)) return { r: NOMATCH, p, s }
|
|
89
|
+
const t = bracket(P, p + 1, S, s)
|
|
90
|
+
if (t === -1) {
|
|
91
|
+
failed = true
|
|
92
|
+
} else {
|
|
93
|
+
p = t
|
|
94
|
+
s++
|
|
95
|
+
continue
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
p = unescape(p)
|
|
99
|
+
if (end(S, s)) return { r: end(P, p) ? 0 : NOMATCH, p, s }
|
|
100
|
+
if (!end(P, p) && (P[p] === S[s] || upper(P[p]) === upper(S[s]))) {
|
|
101
|
+
p++
|
|
102
|
+
s++
|
|
103
|
+
continue
|
|
104
|
+
}
|
|
105
|
+
failed = true
|
|
106
|
+
}
|
|
107
|
+
if (failed && ptmp !== -1) {
|
|
108
|
+
p = ptmp
|
|
109
|
+
stmp++
|
|
110
|
+
s = stmp
|
|
111
|
+
continue
|
|
112
|
+
}
|
|
113
|
+
return { r: NOMATCH, p, s }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// File.fnmatch(pattern, path, File::FNM_CASEFOLD | File::FNM_PATHNAME).
|
|
118
|
+
export const fnmatch = (pattern, path) => matcher(pattern)(path)
|
|
119
|
+
|
|
120
|
+
// fnmatch of one pattern, its characters read once for every path.
|
|
121
|
+
export function matcher(pattern) {
|
|
122
|
+
const P = Array.from(pattern)
|
|
123
|
+
return (path) => matches(P, Array.from(path))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function matches(P, S) {
|
|
127
|
+
let p = 0
|
|
128
|
+
let s = 0
|
|
129
|
+
let ptmp = -1
|
|
130
|
+
let stmp = -1
|
|
131
|
+
const recursive = (i) => at(P, i) === '*' && at(P, i + 1) === '*' && at(P, i + 2) === '/'
|
|
132
|
+
for (;;) {
|
|
133
|
+
if (recursive(p)) {
|
|
134
|
+
do p += 3
|
|
135
|
+
while (recursive(p))
|
|
136
|
+
ptmp = p
|
|
137
|
+
stmp = s
|
|
138
|
+
}
|
|
139
|
+
const result = helper(P, p, S, s)
|
|
140
|
+
p = result.p
|
|
141
|
+
s = result.s
|
|
142
|
+
if (result.r === 0) {
|
|
143
|
+
while (at(S, s) !== '' && at(S, s) !== '/') s++
|
|
144
|
+
if (at(P, p) !== '' && at(S, s) !== '') {
|
|
145
|
+
p++
|
|
146
|
+
s++
|
|
147
|
+
continue
|
|
148
|
+
}
|
|
149
|
+
if (at(P, p) === '' && at(S, s) === '') return true
|
|
150
|
+
}
|
|
151
|
+
if (ptmp !== -1 && at(S, stmp) !== '.') {
|
|
152
|
+
while (at(S, stmp) !== '' && at(S, stmp) !== '/') stmp++
|
|
153
|
+
if (at(S, stmp) !== '') {
|
|
154
|
+
p = ptmp
|
|
155
|
+
stmp++
|
|
156
|
+
s = stmp
|
|
157
|
+
continue
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return false
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Ruby's String#split by ',': empty strings at the end dropped, so that
|
|
165
|
+
// `{}` and `{,}` stand for no pattern at all.
|
|
166
|
+
function splitCommas(text) {
|
|
167
|
+
const values = text.split(',')
|
|
168
|
+
while (values.length > 0 && values.at(-1) === '') values.pop()
|
|
169
|
+
return values
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// More than this many patterns from one is refused, rather than matched,
|
|
173
|
+
// and so is a pattern longer than MAX_PATTERN, whose braces take time to
|
|
174
|
+
// find in proportion to its length squared.
|
|
175
|
+
export const MAX_EXPANDED = 4096
|
|
176
|
+
const MAX_PATTERN = 4096
|
|
177
|
+
|
|
178
|
+
// dir_glob_equivalent_patterns: each `/**/` as `{/**/,/}`, then each
|
|
179
|
+
// `{...}` with no `}` inside, by the text of it, replaced wherever that text
|
|
180
|
+
// is with each of the values between its commas, braces dropped from them,
|
|
181
|
+
// one set after another in the order each is first found. Ruby's gsub reads
|
|
182
|
+
// a backslash in a value as the start of a reference to the match; a
|
|
183
|
+
// pattern with one there, and one that comes to more than MAX_EXPANDED,
|
|
184
|
+
// is undefined, for the caller to refuse, before it is expanded.
|
|
185
|
+
export function expandBraces(pattern) {
|
|
186
|
+
if (pattern.length > MAX_PATTERN) return undefined
|
|
187
|
+
const rewritten = pattern.replaceAll('/**/', '{/**/,/}')
|
|
188
|
+
const sets = new Map()
|
|
189
|
+
for (const [set] of rewritten.matchAll(/\{[^}]*\}/gu)) {
|
|
190
|
+
if (!sets.has(set)) sets.set(set, splitCommas(set.replace(/[{}]/gu, '')))
|
|
191
|
+
}
|
|
192
|
+
let patterns = [rewritten]
|
|
193
|
+
for (const [set, values] of sets) {
|
|
194
|
+
if (values.some((value) => value.includes('\\')) || patterns.length * values.length > MAX_EXPANDED) return undefined
|
|
195
|
+
patterns = patterns.flatMap((old) => values.map((value) => old.replaceAll(set, () => value)))
|
|
196
|
+
}
|
|
197
|
+
return patterns
|
|
198
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// What buildCocoaPodsTree takes, as text or read from the project's root.
|
|
2
|
+
|
|
3
|
+
import { utf8fromString } from '@exodus/bytes/utf8.js'
|
|
4
|
+
import { DeptreeError, quote } from '../error.js'
|
|
5
|
+
import { checkHostKeys, checkLeftOut, checkProject, readBytes, readText, typeOf } from '../project.js'
|
|
6
|
+
import { isObject } from './podspec.js'
|
|
7
|
+
|
|
8
|
+
// CocoaPods 1.13.0 to 1.17.x, which download, clean and lock a pod alike
|
|
9
|
+
// but for one thing, which tree.js follows: 1.16 on copy a download into
|
|
10
|
+
// their cache with rsync, which leaves the clone's .git out, where those
|
|
11
|
+
// before use FileUtils.cp_r, which copies it.
|
|
12
|
+
const VERSION = /^1\.1[3-7]\.\d+$/u
|
|
13
|
+
|
|
14
|
+
export function checkHost(host) {
|
|
15
|
+
checkHostKeys(host, ['cocoapods', 'os'], 'cocoapods and os')
|
|
16
|
+
if (!VERSION.test(host.cocoapods)) throw new DeptreeError(`CocoaPods ${quote(host.cocoapods)} is not supported: only 1.13.0 to 1.17.x are`, 'host.cocoapods')
|
|
17
|
+
if (host.os !== 'darwin' && host.os !== 'linux') throw new DeptreeError(`${quote(host.os)} is not supported: only macOS and Linux are`, 'host.os')
|
|
18
|
+
return { cocoapods: host.cocoapods, os: host.os }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// What the Podfile's targets are for, as Platform names them, each once;
|
|
22
|
+
// undefined for any.
|
|
23
|
+
const PLATFORMS = new Set(['ios', 'osx', 'tvos', 'visionos', 'watchos'])
|
|
24
|
+
const PLATFORMS_TYPE = 'platforms must be a non-empty list of ios, osx, tvos, visionos and watchos, each once, or left out'
|
|
25
|
+
export function platformsOf(platforms) {
|
|
26
|
+
if (platforms === undefined) return undefined
|
|
27
|
+
if (!Array.isArray(platforms) || platforms.length === 0 || platforms.some((name) => !PLATFORMS.has(name)) || new Set(platforms).size !== platforms.length) throw new TypeError(PLATFORMS_TYPE)
|
|
28
|
+
return [...platforms]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// `manifest` and `partial`, each false unless given true.
|
|
32
|
+
export function flagsOf({ manifest = false, partial = false }) {
|
|
33
|
+
for (const [name, value] of Object.entries({ manifest, partial })) if (typeof value !== 'boolean') throw new TypeError(`${name} must be a boolean, or left out`)
|
|
34
|
+
return { manifest, partial }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The names CocoaPods reads a Podfile under, the first one there taken.
|
|
38
|
+
const PODFILES = ['CocoaPods.podfile.yaml', 'CocoaPods.podfile', 'Podfile', 'Podfile.rb']
|
|
39
|
+
|
|
40
|
+
const LOCKFILE = 'lockfile must be the Podfile.lock text, or left out where project is given'
|
|
41
|
+
|
|
42
|
+
// The podspecs of pods by :podspec, as CocoaPods writes each in Pods/Local
|
|
43
|
+
// Podspecs, by name: those given, as text or bytes, or else those in the
|
|
44
|
+
// project's Pods/Local Podspecs; undefined for one neither has.
|
|
45
|
+
const PODSPECS = 'podspecs must be an object of podspecs by name, each as text or bytes, or left out'
|
|
46
|
+
function podspecsOf(podspecs, project) {
|
|
47
|
+
if (podspecs !== undefined) {
|
|
48
|
+
if (!isObject(podspecs)) throw new TypeError(PODSPECS)
|
|
49
|
+
const given = new Map(Object.entries(podspecs))
|
|
50
|
+
for (const value of given.values()) if (!(typeof value === 'string' ? value.isWellFormed() : value instanceof Uint8Array)) throw new TypeError(PODSPECS)
|
|
51
|
+
return (name) => {
|
|
52
|
+
const value = given.get(name)
|
|
53
|
+
return typeof value === 'string' ? utf8fromString(value) : value
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (project === undefined) return () => undefined
|
|
57
|
+
return (name) => {
|
|
58
|
+
const path = `/Pods/Local Podspecs/${name}.podspec.json`
|
|
59
|
+
return typeOf(project, path) === 'file' ? readBytes(project, path) : undefined
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function inputsOf(options) {
|
|
64
|
+
const { lockfile, podfile, project } = options
|
|
65
|
+
const podspecs = podspecsOf(options.podspecs, project)
|
|
66
|
+
if (lockfile === undefined) {
|
|
67
|
+
if (project === undefined) throw new TypeError(LOCKFILE)
|
|
68
|
+
checkProject(project)
|
|
69
|
+
checkLeftOut({ podfile }, 'both')
|
|
70
|
+
const lock = readText(project, '/Podfile.lock', 'Podfile.lock')
|
|
71
|
+
if (lock === undefined) throw new DeptreeError('the project has no Podfile.lock, without which CocoaPods resolves each pod anew')
|
|
72
|
+
const name = PODFILES.find((candidate) => typeOf(project, `/${candidate}`) === 'file')
|
|
73
|
+
if (name === undefined) throw new DeptreeError(`the project has no Podfile, as ${PODFILES.join(', ')}, without which CocoaPods installs nothing`)
|
|
74
|
+
return { lockfile: lock, podfile: readBytes(project, `/${name}`), podspecs }
|
|
75
|
+
}
|
|
76
|
+
if (typeof lockfile !== 'string') throw new TypeError(LOCKFILE)
|
|
77
|
+
if (project !== undefined) throw new TypeError('project must be left out where lockfile is given')
|
|
78
|
+
if (podfile !== undefined && typeof podfile !== 'string' && !(podfile instanceof Uint8Array)) throw new TypeError('podfile must be the Podfile, as text or bytes, or left out')
|
|
79
|
+
return { lockfile, podfile, podspecs }
|
|
80
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// A downloaded pod's directory as `pod install` leaves it in Pods/: cleaned
|
|
2
|
+
// once in CocoaPods' download cache, for every spec of the podspec on every
|
|
3
|
+
// platform each takes; copied into Pods/; cleaned again there, for the
|
|
4
|
+
// specs installed; and its source files made read-only.
|
|
5
|
+
|
|
6
|
+
import { DeptreeError, quote } from '../error.js'
|
|
7
|
+
import { clean, lock } from './clean.js'
|
|
8
|
+
import { PodTree } from './podtree.js'
|
|
9
|
+
import { allSpecs, consumerOf, licenseFileOf, platformsOf } from './podspec.js'
|
|
10
|
+
|
|
11
|
+
// What a spec's file patterns come to on each platform it takes, of
|
|
12
|
+
// `platforms` where they are given. The lockfile does not say which of
|
|
13
|
+
// them a pod was installed for, so a spec installed is held to name the
|
|
14
|
+
// same files on each.
|
|
15
|
+
function uniformConsumer(spec, platforms, where) {
|
|
16
|
+
const taken = platformsOf(spec, where).filter((platform) => platforms?.includes(platform) ?? true)
|
|
17
|
+
if (taken.length === 0) throw new DeptreeError(`${quote(spec.name)} is for none of the platforms given`, where)
|
|
18
|
+
const [first, ...others] = taken.map((platform) => [platform, consumerOf(spec, platform, where)])
|
|
19
|
+
const shown = JSON.stringify(first[1])
|
|
20
|
+
const other = others.find(([, values]) => JSON.stringify(values) !== shown)
|
|
21
|
+
if (other !== undefined) {
|
|
22
|
+
const which = platforms === undefined ? 'and the platforms it is installed for are not given' : 'and the lockfile does not say which of the platforms given it is installed for'
|
|
23
|
+
throw new DeptreeError(`${quote(spec.name)} names other files on ${other[0]} than on ${first[0]}, ${which}`, where)
|
|
24
|
+
}
|
|
25
|
+
return first[1]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// What a pod's podspec says of the files CocoaPods keeps of it, read and
|
|
29
|
+
// checked whole before anything is downloaded: the license file it names,
|
|
30
|
+
// the consumerOf values of every spec on every platform each takes, for
|
|
31
|
+
// the clean in the download cache, and of the specs installed, for the
|
|
32
|
+
// clean in Pods/. `installed` are the specs of `podspec` the lockfile has,
|
|
33
|
+
// and `platforms` those the Podfile's targets are for, or undefined for
|
|
34
|
+
// any.
|
|
35
|
+
export function planPod(podspec, installed, platforms, where) {
|
|
36
|
+
return {
|
|
37
|
+
license: licenseFileOf(podspec, where),
|
|
38
|
+
every: allSpecs(podspec).flatMap((spec) => platformsOf(spec, where).map((platform) => consumerOf(spec, platform, where))),
|
|
39
|
+
used: installed.map((spec) => uniformConsumer(spec, platforms, where)),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The download, `contents` as writeFiles takes them, as planPod's `plan`
|
|
44
|
+
// leaves it. `folded` where the pod is on macOS; `keepsGit` where the
|
|
45
|
+
// download is a clone, whose .git CocoaPods copies into its cache with the
|
|
46
|
+
// rest, as 1.13 to 1.15 do, which is refused where the clean there keeps
|
|
47
|
+
// it, as what is in it is not known; an archive has none.
|
|
48
|
+
export function installPod(contents, plan, { folded, keepsGit, where }) {
|
|
49
|
+
const tree = new PodTree(keepsGit ? { ...contents, dirs: [...contents.dirs, '.git'] } : contents, folded, where)
|
|
50
|
+
const budget = { matches: 0 }
|
|
51
|
+
// Downloader::Cache#copy_and_clean, its group_subspecs_by_platform. Its
|
|
52
|
+
// copy into Pods/, FileUtils.cp_r under a umask of 0o022, keeps the modes
|
|
53
|
+
// a download has, a checkout's 0o644 and 0o755 or an archive's under that
|
|
54
|
+
// umask as tar extracts it.
|
|
55
|
+
clean(tree, plan.every, plan.license, budget)
|
|
56
|
+
if (tree.nodes.has('.git')) throw new DeptreeError('its file patterns keep the .git of the clone, which CocoaPods before 1.16 copies into its cache, and which is not built', where)
|
|
57
|
+
// PodSourceInstaller#clean!, then Installer#lock_pod_sources.
|
|
58
|
+
clean(tree, plan.used, plan.license, budget)
|
|
59
|
+
lock(tree, plan.used, budget)
|
|
60
|
+
return tree.contents()
|
|
61
|
+
}
|