@akanjs/devkit 3.3.0-rc.2 → 3.3.0-rc.21
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/CHANGELOG.md +284 -20
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +3 -2
- package/README.md +3 -3
- package/akanApp/akanApp.host.test.ts +1 -1
- package/akanConfig/akanConfig.test.ts +57 -8
- package/akanConfig/akanConfig.ts +16 -69
- package/akanConfig/dockerImage.ts +17 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/app/applicationBuildRunner.test.ts +321 -1
- package/app/applicationBuildRunner.ts +90 -3
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- 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-err/SKILL.md +11 -2
- package/codeAgent/skills/akan-page/SKILL.md +21 -26
- package/codeAgent/skills/akan-runtime/SKILL.md +41 -16
- package/codeAgent/skills/akan-service/SKILL.md +2 -2
- package/docs/apiReference.test.ts +14 -0
- package/docs/apiReference.ts +21 -3
- package/docs/declarationReader.ts +28 -1
- package/executors/appExecutor.ts +16 -7
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/buildRouteClient.test.ts +2 -7
- package/frontendBuild/clientEntryDiscovery.test.ts +35 -0
- package/frontendBuild/clientEntryDiscovery.ts +16 -3
- package/frontendBuild/cssCompiler.test.ts +112 -0
- package/frontendBuild/cssCompiler.ts +41 -21
- package/frontendBuild/devBarrelImports.test.ts +30 -0
- package/frontendBuild/devBarrelImports.ts +2 -2
- package/frontendBuild/pagesBundleBuilder.ts +3 -1
- package/frontendBuild/plainStylesheet.test.ts +155 -0
- package/frontendBuild/plainStylesheet.ts +197 -0
- package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
- package/frontendBuild/rscServerRendererGuard.ts +68 -0
- package/guideline/agentAssets.test.ts +10 -0
- package/guideline/agentAssets.ts +52 -11
- 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.ts +8 -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/biomeCheck.test.ts +145 -0
- package/lint/biomeCheck.ts +131 -0
- 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/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +117 -1
- package/mobile/nativeConfig.ts +66 -22
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +14 -169
- package/packageExports.test.ts +38 -24
- package/test/secretEnvFixture.ts +134 -0
- package/transforms/barrelAnalyzer.ts +2 -2
- 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 +115 -2
- package/transforms/serverEnvProfile.ts +117 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/transforms/transforms.test.ts +3 -3
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +18 -11
- package/typecheck/projectTypecheck.test.ts +29 -0
- 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/workspace/getRelatedCnsts.ts +7 -0
package/akanConfig/akanConfig.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { WorkspaceExecutor } from "../executors/workspaceExecutor";
|
|
|
11
11
|
import { ServerEnvProfile } from "../transforms/serverEnvProfile";
|
|
12
12
|
import type { BaseDevEnv, PackageJson } from "../workspace/types";
|
|
13
13
|
import { AkanBin } from "./akanBin";
|
|
14
|
+
import { DEFAULT_DOCKER_IMAGE, DOCKER_RUN_USER, DOCKER_WRITE_DIRS } from "./dockerImage";
|
|
15
|
+
import { nativeKeys } from "./nativeKeys";
|
|
14
16
|
import {
|
|
15
17
|
type AkanApiConfig,
|
|
16
18
|
type AkanAssetsConfig,
|
|
@@ -47,8 +49,6 @@ const DEFAULT_OPTIMIZE_IMPORTS = [
|
|
|
47
49
|
"@material-ui/icons @tabler/icons-react mui-core react-icons/*",
|
|
48
50
|
].flatMap((line) => line.split(" "));
|
|
49
51
|
const WORKSPACE_BARREL_FACETS = ["ui", "webkit", "common", "client", "server"] as const;
|
|
50
|
-
// `1-slim` floats to whichever Bun is newest at build time, one the framework was never tested on.
|
|
51
|
-
const DEFAULT_DOCKER_IMAGE = "oven/bun:1.4.4-slim";
|
|
52
52
|
const SSR_RUNTIME_PACKAGES = ["react", "react-dom", "react-server-dom-webpack"] as const;
|
|
53
53
|
const DEFAULT_AKAN_IMAGE_CONFIG: AkanImageConfig = {
|
|
54
54
|
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
|
|
@@ -452,56 +452,6 @@ export class AkanAppConfig implements AppConfigResult {
|
|
|
452
452
|
static #isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
453
453
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
454
454
|
}
|
|
455
|
-
static readonly #nativeKeys = {
|
|
456
|
-
native: [
|
|
457
|
-
"basePath",
|
|
458
|
-
"indexPath",
|
|
459
|
-
"appName",
|
|
460
|
-
"appId",
|
|
461
|
-
"fileName",
|
|
462
|
-
"version",
|
|
463
|
-
"buildNum",
|
|
464
|
-
"icon",
|
|
465
|
-
"splash",
|
|
466
|
-
"backgroundColor",
|
|
467
|
-
"permissions",
|
|
468
|
-
"plugins",
|
|
469
|
-
"deepLinks",
|
|
470
|
-
"updates",
|
|
471
|
-
"devtools",
|
|
472
|
-
"csp",
|
|
473
|
-
"openUrls",
|
|
474
|
-
"ios",
|
|
475
|
-
"android",
|
|
476
|
-
"desktop",
|
|
477
|
-
],
|
|
478
|
-
ios: ["indexPath", "teamId", "infoPlist", "entitlements", "privacy", "files"],
|
|
479
|
-
android: [
|
|
480
|
-
"indexPath",
|
|
481
|
-
"sha256CertFingerprints",
|
|
482
|
-
"googleServices",
|
|
483
|
-
"push",
|
|
484
|
-
"autoplay",
|
|
485
|
-
"manifest",
|
|
486
|
-
"application",
|
|
487
|
-
"activity",
|
|
488
|
-
"files",
|
|
489
|
-
],
|
|
490
|
-
desktop: [
|
|
491
|
-
"indexPath",
|
|
492
|
-
"server",
|
|
493
|
-
"recovery",
|
|
494
|
-
"window",
|
|
495
|
-
"screenCapture",
|
|
496
|
-
"webview2",
|
|
497
|
-
"publisher",
|
|
498
|
-
"entitlements",
|
|
499
|
-
"dmg",
|
|
500
|
-
],
|
|
501
|
-
desktopServer: ["omit", "profile", "modules", "env", "restart", "watchdog"],
|
|
502
|
-
dmg: ["background", "background2x", "window", "iconSize", "textSize", "app", "applications"],
|
|
503
|
-
deepLinks: ["schemes", "domains"],
|
|
504
|
-
} as const;
|
|
505
455
|
//* Settings that moved when `mobile` became `native` are named with where they went, instead of "unknown".
|
|
506
456
|
static readonly #movedKeys: Readonly<Record<string, string>> = {
|
|
507
457
|
native: "the platform sections and plugins sit directly in the native section: ios, android, desktop, plugins",
|
|
@@ -526,19 +476,15 @@ export class AkanAppConfig implements AppConfigResult {
|
|
|
526
476
|
);
|
|
527
477
|
}
|
|
528
478
|
};
|
|
529
|
-
check(section,
|
|
479
|
+
check(section, nativeKeys.native, where, "native");
|
|
530
480
|
const settings = section as AkanNativeSettings;
|
|
531
|
-
check(settings.ios,
|
|
532
|
-
check(settings.android,
|
|
533
|
-
check(settings.desktop,
|
|
534
|
-
check(
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
"desktopServer",
|
|
539
|
-
);
|
|
540
|
-
check(settings.desktop?.dmg, AkanAppConfig.#nativeKeys.dmg, `${where}.desktop.dmg`, "dmg");
|
|
541
|
-
check(settings.deepLinks, AkanAppConfig.#nativeKeys.deepLinks, `${where}.deepLinks`, "deepLinks");
|
|
481
|
+
check(settings.ios, nativeKeys.ios, `${where}.ios`, "ios");
|
|
482
|
+
check(settings.android, nativeKeys.android, `${where}.android`, "android");
|
|
483
|
+
check(settings.desktop, nativeKeys.desktop, `${where}.desktop`, "desktop");
|
|
484
|
+
check(settings.desktop?.server, nativeKeys.desktopServer, `${where}.desktop.server`, "desktopServer");
|
|
485
|
+
check(settings.desktop?.dmg, nativeKeys.dmg, `${where}.desktop.dmg`, "dmg");
|
|
486
|
+
check(settings.desktop?.externalView, nativeKeys.externalView, `${where}.desktop.externalView`, "externalView");
|
|
487
|
+
check(settings.deepLinks, nativeKeys.deepLinks, `${where}.deepLinks`, "deepLinks");
|
|
542
488
|
}
|
|
543
489
|
static readonly #androidFilePattern = /^(?:res\/[^/]+\/[^/]+|assets\/.+)$/;
|
|
544
490
|
static #assertFiles(settings: AkanNativeSettings, where: string, configPath: string) {
|
|
@@ -643,29 +589,30 @@ export class AkanAppConfig implements AppConfigResult {
|
|
|
643
589
|
"ARG AKAN_ALLOW_LOCAL_IMAGE",
|
|
644
590
|
`RUN if [ "$AKAN_ALLOW_LOCAL_IMAGE" != "1" ]; then echo "This build ran with AKAN_PUBLIC_ENV=local, so the server runs without endpoint rate limits and on local defaults for Redis and the database mode. Build for the environment it deploys to with akan build --env, or pass --build-arg AKAN_ALLOW_LOCAL_IMAGE=1." >&2; exit 1; fi`,
|
|
645
591
|
].join("\n");
|
|
646
|
-
dockerfileFor(environment: string,
|
|
647
|
-
return this.#makeDockerfile(environment, lockfile);
|
|
592
|
+
dockerfileFor(environment: string, options: { lockfile?: boolean; env?: Record<string, string> } = {}): string {
|
|
593
|
+
return this.#makeDockerfile(environment, options.lockfile ?? true, options.env);
|
|
648
594
|
}
|
|
649
|
-
#makeDockerfile(environment?: string, lockfile = true): string {
|
|
595
|
+
#makeDockerfile(environment?: string, lockfile = true, env = this.getProductionEnv(environment)): string {
|
|
650
596
|
if (typeof this.docker === "string") return this.docker;
|
|
651
597
|
const { image, preRuns, postRuns, command } = this.docker;
|
|
652
598
|
const preRunScripts = this.#getDockerRunScripts(preRuns);
|
|
653
599
|
const postRunScripts = this.#getDockerRunScripts(postRuns);
|
|
654
600
|
const imageScript = this.#getDockerImageScript(image, DEFAULT_DOCKER_IMAGE);
|
|
655
601
|
const isLocal = (environment ?? this.baseDevEnv.env) === "local";
|
|
656
|
-
const envLines = Object.entries(
|
|
602
|
+
const envLines = Object.entries(env).map(([key, value]) => `ENV ${key}=${value}`);
|
|
657
603
|
return `${imageScript}${isLocal ? `\n${AkanAppConfig.localImageGuard}` : ""}
|
|
658
604
|
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends ca-certificates tzdata && rm -rf /var/lib/apt/lists/*
|
|
659
605
|
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
|
|
660
606
|
ARG TARGETARCH
|
|
661
607
|
${preRunScripts.join("\n")}
|
|
662
|
-
RUN mkdir -p /workspace
|
|
663
608
|
WORKDIR /workspace
|
|
664
609
|
${lockfile ? "COPY ./package.json ./bun.lock ./" : "COPY ./package.json ./package.json"}
|
|
665
610
|
RUN bun install --production${lockfile ? " --frozen-lockfile" : ""}
|
|
666
611
|
${postRunScripts.join("\n")}
|
|
667
612
|
COPY . .
|
|
613
|
+
RUN mkdir -p ${DOCKER_WRITE_DIRS.join(" ")} && chown ${DOCKER_RUN_USER} ${DOCKER_WRITE_DIRS.join(" ")}
|
|
668
614
|
${envLines.join("\n")}
|
|
615
|
+
USER ${DOCKER_RUN_USER}
|
|
669
616
|
CMD [${command.map((c) => `"${c}"`).join(",")}]`;
|
|
670
617
|
}
|
|
671
618
|
static #importGeneration = 0;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//? A Bun bump changes both: `docker buildx imagetools inspect oven/bun:<version>-slim` prints the new multi-arch digest.
|
|
2
|
+
export const BUN_IMAGE_PIN = {
|
|
3
|
+
version: "1.4.4",
|
|
4
|
+
digest: "sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4",
|
|
5
|
+
} as const;
|
|
6
|
+
// `1-slim` floats to whichever Bun is newest at build time, one the framework was never tested on.
|
|
7
|
+
export const DEFAULT_DOCKER_IMAGE = `oven/bun:${BUN_IMAGE_PIN.version}-slim@${BUN_IMAGE_PIN.digest}`;
|
|
8
|
+
//? oven/bun's `bun` user, numeric so a kubelet can check `runAsNonRoot` without reading the image's passwd file.
|
|
9
|
+
export const DOCKER_RUN_USER = "1000:1000";
|
|
10
|
+
//? The directories the server writes, its code staying read-only; an empty named volume mounted on one takes its owner.
|
|
11
|
+
export const DOCKER_WRITE_DIRS = [
|
|
12
|
+
"/workspace/sqlite",
|
|
13
|
+
"/workspace/local",
|
|
14
|
+
"/workspace/runtime",
|
|
15
|
+
"/workspace/data",
|
|
16
|
+
"/workspace/.akan/artifact/image-cache",
|
|
17
|
+
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const nativeKeys = {
|
|
2
|
+
native: [
|
|
3
|
+
"basePath",
|
|
4
|
+
"indexPath",
|
|
5
|
+
"appName",
|
|
6
|
+
"appId",
|
|
7
|
+
"fileName",
|
|
8
|
+
"version",
|
|
9
|
+
"buildNum",
|
|
10
|
+
"icon",
|
|
11
|
+
"splash",
|
|
12
|
+
"backgroundColor",
|
|
13
|
+
"permissions",
|
|
14
|
+
"plugins",
|
|
15
|
+
"deepLinks",
|
|
16
|
+
"updates",
|
|
17
|
+
"devtools",
|
|
18
|
+
"csp",
|
|
19
|
+
"openUrls",
|
|
20
|
+
"ios",
|
|
21
|
+
"android",
|
|
22
|
+
"desktop",
|
|
23
|
+
],
|
|
24
|
+
ios: ["indexPath", "teamId", "infoPlist", "entitlements", "privacy", "files", "hideFormAccessoryBar"],
|
|
25
|
+
android: [
|
|
26
|
+
"indexPath",
|
|
27
|
+
"sha256CertFingerprints",
|
|
28
|
+
"googleServices",
|
|
29
|
+
"push",
|
|
30
|
+
"autoplay",
|
|
31
|
+
"manifest",
|
|
32
|
+
"application",
|
|
33
|
+
"activity",
|
|
34
|
+
"files",
|
|
35
|
+
],
|
|
36
|
+
desktop: [
|
|
37
|
+
"indexPath",
|
|
38
|
+
"server",
|
|
39
|
+
"recovery",
|
|
40
|
+
"window",
|
|
41
|
+
"screenCapture",
|
|
42
|
+
"webview2",
|
|
43
|
+
"publisher",
|
|
44
|
+
"entitlements",
|
|
45
|
+
"dmg",
|
|
46
|
+
"externalView",
|
|
47
|
+
],
|
|
48
|
+
externalView: ["allowOrigins", "evaluate", "sendKey"],
|
|
49
|
+
desktopServer: ["omit", "profile", "modules", "env", "restart", "watchdog"],
|
|
50
|
+
dmg: ["background", "background2x", "window", "iconSize", "textSize", "app", "applications"],
|
|
51
|
+
deepLinks: ["schemes", "domains"],
|
|
52
|
+
} as const;
|
|
@@ -8,6 +8,16 @@ import type { App } from "../commandDecorators";
|
|
|
8
8
|
import { AppExecutor, Executor } from "../executors";
|
|
9
9
|
import { AllRoutesBuilder, type BuildAllRoutesResult, VendorNarrowing } from "../frontendBuild";
|
|
10
10
|
import { bundleDefine } from "../frontendBuild/bundleDefine";
|
|
11
|
+
import {
|
|
12
|
+
computedSecretKeys,
|
|
13
|
+
computedSecrets,
|
|
14
|
+
holdsSentinel,
|
|
15
|
+
secretEnvSentinels,
|
|
16
|
+
twinSecretEnv,
|
|
17
|
+
twinSecrets,
|
|
18
|
+
writeComputedSecretFixture,
|
|
19
|
+
writeSecretEnvFixture,
|
|
20
|
+
} from "../test/secretEnvFixture";
|
|
11
21
|
import { createTempApp } from "../test/testHelpers";
|
|
12
22
|
import { ProjectTypecheck } from "../typecheck/projectTypecheck";
|
|
13
23
|
import { AKAN_BACKEND_MINIFY, AKAN_OPTIONAL_BACKEND_EXTERNALS, ApplicationBuildRunner } from "./applicationBuildRunner";
|
|
@@ -121,6 +131,268 @@ console.info(new SampleService().name);
|
|
|
121
131
|
}
|
|
122
132
|
});
|
|
123
133
|
|
|
134
|
+
test("an image build names the secrets its server reads beside main.js and in its Dockerfile, and holds no value of them", async () => {
|
|
135
|
+
const { root, workspace } = await createTempApp("portal");
|
|
136
|
+
await writeSecretEnvFixture(root, { app: "portal" });
|
|
137
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
138
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
139
|
+
for (const key of keys) delete process.env[key];
|
|
140
|
+
await writeFile(
|
|
141
|
+
path.join(root, ".env"),
|
|
142
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
143
|
+
);
|
|
144
|
+
const metaOf = async (options: ConstructorParameters<typeof ApplicationBuildRunner>[1]) => {
|
|
145
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
146
|
+
spyOn(app.logger, "warn").mockImplementation(() => undefined);
|
|
147
|
+
app.prepareCommand = async () => {
|
|
148
|
+
throw new Error("stopped before the phases");
|
|
149
|
+
};
|
|
150
|
+
const runner = new ApplicationBuildRunner(app, options);
|
|
151
|
+
await expect(runner.build()).rejects.toThrow("stopped before the phases");
|
|
152
|
+
await runner.buildAppMeta();
|
|
153
|
+
const env = JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
|
|
154
|
+
[key: string]: string;
|
|
155
|
+
};
|
|
156
|
+
const dockerfile = await readFile(path.join(app.dist.cwdPath, "Dockerfile"), "utf8");
|
|
157
|
+
const dockerfileEnv = Object.fromEntries(
|
|
158
|
+
dockerfile
|
|
159
|
+
.split("\n")
|
|
160
|
+
.filter((line) => line.startsWith("ENV "))
|
|
161
|
+
.map((line) => line.slice("ENV ".length).split(/=(.*)/s).slice(0, 2)),
|
|
162
|
+
);
|
|
163
|
+
expect(env).toEqual(dockerfileEnv);
|
|
164
|
+
expect(holdsSentinel(`${JSON.stringify(env)}${dockerfile}`)).toBe(false);
|
|
165
|
+
return env;
|
|
166
|
+
};
|
|
167
|
+
const names =
|
|
168
|
+
"JWT_SECRET,SECURITY__SSO__GOOGLE__CLIENT_SECRET,MAILER__AUTH__PASS,OBJECT_STORAGE__ENDPOINT,DISCORD__TOKENS:json,DISCORD__WEBHOOK,PUSH_NOTI__FIREBASE__PRIVATE_KEY:multiline,MESSAGE__API_SECRET,MESSAGE__SENDER_PASSWORD,POSTGRES_URL";
|
|
169
|
+
try {
|
|
170
|
+
const read = await metaOf({ secretEnv: "read" });
|
|
171
|
+
expect(read.AKAN_ENV_NAMES).toBe(names);
|
|
172
|
+
expect(read).not.toHaveProperty("AKAN_ENV_FALLBACK");
|
|
173
|
+
expect(await metaOf({ secretEnv: "inline" })).toMatchObject({
|
|
174
|
+
AKAN_ENV_NAMES: names,
|
|
175
|
+
AKAN_ENV_FALLBACK: "image",
|
|
176
|
+
});
|
|
177
|
+
const carried = await metaOf({});
|
|
178
|
+
expect(carried).not.toHaveProperty("AKAN_ENV_NAMES");
|
|
179
|
+
expect(carried).not.toHaveProperty("AKAN_ENV_FALLBACK");
|
|
180
|
+
} finally {
|
|
181
|
+
for (const key of keys) {
|
|
182
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
183
|
+
else process.env[key] = shellEnv[key];
|
|
184
|
+
}
|
|
185
|
+
await rm(root, { recursive: true, force: true });
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("an image build stops before any phase at a secret whose variable the platform owns, without printing it", async () => {
|
|
190
|
+
const { root, workspace } = await createTempApp("portal");
|
|
191
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n pwd: "sentinel-pwd-1b84",' });
|
|
192
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
193
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
194
|
+
for (const key of keys) delete process.env[key];
|
|
195
|
+
await writeFile(
|
|
196
|
+
path.join(root, ".env"),
|
|
197
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
198
|
+
);
|
|
199
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
200
|
+
let prepared = false;
|
|
201
|
+
app.prepareCommand = async () => {
|
|
202
|
+
prepared = true;
|
|
203
|
+
throw new Error("prepared");
|
|
204
|
+
};
|
|
205
|
+
try {
|
|
206
|
+
const failure = await new ApplicationBuildRunner(app, { secretEnv: "read" })
|
|
207
|
+
.build()
|
|
208
|
+
.catch((error: Error) => error.message);
|
|
209
|
+
expect(failure).toContain("`pwd` is a secret a build would read from the environment variable PWD");
|
|
210
|
+
expect(holdsSentinel(String(failure))).toBe(false);
|
|
211
|
+
expect(prepared).toBe(false);
|
|
212
|
+
} finally {
|
|
213
|
+
for (const key of keys) {
|
|
214
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
215
|
+
else process.env[key] = shellEnv[key];
|
|
216
|
+
}
|
|
217
|
+
await rm(root, { recursive: true, force: true });
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("an env file that needs a variable of the shell to load builds with it set; without it a build stops at the place, and an --inline-secrets build warns and holds the env as written", async () => {
|
|
222
|
+
const { root, workspace } = await createTempApp("portal");
|
|
223
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n hosts: process.env.ZQ_HOSTS!.split(","),' });
|
|
224
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN", "ZQ_HOSTS"] as const;
|
|
225
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
226
|
+
for (const key of keys) delete process.env[key];
|
|
227
|
+
await writeFile(
|
|
228
|
+
path.join(root, ".env"),
|
|
229
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
230
|
+
);
|
|
231
|
+
const started = async (secretEnv: "read" | "inline") => {
|
|
232
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
233
|
+
const warnings: string[] = [];
|
|
234
|
+
spyOn(app.logger, "warn").mockImplementation((message: string) => {
|
|
235
|
+
warnings.push(message);
|
|
236
|
+
});
|
|
237
|
+
app.prepareCommand = async () => {
|
|
238
|
+
throw new Error("stopped before the phases");
|
|
239
|
+
};
|
|
240
|
+
const runner = new ApplicationBuildRunner(app, { secretEnv });
|
|
241
|
+
const failure = await runner.build().then(
|
|
242
|
+
() => "",
|
|
243
|
+
(error: Error) => error.message,
|
|
244
|
+
);
|
|
245
|
+
return { app, runner, failure, warnings };
|
|
246
|
+
};
|
|
247
|
+
const envOf = async ({ app, runner }: Awaited<ReturnType<typeof started>>) => {
|
|
248
|
+
await runner.buildAppMeta();
|
|
249
|
+
return JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
|
|
250
|
+
[key: string]: string;
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
const place =
|
|
254
|
+
/env\.server\.ts could not be evaluated to check it for secrets: TypeError at .*env\.server\.main\.ts:\d+/;
|
|
255
|
+
try {
|
|
256
|
+
const stopped = await started("read");
|
|
257
|
+
expect(stopped.failure).toMatch(place);
|
|
258
|
+
expect(stopped.failure).toContain("Make the file load at that line");
|
|
259
|
+
expect(holdsSentinel(stopped.failure)).toBe(false);
|
|
260
|
+
|
|
261
|
+
const inlined = await started("inline");
|
|
262
|
+
expect(inlined.failure).toBe("stopped before the phases");
|
|
263
|
+
expect(inlined.warnings).toHaveLength(1);
|
|
264
|
+
expect(inlined.warnings[0]).toMatch(place);
|
|
265
|
+
expect(inlined.warnings[0]).toStartWith("--inline-secrets: env.server.ts could not be evaluated");
|
|
266
|
+
expect(holdsSentinel(inlined.warnings.join())).toBe(false);
|
|
267
|
+
const written = await envOf(inlined);
|
|
268
|
+
expect(written).not.toHaveProperty("AKAN_ENV_NAMES");
|
|
269
|
+
expect(written).not.toHaveProperty("AKAN_ENV_FALLBACK");
|
|
270
|
+
|
|
271
|
+
process.env.ZQ_HOSTS = "a.example.test,b.example.test";
|
|
272
|
+
const built = await started("read");
|
|
273
|
+
expect(built.failure).toBe("stopped before the phases");
|
|
274
|
+
expect((await envOf(built)).AKAN_ENV_NAMES).toStartWith("JWT_SECRET,SECURITY__SSO__GOOGLE__CLIENT_SECRET,");
|
|
275
|
+
} finally {
|
|
276
|
+
for (const key of keys) {
|
|
277
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
278
|
+
else process.env[key] = shellEnv[key];
|
|
279
|
+
}
|
|
280
|
+
await rm(root, { recursive: true, force: true });
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("an image build stops before any phase at a secret the env file imports or computes, short or plain as it may be, naming the file and the keys alone", async () => {
|
|
285
|
+
const { root, workspace } = await createTempApp("portal");
|
|
286
|
+
await writeComputedSecretFixture(root, "portal");
|
|
287
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
288
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
289
|
+
for (const key of keys) delete process.env[key];
|
|
290
|
+
await writeFile(
|
|
291
|
+
path.join(root, ".env"),
|
|
292
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
293
|
+
);
|
|
294
|
+
const started = async (secretEnv: "read" | "inline") => {
|
|
295
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
296
|
+
spyOn(app.logger, "warn").mockImplementation(() => undefined);
|
|
297
|
+
let prepared = false;
|
|
298
|
+
app.prepareCommand = async () => {
|
|
299
|
+
prepared = true;
|
|
300
|
+
throw new Error("stopped before the phases");
|
|
301
|
+
};
|
|
302
|
+
const failure = await new ApplicationBuildRunner(app, { secretEnv }).build().then(
|
|
303
|
+
() => "",
|
|
304
|
+
(error: Error) => error.message,
|
|
305
|
+
);
|
|
306
|
+
return { failure, prepared: () => prepared };
|
|
307
|
+
};
|
|
308
|
+
try {
|
|
309
|
+
const stopped = await started("read");
|
|
310
|
+
expect(stopped.prepared()).toBe(false);
|
|
311
|
+
expect(stopped.failure).toStartWith(
|
|
312
|
+
`The server env of portal (main) holds 4 secret values this build cannot leave out, so it stops here: ${computedSecretKeys.join(", ")} (apps/portal/env/env.server.ts and what it imports).\n`,
|
|
313
|
+
);
|
|
314
|
+
expect(holdsSentinel(stopped.failure)).toBe(false);
|
|
315
|
+
for (const value of Object.values(computedSecrets)) expect(stopped.failure).not.toContain(value);
|
|
316
|
+
const inlined = await started("inline");
|
|
317
|
+
expect(inlined.prepared()).toBe(true);
|
|
318
|
+
expect(inlined.failure).toBe("stopped before the phases");
|
|
319
|
+
} finally {
|
|
320
|
+
for (const key of keys) {
|
|
321
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
322
|
+
else process.env[key] = shellEnv[key];
|
|
323
|
+
}
|
|
324
|
+
await rm(root, { recursive: true, force: true });
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("an image build stops before its metadata when a file it wrote holds a secret it left out of the env, and warns of a short one a plain key holds as well", async () => {
|
|
329
|
+
const { root, workspace } = await createTempApp("portal");
|
|
330
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: twinSecretEnv.split("\n").slice(0, 3).join("\n") });
|
|
331
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
332
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
333
|
+
for (const key of keys) delete process.env[key];
|
|
334
|
+
await writeFile(
|
|
335
|
+
path.join(root, ".env"),
|
|
336
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
337
|
+
);
|
|
338
|
+
const runnerOf = async (secretEnv: "read" | "inline") => {
|
|
339
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
340
|
+
const warnings: string[] = [];
|
|
341
|
+
spyOn(app.logger, "warn").mockImplementation((message: string) => {
|
|
342
|
+
warnings.push(message);
|
|
343
|
+
});
|
|
344
|
+
app.prepareCommand = async () => {
|
|
345
|
+
throw new Error("stopped before the phases");
|
|
346
|
+
};
|
|
347
|
+
const runner = new ApplicationBuildRunner(app, { secretEnv });
|
|
348
|
+
await expect(runner.build()).rejects.toThrow("stopped before the phases");
|
|
349
|
+
return { app, runner, warnings };
|
|
350
|
+
};
|
|
351
|
+
try {
|
|
352
|
+
const { app, runner, warnings } = await runnerOf("read");
|
|
353
|
+
await mkdir(app.dist.cwdPath, { recursive: true });
|
|
354
|
+
await writeFile(path.join(app.dist.cwdPath, "server.js"), 'const env = { hostname: "app.example.test" };\n');
|
|
355
|
+
await runner.assertSecretsLeftOut();
|
|
356
|
+
expect(warnings).toEqual([]);
|
|
357
|
+
await writeFile(
|
|
358
|
+
path.join(app.dist.cwdPath, "chunk-a.js"),
|
|
359
|
+
`const cache = { name: ${JSON.stringify(twinSecrets.plain)} };\n`,
|
|
360
|
+
);
|
|
361
|
+
await runner.assertSecretsLeftOut();
|
|
362
|
+
expect(warnings).toHaveLength(1);
|
|
363
|
+
expect(warnings[0]).toContain(
|
|
364
|
+
"\n cache.password (CACHE__PASSWORD): chunk-a.js; the env's cache.name holds the same string\n",
|
|
365
|
+
);
|
|
366
|
+
expect(holdsSentinel(warnings[0] ?? "")).toBe(false);
|
|
367
|
+
await writeFile(
|
|
368
|
+
path.join(app.dist.cwdPath, "chunk-b.js"),
|
|
369
|
+
`const key = ${JSON.stringify(secretEnvSentinels.google)};\nconst label = ${JSON.stringify(twinSecrets.long)};\n`,
|
|
370
|
+
);
|
|
371
|
+
const failure = await runner.assertSecretsLeftOut().then(
|
|
372
|
+
() => "",
|
|
373
|
+
(error: Error) => error.message,
|
|
374
|
+
);
|
|
375
|
+
expect(failure).toStartWith(
|
|
376
|
+
[
|
|
377
|
+
"The build holds secret values the server reads from its process env, so it stops here:",
|
|
378
|
+
" chunk-b.js holds the value of security.sso.google.clientSecret (SECURITY__SSO__GOOGLE__CLIENT_SECRET)",
|
|
379
|
+
" chunk-b.js holds the value of audit.password (AUDIT__PASSWORD), which the env's audit.label holds as well",
|
|
380
|
+
"",
|
|
381
|
+
].join("\n"),
|
|
382
|
+
);
|
|
383
|
+
expect(holdsSentinel(failure)).toBe(false);
|
|
384
|
+
const inlined = await runnerOf("inline");
|
|
385
|
+
await inlined.runner.assertSecretsLeftOut();
|
|
386
|
+
expect(inlined.warnings.join("\n")).not.toContain("also in what this build wrote");
|
|
387
|
+
} finally {
|
|
388
|
+
for (const key of keys) {
|
|
389
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
390
|
+
else process.env[key] = shellEnv[key];
|
|
391
|
+
}
|
|
392
|
+
await rm(root, { recursive: true, force: true });
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
124
396
|
test("writes the pruned lockfile beside package.json, or warns and leaves the image's install unlocked", async () => {
|
|
125
397
|
const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
|
|
126
398
|
const config = new AkanAppConfig(
|
|
@@ -439,7 +711,9 @@ console.info(new SampleService().name);
|
|
|
439
711
|
|
|
440
712
|
expect(proc.exitCode).toBe(1);
|
|
441
713
|
expect(proc.stdout.toString()).toBe("");
|
|
442
|
-
expect(proc.stderr.toString()).toContain(
|
|
714
|
+
expect(proc.stderr.toString()).toContain(
|
|
715
|
+
`${path.join("dist", "verify", "portal")} holds the partial output of akan verify, not a build. Run \`akan build portal\` and start dist/apps/portal.`,
|
|
716
|
+
);
|
|
443
717
|
expect(await Bun.file(path.join(app.dist.cwdPath, "akan.build.json")).json()).toMatchObject({
|
|
444
718
|
profile: "verify",
|
|
445
719
|
});
|
|
@@ -452,4 +726,50 @@ console.info(new SampleService().name);
|
|
|
452
726
|
await rm(root, { recursive: true, force: true });
|
|
453
727
|
}
|
|
454
728
|
});
|
|
729
|
+
|
|
730
|
+
test("a verify build writes to dist/verify/<app> and leaves the full build in dist/apps/<app> as it was", async () => {
|
|
731
|
+
const { root, workspace } = await createTempApp("portal");
|
|
732
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
733
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
734
|
+
const appDir = path.join(root, "apps", "portal");
|
|
735
|
+
await Promise.all(["main.ts", "server.ts"].map((file) => writeFile(path.join(appDir, file), "")));
|
|
736
|
+
await mkdir(path.join(appDir, "public"));
|
|
737
|
+
await writeFile(path.join(appDir, "public", "hero.png"), "image");
|
|
738
|
+
const built = path.join(root, "dist", "apps", "portal");
|
|
739
|
+
const fullBuild = {
|
|
740
|
+
"main.js": 'console.log("booted");\n',
|
|
741
|
+
"akan.build.json": '{ "buildId": "abc123" }\n',
|
|
742
|
+
"akan.env.json": '{ "AKAN_PUBLIC_ENV": "local" }\n',
|
|
743
|
+
"public/hero.png": "image",
|
|
744
|
+
};
|
|
745
|
+
for (const [file, content] of Object.entries(fullBuild)) {
|
|
746
|
+
await mkdir(path.dirname(path.join(built, file)), { recursive: true });
|
|
747
|
+
await writeFile(path.join(built, file), content);
|
|
748
|
+
}
|
|
749
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
750
|
+
const bundle = spyOn(Bun, "build").mockImplementation(
|
|
751
|
+
async () => ({ success: true, outputs: [], logs: [] }) as unknown as Bun.BuildOutput,
|
|
752
|
+
);
|
|
753
|
+
try {
|
|
754
|
+
const { outputDir } = await new ApplicationBuildRunner(app, { verify: true }).build();
|
|
755
|
+
|
|
756
|
+
for (const [file, content] of Object.entries(fullBuild))
|
|
757
|
+
expect(await readFile(path.join(built, file), "utf8").catch(() => null)).toBe(content);
|
|
758
|
+
const verified = path.join(root, "dist", "verify", "portal");
|
|
759
|
+
expect(outputDir).toBe(verified);
|
|
760
|
+
expect(await Bun.file(path.join(verified, "akan.build.json")).json()).toMatchObject({ profile: "verify" });
|
|
761
|
+
expect(await Bun.file(path.join(verified, "console.js")).exists()).toBe(true);
|
|
762
|
+
expect(await Bun.file(path.join(verified, "public", "hero.png")).exists()).toBe(false);
|
|
763
|
+
const outdirs = bundle.mock.calls.map(([config]) => config.outdir);
|
|
764
|
+
expect(outdirs.length).toBeGreaterThan(0);
|
|
765
|
+
expect(outdirs.every((outdir) => outdir === verified)).toBe(true);
|
|
766
|
+
} finally {
|
|
767
|
+
bundle.mockRestore();
|
|
768
|
+
for (const key of keys) {
|
|
769
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
770
|
+
else process.env[key] = shellEnv[key];
|
|
771
|
+
}
|
|
772
|
+
await rm(root, { recursive: true, force: true });
|
|
773
|
+
}
|
|
774
|
+
});
|
|
455
775
|
});
|