diff --git a/packager/react-packager/src/ModuleGraph/output/__tests__/util-test.js b/packager/react-packager/src/ModuleGraph/output/__tests__/util-test.js index 5704a90f3..6984b76f3 100644 --- a/packager/react-packager/src/ModuleGraph/output/__tests__/util-test.js +++ b/packager/react-packager/src/ModuleGraph/output/__tests__/util-test.js @@ -40,13 +40,13 @@ describe('`addModuleIdsToModuleWrapper`:', () => { .withArgs(match({path: dependencies[1].path})).returns(6); expect(addModuleIdsToModuleWrapper(module, idForPath)) - .toEqual('__d(function(){}, 12, [345, 6]);'); + .toEqual('__d(function(){},12,[345,6]);'); }); it('omits the array of dependency IDs if it is empty', () => { const module = createModule(); expect(addModuleIdsToModuleWrapper(module, () => 98)) - .toEqual(`__d(function(){}, ${98});`); + .toEqual(`__d(function(){},${98});`); }); }); diff --git a/packager/react-packager/src/ModuleGraph/output/util.js b/packager/react-packager/src/ModuleGraph/output/util.js index d883a748d..23065d245 100644 --- a/packager/react-packager/src/ModuleGraph/output/util.js +++ b/packager/react-packager/src/ModuleGraph/output/util.js @@ -26,11 +26,19 @@ exports.addModuleIdsToModuleWrapper = ( const {dependencies, file} = module; const {code} = file; const index = code.lastIndexOf(')'); + + // calling `idForPath` on the module itself first gives us a lower module id + // for the file itself than for its dependencies. That reflects their order + // in the bundle. + const fileId = idForPath(file); + + // This code runs for both development and production builds, after + // minification. That's why we leave out all spaces. const depencyIds = - dependencies.length ? `, [${dependencies.map(idForPath).join(', ')}]` : ''; + dependencies.length ? `,[${dependencies.map(idForPath).join(',')}]` : ''; return ( code.slice(0, index) + - `, ${idForPath(file)}` + + `,${fileId}` + depencyIds + code.slice(index) );