fix(plugins): require user plugins relative to the cwd
This commit is contained in:
parent
150273c8fe
commit
43c8df0bfe
@ -22,6 +22,7 @@
|
||||
"npm-registry-client": "^6.4.0",
|
||||
"npmconf": "^2.1.2",
|
||||
"npmlog": "^1.2.1",
|
||||
"require-relative": "^0.8.7",
|
||||
"run-auto": "^1.1.2",
|
||||
"semver": "^4.3.6"
|
||||
},
|
||||
|
@ -1,3 +1,5 @@
|
||||
const relative = require('require-relative')
|
||||
|
||||
let exports = module.exports = function (source) {
|
||||
return {
|
||||
analyzeCommits: exports.normalize(source.analyzeCommits, '@semantic-release/commit-analyzer'),
|
||||
@ -7,10 +9,10 @@ let exports = module.exports = function (source) {
|
||||
}
|
||||
|
||||
exports.normalize = function (plugin, fallback) {
|
||||
if (typeof plugin === 'string') return require(plugin).bind(null, {})
|
||||
if (typeof plugin === 'string') return relative(plugin).bind(null, {})
|
||||
|
||||
if (plugin && (typeof plugin.path === 'string')) {
|
||||
return require(plugin.path).bind(null, plugin)
|
||||
return relative(plugin.path).bind(null, plugin)
|
||||
}
|
||||
|
||||
return require(fallback).bind(null, plugin)
|
||||
|
@ -5,7 +5,7 @@ const { normalize } = require('../../dist/lib/plugins')
|
||||
test('normalize and load plugin', function (t) {
|
||||
|
||||
t.test('load from string', (tt) => {
|
||||
const plugin = normalize('../../dist/lib/plugin-noop')
|
||||
const plugin = normalize('./dist/lib/plugin-noop')
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
||||
@ -14,7 +14,7 @@ test('normalize and load plugin', function (t) {
|
||||
|
||||
t.test('load from object', (tt) => {
|
||||
const plugin = normalize({
|
||||
path: '../../dist/lib/plugin-noop'
|
||||
path: './dist/lib/plugin-noop'
|
||||
})
|
||||
|
||||
tt.is(typeof plugin, 'function')
|
||||
|
Loading…
x
Reference in New Issue
Block a user