Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
31 changes: 13 additions & 18 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -213,9 +218,7 @@ describe('module-resolver', () => {
babelrc: false,
plugins: [
[plugin, {
root: [
'./test/testproject/src/**',
],
root: './test/testproject/src/**',
}],
],
};
Expand Down Expand Up @@ -464,9 +467,7 @@ describe('module-resolver', () => {
babelrc: false,
plugins: [
[plugin, {
root: [
'./testproject/src',
],
root: './testproject/src',
alias: {
test: './testproject/test',
},
Expand Down Expand Up @@ -498,9 +499,7 @@ describe('module-resolver', () => {
babelrc: false,
plugins: [
[plugin, {
root: [
'./src',
],
root: './src',
alias: {
test: './test',
},
Expand Down Expand Up @@ -531,9 +530,7 @@ describe('module-resolver', () => {
babelrc: false,
plugins: [
[plugin, {
root: [
'./src',
],
root: './src',
cwd: 'babelrc',
}],
],
Expand Down Expand Up @@ -571,9 +568,7 @@ describe('module-resolver', () => {
babelrc: false,
plugins: [
[pluginWithMock, {
root: [
'.',
],
root: '.',
cwd: 'babelrc',
}],
],
Expand Down
4 changes: 1 addition & 3 deletions test/jest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ describe('jest functions', () => {
babelrc: false,
plugins: [
[plugin, {
root: [
'./test/testproject/src',
],
root: './test/testproject/src',
alias: {
test: './test/testproject/test',
},
Expand Down
4 changes: 1 addition & 3 deletions test/system.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ describe('System.import', () => {
babelrc: false,
plugins: [
[plugin, {
root: [
'./test/testproject/src',
],
root: './test/testproject/src',
alias: {
test: './test/testproject/test',
},
Expand Down