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