UNPKG

@jsdevtools/npm-publish

Version:
48 lines 1.77 kB
/** * Given a package name and publish configuration, get the NPM CLI view * arguments. * * @param packageName Package name. * @param options Publish configuration. * @param retryWithTag Include a non-latest tag in the package spec for a rety * attempt. * @returns Arguments to pass to the NPM CLI. If `retryWithTag` is true, but the * publish config is using the `latest` tag, will return `undefined`. */ export function getViewArguments(packageName, options, retryWithTag = false) { const packageSpec = retryWithTag ? `${packageName}@${options.tag.value}` : packageName; return [packageSpec, "dist-tags", "versions"]; } /** * Given a publish configuration, get the NPM CLI publish arguments. * * @param packageSpec Package specification path. * @param options Publish configuration. * @returns Arguments to pass to the NPM CLI. */ export function getPublishArguments(packageSpec, options) { const { tag, access, dryRun, provenance } = options; const publishArguments = []; if (packageSpec.length > 0) { publishArguments.push(packageSpec); } if (!tag.isDefault) { publishArguments.push("--tag", tag.value); } if (!access.isDefault && access.value) { publishArguments.push("--access", access.value); } if (!provenance.isDefault && provenance.value) { publishArguments.push("--provenance"); } if (!dryRun.isDefault && dryRun.value) { // NOTE: `--force` does not override `--dry-run`, // but does bypass package existence check in npm >=11 // because we do our own existence checks separately publishArguments.push("--dry-run", "--force"); } return publishArguments; } //# sourceMappingURL=get-arguments.js.map