Skip to content

Commit

Permalink
Resolve webpack dynamic require problem, add additional attribution
Browse files Browse the repository at this point in the history
  • Loading branch information
SounD120 committed Jun 8, 2020
1 parent 4a3506b commit 47b254b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
15 changes: 15 additions & 0 deletions release/AdditionalAttributions.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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 <sindresorhus@gmail.com> (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
17 changes: 17 additions & 0 deletions 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;
8 changes: 5 additions & 3 deletions src/extension/exponent/xdlInterface.ts
Expand Up @@ -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();

Expand All @@ -26,7 +28,7 @@ function getPackage(): Q.Promise<typeof XDLPackage> {
// 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) {
Expand All @@ -36,12 +38,12 @@ function getPackage(): Q.Promise<typeof XDLPackage> {
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;
}
Expand Down

0 comments on commit 47b254b

Please sign in to comment.