Skip to content

Commit

Permalink
feat: add skipValidation to dart publishing (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Jul 2, 2024
1 parent 8d05c1d commit 8945067
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
22 changes: 22 additions & 0 deletions src/targets/__tests__/pubDev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('PubDev target configuration', () => {
PUBDEV_REFRESH_TOKEN: DEFAULT_OPTION_VALUE,
dartCliPath: 'dart',
packages: ['.'],
skipValidation: false,
});
});

Expand All @@ -114,13 +115,15 @@ describe('PubDev target configuration', () => {
dos: undefined,
tres: undefined,
},
skipValidation: true
});

expect(target.pubDevConfig).toStrictEqual({
PUBDEV_ACCESS_TOKEN: 'access',
PUBDEV_REFRESH_TOKEN: 'refresh',
dartCliPath: '/custom/path/dart',
packages: ['uno', 'dos', 'tres'],
skipValidation: true,
});
});
});
Expand Down Expand Up @@ -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';
Expand Down
7 changes: 7 additions & 0 deletions src/targets/pubDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -69,6 +71,7 @@ export class PubDevTarget extends BaseTarget {
? Object.keys(this.config.packages)
: ['.'],
...this.getTargetSecrets(),
skipValidation: this.config.skipValidation ?? false,
};

this.checkRequiredSoftware(config);
Expand Down Expand Up @@ -212,6 +215,10 @@ export class PubDevTarget extends BaseTarget {
}
}

if (this.pubDevConfig.skipValidation) {
args.push('--skip-validation');
}

await spawnProcess(
this.pubDevConfig.dartCliPath,
args,
Expand Down

0 comments on commit 8945067

Please sign in to comment.