@callstack/repack-dev-server 5.0.0-rc.10 → 5.0.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Callstack
3
+ Copyright (c) 2025 Callstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,32 +1,27 @@
1
- <p align="center">
2
- <img src="https://raw.githubusercontent.com/callstack/repack/HEAD/logo.png">
3
- </p>
4
- <p align="center">
5
- A toolkit to build your React Native application with Rspack or Webpack.
6
- </p>
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/callstack/repack/HEAD/logo.png" width="650" alt="Re.Pack logo" />
3
+ <h3>A toolkit to build your React Native application with Rspack or Webpack.</h3>
4
+ </div>
5
+ <div align="center">
7
6
 
8
- ---
9
-
10
- [![Build Status][build-badge]][build]
11
- [![Version][version-badge]][version]
12
- [![MIT License][license-badge]][license]
7
+ [![mit licence][license-badge]][license]
8
+ [![npm downloads][npm-downloads-badge]][npm-downloads]
9
+ [![Chat][chat-badge]][chat]
13
10
  [![PRs Welcome][prs-welcome-badge]][prs-welcome]
14
- [![Code of Conduct][coc-badge]][coc]
15
11
 
16
- `@callstack/repack-dev-sever` is bundler-agnostic development server for React Native applications as part of `@callstack/repack`.
12
+ </div>
13
+
14
+ `@callstack/repack-dev-server` is a bundler-agnostic development server for React Native applications as part of [`@callstack/repack`](https://github.com/callstack/repack).
17
15
 
18
16
  Check out our website at https://re-pack.dev for more info and documentation or out GitHub: https://github.com/callstack/repack.
19
17
 
20
18
  <!-- badges -->
21
19
 
22
- [callstack-readme-with-love]: https://callstack.com/?utm_source=github.com&utm_medium=referral&utm_campaign=react-native-paper&utm_term=readme-with-love
23
- [build-badge]: https://img.shields.io/github/workflow/status/callstack/repack/CI/main?style=flat-square
24
- [build]: https://github.com/callstack/repack/actions/workflows/main.yml
25
- [version-badge]: https://img.shields.io/npm/v/@callstack/repack-dev-server?style=flat-square
26
- [version]: https://www.npmjs.com/package/@callstack/repack-dev-server
27
- [license-badge]: https://img.shields.io/npm/l/@callstack/repack-debugger-app?style=flat-square
28
- [license]: https://github.com/callstack/repack/blob/master/LICENSE
29
- [prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
20
+ [license-badge]: https://img.shields.io/npm/l/@callstack/repack?style=for-the-badge
21
+ [license]: https://github.com/callstack/repack/blob/main/LICENSE
22
+ [npm-downloads-badge]: https://img.shields.io/npm/dm/@callstack/repack?style=for-the-badge
23
+ [npm-downloads]: https://www.npmjs.com/package/@callstack/repack
24
+ [prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge
30
25
  [prs-welcome]: ./CONTRIBUTING.md
31
- [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
32
- [coc]: https://github.com/callstack/repack/blob/master/CODE_OF_CONDUCT.md
26
+ [chat-badge]: https://img.shields.io/discord/426714625279524876.svg?style=for-the-badge
27
+ [chat]: https://discord.gg/Q4yr2rTWYF
@@ -11,6 +11,7 @@ import multipartPlugin from './plugins/multipart/multipartPlugin.js';
11
11
  import symbolicatePlugin from './plugins/symbolicate/sybmolicatePlugin.js';
12
12
  import wssPlugin from './plugins/wss/wssPlugin.js';
13
13
  import { Internal } from './types.js';
14
+ import { normalizeOptions } from './utils/normalizeOptions.js';
14
15
  /**
15
16
  * Create instance of development server, powered by Fastify.
16
17
  *
@@ -20,9 +21,10 @@ import { Internal } from './types.js';
20
21
  export async function createServer(config) {
21
22
  // biome-ignore lint/style/useConst: needed in fastify constructor
22
23
  let delegate;
24
+ const options = normalizeOptions(config.options);
23
25
  /** Fastify instance powering the development server. */
24
26
  const instance = Fastify({
25
- disableRequestLogging: !config.options.logRequests,
27
+ disableRequestLogging: options.disableRequestLogging,
26
28
  logger: {
27
29
  level: 'trace',
28
30
  stream: new Writable({
@@ -34,9 +36,10 @@ export async function createServer(config) {
34
36
  },
35
37
  }),
36
38
  },
37
- ...(config.options.https ? { https: config.options.https } : undefined),
39
+ ...(options.https ? { https: options.https } : {}),
38
40
  });
39
- delegate = await config.delegate({
41
+ delegate = config.delegate({
42
+ options,
40
43
  log: instance.log,
41
44
  notifyBuildStart: (platform) => {
42
45
  instance.wss.apiServer.send({
@@ -58,8 +61,8 @@ export async function createServer(config) {
58
61
  },
59
62
  });
60
63
  const devMiddleware = createDevMiddleware({
61
- projectRoot: config.options.rootDir,
62
- serverBaseUrl: `http://${config.options.host}:${config.options.port}`,
64
+ projectRoot: options.rootDir,
65
+ serverBaseUrl: options.url,
63
66
  logger: instance.log,
64
67
  unstable_experiments: {
65
68
  // @ts-expect-error removed in 0.76, keep this for backkwards compatibility
@@ -70,11 +73,8 @@ export async function createServer(config) {
70
73
  await instance.register(fastifySensible);
71
74
  await instance.register(middie);
72
75
  await instance.register(wssPlugin, {
73
- options: {
74
- ...config.options,
75
- endpoints: devMiddleware.websocketEndpoints,
76
- },
77
76
  delegate,
77
+ endpoints: devMiddleware.websocketEndpoints,
78
78
  });
79
79
  await instance.register(multipartPlugin);
80
80
  await instance.register(apiPlugin, {
@@ -85,7 +85,7 @@ export async function createServer(config) {
85
85
  delegate,
86
86
  });
87
87
  await instance.register(devtoolsPlugin, {
88
- options: config.options,
88
+ rootDir: options.rootDir,
89
89
  });
90
90
  await instance.register(symbolicatePlugin, {
91
91
  delegate,
@@ -95,7 +95,7 @@ export async function createServer(config) {
95
95
  await instance.register(faviconPlugin);
96
96
  instance.addHook('onSend', async (request, reply, payload) => {
97
97
  reply.header('X-Content-Type-Options', 'nosniff');
98
- reply.header('X-React-Native-Project-Root', config.options.rootDir);
98
+ reply.header('X-React-Native-Project-Root', options.rootDir);
99
99
  const [pathname] = request.url.split('?');
100
100
  if (pathname.endsWith('.map')) {
101
101
  reply.header('Access-Control-Allow-Origin', 'devtools://devtools');
@@ -110,8 +110,8 @@ export async function createServer(config) {
110
110
  /** Start the development server. */
111
111
  async function start() {
112
112
  await instance.listen({
113
- port: config.options.port,
114
- host: config.options.host,
113
+ port: options.port,
114
+ host: options.host,
115
115
  });
116
116
  }
117
117
  /** Stop the development server. */
@@ -1,7 +1,6 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
- import type { Server } from '../../types.js';
3
- declare function devtoolsPlugin(instance: FastifyInstance, { options }: {
4
- options: Server.Options;
2
+ declare function devtoolsPlugin(instance: FastifyInstance, { rootDir }: {
3
+ rootDir: string;
5
4
  }): Promise<void>;
6
5
  declare const _default: typeof devtoolsPlugin;
7
6
  export default _default;
@@ -1,9 +1,9 @@
1
1
  import { openStackFrameInEditorMiddleware, openURLMiddleware, } from '@react-native-community/cli-server-api';
2
2
  import fastifyPlugin from 'fastify-plugin';
3
- async function devtoolsPlugin(instance, { options }) {
3
+ async function devtoolsPlugin(instance, { rootDir }) {
4
4
  instance.use('/open-url', openURLMiddleware);
5
5
  instance.use('/open-stack-frame', openStackFrameInEditorMiddleware({
6
- watchFolders: [options.rootDir],
6
+ watchFolders: [rootDir],
7
7
  }));
8
8
  instance.route({
9
9
  method: ['GET', 'POST', 'PUT'],
@@ -1,4 +1,5 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
+ import type { WebSocketServer } from 'ws';
2
3
  import type { Server } from '../../types.js';
3
4
  import { WebSocketRouter } from './WebSocketRouter.js';
4
5
  import { WebSocketServerAdapter } from './WebSocketServerAdapter.js';
@@ -21,9 +22,9 @@ declare module 'fastify' {
21
22
  };
22
23
  }
23
24
  }
24
- declare function wssPlugin(instance: FastifyInstance, { options, delegate, }: {
25
- options: Server.Options;
25
+ declare function wssPlugin(instance: FastifyInstance, { delegate, endpoints, }: {
26
26
  delegate: Server.Delegate;
27
+ endpoints?: Record<string, WebSocketServer>;
27
28
  }): Promise<void>;
28
29
  declare const _default: typeof wssPlugin;
29
30
  export default _default;
@@ -12,7 +12,7 @@ import { WebSocketMessageServer } from './servers/WebSocketMessageServer.js';
12
12
  */
13
13
  const WS_DEVICE_URL = '/inspector/device';
14
14
  const WS_DEBUGGER_URL = '/inspector/debug';
15
- async function wssPlugin(instance, { options, delegate, }) {
15
+ async function wssPlugin(instance, { delegate, endpoints, }) {
16
16
  const router = new WebSocketRouter(instance);
17
17
  const devClientServer = new WebSocketDevClientServer(instance);
18
18
  const messageServer = new WebSocketMessageServer(instance);
@@ -22,8 +22,8 @@ async function wssPlugin(instance, { options, delegate, }) {
22
22
  const apiServer = new WebSocketApiServer(instance);
23
23
  const hmrServer = new WebSocketHMRServer(instance, delegate.hmr);
24
24
  // @react-native/dev-middleware servers
25
- const deviceConnectionServer = new WebSocketServerAdapter(instance, WS_DEVICE_URL, options.endpoints?.[WS_DEVICE_URL]);
26
- const debuggerConnectionServer = new WebSocketServerAdapter(instance, WS_DEBUGGER_URL, options.endpoints?.[WS_DEBUGGER_URL]);
25
+ const deviceConnectionServer = new WebSocketServerAdapter(instance, WS_DEVICE_URL, endpoints?.[WS_DEVICE_URL]);
26
+ const debuggerConnectionServer = new WebSocketServerAdapter(instance, WS_DEBUGGER_URL, endpoints?.[WS_DEBUGGER_URL]);
27
27
  router.registerServer(devClientServer);
28
28
  router.registerServer(messageServer);
29
29
  router.registerServer(eventsServer);
package/dist/types.d.ts CHANGED
@@ -1,11 +1,31 @@
1
+ import type { ServerOptions as HttpsServerOptions } from 'node:https';
1
2
  import type { FastifyBaseLogger } from 'fastify';
2
- import type { WebSocketServer } from 'ws';
3
3
  import type { CompilerDelegate } from './plugins/compiler/types.js';
4
4
  import type { CodeFrame, InputStackFrame, ReactNativeStackFrame, StackFrame, SymbolicatorDelegate, SymbolicatorResults } from './plugins/symbolicate/types.js';
5
5
  import type { HmrDelegate } from './plugins/wss/types.js';
6
+ import type { NormalizedOptions } from './utils/normalizeOptions.js';
6
7
  export type { CompilerDelegate };
7
8
  export type { CodeFrame, InputStackFrame, ReactNativeStackFrame, StackFrame, SymbolicatorDelegate, SymbolicatorResults, };
8
9
  export type { HmrDelegate };
10
+ export interface DevServerOptions {
11
+ /**
12
+ * Hostname or IP address under which to run the development server.
13
+ * Can be 'local-ip', 'local-ipv4', 'local-ipv6' or a custom string.
14
+ * When left unspecified, it will listen on all available network interfaces.
15
+ */
16
+ host?: 'local-ip' | 'local-ipv4' | 'local-ipv6' | string;
17
+ /** Port under which to run the development server. */
18
+ port?: number;
19
+ /** Whether to enable Hot Module Replacement. */
20
+ hot?: boolean;
21
+ /** Options for running the server as HTTPS. If `undefined`, the server will run as HTTP. */
22
+ server?: 'http' | 'https' | {
23
+ type: 'http';
24
+ } | {
25
+ type: 'https';
26
+ options?: HttpsServerOptions;
27
+ };
28
+ }
9
29
  export declare namespace Server {
10
30
  /** Development server configuration. */
11
31
  interface Config {
@@ -15,25 +35,9 @@ export declare namespace Server {
15
35
  delegate: (context: DelegateContext) => Delegate;
16
36
  }
17
37
  /** Development server options. */
18
- interface Options {
38
+ interface Options extends DevServerOptions {
19
39
  /** Root directory of the project. */
20
40
  rootDir: string;
21
- /** Port under which to run the development server. */
22
- port: number;
23
- /**
24
- * Hostname or IP address under which to run the development server.
25
- * When left unspecified, it will listen on all available network interfaces, similarly to listening on '0.0.0.0'.
26
- */
27
- host?: string;
28
- /** Options for running the server as HTTPS. If `undefined`, the server will run as HTTP. */
29
- https?: {
30
- /** Path to certificate when running server as HTTPS. */
31
- cert?: string;
32
- /** Path to certificate key when running server as HTTPS. */
33
- key?: string;
34
- };
35
- /** Additional endpoints with pre-configured servers */
36
- endpoints?: Record<string, WebSocketServer>;
37
41
  /** Whether to enable logging requests. */
38
42
  logRequests?: boolean;
39
43
  }
@@ -60,6 +64,8 @@ export declare namespace Server {
60
64
  * Allows to emit logs, notify about compilation events and broadcast events to connected clients.
61
65
  */
62
66
  interface DelegateContext {
67
+ /** Normalized development server options. */
68
+ options: NormalizedOptions;
63
69
  /** A logger instance, useful for emitting logs from the delegate. */
64
70
  log: FastifyBaseLogger;
65
71
  /** Send notification about compilation start for given `platform`. */
@@ -0,0 +1,12 @@
1
+ import type { ServerOptions as HttpsServerOptions } from 'node:https';
2
+ import type { Server } from '../types.js';
3
+ export interface NormalizedOptions {
4
+ host: string;
5
+ port: number;
6
+ https: HttpsServerOptions | undefined;
7
+ hot: boolean;
8
+ url: string;
9
+ disableRequestLogging: boolean;
10
+ rootDir: string;
11
+ }
12
+ export declare function normalizeOptions(options: Server.Options): NormalizedOptions;
@@ -0,0 +1,28 @@
1
+ function normalizeHttpsOptions(serverOptions) {
2
+ if (serverOptions &&
3
+ typeof serverOptions === 'object' &&
4
+ serverOptions.type === 'https') {
5
+ return serverOptions.options;
6
+ }
7
+ return undefined;
8
+ }
9
+ export function normalizeOptions(options) {
10
+ const host = options.host ?? 'localhost';
11
+ const port = options.port ?? 8081;
12
+ const https = normalizeHttpsOptions(options.server);
13
+ const hot = options.hot ?? false;
14
+ const protocol = https ? 'https' : 'http';
15
+ const url = `${protocol}://${host}:${options.port}`;
16
+ return {
17
+ // webpack dev server compatible options
18
+ host,
19
+ port,
20
+ https,
21
+ hot,
22
+ url,
23
+ // fastify options
24
+ disableRequestLogging: !options.logRequests,
25
+ // project options
26
+ rootDir: options.rootDir,
27
+ };
28
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@callstack/repack-dev-server",
3
3
  "description": "A bundler-agnostic development server for React Native applications as part of @callstack/repack.",
4
4
  "license": "MIT",
5
- "version": "5.0.0-rc.10",
5
+ "version": "5.0.0-rc.11",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",