@akanjs/devkit 3.3.0-rc.6 → 3.3.0-rc.60
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/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +8 -2
- package/README.md +8 -3
- package/akanApp/akanApp.host.test.ts +4 -2
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +280 -19
- package/akanConfig/akanConfig.ts +96 -270
- package/akanConfig/akanWorkers.test.ts +73 -0
- package/akanConfig/akanWorkers.ts +61 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +216 -0
- package/akanConfig/index.ts +2 -0
- package/akanConfig/nativeFileSettings.ts +33 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +2 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +51 -1
- package/app/applicationBuildReporter.ts +6 -1
- package/app/applicationBuildRunner.test.ts +358 -5
- package/app/applicationBuildRunner.ts +204 -30
- package/app/dictionarySizes.test.ts +40 -0
- package/app/dictionarySizes.ts +95 -0
- package/app/routeFilesReport.test.ts +59 -0
- package/app/routeFilesReport.ts +46 -0
- package/app/routeJsBudget.ts +18 -4
- package/artifact/implicitRootLayout.test.ts +19 -0
- package/artifact/implicitRootLayout.ts +16 -2
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +64 -8
- package/biome.base.json +7 -5
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/codeAgent/skills/akan-debug/SKILL.md +1 -1
- package/codeAgent/skills/akan-deps/SKILL.md +3 -2
- package/codeAgent/skills/akan-err/SKILL.md +13 -8
- package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
- package/codeAgent/skills/akan-module/SKILL.md +2 -2
- package/codeAgent/skills/akan-page/SKILL.md +46 -29
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
- package/codeAgent/skills/akan-service/SKILL.md +10 -11
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +16 -21
- package/commandDecorators/command.ts +28 -12
- package/commandDecorators/commandBuilder.ts +8 -1
- package/commandDecorators/commandDecorators.test.ts +70 -3
- package/commandDecorators/helpFormatter.ts +14 -12
- package/context/akanContext.ts +2 -0
- package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
- package/docs/apiReference.test.ts +9 -0
- package/docs/apiReference.ts +15 -0
- package/executors/appExecutor.ts +26 -12
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1690 -0
- package/executors/executor.ts +14 -6
- package/executors/executors.test.ts +140 -1
- package/executors/sysExecutor.ts +112 -8
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +99 -7
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +686 -13
- package/frontendBuild/clientBuildTypes.ts +26 -0
- package/frontendBuild/clientEntriesBundler.ts +49 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
- package/frontendBuild/clientEntryDiscovery.ts +136 -14
- package/frontendBuild/clientEntryGroups.test.ts +77 -0
- package/frontendBuild/clientEntryGroups.ts +61 -0
- package/frontendBuild/csrDevArtifactWriter.ts +2 -2
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.test.ts +1 -1
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +154 -0
- package/frontendBuild/devBarrelImports.ts +83 -23
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
- package/frontendBuild/dictionaryConstants.ts +136 -0
- package/frontendBuild/dictionaryOwnParts.ts +88 -0
- package/frontendBuild/dictionaryPackState.ts +131 -0
- package/frontendBuild/dictionaryPacking.test.ts +207 -0
- package/frontendBuild/dictionaryPacking.ts +160 -0
- package/frontendBuild/dictionaryRoutes.test.ts +251 -0
- package/frontendBuild/dictionaryRoutes.ts +227 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +78 -2
- package/frontendBuild/precompressArtifacts.test.ts +22 -0
- package/frontendBuild/precompressArtifacts.ts +34 -8
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/renderedEntries.ts +144 -0
- package/frontendBuild/routeClientBuilder.ts +407 -43
- package/frontendBuild/routeHandoffs.test.ts +155 -0
- package/frontendBuild/routeHandoffs.ts +117 -0
- package/frontendBuild/routeModulePreloads.test.ts +32 -0
- package/frontendBuild/routeModulePreloads.ts +20 -11
- package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
- package/frontendBuild/routeRuntimeCheck.ts +248 -0
- package/frontendBuild/routeRuntimePays.test.ts +143 -0
- package/frontendBuild/routeRuntimePays.ts +117 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
- package/frontendBuild/ssrDevBundler.test.ts +150 -1
- package/frontendBuild/ssrDevBundler.ts +66 -11
- package/frontendBuild/vendorFileImports.test.ts +254 -0
- package/frontendBuild/vendorFileImports.ts +163 -0
- package/frontendBuild/vendorNarrowing.ts +28 -0
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/incrementalBuilder/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeBase.test.ts +50 -3
- package/lint/biomeBase.ts +1 -1
- package/lint/biomeCheck.test.ts +162 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/linter.test.ts +16 -11
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/desktopBin.ts +2 -2
- package/mobile/desktopServerStage.test.ts +18 -3
- package/mobile/desktopServerStage.ts +7 -2
- package/mobile/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +96 -1
- package/mobile/nativeConfig.ts +46 -12
- package/mobile/nativePublicEnv.ts +1 -1
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +20 -171
- package/packageExports.test.ts +38 -24
- package/quality/dictionaryKeys.test.ts +356 -0
- package/quality/dictionaryKeys.ts +488 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +105 -0
- package/quality/qualityScanner.ts +1 -1
- package/quality/routeRuntimeReport.test.ts +91 -0
- package/quality/routeRuntimeReport.ts +121 -0
- package/quality/runtimeConstantFacts.ts +71 -0
- package/quality/runtimeConstantGraph.ts +123 -0
- package/quality/runtimeConstantReads.ts +116 -0
- package/quality/runtimeImports.test.ts +190 -0
- package/quality/runtimeImports.ts +233 -0
- package/quality/runtimeKeyNames.ts +46 -0
- package/quality/runtimeLexicalScope.ts +132 -0
- package/quality/runtimeMarkerReach.test.ts +84 -0
- package/quality/runtimeMarkerReach.ts +255 -0
- package/quality/runtimeModuleFacts.ts +290 -0
- package/quality/runtimeNameTable.test.ts +172 -0
- package/quality/runtimeNameTable.ts +477 -0
- package/quality/runtimeScopeReport.test.ts +123 -0
- package/quality/runtimeScopeReport.ts +167 -0
- package/quality/runtimeSliceKey.ts +269 -0
- package/quality/runtimeSyntax.ts +133 -0
- package/quality/runtimeTable.fixture.ts +189 -0
- package/quality/runtimeUse.test.ts +737 -0
- package/quality/runtimeUse.ts +696 -0
- package/quality/runtimeUseReadable.test.ts +393 -0
- package/quality/ssrScanner.test.ts +13 -0
- package/quality/ssrScanner.ts +1 -1
- package/quality/translatorBindings.ts +187 -0
- package/test/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +26 -4
- package/transforms/barrelImportsPlugin.ts +121 -32
- package/transforms/exportReach.test.ts +162 -0
- package/transforms/exportReach.ts +308 -0
- package/transforms/frameworkObjects.fixture.tsx +58 -0
- package/transforms/frameworkObjects.test.ts +54 -0
- package/transforms/modelReference.test.ts +196 -0
- package/transforms/modelReference.ts +39 -0
- package/transforms/moduleParts.test.ts +225 -0
- package/transforms/moduleParts.ts +418 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +633 -0
- package/transforms/objectMemberImports.ts +571 -0
- package/transforms/objectMemberLookup.ts +150 -0
- package/transforms/objectModule.test.ts +307 -0
- package/transforms/objectModule.ts +482 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/partImports.test.ts +76 -0
- package/transforms/partImports.ts +110 -0
- package/transforms/partModules.test.ts +187 -0
- package/transforms/partModules.ts +90 -0
- package/transforms/partPurity.ts +124 -0
- package/transforms/reactIconImports.test.ts +231 -0
- package/transforms/reactIconImports.ts +325 -0
- package/transforms/routeConstants.ts +122 -0
- package/transforms/routeRuntime.test.ts +835 -0
- package/transforms/routeRuntime.ts +703 -0
- package/transforms/routeRuntimeEdits.ts +92 -0
- package/transforms/routeRuntimeGraph.ts +66 -0
- package/transforms/routeRuntimePlan.ts +244 -0
- package/transforms/secretEnvDeclaration.test.ts +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +129 -2
- package/transforms/serverEnvProfile.ts +126 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/transforms/signalDescriptors.test.ts +280 -0
- package/transforms/signalDescriptors.ts +227 -0
- package/transforms/thisFreeExports.ts +87 -0
- package/transforms/transforms.test.ts +180 -3
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +22 -11
- package/tunnel/ssh2Module.test.ts +37 -0
- package/tunnel/ssh2Module.ts +32 -0
- package/tunnel/sshTunnel.ts +4 -2
- package/typecheck/projectTypecheck.test.ts +32 -1
- package/typecheck/projectTypecheck.ts +3 -3
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -0
- package/workflow/executor.ts +6 -2
- package/workflow/index.ts +1 -0
- package/workflow/plan.ts +36 -7
- package/workflow/types.ts +1 -1
- package/workflow/uiTarget.ts +50 -0
- package/workspace/envSeed.test.ts +30 -1
- package/workspace/envSeed.ts +30 -1
- package/workspace/getRelatedCnsts.ts +7 -0
- package/workspace/mainCheckout.test.ts +55 -0
- package/workspace/mainCheckout.ts +38 -0
- package/workspace/scanInfo.test.ts +39 -0
- package/workspace/scanInfo.ts +55 -6
- package/workspace/slicePlanner.ts +1 -1
- package/workspace/workspaceLayout.test.ts +5 -1
- package/workspace/workspaceLayout.ts +3 -0
- package/CHANGELOG.md +0 -2717
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { BunPlugin } from "bun";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { VendorNarrowing } from "./vendorNarrowing";
|
|
6
|
+
import { VENDOR_SPECIFIERS, type VendorSpecifier } from "./vendorSpecifiers";
|
|
7
|
+
|
|
8
|
+
const scriptExtensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
9
|
+
//? Only the vendor a page loaded twice: a file of another vendor reached by its path stays in the build, as before.
|
|
10
|
+
const fileVendors: readonly VendorSpecifier[] = ["akanjs/client"];
|
|
11
|
+
|
|
12
|
+
//? A route build bundles a file of a vendor package reached by its path, beside the copy the vendor carries and the
|
|
13
|
+
//? state that copy holds; a file the vendor's barrel re-exports whole, under the same names, comes from the vendor.
|
|
14
|
+
export class VendorFileImports {
|
|
15
|
+
readonly specifiers: readonly VendorSpecifier[];
|
|
16
|
+
readonly #akanjsRoots: readonly string[];
|
|
17
|
+
readonly #specifierByModule: ReadonlyMap<string, VendorSpecifier>;
|
|
18
|
+
readonly #realDirs = new Map<string, string>();
|
|
19
|
+
|
|
20
|
+
static async of(workspaceRoot: string): Promise<VendorFileImports> {
|
|
21
|
+
const akanServerPath = await VendorFileImports.#akanServerPath(workspaceRoot);
|
|
22
|
+
return akanServerPath
|
|
23
|
+
? new VendorFileImports(path.dirname(akanServerPath), VendorFileImports.#shippedIn(akanServerPath))
|
|
24
|
+
: new VendorFileImports(null, VENDOR_SPECIFIERS);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static async specifiersIn(workspaceRoot: string): Promise<readonly VendorSpecifier[]> {
|
|
28
|
+
const akanServerPath = await VendorFileImports.#akanServerPath(workspaceRoot);
|
|
29
|
+
return akanServerPath ? VendorFileImports.#shippedIn(akanServerPath) : VENDOR_SPECIFIERS;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//? Only the vendors this akanjs ships an entry for: an older one has no `akanjs/client` vendor to import from.
|
|
33
|
+
static #shippedIn(akanServerPath: string): VendorSpecifier[] {
|
|
34
|
+
return VendorNarrowing.entriesIn(akanServerPath).map(({ specifier }) => specifier);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static async #akanServerPath(workspaceRoot: string): Promise<string | null> {
|
|
38
|
+
try {
|
|
39
|
+
return await VendorNarrowing.akanServerPath(workspaceRoot);
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
constructor(akanjsRoot: string | null, specifiers: readonly VendorSpecifier[]) {
|
|
46
|
+
this.specifiers = specifiers;
|
|
47
|
+
this.#akanjsRoots = akanjsRoot ? [...new Set([path.resolve(akanjsRoot), fs.realpathSync(akanjsRoot)])] : [];
|
|
48
|
+
this.#specifierByModule = akanjsRoot ? this.#mapModules(akanjsRoot) : new Map();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#mapModules(akanjsRoot: string): Map<string, VendorSpecifier> {
|
|
52
|
+
const specifierByModule = new Map<string, VendorSpecifier>();
|
|
53
|
+
const packaged = this.specifiers.filter((specifier) => fileVendors.includes(specifier));
|
|
54
|
+
for (const specifier of packaged) {
|
|
55
|
+
const barrel = VendorFileImports.#fileOf(path.join(akanjsRoot, specifier.slice("akanjs/".length)));
|
|
56
|
+
if (!barrel) continue;
|
|
57
|
+
for (const file of [barrel, ...VendorFileImports.wholeReexports(barrel)])
|
|
58
|
+
for (const root of this.#akanjsRoots)
|
|
59
|
+
for (const key of VendorFileImports.#moduleKeys(path.join(root, path.relative(akanjsRoot, file))))
|
|
60
|
+
if (!specifierByModule.has(key)) specifierByModule.set(key, specifier);
|
|
61
|
+
}
|
|
62
|
+
return specifierByModule;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
vendorOf(request: string, importer: string): VendorSpecifier | null {
|
|
66
|
+
const [akanjsRoot] = this.#akanjsRoots;
|
|
67
|
+
if (!akanjsRoot) return null;
|
|
68
|
+
const target = request.startsWith("akanjs/")
|
|
69
|
+
? path.join(akanjsRoot, request.slice("akanjs/".length))
|
|
70
|
+
: request.startsWith(".") || path.isAbsolute(request)
|
|
71
|
+
? path.resolve(path.dirname(importer), request)
|
|
72
|
+
: null;
|
|
73
|
+
if (!target) return null;
|
|
74
|
+
const extension = path.extname(target);
|
|
75
|
+
const module = scriptExtensions.includes(extension) ? target.slice(0, -extension.length) : target;
|
|
76
|
+
return this.#specifierByModule.get(module) ?? this.#specifierByModule.get(this.#realModule(module)) ?? null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//? A linked install reaches akanjs through a symlink, so an entry's path need not be the one Bun resolved.
|
|
80
|
+
#realModule(module: string): string {
|
|
81
|
+
const dir = path.dirname(module);
|
|
82
|
+
let realDir = this.#realDirs.get(dir);
|
|
83
|
+
if (realDir === undefined) {
|
|
84
|
+
realDir = fs.existsSync(dir) ? fs.realpathSync(dir) : dir;
|
|
85
|
+
this.#realDirs.set(dir, realDir);
|
|
86
|
+
}
|
|
87
|
+
return path.join(realDir, path.basename(module));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//? A dynamic import stays a lazy chunk of the route build: `import("akanjs/client")` would load the whole vendor.
|
|
91
|
+
plugin(): BunPlugin {
|
|
92
|
+
return {
|
|
93
|
+
name: "akan-vendor-file-imports",
|
|
94
|
+
setup: (build) => {
|
|
95
|
+
build.onResolve({ filter: /^(\.|\/|akanjs\/)/ }, (args) => {
|
|
96
|
+
if (args.kind !== "import-statement" || !args.importer) return undefined;
|
|
97
|
+
const specifier = this.vendorOf(args.path, args.importer);
|
|
98
|
+
return specifier && specifier !== args.path ? { path: specifier, external: true } : undefined;
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static wholeReexports(barrel: string): string[] {
|
|
105
|
+
const text = fs.readFileSync(barrel, "utf8");
|
|
106
|
+
const source = ts.createSourceFile(barrel, text, ts.ScriptTarget.Latest, false);
|
|
107
|
+
const sourceOfName = new Map<string, string | null>();
|
|
108
|
+
const starred = new Map<string, string | null>();
|
|
109
|
+
const files = new Set<string>();
|
|
110
|
+
for (const statement of source.statements) {
|
|
111
|
+
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly) continue;
|
|
112
|
+
const { moduleSpecifier, exportClause } = statement;
|
|
113
|
+
if (!moduleSpecifier || !ts.isStringLiteral(moduleSpecifier)) continue;
|
|
114
|
+
const file = VendorFileImports.#fileOf(path.resolve(path.dirname(barrel), moduleSpecifier.text));
|
|
115
|
+
if (!file) continue;
|
|
116
|
+
files.add(file);
|
|
117
|
+
if (!exportClause) {
|
|
118
|
+
for (const name of VendorFileImports.#exportsOf(file) ?? [])
|
|
119
|
+
if (name !== "default") starred.set(name, starred.has(name) && starred.get(name) !== file ? null : file);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (!ts.isNamedExports(exportClause)) continue;
|
|
123
|
+
for (const element of exportClause.elements) {
|
|
124
|
+
if (element.isTypeOnly) continue;
|
|
125
|
+
const exported = element.name.text;
|
|
126
|
+
sourceOfName.set(exported, (element.propertyName ?? element.name).text === exported ? file : null);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//? A name the barrel exports itself shadows the one an `export *` brings in, so no starred file owns it.
|
|
130
|
+
for (const name of VendorFileImports.#scannedExports(barrel, text))
|
|
131
|
+
if (!sourceOfName.has(name)) sourceOfName.set(name, null);
|
|
132
|
+
const sourceOf = (name: string) => (sourceOfName.has(name) ? sourceOfName.get(name) : starred.get(name)) ?? null;
|
|
133
|
+
return [...files].filter((file) => {
|
|
134
|
+
const names = VendorFileImports.#exportsOf(file);
|
|
135
|
+
return !!names && names.length > 0 && names.every((name) => sourceOf(name) === file);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//? `null` for a file that re-exports with `export *`: its names are not all in its own source.
|
|
140
|
+
static #exportsOf(file: string): string[] | null {
|
|
141
|
+
const source = fs.readFileSync(file, "utf8");
|
|
142
|
+
if (/^\s*export\s*\*/m.test(source)) return null;
|
|
143
|
+
return VendorFileImports.#scannedExports(file, source);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static #scannedExports(file: string, source: string): string[] {
|
|
147
|
+
const loader = file.endsWith(".tsx") || file.endsWith(".jsx") ? "tsx" : "ts";
|
|
148
|
+
return new Bun.Transpiler({ loader }).scan(source).exports;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static #fileOf(base: string): string | null {
|
|
152
|
+
for (const candidate of [...scriptExtensions.map((ext) => `${base}${ext}`), path.join(base, "index.ts")])
|
|
153
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return candidate;
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static #moduleKeys(file: string): string[] {
|
|
158
|
+
const withoutExtension = file.slice(0, -path.extname(file).length);
|
|
159
|
+
return path.basename(withoutExtension) === "index"
|
|
160
|
+
? [withoutExtension, path.dirname(withoutExtension)]
|
|
161
|
+
: [withoutExtension];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -16,6 +16,34 @@ export class VendorNarrowing {
|
|
|
16
16
|
readonly #akanjsRoot: string;
|
|
17
17
|
readonly #vendorExports: Partial<Record<VendorSpecifier, readonly string[]>>;
|
|
18
18
|
|
|
19
|
+
static async akanServerPath(workspaceRoot: string): Promise<string> {
|
|
20
|
+
const candidates: string[] = [];
|
|
21
|
+
try {
|
|
22
|
+
candidates.push(path.dirname(Bun.resolveSync("akanjs/server", workspaceRoot)));
|
|
23
|
+
} catch {
|
|
24
|
+
// Source workspaces and bundled CLI execution have different resolution roots; try explicit candidates below.
|
|
25
|
+
}
|
|
26
|
+
candidates.push(
|
|
27
|
+
path.join(workspaceRoot, "pkgs/akanjs/server"),
|
|
28
|
+
path.join(workspaceRoot, "node_modules/akanjs/server"),
|
|
29
|
+
);
|
|
30
|
+
try {
|
|
31
|
+
candidates.push(path.dirname(Bun.resolveSync("akanjs/server", path.dirname(Bun.main))));
|
|
32
|
+
} catch {
|
|
33
|
+
// Published CLI installs may hoist dependencies differently; explicit Bun.main candidates cover that.
|
|
34
|
+
}
|
|
35
|
+
candidates.push(
|
|
36
|
+
path.join(path.dirname(Bun.main), "node_modules/akanjs/server"),
|
|
37
|
+
path.join(path.dirname(Bun.main), "../../akanjs/server"),
|
|
38
|
+
path.resolve(import.meta.dir, "../../server"),
|
|
39
|
+
path.resolve(import.meta.dir, "../server"),
|
|
40
|
+
);
|
|
41
|
+
for (const candidate of candidates) {
|
|
42
|
+
if (await Bun.file(path.join(candidate, "rscClient.tsx")).exists()) return candidate;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`[base-artifact] failed to locate akanjs/server; looked in: ${candidates.join(", ")}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
19
47
|
//? A devkit newer than the installed akanjs finds no agent vendor or deprecated re-export there, and builds that
|
|
20
48
|
//? akanjs's vendors whole, as the devkit it shipped with did.
|
|
21
49
|
static entriesIn(akanServerPath: string): VendorEntry[] {
|
|
@@ -10,6 +10,7 @@ export const VENDOR_SPECIFIERS = [
|
|
|
10
10
|
"akanjs/store",
|
|
11
11
|
"akanjs/store/agent",
|
|
12
12
|
"akanjs/base",
|
|
13
|
+
"akanjs/client",
|
|
13
14
|
"akanjs/common",
|
|
14
15
|
"akanjs/constant",
|
|
15
16
|
"akanjs/fetch",
|
|
@@ -24,6 +25,7 @@ export const NARROWABLE_VENDOR_SPECIFIERS = [
|
|
|
24
25
|
"akanjs/store",
|
|
25
26
|
"akanjs/store/agent",
|
|
26
27
|
"akanjs/base",
|
|
28
|
+
"akanjs/client",
|
|
27
29
|
"akanjs/common",
|
|
28
30
|
"akanjs/constant",
|
|
29
31
|
"akanjs/fetch",
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import { Logger } from "akanjs/common";
|
|
3
|
+
import type { BuilderMessage, BuildPhase, HmrTrace } from "akanjs/server";
|
|
4
|
+
import { resolveDevCsrMode } from "akanjs/server/hmr/csrDevManifest";
|
|
5
|
+
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
6
|
+
import { resolveSsrPageEntriesForApp } from "../artifact/implicitRootLayout";
|
|
7
|
+
import { computeRouteSeedIndex, saveRouteSeedIndex } from "../artifact/routeSeedIndex";
|
|
8
|
+
import type { App } from "../commandDecorators";
|
|
6
9
|
// Subpath imports only, as few as possible: spawned per generation, this process pays every import on every save.
|
|
7
|
-
import { AppExecutor, WorkspaceExecutor } from "
|
|
10
|
+
import { AppExecutor, WorkspaceExecutor } from "../executors";
|
|
8
11
|
import {
|
|
9
12
|
CsrArtifactBuilder,
|
|
10
13
|
CsrDevBundler,
|
|
@@ -14,10 +17,7 @@ import {
|
|
|
14
17
|
ServerGraphFile,
|
|
15
18
|
SsrBaseArtifactBuilder,
|
|
16
19
|
SsrDevBundler,
|
|
17
|
-
} from "
|
|
18
|
-
import { Logger } from "akanjs/common";
|
|
19
|
-
import type { BuilderMessage, BuildPhase, HmrTrace } from "akanjs/server";
|
|
20
|
-
import { resolveDevCsrMode } from "akanjs/server/hmr/csrDevManifest";
|
|
20
|
+
} from "../frontendBuild";
|
|
21
21
|
import type { BuildBatchRequest, BuildBatchResult, OptimizedFonts, PagesBatchCssAssets } from "./buildBatchProtocol";
|
|
22
22
|
|
|
23
23
|
// `Bun.build` keeps native bundler arenas that `Bun.gc(true)` cannot reclaim; only exiting returns them.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FontOptimizer } from "@akanjs/devkit/frontendBuild";
|
|
2
1
|
import type { BaseBuildArtifact, CssPayload, HmrTrace, PagesBundlePayload } from "akanjs/server";
|
|
2
|
+
import type { FontOptimizer } from "../frontendBuild";
|
|
3
3
|
|
|
4
4
|
export type OptimizedFonts = Awaited<ReturnType<FontOptimizer["optimize"]>>;
|
|
5
5
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
|
-
import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
|
|
4
|
-
import { GraphClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientEntryDiscovery";
|
|
5
|
-
import { HmrWatcher } from "@akanjs/devkit/frontendBuild/hmrWatcher";
|
|
6
|
-
import { WatchRootResolver } from "@akanjs/devkit/frontendBuild/watchRootResolver";
|
|
7
2
|
import type { Logger } from "akanjs/common";
|
|
8
3
|
import type { BaseBuildArtifact } from "akanjs/server";
|
|
4
|
+
import type { App } from "../commandDecorators";
|
|
5
|
+
import type { ClientEntryDiscovery } from "../frontendBuild/clientBuildTypes";
|
|
6
|
+
import { GraphClientEntryDiscovery } from "../frontendBuild/clientEntryDiscovery";
|
|
7
|
+
import { HmrWatcher } from "../frontendBuild/hmrWatcher";
|
|
8
|
+
import { WatchRootResolver } from "../frontendBuild/watchRootResolver";
|
|
9
9
|
import type { OptimizedFonts } from "./buildBatchProtocol";
|
|
10
10
|
import type { BuildBatchRunner } from "./buildBatchRunner";
|
|
11
11
|
import { BuilderChannel } from "./builderChannel";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
2
|
-
import { FrameworkGraph } from "@akanjs/devkit/docs/frameworkGraph";
|
|
3
|
-
import { GitRevision } from "@akanjs/devkit/workspace/gitRevision";
|
|
4
|
-
import { WorkspaceGraph } from "@akanjs/devkit/workspace/workspaceGraph";
|
|
5
1
|
import type { BuildChangesPayload, BuilderGraphReq, BuildFrameworkPayload, BuildGraphPayload } from "akanjs/server";
|
|
2
|
+
import type { App } from "../commandDecorators";
|
|
3
|
+
import { FrameworkGraph } from "../docs/frameworkGraph";
|
|
4
|
+
import { GitRevision } from "../workspace/gitRevision";
|
|
5
|
+
import { WorkspaceGraph } from "../workspace/workspaceGraph";
|
|
6
6
|
|
|
7
7
|
export class BuilderGraphPayloads {
|
|
8
8
|
readonly #app: App;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
|
|
2
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
1
|
import type { Logger } from "akanjs/common";
|
|
2
|
+
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
3
|
+
import type { App } from "../commandDecorators";
|
|
4
4
|
import type { BatchWork, BuildBatchResult } from "./buildBatchProtocol";
|
|
5
5
|
import { sendBuildStatus } from "./builderBuildStatus";
|
|
6
6
|
import { BuilderChannel } from "./builderChannel";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
|
-
import type { PageRoot } from "@akanjs/devkit/executors";
|
|
4
|
-
import { AutoImportSync } from "@akanjs/devkit/frontendBuild/autoImportSync";
|
|
5
|
-
import { DevChangePlanner } from "@akanjs/devkit/frontendBuild/devChangePlanner";
|
|
6
|
-
import { DevGeneratedIndexSync } from "@akanjs/devkit/frontendBuild/devGeneratedIndexSync";
|
|
7
|
-
import { HmrWatcher } from "@akanjs/devkit/frontendBuild/hmrWatcher";
|
|
8
|
-
import { WatchRootResolver } from "@akanjs/devkit/frontendBuild/watchRootResolver";
|
|
9
|
-
import { CodegenLock } from "@akanjs/devkit/workspace/codegenLock";
|
|
10
2
|
import type { Logger } from "akanjs/common";
|
|
11
3
|
import type { ChangeBatch } from "akanjs/server";
|
|
4
|
+
import type { App } from "../commandDecorators";
|
|
5
|
+
import type { PageRoot } from "../executors";
|
|
6
|
+
import { AutoImportSync } from "../frontendBuild/autoImportSync";
|
|
7
|
+
import { DevChangePlanner } from "../frontendBuild/devChangePlanner";
|
|
8
|
+
import { DevGeneratedIndexSync } from "../frontendBuild/devGeneratedIndexSync";
|
|
9
|
+
import { HmrWatcher } from "../frontendBuild/hmrWatcher";
|
|
10
|
+
import { WatchRootResolver } from "../frontendBuild/watchRootResolver";
|
|
11
|
+
import { CodegenLock } from "../workspace/codegenLock";
|
|
12
12
|
import type { BuildBatchNeed } from "./buildBatchProtocol";
|
|
13
13
|
import { sendBuildStatus } from "./builderBuildStatus";
|
|
14
14
|
import { BuilderChannel } from "./builderChannel";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { rm } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
|
|
4
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
5
|
-
import { CsrDevBundler } from "@akanjs/devkit/frontendBuild/csrDevBundler";
|
|
6
|
-
import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
|
|
7
3
|
import type { Logger } from "akanjs/common";
|
|
8
4
|
import type { BaseBuildArtifact, BuilderCsrReq, HmrTrace } from "akanjs/server";
|
|
9
5
|
import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
|
|
6
|
+
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
7
|
+
import type { App } from "../commandDecorators";
|
|
8
|
+
import { CsrDevBundler } from "../frontendBuild/csrDevBundler";
|
|
9
|
+
import { CsrDevPatcher } from "../frontendBuild/csrDevPatcher";
|
|
10
10
|
import type { BatchWork, BuildBatchRequest } from "./buildBatchProtocol";
|
|
11
11
|
import type { BuildBatchRunner } from "./buildBatchRunner";
|
|
12
12
|
import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
|
|
@@ -645,6 +645,85 @@ else {
|
|
|
645
645
|
}
|
|
646
646
|
}, 60_000);
|
|
647
647
|
|
|
648
|
+
test("a route whose client entries an earlier route built still reads their dictionary groups, and one this builder never built loads the whole file", async () => {
|
|
649
|
+
const { root } = track(await createTempApp("demo", path.join(import.meta.dir, "..", "local")));
|
|
650
|
+
const appDir = path.join(root, "apps/demo");
|
|
651
|
+
await writeText(
|
|
652
|
+
path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
|
|
653
|
+
`const { generation, needs } = JSON.parse(process.argv[2]);
|
|
654
|
+
if (needs.includes("ssr")) await import(${JSON.stringify(path.join(import.meta.dir, "buildBatch.proc.ts"))});
|
|
655
|
+
else {
|
|
656
|
+
process.once("disconnect", () => {});
|
|
657
|
+
process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
|
|
658
|
+
}
|
|
659
|
+
`,
|
|
660
|
+
);
|
|
661
|
+
await writeText(path.join(appDir, "akan.config.ts"), "export default {};\n");
|
|
662
|
+
await writeText(path.join(appDir, "env/env.client.ts"), "export const env = {} as const;\n");
|
|
663
|
+
const pages = {
|
|
664
|
+
first: path.join(appDir, "page/_index.tsx"),
|
|
665
|
+
same: path.join(appDir, "page/same.tsx"),
|
|
666
|
+
more: path.join(appDir, "page/more.tsx"),
|
|
667
|
+
lone: path.join(appDir, "page/lone.tsx"),
|
|
668
|
+
};
|
|
669
|
+
await writeText(pages.lone, 'import { Lone } from "../ui/Lone";\nexport default Lone;\n');
|
|
670
|
+
await writeText(pages.first, 'import { Card } from "../ui/Card";\nexport default Card;\n');
|
|
671
|
+
await writeText(pages.same, 'import { Card } from "../ui/Card";\nexport default Card;\n');
|
|
672
|
+
await writeText(
|
|
673
|
+
pages.more,
|
|
674
|
+
'import { Card } from "../ui/Card";\nimport { Note } from "../ui/Note";\nexport default () => [Card, Note];\n',
|
|
675
|
+
);
|
|
676
|
+
const card = path.join(appDir, "ui/Card.tsx");
|
|
677
|
+
await writeText(card, '"use client";\nimport { Label } from "./Label";\nexport const Card = () => Label();\n');
|
|
678
|
+
await writeText(
|
|
679
|
+
path.join(appDir, "ui/Label.tsx"),
|
|
680
|
+
'declare const l: (key: string) => string;\nexport const Label = () => l("memo.title");\n',
|
|
681
|
+
);
|
|
682
|
+
await writeText(path.join(appDir, "ui/Note.tsx"), '"use client";\nexport const Note = () => null;\n');
|
|
683
|
+
const lone = path.join(appDir, "ui/Lone.tsx");
|
|
684
|
+
await writeText(lone, '"use client";\nexport const Lone = () => null;\n');
|
|
685
|
+
|
|
686
|
+
const messages: BuilderMessage[] = [];
|
|
687
|
+
const proc = Bun.spawn(["bun", path.join(import.meta.dir, "incrementalBuilder.proc.ts")], {
|
|
688
|
+
cwd: appDir,
|
|
689
|
+
env: {
|
|
690
|
+
...process.env,
|
|
691
|
+
AKAN_WORKSPACE_ROOT: root,
|
|
692
|
+
AKAN_PUBLIC_APP_NAME: "demo",
|
|
693
|
+
AKAN_PUBLIC_REPO_NAME: "repo",
|
|
694
|
+
AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
|
|
695
|
+
AKAN_PUBLIC_ENV: "local",
|
|
696
|
+
AKAN_WATCH: "0",
|
|
697
|
+
},
|
|
698
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
699
|
+
serialization: "advanced",
|
|
700
|
+
ipc: (message: BuilderMessage) => {
|
|
701
|
+
messages.push(message);
|
|
702
|
+
},
|
|
703
|
+
});
|
|
704
|
+
const buildRoute = async (id: number, routeId: string, seed: string, knownEntries: string[]) => {
|
|
705
|
+
proc.send({ type: "build-route", id, routeId, seeds: [seed], knownEntries, generation: 3 } satisfies BuilderReq);
|
|
706
|
+
await until(proc, `build-route-res ${id}`, () =>
|
|
707
|
+
messages.some((message) => message.type === "build-route-res" && message.id === id),
|
|
708
|
+
);
|
|
709
|
+
const res = messages.find((message) => message.type === "build-route-res" && message.id === id);
|
|
710
|
+
if (res?.type !== "build-route-res" || !res.ok) throw new Error(`route ${routeId} did not build`);
|
|
711
|
+
return res.data;
|
|
712
|
+
};
|
|
713
|
+
try {
|
|
714
|
+
await until(proc, "boot-armed", () => messages.some((message) => message.type === "boot-armed"));
|
|
715
|
+
const first = await buildRoute(1, "page:/", pages.first, []);
|
|
716
|
+
expect(first.newEntries).toEqual([card]);
|
|
717
|
+
expect(first.dictionaryGroups).toEqual(["base", "memo"]);
|
|
718
|
+
expect((await buildRoute(2, "page:/more", pages.more, [card])).dictionaryGroups).toEqual(["base", "memo"]);
|
|
719
|
+
expect((await buildRoute(3, "page:/same", pages.same, [card])).dictionaryGroups).toEqual(["base", "memo"]);
|
|
720
|
+
expect((await buildRoute(4, "page:/lone", pages.lone, [lone])).dictionaryGroups).toBeNull();
|
|
721
|
+
} finally {
|
|
722
|
+
proc.kill();
|
|
723
|
+
await proc.exited;
|
|
724
|
+
}
|
|
725
|
+
}, 60_000);
|
|
726
|
+
|
|
648
727
|
test("a failed boot build waits for the save that fixes it, and the builder it recovers continues the generation and watches", async () => {
|
|
649
728
|
const { root } = track(await createTempApp("demo"));
|
|
650
729
|
const appDir = path.join(root, "apps/demo");
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
// Module paths, never a barrel: the devkit and `frontendBuild` barrels would hold tailwindcss (~40MB), ssh2, ink
|
|
3
|
-
// and the cloud stack for the whole dev session (`entryModuleGraph.test.ts` enforces it).
|
|
4
|
-
import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
|
|
5
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
6
|
-
import { AppExecutor, type PageRoot, WorkspaceExecutor } from "@akanjs/devkit/executors";
|
|
7
|
-
import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
|
|
8
|
-
import { GraphClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientEntryDiscovery";
|
|
9
|
-
import { RouteClientBuilder } from "@akanjs/devkit/frontendBuild/routeClientBuilder";
|
|
10
2
|
import { Logger } from "akanjs/common";
|
|
11
3
|
import type {
|
|
12
4
|
BaseBuildArtifact,
|
|
@@ -18,6 +10,15 @@ import type {
|
|
|
18
10
|
BuildRouteResultPayload,
|
|
19
11
|
ChangeBatch,
|
|
20
12
|
} from "akanjs/server";
|
|
13
|
+
// Module paths, never a barrel: the devkit and `frontendBuild` barrels would hold tailwindcss (~40MB), ssh2, ink
|
|
14
|
+
// and the cloud stack for the whole dev session (`entryModuleGraph.test.ts` enforces it).
|
|
15
|
+
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
16
|
+
import type { App } from "../commandDecorators";
|
|
17
|
+
import { AppExecutor, type PageRoot, WorkspaceExecutor } from "../executors";
|
|
18
|
+
import type { ClientEntryDiscovery, ClientModuleImport } from "../frontendBuild/clientBuildTypes";
|
|
19
|
+
import { GraphClientEntryDiscovery } from "../frontendBuild/clientEntryDiscovery";
|
|
20
|
+
import { DictionaryRoutes } from "../frontendBuild/dictionaryRoutes";
|
|
21
|
+
import { RouteClientBuilder } from "../frontendBuild/routeClientBuilder";
|
|
21
22
|
import type { BatchWork, BuildBatchRequest, BuildBatchResult, OptimizedFonts } from "./buildBatchProtocol";
|
|
22
23
|
import { BuildBatchRunner } from "./buildBatchRunner";
|
|
23
24
|
import { BuilderBoot, type IncrementalBuilderOptions } from "./builderBoot";
|
|
@@ -44,6 +45,8 @@ class IncrementalBuilder {
|
|
|
44
45
|
#discoveredThrough = 0;
|
|
45
46
|
/** How often each reason sent a registry save to a build worker this session: the resident patcher's miss rate. */
|
|
46
47
|
readonly #delegations = new Map<string, number>();
|
|
48
|
+
//? A route build bundles only entries no earlier route built: the dictionary walk reads every build's graph.
|
|
49
|
+
readonly #dictionaryGraph = new Map<string, readonly ClientModuleImport[]>();
|
|
47
50
|
readonly #lanes: BuilderLanes;
|
|
48
51
|
readonly #csr: CsrRegistry;
|
|
49
52
|
readonly #ssr: SsrRegistry;
|
|
@@ -113,6 +116,7 @@ class IncrementalBuilder {
|
|
|
113
116
|
browser: "registry",
|
|
114
117
|
}).build();
|
|
115
118
|
await this.#ssr.ensureSsrEntries(delta.registryEntries ?? []);
|
|
119
|
+
const dictionaryGroups = await this.#dictionaryGroupsOf(msg.seeds, delta);
|
|
116
120
|
this.#logger.verbose(`build-route ok routeId=${msg.routeId} newEntries=${delta.newEntries.length}`);
|
|
117
121
|
//? The builder's generation, not the route cache's: the cache's does not move when a fixed file maps to no entry,
|
|
118
122
|
//? so the rebuild's ok would carry the failure's own number.
|
|
@@ -131,6 +135,7 @@ class IncrementalBuilder {
|
|
|
131
135
|
routeId: msg.routeId,
|
|
132
136
|
generation: msg.generation,
|
|
133
137
|
seenGeneration,
|
|
138
|
+
dictionaryGroups,
|
|
134
139
|
} as BuildRouteResultPayload,
|
|
135
140
|
};
|
|
136
141
|
} catch (err) {
|
|
@@ -147,6 +152,20 @@ class IncrementalBuilder {
|
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
154
|
|
|
155
|
+
//? A route whose groups could not be read loads the whole page file, as one with a key no build can follow does.
|
|
156
|
+
async #dictionaryGroupsOf(
|
|
157
|
+
seeds: string[],
|
|
158
|
+
{ clientGraph, discoveredEntries, newEntries }: Awaited<ReturnType<RouteClientBuilder["build"]>>,
|
|
159
|
+
): Promise<string[] | null> {
|
|
160
|
+
for (const [module, imports] of clientGraph ?? []) this.#dictionaryGraph.set(module, imports);
|
|
161
|
+
const entries = discoveredEntries ?? newEntries;
|
|
162
|
+
const route = { seeds, entries, importsByModule: this.#dictionaryGraph, discovery: this.#discovery };
|
|
163
|
+
return DictionaryRoutes.ofBuiltRoute(this.#app, route).catch((error: unknown) => {
|
|
164
|
+
this.#logger.warn(`dictionary groups of the route could not be read: ${String(error)}`);
|
|
165
|
+
return null;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
150
169
|
// Exits so the OS reclaims the bundler arenas; the host spawns the replacement.
|
|
151
170
|
async shutdown(reason: string): Promise<void> {
|
|
152
171
|
if (this.#lanes.shuttingDown) return;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { rm } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
|
|
4
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
5
|
-
import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
|
|
6
|
-
import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
|
|
7
|
-
import { ServerGraphFile } from "@akanjs/devkit/frontendBuild/serverGraphFile";
|
|
8
|
-
import { SsrDevBundler } from "@akanjs/devkit/frontendBuild/ssrDevBundler";
|
|
9
3
|
import type { Logger } from "akanjs/common";
|
|
10
4
|
import type { HmrTrace } from "akanjs/server";
|
|
11
5
|
import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
|
|
6
|
+
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
7
|
+
import type { App } from "../commandDecorators";
|
|
8
|
+
import type { ClientEntryDiscovery } from "../frontendBuild/clientBuildTypes";
|
|
9
|
+
import { CsrDevPatcher } from "../frontendBuild/csrDevPatcher";
|
|
10
|
+
import { ServerGraphFile } from "../frontendBuild/serverGraphFile";
|
|
11
|
+
import { SsrDevBundler } from "../frontendBuild/ssrDevBundler";
|
|
12
12
|
import type { BatchWork, BuildBatchResult } from "./buildBatchProtocol";
|
|
13
13
|
import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
|
|
14
14
|
import { BuilderChannel } from "./builderChannel";
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// XXX: types only. A value import from this barrel loads every facet (ink, typescript, ssh2, …) into the process;
|
|
2
|
-
// `export type *` erases at runtime. Import values from the owning facet (`@akanjs/devkit/
|
|
2
|
+
// `export type *` erases at runtime. Import values from the owning facet (`@akanjs/devkit/frontendBuild`) and never
|
|
3
3
|
// "fix" a TS1362 by widening an entry back to `export *`.
|
|
4
4
|
export type * from "./akanApp";
|
|
5
5
|
export type * from "./akanConfig";
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { RenderAdmissionSoak } from "./renderAdmissionSoak";
|
|
6
|
+
|
|
7
|
+
const roots: string[] = [];
|
|
8
|
+
|
|
9
|
+
const workspace = () => {
|
|
10
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "akan-soak-"));
|
|
11
|
+
roots.push(root);
|
|
12
|
+
fs.mkdirSync(path.join(root, "apps", "shop", "page"), { recursive: true });
|
|
13
|
+
return { root, pageDir: RenderAdmissionSoak.pageDirOf(root, "shop") };
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const until = async (check: () => boolean, what: string) => {
|
|
17
|
+
const deadline = Date.now() + 20_000;
|
|
18
|
+
while (!check()) {
|
|
19
|
+
if (Date.now() > deadline) throw new Error(`timed out waiting for ${what}`);
|
|
20
|
+
await Bun.sleep(20);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("RenderAdmissionSoak page", () => {
|
|
29
|
+
test("refuses a `page/soak` the app already has, and leaves it as it was", () => {
|
|
30
|
+
const { pageDir } = workspace();
|
|
31
|
+
fs.mkdirSync(pageDir);
|
|
32
|
+
fs.writeFileSync(path.join(pageDir, "_index.tsx"), "export default null;");
|
|
33
|
+
|
|
34
|
+
expect(() => RenderAdmissionSoak.injectPage(pageDir)).toThrow("this script did not create it");
|
|
35
|
+
expect(fs.readdirSync(pageDir)).toEqual(["_index.tsx"]);
|
|
36
|
+
RenderAdmissionSoak.removePage(pageDir);
|
|
37
|
+
expect(fs.readdirSync(pageDir)).toEqual(["_index.tsx"]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("removes only what it wrote, and the directory only when nothing else is left in it", () => {
|
|
41
|
+
const { pageDir } = workspace();
|
|
42
|
+
RenderAdmissionSoak.injectPage(pageDir);
|
|
43
|
+
expect(fs.readdirSync(pageDir).sort()).toEqual([".render-admission-soak.json", "io.tsx"]);
|
|
44
|
+
fs.writeFileSync(path.join(pageDir, "notes.tsx"), "export default null;");
|
|
45
|
+
|
|
46
|
+
RenderAdmissionSoak.removePage(pageDir);
|
|
47
|
+
expect(fs.readdirSync(pageDir)).toEqual(["notes.tsx"]);
|
|
48
|
+
|
|
49
|
+
const fresh = workspace().pageDir;
|
|
50
|
+
RenderAdmissionSoak.injectPage(fresh);
|
|
51
|
+
RenderAdmissionSoak.removePage(fresh);
|
|
52
|
+
expect(fs.existsSync(fresh)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("takes over the page an earlier run of its own left behind", () => {
|
|
56
|
+
const { pageDir } = workspace();
|
|
57
|
+
RenderAdmissionSoak.injectPage(pageDir);
|
|
58
|
+
fs.writeFileSync(path.join(pageDir, "io.tsx"), "stale");
|
|
59
|
+
|
|
60
|
+
RenderAdmissionSoak.injectPage(pageDir);
|
|
61
|
+
expect(fs.readFileSync(path.join(pageDir, "io.tsx"), "utf8")).toContain("akanjs/client");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("a soak stopped while it builds removes its page and stops the build", async () => {
|
|
65
|
+
const { root, pageDir } = workspace();
|
|
66
|
+
const cli = path.join(root, "cli.ts");
|
|
67
|
+
const started = path.join(root, "build.pid");
|
|
68
|
+
fs.writeFileSync(
|
|
69
|
+
cli,
|
|
70
|
+
`await Bun.write(${JSON.stringify(started)}, String(process.pid));\nawait Bun.sleep(60_000);\n`,
|
|
71
|
+
);
|
|
72
|
+
const soak = Bun.spawn(
|
|
73
|
+
[
|
|
74
|
+
"bun",
|
|
75
|
+
path.join(import.meta.dir, "renderAdmissionSoak.ts"),
|
|
76
|
+
"shop",
|
|
77
|
+
"--prepare",
|
|
78
|
+
`--root=${root}`,
|
|
79
|
+
`--cli=${cli}`,
|
|
80
|
+
],
|
|
81
|
+
{ stdout: "ignore", stderr: "ignore" },
|
|
82
|
+
);
|
|
83
|
+
await until(() => fs.existsSync(started), "the build to start");
|
|
84
|
+
expect(fs.existsSync(path.join(pageDir, "io.tsx"))).toBe(true);
|
|
85
|
+
const buildPid = Number(fs.readFileSync(started, "utf8"));
|
|
86
|
+
|
|
87
|
+
soak.kill("SIGTERM");
|
|
88
|
+
expect(await soak.exited).toBe(130);
|
|
89
|
+
expect(fs.existsSync(pageDir)).toBe(false);
|
|
90
|
+
await until(() => {
|
|
91
|
+
try {
|
|
92
|
+
process.kill(buildPid, 0);
|
|
93
|
+
return false;
|
|
94
|
+
} catch {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}, "the build to stop");
|
|
98
|
+
}, 30_000);
|
|
99
|
+
});
|