@hyperfrontend/workspace/executors/serviceservice
Builds a service written on @hyperfrontend/server into a directory that runs with node alone: one CommonJS main with every package inlined, the manifest of its immutable section, its assets, and a release manifest that lists every file by size and SHA-256. The main is sealed by the kernel the service installs, so the built service refuses to boot beside bytes the build did not write.
{
"build": {
"executor": "@hyperfrontend/workspace:service",
"options": {
"assets": ["assets/**"]
}
}
}
| Option | What it does |
|---|---|
--outputPath | Where the service is written, relative to the root; defaults to dist/<project root> |
--tsConfig | The TypeScript configuration, relative to the root; defaults to tsconfig.lib.json in the project |
--assets | Globs relative to src/, the directory of the entry module; each match is copied to the same path beside the main. A list, so it is set in project.json |
--verbose | Prints the build's diagnostics |
The entry is always src/main.ts, and a project also needs service.config.ts, the TypeScript configuration and a package.json that states a name and a version. hf generate service writes all of them. An option the executor does not take is refused, and every problem of the options is reported at once.
What it writes
dist/apps/hello/
main.cjs the bundle, executable
service.manifest.json the immutable section and its digest
hf-release.json every other file, with its size and SHA-256
assets/notice.txt each asset, at its path relative to src/
Nothing else: no package.json and no installed packages. Start it with node dist/apps/hello/main.cjs, with nothing between the platform's signal and the process. The build prints one line, built hello release=<sha256> immutable=<sha256>, and the running service prints the same release digest in its started line.
The output directory is emptied first when it is absent, empty or a previous build of the same service. A directory that holds anything else is refused. A build that fails once it has started writing removes what it wrote, and a build refused before that leaves the previous build as it was. A built service checks its own directory at boot, so it must not write beside its main: data lives elsewhere.
The immutable section
service.config.ts default-exports a plain object with one member, immutable, holding the structural settings fixed when the service is built. It must be JSON values only, nested no deeper than 32 levels, and the file is read twice: by the build and by the service itself, which hands the section to the runner. So the file has to give the same value every time. A section built from the clock or the environment gets another digest at boot, and the service refuses to start.
// service.config.ts
export default { immutable: { greeting: 'Hello', limits: { names: 3 } } }
Assets
In the built main every module has the main's URL, so a file is addressed the same way from source and built only when the URL is formed in a module directly in src/. Form the base once there and import it everywhere else:
// src/assets.ts
export const assetsUrl = new URL('./assets/', import.meta.url)
// src/routes/notice.ts
readFileSync(fileURLToPath(new URL('notice.txt', assetsUrl)), 'utf8')
The build reads the service's own sources and refuses the ones that would resolve differently once built: import.meta.url in a module below src/ or in service.config.ts, and import.meta.dirname or import.meta.filename anywhere, since a built service has neither. A glob that matches no file is refused, and so is one that matches main.cjs, service.manifest.json or hf-release.json.
Limits
- Every package is inlined, so a native addon cannot be built in, and there is no source map.
- The build checks that the main reaches the runner, not that it always starts through it, so keep
src/main.tsas generated. - A service that imports a workspace library through a path alias needs
rootDirstated intsconfig.base.json, whichhf generate workspacewrites. - The source check reads the service's own files,
service.config.tsincluded, and sees a member read fromimport.metadirectly. It does not follow one handed to a variable first, and it does not read a workspace library, which is inlined with the main's URL. - The release check catches a partial or changed deployment. It is not a defence against someone who can write to the directory.
API Reference§
ƒ Functions
service.config.ts exports by default, and reports every problem at once.Parameters
| Name | Type | Description |
|---|---|---|
§value | unknown | The default export |
Returns
unknownExample
A configuration with two problems
import { checkServiceConfig } from '@hyperfrontend/workspace/executors/service'
checkServiceConfig({ immutable: { limits: { names: 3 } } }) // => []
checkServiceConfig({ immutable: { since: new Date(0) }, routes: [] }).map((issue) => issue.message)
// => [
// 'immutable.since must be a JSON value: a string, a finite number, a boolean, null, an array or a plain object.',
// 'the configuration has an unknown member "routes": it takes immutable.',
// ]◈ Interfaces
service.config.ts default-exports.Properties
Properties
readonly message:stringThe problem in a sentence, holding member names and paths and never a value.Properties
outputPath?:stringOutput directory, relative to the workspace root. Defaults to dist/<project root>.tsConfig?:stringPath to tsconfig, relative to the workspace root. Defaults to <project root>/tsconfig.lib.json.assets?:string[ ]Globs relative to the entry module's directory; each match is copied to the same relative path beside the main.service.manifest.json holds, schema 1.Properties
service.manifest.json states it.Properties
◆ Types
type JsonValue = string | number | boolean | null | unknown | { }type ServiceConfigIssueCode = "config-not-object" | "config-unknown-member" | "immutable-not-object" | "immutable-not-json" | "immutable-too-deep"● Variables
service.manifest.json, the assets and hf-release.json.Example
A `build` target that copies a directory of assets beside the main
{
"targets": {
"build": {
"executor": "@hyperfrontend/workspace:service",
"options": { "assets": ["assets/**"] }
}
}
}
```
Run with `npx hf run hello:build`; the service lands in `dist/apps/hello` and starts with `node dist/apps/hello/main.cjs`.