diff --git a/src/index.js b/src/index.js index 6d09bb9..438d577 100644 --- a/src/index.js +++ b/src/index.js @@ -28,6 +28,9 @@ function isRegExp(string) { // So we need to offer a way to customize the cwd for the eslint plugin export function manipulatePluginOptions(pluginOpts, cwd = process.cwd()) { if (pluginOpts.root) { + if (typeof pluginOpts.root === 'string') { + pluginOpts.root = [pluginOpts.root]; // eslint-disable-line no-param-reassign + } // eslint-disable-next-line no-param-reassign pluginOpts.root = pluginOpts.root.reduce((resolvedDirs, dirPath) => { if (glob.hasMagic(dirPath)) { diff --git a/test/index.test.js b/test/index.test.js index 892979b..26df920 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -109,13 +109,18 @@ describe('module-resolver', () => { babelrc: false, plugins: [ [plugin, { - root: [ - './test/testproject/src', - ], + root: './test/testproject/src', }], ], }; + it('should convert root to array if root is a string', () => { + const code = 'var something = require();'; + const result = transform(code, rootTransformerOpts); + + expect(result.code).toBe('var something = require();'); + }); + it('should handle no arguments', () => { const code = 'var something = require();'; const result = transform(code, rootTransformerOpts); @@ -213,9 +218,7 @@ describe('module-resolver', () => { babelrc: false, plugins: [ [plugin, { - root: [ - './test/testproject/src/**', - ], + root: './test/testproject/src/**', }], ], }; @@ -464,9 +467,7 @@ describe('module-resolver', () => { babelrc: false, plugins: [ [plugin, { - root: [ - './testproject/src', - ], + root: './testproject/src', alias: { test: './testproject/test', }, @@ -498,9 +499,7 @@ describe('module-resolver', () => { babelrc: false, plugins: [ [plugin, { - root: [ - './src', - ], + root: './src', alias: { test: './test', }, @@ -531,9 +530,7 @@ describe('module-resolver', () => { babelrc: false, plugins: [ [plugin, { - root: [ - './src', - ], + root: './src', cwd: 'babelrc', }], ], @@ -571,9 +568,7 @@ describe('module-resolver', () => { babelrc: false, plugins: [ [pluginWithMock, { - root: [ - '.', - ], + root: '.', cwd: 'babelrc', }], ], diff --git a/test/jest.test.js b/test/jest.test.js index 0261004..82c7f2e 100644 --- a/test/jest.test.js +++ b/test/jest.test.js @@ -7,9 +7,7 @@ describe('jest functions', () => { babelrc: false, plugins: [ [plugin, { - root: [ - './test/testproject/src', - ], + root: './test/testproject/src', alias: { test: './test/testproject/test', }, diff --git a/test/system.test.js b/test/system.test.js index 74b0e44..bd4c254 100644 --- a/test/system.test.js +++ b/test/system.test.js @@ -7,9 +7,7 @@ describe('System.import', () => { babelrc: false, plugins: [ [plugin, { - root: [ - './test/testproject/src', - ], + root: './test/testproject/src', alias: { test: './test/testproject/test', },