diff --git a/package.json b/package.json index 366ee4b..8fecb90 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/options.js b/src/options.js index 437fb06..552d09b 100644 --- a/src/options.js +++ b/src/options.js @@ -1,5 +1,7 @@ 'use strict' +const req = require('import-cwd') + /** * Load Options * @@ -13,7 +15,7 @@ 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})`) } @@ -21,7 +23,7 @@ const options = (config, 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})`) } @@ -29,7 +31,7 @@ const options = (config, 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})`) } diff --git a/src/plugins.js b/src/plugins.js index c5e1c63..57f3974 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -1,5 +1,7 @@ 'use strict' +const req = require('import-cwd') + /** * Plugin Loader * @@ -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})`) }