Skip to content

Commit

Permalink
fix: crash with ERR_REQUIRE_ESM error
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Jul 20, 2021
1 parent 8ca2564 commit 26b4db3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
26 changes: 26 additions & 0 deletions declarations/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/**
* @template T
* @param {T} value
* @return {
T extends (null | undefined)
? []
: T extends string
? [string]
: T extends readonly unknown[]
? T
: T extends Iterable<infer T>
? T[]
: [T]
}
*/
export function arrify<T>(
value: T
): T extends null | undefined
? []
: T extends string
? [string]
: T extends readonly unknown[]
? T
: T extends Iterable<infer T_1>
? T_1[]
: [T];
/**
* @param {string|string[]} files
* @param {string} context
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { isAbsolute, join } from 'path';

import arrify from 'arrify';
import { isMatch } from 'micromatch';

import { getOptions } from './options';
import linter from './linter';
import { parseFiles, parseFoldersToGlobs } from './utils';
import { arrify, parseFiles, parseFoldersToGlobs } from './utils';

/** @typedef {import('webpack').Compiler} Compiler */
/** @typedef {import('./options').Options} Options */
Expand Down
44 changes: 42 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
import { resolve } from 'path';
import { statSync } from 'fs';

import arrify from 'arrify';

// @ts-ignore
import normalizePath from 'normalize-path';

/**
* @template T
* @param {T} value
* @return {
T extends (null | undefined)
? []
: T extends string
? [string]
: T extends readonly unknown[]
? T
: T extends Iterable<infer T>
? T[]
: [T]
}
*/
export function arrify(value) {
// eslint-disable-next-line no-undefined
if (value === null || value === undefined) {
// @ts-ignore
return [];
}

if (Array.isArray(value)) {
// @ts-ignore
return value;
}

if (typeof value === 'string') {
// @ts-ignore
return [value];
}

// @ts-ignore
if (typeof value[Symbol.iterator] === 'function') {
// @ts-ignore
return [...value];
}

// @ts-ignore
return [value];
}

/**
* @param {string|string[]} files
* @param {string} context
Expand Down

0 comments on commit 26b4db3

Please sign in to comment.