Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target option #69

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ You can set any or all of the following input parameters:
|`package` |string |./package.json |The path of your package.json file
|`tag` |string |"latest" |The tag to publish to. This allows people to install the package using `npm install <package-name>@<tag>`.
|`access` |string |"public" for non-scoped packages. "restricted" for scoped packages.|Determines whether the published package should be publicly visible, or restricted to members of your NPM organization.
|`target` |string |"" |The package to publish (the first argument to npm publish).
|`dry-run` |boolean |false |Run NPM publish with the `--dry-run` flag to prevent publication
|`check-version` |boolean |true |Only publish to NPM if the version number in `package.json` differs from the latest on NPM
|`greater-version-only`|boolean |false |Only publish to NPM if the version number in `package.json` is greater than the latest on NPM |
@@ -135,6 +136,7 @@ As shown in the example above, you can pass options to the `npmPublish()` functi
| `tag` | string | "latest" | The tag to publish to. This allows people to install the package using `npm install <package-name>@<tag>`. |
| `access` | string | "public" for non-scoped packages. "restricted" for scoped packages. | Determines whether the published package should be publicly visible, or restricted to members of your NPM organization. |
| `dryRun` | boolean | false | Run NPM publish with the `--dry-run` flag to prevent publication |
| `target` | string | "" | The package to publish (the first argument to npm publish) |
| `checkVersion` | boolean | true | Only publish to NPM if the version number in `package.json` differs from the latest on NPM |
| `greaterVersionOnly` | boolean | false | Only publish to NPM if the version number in `package.json` is greater then the latest on NPM |
| `quiet` | boolean | false | Suppress console output from NPM and npm-publish |
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -35,6 +35,11 @@ inputs:
This only applies to scoped packages.
required: false

target:
description: The package to publish (the first argument to npm publish).
required: false
default: ""

dry-run:
description: If true, run with the --dry-run flag
required: false
5 changes: 5 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/action/index.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ async function main(): Promise<void> {
getInput("check-version", { required: true }).toLowerCase() === "true",
tag: getInput("tag"),
access: getInput("access") as Access,
target: getInput("target"),
dryRun: getInput("dry-run").toLowerCase() === "true",
greaterVersionOnly: getInput("greater-version-only").toLowerCase() === "true",
debug: debugHandler,
1 change: 1 addition & 0 deletions src/cli/parse-args.ts
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ export function parseArgs(argv: string[]): ParsedArgs {
package: args.package as string,
tag: args.tag as string,
access: args.access as Access,
target: args.target as string,
dryRun: args["dry-run"] as boolean,
debug: args.debug ? console.debug : undefined,
quiet: args.quiet as boolean,
2 changes: 2 additions & 0 deletions src/normalize-options.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ export interface NormalizedOptions {
package: string;
tag: string;
access?: Access;
target: string;
dryRun: boolean;
checkVersion: boolean;
greaterVersionOnly: boolean;
@@ -34,6 +35,7 @@ export function normalizeOptions(options: Options): NormalizedOptions {
package: options.package || "package.json",
tag: options.tag || "latest",
access: options.access,
target: options.target || "",
dryRun: options.dryRun || false,
checkVersion:
options.checkVersion === undefined ? true : Boolean(options.checkVersion),
4 changes: 4 additions & 0 deletions src/npm.ts
Original file line number Diff line number Diff line change
@@ -95,6 +95,10 @@ export const npm = {
command.push("--dry-run");
}

if (options.target) {
command.push(options.target);
}

// Run "npm publish" in the package.json directory
let cwd = resolve(dirname(options.package));

8 changes: 8 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -40,6 +40,14 @@ export interface Options {
*/
access?: Access;

/**
* The package to publish.
* This is the first argument to npm publish.
*
* Defaults to "" which is the default behavior of npm publish.
*/
target?: string;

/**
* If true, run npm publish with the --dry-run flag
* so that the package is not published. Used for
47 changes: 47 additions & 0 deletions test/specs/lib/success.spec.js
Original file line number Diff line number Diff line change
@@ -192,6 +192,53 @@ describe("NPM package - success tests", () => {
npm.assert.ran(2);
});

it("should pass target option as argument to npm publish", async () => {
files.create([
{ path: "workspace/package.json", contents: { name: "my-lib", version: "2.0.0" }},
]);

npm.mock({
args: ["config", "get", "userconfig"],
stdout: `${paths.npmrc}${EOL}`,
});

npm.mock({
args: ["view", "my-lib", "version"],
stdout: `1.0.0${EOL}`,
});

npm.mock({
args: ["config", "get", "userconfig"],
stdout: `${paths.npmrc}${EOL}`,
});

npm.mock({
args: ["publish", "my-lib-2.0.0.tgz"],
stdout: `my-lib 2.0.0${EOL}`,
});

let results = await npmPublish({ target: "my-lib-2.0.0.tgz", quiet: true });

expect(results).to.deep.equal({
type: "major",
package: "my-lib",
registry: new URL("https://registry.npmjs.org/"),
version: "2.0.0",
oldVersion: "1.0.0",
tag: "latest",
access: "public",
dryRun: false,
});

files.assert.contents("home/.npmrc",
`//registry.npmjs.org/:_authToken=\${INPUT_TOKEN}${EOL}` +
`registry=https://registry.npmjs.org/${EOL}`
);

npm.assert.ran(4);
});


it("should use the specified NPM token to publish the package", async () => {
files.create([
{ path: "workspace/package.json", contents: { name: "my-lib", version: "1.0.0-beta.1" }},