Skip to content
This repository was archived by the owner on Feb 25, 2019. It is now read-only.

Commit 4074525

Browse files
committed
feat(Plugin): automate path resolution in plugin.include using callsite
1 parent c261dbf commit 4074525

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

core/arch/Plugin.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
const _ = require('lodash')
77
const path = require('path')
88
const injector = require('./injector')
9+
const callsite = require('callsite')
910

1011
/**
1112
* Symbols
@@ -110,8 +111,8 @@ class Plugin {
110111
* }
111112
* })
112113
* .initializer(function (plugin) {
113-
* .include(__dirname, 'other')
114-
* .include(__dirname, 'yetanother')
114+
* .include('./other')
115+
* .include('./yetanother')
115116
* })
116117
* }
117118
*
@@ -130,10 +131,14 @@ class Plugin {
130131
*
131132
* }
132133
*/
133-
include () {
134-
let segments = Array.prototype.slice.call(arguments, this.include.length)
135-
let filepath = path.join.apply(null, segments)
134+
include (filename) {
135+
// prepend file path from call stack onto the given, possibly relative, filename
136+
let caller = callsite()[1]
137+
let callerpath = caller.getFileName()
138+
let filepath = path.join(path.dirname(callerpath), filename)
139+
136140
require(filepath)(this)
141+
137142
return this
138143
}
139144

0 commit comments

Comments
 (0)