Skip to content

Commit b7c6f30

Browse files
committed
Adding new option and parsing
1 parent 0f451a9 commit b7c6f30

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/action/index.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,30 @@ async function main(): Promise<void> {
1717
token: getInput("token", { required: true }),
1818
registry: getInput("registry", { required: true }),
1919
package: getInput("package", { required: true }),
20-
checkVersion: getInput("check-version", { required: true }).toLowerCase() === "true",
20+
checkVersion:
21+
getInput("check-version", { required: true }).toLowerCase() === "true",
2122
tag: getInput("tag"),
2223
access: getInput("access") as Access,
2324
dryRun: getInput("dry-run").toLowerCase() === "true",
25+
greaterVersion: getInput("greater-version").toLowerCase() === "true",
2426
debug: debugHandler,
2527
};
2628

2729
// Publish to NPM
2830
let results = await npmPublish(options);
2931

3032
if (results.type === "none") {
31-
console.log(`\n📦 ${results.package} v${results.version} is already published to NPM`);
32-
}
33-
else if (results.dryRun) {
34-
console.log(`\n📦 ${results.package} v${results.version} was NOT actually published to NPM (dry run)`);
35-
}
36-
else {
37-
console.log(`\n📦 Successfully published ${results.package} v${results.version} to NPM`);
33+
console.log(
34+
`\n📦 ${results.package} v${results.version} is already published to NPM`
35+
);
36+
} else if (results.dryRun) {
37+
console.log(
38+
`\n📦 ${results.package} v${results.version} was NOT actually published to NPM (dry run)`
39+
);
40+
} else {
41+
console.log(
42+
`\n📦 Successfully published ${results.package} v${results.version} to NPM`
43+
);
3844
}
3945

4046
// Set the GitHub Actions output variables
@@ -44,8 +50,7 @@ async function main(): Promise<void> {
4450
setOutput("tag", results.tag);
4551
setOutput("access", results.access);
4652
setOutput("dry-run", results.dryRun);
47-
}
48-
catch (error) {
53+
} catch (error) {
4954
errorHandler(error as Error);
5055
}
5156
}

src/normalize-options.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface NormalizedOptions {
1313
access?: Access;
1414
dryRun: boolean;
1515
checkVersion: boolean;
16+
greaterVersion: boolean;
1617
quiet: boolean;
1718
debug: Debug;
1819
}
@@ -22,7 +23,10 @@ export interface NormalizedOptions {
2223
* @internal
2324
*/
2425
export function normalizeOptions(options: Options): NormalizedOptions {
25-
let registryURL = typeof options.registry === "string" ? new URL(options.registry) : options.registry;
26+
let registryURL =
27+
typeof options.registry === "string"
28+
? new URL(options.registry)
29+
: options.registry;
2630

2731
return {
2832
token: options.token || "",
@@ -31,7 +35,12 @@ export function normalizeOptions(options: Options): NormalizedOptions {
3135
tag: options.tag || "latest",
3236
access: options.access,
3337
dryRun: options.dryRun || false,
34-
checkVersion: options.checkVersion === undefined ? true : Boolean(options.checkVersion),
38+
checkVersion:
39+
options.checkVersion === undefined ? true : Boolean(options.checkVersion),
40+
greaterVersion:
41+
options.greaterVersion === undefined
42+
? false
43+
: Boolean(options.greaterVersion),
3544
quiet: options.quiet || false,
3645
debug: options.debug || (() => undefined),
3746
};

src/options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ export interface Options {
6464
*/
6565
quiet?: boolean;
6666

67+
/**
68+
* Only publish the package if the version number in package.json
69+
* is greater than the latest on NPM.
70+
*
71+
* Defaults to `false`
72+
*/
73+
greaterVersion?: boolean;
74+
6775
/**
6876
* A function to call to log debug messages.
6977
*

0 commit comments

Comments
 (0)