# 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. ```bash npx hf generate make-publishable my-utils npx hf generate make-publishable my-utils \ --formats=esm,cjs,iife,umd --globalName=AcmeMyUtils ``` | Option | What it sets | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `--project` | The project to make publishable (also the first positional argument) | | `--formats` | The [bundle formats](https://www.hyperfrontend.dev/docs/libraries/workspace/generators/make-publishable/#api-BundleFormat) among esm, cjs, iife and umd; defaults to `esm,cjs` | | `--globalName` | The global for the iife and umd bundles; defaults to the scope and the name as one class name | | `--bundleEntry` | The entry the browser bundles are built from; defaults to `.` | | `--keywords` | npm keywords; defaults to the package's own, else its name, its scope and typescript | | `--nodeEngine` | The Node.js range the package declares; defaults to the package's own, else `>=18.0.0` | | `--buildExecutor` | The executor of the build target; defaults to `@hyperfrontend/workspace:build` | | `--e2eDirectory` | Where the e2e project is created; defaults to e2e | | `--skipE2E` | Write no e2e project | | `--skipFormat` | Leave 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`](https://www.hyperfrontend.dev/docs/libraries/testing.md). ## API Reference ### Functions #### makePublishableGenerator ```typescript function makePublishableGenerator(tree: Tree, options: MakePublishableGeneratorOptions): Promise ``` 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** | Name | Type | Description | | --- | --- | --- | | `tree` | `Tree` | The tree, rooted at the workspace | | `options` | `MakePublishableGeneratorOptions` | Which project, and how it is built and tested | **Returns** `Promise`: Resolves when the project is written **Example: A package in ESM and CommonJS** ```bash npx hf generate make-publishable my-lib ``` **Example: A package with browser bundles under a chosen global** ```bash npx hf generate make-publishable my-lib --formats=esm,cjs,iife,umd --globalName=MyLib ``` **Example: Re-running on a published library changes nothing it already has** ```typescript 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 ``` #### planPublishable ```typescript function planPublishable(tree: Tree, options: MakePublishableGeneratorOptions): PublishablePlan ``` Settles the options: the project, its package, the formats and the e2e project's names. **Parameters** | Name | Type | Description | | --- | --- | --- | | `tree` | `Tree` | The tree the project lives in | | `options` | `MakePublishableGeneratorOptions` | The 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** ```typescript 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 #### MakePublishableGeneratorOptions What the `make-publishable` generator takes. **Properties** | Name | Type | Description | | --- | --- | --- | | `project` | `string` | The project made publishable | | `formats?` | `string[]` | The bundle formats the package builds; `esm` and `cjs` when unset | | `globalName?` | `string` | The global an `iife` or `umd` bundle registers under; derived from the package name when unset | | `bundleEntry?` | `string` | The 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?` | `string` | The Node.js range the package declares; its own, else `>=18.0.0`, when unset | | `buildExecutor?` | `string` | The executor of the `build` target; `@hyperfrontend/workspace:build` when unset | | `e2eDirectory?` | `string` | The directory the e2e project is created under; `e2e` when unset | | `skipE2E?` | `boolean` | Skip creating the e2e project | | `skipFormat?` | `boolean` | Skip formatting the generated files | #### PublishablePlan The options settled. **Properties** | Name | Type | Description | | --- | --- | --- | | `projectName` | `string` | The project's name | | `projectRoot` | `string` | The project's directory, relative to the root | | `packageName` | `string` | The package's name | | `description` | `string` | The package's description | | `formats` | `unknown` | The bundle formats | | `globalName` | `string` | The global of the browser bundles | | `bundleEntry` | `string` | The entry of the browser bundles | | `keywords` | `string[]` | The npm keywords | | `nodeEngine` | `string` | The Node.js range chosen, or undefined to keep the package's own or inherit the root's | | `buildExecutor` | `string` | The executor of the `build` target | | `e2eProjectName` | `string` | The e2e project's name | | `e2ePackageName` | `string` | The e2e package's name | | `e2eProjectRoot` | `string` | The e2e project's directory, relative to the root | | `createE2e` | `boolean` | Whether the e2e project is created | | `republishing` | `boolean` | Whether the project already publishes, so what it has is kept | | `e2eExists` | `boolean` | Whether the e2e project already exists, so every file it has is kept | ### Types #### BundleFormat A bundle format the build writes. ```typescript type BundleFormat = "esm" | "cjs" | "iife" | "umd" ``` --- Canonical page: https://www.hyperfrontend.dev/docs/libraries/workspace/generators/make-publishable/ This file: https://www.hyperfrontend.dev/docs/libraries/workspace/generators/make-publishable.md Documentation index: https://www.hyperfrontend.dev/llms.txt