-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update tsconfig * fix: add file extension * test: update case * chore: update version
- Loading branch information
1 parent
a20cba0
commit bc269dd
Showing
19 changed files
with
218 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import assert from 'assert'; | ||
import * as tslib from 'tslib'; | ||
|
||
/** | ||
* compatible esModule require | ||
* @param path | ||
*/ | ||
export default async function compatibleRequire(path: string, origin = false): Promise<any> { | ||
const requiredModule = await import(path); | ||
if (path.endsWith('.json')) { | ||
return require(path); | ||
} | ||
|
||
assert(requiredModule, `module '${path}' exports is undefined`); | ||
let requiredModule; | ||
try { | ||
/* eslint-disable-next-line @typescript-eslint/no-var-requires */ | ||
requiredModule = tslib.__importStar(require(path)); | ||
assert(requiredModule, `module '${path}' exports is undefined`); | ||
} catch { | ||
requiredModule = await import(path); | ||
assert(requiredModule, `module '${path}' exports is undefined`); | ||
requiredModule = requiredModule.__esModule ? requiredModule.default ?? requiredModule : requiredModule; | ||
} | ||
|
||
return origin ? requiredModule : (requiredModule.default || requiredModule); | ||
} |
Oops, something went wrong.