Skip to content

Commit

Permalink
fix: remove unused config pubspecPath (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeshuaro committed Sep 22, 2023
1 parent fb48e9a commit ba966d4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 22 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
],
"parser": "@typescript-eslint/parser",
"parserOptions": { "project": ["tsconfig.eslint.json"] },
"plugins": ["@typescript-eslint"]
"plugins": ["@typescript-eslint"],
"rules": {
"no-unused-vars": [
"error",
{ "vars": "all", "args": "all", "ignoreRestSiblings": false }
]
}
}
13 changes: 4 additions & 9 deletions src/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ import { readFileSync, writeFileSync } from 'fs';
import { PrepareContext } from 'semantic-release';
import { parse } from 'yaml';
import { Pubspec } from './schemas.js';
import { PluginConfig } from './types.js';
import { getConfig } from './utils.js';

export const prepare = async (
pluginConfig: PluginConfig,
{ nextRelease }: PrepareContext
) => {
const { pubspecPath } = getConfig(pluginConfig);
const PUBSPEC_PATH = 'pubspec.yaml';

const data = readFileSync(pubspecPath, 'utf-8');
export const prepare = async ({ nextRelease }: PrepareContext) => {
const data = readFileSync(PUBSPEC_PATH, 'utf-8');
const pubspec = Pubspec.parse(parse(data));

const newData = data.replace(
new RegExp(`version:[ \t]+${pubspec.version}`),
`version: ${nextRelease.version}`
);

writeFileSync(pubspecPath, newData);
writeFileSync(PUBSPEC_PATH, newData);
};
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export type PluginConfig = {
cli: 'dart' | 'flutter';
pubspecPath: string;
};
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { ServiceAccount } from './schemas.js';
import { PluginConfig } from './types.js';

const DEFAULT_CONFIG: PluginConfig = {
cli: 'dart',
pubspecPath: 'pubspec.yaml'
cli: 'dart'
};

const PUB_DEV_AUDIENCE = 'https://pub.dev';
Expand Down
11 changes: 4 additions & 7 deletions tests/prepare.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { readFileSync, writeFileSync } from 'fs';
import { codeBlock } from 'common-tags';
import { readFileSync, writeFileSync } from 'fs';
import { NextRelease, PrepareContext } from 'semantic-release';
import { afterEach, describe, expect, test, vi } from 'vitest';
import { mock } from 'vitest-mock-extended';
import { PluginConfig, prepare } from '../src/index.js';
import { prepare } from '../src/index.js';

vi.mock('fs');

describe('prepare', () => {
const cli = 'dart';
const newVersion = '1.2.3';
const pubspecPath = 'pubspecPath';
const pubspecPath = 'pubspec.yaml';
const oldPubspec = codeBlock`
name: pub_package
version: 1.2.0
Expand All @@ -32,8 +31,6 @@ describe('prepare', () => {
cupertino_icons: 1.0.6
`;

const config: PluginConfig = { cli, pubspecPath };

afterEach(() => {
vi.restoreAllMocks();
});
Expand All @@ -47,7 +44,7 @@ describe('prepare', () => {

vi.mocked(readFileSync).mockReturnValue(oldPubspec);

await prepare(config, context);
await prepare(context);

expect(readFileSync).toHaveBeenNthCalledWith(1, pubspecPath, 'utf-8');
expect(writeFileSync).toHaveBeenNthCalledWith(1, pubspecPath, newPubspec);
Expand Down
3 changes: 1 addition & 2 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ vi.mock('google-auth-library');

describe('getConfig', () => {
const config: PluginConfig = {
cli: 'flutter',
pubspecPath: 'a/pubspec.yaml'
cli: 'flutter'
};

test('success', () => {
Expand Down

0 comments on commit ba966d4

Please sign in to comment.