A much better npm publish
, that:
- performs automatic semantic release versioning, like
semantic-release
- has zero dependencies - uses your built-in
git
,npm
- integrates with your npm scripts like
build
,test
andlint
- checks your package.json for invalid types
- includes an API (including TypeScript support)
- supports a
--dry-run
option to give it a test drive
If "checks" fail or "runs script" has nonzero error code, pub-time
exits and the publish
is cancelled.
-
checks you are on local
main
branch -
checks you are level with remote
origin/main
-
checks various key fields in
package.json
-
checks for a
README.md
-
checks that
npm audit
shows no vulnerabilities -
runs script
npm run lint
if it exists (with default setting) -
calculates the next version by looking at both:
- the latest version (if any) published to
npm
- commits since the previous git tag
v#.#.#
- the latest version (if any) published to
-
final warning, pausing for user input and showing some common final todos that can't be automatically checked
-
updates the version in package.json
-
checks that the user's
npm
andnode
versions match the user'sengines
inpackage.json
-
deletes and reinstalls npm dependencies
-
runs script
npm run build
(with default setting) -
runs script
npm run test
(with default setting) -
runs script
npm run check-build
if it exists (with default setting) -
(!) dry run stops doing anything here, but instead logs out the commands it would run
-
releases
- commits any changes
- creates a new
v#.#.#
git tag - pushes up commits and tag
npm publish
🎉
I created this library because I was unhappy with the alternatives (especially the install size):
package | install size |
---|---|
np |
|
release-it |
|
semantic-release |
pub-time
leans into the conventions you may already use in your projects and will use your
pre-existing project specific scripts in your package.json
.
This package is available from the npm
registry.
npm install pub-time
npx pub-time
Usage: pub-time [options]
Options:
--dry-run Perform a dry run without making any changes
--force-version <version> Override the autocalculated version
--prev-hash <hash> Specify the previous hash
-h, --help display help for command
Supports JavaScript + TypeScript:
import { publish } from "pub-time";
export const publish = (config: Partial<Config>) => Promise<boolean>;
export type Config = {
/* custom log function instead of console.log */
log: (message: string) => void;
/* if true, package will not be published, git will not be updated */
dryRun: boolean;
/* if left undefined, will treat last 'v#.#.#' git tag as the last commit of the prev release
if a string, will be treated as the hash of the last commit of the prev release
to force include all commits, use the value 'all' */
prevHash?: string;
/* skips inference completely, blindly trusts the version */
forceVersion?: string;
/* custom functions used in publish process */
build: string | ((nextSemver: string) => Promise<void>);
checkBuild: string | ((nextSemver: string) => Promise<void>);
test: string | (() => Promise<void>);
lint: string | (() => Promise<void>);
};
export const DEFAULT_CONFIG: Config = {
log: console.log,
prevHash: undefined,
dryRun: false,
lint: "lint",
build: "build",
checkBuild: "check-build",
test: "test",
};
Can also be imported via require("pub-time")
.
GitHub issues / PRs welcome.
Dev environment requires:
- node >= 16.14.0
- npm >= 6.8.0
- git >= 2.11
Apache-2.0