@akanjs/devkit 3.3.0-rc.5 → 3.3.0-rc.50
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 +650 -0
- 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/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +70 -10
- package/akanConfig/akanConfig.ts +57 -206
- package/akanConfig/akanWorkers.test.ts +39 -0
- package/akanConfig/akanWorkers.ts +32 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +39 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +1 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +49 -0
- package/app/applicationBuildReporter.ts +5 -0
- package/app/applicationBuildRunner.test.ts +275 -0
- package/app/applicationBuildRunner.ts +149 -12
- package/app/dictionarySizes.ts +91 -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 +6 -2
- 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-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 +34 -26
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
- 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 +2 -5
- 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 +14 -0
- package/executors/appExecutor.ts +3 -1
- 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 +12 -4
- package/executors/executors.test.ts +2 -0
- package/executors/sysExecutor.ts +70 -4
- 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 +329 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +165 -16
- package/frontendBuild/dictionaryConstants.ts +136 -0
- package/frontendBuild/dictionaryPacking.test.ts +142 -0
- package/frontendBuild/dictionaryPacking.ts +135 -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 +81 -3
- package/frontendBuild/precompressArtifacts.test.ts +22 -0
- package/frontendBuild/precompressArtifacts.ts +22 -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/rscServerRendererGuard.test.ts +60 -0
- package/frontendBuild/rscServerRendererGuard.ts +68 -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 +21 -2
- 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 +9 -2
- package/mobile/desktopServerStage.ts +1 -0
- 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 +15 -169
- 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 +115 -2
- package/transforms/serverEnvProfile.ts +117 -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 +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/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/getRelatedCnsts.ts +7 -0
- package/workspace/scanInfo.test.ts +39 -0
- package/workspace/scanInfo.ts +48 -5
- package/workspace/slicePlanner.ts +1 -1
- package/workspace/workspaceLayout.ts +1 -0
|
@@ -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";
|
|
@@ -71,6 +81,7 @@ console.info(new SampleService().name);
|
|
|
71
81
|
);
|
|
72
82
|
const app = {
|
|
73
83
|
getConfig: async () => config,
|
|
84
|
+
getScanInfo: () => ({ getLibs: () => [] }),
|
|
74
85
|
dist: new Executor("dist", root),
|
|
75
86
|
workspace: { workspaceRoot: root },
|
|
76
87
|
logger: { warn: () => undefined },
|
|
@@ -96,6 +107,7 @@ console.info(new SampleService().name);
|
|
|
96
107
|
);
|
|
97
108
|
const app = {
|
|
98
109
|
getConfig: async () => config,
|
|
110
|
+
getScanInfo: () => ({ getLibs: () => [] }),
|
|
99
111
|
dist: new Executor("dist", root),
|
|
100
112
|
workspace: { workspaceRoot: root },
|
|
101
113
|
logger: { warn: () => undefined },
|
|
@@ -121,6 +133,268 @@ console.info(new SampleService().name);
|
|
|
121
133
|
}
|
|
122
134
|
});
|
|
123
135
|
|
|
136
|
+
test("an image build names the secrets its server reads beside main.js and in its Dockerfile, and holds no value of them", async () => {
|
|
137
|
+
const { root, workspace } = await createTempApp("portal");
|
|
138
|
+
await writeSecretEnvFixture(root, { app: "portal" });
|
|
139
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
140
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
141
|
+
for (const key of keys) delete process.env[key];
|
|
142
|
+
await writeFile(
|
|
143
|
+
path.join(root, ".env"),
|
|
144
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
145
|
+
);
|
|
146
|
+
const metaOf = async (options: ConstructorParameters<typeof ApplicationBuildRunner>[1]) => {
|
|
147
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
148
|
+
spyOn(app.logger, "warn").mockImplementation(() => undefined);
|
|
149
|
+
app.prepareCommand = async () => {
|
|
150
|
+
throw new Error("stopped before the phases");
|
|
151
|
+
};
|
|
152
|
+
const runner = new ApplicationBuildRunner(app, options);
|
|
153
|
+
await expect(runner.build()).rejects.toThrow("stopped before the phases");
|
|
154
|
+
await runner.buildAppMeta();
|
|
155
|
+
const env = JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
|
|
156
|
+
[key: string]: string;
|
|
157
|
+
};
|
|
158
|
+
const dockerfile = await readFile(path.join(app.dist.cwdPath, "Dockerfile"), "utf8");
|
|
159
|
+
const dockerfileEnv = Object.fromEntries(
|
|
160
|
+
dockerfile
|
|
161
|
+
.split("\n")
|
|
162
|
+
.filter((line) => line.startsWith("ENV "))
|
|
163
|
+
.map((line) => line.slice("ENV ".length).split(/=(.*)/s).slice(0, 2)),
|
|
164
|
+
);
|
|
165
|
+
expect(env).toEqual(dockerfileEnv);
|
|
166
|
+
expect(holdsSentinel(`${JSON.stringify(env)}${dockerfile}`)).toBe(false);
|
|
167
|
+
return env;
|
|
168
|
+
};
|
|
169
|
+
const names =
|
|
170
|
+
"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";
|
|
171
|
+
try {
|
|
172
|
+
const read = await metaOf({ secretEnv: "read" });
|
|
173
|
+
expect(read.AKAN_ENV_NAMES).toBe(names);
|
|
174
|
+
expect(read).not.toHaveProperty("AKAN_ENV_FALLBACK");
|
|
175
|
+
expect(await metaOf({ secretEnv: "inline" })).toMatchObject({
|
|
176
|
+
AKAN_ENV_NAMES: names,
|
|
177
|
+
AKAN_ENV_FALLBACK: "image",
|
|
178
|
+
});
|
|
179
|
+
const carried = await metaOf({});
|
|
180
|
+
expect(carried).not.toHaveProperty("AKAN_ENV_NAMES");
|
|
181
|
+
expect(carried).not.toHaveProperty("AKAN_ENV_FALLBACK");
|
|
182
|
+
} finally {
|
|
183
|
+
for (const key of keys) {
|
|
184
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
185
|
+
else process.env[key] = shellEnv[key];
|
|
186
|
+
}
|
|
187
|
+
await rm(root, { recursive: true, force: true });
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("an image build stops before any phase at a secret whose variable the platform owns, without printing it", async () => {
|
|
192
|
+
const { root, workspace } = await createTempApp("portal");
|
|
193
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n pwd: "sentinel-pwd-1b84",' });
|
|
194
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
195
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
196
|
+
for (const key of keys) delete process.env[key];
|
|
197
|
+
await writeFile(
|
|
198
|
+
path.join(root, ".env"),
|
|
199
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
200
|
+
);
|
|
201
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
202
|
+
let prepared = false;
|
|
203
|
+
app.prepareCommand = async () => {
|
|
204
|
+
prepared = true;
|
|
205
|
+
throw new Error("prepared");
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
const failure = await new ApplicationBuildRunner(app, { secretEnv: "read" })
|
|
209
|
+
.build()
|
|
210
|
+
.catch((error: Error) => error.message);
|
|
211
|
+
expect(failure).toContain("`pwd` is a secret a build would read from the environment variable PWD");
|
|
212
|
+
expect(holdsSentinel(String(failure))).toBe(false);
|
|
213
|
+
expect(prepared).toBe(false);
|
|
214
|
+
} finally {
|
|
215
|
+
for (const key of keys) {
|
|
216
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
217
|
+
else process.env[key] = shellEnv[key];
|
|
218
|
+
}
|
|
219
|
+
await rm(root, { recursive: true, force: true });
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
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 () => {
|
|
224
|
+
const { root, workspace } = await createTempApp("portal");
|
|
225
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n hosts: process.env.ZQ_HOSTS!.split(","),' });
|
|
226
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN", "ZQ_HOSTS"] as const;
|
|
227
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
228
|
+
for (const key of keys) delete process.env[key];
|
|
229
|
+
await writeFile(
|
|
230
|
+
path.join(root, ".env"),
|
|
231
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
232
|
+
);
|
|
233
|
+
const started = async (secretEnv: "read" | "inline") => {
|
|
234
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
235
|
+
const warnings: string[] = [];
|
|
236
|
+
spyOn(app.logger, "warn").mockImplementation((message: string) => {
|
|
237
|
+
warnings.push(message);
|
|
238
|
+
});
|
|
239
|
+
app.prepareCommand = async () => {
|
|
240
|
+
throw new Error("stopped before the phases");
|
|
241
|
+
};
|
|
242
|
+
const runner = new ApplicationBuildRunner(app, { secretEnv });
|
|
243
|
+
const failure = await runner.build().then(
|
|
244
|
+
() => "",
|
|
245
|
+
(error: Error) => error.message,
|
|
246
|
+
);
|
|
247
|
+
return { app, runner, failure, warnings };
|
|
248
|
+
};
|
|
249
|
+
const envOf = async ({ app, runner }: Awaited<ReturnType<typeof started>>) => {
|
|
250
|
+
await runner.buildAppMeta();
|
|
251
|
+
return JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
|
|
252
|
+
[key: string]: string;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
const place =
|
|
256
|
+
/env\.server\.ts could not be evaluated to check it for secrets: TypeError at .*env\.server\.main\.ts:\d+/;
|
|
257
|
+
try {
|
|
258
|
+
const stopped = await started("read");
|
|
259
|
+
expect(stopped.failure).toMatch(place);
|
|
260
|
+
expect(stopped.failure).toContain("Make the file load at that line");
|
|
261
|
+
expect(holdsSentinel(stopped.failure)).toBe(false);
|
|
262
|
+
|
|
263
|
+
const inlined = await started("inline");
|
|
264
|
+
expect(inlined.failure).toBe("stopped before the phases");
|
|
265
|
+
expect(inlined.warnings).toHaveLength(1);
|
|
266
|
+
expect(inlined.warnings[0]).toMatch(place);
|
|
267
|
+
expect(inlined.warnings[0]).toStartWith("--inline-secrets: env.server.ts could not be evaluated");
|
|
268
|
+
expect(holdsSentinel(inlined.warnings.join())).toBe(false);
|
|
269
|
+
const written = await envOf(inlined);
|
|
270
|
+
expect(written).not.toHaveProperty("AKAN_ENV_NAMES");
|
|
271
|
+
expect(written).not.toHaveProperty("AKAN_ENV_FALLBACK");
|
|
272
|
+
|
|
273
|
+
process.env.ZQ_HOSTS = "a.example.test,b.example.test";
|
|
274
|
+
const built = await started("read");
|
|
275
|
+
expect(built.failure).toBe("stopped before the phases");
|
|
276
|
+
expect((await envOf(built)).AKAN_ENV_NAMES).toStartWith("JWT_SECRET,SECURITY__SSO__GOOGLE__CLIENT_SECRET,");
|
|
277
|
+
} finally {
|
|
278
|
+
for (const key of keys) {
|
|
279
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
280
|
+
else process.env[key] = shellEnv[key];
|
|
281
|
+
}
|
|
282
|
+
await rm(root, { recursive: true, force: true });
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
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 () => {
|
|
287
|
+
const { root, workspace } = await createTempApp("portal");
|
|
288
|
+
await writeComputedSecretFixture(root, "portal");
|
|
289
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
290
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
291
|
+
for (const key of keys) delete process.env[key];
|
|
292
|
+
await writeFile(
|
|
293
|
+
path.join(root, ".env"),
|
|
294
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
295
|
+
);
|
|
296
|
+
const started = async (secretEnv: "read" | "inline") => {
|
|
297
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
298
|
+
spyOn(app.logger, "warn").mockImplementation(() => undefined);
|
|
299
|
+
let prepared = false;
|
|
300
|
+
app.prepareCommand = async () => {
|
|
301
|
+
prepared = true;
|
|
302
|
+
throw new Error("stopped before the phases");
|
|
303
|
+
};
|
|
304
|
+
const failure = await new ApplicationBuildRunner(app, { secretEnv }).build().then(
|
|
305
|
+
() => "",
|
|
306
|
+
(error: Error) => error.message,
|
|
307
|
+
);
|
|
308
|
+
return { failure, prepared: () => prepared };
|
|
309
|
+
};
|
|
310
|
+
try {
|
|
311
|
+
const stopped = await started("read");
|
|
312
|
+
expect(stopped.prepared()).toBe(false);
|
|
313
|
+
expect(stopped.failure).toStartWith(
|
|
314
|
+
`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`,
|
|
315
|
+
);
|
|
316
|
+
expect(holdsSentinel(stopped.failure)).toBe(false);
|
|
317
|
+
for (const value of Object.values(computedSecrets)) expect(stopped.failure).not.toContain(value);
|
|
318
|
+
const inlined = await started("inline");
|
|
319
|
+
expect(inlined.prepared()).toBe(true);
|
|
320
|
+
expect(inlined.failure).toBe("stopped before the phases");
|
|
321
|
+
} finally {
|
|
322
|
+
for (const key of keys) {
|
|
323
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
324
|
+
else process.env[key] = shellEnv[key];
|
|
325
|
+
}
|
|
326
|
+
await rm(root, { recursive: true, force: true });
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
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 () => {
|
|
331
|
+
const { root, workspace } = await createTempApp("portal");
|
|
332
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: twinSecretEnv.split("\n").slice(0, 3).join("\n") });
|
|
333
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
334
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
335
|
+
for (const key of keys) delete process.env[key];
|
|
336
|
+
await writeFile(
|
|
337
|
+
path.join(root, ".env"),
|
|
338
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
339
|
+
);
|
|
340
|
+
const runnerOf = async (secretEnv: "read" | "inline") => {
|
|
341
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
342
|
+
const warnings: string[] = [];
|
|
343
|
+
spyOn(app.logger, "warn").mockImplementation((message: string) => {
|
|
344
|
+
warnings.push(message);
|
|
345
|
+
});
|
|
346
|
+
app.prepareCommand = async () => {
|
|
347
|
+
throw new Error("stopped before the phases");
|
|
348
|
+
};
|
|
349
|
+
const runner = new ApplicationBuildRunner(app, { secretEnv });
|
|
350
|
+
await expect(runner.build()).rejects.toThrow("stopped before the phases");
|
|
351
|
+
return { app, runner, warnings };
|
|
352
|
+
};
|
|
353
|
+
try {
|
|
354
|
+
const { app, runner, warnings } = await runnerOf("read");
|
|
355
|
+
await mkdir(app.dist.cwdPath, { recursive: true });
|
|
356
|
+
await writeFile(path.join(app.dist.cwdPath, "server.js"), 'const env = { hostname: "app.example.test" };\n');
|
|
357
|
+
await runner.assertSecretsLeftOut();
|
|
358
|
+
expect(warnings).toEqual([]);
|
|
359
|
+
await writeFile(
|
|
360
|
+
path.join(app.dist.cwdPath, "chunk-a.js"),
|
|
361
|
+
`const cache = { name: ${JSON.stringify(twinSecrets.plain)} };\n`,
|
|
362
|
+
);
|
|
363
|
+
await runner.assertSecretsLeftOut();
|
|
364
|
+
expect(warnings).toHaveLength(1);
|
|
365
|
+
expect(warnings[0]).toContain(
|
|
366
|
+
"\n cache.password (CACHE__PASSWORD): chunk-a.js; the env's cache.name holds the same string\n",
|
|
367
|
+
);
|
|
368
|
+
expect(holdsSentinel(warnings[0] ?? "")).toBe(false);
|
|
369
|
+
await writeFile(
|
|
370
|
+
path.join(app.dist.cwdPath, "chunk-b.js"),
|
|
371
|
+
`const key = ${JSON.stringify(secretEnvSentinels.google)};\nconst label = ${JSON.stringify(twinSecrets.long)};\n`,
|
|
372
|
+
);
|
|
373
|
+
const failure = await runner.assertSecretsLeftOut().then(
|
|
374
|
+
() => "",
|
|
375
|
+
(error: Error) => error.message,
|
|
376
|
+
);
|
|
377
|
+
expect(failure).toStartWith(
|
|
378
|
+
[
|
|
379
|
+
"The build holds secret values the server reads from its process env, so it stops here:",
|
|
380
|
+
" chunk-b.js holds the value of security.sso.google.clientSecret (SECURITY__SSO__GOOGLE__CLIENT_SECRET)",
|
|
381
|
+
" chunk-b.js holds the value of audit.password (AUDIT__PASSWORD), which the env's audit.label holds as well",
|
|
382
|
+
"",
|
|
383
|
+
].join("\n"),
|
|
384
|
+
);
|
|
385
|
+
expect(holdsSentinel(failure)).toBe(false);
|
|
386
|
+
const inlined = await runnerOf("inline");
|
|
387
|
+
await inlined.runner.assertSecretsLeftOut();
|
|
388
|
+
expect(inlined.warnings.join("\n")).not.toContain("also in what this build wrote");
|
|
389
|
+
} finally {
|
|
390
|
+
for (const key of keys) {
|
|
391
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
392
|
+
else process.env[key] = shellEnv[key];
|
|
393
|
+
}
|
|
394
|
+
await rm(root, { recursive: true, force: true });
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
124
398
|
test("writes the pruned lockfile beside package.json, or warns and leaves the image's install unlocked", async () => {
|
|
125
399
|
const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
|
|
126
400
|
const config = new AkanAppConfig(
|
|
@@ -133,6 +407,7 @@ console.info(new SampleService().name);
|
|
|
133
407
|
const warnings: string[] = [];
|
|
134
408
|
const app = {
|
|
135
409
|
getConfig: async () => config,
|
|
410
|
+
getScanInfo: () => ({ getLibs: () => [] }),
|
|
136
411
|
dist: new Executor("dist", root),
|
|
137
412
|
workspace: { workspaceRoot: root },
|
|
138
413
|
logger: { warn: (message: string) => warnings.push(message) },
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { toError } from "akanjs/common";
|
|
3
|
+
import { AppWorkerPath } from "akanjs/server/appWorkerPath";
|
|
3
4
|
import { BUILD_ENV_FILE } from "akanjs/server/lifecycle/buildEnv";
|
|
5
|
+
import { SecretEnv } from "akanjs/server/lifecycle/secretEnv";
|
|
4
6
|
import type { BunPlugin } from "bun";
|
|
7
|
+
import { AkanBin } from "../akanConfig/akanBin";
|
|
5
8
|
import { ProductionLockfile } from "../akanConfig/productionLockfile";
|
|
9
|
+
import type { AkanWorkersConfig } from "../akanConfig/types";
|
|
6
10
|
import type { App } from "../commandDecorators";
|
|
7
11
|
import { parseEnvFile, WorkspaceExecutor } from "../executors";
|
|
8
12
|
import {
|
|
9
13
|
AllRoutesBuilder,
|
|
14
|
+
type BuildAllRoutesResult,
|
|
10
15
|
CsrArtifactBuilder,
|
|
11
16
|
FontPruner,
|
|
12
17
|
NARROWABLE_VENDOR_SPECIFIERS,
|
|
@@ -14,16 +19,24 @@ import {
|
|
|
14
19
|
SsrBaseArtifactBuilder,
|
|
15
20
|
VendorImportScanner,
|
|
16
21
|
} from "../frontendBuild";
|
|
22
|
+
import { ServerBundleSecrets } from "../mobile/serverBundleSecrets";
|
|
23
|
+
import { RouteRuntimeReport } from "../quality/routeRuntimeReport";
|
|
24
|
+
import { SecretEnvDeclaration, type SecretEnvDeclared } from "../transforms/secretEnvDeclaration";
|
|
25
|
+
import { SecretEnvFile } from "../transforms/secretEnvFile";
|
|
26
|
+
import { ServerEnvEvaluationError } from "../transforms/serverEnvEvaluationError";
|
|
17
27
|
import { createServerEnvPlugin } from "../transforms/serverEnvPlugin";
|
|
18
28
|
import { ServerEnvProfile } from "../transforms/serverEnvProfile";
|
|
19
29
|
import { ProjectTypecheck } from "../typecheck/projectTypecheck";
|
|
20
30
|
import { Spinner } from "../util/spinner";
|
|
21
31
|
import type { BaseDevEnv, PackageJson } from "../workspace/types";
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
import { AppBin } from "./appBin";
|
|
33
|
+
import {
|
|
34
|
+
type ApplicationBuildPhaseResult,
|
|
35
|
+
type ApplicationBuildProgressReporter,
|
|
36
|
+
ApplicationBuildReporter,
|
|
37
|
+
type ApplicationBuildResult,
|
|
26
38
|
} from "./applicationBuildReporter";
|
|
39
|
+
import { RouteFilesReport } from "./routeFilesReport";
|
|
27
40
|
import { RouteJsBudget, type RouteJsBudgetMode, type RouteJsBudgetStatus, type RouteJsSize } from "./routeJsBudget";
|
|
28
41
|
|
|
29
42
|
export interface TypecheckOptions {
|
|
@@ -59,6 +72,12 @@ export interface ApplicationBuildRunnerOptions {
|
|
|
59
72
|
environment?: string;
|
|
60
73
|
/** Bundles `env/env.server.<environment>.<profile>.ts`, which may hold no secret, in place of the environment's file. */
|
|
61
74
|
profile?: string;
|
|
75
|
+
/**
|
|
76
|
+
* An image build's: `read` leaves the server env's secret strings out of the server, which reads each from its process
|
|
77
|
+
* env, and `inline` keeps them in it as what an unset variable falls back to. Unset, as for the server a desktop app
|
|
78
|
+
* carries, or under a `profile`, the env files are bundled as written.
|
|
79
|
+
*/
|
|
80
|
+
secretEnv?: "read" | "inline";
|
|
62
81
|
/**
|
|
63
82
|
* `enforce` fails on an overage, a route with no entry, or a missing or unreadable akan.budget.json; `update` and
|
|
64
83
|
* `raise` rewrite the file first; `report` only warns.
|
|
@@ -109,6 +128,8 @@ export class ApplicationBuildRunner {
|
|
|
109
128
|
#reporter?: BuildProgressReporter;
|
|
110
129
|
#environment?: string;
|
|
111
130
|
#profile?: string;
|
|
131
|
+
#secretEnv?: "read" | "inline";
|
|
132
|
+
#secrets: SecretEnvDeclared = { variables: [], unmoved: [], moved: [] };
|
|
112
133
|
#budget: RouteJsBudgetMode;
|
|
113
134
|
#modulesByRoute?: Record<string, string[]>;
|
|
114
135
|
#spinner?: boolean;
|
|
@@ -123,6 +144,7 @@ export class ApplicationBuildRunner {
|
|
|
123
144
|
reporter,
|
|
124
145
|
environment,
|
|
125
146
|
profile,
|
|
147
|
+
secretEnv,
|
|
126
148
|
budget = "report",
|
|
127
149
|
}: ApplicationBuildRunnerOptions = {},
|
|
128
150
|
) {
|
|
@@ -132,6 +154,7 @@ export class ApplicationBuildRunner {
|
|
|
132
154
|
this.#reporter = reporter;
|
|
133
155
|
this.#environment = environment;
|
|
134
156
|
this.#profile = profile;
|
|
157
|
+
this.#secretEnv = profile ? undefined : secretEnv;
|
|
135
158
|
this.#budget = budget;
|
|
136
159
|
}
|
|
137
160
|
|
|
@@ -163,7 +186,9 @@ export class ApplicationBuildRunner {
|
|
|
163
186
|
|
|
164
187
|
async build({ spinner = false }: BuildOptions = {}): Promise<BuildResult> {
|
|
165
188
|
// serial build is needed because of Bun.build is unstable for parallel build
|
|
166
|
-
|
|
189
|
+
//? ora writes to stderr, and to a file or a pipe it prints each phase twice, the end line in colour.
|
|
190
|
+
this.#spinner = spinner && process.stderr.isTTY;
|
|
191
|
+
if (spinner && !this.#spinner) this.#reporter ??= ApplicationBuildReporter.create();
|
|
167
192
|
if (this.#verify) this.#app.useVerifyDist();
|
|
168
193
|
const { web, assets, baseDevEnv } = await this.#app.getConfig();
|
|
169
194
|
const environment = this.#environment ?? baseDevEnv.env;
|
|
@@ -172,6 +197,7 @@ export class ApplicationBuildRunner {
|
|
|
172
197
|
//? Before any phase: a profile that would ship a secret stops the build, not the image after it.
|
|
173
198
|
if (this.#profile)
|
|
174
199
|
await ServerEnvProfile.assertShippable({ envDir: this.#envDir, environment, profile: this.#profile });
|
|
200
|
+
if (this.#secretEnv) await this.#declareSecrets(environment);
|
|
175
201
|
await this.#runPhase("prepare", "Preparing output directory", () => this.#app.prepareCommand("build"));
|
|
176
202
|
if (!this.#fast) await this.#runPhase("typecheck", "Typechecking", () => this.typecheck());
|
|
177
203
|
await this.#runPhase(
|
|
@@ -186,7 +212,7 @@ export class ApplicationBuildRunner {
|
|
|
186
212
|
async () => (web.ssr ? await this.#buildSsr() : null),
|
|
187
213
|
(result) =>
|
|
188
214
|
result
|
|
189
|
-
?
|
|
215
|
+
? ApplicationBuildRunner.#ssrSummary(result.allRoutes)
|
|
190
216
|
: web.ssr
|
|
191
217
|
? "skipped"
|
|
192
218
|
: "disabled by akan.config.ts web.ssr",
|
|
@@ -221,10 +247,68 @@ export class ApplicationBuildRunner {
|
|
|
221
247
|
: "no files",
|
|
222
248
|
);
|
|
223
249
|
const routeJs = await this.#runBudgetPhase(environment);
|
|
250
|
+
await this.assertSecretsLeftOut();
|
|
224
251
|
await this.#runPhase("metadata", "Writing production metadata", () => this.buildAppMeta());
|
|
252
|
+
this.#reportSecretEnv(environment);
|
|
225
253
|
return this.#resultOf(environment, routeJs);
|
|
226
254
|
}
|
|
227
255
|
|
|
256
|
+
//* A build that cannot load the env file cannot say what it left out, so it stops; under --inline-secrets, which
|
|
257
|
+
//* leaves nothing out, it goes on as a build without the setting does.
|
|
258
|
+
async #declareSecrets(environment: string) {
|
|
259
|
+
try {
|
|
260
|
+
this.#secrets = await SecretEnvDeclaration.of(this.#envDir, environment);
|
|
261
|
+
} catch (error) {
|
|
262
|
+
if (!(error instanceof ServerEnvEvaluationError)) throw error;
|
|
263
|
+
if (this.#secretEnv === "read")
|
|
264
|
+
throw new Error(
|
|
265
|
+
`${error.message}\nA build leaves the secret values of the server env out of what it writes, and names the variables the server reads them from by loading the env file: with no variable of this shell first, then with them. Make the file load at that line, by setting the variable it reads there in this shell or giving it a fallback, and build again. \`akan build --inline-secrets\` builds with the env files as written until akanjs 3.5.0 removes it.`,
|
|
266
|
+
);
|
|
267
|
+
this.#app.logger.warn(
|
|
268
|
+
`--inline-secrets: ${error.message}. The secret values of the server env could not be listed, so this build holds the env files as written: the server reads no secret from a variable of its process env, and names none at boot.`,
|
|
269
|
+
);
|
|
270
|
+
this.#secretEnv = undefined;
|
|
271
|
+
}
|
|
272
|
+
//? Before any phase, and by the env's value alone: a search of the files written misses a short or a plain one.
|
|
273
|
+
if (this.#secretEnv === "read" && this.#secrets.unmoved.length)
|
|
274
|
+
throw new Error(
|
|
275
|
+
SecretEnvFile.unmovedStop(
|
|
276
|
+
this.#app.name,
|
|
277
|
+
environment,
|
|
278
|
+
path
|
|
279
|
+
.relative(this.#app.workspace.workspaceRoot, path.join(this.#envDir, "env.server.ts"))
|
|
280
|
+
.replaceAll("\\", "/"),
|
|
281
|
+
this.#secrets.unmoved,
|
|
282
|
+
),
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
//? Before the metadata phase: a build that still holds a secret gets no Dockerfile to build an image from.
|
|
287
|
+
async assertSecretsLeftOut() {
|
|
288
|
+
if (this.#secretEnv !== "read" || !this.#secrets.moved.length) return;
|
|
289
|
+
const { workspaceRoot } = this.#app.workspace;
|
|
290
|
+
const note = await new ServerBundleSecrets(workspaceRoot, this.#app.cwdPath).assertImageClean(
|
|
291
|
+
this.#app.dist.cwdPath,
|
|
292
|
+
this.#secrets.moved,
|
|
293
|
+
);
|
|
294
|
+
if (note) this.#app.logger.warn(note);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
#reportSecretEnv(environment: string) {
|
|
298
|
+
const { variables } = this.#secrets;
|
|
299
|
+
const { logger, name } = this.#app;
|
|
300
|
+
const names = variables.map((variable) => variable.name).join(", ");
|
|
301
|
+
const count = `${variables.length} secret value${variables.length === 1 ? "" : "s"}`;
|
|
302
|
+
if (variables.length && this.#secretEnv === "inline")
|
|
303
|
+
logger.warn(
|
|
304
|
+
`--inline-secrets keeps ${count} of the server env in this build, where whoever can read the image reads them: ${names}. A variable the deployment sets still wins over the built-in value. akanjs 3.5.0 removes the flag: set them where the server is deployed and build without it.`,
|
|
305
|
+
);
|
|
306
|
+
else if (variables.length)
|
|
307
|
+
logger.info(
|
|
308
|
+
`The server reads ${count} from its process env when it starts, not from this build: ${names}. Set them where it is deployed; \`akan secret-env ${name} --env ${environment}\` lists them and writes them from the env file.`,
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
228
312
|
#runBudgetPhase(environment: string) {
|
|
229
313
|
return this.#runPhase(
|
|
230
314
|
"budget",
|
|
@@ -275,6 +359,11 @@ export class ApplicationBuildRunner {
|
|
|
275
359
|
);
|
|
276
360
|
}
|
|
277
361
|
|
|
362
|
+
static #ssrSummary({ manifest, runtimeReport }: BuildAllRoutesResult) {
|
|
363
|
+
const built = `${manifest.routeIds.length} routes, ${manifest.knownEntries.length} entries`;
|
|
364
|
+
return runtimeReport ? `${built}; ${RouteRuntimeReport.summary(runtimeReport)}` : built;
|
|
365
|
+
}
|
|
366
|
+
|
|
278
367
|
async #runPhase<T>(
|
|
279
368
|
id: BuildPhaseId,
|
|
280
369
|
label: string,
|
|
@@ -305,10 +394,21 @@ export class ApplicationBuildRunner {
|
|
|
305
394
|
const environment = this.#environment ?? akanConfig.baseDevEnv.env;
|
|
306
395
|
const packageJson = akanConfig.getProductionPackageJson();
|
|
307
396
|
const lockfile = await this.#pruneLockfile(packageJson);
|
|
308
|
-
const
|
|
397
|
+
const env = { ...akanConfig.getProductionEnv(environment), ...this.#secretEnvList() };
|
|
398
|
+
const carried = await new AppBin(this.#app, akanConfig).stageImage(this.#app.dist.cwdPath);
|
|
399
|
+
if (carried.length)
|
|
400
|
+
this.#app.logger.info(
|
|
401
|
+
typeof akanConfig.docker === "string"
|
|
402
|
+
? `The build carries ${carried.join(", ")} in ${AppBin.dir}/<TARGETARCH>/; apps/${this.#app.name}/akan.config.ts writes its own Dockerfile, which puts that folder on PATH itself (ENV PATH=${AkanBin.imagePath(AppBin.dir)}).`
|
|
403
|
+
: `The image carries ${carried.join(", ")} from bin, first on its PATH.`,
|
|
404
|
+
);
|
|
405
|
+
const dockerfile = akanConfig.dockerfileFor(environment, {
|
|
406
|
+
lockfile: lockfile !== null,
|
|
407
|
+
env: { ...(carried.length ? { PATH: AkanBin.imagePath(AppBin.dir) } : {}), ...env },
|
|
408
|
+
});
|
|
309
409
|
await Promise.all([
|
|
310
410
|
this.#app.dist.writeJson("package.json", packageJson),
|
|
311
|
-
this.#app.dist.writeJson(BUILD_ENV_FILE,
|
|
411
|
+
this.#app.dist.writeJson(BUILD_ENV_FILE, env),
|
|
312
412
|
...(lockfile !== null
|
|
313
413
|
? [this.#app.dist.writeFile(`${this.#app.dist.cwdPath}/${ProductionLockfile.fileName}`, lockfile)]
|
|
314
414
|
: []),
|
|
@@ -321,6 +421,15 @@ export class ApplicationBuildRunner {
|
|
|
321
421
|
]);
|
|
322
422
|
}
|
|
323
423
|
|
|
424
|
+
//? Names and kinds alone: the image carries the list of what its deployment owes, never a value.
|
|
425
|
+
#secretEnvList(): Record<string, string> {
|
|
426
|
+
if (!this.#secrets.variables.length) return {};
|
|
427
|
+
return {
|
|
428
|
+
[SecretEnv.listKey]: SecretEnv.format(this.#secrets.variables),
|
|
429
|
+
...(this.#secretEnv === "inline" ? { [SecretEnv.fallbackKey]: "image" } : {}),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
324
433
|
async #pruneLockfile(packageJson: PackageJson): Promise<string | null> {
|
|
325
434
|
try {
|
|
326
435
|
return await ProductionLockfile.prune(this.#app.workspace.workspaceRoot, packageJson);
|
|
@@ -356,6 +465,7 @@ export class ApplicationBuildRunner {
|
|
|
356
465
|
environment: this.#environment ?? baseEnv,
|
|
357
466
|
environments: ["local", "testing", ...branches],
|
|
358
467
|
profile: this.#profile,
|
|
468
|
+
secrets: this.#secretEnv,
|
|
359
469
|
onLibEnv: (file, { profileFile, stripped }) => {
|
|
360
470
|
if (profileFile || !stripped.length || this.#warnedLibEnvs.has(file)) return;
|
|
361
471
|
this.#warnedLibEnvs.add(file);
|
|
@@ -377,7 +487,7 @@ export class ApplicationBuildRunner {
|
|
|
377
487
|
}
|
|
378
488
|
|
|
379
489
|
async #buildBackend() {
|
|
380
|
-
const { externalLibs, web, baseDevEnv, branches } = await this.#app.getConfig();
|
|
490
|
+
const { externalLibs, web, baseDevEnv, branches, workers } = await this.#app.getConfig();
|
|
381
491
|
const backendEntryPoints = [`${this.#app.cwdPath}/main.ts`, `${this.#app.cwdPath}/server.ts`];
|
|
382
492
|
for (const entrypoint of backendEntryPoints) {
|
|
383
493
|
if (!(await Bun.file(entrypoint).exists())) throw new Error(`Backend entrypoint not found: ${entrypoint}`);
|
|
@@ -418,13 +528,34 @@ export class ApplicationBuildRunner {
|
|
|
418
528
|
naming: { entry: "console-runtime.[ext]", chunk: "chunk-[hash].[ext]" },
|
|
419
529
|
});
|
|
420
530
|
await this.#writeConsoleShim();
|
|
421
|
-
const
|
|
531
|
+
const workerResults = await this.#buildWorkers(workers, backendConfig);
|
|
532
|
+
const results = [mainResult, serverResult, rscWorkerResult, consoleRuntimeResult, ...workerResults];
|
|
422
533
|
return {
|
|
423
|
-
entrypoints: backendEntryPoints.length + (rscWorkerResult ? 2 : 1),
|
|
534
|
+
entrypoints: backendEntryPoints.length + (rscWorkerResult ? 2 : 1) + workerResults.length,
|
|
424
535
|
outputs: results.reduce((sum, result) => sum + (result?.outputs.length ?? 0), 1),
|
|
425
536
|
};
|
|
426
537
|
}
|
|
427
538
|
|
|
539
|
+
//* Never a chunk of server.js: the process that runs a worker loads nothing of the server, nor the server of it.
|
|
540
|
+
async #buildWorkers(workers: AkanWorkersConfig, backendConfig: Omit<Bun.BuildConfig, "entrypoints">) {
|
|
541
|
+
const results: Bun.BuildOutput[] = [];
|
|
542
|
+
for (const [name, entry] of Object.entries(workers)) {
|
|
543
|
+
if (!(await Bun.file(entry).exists()))
|
|
544
|
+
throw new Error(
|
|
545
|
+
`apps/${this.#app.name}/akan.config.ts: workers.${name} names ${path.relative(this.#app.workspace.workspaceRoot, entry)}, which does not exist.`,
|
|
546
|
+
);
|
|
547
|
+
results.push(
|
|
548
|
+
await this.#buildOrThrow(`worker ${name}`, {
|
|
549
|
+
...backendConfig,
|
|
550
|
+
outdir: path.join(this.#app.dist.cwdPath, AppWorkerPath.dir),
|
|
551
|
+
entrypoints: [entry],
|
|
552
|
+
naming: { entry: `${name}.[ext]`, chunk: "chunk-[hash].[ext]" },
|
|
553
|
+
}),
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
return results;
|
|
557
|
+
}
|
|
558
|
+
|
|
428
559
|
async #writeConsoleShim() {
|
|
429
560
|
await Bun.write(
|
|
430
561
|
path.join(this.#app.dist.cwdPath, "console.js"),
|
|
@@ -484,6 +615,7 @@ void run().catch((error) => {
|
|
|
484
615
|
const base = await new SsrBaseArtifactBuilder(this.#app, "build", {
|
|
485
616
|
serverEnv: this.#serverEnvPlugin(baseDevEnv.env, branches),
|
|
486
617
|
vendorExports,
|
|
618
|
+
dictionaryRoutes: allRoutes.dictionaryRoutes,
|
|
487
619
|
}).build();
|
|
488
620
|
this.#modulesByRoute = (await routes.writeModulePreloads(base.runtimeChunks)).modulesByRoute();
|
|
489
621
|
return { base, allRoutes };
|
|
@@ -493,11 +625,16 @@ void run().catch((error) => {
|
|
|
493
625
|
//? verify build skips writing and measures in memory instead.
|
|
494
626
|
async #measureRouteJs(environment: string): Promise<RouteJsMeasure | null> {
|
|
495
627
|
if (this.#budget === "off" || !this.#modulesByRoute) return null;
|
|
496
|
-
const
|
|
628
|
+
const sizeByUrl = await RouteJsBudget.fileSizes(
|
|
497
629
|
path.join(this.#app.dist.cwdPath, ".akan/artifact"),
|
|
498
630
|
this.#modulesByRoute,
|
|
499
631
|
{ precompressed: !this.#verify },
|
|
500
632
|
);
|
|
633
|
+
const sizes = RouteJsBudget.sizesOf(this.#modulesByRoute, sizeByUrl);
|
|
634
|
+
await RouteFilesReport.write(
|
|
635
|
+
this.#app.cwdPath,
|
|
636
|
+
RouteFilesReport.build(this.#app.name, this.#modulesByRoute, sizeByUrl),
|
|
637
|
+
);
|
|
501
638
|
const budgetPath = path.join(this.#app.cwdPath, RouteJsBudget.fileName);
|
|
502
639
|
const { summary: status, warnings } = await RouteJsBudget.check(sizes, {
|
|
503
640
|
mode: this.#budget,
|