Skip to content

Commit

Permalink
refactor: use semantic-release v20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Jan 30, 2023
1 parent 6e2cb05 commit 75ec47b
Show file tree
Hide file tree
Showing 12 changed files with 3,827 additions and 2,256 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
]
},
"devDependencies": {
"@bubkoo/eslint-config": "^1.1.0",
"@bubkoo/eslint-config": "^1.3.0",
"@bubkoo/semantic-release-config": "^1.6.0",
"@commitlint/config-conventional": "^17.3.0",
"@types/node": "^18.11.10",
"eslint": "^8.28.0",
"husky": "^8.0.2",
"@commitlint/config-conventional": "^17.4.2",
"@types/node": "^18.11.18",
"eslint": "^8.33.0",
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.0",
"rimraf": "^3.0.2",
"semantic-release": "^19.0.5",
"prettier": "^2.8.3",
"rimraf": "^4.1.2",
"semantic-release": "^20.1.0",
"ts-node": "^10.9.1",
"tslib": "^2.4.1",
"typescript": "^4.9.3"
"tslib": "^2.5.0",
"typescript": "^4.9.4"
},
"pnpm": {
"overrides": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"semantic-release": "^19.x"
},
"dependencies": {
"@semantic-release-monorepo/core": "2.4.1",
"@semantic-release-monorepo/core": "workspace:*",
"lodash": "^4.17.21",
"meow": "^11.0.0"
},
Expand Down
14 changes: 7 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"prebuild": "run-s clean"
},
"peerDependencies": {
"semantic-release": "^19.x"
"semantic-release": "^19.x || ^20.x"
},
"dependencies": {
"@manypkg/get-packages": "^1.1.3",
"@manypkg/get-packages": "^2.0.0",
"blork": "^9.3.0",
"cosmiconfig": "^8.0.0",
"debug": "^4.3.4",
Expand All @@ -44,7 +44,7 @@
"get-stream": "^6.0.1",
"git-log-parser": "^1.2.0",
"git-username": "^1.0.0",
"globby": "^13.1.2",
"globby": "^13.1.3",
"lodash": "^4.17.21",
"meow": "^11.0.0",
"promise-events": "^0.2.4",
Expand All @@ -54,19 +54,19 @@
"unixify": "^1.0.0"
},
"devDependencies": {
"@changesets/types": "^5.2.0",
"@changesets/types": "^5.2.1",
"@types/bash-glob": "^2.0.1",
"@types/debug": "^4.1.7",
"@types/fs-extra": "^9.0.13",
"@types/fs-extra": "^11.0.1",
"@types/git-username": "^1.0.2",
"@types/lodash": "^4.14.191",
"@types/semantic-release": "^17.2.4",
"@types/semantic-release": "^20.0.0",
"@types/semver": "^7.3.13",
"@types/signale": "^1.4.4",
"@types/stream-buffers": "^3.0.4",
"@types/unixify": "^1.0.0",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2"
"rimraf": "^4.1.2"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dotenv/config'
import path from 'path'
import * as SemanticRelease from 'semantic-release'
import { fileURLToPath } from 'url'
import SemanticRelease from 'semantic-release'
import { getLogger } from './logger.js'
import { releasePackages } from './release.js'
import { Context, SRMOptions as Options } from './types.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/local-deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash'
import SemanticRelease from 'semantic-release'
import * as SemanticRelease from 'semantic-release'
import { writeFileSync } from 'fs'
import { getManifest } from './manifest.js'
import {
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import fs from 'fs'
import path from 'path'
import unixify from 'unixify'
import { globbySync } from 'globby'
import { existsSync, lstatSync, readFileSync, Stats } from 'fs'
import { getPackagesSync, Packages } from '@manypkg/get-packages'
import { PackageJSON } from './types.js'

export function readManifest(path: string) {
if (!existsSync(path)) {
if (!fs.existsSync(path)) {
throw new ReferenceError(`package.json file not found: "${path}"`)
}

let stat: Stats
let stat: fs.Stats
try {
stat = lstatSync(path)
stat = fs.lstatSync(path)
} catch (_) {
throw new ReferenceError(`package.json cannot be read: "${path}"`)
}
Expand All @@ -21,7 +21,7 @@ export function readManifest(path: string) {
throw new ReferenceError(`package.json is not a file: "${path}"`)

try {
return readFileSync(path, 'utf8')
return fs.readFileSync(path, 'utf8')
} catch (_) {
throw new ReferenceError(`package.json cannot be read: "${path}"`)
}
Expand Down Expand Up @@ -79,13 +79,13 @@ export function getManifestPaths(cwd: string, ignorePackages?: string[]) {
} catch (e) {
console.warn(e)
workspace = {
tool: 'root',
tool: { type: 'root' },
root: {
dir: cwd,
packageJson: getManifest(path.join(cwd, 'package.json')),
},
packages: [],
}
} as any as Packages
}

const packages = workspace.packages.map((p) => path.relative(cwd, p.dir))
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SemanticRelease from 'semantic-release'
import * as SemanticRelease from 'semantic-release'
import { cosmiconfig } from 'cosmiconfig'

const CONFIG_NAME = 'release'
Expand Down
15 changes: 8 additions & 7 deletions packages/core/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import _ from 'lodash'
import path from 'path'
import fse from 'fs-extra'
import fs from 'fs/promises'
import fse from 'fs-extra/esm'
import gitOwner from 'git-username'
import SemanticRelease from 'semantic-release'
import * as SemanticRelease from 'semantic-release'
import { execa } from 'execa'
import {
Package,
Expand Down Expand Up @@ -278,12 +279,12 @@ export function getInlinePluginsCreator(

const npmrcPath = path.join(path.dirname(pkgPath), '.npmrc')
const hasNpmrc = await fse.pathExists(npmrcPath)
const oldNpmrc = hasNpmrc ? await fse.readFile(npmrcPath) : null
await fse.writeFile(
const oldNpmrc = hasNpmrc ? await fs.readFile(npmrcPath) : null
await fs.writeFile(
npmrcPath,
`@${gprScope}:registry=https://npm.pkg.github.com\n//${host}/:_authToken=${token}\nscripts-prepend-node-path=true`,
)
await fse.writeFile(pkgPath, JSON.stringify(manifest, null, 2))
await fs.writeFile(pkgPath, JSON.stringify(manifest, null, 2))

const pub = execa('npm', ['publish'], {
cwd: pkg.dir,
Expand All @@ -295,9 +296,9 @@ export function getInlinePluginsCreator(

const ret = await pub

await fse.writeFile(pkgPath, oldManifest)
await fs.writeFile(pkgPath, oldManifest)
if (hasNpmrc) {
await fse.writeFile(npmrcPath, oldNpmrc)
await fs.writeFile(npmrcPath, oldNpmrc!)
} else {
await fse.remove(npmrcPath)
}
Expand Down
17 changes: 9 additions & 8 deletions packages/core/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'lodash'
import path, { dirname } from 'path'
import signale, { Signale } from 'signale'
import semanticRelease from 'semantic-release'
import * as SemanticRelease from 'semantic-release'
import semanticGetConfig from 'semantic-release/lib/get-config.js'
import { WritableStreamBuffer } from 'stream-buffers'
import { check } from './blork.js'
Expand All @@ -23,7 +24,7 @@ import { getOptions, getSuccessComment, getFailComment } from './options.js'

export async function releasePackages(
paths: string[],
localOptions: semanticRelease.Options,
localOptions: SemanticRelease.Options,
srmOptions: SRMOptions,
{ cwd, env, stdout, stderr }: Context,
logger: Signale,
Expand Down Expand Up @@ -202,18 +203,18 @@ async function loadPackage(

function makePushToGitMethod(
context: any,
parsedOptions: semanticRelease.Options,
parsedOptions: SemanticRelease.Options,
plugin: undefined | string | [string, any],
srmOptions: SRMOptions,
) {
// https://github.com/semantic-release/git
if (plugin) {
return async (
branch: semanticRelease.BranchObject,
branch: SemanticRelease.BranchObject,
releases: {
package: Package
lastRelease: semanticRelease.LastRelease
nextReleases: semanticRelease.Release[]
lastRelease: SemanticRelease.LastRelease
nextReleases: SemanticRelease.Release[]
}[],
) => {
const pluginName = Array.isArray(plugin) ? plugin[0] : plugin
Expand Down Expand Up @@ -297,7 +298,7 @@ async function getSemanticConfig(
stderr: NodeJS.WriteStream
logger: Logger
},
options: semanticRelease.Options,
options: SemanticRelease.Options,
srmOptions: SRMOptions,
) {
try {
Expand All @@ -308,8 +309,8 @@ async function getSemanticConfig(

const context = { cwd, env, stdout, stderr, logger: blackhole }
const raw = await semanticGetConfig(context, options)
const parsedOptions: semanticRelease.Options = raw.options
const plugins: semanticRelease.PluginSpec[] = parsedOptions.plugins
const parsedOptions: SemanticRelease.Options = raw.options
const plugins: SemanticRelease.PluginSpec[] = parsedOptions.plugins
? parsedOptions.plugins.slice()
: []

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/semver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import semver from 'semver'
import SemanticRelease from 'semantic-release'
import * as SemanticRelease from 'semantic-release'
import { getTags } from './git.js'
import { BumpStrategy, Package, VersionPrefix } from './types.js'

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SemanticRelease from 'semantic-release'
import * as SemanticRelease from 'semantic-release'
import { PackageJSON } from '@changesets/types'

export type { PackageJSON }
Expand Down
Loading

0 comments on commit 75ec47b

Please sign in to comment.