Skip to content

Commit 9587bd1

Browse files
committed
fix: install semantic-release at runtime
1 parent eeba7b1 commit 9587bd1

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

build.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ buildSync({
55
bundle: true,
66
platform: 'node',
77
outfile: 'build/index.js',
8+
external: [
9+
'debug',
10+
'semantic-release',
11+
],
812
})

src/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import * as core from '@actions/core'
2-
import semanticRelease from 'semantic-release'
2+
import type SemanticRelease from 'semantic-release'
33
import defaultConfig from './defaultConfig'
44
import { install } from './util/install'
5-
import debugLib from 'debug'
65
import { forceRelease, initialRelease } from './plugin'
7-
import { PluginSpec } from './semantic-release'
6+
import type { PluginSpec } from './semantic-release'
87
import { updateTags } from './util/updateTags'
98
import { gitConfig } from './util/gitConfig'
109

1110
export default async function run(env = process.env): Promise<void> {
1211
try {
13-
const packages: string[] = ['semantic-release'] // npm warns about missing peer dependency without this
12+
const packages: string[] = ['semantic-release']
1413

1514
const config = getConfig(core.getInput('config', { required: false}), defaultConfig, packages)
1615
const plugins: PluginSpec[] = Array.from(config.plugins ?? [])
@@ -43,14 +42,16 @@ export default async function run(env = process.env): Promise<void> {
4342
log('DRY RUN')
4443
}
4544
if (debug) {
45+
const {default: debugLib} = await import('debug')
4646
debugLib.enable('semantic-release:*')
4747
}
4848

4949
plugins.push(forceRelease, initialRelease)
5050

51+
const {default: semanticRelease} = await import('semantic-release')
5152
const result = await semanticRelease({
5253
...config,
53-
plugins: plugins as semanticRelease.PluginSpec[],
54+
plugins: plugins as SemanticRelease.PluginSpec[],
5455
dryRun,
5556
}, {
5657
env: {
@@ -119,9 +120,9 @@ function safeParse(val: string) {
119120

120121
function getConfig(
121122
configInput: string,
122-
defaultConfig: Partial<semanticRelease.GlobalConfig>,
123+
defaultConfig: Partial<SemanticRelease.GlobalConfig>,
123124
packages: string[],
124-
): Partial<semanticRelease.GlobalConfig> {
125+
): Partial<SemanticRelease.GlobalConfig> {
125126
if (configInput[0] === '.') {
126127
return {
127128
...defaultConfig,
@@ -131,7 +132,7 @@ function getConfig(
131132
try {
132133
return {
133134
...defaultConfig,
134-
...JSON.parse(configInput) as Partial<semanticRelease.GlobalConfig>,
135+
...JSON.parse(configInput) as Partial<SemanticRelease.GlobalConfig>,
135136
}
136137
} catch(e) {
137138
throw 'Invalid inline config'

src/plugin/forceRelease.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import SemanticRelease from 'semantic-release'
2-
import { PluginConfig } from '../semantic-release'
1+
import type SemanticRelease from 'semantic-release'
2+
import type { PluginConfig } from '../semantic-release'
33
import { getReleaseType, releaseTypes } from './shared/releaseTypes'
44

55
/**

src/plugin/initialRelease.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import SemanticRelease from 'semantic-release'
2-
import { PluginConfig } from '../semantic-release'
1+
import type SemanticRelease from 'semantic-release'
2+
import type { PluginConfig } from '../semantic-release'
33
import { releaseTypes } from './shared/releaseTypes'
44

55
/**

0 commit comments

Comments
 (0)