generated from JS-DevTools/template-node-typescript
-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathnpm-publish.ts
40 lines (37 loc) · 1.29 KB
/
npm-publish.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { readManifest } from "./read-manifest.js";
import { normalizeOptions } from "./normalize-options.js";
import { useNpmEnvironment } from "./npm/index.js";
import { compareAndPublish } from "./compare-and-publish/index.js";
import { formatPublishResult } from "./format-publish-result.js";
import type { Options } from "./options.js";
import type { Results } from "./results.js";
/**
* Publishes a package to NPM, if its version has changed.
*
* @param options Publish options.
* @returns Release metadata.
*/
export async function npmPublish(options: Options): Promise<Results> {
const manifest = await readManifest(options.package);
const normalizedOptions = normalizeOptions(manifest, options);
const publishResult = await useNpmEnvironment(
manifest,
normalizedOptions,
compareAndPublish
);
normalizedOptions.logger?.info?.(
formatPublishResult(manifest, normalizedOptions, publishResult)
);
return {
id: publishResult.id,
type: publishResult.type,
oldVersion: publishResult.oldVersion,
name: manifest.name,
version: manifest.version,
registry: normalizedOptions.registry,
tag: normalizedOptions.tag.value,
access: normalizedOptions.access.value,
strategy: normalizedOptions.strategy.value,
dryRun: normalizedOptions.dryRun.value,
};
}