From 1108ebf0c6fd5dd1fc83713b792ed76738907169 Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 4 Sep 2024 17:58:34 +0400 Subject: [PATCH] fix(release): support forwarding the --access flag to npm publish (#27765) --- docs/generated/cli/release.md | 46 +++++++++++++++++++ .../js/executors/release-publish.json | 5 ++ .../packages/nx/documents/release.md | 46 +++++++++++++++++++ .../release-publish/release-publish.impl.ts | 4 ++ .../src/executors/release-publish/schema.d.ts | 1 + .../src/executors/release-publish/schema.json | 5 ++ .../command-line/release/command-object.ts | 19 ++++---- .../nx/src/command-line/release/publish.ts | 3 ++ 8 files changed, 121 insertions(+), 8 deletions(-) diff --git a/docs/generated/cli/release.md b/docs/generated/cli/release.md index beef77cf2d865..0418c82a61d32 100644 --- a/docs/generated/cli/release.md +++ b/docs/generated/cli/release.md @@ -112,6 +112,7 @@ nx release publish | Option | Type | Description | | --------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `--access` | `public`, `restricted` | Overrides the access level of the published package. Unscoped packages cannot be set to restricted. See the npm publish documentation for more information. | | `--all` | boolean | [deprecated] `run-many` runs all targets on all projects in the workspace if no projects are provided. This option is no longer required. (Default: `true`) | | `--exclude` | string | Exclude certain projects from being processed | | `--excludeTaskDependencies` | boolean | Skips running dependent tasks first (Default: `false`) | @@ -130,3 +131,48 @@ nx release publish | `--tag` | string | The distribution tag to apply to the published package | | `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces) | | `--version` | boolean | Show version number | + +### plan + +Create a version plan file to specify the desired semver bump for one or more projects or groups, as well as the relevant changelog entry + +```shell +nx release plan [bump] +``` + +## Options + +| Option | Type | Description | +| --------------- | --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| `--base` | string | Base of the current branch (usually main) | +| `--bump` | `major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, `prerelease` | Semver keyword to use for the selected release group. | +| `--exclude` | string | Exclude certain projects from being processed | +| `--files` | string | Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces | +| `--head` | string | Latest commit of the current branch (usually HEAD) | +| `--help` | boolean | Show help | +| `--message` | string | Custom message to use for the changelog entry | +| `--onlyTouched` | boolean | Only include projects that have been affected by the current changes (Default: `true`) | +| `--uncommitted` | boolean | Uncommitted changes | +| `--untracked` | boolean | Untracked changes | +| `--version` | boolean | Show version number | + +### plan:check + +Ensure that all touched projects have an applicable version plan created for them + +```shell +nx release plan:check +``` + +## Options + +| Option | Type | Description | +| --------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| `--base` | string | Base of the current branch (usually main) | +| `--exclude` | string | Exclude certain projects from being processed | +| `--files` | string | Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces | +| `--head` | string | Latest commit of the current branch (usually HEAD) | +| `--help` | boolean | Show help | +| `--uncommitted` | boolean | Uncommitted changes | +| `--untracked` | boolean | Untracked changes | +| `--version` | boolean | Show version number | diff --git a/docs/generated/packages/js/executors/release-publish.json b/docs/generated/packages/js/executors/release-publish.json index b6a36f4f33aa1..61e58693da889 100644 --- a/docs/generated/packages/js/executors/release-publish.json +++ b/docs/generated/packages/js/executors/release-publish.json @@ -20,6 +20,11 @@ "type": "string", "description": "The distribution tag to apply to the published package." }, + "access": { + "type": "string", + "enum": ["public", "restricted"], + "description": "Overrides the access level of the published package. Unscoped packages cannot be set to restricted. See the npm publish documentation for more information." + }, "dryRun": { "type": "boolean", "description": "Whether to run the command without actually publishing the package to the registry." diff --git a/docs/generated/packages/nx/documents/release.md b/docs/generated/packages/nx/documents/release.md index beef77cf2d865..0418c82a61d32 100644 --- a/docs/generated/packages/nx/documents/release.md +++ b/docs/generated/packages/nx/documents/release.md @@ -112,6 +112,7 @@ nx release publish | Option | Type | Description | | --------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `--access` | `public`, `restricted` | Overrides the access level of the published package. Unscoped packages cannot be set to restricted. See the npm publish documentation for more information. | | `--all` | boolean | [deprecated] `run-many` runs all targets on all projects in the workspace if no projects are provided. This option is no longer required. (Default: `true`) | | `--exclude` | string | Exclude certain projects from being processed | | `--excludeTaskDependencies` | boolean | Skips running dependent tasks first (Default: `false`) | @@ -130,3 +131,48 @@ nx release publish | `--tag` | string | The distribution tag to apply to the published package | | `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces) | | `--version` | boolean | Show version number | + +### plan + +Create a version plan file to specify the desired semver bump for one or more projects or groups, as well as the relevant changelog entry + +```shell +nx release plan [bump] +``` + +## Options + +| Option | Type | Description | +| --------------- | --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| `--base` | string | Base of the current branch (usually main) | +| `--bump` | `major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, `prerelease` | Semver keyword to use for the selected release group. | +| `--exclude` | string | Exclude certain projects from being processed | +| `--files` | string | Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces | +| `--head` | string | Latest commit of the current branch (usually HEAD) | +| `--help` | boolean | Show help | +| `--message` | string | Custom message to use for the changelog entry | +| `--onlyTouched` | boolean | Only include projects that have been affected by the current changes (Default: `true`) | +| `--uncommitted` | boolean | Uncommitted changes | +| `--untracked` | boolean | Untracked changes | +| `--version` | boolean | Show version number | + +### plan:check + +Ensure that all touched projects have an applicable version plan created for them + +```shell +nx release plan:check +``` + +## Options + +| Option | Type | Description | +| --------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| `--base` | string | Base of the current branch (usually main) | +| `--exclude` | string | Exclude certain projects from being processed | +| `--files` | string | Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces | +| `--head` | string | Latest commit of the current branch (usually HEAD) | +| `--help` | boolean | Show help | +| `--uncommitted` | boolean | Uncommitted changes | +| `--untracked` | boolean | Untracked changes | +| `--version` | boolean | Show version number | diff --git a/packages/js/src/executors/release-publish/release-publish.impl.ts b/packages/js/src/executors/release-publish/release-publish.impl.ts index 91c3b08b38109..476d009448e3e 100644 --- a/packages/js/src/executors/release-publish/release-publish.impl.ts +++ b/packages/js/src/executors/release-publish/release-publish.impl.ts @@ -219,6 +219,10 @@ export default async function runExecutor( npmPublishCommandSegments.push(`--otp=${options.otp}`); } + if (options.access) { + npmPublishCommandSegments.push(`--access=${options.access}`); + } + if (isDryRun) { npmPublishCommandSegments.push(`--dry-run`); } diff --git a/packages/js/src/executors/release-publish/schema.d.ts b/packages/js/src/executors/release-publish/schema.d.ts index 07870ebde676b..ff7f80307a489 100644 --- a/packages/js/src/executors/release-publish/schema.d.ts +++ b/packages/js/src/executors/release-publish/schema.d.ts @@ -4,5 +4,6 @@ export interface PublishExecutorSchema { tag?: string; otp?: number; dryRun?: boolean; + access?: 'public' | 'restricted'; firstRelease?: boolean; } diff --git a/packages/js/src/executors/release-publish/schema.json b/packages/js/src/executors/release-publish/schema.json index 36b77bbd8f787..ec6ccc253638e 100644 --- a/packages/js/src/executors/release-publish/schema.json +++ b/packages/js/src/executors/release-publish/schema.json @@ -17,6 +17,11 @@ "type": "string", "description": "The distribution tag to apply to the published package." }, + "access": { + "type": "string", + "enum": ["public", "restricted"], + "description": "Overrides the access level of the published package. Unscoped packages cannot be set to restricted. See the npm publish documentation for more information." + }, "dryRun": { "type": "boolean", "description": "Whether to run the command without actually publishing the package to the registry." diff --git a/packages/nx/src/command-line/release/command-object.ts b/packages/nx/src/command-line/release/command-object.ts index 95511188cf4b7..c26476efaa5e5 100644 --- a/packages/nx/src/command-line/release/command-object.ts +++ b/packages/nx/src/command-line/release/command-object.ts @@ -64,6 +64,7 @@ export type PublishOptions = NxReleaseArgs & Partial & { outputStyle?: OutputStyle } & FirstReleaseArgs & { registry?: string; tag?: string; + access?: string; otp?: number; }; @@ -328,6 +329,12 @@ const publishCommand: CommandModule = { type: 'string', description: 'The distribution tag to apply to the published package', }) + .option('access', { + type: 'string', + choices: ['public', 'restricted'], + description: + 'Overrides the access level of the published package. Unscoped packages cannot be set to restricted. See the npm publish documentation for more information.', + }) .option('otp', { type: 'number', description: @@ -349,10 +356,8 @@ const publishCommand: CommandModule = { const planCommand: CommandModule = { command: 'plan [bump]', aliases: ['pl'], - // TODO: Remove this when docs are added - // Create a plan to pick a new version and generate a changelog entry. - // Hidden for now until the feature is more stable - describe: false, + describe: + 'Create a version plan file to specify the desired semver bump for one or more projects or groups, as well as the relevant changelog entry', builder: (yargs) => withAffectedOptions(yargs) .positional('bump', { @@ -392,10 +397,8 @@ const planCommand: CommandModule = { const planCheckCommand: CommandModule = { command: 'plan:check', - // TODO: Remove this when docs are added - // Create a plan to pick a new version and generate a changelog entry. - // Hidden for now until the feature is more stable - describe: false, + describe: + 'Ensure that all touched projects have an applicable version plan created for them', builder: (yargs) => withAffectedOptions(yargs), handler: async (args) => { const release = await import('./plan-check'); diff --git a/packages/nx/src/command-line/release/publish.ts b/packages/nx/src/command-line/release/publish.ts index e246d16a174f8..d8f6890730705 100644 --- a/packages/nx/src/command-line/release/publish.ts +++ b/packages/nx/src/command-line/release/publish.ts @@ -174,6 +174,9 @@ async function runPublishOnProjects( if (args.otp) { overrides.otp = args.otp; } + if (args.access) { + overrides.access = args.access; + } if (args.dryRun) { overrides.dryRun = args.dryRun; /**