Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local-cli assetRegistryPath and middlewares #20162

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions local-cli/server/middleware/MiddlewareManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const indexPageMiddleware = require('./indexPage');
const copyToClipBoardMiddleware = require('./copyToClipBoardMiddleware');
const loadRawBodyMiddleware = require('./loadRawBodyMiddleware');
const openStackFrameInEditorMiddleware = require('./openStackFrameInEditorMiddleware');
const statusPageMiddleware = require('./statusPageMiddleware.js');
const systraceProfileMiddleware = require('./systraceProfileMiddleware.js');
const statusPageMiddleware = require('./statusPageMiddleware');
const systraceProfileMiddleware = require('./systraceProfileMiddleware');
const getDevToolsMiddleware = require('./getDevToolsMiddleware');

type Options = {
Expand Down
28 changes: 21 additions & 7 deletions local-cli/server/runServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ const Metro = require('metro');

const {Terminal} = require('metro-core');

const messageSocket = require('./util/messageSocket');
const morgan = require('morgan');
const path = require('path');
const webSocketProxy = require('./util/webSocketProxy');
const MiddlewareManager = require('./middleware/MiddlewareManager');

const {ASSET_REGISTRY_PATH} = require('../core/Constants');

import type {ConfigT} from 'metro';

export type Args = {|
Expand Down Expand Up @@ -55,21 +59,31 @@ async function runServer(args: Args, config: ConfigT) {
const serverInstance = await Metro.runServer({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error ---------- local-cli/server/runServer.js:59:48
Cannot call `Metro.runServer` with object literal bound to the first parameter because property `watch` is missing in `RunServerOptions` [1] but exists in object literal [2].

                                                     v
  59|   const serverInstance = await Metro.runServer({
  60|     config: {
  61|       ...config,
    :
  77|     watch: !args.nonPersistent,
  78|   });
      --^

References:
  metro/packages/metro/src/index.js:201:4
  201| }: RunServerOptions) => {
          ^^^^^^^^^^^^^^^^ [1]
                                                     v
  59|   const serverInstance = await Metro.runServer({
  60|     config: {
  61|       ...config,
    :
  77|     watch: !args.nonPersistent,
  78|   });
      --^ [2]

config: {
...config,
hmrEnabled: true,
maxWorkers: args.maxWorkers,
reporter,
secure: args.https,
secureKey: args.key,
secureCert: args.cert,
assetRegistryPath: ASSET_REGISTRY_PATH,
enhanceMiddleware: middleware =>
middlewareManager.getConnectInstance().use(middleware),
transformModulePath: args.transformer
? path.resolve(args.transformer)
: config.getTransformModulePath(),
watch: !args.nonPersistent,
},
hmrEnabled: true,
host: args.host,
maxWorkers: args.maxWorkers,
port: args.port,
reporter,
secure: args.https,
secureCert: args.cert,
secureKey: args.key,
});

const wsProxy = webSocketProxy.attachToServer(
serverInstance,
'/debugger-proxy',
);
const ms = messageSocket.attachToServer(serverInstance, '/message');
middlewareManager.attachDevToolsSocket(wsProxy);
middlewareManager.attachDevToolsSocket(ms);

// In Node 8, the default keep-alive for an HTTP connection is 5 seconds. In
// early versions of Node 8, this was implemented in a buggy way which caused
// some HTTP responses (like those containing large JS bundles) to be
Expand Down