Skip to content

Commit 26b4db3

Browse files
fix: crash with ERR_REQUIRE_ESM error
1 parent 8ca2564 commit 26b4db3

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

declarations/utils.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/**
2+
* @template T
3+
* @param {T} value
4+
* @return {
5+
T extends (null | undefined)
6+
? []
7+
: T extends string
8+
? [string]
9+
: T extends readonly unknown[]
10+
? T
11+
: T extends Iterable<infer T>
12+
? T[]
13+
: [T]
14+
}
15+
*/
16+
export function arrify<T>(
17+
value: T
18+
): T extends null | undefined
19+
? []
20+
: T extends string
21+
? [string]
22+
: T extends readonly unknown[]
23+
? T
24+
: T extends Iterable<infer T_1>
25+
? T_1[]
26+
: [T];
127
/**
228
* @param {string|string[]} files
329
* @param {string} context

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { isAbsolute, join } from 'path';
22

3-
import arrify from 'arrify';
43
import { isMatch } from 'micromatch';
54

65
import { getOptions } from './options';
76
import linter from './linter';
8-
import { parseFiles, parseFoldersToGlobs } from './utils';
7+
import { arrify, parseFiles, parseFoldersToGlobs } from './utils';
98

109
/** @typedef {import('webpack').Compiler} Compiler */
1110
/** @typedef {import('./options').Options} Options */

src/utils.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
11
import { resolve } from 'path';
22
import { statSync } from 'fs';
33

4-
import arrify from 'arrify';
5-
64
// @ts-ignore
75
import normalizePath from 'normalize-path';
86

7+
/**
8+
* @template T
9+
* @param {T} value
10+
* @return {
11+
T extends (null | undefined)
12+
? []
13+
: T extends string
14+
? [string]
15+
: T extends readonly unknown[]
16+
? T
17+
: T extends Iterable<infer T>
18+
? T[]
19+
: [T]
20+
}
21+
*/
22+
export function arrify(value) {
23+
// eslint-disable-next-line no-undefined
24+
if (value === null || value === undefined) {
25+
// @ts-ignore
26+
return [];
27+
}
28+
29+
if (Array.isArray(value)) {
30+
// @ts-ignore
31+
return value;
32+
}
33+
34+
if (typeof value === 'string') {
35+
// @ts-ignore
36+
return [value];
37+
}
38+
39+
// @ts-ignore
40+
if (typeof value[Symbol.iterator] === 'function') {
41+
// @ts-ignore
42+
return [...value];
43+
}
44+
45+
// @ts-ignore
46+
return [value];
47+
}
48+
949
/**
1050
* @param {string|string[]} files
1151
* @param {string} context

0 commit comments

Comments
 (0)