Skip to content

Commit

Permalink
create build number as a source of truth for bundle id
Browse files Browse the repository at this point in the history
Summary:
Using build number for bundle id, rename buildID to buildNumber and pass string casted build number for reportor api

Changelog: [Internal]

Reviewed By: arushikesarwani94

Differential Revision: D40636993

fbshipit-source-id: c8a4093b84b43ff6df161620aa823917ade3b89b
  • Loading branch information
jacdebug authored and facebook-github-bot committed Oct 25, 2022
1 parent a66aeb3 commit 455c40c
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions packages/metro/src/Server.js
Expand Up @@ -89,7 +89,7 @@ export type BundleMetadata = {
};

type ProcessStartContext = {
+buildID: string,
+buildNumber: number,
+bundleOptions: BundleOptions,
+graphId: GraphId,
+graphOptions: GraphOptions,
Expand Down Expand Up @@ -129,7 +129,7 @@ class Server {
_createModuleId: (path: string) => number;
_isEnded: boolean;
_logger: typeof Logger;
_nextBundleBuildID: number;
_nextBundleBuildNumber: number;
_platforms: Set<string>;
_reporter: Reporter;
_serverOptions: ServerOptions | void;
Expand Down Expand Up @@ -159,7 +159,7 @@ class Server {
hasReducedPerformance: options && options.hasReducedPerformance,
watch: options ? options.watch : undefined,
});
this._nextBundleBuildID = 1;
this._nextBundleBuildNumber = 1;
}

end() {
Expand Down Expand Up @@ -603,7 +603,7 @@ class Server {
}

const mres = MultipartResponse.wrapIfSupported(req, res);
const buildID = this.getNewBuildID();
const buildNumber = this.getNewBuildNumber();

let onProgress = null;
let lastProgress = -1;
Expand Down Expand Up @@ -644,7 +644,7 @@ class Server {
}

this._reporter.update({
buildID,
buildID: getBuildID(buildNumber),
type: 'bundle_transform_progressed',
transformedFileCount,
totalFileCount,
Expand All @@ -653,7 +653,7 @@ class Server {
}

this._reporter.update({
buildID,
buildID: getBuildID(buildNumber),
bundleDetails: {
bundleType: bundleOptions.bundleType,
dev: transformOptions.dev,
Expand All @@ -667,7 +667,7 @@ class Server {
});

const startContext = {
buildID,
buildNumber,
bundleOptions,
entryFile: resolvedEntryFilePath,
graphId,
Expand Down Expand Up @@ -696,7 +696,7 @@ class Server {
mres.end(JSON.stringify(formattedError));

this._reporter.update({
buildID,
buildID: getBuildID(buildNumber),
type: 'bundle_build_failed',
bundleOptions,
});
Expand All @@ -708,7 +708,7 @@ class Server {
error_type: formattedError.type,
log_entry_label: 'bundling_error',
bundle_id: graphId,
build_id: buildID,
build_id: getBuildID(buildNumber),
stack: formattedError.message,
});

Expand All @@ -724,7 +724,7 @@ class Server {
finish(endContext);

this._reporter.update({
buildID,
buildID: getBuildID(buildNumber),
type: 'bundle_build_done',
});

Expand All @@ -751,7 +751,7 @@ class Server {
bundle_url: context.req.url,
entry_point: context.entryFile,
bundler: 'delta',
build_id: context.buildID,
build_id: getBuildID(context.buildNumber),
bundle_options: context.bundleOptions,
bundle_hash: context.graphId,
};
Expand Down Expand Up @@ -882,7 +882,7 @@ class Server {
bundle_url: context.req.url,
entry_point: context.entryFile,
bundler: 'delta',
build_id: context.buildID,
build_id: getBuildID(context.buildNumber),
bundle_options: context.bundleOptions,
bundle_hash: context.graphId,
};
Expand Down Expand Up @@ -1287,8 +1287,8 @@ class Server {
return resolutionFn(`${rootDir}/.`, filePath);
}

getNewBuildID(): string {
return (this._nextBundleBuildID++).toString(36);
getNewBuildNumber(): number {
return this._nextBundleBuildNumber++;
}

getPlatforms(): $ReadOnlyArray<string> {
Expand Down Expand Up @@ -1365,4 +1365,8 @@ function* zip<X, Y>(xs: Iterable<X>, ys: Iterable<Y>): Iterable<[X, Y]> {
}
}

function getBuildID(buildNumber: number): string {
return buildNumber.toString(36);
}

module.exports = Server;

0 comments on commit 455c40c

Please sign in to comment.