Add require.getModules

Summary:
In order to aid with debugging inline requires we add a method that
will give us the modules.

**Summary**

I was looking for a way to see what modules had been loaded when I was working with inline requires. I had tried using beginEvent on Systrace, but I was worried that there were modules that I might have missed (I'm not certain if all the loaded files are polyfills before the entryFile is invoked for instance). By adding getModules() it simplifies seeing what modules are loaded.

**Test plan**

At the root of my app `index.ios.js`:

```

import App from './App';
import { AppRegistry } from 'react-native';

AppRegistry.registerComponent('App', () => App);

// after 3 seconds the initial app data should have loaded, so lets take a look:
setTimeout(() => {
  console.log(require.getModules());
}, 3000);

```

**NOTE**
If there is a way to get to this easily (via the debugger or some other mechanism) I would be happy to use that instead and add documentation for it.
Closes https://github.com/facebook/metro-bundler/pull/37

Differential Revision: D6008180

Pulled By: cpojer

fbshipit-source-id: 850103bbce166bf65a0cbd710582198c66273db5
This commit is contained in:
Daniel Mueller 2017-10-09 07:59:51 -07:00 committed by Facebook Github Bot
parent c4307d7170
commit 475a580569
2 changed files with 12 additions and 0 deletions

View File

@ -234,6 +234,10 @@ function moduleThrewError(id, error: any) {
if (__DEV__) {
require.Systrace = {beginEvent: () => {}, endEvent: () => {}};
require.getModules = () => {
return modules;
};
// HOT MODULE RELOADING
var createHotReloadingObject = function() {
const hot: HotModuleReloadingData = {

View File

@ -159,6 +159,10 @@ if (__DEV__) {
(function () {
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
_require.getModules = function () {
return modules;
};
createHotReloadingObject = function createHotReloadingObject() {
var hot = {
acceptCallback: null,
@ -437,6 +441,10 @@ if (__DEV__) {
(function () {
_require.Systrace = { beginEvent: function beginEvent() {}, endEvent: function endEvent() {} };
_require.getModules = function () {
return modules;
};
createHotReloadingObject = function createHotReloadingObject() {
var hot = {
acceptCallback: null,