Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Object {
},
"serializer": Object {
"createModuleIdFactory": [Function],
"customSerializer": null,
"experimentalSerializerHook": [Function],
"getModulesRunBeforeMainModule": [Function],
"getPolyfills": [Function],
Expand Down Expand Up @@ -184,6 +185,7 @@ Object {
},
"serializer": Object {
"createModuleIdFactory": [Function],
"customSerializer": null,
"experimentalSerializerHook": [Function],
"getModulesRunBeforeMainModule": [Function],
"getPolyfills": [Function],
Expand Down
7 changes: 7 additions & 0 deletions packages/metro-config/src/configTypes.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {TransformVariants} from 'metro/src/ModuleGraph/types.flow.js';
import type {DynamicRequiresBehavior} from 'metro/src/ModuleGraph/worker/collectDependencies';
import type Server from 'metro/src/Server';
import type {Reporter} from 'metro/src/lib/reporting';
import type {Options} from 'metro/src/DeltaBundler/Serializers/plainJSBundle';

export type PostMinifyProcess = ({
code: string,
Expand Down Expand Up @@ -115,6 +116,12 @@ type ResolverConfigT = {|

type SerializerConfigT = {|
createModuleIdFactory: () => (path: string) => number,
customSerializer: ?(
entryPoint: string,
preModules: $ReadOnlyArray<Module<>>,
graph: Graph<>,
options: Options,
) => string,
experimentalSerializerHook: (graph: Graph<>, delta: DeltaResult<>) => mixed,
getModulesRunBeforeMainModule: (entryFilePath: string) => Array<string>,
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
Expand Down
1 change: 1 addition & 0 deletions packages/metro-config/src/convertConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async function convertOldToNew({
useWatchman: true,
},
serializer: {
customSerializer: defaultConfig.serializer.customSerializer,
createModuleIdFactory:
createModuleIdFactory || defaultConfig.serializer.createModuleIdFactory,
polyfillModuleNames: getPolyfillModuleNames(),
Expand Down
1 change: 1 addition & 0 deletions packages/metro-config/src/defaults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
processModuleFilter: module => true,
createModuleIdFactory: defaultCreateModuleIdFactory,
experimentalSerializerHook: () => {},
customSerializer: null,
},

server: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {isJsModule, wrapModule} = require('./helpers/js');
import type {ModuleMap} from '../../lib/bundle-modules/types.flow';
import type {Graph, Module, SerializerOptions} from '../types.flow';

type Options =
export type Options =
| {|
...SerializerOptions,
embedDelta: false,
Expand Down
11 changes: 9 additions & 2 deletions packages/metro/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ class Server {
inlineSourceMap: serializerOptions.inlineSourceMap,
};

const bundle = plainJSBundle(
const serializerArguments = [
entryFile,
revision.prepend,
revision.graph,
Expand All @@ -689,7 +689,14 @@ class Server {
revisionId: revision.id,
})
: Object.assign({}, options, {embedDelta: false}),
);
];
let bundle;
const possibleCustomSerializer = this._config.serializer.customSerializer;
if (possibleCustomSerializer) {
bundle = possibleCustomSerializer(...serializerArguments);
} else {
bundle = plainJSBundle(...serializerArguments);
}

return {
numModifiedFiles: delta.reset
Expand Down