@hyperfrontend/workspace/generators/make-publishable

make-publishable

Gives a library what a published package needs: a build target in the chosen formats, the publish, version and version-check targets, the manifest fields a registry asks for, a README where the project has none, and an e2e project with one suite per format that installs the packed tarball into a consumer outside the workspace.

npx hf generate make-publishable my-utils
npx hf generate make-publishable my-utils \
  --formats=esm,cjs,iife,umd --globalName=AcmeMyUtils
OptionWhat it sets
--projectThe project to make publishable (also the first positional argument)
--formatsThe bundle formats among esm, cjs, iife and umd; defaults to esm,cjs
--globalNameThe global for the iife and umd bundles; defaults to the scope and the name as one class name
--bundleEntryThe entry the browser bundles are built from; defaults to .
--keywordsnpm keywords; defaults to the package's own, else its name, its scope and typescript
--nodeEngineThe Node.js range the package declares; defaults to the package's own, else >=18.0.0
--buildExecutorThe executor of the build target; defaults to @hyperfrontend/workspace:build
--e2eDirectoryWhere the e2e project is created; defaults to e2e
--skipE2EWrite no e2e project
--skipFormatLeave the written files unformatted

A target the project already configures is kept; the build target gains the executor and the formats it lacks. A project that already publishes keeps every e2e file it has. The browser suites of the e2e project preload a DOM, which needs jsdom installed beside @hyperfrontend/testing.

API Reference§

ƒ Functions

§function

makePublishableGenerator(tree: Tree, options: MakePublishableGeneratorOptions): Promise<void>

Makes a library publishable: the targets a package runs, the manifest fields a registry asks for, a README when the project has none, and the project that tests the package.
Parameters
NameTypeDescription
§tree
TreeThe tree, rooted at the workspace
§options
MakePublishableGeneratorOptionsWhich project, and how it is built and tested
Returns
Promise<void>
Resolves when the project is written
Examples

A package in ESM and CommonJS

npx hf generate make-publishable my-lib

A package with browser bundles under a chosen global

npx hf generate make-publishable my-lib --formats=esm,cjs,iife,umd --globalName=MyLib

Re-running on a published library changes nothing it already has

import makePublishableGenerator from '@hyperfrontend/workspace/generators/make-publishable'

await makePublishableGenerator(tree, { project: 'my-lib', formats: ['esm', 'cjs', 'umd'] })
// the build target gains its umd options; the existing targets, keywords, README and e2e suites are kept
§function

planPublishable(tree: Tree, options: MakePublishableGeneratorOptions): PublishablePlan

Settles the options: the project, its package, the formats and the e2e project's names.
Parameters
NameTypeDescription
§tree
TreeThe tree the project lives in
§options
MakePublishableGeneratorOptionsThe options as given
Returns
PublishablePlan
The names, the formats and the e2e project the generator writes from
Example

The formats fall into the build's order and the e2e names follow the package's

planPublishable(tree, { project: 'data-utils', formats: ['umd', 'esm'] })
// => {
//   projectName: 'data-utils',
//   projectRoot: 'libs/data-utils',
//   packageName: '@acme/data-utils',
//   formats: ['esm', 'umd'],
//   globalName: 'AcmeDataUtils',
//   bundleEntry: '.',
//   keywords: ['data-utils', 'acme', 'typescript'],
//   buildExecutor: '@hyperfrontend/workspace:build',
//   e2eProjectName: 'e2e-data-utils',
//   e2ePackageName: '@acme/e2e-data-utils',
//   e2eProjectRoot: 'e2e/data-utils',
//   createE2e: true,
//   republishing: false,
//   e2eExists: false,
//   ...
// }

◈ Interfaces

§interface

MakePublishableGeneratorOptions

What the make-publishable generator takes.
Properties
§project:stringThe project made publishable
§formats?:string[]The bundle formats the package builds; esm and cjs when unset
§globalName?:stringThe global an iife or umd bundle registers under; derived from the package name when unset
§bundleEntry?:stringThe entry the iife and umd bundles are built from; . when unset
§keywords?:string[]npm keywords; the package's own, else its name, its scope and typescript, when unset
§nodeEngine?:stringThe Node.js range the package declares; its own, else >=18.0.0, when unset
§buildExecutor?:stringThe executor of the build target; @hyperfrontend/workspace:build when unset
§e2eDirectory?:stringThe directory the e2e project is created under; e2e when unset
§skipE2E?:booleanSkip creating the e2e project
§skipFormat?:booleanSkip formatting the generated files
§interface

PublishablePlan

The options settled.
Properties
§projectName:stringThe project's name
§projectRoot:stringThe project's directory, relative to the root
§packageName:stringThe package's name
§description:stringThe package's description
§formats:unknownThe bundle formats
§globalName:stringThe global of the browser bundles
§bundleEntry:stringThe entry of the browser bundles
§keywords:string[]The npm keywords
§nodeEngine:stringThe Node.js range chosen, or undefined to keep the package's own or inherit the root's
§buildExecutor:stringThe executor of the build target
§e2eProjectName:stringThe e2e project's name
§e2ePackageName:stringThe e2e package's name
§e2eProjectRoot:stringThe e2e project's directory, relative to the root
§createE2e:booleanWhether the e2e project is created
§republishing:booleanWhether the project already publishes, so what it has is kept
§e2eExists:booleanWhether the e2e project already exists, so every file it has is kept

◆ Types

§type

BundleFormat

A bundle format the build writes.
type BundleFormat = "esm" | "cjs" | "iife" | "umd"