Files
tech-log-frontend/vite.service-worker.config.ts
T
DongHyeonka c80320dfc7 chore: sync the frontend template from ebea300 to af3d8e6
Carries 359 template commits, tag v0.2.0 plus one documentation commit: the
generator-built feature index with its app, bounded-context and feature
declarations, the src/platform kernel and scale tooling, the 2026-09-24 src
review fixes, and the 2026-09-25 maturity review round with its CHANGELOG
[보안]/[계약] rows. 691 of the 824 template paths are applied, 85 of them
merged with product changes; 127 are not carried.

Product identity is unchanged: name, version 0.1.0, routes, design and the
TechLog domain.

Three decisions worth naming. TechLog stays composed directly, as the last
two syncs recorded; its directory carries a NOT_INSTALLED marker that says so,
and every installed-* composer takes the template's projection with TechLog
added on top. The reference sample is no longer installed: the template now
installs a feature only through feature-module.ts and context-routes.ts,
which load the screens this product deleted, so its three operations, six
schemas and one topic leave the registries, recorded as registry change
evidence. And AppRouter mounts the platform and TechLog routes only; the
template's bounded-context route gateway waits for a generator-installed
feature.

Required fixes: readSubject on the BFF session owner (without it every HTTP
Studio session would close as integration-failed), zod through the facade in
nine TechLog files, noUnusedLocals, and public/config.json written out to
match the local profile. Derived baselines were recomputed after reproducing
both sides' values: CI contract 101 commands / 106 references / 141
artifacts, gate shape c9adcf85; registry approval 2dc6c3a3; the runtime
config schema baseline equals the schema at 8210d48.

Verified here: types, lint, architecture, adapter inventory, CI contract,
i18n, design system, diagnostics, browser security, dev release manifest,
TechLog contract and build pass; 220 component, 155 integration, 15
contract, 418 TechLog, 43 reference-feature, 18 recipe and 46
release-coherence tests pass, and 2381 of 2383 unit tests. Reproduced at
8210d48 first and unchanged: check:registries (byte-identical),
test:runtime-schema, verify:documentation. Brought by the template and
escalated rather than suppressed: check:request-fanout on TechLog's cursor
pagination, check:remediation-ledger (fails upstream too), the shared-chunk
hash test, and the registry-dependent sample removal and second-feature
tests. Playwright suites were not run.

Full record, the five open questions and the follow-ups in
docs/operations/template-sync-2026-09-29.md.

(cherry picked from commit b2170cf265dea45dc9cc05d3c61e627e97f31cdb)
2026-11-12 08:28:54 +09:00

102 lines
3.4 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { defineConfig } from "vite";
import {
SERVICE_WORKER_CACHE_SCHEMA_VERSION,
SERVICE_WORKER_PROTOCOL_VERSION,
SERVICE_WORKER_SCRIPT_PATH,
} from "./src/contracts/service-worker.ts";
import { INSTALLED_RUNTIME_CAPABILITIES } from "./src/features/installed-runtime-capabilities.ts";
import { resolveServiceWorkerBuildInput } from "./scripts/lib/service-worker-build-input.ts";
/**
* §17.2.2 step 5. The Service Worker build.
*
* Runs only when the static selection is `ACTIVE`, after the app build has
* completed and the hashed asset list has been generated. `emptyOutDir` is
* false so it adds `service-worker.js` beside the already-built app rather than
* replacing it.
*/
const selection = INSTALLED_RUNTIME_CAPABILITIES.serviceWorker;
// Relative to this file: Vite's default `bundle` config loader runs the config
// from `node_modules/.vite-temp/`, so a bare `import("./.generated/...")` would
// resolve there. Every loader keeps `import.meta.url` pointing at this file.
async function readGenerated<T>(path: string, exportName: string): Promise<T> {
try {
const module = (await import(new URL(path, import.meta.url).href)) as Record<
string,
unknown
>;
if (!(exportName in module)) {
throw new TypeError(`Generated module does not export ${exportName}.`);
}
return module[exportName] as T;
} catch (error) {
throw new TypeError(`Required generated module is unavailable: ${path}`, {
cause: error,
});
}
}
const assets = await readGenerated(
"./.generated/frontend-runtime/service-worker-assets.ts",
"SERVICE_WORKER_ASSETS",
);
const contractSet = await readGenerated<{ setDigest?: string }>(
"./.generated/frontend-runtime/contract-set.ts",
"BUILD_CONTRACT_SET",
);
// 06-10 / F-8. The profile document `scripts/generate-runtime-config.ts` wrote
// in step 4, not `public/config.json`, which is always the local profile.
const runtimeConfig = JSON.parse(
await readFile("dist/config.json", "utf8"),
) as Record<string, string>;
const buildId = process.env.VITE_BUILD_ID ?? "local-build";
const releaseId = process.env.RELEASE_ID ?? "local-release";
const buildInput = resolveServiceWorkerBuildInput({
selection,
assets,
contractSet,
runtimeConfig,
appProfile: process.env.APP_PROFILE ?? "local",
buildId,
releaseId,
});
export default defineConfig({
build: {
// §17.2.2: exactly one input, exactly one output, no additional chunk.
emptyOutDir: false,
sourcemap: false,
rollupOptions: {
input: "src/adapters/service-worker/service-worker-entry.ts",
output: {
format: "es",
inlineDynamicImports: true,
entryFileNames: SERVICE_WORKER_SCRIPT_PATH,
},
},
},
define: {
__CA_SERVICE_WORKER_BUILD_INFO__: JSON.stringify({
serviceWorkerProtocolVersion: SERVICE_WORKER_PROTOCOL_VERSION,
cacheSchemaVersion: SERVICE_WORKER_CACHE_SCHEMA_VERSION,
buildId,
releaseId,
contractSetDigest: buildInput.contractSetDigest,
staticAssetSetDigest: buildInput.assets.setDigest,
}),
__CA_SERVICE_WORKER_ASSETS__: JSON.stringify(buildInput.assets),
__CA_SERVICE_WORKER_HANDLERS__: JSON.stringify(buildInput.handlers),
__CA_RUNTIME_CONFIG_URL__: JSON.stringify(
process.env.VITE_RUNTIME_CONFIG_URL ?? "/config.json",
),
__CA_RELEASE_MANIFEST_URL__: JSON.stringify(
buildInput.releaseManifestUrl,
),
},
});