From 894506753f97bb3d3b6768d3436ff93206e4d38b Mon Sep 17 00:00:00 2001 From: Ivan Dlugos <6349682+vaind@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:14:38 +0200 Subject: [PATCH] feat: add skipValidation to dart publishing (#544) --- README.md | 6 ++++-- src/targets/__tests__/pubDev.test.ts | 22 ++++++++++++++++++++++ src/targets/pubDev.ts | 7 +++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 795ddab7..951703ca 100644 --- a/README.md +++ b/README.md @@ -1157,8 +1157,10 @@ For this target to work correctly, either `dart` must be installed on the system | Option | Description | | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `dartCliPath` | **optional** Path to the Dart CLI. It must be executable by the calling process. Defaults to `dart`. | -| `packages` | **optional** List of directories to be released, relative to the root. Useful when a single repository contains multiple packages. When skipped, root directory is assumed as the only package. | +| `dartCliPath` | **optional** Path to the Dart CLI. It must be executable by the calling process. Defaults to `dart`. | +| `packages` | **optional** List of directories to be released, relative to the root. Useful when a single repository contains multiple packages. When skipped, root directory is assumed as the only package. | +| `skipValidation` | **optional** Publishes the package without going through validation steps, such as analyzer & dependency checks. This is useful in particular situations when package maintainers know why the validation fails and wish to side step the issue. For example, there may be analyzer issues due to not following the current (latest) dart SDK recommendation because the package needs to maintain the package compatibility with an old SDK version. +This option should be used with caution and only after testing and verifying the reported issue shouldn't affect the package. It is advisable to do an alpha pre-release to further reduce the chance of a potential negative impact. | **Example** diff --git a/src/targets/__tests__/pubDev.test.ts b/src/targets/__tests__/pubDev.test.ts index ed5f6810..03813e8b 100644 --- a/src/targets/__tests__/pubDev.test.ts +++ b/src/targets/__tests__/pubDev.test.ts @@ -99,6 +99,7 @@ describe('PubDev target configuration', () => { PUBDEV_REFRESH_TOKEN: DEFAULT_OPTION_VALUE, dartCliPath: 'dart', packages: ['.'], + skipValidation: false, }); }); @@ -114,6 +115,7 @@ describe('PubDev target configuration', () => { dos: undefined, tres: undefined, }, + skipValidation: true }); expect(target.pubDevConfig).toStrictEqual({ @@ -121,6 +123,7 @@ describe('PubDev target configuration', () => { PUBDEV_REFRESH_TOKEN: 'refresh', dartCliPath: '/custom/path/dart', packages: ['uno', 'dos', 'tres'], + skipValidation: true, }); }); }); @@ -390,6 +393,25 @@ dependency_overrides: ); }); + test('should call `dart` cli with skip-validation if requesteed', async () => { + const pkg = 'uno'; + const target = createPubDevTarget({ skipValidation: true }); + await target.publishPackage(TMP_DIR, pkg); + + const spawnProcessMock = spawnProcess as jest.MockedFunction< + typeof spawnProcess + >; + + expect(spawnProcessMock).toHaveBeenCalledWith( + 'dart', + ['pub', 'publish', '--force', '--skip-validation'], + { + cwd: `${TMP_DIR}/${pkg}`, + }, + { showStdout: true } + ); + }); + test('should use custom cli path if provided', async () => { const dartCliPath = '/custom/path/dart'; const pkg = 'uno'; diff --git a/src/targets/pubDev.ts b/src/targets/pubDev.ts index 8bfc6d50..d4f1a41a 100644 --- a/src/targets/pubDev.ts +++ b/src/targets/pubDev.ts @@ -24,6 +24,8 @@ export interface PubDevTargetOptions { dartCliPath: string; /** List of directories to be released. Useful when a single repository contains multiple packages. */ packages: string[]; + /** Whether to skip validation */ + skipValidation: boolean; } /** @@ -69,6 +71,7 @@ export class PubDevTarget extends BaseTarget { ? Object.keys(this.config.packages) : ['.'], ...this.getTargetSecrets(), + skipValidation: this.config.skipValidation ?? false, }; this.checkRequiredSoftware(config); @@ -212,6 +215,10 @@ export class PubDevTarget extends BaseTarget { } } + if (this.pubDevConfig.skipValidation) { + args.push('--skip-validation'); + } + await spawnProcess( this.pubDevConfig.dartCliPath, args,