Skip to content

Commit

Permalink
Add module.id param to production bundles
Browse files Browse the repository at this point in the history
Reviewed By: mjesun

Differential Revision: D10083505

fbshipit-source-id: fd49e5e1ab5f30b5f2ebb10c94e52f710cd9dfbf
  • Loading branch information
rafeca authored and facebook-github-bot committed Sep 27, 2018
1 parent 66aa795 commit e87eaf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
14 changes: 7 additions & 7 deletions packages/metro/src/lib/polyfills/__tests__/require-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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}]]);
});
});

Expand Down
7 changes: 3 additions & 4 deletions packages/metro/src/lib/polyfills/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e87eaf3

Please sign in to comment.