diff --git a/release/AdditionalAttributions.txt b/release/AdditionalAttributions.txt index df4aa87e0..e08c92968 100644 --- a/release/AdditionalAttributions.txt +++ b/release/AdditionalAttributions.txt @@ -2,6 +2,7 @@ 2. TACO Tools for Apache Cordova (https://github.com/Microsoft/TACO) 3. React Native command line tools (https://github.com/react-native-community/react-native-cli) 4. Expo XDL (https://github.com/expo/expo-cli/tree/master/packages/xdl) +5. OW (https://github.com/sindresorhus/ow) %% DefinitelyTyped NOTICES, INFORMATION, AND LICENSE BEGIN HERE @@ -123,3 +124,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ========================================= END OF Expo XDL NOTICES, INFORMATION, AND LICENSE + +%% ow NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +MIT License + +Copyright (c) Sindre Sorhus (https://sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================= +END OF ow NOTICES, INFORMATION, AND LICENSE diff --git a/src/common/customRequire.ts b/src/common/customRequire.ts new file mode 100644 index 000000000..7365ffbd3 --- /dev/null +++ b/src/common/customRequire.ts @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +// Portion of code was taken from https://github.com/sindresorhus/ow/blob/d62a06c192b892d504887f0b97fdc842e8cbf862/source/utils/node/require.ts +let customRequire: (packageName: string) => any; + +try { + // Export `__non_webpack_require__` in Webpack environments to make sure it doesn't bundle modules loaded via this method + customRequire = (global as any).__non_webpack_require__ === 'function' + ? (global as any).__non_webpack_require__ + : eval('require'); // tslint:disable-line:no-eval +} catch { + // Use a noop in case both `__non_webpack_require__` and `require` does not exist + customRequire = () => {}; // tslint:disable-line:no-empty +} + +export default customRequire; \ No newline at end of file diff --git a/src/extension/exponent/xdlInterface.ts b/src/extension/exponent/xdlInterface.ts index 4a7ddcaee..2f23f8f46 100644 --- a/src/extension/exponent/xdlInterface.ts +++ b/src/extension/exponent/xdlInterface.ts @@ -8,6 +8,8 @@ import {OutputChannelLogger} from "../log/OutputChannelLogger"; import * as XDLPackage from "xdl"; import * as path from "path"; import * as Q from "q"; +import { findFileInFolderHierarchy } from "../../common/extensionHelper"; +import customRequire from "../../common/customRequire"; const logger: OutputChannelLogger = OutputChannelLogger.getMainChannel(); @@ -26,7 +28,7 @@ function getPackage(): Q.Promise { // Don't do the require if we don't actually need it try { logger.debug("Getting exponent dependency."); - const xdl = require(XDL_PACKAGE); + const xdl = customRequire(XDL_PACKAGE); xdlPackage = Q(xdl); return xdlPackage; } catch (e) { @@ -36,12 +38,12 @@ function getPackage(): Q.Promise { throw e; } } - let commandExecutor = new CommandExecutor(path.dirname(path.join(__dirname, "..", "..", "..")), logger); + let commandExecutor = new CommandExecutor(path.dirname(findFileInFolderHierarchy(__dirname, "package.json") || ""), logger); xdlPackage = commandExecutor.spawnWithProgress(HostPlatform.getNpmCliCommand("npm"), ["install", ...EXPO_DEPS, "--verbose", "--no-save"], { verbosity: CommandVerbosity.PROGRESS }) .then((): typeof XDLPackage => { - return require(XDL_PACKAGE); + return customRequire(XDL_PACKAGE); }); return xdlPackage; }