Skip to content

Commit 2bcea0c

Browse files
rohmanhmfatfisz
authored andcommitted
feat: Convert root to array if root is a string (#153)
Closes #152.
1 parent 566c777 commit 2bcea0c

4 files changed

Lines changed: 18 additions & 24 deletions

File tree

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function isRegExp(string) {
2828
// So we need to offer a way to customize the cwd for the eslint plugin
2929
export function manipulatePluginOptions(pluginOpts, cwd = process.cwd()) {
3030
if (pluginOpts.root) {
31+
if (typeof pluginOpts.root === 'string') {
32+
pluginOpts.root = [pluginOpts.root]; // eslint-disable-line no-param-reassign
33+
}
3134
// eslint-disable-next-line no-param-reassign
3235
pluginOpts.root = pluginOpts.root.reduce((resolvedDirs, dirPath) => {
3336
if (glob.hasMagic(dirPath)) {

test/index.test.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,18 @@ describe('module-resolver', () => {
109109
babelrc: false,
110110
plugins: [
111111
[plugin, {
112-
root: [
113-
'./test/testproject/src',
114-
],
112+
root: './test/testproject/src',
115113
}],
116114
],
117115
};
118116

117+
it('should convert root to array if root is a string', () => {
118+
const code = 'var something = require();';
119+
const result = transform(code, rootTransformerOpts);
120+
121+
expect(result.code).toBe('var something = require();');
122+
});
123+
119124
it('should handle no arguments', () => {
120125
const code = 'var something = require();';
121126
const result = transform(code, rootTransformerOpts);
@@ -213,9 +218,7 @@ describe('module-resolver', () => {
213218
babelrc: false,
214219
plugins: [
215220
[plugin, {
216-
root: [
217-
'./test/testproject/src/**',
218-
],
221+
root: './test/testproject/src/**',
219222
}],
220223
],
221224
};
@@ -464,9 +467,7 @@ describe('module-resolver', () => {
464467
babelrc: false,
465468
plugins: [
466469
[plugin, {
467-
root: [
468-
'./testproject/src',
469-
],
470+
root: './testproject/src',
470471
alias: {
471472
test: './testproject/test',
472473
},
@@ -498,9 +499,7 @@ describe('module-resolver', () => {
498499
babelrc: false,
499500
plugins: [
500501
[plugin, {
501-
root: [
502-
'./src',
503-
],
502+
root: './src',
504503
alias: {
505504
test: './test',
506505
},
@@ -531,9 +530,7 @@ describe('module-resolver', () => {
531530
babelrc: false,
532531
plugins: [
533532
[plugin, {
534-
root: [
535-
'./src',
536-
],
533+
root: './src',
537534
cwd: 'babelrc',
538535
}],
539536
],
@@ -571,9 +568,7 @@ describe('module-resolver', () => {
571568
babelrc: false,
572569
plugins: [
573570
[pluginWithMock, {
574-
root: [
575-
'.',
576-
],
571+
root: '.',
577572
cwd: 'babelrc',
578573
}],
579574
],

test/jest.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ describe('jest functions', () => {
77
babelrc: false,
88
plugins: [
99
[plugin, {
10-
root: [
11-
'./test/testproject/src',
12-
],
10+
root: './test/testproject/src',
1311
alias: {
1412
test: './test/testproject/test',
1513
},

test/system.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ describe('System.import', () => {
77
babelrc: false,
88
plugins: [
99
[plugin, {
10-
root: [
11-
'./test/testproject/src',
12-
],
10+
root: './test/testproject/src',
1311
alias: {
1412
test: './test/testproject/test',
1513
},

0 commit comments

Comments
 (0)