@akanjs/devkit 3.3.0-rc.8 → 3.3.0-rc.81
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 +7 -1
- package/README.md +7 -1
- package/akanApp/akanApp.host.test.ts +3 -1
- package/akanApp/akanApp.host.ts +26 -2
- package/akanApp/akanApp.host.wiring.test.ts +111 -0
- package/akanApp/devHostPolicy.ts +5 -0
- package/akanApp/devMetadataRestart.ts +93 -0
- package/akanApp/devRecycler.test.ts +2 -0
- package/akanApp/devRecycler.ts +9 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +307 -18
- package/akanConfig/akanConfig.ts +104 -210
- package/akanConfig/akanPreview.test.ts +28 -0
- package/akanConfig/akanPreview.ts +24 -0
- package/akanConfig/akanWorkers.test.ts +73 -0
- package/akanConfig/akanWorkers.ts +61 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +233 -0
- package/akanConfig/index.ts +3 -0
- package/akanConfig/nativeFileSettings.ts +33 -0
- package/akanConfig/types.ts +4 -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 +436 -5
- package/app/applicationBuildRunner.ts +237 -37
- package/app/clientServerBoundary.test.ts +115 -0
- package/app/clientServerBoundary.ts +89 -0
- 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 +7 -2
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +64 -8
- package/biome.base.json +7 -5
- package/codeAgent/index.ts +1 -34
- package/codeAgent/skills/akan-agent/SKILL.md +2 -2
- package/codeAgent/skills/akan-debug/SKILL.md +11 -5
- package/codeAgent/skills/akan-deps/SKILL.md +10 -3
- 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 +65 -30
- 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 +21 -20
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +16 -21
- package/codeAgent/skills/akan-validate/SKILL.md +8 -2
- 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/csrE2e/ssrRegistry.e2e.test.ts +108 -22
- package/docs/apiReference.test.ts +25 -0
- package/docs/apiReference.ts +38 -5
- package/docs/declarationReader.ts +30 -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 +155 -1
- package/executors/pkgExecutor.ts +2 -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 +684 -6
- package/frontendBuild/clientBuildTypes.ts +26 -0
- package/frontendBuild/clientEntriesBundler.test.ts +79 -0
- package/frontendBuild/clientEntriesBundler.ts +70 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
- package/frontendBuild/clientEntryDiscovery.ts +134 -12
- 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 +4 -5
- package/frontendBuild/csrDevPatcher.ts +37 -11
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/cssCandidateCache.test.ts +12 -0
- package/frontendBuild/cssCandidateCache.ts +5 -3
- package/frontendBuild/cssCompiler.test.ts +14 -0
- package/frontendBuild/devBarrelImports.test.ts +124 -0
- package/frontendBuild/devBarrelImports.ts +81 -21
- package/frontendBuild/devChangePlanner.ts +0 -1
- 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/frontendBuild.test.ts +5 -3
- 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 +30 -35
- 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.test.ts +47 -3
- package/frontendBuild/vendorNarrowing.ts +38 -2
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/frontendBuild/workerChunks.ts +61 -0
- package/guideline/agentAssets.ts +1 -1
- package/incrementalBuilder/buildBatch.proc.ts +27 -1
- package/incrementalBuilder/buildBatchProtocol.ts +1 -0
- package/incrementalBuilder/builderWatch.ts +11 -1
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +159 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +31 -3
- package/incrementalBuilder/pendingMetadata.test.ts +27 -0
- package/incrementalBuilder/pendingMetadata.ts +19 -0
- package/integration/devResourceProbe.ts +14 -0
- package/integration/devStability.integration.test.ts +46 -21
- package/integration/renderAdmissionSoak.ts +6 -0
- package/integration/ssrMemoryProbe.ts +5 -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 +13 -5
- package/mobile/nativeApp.ts +9 -4
- package/mobile/nativeConfig.test.ts +17 -1
- package/mobile/nativeConfig.ts +11 -6
- package/mobile/nativePublicEnv.ts +1 -1
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +11 -12
- package/packageExports.test.ts +3 -2
- package/preview/PreviewView.ts +43 -6
- package/preview/previewView.test.ts +31 -0
- 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/fakeTerminal.ts +45 -0
- package/test/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +24 -2
- 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 +211 -0
- package/transforms/secretEnvDeclaration.ts +219 -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 +152 -0
- package/transforms/secretEnvSource.ts +197 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +155 -1
- package/transforms/serverEnvPlugin.ts +123 -19
- package/transforms/serverEnvProfile.test.ts +129 -2
- package/transforms/serverEnvProfile.ts +133 -43
- package/transforms/serverEnvSecrets.test.ts +268 -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 +177 -0
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.ts +5 -1
- package/tunnel/ssh2Module.test.ts +37 -0
- package/tunnel/ssh2Module.ts +28 -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/devInstallCommand.ts +7 -0
- package/util/jsonFormatter.test.ts +13 -9
- 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/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 +2 -1
- package/workspace/workspaceLayout.test.ts +22 -1
- package/workspace/workspaceLayout.ts +3 -3
- package/CHANGELOG.md +0 -2903
- package/codeAgent/agent/AkanCodeCompaction.ts +0 -49
- package/codeAgent/agent/AkanCodeServices.ts +0 -122
- package/codeAgent/agent/AkanContextFiles.ts +0 -94
- package/codeAgent/agent/CodeAgent.ts +0 -626
- package/codeAgent/agent/CodeAgentAllowed.ts +0 -35
- package/codeAgent/agent/CodeAgentAsks.ts +0 -66
- package/codeAgent/agent/CodeAgentCommandLine.ts +0 -372
- package/codeAgent/agent/CodeAgentEventMapper.ts +0 -225
- package/codeAgent/agent/CodeAgentGate.ts +0 -258
- package/codeAgent/agent/CodeAgentProxy.ts +0 -83
- package/codeAgent/agent/CodeAgentRpcHost.ts +0 -109
- package/codeAgent/agent/CodeAgentRpcListener.ts +0 -195
- package/codeAgent/agent/CodeAgentStreamPrinter.ts +0 -86
- package/codeAgent/agent/CodeAgentSuspended.ts +0 -85
- package/codeAgent/agent/CodeAgentUi.ts +0 -47
- package/codeAgent/agent/CodeMailbox.ts +0 -148
- package/codeAgent/agent/CodeSessionFork.ts +0 -56
- package/codeAgent/agent/CodeSessionIndex.ts +0 -78
- package/codeAgent/agent/SubagentPool.ts +0 -219
- package/codeAgent/agent/WorkspaceTrust.ts +0 -200
- package/codeAgent/agent/akanCodeCompaction.test.ts +0 -36
- package/codeAgent/agent/akanCodeModel.ts +0 -47
- package/codeAgent/agent/akanCodeServices.test.ts +0 -54
- package/codeAgent/agent/akanContextFiles.test.ts +0 -116
- package/codeAgent/agent/akanSystemPrompt.ts +0 -50
- package/codeAgent/agent/codeAgent.test.ts +0 -337
- package/codeAgent/agent/codeAgentCommandLine.test.ts +0 -212
- package/codeAgent/agent/codeAgentContract.test.ts +0 -755
- package/codeAgent/agent/codeAgentHosts.ts +0 -30
- package/codeAgent/agent/codeAgentProxy.test.ts +0 -126
- package/codeAgent/agent/codeAgentRpcListener.test.ts +0 -215
- package/codeAgent/agent/codeAgentSuspended.test.ts +0 -47
- package/codeAgent/agent/codeMailbox.test.ts +0 -76
- package/codeAgent/agent/codeSessionFork.test.ts +0 -58
- package/codeAgent/agent/codeSessionIndex.test.ts +0 -77
- package/codeAgent/agent/consoleToStderr.ts +0 -8
- package/codeAgent/agent/jsonLines.ts +0 -29
- package/codeAgent/agent/stringArg.ts +0 -5
- package/codeAgent/feedback/DevLogFeedback.ts +0 -82
- package/codeAgent/feedback/PreviewFeedback.ts +0 -46
- package/codeAgent/feedback/TurnFeedback.ts +0 -98
- package/codeAgent/feedback/VerifyFeedback.ts +0 -39
- package/codeAgent/tools/AkanCli.ts +0 -51
- package/codeAgent/tools/AkanCodePlugins.ts +0 -142
- package/codeAgent/tools/AkanEditScope.ts +0 -53
- package/codeAgent/tools/AkanEnvKeys.ts +0 -50
- package/codeAgent/tools/AkanToolPack.ts +0 -86
- package/codeAgent/tools/AkanVerifier.ts +0 -30
- package/codeAgent/tools/AskToolPack.ts +0 -99
- package/codeAgent/tools/DeepSeekWeb.ts +0 -127
- package/codeAgent/tools/MailToolPack.ts +0 -76
- package/codeAgent/tools/McpClient.ts +0 -209
- package/codeAgent/tools/McpOAuth.ts +0 -233
- package/codeAgent/tools/McpOAuthLoopback.ts +0 -64
- package/codeAgent/tools/McpServerConfig.ts +0 -131
- package/codeAgent/tools/McpSignIn.ts +0 -158
- package/codeAgent/tools/McpTokenStore.ts +0 -128
- package/codeAgent/tools/McpToolPack.ts +0 -206
- package/codeAgent/tools/SessionToolPack.ts +0 -91
- package/codeAgent/tools/WebToolPack.ts +0 -315
- package/codeAgent/tools/akanCodePlugins.test.ts +0 -954
- package/codeAgent/tools/askToolPack.test.ts +0 -116
- package/codeAgent/tools/deepSeekWeb.test.ts +0 -113
- package/codeAgent/tools/mcpOAuth.test.ts +0 -648
- package/codeAgent/tools/mcpServerConfig.test.ts +0 -341
- package/piDependencyPins.test.ts +0 -45
|
@@ -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 },
|
|
@@ -85,6 +96,67 @@ console.info(new SampleService().name);
|
|
|
85
96
|
}
|
|
86
97
|
});
|
|
87
98
|
|
|
99
|
+
test("writes each docker variant beside the Dockerfile as Dockerfile.<name>, for the build's environment", async () => {
|
|
100
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
|
|
101
|
+
const config = new AkanAppConfig(
|
|
102
|
+
{ name: "portal" } as never,
|
|
103
|
+
[],
|
|
104
|
+
{ name: "repo", version: "1.0.0", description: "repo" },
|
|
105
|
+
{ docker: { variants: { edge: { env: { AKAN_PUBLIC_OPERATION_MODE: "edge" } } } } },
|
|
106
|
+
{ repoName: "akanjs", serveDomain: "akanjs.com", env: "local", portOffset: 0, workspaceRoot: root },
|
|
107
|
+
);
|
|
108
|
+
const app = {
|
|
109
|
+
getConfig: async () => config,
|
|
110
|
+
getScanInfo: () => ({ getLibs: () => [] }),
|
|
111
|
+
dist: new Executor("dist", root),
|
|
112
|
+
workspace: { workspaceRoot: root },
|
|
113
|
+
logger: { warn: () => undefined },
|
|
114
|
+
} as unknown as App;
|
|
115
|
+
try {
|
|
116
|
+
await new ApplicationBuildRunner(app, { environment: "debug" }).buildAppMeta();
|
|
117
|
+
const image = await readFile(path.join(root, "Dockerfile"), "utf8");
|
|
118
|
+
const edge = await readFile(path.join(root, "Dockerfile.edge"), "utf8");
|
|
119
|
+
expect(image).toContain("ENV AKAN_PUBLIC_OPERATION_MODE=cloud\n");
|
|
120
|
+
expect(edge).toBe(
|
|
121
|
+
image.replace("ENV AKAN_PUBLIC_OPERATION_MODE=cloud\n", "ENV AKAN_PUBLIC_OPERATION_MODE=edge\n"),
|
|
122
|
+
);
|
|
123
|
+
expect(edge).toContain("ENV AKAN_PUBLIC_ENV=debug\n");
|
|
124
|
+
expect((await readFile(path.join(root, ".dockerignore"), "utf8")).split("\n")).toContain("Dockerfile.*");
|
|
125
|
+
} finally {
|
|
126
|
+
await rm(root, { recursive: true, force: true });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("a variant on an env profile names it and asks for none of the secret env values the image's own lists", async () => {
|
|
131
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
|
|
132
|
+
const config = new AkanAppConfig(
|
|
133
|
+
{ name: "portal" } as never,
|
|
134
|
+
[],
|
|
135
|
+
{ name: "repo", version: "1.0.0", description: "repo" },
|
|
136
|
+
{ docker: { variants: { edge: { profile: "edge" }, mirror: {} } } },
|
|
137
|
+
{ repoName: "akanjs", serveDomain: "akanjs.com", env: "local", portOffset: 0, workspaceRoot: root },
|
|
138
|
+
);
|
|
139
|
+
const app = {
|
|
140
|
+
getConfig: async () => config,
|
|
141
|
+
getScanInfo: () => ({ getLibs: () => [] }),
|
|
142
|
+
dist: new Executor("dist", root),
|
|
143
|
+
workspace: { workspaceRoot: root },
|
|
144
|
+
logger: { warn: () => undefined },
|
|
145
|
+
} as unknown as App;
|
|
146
|
+
const runner = new ApplicationBuildRunner(app, { environment: "debug" });
|
|
147
|
+
try {
|
|
148
|
+
await runner.buildAppMeta();
|
|
149
|
+
const [image, edge, mirror] = await Promise.all(
|
|
150
|
+
["Dockerfile", "Dockerfile.edge", "Dockerfile.mirror"].map((name) => readFile(path.join(root, name), "utf8")),
|
|
151
|
+
);
|
|
152
|
+
expect(edge).toContain("ENV AKAN_ENV_PROFILE=edge\n");
|
|
153
|
+
expect(image).not.toContain("AKAN_ENV_PROFILE");
|
|
154
|
+
expect(mirror).toBe(image);
|
|
155
|
+
} finally {
|
|
156
|
+
await rm(root, { recursive: true, force: true });
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
88
160
|
test("writes beside main.js the env its Dockerfile sets, so a host without the image runs the build as is", async () => {
|
|
89
161
|
const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
|
|
90
162
|
const config = new AkanAppConfig(
|
|
@@ -94,9 +166,12 @@ console.info(new SampleService().name);
|
|
|
94
166
|
{},
|
|
95
167
|
{ repoName: "akanjs", serveDomain: "akanjs.com", env: "local", portOffset: 0, workspaceRoot: root },
|
|
96
168
|
);
|
|
169
|
+
const dist = new Executor("dist", root);
|
|
170
|
+
const printed = spyOn(dist.logger, "rawLog").mockImplementation(() => undefined);
|
|
97
171
|
const app = {
|
|
98
172
|
getConfig: async () => config,
|
|
99
|
-
|
|
173
|
+
getScanInfo: () => ({ getLibs: () => [] }),
|
|
174
|
+
dist,
|
|
100
175
|
workspace: { workspaceRoot: root },
|
|
101
176
|
logger: { warn: () => undefined },
|
|
102
177
|
} as unknown as App;
|
|
@@ -113,6 +188,10 @@ console.info(new SampleService().name);
|
|
|
113
188
|
expect(await builtEnv()).toEqual(config.getProductionEnv("debug"));
|
|
114
189
|
expect(await builtEnv()).toEqual(await dockerfileEnv());
|
|
115
190
|
expect(await builtEnv()).toMatchObject({ AKAN_PUBLIC_APP_NAME: "portal", AKAN_PUBLIC_ENV: "debug" });
|
|
191
|
+
expect((await readFile(path.join(root, ".dockerignore"), "utf8")).split("\n")).toEqual(
|
|
192
|
+
expect.arrayContaining(["sqlite", "local", "runtime", "data", ".akan/artifact/image-cache", "node_modules"]),
|
|
193
|
+
);
|
|
194
|
+
expect(printed).not.toHaveBeenCalled();
|
|
116
195
|
await new ApplicationBuildRunner(app).buildAppMeta();
|
|
117
196
|
expect(await builtEnv()).toMatchObject({ AKAN_PUBLIC_ENV: "local" });
|
|
118
197
|
expect(await builtEnv()).toEqual(await dockerfileEnv());
|
|
@@ -121,6 +200,316 @@ console.info(new SampleService().name);
|
|
|
121
200
|
}
|
|
122
201
|
});
|
|
123
202
|
|
|
203
|
+
test("an image build names the secrets its server reads beside main.js and in its Dockerfile, and holds no value of them", async () => {
|
|
204
|
+
const { root, workspace } = await createTempApp("portal");
|
|
205
|
+
await writeSecretEnvFixture(root, { app: "portal" });
|
|
206
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
207
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
208
|
+
for (const key of keys) delete process.env[key];
|
|
209
|
+
await writeFile(
|
|
210
|
+
path.join(root, ".env"),
|
|
211
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
212
|
+
);
|
|
213
|
+
const metaOf = async (options: ConstructorParameters<typeof ApplicationBuildRunner>[1]) => {
|
|
214
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
215
|
+
spyOn(app.logger, "warn").mockImplementation(() => undefined);
|
|
216
|
+
app.prepareCommand = async () => {
|
|
217
|
+
throw new Error("stopped before the phases");
|
|
218
|
+
};
|
|
219
|
+
const runner = new ApplicationBuildRunner(app, options);
|
|
220
|
+
await expect(runner.build()).rejects.toThrow("stopped before the phases");
|
|
221
|
+
await runner.buildAppMeta();
|
|
222
|
+
const env = JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
|
|
223
|
+
[key: string]: string;
|
|
224
|
+
};
|
|
225
|
+
const dockerfile = await readFile(path.join(app.dist.cwdPath, "Dockerfile"), "utf8");
|
|
226
|
+
const dockerfileEnv = Object.fromEntries(
|
|
227
|
+
dockerfile
|
|
228
|
+
.split("\n")
|
|
229
|
+
.filter((line) => line.startsWith("ENV "))
|
|
230
|
+
.map((line) => line.slice("ENV ".length).split(/=(.*)/s).slice(0, 2)),
|
|
231
|
+
);
|
|
232
|
+
expect(env).toEqual(dockerfileEnv);
|
|
233
|
+
expect(holdsSentinel(`${JSON.stringify(env)}${dockerfile}`)).toBe(false);
|
|
234
|
+
return env;
|
|
235
|
+
};
|
|
236
|
+
const names =
|
|
237
|
+
"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|DATABASE_URL";
|
|
238
|
+
try {
|
|
239
|
+
expect((await metaOf({ secretEnv: "read" })).AKAN_ENV_NAMES).toBe(names);
|
|
240
|
+
expect(await metaOf({})).not.toHaveProperty("AKAN_ENV_NAMES");
|
|
241
|
+
} finally {
|
|
242
|
+
for (const key of keys) {
|
|
243
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
244
|
+
else process.env[key] = shellEnv[key];
|
|
245
|
+
}
|
|
246
|
+
await rm(root, { recursive: true, force: true });
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("an image build checks each profile its variants name before any phase, and that variant's Dockerfile lists no secret env name", async () => {
|
|
251
|
+
const { root, workspace } = await createTempApp("portal");
|
|
252
|
+
await writeSecretEnvFixture(root, { app: "portal" });
|
|
253
|
+
await writeFile(
|
|
254
|
+
path.join(root, "apps/portal/akan.config.ts"),
|
|
255
|
+
'export default { docker: { variants: { edge: { profile: "edge" } } } };\n',
|
|
256
|
+
);
|
|
257
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
258
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
259
|
+
for (const key of keys) delete process.env[key];
|
|
260
|
+
await writeFile(
|
|
261
|
+
path.join(root, ".env"),
|
|
262
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
263
|
+
);
|
|
264
|
+
const started = async (options: ConstructorParameters<typeof ApplicationBuildRunner>[1]) => {
|
|
265
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
266
|
+
spyOn(app.logger, "warn").mockImplementation(() => undefined);
|
|
267
|
+
app.prepareCommand = async () => {
|
|
268
|
+
throw new Error("stopped before the phases");
|
|
269
|
+
};
|
|
270
|
+
const runner = new ApplicationBuildRunner(app, options);
|
|
271
|
+
const failure = await runner.build().then(
|
|
272
|
+
() => "",
|
|
273
|
+
(error: Error) => error.message,
|
|
274
|
+
);
|
|
275
|
+
return { app, runner, failure };
|
|
276
|
+
};
|
|
277
|
+
const profileFile = path.join(root, "apps/portal/env/env.server.main.edge.ts");
|
|
278
|
+
try {
|
|
279
|
+
expect((await started({ secretEnv: "read" })).failure).toContain(
|
|
280
|
+
'The server env profile "edge" bundles env/env.server.main.edge.ts',
|
|
281
|
+
);
|
|
282
|
+
expect((await started({})).failure).toBe("stopped before the phases");
|
|
283
|
+
await writeFile(
|
|
284
|
+
path.join(root, "apps/portal/env/env.server.main.runtime.ts"),
|
|
285
|
+
'export const env = { hostname: "runtime-host" };\n',
|
|
286
|
+
);
|
|
287
|
+
expect((await started({ secretEnv: "read", profile: "runtime" })).failure).toContain(
|
|
288
|
+
'The server env profile "edge" bundles env/env.server.main.edge.ts',
|
|
289
|
+
);
|
|
290
|
+
expect((await started({ profile: "runtime" })).failure).toBe("stopped before the phases");
|
|
291
|
+
|
|
292
|
+
await writeFile(profileFile, 'export const env = { mailer: { auth: { pass: "sentinel-edge-pass" } } };\n');
|
|
293
|
+
const secret = await started({ secretEnv: "read" });
|
|
294
|
+
expect(secret.failure).toContain("env/env.server.main.edge.ts holds secret-named values");
|
|
295
|
+
expect(secret.failure).not.toContain("sentinel-edge-pass");
|
|
296
|
+
|
|
297
|
+
await writeFile(profileFile, 'export const env = { hostname: "edge-host" };\n');
|
|
298
|
+
expect((await started({ secretEnv: "read", profile: "runtime" })).failure).toBe("stopped before the phases");
|
|
299
|
+
const { app, runner, failure } = await started({ secretEnv: "read" });
|
|
300
|
+
expect(failure).toBe("stopped before the phases");
|
|
301
|
+
await runner.buildAppMeta();
|
|
302
|
+
const [image, edge] = await Promise.all(
|
|
303
|
+
["Dockerfile", "Dockerfile.edge"].map((name) => readFile(path.join(app.dist.cwdPath, name), "utf8")),
|
|
304
|
+
);
|
|
305
|
+
expect(image).toContain("ENV AKAN_ENV_NAMES=JWT_SECRET,");
|
|
306
|
+
expect(image).not.toContain("AKAN_ENV_PROFILE");
|
|
307
|
+
expect(edge).toContain("ENV AKAN_ENV_PROFILE=edge\n");
|
|
308
|
+
expect(edge).not.toContain("AKAN_ENV_NAMES");
|
|
309
|
+
expect(edge.replace("ENV AKAN_ENV_PROFILE=edge\n", "")).toBe(image.replace(/ENV AKAN_ENV_NAMES=.*\n/, ""));
|
|
310
|
+
} finally {
|
|
311
|
+
for (const key of keys) {
|
|
312
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
313
|
+
else process.env[key] = shellEnv[key];
|
|
314
|
+
}
|
|
315
|
+
await rm(root, { recursive: true, force: true });
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test("an image build stops before any phase at a secret whose variable the platform owns, without printing it", async () => {
|
|
320
|
+
const { root, workspace } = await createTempApp("portal");
|
|
321
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n pwd: "sentinel-pwd-1b84",' });
|
|
322
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
323
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
324
|
+
for (const key of keys) delete process.env[key];
|
|
325
|
+
await writeFile(
|
|
326
|
+
path.join(root, ".env"),
|
|
327
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
328
|
+
);
|
|
329
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
330
|
+
let prepared = false;
|
|
331
|
+
app.prepareCommand = async () => {
|
|
332
|
+
prepared = true;
|
|
333
|
+
throw new Error("prepared");
|
|
334
|
+
};
|
|
335
|
+
try {
|
|
336
|
+
const failure = await new ApplicationBuildRunner(app, { secretEnv: "read" })
|
|
337
|
+
.build()
|
|
338
|
+
.catch((error: Error) => error.message);
|
|
339
|
+
expect(failure).toContain("`pwd` is a secret a build would read from the environment variable PWD");
|
|
340
|
+
expect(holdsSentinel(String(failure))).toBe(false);
|
|
341
|
+
expect(prepared).toBe(false);
|
|
342
|
+
} finally {
|
|
343
|
+
for (const key of keys) {
|
|
344
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
345
|
+
else process.env[key] = shellEnv[key];
|
|
346
|
+
}
|
|
347
|
+
await rm(root, { recursive: true, force: true });
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
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", async () => {
|
|
352
|
+
const { root, workspace } = await createTempApp("portal");
|
|
353
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n hosts: process.env.ZQ_HOSTS!.split(","),' });
|
|
354
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN", "ZQ_HOSTS"] as const;
|
|
355
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
356
|
+
for (const key of keys) delete process.env[key];
|
|
357
|
+
await writeFile(
|
|
358
|
+
path.join(root, ".env"),
|
|
359
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
360
|
+
);
|
|
361
|
+
const started = async () => {
|
|
362
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
363
|
+
const warnings: string[] = [];
|
|
364
|
+
spyOn(app.logger, "warn").mockImplementation((message: string) => {
|
|
365
|
+
warnings.push(message);
|
|
366
|
+
});
|
|
367
|
+
app.prepareCommand = async () => {
|
|
368
|
+
throw new Error("stopped before the phases");
|
|
369
|
+
};
|
|
370
|
+
const runner = new ApplicationBuildRunner(app, { secretEnv: "read" });
|
|
371
|
+
const failure = await runner.build().then(
|
|
372
|
+
() => "",
|
|
373
|
+
(error: Error) => error.message,
|
|
374
|
+
);
|
|
375
|
+
return { app, runner, failure, warnings };
|
|
376
|
+
};
|
|
377
|
+
const envOf = async ({ app, runner }: Awaited<ReturnType<typeof started>>) => {
|
|
378
|
+
await runner.buildAppMeta();
|
|
379
|
+
return JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
|
|
380
|
+
[key: string]: string;
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
const place =
|
|
384
|
+
/env\.server\.ts could not be evaluated to check it for secrets: TypeError at .*env\.server\.main\.ts:\d+/;
|
|
385
|
+
try {
|
|
386
|
+
const stopped = await started();
|
|
387
|
+
expect(stopped.failure).toMatch(place);
|
|
388
|
+
expect(stopped.failure).toEndWith(
|
|
389
|
+
"by setting the variable it reads there in this shell or giving it a fallback, and build again.",
|
|
390
|
+
);
|
|
391
|
+
expect(stopped.warnings).toEqual([]);
|
|
392
|
+
expect(holdsSentinel(stopped.failure)).toBe(false);
|
|
393
|
+
|
|
394
|
+
process.env.ZQ_HOSTS = "a.example.test,b.example.test";
|
|
395
|
+
const built = await started();
|
|
396
|
+
expect(built.failure).toBe("stopped before the phases");
|
|
397
|
+
expect((await envOf(built)).AKAN_ENV_NAMES).toStartWith("JWT_SECRET,SECURITY__SSO__GOOGLE__CLIENT_SECRET,");
|
|
398
|
+
} finally {
|
|
399
|
+
for (const key of keys) {
|
|
400
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
401
|
+
else process.env[key] = shellEnv[key];
|
|
402
|
+
}
|
|
403
|
+
await rm(root, { recursive: true, force: true });
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
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 () => {
|
|
408
|
+
const { root, workspace } = await createTempApp("portal");
|
|
409
|
+
await writeComputedSecretFixture(root, "portal");
|
|
410
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
411
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
412
|
+
for (const key of keys) delete process.env[key];
|
|
413
|
+
await writeFile(
|
|
414
|
+
path.join(root, ".env"),
|
|
415
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
416
|
+
);
|
|
417
|
+
const started = async () => {
|
|
418
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
419
|
+
spyOn(app.logger, "warn").mockImplementation(() => undefined);
|
|
420
|
+
let prepared = false;
|
|
421
|
+
app.prepareCommand = async () => {
|
|
422
|
+
prepared = true;
|
|
423
|
+
throw new Error("stopped before the phases");
|
|
424
|
+
};
|
|
425
|
+
const failure = await new ApplicationBuildRunner(app, { secretEnv: "read" }).build().then(
|
|
426
|
+
() => "",
|
|
427
|
+
(error: Error) => error.message,
|
|
428
|
+
);
|
|
429
|
+
return { failure, prepared: () => prepared };
|
|
430
|
+
};
|
|
431
|
+
try {
|
|
432
|
+
const stopped = await started();
|
|
433
|
+
expect(stopped.prepared()).toBe(false);
|
|
434
|
+
expect(stopped.failure).toStartWith(
|
|
435
|
+
`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`,
|
|
436
|
+
);
|
|
437
|
+
expect(holdsSentinel(stopped.failure)).toBe(false);
|
|
438
|
+
for (const value of Object.values(computedSecrets)) expect(stopped.failure).not.toContain(value);
|
|
439
|
+
} finally {
|
|
440
|
+
for (const key of keys) {
|
|
441
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
442
|
+
else process.env[key] = shellEnv[key];
|
|
443
|
+
}
|
|
444
|
+
await rm(root, { recursive: true, force: true });
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
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 () => {
|
|
449
|
+
const { root, workspace } = await createTempApp("portal");
|
|
450
|
+
await writeSecretEnvFixture(root, { app: "portal", mainExtra: twinSecretEnv.split("\n").slice(0, 3).join("\n") });
|
|
451
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
452
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
453
|
+
for (const key of keys) delete process.env[key];
|
|
454
|
+
await writeFile(
|
|
455
|
+
path.join(root, ".env"),
|
|
456
|
+
"AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
|
|
457
|
+
);
|
|
458
|
+
const runnerOf = async () => {
|
|
459
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
460
|
+
const warnings: string[] = [];
|
|
461
|
+
spyOn(app.logger, "warn").mockImplementation((message: string) => {
|
|
462
|
+
warnings.push(message);
|
|
463
|
+
});
|
|
464
|
+
app.prepareCommand = async () => {
|
|
465
|
+
throw new Error("stopped before the phases");
|
|
466
|
+
};
|
|
467
|
+
const runner = new ApplicationBuildRunner(app, { secretEnv: "read" });
|
|
468
|
+
await expect(runner.build()).rejects.toThrow("stopped before the phases");
|
|
469
|
+
return { app, runner, warnings };
|
|
470
|
+
};
|
|
471
|
+
try {
|
|
472
|
+
const { app, runner, warnings } = await runnerOf();
|
|
473
|
+
await mkdir(app.dist.cwdPath, { recursive: true });
|
|
474
|
+
await writeFile(path.join(app.dist.cwdPath, "server.js"), 'const env = { hostname: "app.example.test" };\n');
|
|
475
|
+
await runner.assertSecretsLeftOut();
|
|
476
|
+
expect(warnings).toEqual([]);
|
|
477
|
+
await writeFile(
|
|
478
|
+
path.join(app.dist.cwdPath, "chunk-a.js"),
|
|
479
|
+
`const cache = { name: ${JSON.stringify(twinSecrets.plain)} };\n`,
|
|
480
|
+
);
|
|
481
|
+
await runner.assertSecretsLeftOut();
|
|
482
|
+
expect(warnings).toHaveLength(1);
|
|
483
|
+
expect(warnings[0]).toContain(
|
|
484
|
+
"\n cache.password (CACHE__PASSWORD): chunk-a.js; the env's cache.name holds the same string\n",
|
|
485
|
+
);
|
|
486
|
+
expect(holdsSentinel(warnings[0] ?? "")).toBe(false);
|
|
487
|
+
await writeFile(
|
|
488
|
+
path.join(app.dist.cwdPath, "chunk-b.js"),
|
|
489
|
+
`const key = ${JSON.stringify(secretEnvSentinels.google)};\nconst label = ${JSON.stringify(twinSecrets.long)};\n`,
|
|
490
|
+
);
|
|
491
|
+
const failure = await runner.assertSecretsLeftOut().then(
|
|
492
|
+
() => "",
|
|
493
|
+
(error: Error) => error.message,
|
|
494
|
+
);
|
|
495
|
+
expect(failure).toStartWith(
|
|
496
|
+
[
|
|
497
|
+
"The build holds secret values the server reads from its process env, so it stops here:",
|
|
498
|
+
" chunk-b.js holds the value of security.sso.google.clientSecret (SECURITY__SSO__GOOGLE__CLIENT_SECRET)",
|
|
499
|
+
" chunk-b.js holds the value of audit.password (AUDIT__PASSWORD), which the env's audit.label holds as well",
|
|
500
|
+
"",
|
|
501
|
+
].join("\n"),
|
|
502
|
+
);
|
|
503
|
+
expect(holdsSentinel(failure)).toBe(false);
|
|
504
|
+
} finally {
|
|
505
|
+
for (const key of keys) {
|
|
506
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
507
|
+
else process.env[key] = shellEnv[key];
|
|
508
|
+
}
|
|
509
|
+
await rm(root, { recursive: true, force: true });
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
|
|
124
513
|
test("writes the pruned lockfile beside package.json, or warns and leaves the image's install unlocked", async () => {
|
|
125
514
|
const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
|
|
126
515
|
const config = new AkanAppConfig(
|
|
@@ -133,6 +522,7 @@ console.info(new SampleService().name);
|
|
|
133
522
|
const warnings: string[] = [];
|
|
134
523
|
const app = {
|
|
135
524
|
getConfig: async () => config,
|
|
525
|
+
getScanInfo: () => ({ getLibs: () => [] }),
|
|
136
526
|
dist: new Executor("dist", root),
|
|
137
527
|
workspace: { workspaceRoot: root },
|
|
138
528
|
logger: { warn: (message: string) => warnings.push(message) },
|
|
@@ -379,16 +769,16 @@ console.info(new SampleService().name);
|
|
|
379
769
|
expect(order).toEqual(["routes"]);
|
|
380
770
|
});
|
|
381
771
|
|
|
382
|
-
test("akan typecheck
|
|
772
|
+
test("akan typecheck asks for the tests and script/ files nothing imports, and a build's typecheck does not", async () => {
|
|
383
773
|
const { root, app } = await createTempApp("portal");
|
|
384
774
|
const run = spyOn(ProjectTypecheck.prototype, "run").mockImplementation(async () => "");
|
|
385
775
|
try {
|
|
386
776
|
const runner = new ApplicationBuildRunner(app);
|
|
387
777
|
await runner.typecheck({ tests: true });
|
|
388
778
|
await runner.typecheck();
|
|
389
|
-
const [checked, built] = run.mock.calls.map(([
|
|
390
|
-
expect(checked).
|
|
391
|
-
expect(built).
|
|
779
|
+
const [checked, built] = run.mock.calls.map(([, options]) => options?.tests);
|
|
780
|
+
expect(checked).toBe(true);
|
|
781
|
+
expect(built).toBeUndefined();
|
|
392
782
|
} finally {
|
|
393
783
|
run.mockRestore();
|
|
394
784
|
await rm(root, { recursive: true, force: true });
|
|
@@ -455,6 +845,47 @@ console.info(new SampleService().name);
|
|
|
455
845
|
}
|
|
456
846
|
});
|
|
457
847
|
|
|
848
|
+
test("main.js sets the build's env before a package the bundle leaves outside loads", async () => {
|
|
849
|
+
const { root, workspace } = await createTempApp("portal");
|
|
850
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
851
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
852
|
+
await Promise.all(["main.ts", "server.ts"].map((file) => writeFile(path.join(root, "apps", "portal", file), "")));
|
|
853
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
854
|
+
app.prepareCommand = async () => ({ env: {} });
|
|
855
|
+
const bundle = spyOn(Bun, "build").mockImplementation(
|
|
856
|
+
async () => ({ success: true, outputs: [], logs: [] }) as unknown as Bun.BuildOutput,
|
|
857
|
+
);
|
|
858
|
+
try {
|
|
859
|
+
await new ApplicationBuildRunner(app, { verify: true }).build();
|
|
860
|
+
const configs = bundle.mock.calls.map(([config]) => config);
|
|
861
|
+
const envModule = configs.find(({ entrypoints }) =>
|
|
862
|
+
entrypoints.some((entry) => entry.endsWith("loadBuildEnv.ts")),
|
|
863
|
+
);
|
|
864
|
+
const main = configs.find(({ entrypoints }) => entrypoints.some((entry) => entry.endsWith("main.ts")));
|
|
865
|
+
bundle.mockRestore();
|
|
866
|
+
if (!envModule || !main) throw new Error("the build made no env module or no main bundle");
|
|
867
|
+
const { entry: mainBundle } = main.naming as { entry: string };
|
|
868
|
+
await Bun.build(envModule);
|
|
869
|
+
const dist = app.dist.cwdPath;
|
|
870
|
+
await mkdir(path.join(dist, "node_modules", "probe"), { recursive: true });
|
|
871
|
+
await writeFile(path.join(dist, "node_modules", "probe", "index.js"), "module.exports = process.env.NODE_ENV;\n");
|
|
872
|
+
await writeFile(path.join(dist, "akan.env.json"), '{ "NODE_ENV": "production" }\n');
|
|
873
|
+
await writeFile(path.join(dist, mainBundle), 'import mode from "probe";\nconsole.log(mode);\n');
|
|
874
|
+
const { NODE_ENV: _mode, ...env } = process.env;
|
|
875
|
+
const proc = Bun.spawnSync([process.execPath, "main.js"], { cwd: dist, env, stdout: "pipe", stderr: "pipe" });
|
|
876
|
+
|
|
877
|
+
expect(proc.stderr.toString()).toBe("");
|
|
878
|
+
expect(proc.stdout.toString()).toBe("production\n");
|
|
879
|
+
} finally {
|
|
880
|
+
bundle.mockRestore();
|
|
881
|
+
for (const key of keys) {
|
|
882
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
883
|
+
else process.env[key] = shellEnv[key];
|
|
884
|
+
}
|
|
885
|
+
await rm(root, { recursive: true, force: true });
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
|
|
458
889
|
test("a verify build writes to dist/verify/<app> and leaves the full build in dist/apps/<app> as it was", async () => {
|
|
459
890
|
const { root, workspace } = await createTempApp("portal");
|
|
460
891
|
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|