Package templates
Package templates create new packages with the same configuration and starter files as the rest
of your workspace. A template is not a separate configuration type: it is built from one or more
variants and their optional initialization content.
Define a package template
Section titled “Define a package template”Add initialization to a variant for values that should be written when a package is created but
do not need to be enforced by linting later.
import { defineConfig } from "monoswan";
export default defineConfig({ variants: { "my-library": { packageJson: { type: "module", scripts: { build: "tsdown" }, }, initialization: { packageJson: { version: "0.0.0", private: true, }, tsConfig: { extends: "@myrepo/typescript-config/library.json", }, additionalTextFiles: { "src/index.ts": "export {};\n", }, }, }, },});The regular variant content is both written during package creation and checked by
monoswan lint. The initialization content is only used when creating the package. This makes
it useful for initial versions, private flags, starter source files, and other defaults that a
package may change later.
Package templates can create or populate:
package.jsontsconfig.jsonand other TypeScript configuration files- Additional JSON files
- Additional text files, including source files
Create a package
Section titled “Create a package”Pass the destination, package name, and one or more variants to create-package:
monoswan create-package packages/ui-button @myrepo/ui-button my-libraryThe generated package.json always uses the package name supplied to the command. By default, it
also records the selected variants in its monoswan field so the new package is ready for
linting. See the create-package command reference for all
arguments and options.
Compose package templates
Section titled “Compose package templates”You can select multiple variants to assemble a package from smaller building blocks:
monoswan create-package packages/api @myrepo/api base node serviceFor base and my-library, for example, creation order is base, base.initialization,
my-library, then my-library.initialization. Later values win according to the configured merge
functions.
Normal linting uses only regular variant content.
