semantic-release-pub 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  [![npm](https://img.shields.io/npm/v/semantic-release-pub)](https://www.npmjs.com/package/semantic-release-pub)
4
4
  [![License](https://img.shields.io/github/license/zeshuaro/semantic-release-pub)](https://github.com/zeshuaro/semantic-release-pub/blob/main/LICENSE)
5
5
  [![GitHub Actions](https://github.com/zeshuaro/semantic-release-pub/actions/workflows/github-actions.yml/badge.svg)](https://github.com/zeshuaro/semantic-release-pub/actions/workflows/github-actions.yml)
6
- [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=semantic-release-pub&metric=coverage)](https://sonarcloud.io/summary/new_code?id=semantic-release-pub)
7
- [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=semantic-release-pub&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=semantic-release-pub)
6
+ [![codecov](https://codecov.io/github/zeshuaro/semantic-release-pub/graph/badge.svg?token=P40ZNZNXG2)](https://codecov.io/github/zeshuaro/semantic-release-pub)
7
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/2694cc48a8dd416798eaab232948090a)](https://app.codacy.com/gh/zeshuaro/semantic-release-pub/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
8
8
  [![Code Style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
9
9
 
10
10
  [![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/zeshuaro)
@@ -92,10 +92,11 @@ The following instructions are referenced from the [documentation](https://dart.
92
92
 
93
93
  ### Options
94
94
 
95
- | Option | Description | Default |
96
- | ------------ | -------------------------------------------------------------------------------------------------------------------- | ------- |
97
- | `cli` | The `dart` or `flutter` CLI to use to publish the package to the registry. | `dart` |
98
- | `publishPub` | Whether to publish the package to the registry. If set to `false`, the `pubspec.yaml` version will still be updated. | `true` |
95
+ | Option | Description | Default |
96
+ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
97
+ | `cli` | The `dart` or `flutter` CLI to use to publish the package to the registry. | `dart` |
98
+ | `publishPub` | Whether to publish the package to the registry. If set to `false`, the `pubspec.yaml` version will still be updated. | `true` |
99
+ | `updateBuildNumber` | Whether to write build number for every newly bumped version in `pubspec.yaml`. Note that the build number will always be increased by one. Learn more on [Flutter docs](https://docs.flutter.dev/deployment/android#updating-the-apps-version-number). | `false` |
99
100
 
100
101
  ### Examples
101
102
 
@@ -115,3 +116,5 @@ The following instructions are referenced from the [documentation](https://dart.
115
116
  ]
116
117
  }
117
118
  ```
119
+
120
+ See [here](https://github.com/zeshuaro/firestore_cache/pull/162) for a sample pull request utilising this plugin and `semantic-release` to publish a Flutter package.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { verifyConditions } from './verifyConditions.js';
2
- export { PluginConfig } from './types.js';
3
- export { prepare } from './prepare.js';
4
- export { publish } from './publish.js';
1
+ export { verifyConditions } from "./verifyConditions.js";
2
+ export { PluginConfig } from "./types.js";
3
+ export { prepare } from "./prepare.js";
4
+ export { publish } from "./publish.js";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { verifyConditions } from './verifyConditions.js';
2
- export { prepare } from './prepare.js';
3
- export { publish } from './publish.js';
1
+ export { verifyConditions } from "./verifyConditions.js";
2
+ export { prepare } from "./prepare.js";
3
+ export { publish } from "./publish.js";
package/dist/prepare.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { PrepareContext } from 'semantic-release';
2
- import { PluginConfig } from './types.js';
3
- export declare const prepare: (_pluginConfig: PluginConfig, { nextRelease: { version }, logger }: PrepareContext) => Promise<void>;
1
+ import { PrepareContext } from "semantic-release";
2
+ import { PluginConfig } from "./types.js";
3
+ export declare const prepare: (pluginConfig: PluginConfig, { nextRelease: { version }, logger }: PrepareContext) => Promise<void>;
package/dist/prepare.js CHANGED
@@ -1,12 +1,24 @@
1
- import { readFileSync, writeFileSync } from 'fs';
2
- import { parse } from 'yaml';
3
- import { Pubspec } from './schemas.js';
4
- const PUBSPEC_PATH = 'pubspec.yaml';
5
- export const prepare = async (_pluginConfig, { nextRelease: { version }, logger }) => {
6
- const data = readFileSync(PUBSPEC_PATH, 'utf-8');
1
+ import { readFileSync, writeFileSync } from "fs";
2
+ import { parse } from "yaml";
3
+ import SemanticReleaseError from "@semantic-release/error";
4
+ import { Pubspec } from "./schemas.js";
5
+ import { getConfig } from "./utils.js";
6
+ const PUBSPEC_PATH = "pubspec.yaml";
7
+ export const prepare = async (pluginConfig, { nextRelease: { version }, logger }) => {
8
+ const { updateBuildNumber } = getConfig(pluginConfig);
9
+ const data = readFileSync(PUBSPEC_PATH, "utf-8");
7
10
  const pubspec = Pubspec.parse(parse(data));
8
- const pubspecVersionEscaped = pubspec.version.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
9
- const newData = data.replace(new RegExp(`version:[ \t]+${pubspecVersionEscaped}`), `version: ${version}`);
10
- logger.log(`Writing version ${version} to ${PUBSPEC_PATH}`);
11
+ const pubspecVersionEscaped = pubspec.version.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
12
+ let nextVersion = version;
13
+ if (updateBuildNumber) {
14
+ const parts = pubspec.version.split("+");
15
+ const buildNumber = parts.length > 1 ? Number(parts[1]) : 0;
16
+ if (isNaN(buildNumber)) {
17
+ throw new SemanticReleaseError(`Invalid build number: ${buildNumber} in ${pubspec.version}`);
18
+ }
19
+ nextVersion = `${version}+${buildNumber + 1}`;
20
+ }
21
+ const newData = data.replace(new RegExp(`version:[ \t]+${pubspecVersionEscaped}`), `version: ${nextVersion}`);
22
+ logger.log(`Writing version ${nextVersion} to ${PUBSPEC_PATH}`);
11
23
  writeFileSync(PUBSPEC_PATH, newData);
12
24
  };
package/dist/publish.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { PublishContext } from 'semantic-release';
2
- import { PluginConfig } from './types.js';
1
+ import { PublishContext } from "semantic-release";
2
+ import { PluginConfig } from "./types.js";
3
3
  export declare const publish: (pluginConfig: PluginConfig, { nextRelease: { version }, logger }: PublishContext) => Promise<void>;
package/dist/publish.js CHANGED
@@ -1,6 +1,6 @@
1
- import { execa } from 'execa';
2
- import { getConfig, getGoogleIdentityToken } from './utils.js';
3
- const SEMANTIC_RELEASE_PUB_TOKEN = 'SEMANTIC_RELEASE_PUB_TOKEN';
1
+ import { execa } from "execa";
2
+ import { getConfig, getGoogleIdentityToken } from "./utils.js";
3
+ const SEMANTIC_RELEASE_PUB_TOKEN = "SEMANTIC_RELEASE_PUB_TOKEN";
4
4
  export const publish = async (pluginConfig, { nextRelease: { version }, logger }) => {
5
5
  const { cli, publishPub } = getConfig(pluginConfig);
6
6
  if (!publishPub) {
@@ -11,16 +11,16 @@ export const publish = async (pluginConfig, { nextRelease: { version }, logger }
11
11
  const idToken = await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
12
12
  await setPubToken(cli, idToken);
13
13
  logger.log(`Publishing version ${version} to pub.dev`);
14
- await execa(cli, ['pub', 'publish', '--force']);
15
- logger.log('Published package');
14
+ await execa(cli, ["pub", "publish", "--force"]);
15
+ logger.log("Published package");
16
16
  };
17
17
  const setPubToken = async (cli, idToken) => {
18
18
  process.env[SEMANTIC_RELEASE_PUB_TOKEN] = idToken;
19
19
  await execa(cli, [
20
- 'pub',
21
- 'token',
22
- 'add',
23
- 'https://pub.dev',
24
- `--env-var=${SEMANTIC_RELEASE_PUB_TOKEN}`
20
+ "pub",
21
+ "token",
22
+ "add",
23
+ "https://pub.dev",
24
+ `--env-var=${SEMANTIC_RELEASE_PUB_TOKEN}`,
25
25
  ]);
26
26
  };
package/dist/schemas.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
  export declare const ServiceAccount: z.ZodObject<{
3
3
  client_email: z.ZodString;
4
4
  private_key: z.ZodString;
package/dist/schemas.js CHANGED
@@ -1,6 +1,6 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
  export const ServiceAccount = z.object({
3
3
  client_email: z.string(),
4
- private_key: z.string()
4
+ private_key: z.string(),
5
5
  });
6
6
  export const Pubspec = z.object({ version: z.string() });
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type PluginConfig = {
2
- cli: 'dart' | 'flutter';
2
+ cli: "dart" | "flutter";
3
3
  publishPub: boolean;
4
+ updateBuildNumber: boolean;
4
5
  };
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { PluginConfig } from './types.js';
1
+ import { PluginConfig } from "./types.js";
2
2
  export declare const getConfig: (config: PluginConfig) => PluginConfig;
3
3
  export declare const getGoogleIdentityToken: (serviceAccountStr: string) => Promise<string>;
package/dist/utils.js CHANGED
@@ -1,11 +1,12 @@
1
- import SemanticReleaseError from '@semantic-release/error';
2
- import { JWT } from 'google-auth-library';
3
- import { ServiceAccount } from './schemas.js';
1
+ import SemanticReleaseError from "@semantic-release/error";
2
+ import { JWT } from "google-auth-library";
3
+ import { ServiceAccount } from "./schemas.js";
4
4
  const DEFAULT_CONFIG = {
5
- cli: 'dart',
6
- publishPub: true
5
+ cli: "dart",
6
+ publishPub: true,
7
+ updateBuildNumber: false,
7
8
  };
8
- const PUB_DEV_AUDIENCE = 'https://pub.dev';
9
+ const PUB_DEV_AUDIENCE = "https://pub.dev";
9
10
  export const getConfig = (config) => {
10
11
  return { ...DEFAULT_CONFIG, ...config };
11
12
  };
@@ -14,7 +15,7 @@ export const getGoogleIdentityToken = async (serviceAccountStr) => {
14
15
  const jwtClient = new JWT(serviceAccountJson.client_email, undefined, serviceAccountJson.private_key, PUB_DEV_AUDIENCE);
15
16
  const creds = await jwtClient.authorize();
16
17
  if (!creds.id_token) {
17
- throw new SemanticReleaseError('Failed to retrieve identity token from Google');
18
+ throw new SemanticReleaseError("Failed to retrieve identity token from Google");
18
19
  }
19
20
  return creds.id_token;
20
21
  };
@@ -1,3 +1,3 @@
1
- import { VerifyConditionsContext } from 'semantic-release';
2
- import { PluginConfig } from './types.js';
1
+ import { VerifyConditionsContext } from "semantic-release";
2
+ import { PluginConfig } from "./types.js";
3
3
  export declare const verifyConditions: (pluginConfig: PluginConfig, { logger }: VerifyConditionsContext) => Promise<void>;
@@ -1,12 +1,12 @@
1
- import SemanticReleaseError from '@semantic-release/error';
2
- import { execa } from 'execa';
3
- import { getConfig, getGoogleIdentityToken } from './utils.js';
1
+ import SemanticReleaseError from "@semantic-release/error";
2
+ import { execa } from "execa";
3
+ import { getConfig, getGoogleIdentityToken } from "./utils.js";
4
4
  export const verifyConditions = async (pluginConfig, { logger }) => {
5
5
  const { cli, publishPub } = getConfig(pluginConfig);
6
6
  const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
7
7
  if (publishPub) {
8
8
  if (!GOOGLE_SERVICE_ACCOUNT_KEY) {
9
- throw new SemanticReleaseError('Environment variable not found: GOOGLE_SERVICE_ACCOUNT_KEY');
9
+ throw new SemanticReleaseError("Environment variable not found: GOOGLE_SERVICE_ACCOUNT_KEY");
10
10
  }
11
11
  await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
12
12
  await verifyCommand(cli);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semantic-release-pub",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "semantic-release plugin to publish a Dart or Flutter package",
5
5
  "main": "dist/index.js",
6
6
  "author": "zeshuaro@gmail.com",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@semantic-release/error": "^4.0.0",
36
36
  "execa": "^8.0.1",
37
- "google-auth-library": "^9.3.0",
37
+ "google-auth-library": "^9.4.1",
38
38
  "yaml": "^2.3.4",
39
39
  "zod": "^3.22.4"
40
40
  },
@@ -45,21 +45,22 @@
45
45
  "@types/semantic-release": "20.0.6",
46
46
  "@types/semantic-release__error": "3.0.3",
47
47
  "@types/signale": "1.4.7",
48
- "@typescript-eslint/eslint-plugin": "6.13.1",
49
- "@typescript-eslint/parser": "6.13.1",
50
- "@vitest/coverage-v8": "0.34.6",
48
+ "@typescript-eslint/eslint-plugin": "6.17.0",
49
+ "@typescript-eslint/parser": "6.17.0",
50
+ "@vitest/coverage-v8": "1.1.1",
51
51
  "common-tags": "1.8.2",
52
52
  "conventional-changelog-conventionalcommits": "7.0.2",
53
- "eslint": "8.54.0",
53
+ "eslint": "8.56.0",
54
+ "eslint-config-prettier": "^9.1.0",
54
55
  "eslint-config-semistandard": "17.0.0",
55
56
  "eslint-config-standard": "17.1.0",
56
- "eslint-plugin-import": "2.29.0",
57
- "eslint-plugin-n": "16.3.1",
57
+ "eslint-plugin-import": "2.29.1",
58
+ "eslint-plugin-n": "16.6.1",
58
59
  "eslint-plugin-promise": "6.1.1",
59
- "prettier": "3.1.0",
60
- "semantic-release": "22.0.8",
61
- "typescript": "5.3.2",
62
- "vitest": "0.34.6",
60
+ "prettier": "3.1.1",
61
+ "semantic-release": "22.0.12",
62
+ "typescript": "5.3.3",
63
+ "vitest": "1.1.1",
63
64
  "vitest-mock-extended": "1.3.1"
64
65
  }
65
66
  }