Skip to content

Commit

Permalink
Move experimentalImportBundleSupport option from transformer to server
Browse files Browse the repository at this point in the history
Summary:
`experimentalImportBundleSupport` (introduced in D15943150 (72329d0)) is never used to change the transformer's output for a given module, so having it under `transformer` is (1) confusing and (2) inefficient, because it gets added to the transformer cache key and therefore forks the transformer cache. Here we move it to `server` while keeping it as an experimental, undocumented option (for now).

This change removes one of the blockers to officially releasing this feature in open source: `metro build` only ever makes sense with `experimentalImportBundleSupport: false`, but prior to this diff, it couldn't share a cache with `metro serve` running with `experimentalImportBundleSupport: true` - so enabling this feature in the server would have regressed Metro's overall perceived performance on a given machine.

Changelog: [Internal]

Reviewed By: jacdebug

Differential Revision: D40389568

fbshipit-source-id: 644d070ff069e8396b9f44e8429147a42727eb5f
  • Loading branch information
motiz88 authored and facebook-github-bot committed Oct 18, 2022
1 parent a557c3c commit 3c0e1f7
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Object {
},
"server": Object {
"enhanceMiddleware": [Function],
"experimentalImportBundleSupport": false,
"port": 8080,
"rewriteRequestUrl": [Function],
"runInspectorProxy": true,
Expand All @@ -108,7 +109,6 @@ Object {
"dynamicDepsInPackages": "throwAtRuntime",
"enableBabelRCLookup": true,
"enableBabelRuntime": true,
"experimentalImportBundleSupport": false,
"getTransformOptions": [Function],
"globalPrefix": "",
"hermesParser": false,
Expand Down Expand Up @@ -255,6 +255,7 @@ Object {
},
"server": Object {
"enhanceMiddleware": [Function],
"experimentalImportBundleSupport": false,
"port": 8080,
"rewriteRequestUrl": [Function],
"runInspectorProxy": true,
Expand All @@ -275,7 +276,6 @@ Object {
"dynamicDepsInPackages": "throwAtRuntime",
"enableBabelRCLookup": true,
"enableBabelRuntime": true,
"experimentalImportBundleSupport": false,
"getTransformOptions": [Function],
"globalPrefix": "",
"hermesParser": false,
Expand Down Expand Up @@ -422,6 +422,7 @@ Object {
},
"server": Object {
"enhanceMiddleware": [Function],
"experimentalImportBundleSupport": false,
"port": 8080,
"rewriteRequestUrl": [Function],
"runInspectorProxy": true,
Expand All @@ -442,7 +443,6 @@ Object {
"dynamicDepsInPackages": "throwAtRuntime",
"enableBabelRCLookup": true,
"enableBabelRuntime": true,
"experimentalImportBundleSupport": false,
"getTransformOptions": [Function],
"globalPrefix": "",
"hermesParser": false,
Expand Down Expand Up @@ -589,6 +589,7 @@ Object {
},
"server": Object {
"enhanceMiddleware": [Function],
"experimentalImportBundleSupport": false,
"port": 8080,
"rewriteRequestUrl": [Function],
"runInspectorProxy": true,
Expand All @@ -609,7 +610,6 @@ Object {
"dynamicDepsInPackages": "throwAtRuntime",
"enableBabelRCLookup": true,
"enableBabelRuntime": true,
"experimentalImportBundleSupport": false,
"getTransformOptions": [Function],
"globalPrefix": "",
"hermesParser": false,
Expand Down
6 changes: 3 additions & 3 deletions packages/metro-config/src/configTypes.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ type TransformerConfigT = {
transformVariants: TransformVariants,
workerPath: string,
publicPath: string,
experimentalImportBundleSupport: boolean,
};

type MetalConfigT = {
Expand All @@ -152,11 +151,12 @@ type MetalConfigT = {

type ServerConfigT = {
enhanceMiddleware: (Middleware, Server) => Middleware,
useGlobalHotkey: boolean,
experimentalImportBundleSupport: boolean,
port: number,
unstable_serverRoot: ?string,
rewriteRequestUrl: string => string,
runInspectorProxy: boolean,
unstable_serverRoot: ?string,
useGlobalHotkey: boolean,
verifyConnections: boolean,
};

Expand Down
8 changes: 4 additions & 4 deletions packages/metro-config/src/defaults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
},

server: {
useGlobalHotkey: true,
port: 8080,
enhanceMiddleware: middleware => middleware,
experimentalImportBundleSupport: false,
port: 8080,
rewriteRequestUrl: url => url,
runInspectorProxy: true,
verifyConnections: false,
unstable_serverRoot: null,
useGlobalHotkey: true,
verifyConnections: false,
},

symbolicator: {
Expand All @@ -86,7 +87,6 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
dynamicDepsInPackages: 'throwAtRuntime',
enableBabelRCLookup: true,
enableBabelRuntime: true,
experimentalImportBundleSupport: false,
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const baseConfig: JsTransformerConfig = {
dynamicDepsInPackages: 'reject',
enableBabelRCLookup: false,
enableBabelRuntime: true,
experimentalImportBundleSupport: false,
globalPrefix: '',
hermesParser: false,
minifierConfig: {},
Expand Down
1 change: 0 additions & 1 deletion packages/metro-transform-worker/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export type JsTransformerConfig = $ReadOnly<{
dynamicDepsInPackages: DynamicRequiresBehavior,
enableBabelRCLookup: boolean,
enableBabelRuntime: boolean | string,
experimentalImportBundleSupport: boolean,
globalPrefix: string,
hermesParser: boolean,
minifierConfig: MinifierConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/metro/src/HmrServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class HmrServer<TClient: Client> {
resolverOptions,
shallow: graphOptions.shallow,
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
this._config.server.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/metro/src/IncrementalBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class IncrementalBundler {
transformOptions,
onProgress: otherOptions.onProgress,
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
this._config.server.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
shallow: otherOptions.shallow,
Expand Down Expand Up @@ -173,7 +173,7 @@ class IncrementalBundler {
transformOptions,
onProgress: otherOptions.onProgress,
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
this._config.server.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
shallow: otherOptions.shallow,
Expand Down Expand Up @@ -234,7 +234,7 @@ class IncrementalBundler {
resolverOptions,
shallow: otherOptions.shallow,
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
this._config.server.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/metro/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class Server {
});
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
this._config.server.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
resolverOptions,
Expand Down Expand Up @@ -1231,7 +1231,7 @@ class Server {

const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
this._config.server.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
resolverOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/metro/src/__tests__/HmrServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ describe('HmrServer', () => {
serializer: {experimentalSerializerHook: () => {}},
reporter: {update: jest.fn()},
transformer: {
experimentalImportBundleSupport: false,
unstable_allowRequireContext: false,
},
resolver: {platforms: []},
server: {
experimentalImportBundleSupport: false,
rewriteRequestUrl(requrl) {
const rewritten = requrl.replace(
/__REMOVE_THIS_WHEN_REWRITING__/g,
Expand Down
2 changes: 1 addition & 1 deletion packages/metro/src/lib/getPrependedScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function getPrependedScripts(
transformOptions,
onProgress: null,
experimentalImportBundleSupport:
config.transformer.experimentalImportBundleSupport,
config.server.experimentalImportBundleSupport,
shallow: false,
},
);
Expand Down
2 changes: 1 addition & 1 deletion packages/metro/src/lib/transformHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function calcTransformerOptions(
transformOptions: options,
onProgress: null,
experimentalImportBundleSupport:
config.transformer.experimentalImportBundleSupport,
config.server.experimentalImportBundleSupport,
unstable_allowRequireContext:
config.transformer.unstable_allowRequireContext,
shallow: false,
Expand Down

0 comments on commit 3c0e1f7

Please sign in to comment.