diff --git a/packages/metro/src/lib/polyfills/__tests__/require-test.js b/packages/metro/src/lib/polyfills/__tests__/require-test.js index 7d8e29b47f..a04b9c76d4 100644 --- a/packages/metro/src/lib/polyfills/__tests__/require-test.js +++ b/packages/metro/src/lib/polyfills/__tests__/require-test.js @@ -226,34 +226,34 @@ describe('require', () => { moduleSystem.__r(0); }); - it('exposes module.id as path on the module in dev mode', () => { + it('exposes module.id as moduleId on the module in dev mode', () => { createModuleSystem(moduleSystem, true); createModule( moduleSystem, - 0, + 1254, 'index.js', (global, require, importDefault, importAll, module) => { module.exports = module.id; }, ); - expect(moduleSystem.__r(0)).toEqual('index.js'); + expect(moduleSystem.__r(1254)).toEqual(1254); }); - it("doesn't expose module.id as moduleId on the module in prod mode", () => { + it('exposes module.id as moduleId on the module in prod mode', () => { createModuleSystem(moduleSystem, false); createModule( moduleSystem, - 0, + 1337, 'index.js', (global, require, importDefault, importAll, module) => { module.exports = module.id; }, ); - expect(moduleSystem.__r(0)).toBeUndefined(); + expect(moduleSystem.__r(1337)).toEqual(1337); }); it('handles requires/exports correctly', () => { @@ -441,7 +441,7 @@ describe('require', () => { expect(moduleSystem.__r(0)).toEqual('foo'); hook.release(); expect(moduleSystem.__r(1)).toEqual('bar'); - expect(received).toEqual([[0, {exports: 'foo'}]]); + expect(received).toEqual([[0, {exports: 'foo', id: 0}]]); }); }); diff --git a/packages/metro/src/lib/polyfills/require.js b/packages/metro/src/lib/polyfills/require.js index c24b403dd1..4e63923750 100644 --- a/packages/metro/src/lib/polyfills/require.js +++ b/packages/metro/src/lib/polyfills/require.js @@ -34,12 +34,12 @@ type HotModuleReloadingData = {| disposeCallback: ?HotModuleReloadingCallback, dispose: (callback: HotModuleReloadingCallback) => void, |}; +type ModuleID = number; type Module = { - id?: string, + id?: ModuleID, exports: Exports, hot?: HotModuleReloadingData, }; -type ModuleID = number; type ModuleDefinition = {| dependencyMap: ?DependencyMap, error?: any, @@ -341,12 +341,11 @@ function loadModuleImplementation(moduleId, module) { const moduleObject: Module = module.publicModule; if (__DEV__) { - moduleObject.id = module.verboseName || moduleObject.id; - if (module.hot) { moduleObject.hot = module.hot; } } + moduleObject.id = moduleId; if (hooks.length > 0) { for (let i = 0; i < hooks.length; ++i) {