microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/common/customRequire.ts
27lines · modeblame
2d8af448Yuri Skorokhodov6 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
09f6024fHeniker4 years ago | 4 | /* eslint-disable */ |
| 5 | /* eslint-enable prettier/prettier*/ | |
| 6 | | |
65e55367RedMickey4 years ago | 7 | interface CustomRequire extends NodeRequireFunction { |
| 8 | cache: any; | |
| 9 | } | |
| 10 | | |
2d8af448Yuri Skorokhodov6 years ago | 11 | // Portion of code was taken from https://github.com/sindresorhus/ow/blob/d62a06c192b892d504887f0b97fdc842e8cbf862/source/utils/node/require.ts |
65e55367RedMickey4 years ago | 12 | let customRequire: CustomRequire; |
2d8af448Yuri Skorokhodov6 years ago | 13 | |
| 14 | try { | |
| 15 | // Export `__non_webpack_require__` in Webpack environments to make sure it doesn't bundle modules loaded via this method | |
34472878RedMickey5 years ago | 16 | customRequire = |
| 17 | (global as any).__non_webpack_require__ === "function" | |
| 18 | ? (global as any).__non_webpack_require__ | |
348153c0Ezio Li2 years ago | 19 | : eval("require"); // CodeQL [js/eval-usage] Export `__non_webpack_require__` in Webpack environments to make sure it doesn't bundle modules loaded via this method |
2d8af448Yuri Skorokhodov6 years ago | 20 | } catch { |
| 21 | // Use a noop in case both `__non_webpack_require__` and `require` does not exist | |
09f6024fHeniker4 years ago | 22 | customRequire = (() => { |
65e55367RedMickey4 years ago | 23 | customRequire.cache = {}; // eslint-disable-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-empty-function |
09f6024fHeniker4 years ago | 24 | }) as any as CustomRequire; |
2d8af448Yuri Skorokhodov6 years ago | 25 | } |
| 26 | | |
34472878RedMickey5 years ago | 27 | export default customRequire; |