@jskit-ai/jskit-catalog 0.2.147 → 0.2.148
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/catalog/packages.json +274 -273
- package/package.json +1 -1
- package/scripts/capacitor.mjs +663 -0
- package/scripts/data-access-files.mjs +4 -3
- package/scripts/jskit.mjs +33 -54
- package/scripts/project-check.mjs +69 -0
- package/scripts/project-manifests.mjs +80 -1
- package/scripts/project-packages.mjs +134 -28
- package/scripts/verify.mjs +73 -9
package/package.json
CHANGED
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileExists, toPosixPath } from "./files.mjs";
|
|
4
|
+
|
|
5
|
+
// The Capacitor part of `jskit check`, and the update's refusal: an app whose JSKIT packages need Capacitor (the
|
|
6
|
+
// catalog's packages that depend on @capacitor/core, such as @jskit-ai/mobile-capacitor) must be on that Capacitor
|
|
7
|
+
// major in its own packages and in the native projects Capacitor made for it (android/, ios/). Those projects are
|
|
8
|
+
// app-owned source that `npx cap add` wrote once from the Capacitor of that day, so a JSKIT update cannot move them;
|
|
9
|
+
// Capacitor's own `npx cap migrate` does, and what it leaves the app changes by hand. Read from files, never run.
|
|
10
|
+
|
|
11
|
+
const CORE_PACKAGE = "@capacitor/core";
|
|
12
|
+
const DEPENDENCY_FIELDS = Object.freeze(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]);
|
|
13
|
+
|
|
14
|
+
// The packages `npx cap migrate` moves with the major (@capacitor/cli 9.0.0's migrate task, its libs and plugins):
|
|
15
|
+
// Capacitor's own, released at Capacitor's majors. The plugins it moves to ranges of their own (inappbrowser and the like)
|
|
16
|
+
// are not among them.
|
|
17
|
+
// Capacitor's own libraries, whose major is the app's Capacitor major.
|
|
18
|
+
const CAPACITOR_LIBRARIES = Object.freeze(["@capacitor/core", "@capacitor/cli", "@capacitor/ios", "@capacitor/android"]);
|
|
19
|
+
const CAPACITOR_PACKAGES = Object.freeze([
|
|
20
|
+
...CAPACITOR_LIBRARIES,
|
|
21
|
+
"@capacitor/action-sheet", "@capacitor/app", "@capacitor/app-launcher", "@capacitor/browser", "@capacitor/camera",
|
|
22
|
+
"@capacitor/clipboard", "@capacitor/device", "@capacitor/dialog", "@capacitor/filesystem", "@capacitor/geolocation",
|
|
23
|
+
"@capacitor/google-maps", "@capacitor/haptics", "@capacitor/keyboard", "@capacitor/local-notifications",
|
|
24
|
+
"@capacitor/motion", "@capacitor/network", "@capacitor/preferences", "@capacitor/push-notifications",
|
|
25
|
+
"@capacitor/screen-orientation", "@capacitor/screen-reader", "@capacitor/share", "@capacitor/splash-screen",
|
|
26
|
+
"@capacitor/status-bar", "@capacitor/text-zoom", "@capacitor/toast"
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
// What the Capacitor major JSKIT's packages need asks of an app, from its upgrade guide and its CLI's templates. Each
|
|
30
|
+
// version is the least the app may have.
|
|
31
|
+
const REQUIREMENTS = Object.freeze({
|
|
32
|
+
9: Object.freeze({
|
|
33
|
+
guide: "https://capacitorjs.com/docs/updating/9-0",
|
|
34
|
+
node: 24,
|
|
35
|
+
jdk: 21,
|
|
36
|
+
android: Object.freeze({
|
|
37
|
+
// android/variables.gradle, the guide's "new minimums" (required). targetSdkVersion 37 is above Google Play's floor
|
|
38
|
+
// of 36 for new apps and updates since 31 August 2026.
|
|
39
|
+
variables: Object.freeze({
|
|
40
|
+
minSdkVersion: "26",
|
|
41
|
+
compileSdkVersion: "37",
|
|
42
|
+
targetSdkVersion: "37",
|
|
43
|
+
androidxActivityVersion: "1.13.0",
|
|
44
|
+
androidxAppCompatVersion: "1.8.0",
|
|
45
|
+
androidxCoordinatorLayoutVersion: "1.3.0",
|
|
46
|
+
androidxCoreVersion: "1.19.1",
|
|
47
|
+
androidxFragmentVersion: "1.9.1",
|
|
48
|
+
coreSplashScreenVersion: "1.2.0",
|
|
49
|
+
androidxWebkitVersion: "1.17.1",
|
|
50
|
+
junitVersion: "4.13.2",
|
|
51
|
+
androidxJunitVersion: "1.3.0",
|
|
52
|
+
androidxEspressoCoreVersion: "3.7.0",
|
|
53
|
+
cordovaAndroidVersion: "15.1.0"
|
|
54
|
+
}),
|
|
55
|
+
// The plugins' variables, which the guide says "has been updated to" (recommended), where the app has them.
|
|
56
|
+
pluginVariables: Object.freeze({
|
|
57
|
+
androidxBrowserVersion: "1.10.0",
|
|
58
|
+
androidxMaterialVersion: "1.14.0",
|
|
59
|
+
androidxExifInterfaceVersion: "1.4.2",
|
|
60
|
+
androidxCoreKTXVersion: "1.19.1",
|
|
61
|
+
firebaseMessagingVersion: "25.0.1",
|
|
62
|
+
playServicesLocationVersion: "21.4.0",
|
|
63
|
+
googleMapsPlayServicesVersion: "20.1.0",
|
|
64
|
+
googleMapsUtilsVersion: "5.0.0",
|
|
65
|
+
googleMapsKtxVersion: "6.0.1",
|
|
66
|
+
googleMapsUtilsKtxVersion: "6.0.1",
|
|
67
|
+
kotlinxCoroutinesVersion: "1.11.0"
|
|
68
|
+
}),
|
|
69
|
+
// Gradle and AGP are the guide's upgrade steps, which Capacitor 9's plugins need (required); google-services is an
|
|
70
|
+
// update the guide gives no reason for (recommended).
|
|
71
|
+
gradle: "9.8.2",
|
|
72
|
+
androidGradlePlugin: "9.4.1",
|
|
73
|
+
googleServices: "4.5.0",
|
|
74
|
+
configChange: "density",
|
|
75
|
+
// Lines that break a Capacitor 9 build, as the guide says of each (required), with where each is read and what
|
|
76
|
+
// replaces it.
|
|
77
|
+
removedLines: Object.freeze([
|
|
78
|
+
Object.freeze({
|
|
79
|
+
file: "build.gradle",
|
|
80
|
+
pattern: /org\.jetbrains\.kotlin:kotlin-gradle-plugin/u,
|
|
81
|
+
message: "The Kotlin Gradle Plugin is applied by hand; AGP 9 bundles Kotlin (2.2.10): remove its classpath."
|
|
82
|
+
}),
|
|
83
|
+
Object.freeze({
|
|
84
|
+
file: "app/build.gradle",
|
|
85
|
+
pattern: /apply plugin:\s*['"](?:kotlin-android|org\.jetbrains\.kotlin\.android)['"]|id\s*\(?\s*['"](?:kotlin-android|org\.jetbrains\.kotlin\.android)['"]/u,
|
|
86
|
+
message: "The kotlin-android plugin is applied by hand; AGP 9 bundles Kotlin (2.2.10): remove it."
|
|
87
|
+
}),
|
|
88
|
+
Object.freeze({
|
|
89
|
+
file: "app/build.gradle",
|
|
90
|
+
pattern: /org\.jetbrains\.kotlin:kotlin-stdlib/u,
|
|
91
|
+
message: "kotlin-stdlib is a dependency by hand; AGP 9 bundles Kotlin (2.2.10): remove it."
|
|
92
|
+
}),
|
|
93
|
+
Object.freeze({ file: "build.gradle", pattern: /\bjcenter\s*\(\s*\)/u, message: "jcenter() is gone in Gradle 9: use mavenCentral()." }),
|
|
94
|
+
Object.freeze({ file: "app/build.gradle", pattern: /\bjcenter\s*\(\s*\)/u, message: "jcenter() is gone in Gradle 9: use mavenCentral()." }),
|
|
95
|
+
Object.freeze({
|
|
96
|
+
file: "settings.gradle",
|
|
97
|
+
pattern: /capacitor-cordova-android-plugins/u,
|
|
98
|
+
message: "capacitor-cordova-android-plugins is named by hand; Capacitor 9 includes it through " +
|
|
99
|
+
"capacitor.settings.gradle only when a Cordova plugin is installed: remove these lines."
|
|
100
|
+
}),
|
|
101
|
+
Object.freeze({
|
|
102
|
+
file: "app/build.gradle",
|
|
103
|
+
pattern: /capacitor-cordova-android-plugins/u,
|
|
104
|
+
message: "capacitor-cordova-android-plugins is named by hand; Capacitor 9 includes it through " +
|
|
105
|
+
"capacitor.build.gradle only when a Cordova plugin is installed: remove these lines (and re-add " +
|
|
106
|
+
"repositories { flatDir { dirs 'libs' } } if the app uses .aar files in app/libs)."
|
|
107
|
+
}),
|
|
108
|
+
Object.freeze({
|
|
109
|
+
file: "app/build.gradle",
|
|
110
|
+
pattern: /proguard-android\.txt/u,
|
|
111
|
+
message: "proguard-android.txt is gone in AGP 9: use proguard-android-optimize.txt."
|
|
112
|
+
})
|
|
113
|
+
]),
|
|
114
|
+
// gradle.properties flags the AGP Upgrade Assistant added, which the guide calls deprecated (recommended) but for two
|
|
115
|
+
// values that "actively break a Capacitor 9 build" (breakingProperties, required).
|
|
116
|
+
breakingProperties: Object.freeze({
|
|
117
|
+
"android.builtInKotlin": "false",
|
|
118
|
+
"android.sdk.defaultTargetSdkToCompileSdkIfUnset": "false"
|
|
119
|
+
}),
|
|
120
|
+
removedProperties: Object.freeze([
|
|
121
|
+
"android.builtInKotlin", "android.defaults.buildfeatures.resvalues", "android.dependency.useConstraints",
|
|
122
|
+
"android.enableAppCompileTimeRClass", "android.newDsl", "android.r8.optimizedResourceShrinking",
|
|
123
|
+
"android.r8.strictFullModeForKeepRules", "android.sdk.defaultTargetSdkToCompileSdkIfUnset",
|
|
124
|
+
"android.uniquePackageNames", "android.usesSdkInManifest.disallowed"
|
|
125
|
+
]),
|
|
126
|
+
// The bridge activity calls EdgeToEdge.enable(this) (Java) or enableEdgeToEdge() (Kotlin) after super.onCreate,
|
|
127
|
+
// which System Bars' insets "rely on" (required), unless the Capacitor config turns its insets handling off.
|
|
128
|
+
edgeToEdge: /\bEdgeToEdge\.enable\s*\(|\benableEdgeToEdge\s*\(/u
|
|
129
|
+
}),
|
|
130
|
+
ios: Object.freeze({
|
|
131
|
+
deploymentTarget: "16.0",
|
|
132
|
+
// "Every app needs" a SwiftUI entry point (required): a file of the app target that declares an @main SwiftUI App.
|
|
133
|
+
// CAPACITOR_DEBUG is "unused" (recommended).
|
|
134
|
+
swiftUiEntry: /@main\s+(?:@\w+\s+)*struct\s+\w+\s*:\s*(?:SwiftUI\.)?App\b/u,
|
|
135
|
+
debugSetting: "CAPACITOR_DEBUG"
|
|
136
|
+
}),
|
|
137
|
+
// Capacitor config options a major removed, with what replaces them.
|
|
138
|
+
removedConfig: Object.freeze({
|
|
139
|
+
adjustMarginsForEdgeToEdge: "android.adjustMarginsForEdgeToEdge is gone since Capacitor 8: remove it, and lay out " +
|
|
140
|
+
"edge to edge with the System Bars core plugin and CSS env(safe-area-inset-*)."
|
|
141
|
+
}),
|
|
142
|
+
// config.mobile.android in config/public.js, as the foundation patterns write it.
|
|
143
|
+
appConfig: Object.freeze({ minSdk: "26", targetSdk: "37" }),
|
|
144
|
+
// Google Play takes new apps and updates only at this targetSdkVersion or higher, since 31 August 2026.
|
|
145
|
+
playTargetSdk: "36"
|
|
146
|
+
})
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
function compareVersions(left, right) {
|
|
150
|
+
const a = String(left).split(".").map(Number);
|
|
151
|
+
const b = String(right).split(".").map(Number);
|
|
152
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
153
|
+
const difference = (a[index] || 0) - (b[index] || 0);
|
|
154
|
+
if (difference !== 0) return difference < 0 ? -1 : 1;
|
|
155
|
+
}
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// The major a dependency spec asks for: 8 for "^8.6.3", "~8.0.0", "8.x" or ">=8.0.0". null for a local or remote
|
|
160
|
+
// source (file:, link:, git, a URL, an npm alias), which this check leaves alone, and NaN for anything else ("latest",
|
|
161
|
+
// "*"), which names no major.
|
|
162
|
+
function specMajor(spec) {
|
|
163
|
+
const text = String(spec || "").trim();
|
|
164
|
+
if (/^(?:file|link|workspace|git|git\+\w+|github|https?|npm):/u.test(text) || /^[\w.-]+\/[\w.-]+/u.test(text)) return null;
|
|
165
|
+
const match = /^(?:\^|~|>=|=)?\s*v?(\d+)(?:\.|$)/u.exec(text);
|
|
166
|
+
return match ? Number(match[1]) : Number.NaN;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// The Capacitor the catalog's packages need: the @capacitor/core range they declare, its major, and every catalog package
|
|
170
|
+
// that needs it, directly or through another JSKIT package it depends on. null when none does.
|
|
171
|
+
function capacitorRequirement(catalog) {
|
|
172
|
+
const entries = Array.isArray(catalog?.packages) ? catalog.packages : [];
|
|
173
|
+
const ranges = new Set();
|
|
174
|
+
const requiredBy = new Set();
|
|
175
|
+
for (const entry of entries) {
|
|
176
|
+
const range = entry?.packageJson?.dependencies?.[CORE_PACKAGE];
|
|
177
|
+
if (!range) continue;
|
|
178
|
+
ranges.add(range);
|
|
179
|
+
requiredBy.add(entry.packageId);
|
|
180
|
+
}
|
|
181
|
+
if (ranges.size < 1) return null;
|
|
182
|
+
const majors = new Set([...ranges].map(specMajor));
|
|
183
|
+
if (majors.size > 1) {
|
|
184
|
+
throw new Error(`JSKIT catalog requires ${CORE_PACKAGE} at several majors: ${[...ranges].sort().join(", ")}.`);
|
|
185
|
+
}
|
|
186
|
+
const major = [...majors][0];
|
|
187
|
+
if (!REQUIREMENTS[major]) {
|
|
188
|
+
throw new Error(`JSKIT catalog requires ${CORE_PACKAGE} ${[...ranges][0]}, a Capacitor major this check has no requirements for.`);
|
|
189
|
+
}
|
|
190
|
+
for (let grew = true; grew;) {
|
|
191
|
+
grew = false;
|
|
192
|
+
for (const entry of entries) {
|
|
193
|
+
const dependencies = Object.keys({ ...entry?.packageJson?.dependencies, ...entry?.packageJson?.peerDependencies });
|
|
194
|
+
if (!requiredBy.has(entry?.packageId) && dependencies.some((dependency) => requiredBy.has(dependency))) {
|
|
195
|
+
requiredBy.add(entry.packageId);
|
|
196
|
+
grew = true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const directEntries = entries.filter((entry) => entry?.packageJson?.dependencies?.[CORE_PACKAGE]);
|
|
201
|
+
// The Capacitor plugins those packages call, such as @capacitor/browser: npx cap sync builds a plugin's native code only
|
|
202
|
+
// when the app's own package.json lists it, so the app declares each one itself.
|
|
203
|
+
const plugins = new Map();
|
|
204
|
+
for (const entry of directEntries) {
|
|
205
|
+
for (const [name, pluginRange] of Object.entries(entry.packageJson.dependencies)) {
|
|
206
|
+
if (name.startsWith("@capacitor/") && name !== CORE_PACKAGE) plugins.set(name, { range: pluginRange, usedBy: entry.packageId });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return Object.freeze({
|
|
210
|
+
major,
|
|
211
|
+
// The highest floor among them, which satisfies them all within the major.
|
|
212
|
+
range: [...ranges].sort((left, right) => compareVersions(left.replace(/^\D+/u, ""), right.replace(/^\D+/u, ""))).at(-1),
|
|
213
|
+
requiredBy,
|
|
214
|
+
direct: directEntries.map((entry) => entry.packageId).sort(),
|
|
215
|
+
plugins,
|
|
216
|
+
requirements: REQUIREMENTS[major]
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function lineAt(text, index) {
|
|
221
|
+
return text.slice(0, index).split("\n").length;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function readOptional(absolutePath) {
|
|
225
|
+
try {
|
|
226
|
+
return await readFile(absolutePath, "utf8");
|
|
227
|
+
} catch (error) {
|
|
228
|
+
if (error?.code === "ENOENT" || error?.code === "EISDIR") return null;
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// capacitor.config.json, .ts or .js: its file, its text, and the native project paths a JSON config sets.
|
|
234
|
+
async function readCapacitorConfig(root) {
|
|
235
|
+
for (const name of ["capacitor.config.json", "capacitor.config.ts", "capacitor.config.js", "capacitor.config.mjs"]) {
|
|
236
|
+
const text = await readOptional(path.join(root, name));
|
|
237
|
+
if (text === null) continue;
|
|
238
|
+
let android = "android";
|
|
239
|
+
let ios = "ios";
|
|
240
|
+
if (name.endsWith(".json")) {
|
|
241
|
+
try {
|
|
242
|
+
const value = JSON.parse(text);
|
|
243
|
+
android = String(value?.android?.path || android);
|
|
244
|
+
ios = String(value?.ios?.path || ios);
|
|
245
|
+
} catch {
|
|
246
|
+
// The pattern's example is adapted into valid JSON; one that is not still has its text read below.
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return { file: name, text, android, ios };
|
|
250
|
+
}
|
|
251
|
+
return { file: "", text: "", android: "android", ios: "ios" };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function packageFindings({ manifests, root, lockPackages, requirement, native }) {
|
|
255
|
+
const findings = [];
|
|
256
|
+
const { major, range } = requirement;
|
|
257
|
+
if (native) {
|
|
258
|
+
const declared = new Set(manifests.flatMap((manifest) =>
|
|
259
|
+
Object.keys({ ...manifest.value?.dependencies, ...manifest.value?.devDependencies })));
|
|
260
|
+
for (const [name, { range: pluginRange, usedBy }] of requirement.plugins) {
|
|
261
|
+
if (declared.has(name)) continue;
|
|
262
|
+
findings.push({
|
|
263
|
+
file: "package.json",
|
|
264
|
+
rule: "capacitor/packages",
|
|
265
|
+
required: false,
|
|
266
|
+
message: `${name} is not a dependency of the app; ${usedBy} calls its native plugin, and npx cap sync builds only ` +
|
|
267
|
+
`the plugins the app's package.json lists. Run npm install ${name}@${pluginRange}.`
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
for (const manifest of manifests) {
|
|
272
|
+
const source = toPosixPath(path.relative(root, manifest.absolutePath)) || "package.json";
|
|
273
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
274
|
+
for (const name of CAPACITOR_PACKAGES) {
|
|
275
|
+
const spec = manifest.value?.[field]?.[name];
|
|
276
|
+
if (spec === undefined) continue;
|
|
277
|
+
const declared = specMajor(spec);
|
|
278
|
+
if (declared === null || declared === major) continue;
|
|
279
|
+
findings.push({
|
|
280
|
+
file: source,
|
|
281
|
+
rule: "capacitor/packages",
|
|
282
|
+
required: true,
|
|
283
|
+
message: `${field}.${name} is ${spec}; JSKIT's packages need Capacitor ${major} (${CORE_PACKAGE} ${range}), and ` +
|
|
284
|
+
`every Capacitor package of an app moves with its major.`
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const copies = Object.entries(lockPackages)
|
|
290
|
+
.filter(([packagePath, record]) => record && !record.link &&
|
|
291
|
+
(packagePath === `node_modules/${CORE_PACKAGE}` || packagePath.endsWith(`/node_modules/${CORE_PACKAGE}`)));
|
|
292
|
+
if (copies.length > 1) {
|
|
293
|
+
// A copy inside an @jskit-ai package is that package's own dependency, which JSKIT's update replaces.
|
|
294
|
+
const nested = copies.filter(([packagePath]) => packagePath !== `node_modules/${CORE_PACKAGE}`);
|
|
295
|
+
const insideJskit = nested.every(([packagePath]) => packagePath.startsWith("node_modules/@jskit-ai/"));
|
|
296
|
+
findings.push({
|
|
297
|
+
file: "package-lock.json",
|
|
298
|
+
rule: "capacitor/packages",
|
|
299
|
+
required: false,
|
|
300
|
+
message: `${CORE_PACKAGE} is installed ${copies.length} times (${copies.map(([packagePath, record]) =>
|
|
301
|
+
`${record.version} at ${packagePath}`).join(", ")}); Capacitor's bridge and plugins need one copy. ` +
|
|
302
|
+
(insideJskit
|
|
303
|
+
? "The copies inside @jskit-ai packages go when npm run jskit:update installs the JSKIT release that needs " +
|
|
304
|
+
`Capacitor ${major}.`
|
|
305
|
+
: `Run npm install ${CORE_PACKAGE}@${range}.`)
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
return findings;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function configFindings(config, { requirements }) {
|
|
312
|
+
const findings = [];
|
|
313
|
+
if (!config.file) return findings;
|
|
314
|
+
for (const [option, message] of Object.entries(requirements.removedConfig)) {
|
|
315
|
+
const index = config.text.search(new RegExp(String.raw`\b${option}\b`, "u"));
|
|
316
|
+
if (index >= 0) {
|
|
317
|
+
findings.push({ file: config.file, line: lineAt(config.text, index), rule: "capacitor/config", required: false, message });
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return findings;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// config.mobile.android's minSdk and targetSdk, as config/public.js writes them in the foundation patterns.
|
|
324
|
+
async function appConfigFindings(root, { major, requirements }) {
|
|
325
|
+
const file = "config/public.js";
|
|
326
|
+
const text = await readOptional(path.join(root, file));
|
|
327
|
+
if (text === null) return [];
|
|
328
|
+
const findings = [];
|
|
329
|
+
for (const [key, least] of Object.entries(requirements.appConfig)) {
|
|
330
|
+
for (const match of text.matchAll(new RegExp(String.raw`\b${key}\s*:\s*(\d+)`, "gu"))) {
|
|
331
|
+
if (compareVersions(match[1], least) >= 0) continue;
|
|
332
|
+
findings.push({
|
|
333
|
+
file,
|
|
334
|
+
line: lineAt(text, match.index),
|
|
335
|
+
rule: "capacitor/config",
|
|
336
|
+
required: false,
|
|
337
|
+
message: `config.mobile.android.${key} is ${match[1]}; Capacitor ${major} needs ${least} or higher` +
|
|
338
|
+
(key === "targetSdk" && compareVersions(match[1], requirements.playTargetSdk) < 0
|
|
339
|
+
? `, and Google Play takes new apps and updates only at ${requirements.playTargetSdk} or higher.`
|
|
340
|
+
: ".")
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return findings;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// A Capacitor Android project: `npx cap add android` writes capacitor.settings.gradle beside variables.gradle.
|
|
348
|
+
async function hasAndroidProject(base) {
|
|
349
|
+
return await fileExists(path.join(base, "capacitor.settings.gradle")) || fileExists(path.join(base, "variables.gradle"));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// The app's activities that extend Capacitor's BridgeActivity, each with its path below the Android project and its text.
|
|
353
|
+
async function bridgeActivities(base) {
|
|
354
|
+
const activities = [];
|
|
355
|
+
const visit = async (directory) => {
|
|
356
|
+
let entries;
|
|
357
|
+
try {
|
|
358
|
+
entries = await readdir(path.join(base, directory), { withFileTypes: true });
|
|
359
|
+
} catch (error) {
|
|
360
|
+
if (error?.code === "ENOENT" || error?.code === "ENOTDIR") return;
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
364
|
+
const relative = path.join(directory, entry.name);
|
|
365
|
+
if (entry.isDirectory()) {
|
|
366
|
+
await visit(relative);
|
|
367
|
+
} else if (/\.(?:java|kt)$/u.test(entry.name)) {
|
|
368
|
+
const text = await readFile(path.join(base, relative), "utf8");
|
|
369
|
+
if (/\bextends\s+BridgeActivity\b|:\s*BridgeActivity\s*\(/u.test(text)) activities.push({ file: relative, text });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
await visit(path.join("app", "src", "main", "java"));
|
|
374
|
+
await visit(path.join("app", "src", "main", "kotlin"));
|
|
375
|
+
return activities;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
async function androidFindings(root, directory, { major, requirements }, config) {
|
|
379
|
+
const android = requirements.android;
|
|
380
|
+
const base = path.join(root, directory);
|
|
381
|
+
const relative = (file) => toPosixPath(path.join(directory, file));
|
|
382
|
+
if (!(await hasAndroidProject(base))) return [];
|
|
383
|
+
const byFile = new Map();
|
|
384
|
+
const add = (file, text, index, required, message) => {
|
|
385
|
+
const list = byFile.get(file) || [];
|
|
386
|
+
list.push({
|
|
387
|
+
file: relative(file),
|
|
388
|
+
line: index === null ? undefined : lineAt(text, index),
|
|
389
|
+
rule: "capacitor/android",
|
|
390
|
+
required,
|
|
391
|
+
message
|
|
392
|
+
});
|
|
393
|
+
byFile.set(file, list);
|
|
394
|
+
};
|
|
395
|
+
const below = (file, text, index, required, what, found, least) =>
|
|
396
|
+
add(file, text, index, required, `${what} is ${found}; Capacitor ${major} needs ${least} or higher.`);
|
|
397
|
+
const texts = new Map();
|
|
398
|
+
const read = async (file) => {
|
|
399
|
+
if (!texts.has(file)) texts.set(file, await readOptional(path.join(base, file)));
|
|
400
|
+
return texts.get(file);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
const variables = await read("variables.gradle");
|
|
404
|
+
if (variables !== null) {
|
|
405
|
+
for (const match of variables.matchAll(/^[ \t]*(\w+)[ \t]*=[ \t]*['"]?(\d+(?:\.\d+)*)['"]?[ \t]*$/gmu)) {
|
|
406
|
+
const required = Object.hasOwn(android.variables, match[1]);
|
|
407
|
+
const least = required ? android.variables[match[1]] : android.pluginVariables[match[1]];
|
|
408
|
+
if (least && compareVersions(match[2], least) < 0) {
|
|
409
|
+
below("variables.gradle", variables, match.index, required, match[1], match[2], least);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const wrapperFile = "gradle/wrapper/gradle-wrapper.properties";
|
|
415
|
+
const wrapper = await read(wrapperFile);
|
|
416
|
+
const gradle = wrapper === null ? null : /gradle-(\d+(?:\.\d+)*)-(?:all|bin)\.zip/u.exec(wrapper);
|
|
417
|
+
if (gradle && compareVersions(gradle[1], android.gradle) < 0) {
|
|
418
|
+
below(wrapperFile, wrapper, gradle.index, true, "The Gradle wrapper", gradle[1], android.gradle);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const build = await read("build.gradle");
|
|
422
|
+
if (build !== null) {
|
|
423
|
+
const pins = [
|
|
424
|
+
[/com\.android\.tools\.build:gradle:(\d+(?:\.\d+)*)/gu, true, "The Android Gradle Plugin", android.androidGradlePlugin],
|
|
425
|
+
[/com\.google\.gms:google-services:(\d+(?:\.\d+)*)/gu, false, "com.google.gms:google-services", android.googleServices]
|
|
426
|
+
];
|
|
427
|
+
for (const [pattern, required, what, least] of pins) {
|
|
428
|
+
for (const match of build.matchAll(pattern)) {
|
|
429
|
+
if (compareVersions(match[1], least) < 0) below("build.gradle", build, match.index, required, what, match[1], least);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
for (const { file, pattern, message } of android.removedLines) {
|
|
435
|
+
const text = await read(file);
|
|
436
|
+
const match = text === null ? null : pattern.exec(text);
|
|
437
|
+
if (match) add(file, text, match.index, true, message);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const properties = await read("gradle.properties");
|
|
441
|
+
if (properties !== null) {
|
|
442
|
+
for (const name of android.removedProperties) {
|
|
443
|
+
const match = new RegExp(String.raw`^[ \t]*${name.replace(/\./gu, "\\.")}[ \t]*=[ \t]*(\S*)`, "mu").exec(properties);
|
|
444
|
+
if (!match) continue;
|
|
445
|
+
const breaking = android.breakingProperties[name] === match[1];
|
|
446
|
+
add("gradle.properties", properties, match.index, breaking, breaking
|
|
447
|
+
? `${name}=${match[1]} breaks a Capacitor ${major} build: remove the line.`
|
|
448
|
+
: `${name} is set; AGP 9 deprecated it and a Capacitor app needs none of these flags: remove the line.`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const activities = await bridgeActivities(base);
|
|
453
|
+
// Capacitor's bridge activity: the manifest's activity whose class extends BridgeActivity (its template's MainActivity
|
|
454
|
+
// when no source says). Other activities, such as a sign-in SDK's, keep the configChanges their own library sets.
|
|
455
|
+
const bridgeNames = new Set(activities.length > 0
|
|
456
|
+
? activities.map(({ file }) => path.basename(file).replace(/\.(?:java|kt)$/u, ""))
|
|
457
|
+
: ["MainActivity"]);
|
|
458
|
+
const manifestFile = "app/src/main/AndroidManifest.xml";
|
|
459
|
+
const manifest = await read(manifestFile);
|
|
460
|
+
if (manifest !== null) {
|
|
461
|
+
for (const element of manifest.matchAll(/<activity\b[^>]*>/gu)) {
|
|
462
|
+
const name = /android:name\s*=\s*"([^"]*)"/u.exec(element[0])?.[1] || "";
|
|
463
|
+
const changes = /android:configChanges\s*=\s*"([^"]*)"/u.exec(element[0]);
|
|
464
|
+
if (!changes || !bridgeNames.has(name.slice(name.lastIndexOf(".") + 1))) continue;
|
|
465
|
+
if (changes[1].split("|").includes(android.configChange)) continue;
|
|
466
|
+
add(manifestFile, manifest, element.index + changes.index, false, `android:configChanges lacks ${android.configChange}; ` +
|
|
467
|
+
"Capacitor adds it so that the WebView does not reload when the screen's density changes.");
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (!/insetsHandling["']?\s*:\s*["']disable["']/u.test(config.text)) {
|
|
472
|
+
for (const { file, text } of activities) {
|
|
473
|
+
if (android.edgeToEdge.test(text)) continue;
|
|
474
|
+
const name = path.basename(file).replace(/\.(?:java|kt)$/u, "");
|
|
475
|
+
const declaration = /\bclass\s+\w+/u.exec(text);
|
|
476
|
+
add(file, text, declaration ? declaration.index : null, true, `${name} does not enable edge to edge; Capacitor ` +
|
|
477
|
+
`${major}'s System Bars insets need EdgeToEdge.enable(this) (Java) or enableEdgeToEdge() (Kotlin) after ` +
|
|
478
|
+
"super.onCreate.");
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const order = ["variables.gradle", wrapperFile, "build.gradle", "settings.gradle", "app/build.gradle", "gradle.properties",
|
|
483
|
+
manifestFile];
|
|
484
|
+
const rank = (file) => (order.includes(file) ? order.indexOf(file) : order.length);
|
|
485
|
+
return [...byFile].sort(([left], [right]) => rank(left) - rank(right) || left.localeCompare(right))
|
|
486
|
+
.flatMap(([, list]) => list.sort((left, right) => (left.line || 0) - (right.line || 0)));
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// Whether a Swift file of the app target (ios/App/App and its folders) declares the @main SwiftUI App.
|
|
490
|
+
async function declaresSwiftUiApp(directory, pattern) {
|
|
491
|
+
let entries;
|
|
492
|
+
try {
|
|
493
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
494
|
+
} catch (error) {
|
|
495
|
+
if (error?.code === "ENOENT" || error?.code === "ENOTDIR") return false;
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
for (const entry of entries) {
|
|
499
|
+
const absolute = path.join(directory, entry.name);
|
|
500
|
+
if (entry.isDirectory() && !entry.name.endsWith(".xcassets") && await declaresSwiftUiApp(absolute, pattern)) return true;
|
|
501
|
+
if (entry.isFile() && entry.name.endsWith(".swift") && pattern.test(await readFile(absolute, "utf8"))) return true;
|
|
502
|
+
}
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
async function iosFindings(root, directory, { major, requirements }) {
|
|
507
|
+
const { deploymentTarget: least, swiftUiEntry, debugSetting } = requirements.ios;
|
|
508
|
+
const findings = [];
|
|
509
|
+
const projectFile = toPosixPath(path.join(directory, "App/App.xcodeproj/project.pbxproj"));
|
|
510
|
+
const project = await readOptional(path.join(root, projectFile));
|
|
511
|
+
if (project === null) return findings;
|
|
512
|
+
const lower = [...project.matchAll(/IPHONEOS_DEPLOYMENT_TARGET\s*=\s*"?(\d+(?:\.\d+)*)"?\s*;/gu)]
|
|
513
|
+
.filter((match) => compareVersions(match[1], least) < 0);
|
|
514
|
+
if (lower.length > 0) {
|
|
515
|
+
findings.push({
|
|
516
|
+
file: projectFile,
|
|
517
|
+
line: lineAt(project, lower[0].index),
|
|
518
|
+
rule: "capacitor/ios",
|
|
519
|
+
required: true,
|
|
520
|
+
message: `IPHONEOS_DEPLOYMENT_TARGET is ${[...new Set(lower.map((match) => match[1]))].join(", ")} in ${lower.length} ` +
|
|
521
|
+
`place(s); Capacitor ${major} needs ${least} for the project and every target.`
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
const podfileFile = toPosixPath(path.join(directory, "App/Podfile"));
|
|
525
|
+
const podfile = await readOptional(path.join(root, podfileFile));
|
|
526
|
+
const platform = podfile === null ? null : /platform\s+:ios\s*,\s*['"](\d+(?:\.\d+)*)['"]/u.exec(podfile);
|
|
527
|
+
if (platform && compareVersions(platform[1], least) < 0) {
|
|
528
|
+
findings.push({
|
|
529
|
+
file: podfileFile,
|
|
530
|
+
line: lineAt(podfile, platform.index),
|
|
531
|
+
rule: "capacitor/ios",
|
|
532
|
+
required: true,
|
|
533
|
+
message: `platform :ios is ${platform[1]}; Capacitor ${major} needs ${least}.`
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
if (!(await declaresSwiftUiApp(path.join(root, directory, "App", "App"), swiftUiEntry))) {
|
|
537
|
+
const delegateFile = toPosixPath(path.join(directory, "App/App/AppDelegate.swift"));
|
|
538
|
+
const delegate = await readOptional(path.join(root, delegateFile));
|
|
539
|
+
const entry = delegate === null ? null : /@(?:main|UIApplicationMain)\b/u.exec(delegate);
|
|
540
|
+
findings.push({
|
|
541
|
+
file: delegate === null ? toPosixPath(path.join(directory, "App/App")) : delegateFile,
|
|
542
|
+
line: entry ? lineAt(delegate, entry.index) : undefined,
|
|
543
|
+
rule: "capacitor/ios",
|
|
544
|
+
required: true,
|
|
545
|
+
message: `AppDelegate.swift is the app's entry point; Capacitor ${major}'s is an @main SwiftUI App (App.swift, with ` +
|
|
546
|
+
"CapacitorView.swift, which npx cap migrate writes)."
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
for (const file of ["App/App/Info.plist", "debug.xcconfig"]) {
|
|
550
|
+
const name = toPosixPath(path.join(directory, file));
|
|
551
|
+
const text = await readOptional(path.join(root, name));
|
|
552
|
+
const setting = text === null ? null : new RegExp(String.raw`\b${debugSetting}\b`, "u").exec(text);
|
|
553
|
+
if (setting) {
|
|
554
|
+
findings.push({
|
|
555
|
+
file: name,
|
|
556
|
+
line: lineAt(text, setting.index),
|
|
557
|
+
rule: "capacitor/ios",
|
|
558
|
+
required: false,
|
|
559
|
+
message: `${debugSetting} is set; Capacitor ${major} no longer reads it (debug builds keep web inspection): remove it.`
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return findings;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// The app's Capacitor findings against what its JSKIT packages need. `applies` is false for an app none of whose
|
|
567
|
+
// declared JSKIT packages needs Capacitor; such an app's Capacitor, if any, is its own.
|
|
568
|
+
async function checkCapacitor({ projectRoot, catalog, manifests, declaredPackageIds }) {
|
|
569
|
+
const root = path.resolve(projectRoot);
|
|
570
|
+
const requirement = capacitorRequirement(catalog);
|
|
571
|
+
const needing = requirement ? [...declaredPackageIds].filter((packageId) => requirement.requiredBy.has(packageId)).sort() : [];
|
|
572
|
+
if (!requirement || needing.length < 1) return { ok: true, applies: false, findings: [] };
|
|
573
|
+
|
|
574
|
+
const lockText = await readOptional(path.join(root, "package-lock.json"));
|
|
575
|
+
let lockPackages = {};
|
|
576
|
+
try {
|
|
577
|
+
lockPackages = lockText === null ? {} : JSON.parse(lockText).packages || {};
|
|
578
|
+
} catch {
|
|
579
|
+
// jskit check's graph report names an unreadable lockfile.
|
|
580
|
+
}
|
|
581
|
+
const config = await readCapacitorConfig(root);
|
|
582
|
+
const native = await hasAndroidProject(path.join(root, config.android)) ||
|
|
583
|
+
await fileExists(path.join(root, config.ios, "App/App.xcodeproj/project.pbxproj"));
|
|
584
|
+
const findings = [
|
|
585
|
+
...packageFindings({ manifests, root, lockPackages, requirement, native }),
|
|
586
|
+
...configFindings(config, requirement),
|
|
587
|
+
...(await appConfigFindings(root, requirement)),
|
|
588
|
+
...(await androidFindings(root, config.android, requirement, config)),
|
|
589
|
+
...(await iosFindings(root, config.ios, requirement))
|
|
590
|
+
];
|
|
591
|
+
// The lowest Capacitor major the app declares for Capacitor's own packages, where its steps start.
|
|
592
|
+
const declaredMajors = manifests.flatMap((manifest) => DEPENDENCY_FIELDS.flatMap((field) =>
|
|
593
|
+
CAPACITOR_LIBRARIES.map((name) => specMajor(manifest.value?.[field]?.[name])))).filter(Number.isInteger);
|
|
594
|
+
const fromMajor = declaredMajors.length > 0 ? Math.min(...declaredMajors) : null;
|
|
595
|
+
// jskit update waits only for what the major's upgrade guide requires; jskit check names every finding.
|
|
596
|
+
const required = findings.filter((finding) => finding.required);
|
|
597
|
+
return { ok: findings.length < 1, applies: true, findings, required, requirement, needing, fromMajor };
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// What the app does to move, in order: Capacitor's own migration first, then JSKIT's update.
|
|
601
|
+
// What the app does to move, in order, from the lowest Capacitor major it declares (fromMajor; null when it declares none):
|
|
602
|
+
// Capacitor's own migration first, one major at a time, since each major's npx cap migrate takes only an app on the major
|
|
603
|
+
// before it; then the plugins JSKIT's packages call, which peer on the new @capacitor/core; then JSKIT's update.
|
|
604
|
+
function capacitorMigrationSteps(requirement, fromMajor = null) {
|
|
605
|
+
const { major, range, requirements, plugins } = requirement;
|
|
606
|
+
const pluginSpecs = [...plugins].map(([name, { range: pluginRange }]) => `${name}@${pluginRange}`).sort();
|
|
607
|
+
const steps = [];
|
|
608
|
+
for (let step = Number.isInteger(fromMajor) ? fromMajor + 1 : major; step < major; step += 1) {
|
|
609
|
+
steps.push(`npm install --save-dev @capacitor/cli@^${step}.0.0 (Capacitor ${step + 1}'s npx cap migrate takes only a ` +
|
|
610
|
+
`Capacitor ${step} app)`, "npx cap migrate");
|
|
611
|
+
}
|
|
612
|
+
steps.push(`npm install --save-dev @capacitor/cli@${range}`, "npx cap migrate");
|
|
613
|
+
if (pluginSpecs.length > 0) {
|
|
614
|
+
steps.push(`npm install ${pluginSpecs.join(" ")} (the native plugins JSKIT's packages call, which npx cap sync builds ` +
|
|
615
|
+
"only when the app lists them)");
|
|
616
|
+
}
|
|
617
|
+
steps.push(
|
|
618
|
+
"Change by hand what cap migrate reports it could not, and each finding above it leaves, such as a Capacitor " +
|
|
619
|
+
"config option the major removed or config.mobile.android in config/public.js.",
|
|
620
|
+
"npx cap sync",
|
|
621
|
+
"npm run jskit:update, then npm run jskit:check, which repeats this check."
|
|
622
|
+
);
|
|
623
|
+
return [
|
|
624
|
+
`Move the app to Capacitor ${major} as Capacitor's upgrade guide says (${requirements.guide}), with Node.js ` +
|
|
625
|
+
`${requirements.node} or newer and JDK ${requirements.jdk} or newer as JAVA_HOME:`,
|
|
626
|
+
...steps.map((step, index) => ` ${index + 1}. ${step}`)
|
|
627
|
+
].join("\n");
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function formatFinding({ file, line, rule, message }) {
|
|
631
|
+
return `${file}${line ? `:${line}` : ""} ${rule} ${message}`;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function formatCapacitorReport(result) {
|
|
635
|
+
if (!result.applies) return "";
|
|
636
|
+
const { major, range } = result.requirement;
|
|
637
|
+
const needs = `${result.needing.join(", ")} need${result.needing.length > 1 ? "" : "s"} Capacitor ${major} (${CORE_PACKAGE} ${range})`;
|
|
638
|
+
if (result.ok) return `JSKIT Capacitor: the app's Capacitor packages and native projects are on Capacitor ${major}; ${needs}.`;
|
|
639
|
+
const required = result.findings.filter((finding) => finding.required);
|
|
640
|
+
const others = result.findings.filter((finding) => !finding.required);
|
|
641
|
+
return [
|
|
642
|
+
...required.map(formatFinding),
|
|
643
|
+
...(others.length > 0
|
|
644
|
+
? [`Not required by Capacitor ${major}'s upgrade guide, so jskit update does not wait for them (${others.length}):`,
|
|
645
|
+
...others.map(formatFinding)]
|
|
646
|
+
: []),
|
|
647
|
+
`JSKIT Capacitor: ${result.findings.length} error(s), ${required.length} of them required by Capacitor ${major}'s ` +
|
|
648
|
+
`upgrade guide, which jskit update waits for. ${needs}.`,
|
|
649
|
+
required.length > 0
|
|
650
|
+
? capacitorMigrationSteps(result.requirement, result.fromMajor)
|
|
651
|
+
: "Change what each finding says; npm run jskit:check repeats this check."
|
|
652
|
+
].join("\n");
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export {
|
|
656
|
+
CAPACITOR_PACKAGES,
|
|
657
|
+
REQUIREMENTS as CAPACITOR_REQUIREMENTS,
|
|
658
|
+
capacitorMigrationSteps,
|
|
659
|
+
capacitorRequirement,
|
|
660
|
+
checkCapacitor,
|
|
661
|
+
formatCapacitorReport,
|
|
662
|
+
formatFinding as formatCapacitorFinding
|
|
663
|
+
};
|