Entrysmith is a CLI tool for keeping package entrypoints in sync across a TypeScript workspace.
It lets a package expose imports such as @scope/package/model or @scope/package/test/another from files under src, then updates the package metadata and TypeScript project references needed for other workspace packages to consume those entrypoints.
Running entrysmith fix in a configured workspace package:
- ensures the configured build output directory is listed in
package.jsonfiles - rewrites
package.jsonexportsfor every configured entrypoint - keeps
./package.jsonexported - adds TypeScript project references for workspace dependencies
- adds
compilerOptions.pathsmappings for entrypoints exposed by workspace dependencies
Running entrysmith without arguments runs entrysmith fix.
Entrypoints are files in the package src directory. Each entrypoint becomes an importable package subpath.
{
"entrysmith": {
"entrypoints": [
"model/index.ts",
"test/index.ts",
"test/another.ts"
],
"entrypointOutputMode": "esm"
}
}These entrypoints expose imports like:
import { Model } from "@scope/package/model";
import { testHelper } from "@scope/package/test";
import { anotherHelper } from "@scope/package/test/another";index.ts maps to its containing directory. Other file names map to their full path without extension.
Entrysmith loads configuration from one of:
package.jsonunder theentrysmithkeyentrysmith.config.jsentrysmith.config.tsentrysmith.config.json
Configuration fields:
entrypoints: list of entrypoint files undersrcentrypointOutputMode:"esm"or"cjs"packageOutputDirectory: build output directory used in package exports, defaults to"dist"typescript.tsConfigReferenceTargetPath: target path used when other workspace packages reference this package, defaults to the package roottypescript.referenceTsConfigPaths: tsconfig files that receive references and path mappings, defaults to["tsconfig.json"]
Example:
{
"entrysmith": {
"entrypoints": [
"model/index.ts",
"test/another.ts"
],
"entrypointOutputMode": "esm",
"packageOutputDirectory": "dist",
"typescript": {
"tsConfigReferenceTargetPath": "tsconfig.json",
"referenceTsConfigPaths": ["tsconfig.json"]
}
}
}For entrypointOutputMode: "esm", Entrysmith writes exports like:
{
"exports": {
"./model": {
"import": "./dist/model/index.js"
},
"./test/another": {
"import": "./dist/test/another.js"
},
"./package.json": "./package.json"
}
}For entrypointOutputMode: "cjs", Entrysmith uses default instead of import.
Entrysmith discovers packages in the current workspace.
When the current package depends on another workspace package that has Entrysmith configuration, entrysmith fix updates the configured tsconfig files with:
referencespointing to the dependency package or its configuredtsConfigReferenceTargetPathcompilerOptions.pathsentries such as@scope/dependency/modelpointing at the dependency source entrypoint
If multiple configured tsconfig files extend a common parent that is also configured, Entrysmith stores path mappings in the common parent.
Run from a workspace package directory that contains Entrysmith configuration:
entrysmith fixTo keep entrypoints synchronized automatically, add entrysmith fix to the package prepare script:
{
"scripts": {
"prepare": "entrysmith fix"
}
}