Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add @bfra.me/semantic-release #146

Merged
merged 13 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-frogs-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bfra.me/semantic-release": minor
---

Add the `@bfra.me/semantic-release` package.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint": "manypkg check && pnpm -r run --parallel lint",
"check-format": "prettier --check .",
"format": "prettier --write .",
"test": "pnpm -r run --parallel test",
"test": "pnpm -r run test",
"publish-changesets": "changeset publish",
"version-changesets": "changeset version"
},
Expand Down
58 changes: 58 additions & 0 deletions packages/semantic-release/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@bfra.me/semantic-release",
"description": "Semantic Release shareable configuration and plugins for bfra.me.",
"version": "0.0.0",
"author": "Marcus R. Brown <contact@bfra.me>",
"license": "MIT",
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"exports": {
".": {
"import": {
"default": "./lib/index.js",
"types": "./lib/index.d.ts"
}
},
"./package.json": "./package.json"
},
"homepage": "https://github.com/bfra-me/works/tree/main/packages/semantic-release#readme",
"repository": {
"directory": "packages/semantic-release",
"type": "git",
"url": "https://github.com/bfra-me/works.git"
},
"bugs": "https://github.com/bfra-me/works/issues",
"keywords": [
"bfra.me",
"typescript",
"semantic-release",
"config",
"shared"
],
"publishConfig": {
"access": "public",
"provenance": true
},
"files": [
"lib",
"tsconfig.json",
"!*.map"
],
"devDependencies": {
"@bfra.me/semantic-release": "workspace:*",
"@bfra.me/tsconfig": "workspace:*",
"@swc/core": "1.4.6",
"semantic-release": "23.0.2",
"tsup": "8.0.2",
"type-fest": "4.13.1",
"vitest": "1.3.1"
},
"peerDependencies": {
"semantic-release": ">=23"
},
"scripts": {
"build": "tsup-node",
"test": "pnpm build && vitest --typecheck"
}
}
49 changes: 49 additions & 0 deletions packages/semantic-release/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# @bfra.me/semantic-release

> Sharable Semantic Release configuration for bfra.me.

## Install

### NPM

```sh
npm install --save-dev @bfra.me/semantic-release semantic-release
```

### PNPM

```sh
pnpm add --save-dev @bfra.me/semantic-release semantic-release
```

### Yarn

```sh
yarn add --dev @bfra.me/semantic-release semantic-release
```

## Usage

Import the `defineConfig` utility to use in your `semantic-release` config file:

```javascript
import {defineConfig} from "@bfra.me/semantic-release"

export default defineConfig({
branches: ["main"],
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git",
],
})
```

Code editors that support TypeScript type acquisition should be able to provide type hints for the `defineConfig` function.

## License

[MIT](../../LICENSE.md)
11 changes: 11 additions & 0 deletions packages/semantic-release/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type {SemanticReleaseConfig} from './types'

/**
* Define semantic-release global config.
*
* @param config Semantic Release configuration
* @returns Semantic Release configuration
*/
export function defineConfig(config: SemanticReleaseConfig) {
return config
}
2 changes: 2 additions & 0 deletions packages/semantic-release/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './config'
export type * from './types'
30 changes: 30 additions & 0 deletions packages/semantic-release/src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {BranchSpec} from 'semantic-release'
import type {LiteralUnion} from 'type-fest'
import type {Plugin} from './plugin'

export interface CustomExtends {}

export type KnownExtends = LiteralUnion<
'@bfra.me/semantic-release' | 'semantic-release-monorepo' | keyof CustomExtends,
string
>

export type Extends = KnownExtends | KnownExtends[]

export interface SemanticReleaseConfig {
extends?: Extends

branches: ReadonlyArray<BranchSpec> | BranchSpec

repositoryUrl?: string

tagFormat?: string

plugins?: Plugin[]

dryRun?: boolean

ci?: boolean | undefined

[name: string]: unknown
}
48 changes: 48 additions & 0 deletions packages/semantic-release/src/types/plugin/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type {LiteralUnion} from 'type-fest'
import type {PluginSpec} from './plugin-spec'
import type {SemanticReleasePlugins} from './semantic-release'

