Use default Metro implementation of source module ID mappings for "flipper-pkg bundle"

Summary: Use default Metro implementation of source module ID mappings for "flipper-pkg bundle". The problem with the custom implementation we used before is that it is not deterministic, i.e. produced bundles are different on different machines. We need deterministic bundles to reliably detect if the version changed from the last deployment to Marketplace.

Reviewed By: mweststrate

Differential Revision: D22158794

fbshipit-source-id: ae4b4b05e020489c0900423107a938a5b670e7d8
This commit is contained in:
Anton Nikolaev
2020-06-22 02:39:30 -07:00
committed by Facebook GitHub Bot
parent 21ab8dc25c
commit c359d666c5

View File

@@ -29,32 +29,6 @@ async function getMetroDir() {
return __dirname; return __dirname;
} }
function hash(string: string) {
let hash = 0;
if (string.length === 0) {
return hash;
}
let chr;
for (let i = 0; i < string.length; i++) {
chr = string.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0;
}
return hash;
}
const fileToIdMap = new Map();
const createModuleIdFactory = () => (filePath: string) => {
if (filePath === '__prelude__') {
return 0;
}
let id = fileToIdMap.get(filePath);
if (typeof id !== 'number') {
id = hash(filePath);
fileToIdMap.set(filePath, id);
}
return id;
};
export default async function runBuild( export default async function runBuild(
inputDirectory: string, inputDirectory: string,
entry: string, entry: string,
@@ -72,7 +46,6 @@ export default async function runBuild(
...baseConfig.serializer, ...baseConfig.serializer,
getRunModuleStatement: (moduleID: string) => getRunModuleStatement: (moduleID: string) =>
`module.exports = global.__r(${moduleID}).default;`, `module.exports = global.__r(${moduleID}).default;`,
createModuleIdFactory,
}, },
transformer: { transformer: {
...baseConfig.transformer, ...baseConfig.transformer,