@akanjs/devkit 3.0.0-alpha.5 → 3.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/capacitorApp.test.ts +8 -0
- package/capacitorApp.ts +112 -18
- package/frontendBuild/cssCandidateCache.test.ts +38 -0
- package/frontendBuild/cssCandidateCache.ts +15 -3
- package/lint/no-return-in-store-action.grit +35 -0
- package/package.json +2 -2
- package/qualityScanner.ts +2 -19
- package/routeSourceValidator.test.ts +41 -0
- package/routeSourceValidator.ts +2 -44
package/capacitorApp.test.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
clearRootCapacitorConfigs,
|
|
12
12
|
formatAndroidReleaseSigningError,
|
|
13
13
|
getAdbDeviceStateIssues,
|
|
14
|
+
getAndroidLocalServerHost,
|
|
14
15
|
getMissingAndroidReleaseSigningKeys,
|
|
15
16
|
isPlaceholderAppId,
|
|
16
17
|
materializeCapacitorConfig,
|
|
@@ -339,6 +340,13 @@ describe("Android signing diagnostics", () => {
|
|
|
339
340
|
"Android device abc123 is unauthorized. Confirm USB debugging authorization on the device.",
|
|
340
341
|
"Android device xyz is offline. Reconnect the device or restart adb.",
|
|
341
342
|
]);
|
|
343
|
+
expect(getAndroidLocalServerHost("List of devices attached\nemulator-5554 device\n", "192.168.0.5")).toBe(
|
|
344
|
+
"10.0.2.2",
|
|
345
|
+
);
|
|
346
|
+
expect(getAndroidLocalServerHost("List of devices attached\nabc123 device\n", "192.168.0.5")).toBe("192.168.0.5");
|
|
347
|
+
expect(
|
|
348
|
+
getAndroidLocalServerHost("List of devices attached\nemulator-5554 device\nabc123 device\n", "192.168.0.5"),
|
|
349
|
+
).toBe("192.168.0.5");
|
|
342
350
|
});
|
|
343
351
|
});
|
|
344
352
|
|
package/capacitorApp.ts
CHANGED
|
@@ -24,7 +24,9 @@ interface RunIosConfig extends RunConfig {
|
|
|
24
24
|
iosDeviceId?: string;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
interface PrepareConfig extends RunConfig {
|
|
27
|
+
interface PrepareConfig extends RunConfig {
|
|
28
|
+
iosRunTargetKind?: IosRunTargetKind;
|
|
29
|
+
}
|
|
28
30
|
|
|
29
31
|
type MobileCommandEnv = Record<string, string | undefined>;
|
|
30
32
|
|
|
@@ -119,10 +121,11 @@ interface MaterializeCapacitorConfigOptions {
|
|
|
119
121
|
localServerUrl?: string;
|
|
120
122
|
localIp?: string;
|
|
121
123
|
}
|
|
124
|
+
type MobilePlatform = "ios" | "android";
|
|
122
125
|
|
|
123
126
|
export interface LocalDevHostResolution {
|
|
124
127
|
host: string;
|
|
125
|
-
source: "override" | "detected" | "loopback";
|
|
128
|
+
source: "override" | "detected" | "loopback" | "platform";
|
|
126
129
|
candidates: { name: string; address: string }[];
|
|
127
130
|
}
|
|
128
131
|
|
|
@@ -565,6 +568,16 @@ export function getAdbDeviceStateIssues(output: string) {
|
|
|
565
568
|
});
|
|
566
569
|
}
|
|
567
570
|
|
|
571
|
+
export function getAndroidLocalServerHost(adbDevicesOutput: string | undefined, fallbackHost: string) {
|
|
572
|
+
const onlineDeviceIds =
|
|
573
|
+
adbDevicesOutput
|
|
574
|
+
?.split(/\r?\n/)
|
|
575
|
+
.map((line) => line.trim().split(/\s+/))
|
|
576
|
+
.filter(([id, state]) => id && state === "device")
|
|
577
|
+
.map(([id]) => id) ?? [];
|
|
578
|
+
return onlineDeviceIds.length === 1 && onlineDeviceIds[0]?.startsWith("emulator-") ? "10.0.2.2" : fallbackHost;
|
|
579
|
+
}
|
|
580
|
+
|
|
568
581
|
export const ANDROID_MIN_SDK_VERSION = 26;
|
|
569
582
|
export function raiseGradleMinSdkVersion(content: string, floor: number = ANDROID_MIN_SDK_VERSION): string | null {
|
|
570
583
|
const match = content.match(/minSdkVersion\s*=\s*(\d+)/);
|
|
@@ -748,7 +761,7 @@ export class CapacitorApp {
|
|
|
748
761
|
async save() {
|
|
749
762
|
await this.project.commit();
|
|
750
763
|
}
|
|
751
|
-
async #prepareIos({ operation, env, regenerate = false }: PrepareConfig) {
|
|
764
|
+
async #prepareIos({ operation, env, regenerate = false, iosRunTargetKind }: PrepareConfig) {
|
|
752
765
|
await this.init({ platform: "ios", operation, env, regenerate });
|
|
753
766
|
await this.#prepareTargetAssets();
|
|
754
767
|
await this.#prepareExternalFiles("ios");
|
|
@@ -757,9 +770,10 @@ export class CapacitorApp {
|
|
|
757
770
|
await this.#applyDeepLinks("ios", { operation, env });
|
|
758
771
|
await this.#flushIosEntitlements();
|
|
759
772
|
await this.project.commit();
|
|
773
|
+
await this.#setCodeSignEntitlementsInIosIfExists("App/App.entitlements");
|
|
760
774
|
await this.#generateAssets({ operation, env });
|
|
761
775
|
this.app.verbose(`syncing iOS`);
|
|
762
|
-
await this.#spawnMobile("npx", ["cap", "sync", "ios"], { operation, env });
|
|
776
|
+
await this.#spawnMobile("npx", ["cap", "sync", "ios"], { operation, env }, { iosRunTargetKind });
|
|
763
777
|
this.app.verbose(`sync completed.`);
|
|
764
778
|
}
|
|
765
779
|
async buildIos({ env = "debug", regenerate = false }: { env?: RunConfig["env"]; regenerate?: boolean } = {}) {
|
|
@@ -777,14 +791,14 @@ export class CapacitorApp {
|
|
|
777
791
|
}
|
|
778
792
|
async runIos({ operation, env, regenerate = false, noAllowProvisioningUpdates = false, iosDeviceId }: RunIosConfig) {
|
|
779
793
|
if (operation === "release") await this.prepareWww();
|
|
780
|
-
await this.#prepareIos({ operation, env, regenerate });
|
|
781
794
|
const runTarget = await this.#selectIosRunTarget(iosDeviceId);
|
|
795
|
+
await this.#prepareIos({ operation, env, regenerate, iosRunTargetKind: runTarget.kind });
|
|
782
796
|
if (runTarget.kind === "simulator") {
|
|
783
797
|
await this.#spawnMobile(
|
|
784
798
|
"npx",
|
|
785
|
-
["cap", "run", "ios", "--target", runTarget.id],
|
|
799
|
+
["cap", "run", "ios", "--target", runTarget.id, "--no-sync"],
|
|
786
800
|
{ operation, env },
|
|
787
|
-
{ stdio: "inherit" },
|
|
801
|
+
{ stdio: "inherit", platform: "ios", iosRunTargetKind: runTarget.kind },
|
|
788
802
|
);
|
|
789
803
|
return;
|
|
790
804
|
}
|
|
@@ -878,7 +892,10 @@ export class CapacitorApp {
|
|
|
878
892
|
noAllowProvisioningUpdates: boolean;
|
|
879
893
|
}) {
|
|
880
894
|
const mobileEnv = sanitizeIosNativeRunEnv(await this.#commandEnv(operation, env));
|
|
881
|
-
const configContent = await this.#writeCapacitorConfig(
|
|
895
|
+
const configContent = await this.#writeCapacitorConfig(
|
|
896
|
+
{ operation, platform: "ios", iosRunTargetKind: runTarget.kind },
|
|
897
|
+
mobileEnv,
|
|
898
|
+
);
|
|
882
899
|
await this.#writeRootCapacitorConfig(configContent);
|
|
883
900
|
const scheme = this.#iosScheme();
|
|
884
901
|
const command = buildIosNativeRunCommand({
|
|
@@ -943,6 +960,7 @@ export class CapacitorApp {
|
|
|
943
960
|
await this.#applyAndroidMinSdkVersion();
|
|
944
961
|
await this.#applyPermissions({ operation, env });
|
|
945
962
|
await this.#applyDeepLinks("android", { operation, env });
|
|
963
|
+
await this.#disableNativeKeyboardResizeInAndroid();
|
|
946
964
|
await this.project.commit();
|
|
947
965
|
await this.#generateAssets({ operation, env });
|
|
948
966
|
await this.#ensureAndroidAssetsDir();
|
|
@@ -1010,6 +1028,24 @@ export class CapacitorApp {
|
|
|
1010
1028
|
async openAndroid() {
|
|
1011
1029
|
await this.#spawnMobile("npx", ["cap", "open", "android"], { operation: "local", env: "local" });
|
|
1012
1030
|
}
|
|
1031
|
+
async #disableNativeKeyboardResizeInAndroid() {
|
|
1032
|
+
const manifestPath = path.join(this.app.cwdPath, this.androidRootPath, "app/src/main/AndroidManifest.xml");
|
|
1033
|
+
let manifest = await readFile(manifestPath, "utf8");
|
|
1034
|
+
let changed = false;
|
|
1035
|
+
manifest = manifest.replace(/<activity\b[^>]*android:name="\.MainActivity"[^>]*>/, (activityTag) => {
|
|
1036
|
+
if (activityTag.includes("android:windowSoftInputMode=")) {
|
|
1037
|
+
const nextTag = activityTag.replace(
|
|
1038
|
+
/android:windowSoftInputMode="[^"]*"/,
|
|
1039
|
+
'android:windowSoftInputMode="adjustNothing"',
|
|
1040
|
+
);
|
|
1041
|
+
changed ||= nextTag !== activityTag;
|
|
1042
|
+
return nextTag;
|
|
1043
|
+
}
|
|
1044
|
+
changed = true;
|
|
1045
|
+
return activityTag.replace(/>$/, '\n android:windowSoftInputMode="adjustNothing">');
|
|
1046
|
+
});
|
|
1047
|
+
if (changed) await writeFile(manifestPath, manifest);
|
|
1048
|
+
}
|
|
1013
1049
|
async #ensureAndroidAssetsDir() {
|
|
1014
1050
|
await mkdir(path.join(this.app.cwdPath, this.androidAssetsPath), { recursive: true });
|
|
1015
1051
|
}
|
|
@@ -1100,12 +1136,19 @@ export class CapacitorApp {
|
|
|
1100
1136
|
if (html.includes("window.__AKAN_MOBILE_TARGET__")) return html;
|
|
1101
1137
|
return html.replace(/<\/head\s*>/i, `${script}\n</head>`);
|
|
1102
1138
|
}
|
|
1103
|
-
async #writeCapacitorConfig(
|
|
1139
|
+
async #writeCapacitorConfig(
|
|
1140
|
+
{
|
|
1141
|
+
operation,
|
|
1142
|
+
platform,
|
|
1143
|
+
iosRunTargetKind,
|
|
1144
|
+
}: Pick<RunConfig, "operation"> & { platform?: MobilePlatform; iosRunTargetKind?: IosRunTargetKind },
|
|
1145
|
+
commandEnv: MobileCommandEnv,
|
|
1146
|
+
) {
|
|
1104
1147
|
await mkdir(this.targetRoot, { recursive: true });
|
|
1105
1148
|
let localIp: string | undefined;
|
|
1106
1149
|
if (operation === "local") {
|
|
1107
1150
|
const override = commandEnv.AKAN_PUBLIC_CLIENT_HOST ?? process.env.AKAN_PUBLIC_CLIENT_HOST;
|
|
1108
|
-
const resolution =
|
|
1151
|
+
const resolution = await this.#resolveLocalDevHost({ override, platform, iosRunTargetKind });
|
|
1109
1152
|
localIp = resolution.host;
|
|
1110
1153
|
this.#logDevHostResolution(resolution, commandEnv);
|
|
1111
1154
|
}
|
|
@@ -1118,11 +1161,36 @@ export class CapacitorApp {
|
|
|
1118
1161
|
await Bun.write(path.join(this.targetRoot, "capacitor.config.json"), content);
|
|
1119
1162
|
return content;
|
|
1120
1163
|
}
|
|
1164
|
+
// An explicit override always wins; an emulator/simulator run reaches the host machine through a
|
|
1165
|
+
// loopback alias (10.0.2.2 / localhost), so LAN detection only applies to physical-device runs.
|
|
1166
|
+
async #resolveLocalDevHost({
|
|
1167
|
+
override,
|
|
1168
|
+
platform,
|
|
1169
|
+
iosRunTargetKind,
|
|
1170
|
+
}: {
|
|
1171
|
+
override?: string;
|
|
1172
|
+
platform?: MobilePlatform;
|
|
1173
|
+
iosRunTargetKind?: IosRunTargetKind;
|
|
1174
|
+
}): Promise<LocalDevHostResolution> {
|
|
1175
|
+
const resolution = selectLocalDevHost(os.networkInterfaces(), { override });
|
|
1176
|
+
if (resolution.source === "override") return resolution;
|
|
1177
|
+
if (platform === "ios" && iosRunTargetKind === "simulator")
|
|
1178
|
+
return { ...resolution, host: "localhost", source: "platform" };
|
|
1179
|
+
if (platform === "android") {
|
|
1180
|
+
try {
|
|
1181
|
+
const host = getAndroidLocalServerHost(await this.#spawn("adb", ["devices"]), resolution.host);
|
|
1182
|
+
return host === resolution.host ? resolution : { ...resolution, host, source: "platform" };
|
|
1183
|
+
} catch {
|
|
1184
|
+
return resolution;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
return resolution;
|
|
1188
|
+
}
|
|
1121
1189
|
// Surface the live-reload URL a physical device must reach, and warn when auto-detection landed on
|
|
1122
1190
|
// a likely-unreachable host so a blank WebView is not mistaken for an app bug.
|
|
1123
1191
|
#logDevHostResolution(resolution: LocalDevHostResolution, commandEnv: MobileCommandEnv) {
|
|
1124
1192
|
this.app.log(`Mobile live-reload server: ${this.#localCsrUrl(resolution.host, commandEnv)}`);
|
|
1125
|
-
if (resolution.source === "override") return;
|
|
1193
|
+
if (resolution.source === "override" || resolution.source === "platform") return;
|
|
1126
1194
|
const suspicious = resolution.host === "127.0.0.1" || resolution.host.startsWith("169.254.");
|
|
1127
1195
|
const alternatives = resolution.candidates.filter((candidate) => candidate.address !== resolution.host);
|
|
1128
1196
|
if (!suspicious && alternatives.length === 0) return;
|
|
@@ -1332,20 +1400,29 @@ export class CapacitorApp {
|
|
|
1332
1400
|
command: string,
|
|
1333
1401
|
args: string[] = [],
|
|
1334
1402
|
{ operation, env }: Pick<RunConfig, "operation" | "env">,
|
|
1335
|
-
options:
|
|
1403
|
+
options: SpawnMobileOptions = {},
|
|
1336
1404
|
) {
|
|
1405
|
+
const { iosRunTargetKind, platform, ...spawnOptions } = options;
|
|
1337
1406
|
const mobileEnv = { ...(await this.#commandEnv(operation, env)), ...options.env };
|
|
1338
|
-
const configContent = await this.#writeCapacitorConfig(
|
|
1407
|
+
const configContent = await this.#writeCapacitorConfig(
|
|
1408
|
+
{ operation, platform: platform ?? this.#inferMobilePlatform(args), iosRunTargetKind },
|
|
1409
|
+
mobileEnv,
|
|
1410
|
+
);
|
|
1339
1411
|
await this.#writeRootCapacitorConfig(configContent);
|
|
1340
1412
|
try {
|
|
1341
1413
|
return await this.#spawn(command, args, {
|
|
1342
|
-
...
|
|
1414
|
+
...spawnOptions,
|
|
1343
1415
|
env: mobileEnv,
|
|
1344
1416
|
});
|
|
1345
1417
|
} finally {
|
|
1346
1418
|
await this.#clearRootCapacitorConfigs();
|
|
1347
1419
|
}
|
|
1348
1420
|
}
|
|
1421
|
+
#inferMobilePlatform(args: string[]): MobilePlatform | undefined {
|
|
1422
|
+
if (args.includes("android")) return "android";
|
|
1423
|
+
if (args.includes("ios")) return "ios";
|
|
1424
|
+
return undefined;
|
|
1425
|
+
}
|
|
1349
1426
|
async addCamera() {
|
|
1350
1427
|
await this.#setPermissionInIos({
|
|
1351
1428
|
cameraUsageDescription: "$(PRODUCT_NAME) requires access to the camera to take photos.",
|
|
@@ -1446,14 +1523,31 @@ export class CapacitorApp {
|
|
|
1446
1523
|
let end = index;
|
|
1447
1524
|
while (end < lines.length && !/^\s*\};\s*$/.test(lines[end] ?? "")) end++;
|
|
1448
1525
|
const settings = lines.slice(start, end + 1);
|
|
1449
|
-
|
|
1526
|
+
const configName = lines.slice(end + 1, end + 8).find((setting) => setting.includes("name = ")) ?? "";
|
|
1450
1527
|
const indent = line.match(/^\s*/)?.[0] ?? "";
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1528
|
+
const insertSettings = [];
|
|
1529
|
+
if (!settings.some((setting) => setting.includes("CODE_SIGN_ENTITLEMENTS"))) {
|
|
1530
|
+
insertSettings.push(`${indent}CODE_SIGN_ENTITLEMENTS = ${entitlementsRelPath};`);
|
|
1531
|
+
}
|
|
1532
|
+
if (
|
|
1533
|
+
configName.includes("name = Debug;") &&
|
|
1534
|
+
!settings.some((setting) => setting.includes("CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION"))
|
|
1535
|
+
) {
|
|
1536
|
+
insertSettings.push(`${indent}CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION = YES;`);
|
|
1537
|
+
}
|
|
1538
|
+
if (insertSettings.length > 0) {
|
|
1539
|
+
lines.splice(index, 0, ...insertSettings);
|
|
1540
|
+
index += insertSettings.length;
|
|
1541
|
+
changed = true;
|
|
1542
|
+
}
|
|
1454
1543
|
}
|
|
1455
1544
|
if (changed) await writeFile(pbxprojPath, lines.join("\n"));
|
|
1456
1545
|
}
|
|
1546
|
+
async #setCodeSignEntitlementsInIosIfExists(entitlementsRelPath: string) {
|
|
1547
|
+
const entitlementsPath = path.join(this.app.cwdPath, this.iosProjectPath, entitlementsRelPath);
|
|
1548
|
+
if (!(await Bun.file(entitlementsPath).exists())) return;
|
|
1549
|
+
await this.#setCodeSignEntitlementsInIos(entitlementsRelPath);
|
|
1550
|
+
}
|
|
1457
1551
|
async #setUrlSchemesInAndroid(schemes: string[]) {
|
|
1458
1552
|
const manifestPath = path.join(this.app.cwdPath, this.androidRootPath, "app/src/main/AndroidManifest.xml");
|
|
1459
1553
|
let manifest = await readFile(manifestPath, "utf8");
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { CssCandidateCache } from "./cssCandidateCache";
|
|
6
|
+
|
|
7
|
+
const scan = async (source: string) => {
|
|
8
|
+
const dir = await mkdtemp(path.join(tmpdir(), "css-candidate-"));
|
|
9
|
+
const file = path.join(dir, "probe.tsx");
|
|
10
|
+
await writeFile(file, source);
|
|
11
|
+
return await new CssCandidateCache(path.join(dir, "cache.json")).load().then((c) => c.candidatesFor(file));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe("CssCandidateCache token extraction", () => {
|
|
15
|
+
test("keeps plain utilities, variants and arbitrary values whole", async () => {
|
|
16
|
+
const candidates = await scan(`const c = "w-full hover:bg-muted md:w-1/2 text-[#fff]";`);
|
|
17
|
+
expect(candidates).toEqual(expect.arrayContaining(["w-full", "hover:bg-muted", "md:w-1/2", "text-[#fff]"]));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// A candidate that opens with `[` used to be torn into `_td` + `px-3`, so every descendant-variant
|
|
21
|
+
// rule in the framework compiled to nothing and its element rendered unstyled with no diagnostic.
|
|
22
|
+
test("keeps an arbitrary variant that starts with a bracket", async () => {
|
|
23
|
+
const candidates = await scan(`const c = "[&_td]:px-3 [&>*]:gap-2 [&_tbody_tr]:border-t";`);
|
|
24
|
+
expect(candidates).toEqual(expect.arrayContaining(["[&_td]:px-3", "[&>*]:gap-2", "[&_tbody_tr]:border-t"]));
|
|
25
|
+
expect(candidates).not.toContain("_td");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// A labelled tuple type looks like an arbitrary property, and compiles to a rule whose declaration is
|
|
29
|
+
// TypeScript. `optimize()` cannot parse that, and drops far more than the offending rule on its way
|
|
30
|
+
// out — every variant in the build went missing, so nothing hovered, focused or responded to a
|
|
31
|
+
// breakpoint. Tailwind writes a space in an arbitrary value as `_`, so whitespace rules the token out.
|
|
32
|
+
test("ignores a labelled tuple type that only looks like an arbitrary property", async () => {
|
|
33
|
+
const candidates = await scan(
|
|
34
|
+
`type A = [key: string, make: () => unknown][];\ntype B = [setQueryArgs: (a: Args) => Args, options?: Policy];`,
|
|
35
|
+
);
|
|
36
|
+
expect(candidates.filter((candidate) => candidate.startsWith("["))).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Every identifier-ish token in a source file is a potential tailwind class. The leading alternation
|
|
5
|
+
* matters: an arbitrary variant starts with `[` (`[&_td]:px-3`, `[&>*]:gap-2`), and a pattern anchored
|
|
6
|
+
* on a word character tears it into `_td` plus `px-3` instead — both meaningless, so the rule compiles
|
|
7
|
+
* to nothing and the element silently renders unstyled.
|
|
8
|
+
*
|
|
9
|
+
* Brackets must hold no whitespace. Tailwind spells a space in an arbitrary value `_`, so a bracket
|
|
10
|
+
* group containing one is never a class — but it is exactly the shape of a labelled tuple type
|
|
11
|
+
* (`[key: string, make: () => unknown]`). Scanned as a candidate, that compiles to an arbitrary
|
|
12
|
+
* *property* rule carrying TypeScript as its declaration, which the lightningcss pass in `optimize()`
|
|
13
|
+
* cannot parse; its error recovery then drops a whole span of the stylesheet — in practice every
|
|
14
|
+
* variant rule in the build, leaving hover, focus, responsive and dark styles silently absent.
|
|
15
|
+
*/
|
|
16
|
+
const CANDIDATE_RE = /-?(?:[\w@]|\[[^\]\s]+\])[\w:/.-]*(?:\[[^\]\s]+\][\w:/.-]*)*/g;
|
|
5
17
|
|
|
6
18
|
interface CachedFile {
|
|
7
19
|
mtimeMs: number;
|
|
@@ -27,7 +39,7 @@ interface CacheFile {
|
|
|
27
39
|
*/
|
|
28
40
|
export class CssCandidateCache {
|
|
29
41
|
/** Bump when the token regex or the entry shape changes, so stale extractions are not reused. */
|
|
30
|
-
static readonly #version =
|
|
42
|
+
static readonly #version = 3;
|
|
31
43
|
readonly #path: string;
|
|
32
44
|
readonly #entries = new Map<string, CachedFile>();
|
|
33
45
|
#dirty = false;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
engine biome(1.0)
|
|
2
|
+
language js(typescript, jsx)
|
|
3
|
+
|
|
4
|
+
// Every prototype method of a `store(...)` class is registered as an action
|
|
5
|
+
// (StoreRegistry.register) and reaches callers only as `st.do.<action>`, which re-wraps it
|
|
6
|
+
// (StoreInstance.#extendAccessors) and is typed void by `VoidActions` in
|
|
7
|
+
// pkgs/akanjs/store/types.ts. A returned value is therefore unreachable from every call
|
|
8
|
+
// site — it reads like a contract while being dead code. Write the result into state with
|
|
9
|
+
// `this.set({ ... })` instead.
|
|
10
|
+
//
|
|
11
|
+
// Deliberately not flagged, because none of these are actions: a bare `return;` guard, a
|
|
12
|
+
// `return` belonging to a nested callback, a getter, a `static` helper, and a class-property
|
|
13
|
+
// arrow (an instance field, so `register` never sees it).
|
|
14
|
+
`return $value;` as $return where {
|
|
15
|
+
not $value <: r"",
|
|
16
|
+
$return <: within JsClassDeclaration() as $storeClass where {
|
|
17
|
+
$storeClass <: contains JsExtendsClause() as $extends where {
|
|
18
|
+
$extends <: r"extends\s+store\([\s\S]*"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
$return <: within JsMethodClassMember() as $action where {
|
|
22
|
+
not $action <: r"static[\s\S]*"
|
|
23
|
+
},
|
|
24
|
+
not $return <: within JsArrowFunctionExpression(),
|
|
25
|
+
not $return <: within JsFunctionExpression(),
|
|
26
|
+
not $return <: within JsFunctionDeclaration(),
|
|
27
|
+
not $return <: within JsMethodObjectMember(),
|
|
28
|
+
not $return <: within JsGetterObjectMember(),
|
|
29
|
+
not $return <: within JsSetterObjectMember(),
|
|
30
|
+
register_diagnostic(
|
|
31
|
+
span = $return,
|
|
32
|
+
message = "Store actions dispatch as void — st.do.<action>() never exposes this value. Write the result into state with this.set({ ... }) and drop the returned value; a bare 'return;' guard clause is fine.",
|
|
33
|
+
severity = "error"
|
|
34
|
+
)
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/devkit",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.7",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@langchain/openai": "^1.4.6",
|
|
45
45
|
"@tailwindcss/node": "^4.3.0",
|
|
46
46
|
"@trapezedev/project": "^7.1.4",
|
|
47
|
-
"akanjs": "3.0.0-alpha.
|
|
47
|
+
"akanjs": "3.0.0-alpha.7",
|
|
48
48
|
"chalk": "^5.6.2",
|
|
49
49
|
"commander": "^14.0.3",
|
|
50
50
|
"dayjs": "^1.11.20",
|
package/qualityScanner.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { RESERVED_ROUTE_CONFIG_EXPORTS } from "akanjs/common";
|
|
4
5
|
import ignore from "ignore";
|
|
5
6
|
import ts from "typescript";
|
|
6
7
|
import { AbstractDoc } from "./abstractDoc";
|
|
@@ -100,24 +101,6 @@ const CONVENTION_SUFFIXES = [
|
|
|
100
101
|
".store.ts",
|
|
101
102
|
] as const;
|
|
102
103
|
|
|
103
|
-
// Non-PascalCase exports the framework recognizes on page/layout route modules (see PageModule/LayoutModule
|
|
104
|
-
// in pkgs/akanjs/client/csrTypes.ts). PascalCase route exports (Loading, NotFound, Error) pass the component
|
|
105
|
-
// check, and the `default` export is handled separately.
|
|
106
|
-
const PAGE_RESERVED_EXPORTS = new Set([
|
|
107
|
-
"pageConfig",
|
|
108
|
-
"head",
|
|
109
|
-
"metadata",
|
|
110
|
-
"generateHead",
|
|
111
|
-
"generateMetadata",
|
|
112
|
-
"fonts",
|
|
113
|
-
"manifest",
|
|
114
|
-
"theme",
|
|
115
|
-
"reconnect",
|
|
116
|
-
"wsConnect",
|
|
117
|
-
"layoutStyle",
|
|
118
|
-
"gaTrackingId",
|
|
119
|
-
]);
|
|
120
|
-
|
|
121
104
|
// How to remediate each rule, keyed by rule id. Surfaced as a `fix:` line per warning (text + JSON output)
|
|
122
105
|
// so the scan result tells the reader what to do, not just what is wrong.
|
|
123
106
|
const RULE_FIXES: Record<string, string> = {
|
|
@@ -669,7 +652,7 @@ function isRestrictedInternalKind(kind: ComponentFileDeclaration["kind"]) {
|
|
|
669
652
|
|
|
670
653
|
function isAllowedComponentExport(declaration: ComponentFileDeclaration, isPage: boolean) {
|
|
671
654
|
if (isComponentValueKind(declaration.kind) && isPascalCaseName(declaration.name)) return true;
|
|
672
|
-
return isPage &&
|
|
655
|
+
return isPage && RESERVED_ROUTE_CONFIG_EXPORTS.has(declaration.name);
|
|
673
656
|
}
|
|
674
657
|
|
|
675
658
|
function isPascalCaseName(name: string) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { RouteSourceValidator } from "./routeSourceValidator";
|
|
4
|
+
|
|
5
|
+
const validate = (source: string, kind: "page" | "layout", rootLayout = false) =>
|
|
6
|
+
RouteSourceValidator.validateRouteSourceExports(source, `page/_${kind}.tsx`, kind, { rootLayout });
|
|
7
|
+
|
|
8
|
+
describe("RouteSourceValidator", () => {
|
|
9
|
+
test("accepts every root-layout config export the route tree honors", () => {
|
|
10
|
+
const source = [
|
|
11
|
+
"export default function Layout() { return null; }",
|
|
12
|
+
"export const fonts = [];",
|
|
13
|
+
"export const manifest = {};",
|
|
14
|
+
'export const theme = "dark";',
|
|
15
|
+
"export const reconnect = true;",
|
|
16
|
+
"export const wsConnect = true;",
|
|
17
|
+
"export const layoutStyle = {};",
|
|
18
|
+
'export const gaTrackingId = "G-1";',
|
|
19
|
+
].join("\n");
|
|
20
|
+
|
|
21
|
+
expect(() => validate(source, "layout", true)).not.toThrow();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("rejects root-layout-only exports on a nested layout and on a page", () => {
|
|
25
|
+
const source = ["export default function Layout() { return null; }", "export const wsConnect = true;"].join("\n");
|
|
26
|
+
|
|
27
|
+
expect(() => validate(source, "layout")).toThrow('unsupported export "wsConnect"');
|
|
28
|
+
expect(() => validate(source, "page")).toThrow('unsupported export "wsConnect"');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("reads devOnly off pageConfig without evaluating the module", () => {
|
|
32
|
+
const source = [
|
|
33
|
+
"export default function Page() { return null; }",
|
|
34
|
+
"export const pageConfig = { devOnly: true };",
|
|
35
|
+
].join("\n");
|
|
36
|
+
|
|
37
|
+
expect(RouteSourceValidator.validateRouteSourceExports(source, "page/_index.tsx", "page")).toEqual({
|
|
38
|
+
devOnly: true,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
package/routeSourceValidator.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getRouteExports } from "akanjs/common";
|
|
1
2
|
import ts from "typescript";
|
|
2
3
|
|
|
3
4
|
/** What the build needs out of a route module without evaluating it. */
|
|
@@ -16,44 +17,6 @@ export interface RouteSourceInfo {
|
|
|
16
17
|
* validate a route source stay lean.
|
|
17
18
|
*/
|
|
18
19
|
export class RouteSourceValidator {
|
|
19
|
-
static readonly #pageExports = new Set([
|
|
20
|
-
"default",
|
|
21
|
-
"pageConfig",
|
|
22
|
-
"head",
|
|
23
|
-
"metadata",
|
|
24
|
-
"generateHead",
|
|
25
|
-
"generateMetadata",
|
|
26
|
-
"Loading",
|
|
27
|
-
]);
|
|
28
|
-
static readonly #rootLayoutExports = new Set([
|
|
29
|
-
"default",
|
|
30
|
-
"pageConfig",
|
|
31
|
-
"head",
|
|
32
|
-
"metadata",
|
|
33
|
-
"generateHead",
|
|
34
|
-
"generateMetadata",
|
|
35
|
-
"fonts",
|
|
36
|
-
"manifest",
|
|
37
|
-
"theme",
|
|
38
|
-
"reconnect",
|
|
39
|
-
"layoutStyle",
|
|
40
|
-
"gaTrackingId",
|
|
41
|
-
"Loading",
|
|
42
|
-
"NotFound",
|
|
43
|
-
"Error",
|
|
44
|
-
]);
|
|
45
|
-
static readonly #layoutExports = new Set([
|
|
46
|
-
"default",
|
|
47
|
-
"pageConfig",
|
|
48
|
-
"head",
|
|
49
|
-
"metadata",
|
|
50
|
-
"generateHead",
|
|
51
|
-
"generateMetadata",
|
|
52
|
-
"Loading",
|
|
53
|
-
"NotFound",
|
|
54
|
-
"Error",
|
|
55
|
-
]);
|
|
56
|
-
|
|
57
20
|
static validateRouteSourceExports(
|
|
58
21
|
source: string,
|
|
59
22
|
filePath: string,
|
|
@@ -61,12 +24,7 @@ export class RouteSourceValidator {
|
|
|
61
24
|
options: { rootLayout?: boolean } = {},
|
|
62
25
|
): RouteSourceInfo {
|
|
63
26
|
const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
64
|
-
const allowed =
|
|
65
|
-
kind === "page"
|
|
66
|
-
? RouteSourceValidator.#pageExports
|
|
67
|
-
: options.rootLayout
|
|
68
|
-
? RouteSourceValidator.#rootLayoutExports
|
|
69
|
-
: RouteSourceValidator.#layoutExports;
|
|
27
|
+
const allowed = getRouteExports(kind, { rootLayout: options.rootLayout });
|
|
70
28
|
const exported = new Set<string>();
|
|
71
29
|
const assertExport = (name: string) => {
|
|
72
30
|
if (!allowed.has(name)) {
|