/**
* This is a special exported interface for other packages to declare
* additional types that should bail out for eslint rules. For example
* `semantic-release-license` can declare it like so in its `d.ts`:
*
* ```ts
* declare module '@bfra-me/semantic-release' {
* export interface CustomPluginConfig {
* /**
* * The path to your license path.
* *
* * \@see [Options](https://github.com/cbhq/semantic-release-license/tree/latest#options)
* *\/
* 'semantic-release-license': {
* license: {
* path?: string;
* }
* }
* }
* }
* ```
*/
export interface CustomPluginConfig {}

type WrapPlugin<T extends {[key: string]: any}> = {
[K in keyof T]: T[K] extends PluginSpec ? T[K] : PluginSpec<[K, T[K]]>
}

type CustomPlugins = WrapPlugin<CustomPluginConfig>

export interface KnownPlugins extends CustomPlugins, SemanticReleasePlugins {}

// Extract the TConfig type from a PluginNameAndConfig
export type PluginConfig<TSpec extends PluginSpec> = TSpec extends [string, infer TConfig]
? TConfig
: never

export type PluginName = LiteralUnion<keyof KnownPlugins, string>

export type Plugin<TLookup extends any = PluginName> = TLookup extends keyof KnownPlugins
? PluginSpec<[TLookup, PluginConfig<KnownPlugins[TLookup]>]>
: TLookup extends string
? PluginSpec<[TLookup, {[key: string]: unknown}]>
: PluginSpec<TLookup>
3 changes: 3 additions & 0 deletions packages/semantic-release/src/types/plugin/plugin-spec.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type PluginSpec<TSpec extends any[] = any[]> = TSpec extends [infer TName, (infer TConfig)?]
? TName | [TName, TConfig]
: never
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type {PluginSpec} from '../plugin-spec'

export interface CommitAnalyzerPluginConfig {
/**
* Preset value.
*/
preset?: string
releaseRules?: {
type: string
scope: string
release: string
}[]
}

export type CommitAnalyzerPluginSpec = PluginSpec<
['@semantic-release/commit-analyzer', CommitAnalyzerPluginConfig]
>

export interface ReleaseNotesGeneratorPluginConfig {
/**
* Preset value.
*/
preset?: string
}

export type ReleaseNotesGeneratorPluginSpec = PluginSpec<
['@semantic-release/release-notes-generator', ReleaseNotesGeneratorPluginConfig]
>

export interface NpmPluginConfig {
npmPublish?: boolean
}

export type NpmPluginSpec = PluginSpec<['@semantic-release/npm', NpmPluginConfig]>

export interface GitHubPluginConfig {
/**
* Some assets
*/
assets?: string
}

export type GitHubPluginSpec = PluginSpec<['@semantic-release/github', GitHubPluginConfig]>

export interface SemanticReleasePlugins {
'@semantic-release/commit-analyzer': CommitAnalyzerPluginSpec

'@semantic-release/release-notes-generator': ReleaseNotesGeneratorPluginSpec

'@semantic-release/npm': NpmPluginSpec

'@semantic-release/github': GitHubPluginSpec
}
12 changes: 12 additions & 0 deletions packages/semantic-release/test/define-config.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {describe, expectTypeOf, test} from 'vitest'
import {defineConfig} from '@bfra.me/semantic-release'
import type {SemanticReleaseConfig} from '@bfra.me/semantic-release'

describe('defineConfig', {}, () => {
test('minimal config', () => {
const config = defineConfig({
branches: 'main',
})
expectTypeOf(config).toEqualTypeOf<SemanticReleaseConfig>()
})
})
10 changes: 10 additions & 0 deletions packages/semantic-release/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@bfra.me/tsconfig",
"compilerOptions": {
"composite": false,
"incremental": false,
"noEmit": true,
"outDir": "lib"
},
"exclude": ["lib", "node_modules"]
}
12 changes: 12 additions & 0 deletions packages/semantic-release/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {defineConfig} from 'tsup'

export default defineConfig({
entry: ['src/index.ts'],
format: ['esm'],
dts: true,
clean: true,
sourcemap: true,
minify: true,
outDir: 'lib',
splitting: true,
})
Loading