Skip to content

Commit

Permalink
feat(src): load plugins from the current working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Jul 9, 2018
1 parent 14f3e53 commit 9745bf0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"release": "commitlint --to 'HEAD' && standard-version"
},
"dependencies": {
"cosmiconfig": "^2.1.0"
"cosmiconfig": "^2.1.0",
"import-cwd": "^2.0.0"
},
"devDependencies": {
"@commitlint/cli": "^7.0.0",
Expand Down
8 changes: 5 additions & 3 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const req = require('import-cwd')

/**
* Load Options
*
Expand All @@ -13,23 +15,23 @@
const options = (config, file) => {
if (config.parser && typeof config.parser === 'string') {
try {
config.parser = require(config.parser)
config.parser = req(config.parser)
} catch (err) {
throw new Error(`Loading PostCSS Parser failed: ${err.message}\n\n(@${file})`)
}
}

if (config.syntax && typeof config.syntax === 'string') {
try {
config.syntax = require(config.syntax)
config.syntax = req(config.syntax)
} catch (err) {
throw new Error(`Loading PostCSS Syntax failed: ${err.message}\n\n(@${file})`)
}
}

if (config.stringifier && typeof config.stringifier === 'string') {
try {
config.stringifier = require(config.stringifier)
config.stringifier = req(config.stringifier)
} catch (err) {
throw new Error(`Loading PostCSS Stringifier failed: ${err.message}\n\n(@${file})`)
}
Expand Down
6 changes: 4 additions & 2 deletions src/plugins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const req = require('import-cwd')

/**
* Plugin Loader
*
Expand All @@ -14,13 +16,13 @@
const load = (plugin, options, file) => {
if (options === null || Object.keys(options).length === 0) {
try {
return require(plugin)
return req(plugin)
} catch (err) {
throw new Error(`Loading PostCSS Plugin failed: ${err.message}\n\n(@${file})`)
}
} else {
try {
return require(plugin)(options)
return req(plugin)(options)
} catch (err) {
throw new Error(`Loading PostCSS Plugin failed: ${err.message}\n\n(@${file})`)
}
Expand Down

0 comments on commit 9745bf0

Please sign in to comment.