@callstack/repack-dev-server 0.0.0-canary-20240602190113
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/CHANGELOG.md +140 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/createServer.d.ts +13 -0
- package/dist/createServer.js +147 -0
- package/dist/createServer.js.map +1 -0
- package/dist/img/favicon.ico +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/api/apiPlugin.d.ts +6 -0
- package/dist/plugins/api/apiPlugin.js +32 -0
- package/dist/plugins/api/apiPlugin.js.map +1 -0
- package/dist/plugins/api/index.d.ts +1 -0
- package/dist/plugins/api/index.js +2 -0
- package/dist/plugins/api/index.js.map +1 -0
- package/dist/plugins/compiler/compilerPlugin.d.ts +7 -0
- package/dist/plugins/compiler/compilerPlugin.js +75 -0
- package/dist/plugins/compiler/compilerPlugin.js.map +1 -0
- package/dist/plugins/compiler/index.d.ts +2 -0
- package/dist/plugins/compiler/index.js +3 -0
- package/dist/plugins/compiler/index.js.map +1 -0
- package/dist/plugins/compiler/types.d.ts +31 -0
- package/dist/plugins/compiler/types.js +2 -0
- package/dist/plugins/compiler/types.js.map +1 -0
- package/dist/plugins/devtools/devtoolsPlugin.d.ts +7 -0
- package/dist/plugins/devtools/devtoolsPlugin.js +47 -0
- package/dist/plugins/devtools/devtoolsPlugin.js.map +1 -0
- package/dist/plugins/devtools/index.d.ts +1 -0
- package/dist/plugins/devtools/index.js +2 -0
- package/dist/plugins/devtools/index.js.map +1 -0
- package/dist/plugins/favicon/faviconPlugin.d.ts +4 -0
- package/dist/plugins/favicon/faviconPlugin.js +17 -0
- package/dist/plugins/favicon/faviconPlugin.js.map +1 -0
- package/dist/plugins/favicon/index.d.ts +1 -0
- package/dist/plugins/favicon/index.js +2 -0
- package/dist/plugins/favicon/index.js.map +1 -0
- package/dist/plugins/multipart/index.d.ts +2 -0
- package/dist/plugins/multipart/index.js +3 -0
- package/dist/plugins/multipart/index.js.map +1 -0
- package/dist/plugins/multipart/multipartPlugin.d.ts +4 -0
- package/dist/plugins/multipart/multipartPlugin.js +55 -0
- package/dist/plugins/multipart/multipartPlugin.js.map +1 -0
- package/dist/plugins/multipart/types.d.ts +12 -0
- package/dist/plugins/multipart/types.js +2 -0
- package/dist/plugins/multipart/types.js.map +1 -0
- package/dist/plugins/symbolicate/Symbolicator.d.ts +46 -0
- package/dist/plugins/symbolicate/Symbolicator.js +208 -0
- package/dist/plugins/symbolicate/Symbolicator.js.map +1 -0
- package/dist/plugins/symbolicate/index.d.ts +3 -0
- package/dist/plugins/symbolicate/index.js +4 -0
- package/dist/plugins/symbolicate/index.js.map +1 -0
- package/dist/plugins/symbolicate/sybmolicatePlugin.d.ts +7 -0
- package/dist/plugins/symbolicate/sybmolicatePlugin.js +44 -0
- package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +1 -0
- package/dist/plugins/symbolicate/types.d.ts +65 -0
- package/dist/plugins/symbolicate/types.js +2 -0
- package/dist/plugins/symbolicate/types.js.map +1 -0
- package/dist/plugins/wss/WebSocketRouter.d.ts +32 -0
- package/dist/plugins/wss/WebSocketRouter.js +57 -0
- package/dist/plugins/wss/WebSocketRouter.js.map +1 -0
- package/dist/plugins/wss/WebSocketServer.d.ts +38 -0
- package/dist/plugins/wss/WebSocketServer.js +45 -0
- package/dist/plugins/wss/WebSocketServer.js.map +1 -0
- package/dist/plugins/wss/WebSocketServerAdapter.d.ts +16 -0
- package/dist/plugins/wss/WebSocketServerAdapter.js +22 -0
- package/dist/plugins/wss/WebSocketServerAdapter.js.map +1 -0
- package/dist/plugins/wss/index.d.ts +3 -0
- package/dist/plugins/wss/index.js +4 -0
- package/dist/plugins/wss/index.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketApiServer.d.ts +32 -0
- package/dist/plugins/wss/servers/WebSocketApiServer.js +62 -0
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.d.ts +64 -0
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js +142 -0
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketDevClientServer.d.ts +32 -0
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js +86 -0
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketEventsServer.d.ts +75 -0
- package/dist/plugins/wss/servers/WebSocketEventsServer.js +180 -0
- package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketHMRServer.d.ts +38 -0
- package/dist/plugins/wss/servers/WebSocketHMRServer.js +89 -0
- package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +140 -0
- package/dist/plugins/wss/servers/WebSocketMessageServer.js +350 -0
- package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +1 -0
- package/dist/plugins/wss/types.d.ts +25 -0
- package/dist/plugins/wss/types.js +2 -0
- package/dist/plugins/wss/types.js.map +1 -0
- package/dist/plugins/wss/wssPlugin.d.ts +31 -0
- package/dist/plugins/wss/wssPlugin.js +56 -0
- package/dist/plugins/wss/wssPlugin.js.map +1 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/package.json +83 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# @callstack/repack-dev-server
|
|
2
|
+
|
|
3
|
+
## 0.0.0-canary-20240602190113
|
|
4
|
+
|
|
5
|
+
## 4.0.0
|
|
6
|
+
|
|
7
|
+
### Major Changes
|
|
8
|
+
|
|
9
|
+
- [#430](https://github.com/callstack/repack/pull/430) [`0d96b11`](https://github.com/callstack/repack/commit/0d96b11ff3a6e2c21eb622e21ff7947db29a3272) Thanks [@jbroma](https://github.com/jbroma)! - Upgrade to Node 18, drop support for Node 16
|
|
10
|
+
|
|
11
|
+
- [#508](https://github.com/callstack/repack/pull/508) [`fec8962`](https://github.com/callstack/repack/commit/fec8962b45f3d744d7c41e8f6eeae0a2310c7693) Thanks [@RafikiTiki](https://github.com/RafikiTiki)! - - Fixed deprecated remote debugger integration:
|
|
12
|
+
- Removed vendored code and used middlewares from `@react-native-community/cli-server-api`
|
|
13
|
+
- Removed `package/debugger-app` and replaced it with `@react-native-community/cli-debugger-ui`
|
|
14
|
+
- Removed vendored code responsible for integration with Flipper debugger & custom implementation of the Hermes Inspector Proxy
|
|
15
|
+
- Added integration with `@react-native/dev-middleware` which enables us to use both Flipper and new experimental debugger
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#567](https://github.com/callstack/repack/pull/567) [`6417da7`](https://github.com/callstack/repack/commit/6417da7ba72e39602735062198165c998e4e19cf) Thanks [@kerm1it](https://github.com/kerm1it)! - Notify clients on all platforms when sending an HMR event update
|
|
20
|
+
|
|
21
|
+
- [#554](https://github.com/callstack/repack/pull/554) [`ed82e29`](https://github.com/callstack/repack/commit/ed82e29c2871411fd73616f29a7d4b75ff3dd913) Thanks [@jbroma](https://github.com/jbroma)! - Fix path to `favicon.ico` on Windows
|
|
22
|
+
|
|
23
|
+
- [#464](https://github.com/callstack/repack/pull/464) [`72c770b`](https://github.com/callstack/repack/commit/72c770bb4ac5540a3c73cf244ca861069a37b045) Thanks [@jbroma](https://github.com/jbroma)! - Upgrade TypeScript, ESLint, TypeDoc in the repository
|
|
24
|
+
|
|
25
|
+
## 4.0.0-rc.2
|
|
26
|
+
|
|
27
|
+
## 4.0.0-rc.1
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#554](https://github.com/callstack/repack/pull/554) [`ed82e29`](https://github.com/callstack/repack/commit/ed82e29c2871411fd73616f29a7d4b75ff3dd913) Thanks [@jbroma](https://github.com/jbroma)! - Fix path to favicon.ico on Windows
|
|
32
|
+
|
|
33
|
+
## 4.0.0-rc.0
|
|
34
|
+
|
|
35
|
+
### Major Changes
|
|
36
|
+
|
|
37
|
+
- [#430](https://github.com/callstack/repack/pull/430) [`0d96b11`](https://github.com/callstack/repack/commit/0d96b11ff3a6e2c21eb622e21ff7947db29a3272) Thanks [@jbroma](https://github.com/jbroma)! - BREAKING CHANGE: Upgrade to Node 18, drop support for Node 16.
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- [#464](https://github.com/callstack/repack/pull/464) [`72c770b`](https://github.com/callstack/repack/commit/72c770bb4ac5540a3c73cf244ca861069a37b045) Thanks [@jbroma](https://github.com/jbroma)! - chore: upgrade TypeScript, ESLint, TypeDoc
|
|
42
|
+
|
|
43
|
+
## 1.1.0
|
|
44
|
+
|
|
45
|
+
### Minor Changes
|
|
46
|
+
|
|
47
|
+
- [#475](https://github.com/callstack/repack/pull/475) [`cc997a2`](https://github.com/callstack/repack/commit/cc997a2f84b4835f8fe597487b0cde6f41b4b7f0) Thanks [@szymonrybczak](https://github.com/szymonrybczak)! - Added X-React-Native-Project-Root header, so the RN CLI picks up the running bundler correctly
|
|
48
|
+
|
|
49
|
+
## 1.0.2
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- [#441](https://github.com/callstack/repack/pull/441) [`a66785d`](https://github.com/callstack/repack/commit/a66785d4bdb629ab9abce2bf5fc0dc4b632072ef) Thanks [@hexboy](https://github.com/hexboy)! - fix(dev-server): fix Failed to open stack frame in editor error
|
|
54
|
+
|
|
55
|
+
* [#426](https://github.com/callstack/repack/pull/426) [`719c2ef`](https://github.com/callstack/repack/commit/719c2ef3e1af0c82de8042de2c5c21ab88a287ea) Thanks [@jbroma](https://github.com/jbroma)! - Upgraded source-map to 0.7.4
|
|
56
|
+
|
|
57
|
+
## 1.0.1
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- [#308](https://github.com/callstack/repack/pull/308) [`ad9581a`](https://github.com/callstack/repack/commit/ad9581a6d690b128991a9d64374ecb4b8d49c413) Thanks [@jbroma](https://github.com/jbroma)! - Make all packages compatible with Node v18
|
|
62
|
+
|
|
63
|
+
- Updated dependencies [[`ad9581a`](https://github.com/callstack/repack/commit/ad9581a6d690b128991a9d64374ecb4b8d49c413)]:
|
|
64
|
+
- @callstack/repack-debugger-app@1.0.2
|
|
65
|
+
|
|
66
|
+
## 1.0.0
|
|
67
|
+
|
|
68
|
+
### Major Changes
|
|
69
|
+
|
|
70
|
+
- [#186](https://github.com/callstack/repack/pull/186) [`05d126e`](https://github.com/callstack/repack/commit/05d126e63802f0702a9e353e762f8b6a77fcd73e) Thanks [@zamotany](https://github.com/zamotany)! - ### Bundler-agnostic development server
|
|
71
|
+
|
|
72
|
+
Extracted development server from `@callstack/repack` into a separate package and made it bundler-agnostic.
|
|
73
|
+
|
|
74
|
+
### Minor Changes
|
|
75
|
+
|
|
76
|
+
- [#189](https://github.com/callstack/repack/pull/189) [`bc42023`](https://github.com/callstack/repack/commit/bc420236687047752cf1ee42204b2f510aec144a) Thanks [@zamotany](https://github.com/zamotany)! - ### Development server API
|
|
77
|
+
|
|
78
|
+
Added API endpoints to `@callstack/repack-dev-server`:
|
|
79
|
+
|
|
80
|
+
- `GET /api/platforms` - List all platforms with active compilations
|
|
81
|
+
- `GET /api/:platform/assets` - List all assets (`name` and `size`) for a given compilation
|
|
82
|
+
- `GET /api/:platform/stats` - Get compilation stats
|
|
83
|
+
- Websocket server under `/api` URI for logs and compilations events
|
|
84
|
+
|
|
85
|
+
* [#230](https://github.com/callstack/repack/pull/230) [`e6dc69d`](https://github.com/callstack/repack/commit/e6dc69d35f287af08d09944edd8e6d12f28484cf) Thanks [@jbinda](https://github.com/jbinda)! - Introduce `fastify-favicon` plugin to prevent server logger from emitting error log related to `GET 400 /favicon.ico` when requesting bundles via browser.
|
|
86
|
+
|
|
87
|
+
- [#239](https://github.com/callstack/repack/pull/239) [`6d65156`](https://github.com/callstack/repack/commit/6d65156366bc88edefdae7a3d0310ddbcdf48886) Thanks [@jbinda](https://github.com/jbinda)! - Expose favicon.ico in devserver
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- [#238](https://github.com/callstack/repack/pull/238) [`b913b89`](https://github.com/callstack/repack/commit/b913b8981334854cc13076af2a9c8a12bc465d1b) Thanks [@jbinda](https://github.com/jbinda)! - Add `archive` script in dev-server
|
|
92
|
+
|
|
93
|
+
* [#200](https://github.com/callstack/repack/pull/200) [`c75cdc7`](https://github.com/callstack/repack/commit/c75cdc7a44351bb4702232e603031e2880f2839d) Thanks [@zamotany](https://github.com/zamotany)! - Prevent server logger from emitting log to API WS server before WS servers are created.
|
|
94
|
+
|
|
95
|
+
* Updated dependencies [[`05d126e`](https://github.com/callstack/repack/commit/05d126e63802f0702a9e353e762f8b6a77fcd73e)]:
|
|
96
|
+
- @callstack/repack-debugger-app@1.0.0
|
|
97
|
+
|
|
98
|
+
## 1.0.0-next.3
|
|
99
|
+
|
|
100
|
+
### Minor Changes
|
|
101
|
+
|
|
102
|
+
- [#230](https://github.com/callstack/repack/pull/230) [`e6dc69d`](https://github.com/callstack/repack/commit/e6dc69d35f287af08d09944edd8e6d12f28484cf) Thanks [@jbinda](https://github.com/jbinda)! - Introduce `fastify-favicon` plugin to prevent server logger from emitting error log related to `GET 400 /favicon.ico` when requesting bundles via browser.
|
|
103
|
+
|
|
104
|
+
* [#239](https://github.com/callstack/repack/pull/239) [`6d65156`](https://github.com/callstack/repack/commit/6d65156366bc88edefdae7a3d0310ddbcdf48886) Thanks [@jbinda](https://github.com/jbinda)! - Expose favicon.ico in devserver
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- [#238](https://github.com/callstack/repack/pull/238) [`b913b89`](https://github.com/callstack/repack/commit/b913b8981334854cc13076af2a9c8a12bc465d1b) Thanks [@jbinda](https://github.com/jbinda)! - Add `archive` script in dev-server
|
|
109
|
+
|
|
110
|
+
## 1.0.0-next.2
|
|
111
|
+
|
|
112
|
+
### Patch Changes
|
|
113
|
+
|
|
114
|
+
- [#200](https://github.com/callstack/repack/pull/200) [`c75cdc7`](https://github.com/callstack/repack/commit/c75cdc7a44351bb4702232e603031e2880f2839d) Thanks [@zamotany](https://github.com/zamotany)! - Prevent server logger from emitting log to API WS server before WS servers are created.
|
|
115
|
+
|
|
116
|
+
## 1.0.0-next.1
|
|
117
|
+
|
|
118
|
+
### Minor Changes
|
|
119
|
+
|
|
120
|
+
- ### Development server API
|
|
121
|
+
|
|
122
|
+
Added API endpoints to `@callstack/repack-dev-server`:
|
|
123
|
+
|
|
124
|
+
- `GET /api/platforms` - List all platforms with active compilations
|
|
125
|
+
- `GET /api/:platform/assets` - List all assets (`name` and `size`) for a given compilation
|
|
126
|
+
- `GET /api/:platform/stats` - Get compilation stats
|
|
127
|
+
- Websocket server under `/api` URI for logs and compilations events
|
|
128
|
+
|
|
129
|
+
## 1.0.0-next.0
|
|
130
|
+
|
|
131
|
+
### Major Changes
|
|
132
|
+
|
|
133
|
+
- ### Bundler-agnostic development server
|
|
134
|
+
|
|
135
|
+
Extracted development server from `@callstack/repack` into a separate package and made it bundler-agnostic.
|
|
136
|
+
|
|
137
|
+
### Patch Changes
|
|
138
|
+
|
|
139
|
+
- Updated dependencies []:
|
|
140
|
+
- @callstack/repack-debugger-app@1.0.0-next.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Callstack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/callstack/repack/HEAD/logo.png">
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
A Webpack-based toolkit to build your React Native application with full support of Webpack ecosystem.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
[![Build Status][build-badge]][build]
|
|
11
|
+
[![Version][version-badge]][version]
|
|
12
|
+
[![MIT License][license-badge]][license]
|
|
13
|
+
[![PRs Welcome][prs-welcome-badge]][prs-welcome]
|
|
14
|
+
[![Code of Conduct][coc-badge]][coc]
|
|
15
|
+
|
|
16
|
+
`@callstack/repack-dev-sever` is bundler-agnostic development server for React Native applications as part of `@callstack/repack`.
|
|
17
|
+
|
|
18
|
+
Check out our website at https://re-pack.dev for more info and documentation or out GitHub: https://github.com/callstack/repack.
|
|
19
|
+
|
|
20
|
+
<!-- badges -->
|
|
21
|
+
|
|
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
|
|
30
|
+
[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
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Server } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create instance of development server, powered by Fastify.
|
|
5
|
+
*
|
|
6
|
+
* @param config Server configuration.
|
|
7
|
+
* @returns `start` and `stop` functions as well as an underlying Fastify `instance`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createServer(config: Server.Config): Promise<{
|
|
10
|
+
start: () => Promise<void>;
|
|
11
|
+
stop: () => Promise<void>;
|
|
12
|
+
instance: import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Writable } from 'stream';
|
|
2
|
+
import Fastify from 'fastify';
|
|
3
|
+
import fastifySensible from '@fastify/sensible';
|
|
4
|
+
import middie from '@fastify/middie';
|
|
5
|
+
// eslint-disable-next-line import/no-unresolved -- no main field in package.json
|
|
6
|
+
import { createDevMiddleware } from '@react-native/dev-middleware';
|
|
7
|
+
import { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';
|
|
8
|
+
import { openURLMiddleware, openStackFrameInEditorMiddleware } from '@react-native-community/cli-server-api';
|
|
9
|
+
import multipartPlugin from "./plugins/multipart/index.js";
|
|
10
|
+
import compilerPlugin from "./plugins/compiler/index.js";
|
|
11
|
+
import apiPlugin from "./plugins/api/index.js";
|
|
12
|
+
import wssPlugin from "./plugins/wss/index.js";
|
|
13
|
+
import faviconPlugin from "./plugins/favicon/index.js";
|
|
14
|
+
import { Internal } from "./types.js";
|
|
15
|
+
import symbolicatePlugin from "./plugins/symbolicate/index.js";
|
|
16
|
+
import devtoolsPlugin from "./plugins/devtools/index.js";
|
|
17
|
+
/**
|
|
18
|
+
* Create instance of development server, powered by Fastify.
|
|
19
|
+
*
|
|
20
|
+
* @param config Server configuration.
|
|
21
|
+
* @returns `start` and `stop` functions as well as an underlying Fastify `instance`.
|
|
22
|
+
*/
|
|
23
|
+
export async function createServer(config) {
|
|
24
|
+
let delegate;
|
|
25
|
+
|
|
26
|
+
/** Fastify instance powering the development server. */
|
|
27
|
+
const instance = Fastify({
|
|
28
|
+
logger: {
|
|
29
|
+
level: 'trace',
|
|
30
|
+
stream: new Writable({
|
|
31
|
+
write: (chunk, _encoding, callback) => {
|
|
32
|
+
const log = JSON.parse(chunk.toString());
|
|
33
|
+
delegate?.logger.onMessage(log);
|
|
34
|
+
instance.wss?.apiServer.send(log);
|
|
35
|
+
callback();
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
},
|
|
39
|
+
...(config.options.https ? {
|
|
40
|
+
https: config.options.https
|
|
41
|
+
} : undefined)
|
|
42
|
+
});
|
|
43
|
+
delegate = config.delegate({
|
|
44
|
+
log: instance.log,
|
|
45
|
+
notifyBuildStart: platform => {
|
|
46
|
+
instance.wss.apiServer.send({
|
|
47
|
+
event: Internal.EventTypes.BuildStart,
|
|
48
|
+
platform
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
notifyBuildEnd: platform => {
|
|
52
|
+
instance.wss.apiServer.send({
|
|
53
|
+
event: Internal.EventTypes.BuildEnd,
|
|
54
|
+
platform
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
broadcastToHmrClients: (event, platform, clientIds) => {
|
|
58
|
+
instance.wss.hmrServer.send(event, platform, clientIds);
|
|
59
|
+
},
|
|
60
|
+
broadcastToMessageClients: ({
|
|
61
|
+
method,
|
|
62
|
+
params
|
|
63
|
+
}) => {
|
|
64
|
+
instance.wss.messageServer.broadcast(method, params);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const devMiddleware = createDevMiddleware({
|
|
68
|
+
projectRoot: config.options.rootDir,
|
|
69
|
+
serverBaseUrl: `http://${config.options.host}:${config.options.port}`,
|
|
70
|
+
logger: instance.log,
|
|
71
|
+
unstable_experiments: {
|
|
72
|
+
enableNewDebugger: config.experiments?.experimentalDebugger
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Register plugins
|
|
77
|
+
await instance.register(fastifySensible);
|
|
78
|
+
await instance.register(middie);
|
|
79
|
+
await instance.register(wssPlugin, {
|
|
80
|
+
options: {
|
|
81
|
+
...config.options,
|
|
82
|
+
endpoints: devMiddleware.websocketEndpoints
|
|
83
|
+
},
|
|
84
|
+
delegate
|
|
85
|
+
});
|
|
86
|
+
await instance.register(multipartPlugin);
|
|
87
|
+
await instance.register(apiPlugin, {
|
|
88
|
+
delegate,
|
|
89
|
+
prefix: '/api'
|
|
90
|
+
});
|
|
91
|
+
await instance.register(compilerPlugin, {
|
|
92
|
+
delegate
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after
|
|
96
|
+
// the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.
|
|
97
|
+
// When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui
|
|
98
|
+
// from the dependencies.
|
|
99
|
+
await instance.register(devtoolsPlugin, {
|
|
100
|
+
options: config.options
|
|
101
|
+
});
|
|
102
|
+
instance.use('/debugger-ui', debuggerUIMiddleware());
|
|
103
|
+
instance.use('/open-url', openURLMiddleware);
|
|
104
|
+
instance.use('/open-stack-frame', openStackFrameInEditorMiddleware);
|
|
105
|
+
await instance.register(symbolicatePlugin, {
|
|
106
|
+
delegate
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// below is to prevent showing `GET 400 /favicon.ico`
|
|
110
|
+
// errors in console when requesting the bundle via browser
|
|
111
|
+
await instance.register(faviconPlugin);
|
|
112
|
+
instance.addHook('onSend', async (request, reply, payload) => {
|
|
113
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
114
|
+
reply.header('X-React-Native-Project-Root', config.options.rootDir);
|
|
115
|
+
const [pathname] = request.url.split('?');
|
|
116
|
+
if (pathname.endsWith('.map')) {
|
|
117
|
+
reply.header('Access-Control-Allow-Origin', 'devtools://devtools');
|
|
118
|
+
}
|
|
119
|
+
return payload;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Register dev middleware
|
|
123
|
+
instance.use(devMiddleware.middleware);
|
|
124
|
+
|
|
125
|
+
// Register routes
|
|
126
|
+
instance.get('/', async () => delegate.messages.getHello());
|
|
127
|
+
instance.get('/status', async () => delegate.messages.getStatus());
|
|
128
|
+
|
|
129
|
+
/** Start the development server. */
|
|
130
|
+
async function start() {
|
|
131
|
+
await instance.listen({
|
|
132
|
+
port: config.options.port,
|
|
133
|
+
host: config.options.host
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Stop the development server. */
|
|
138
|
+
async function stop() {
|
|
139
|
+
await instance.close();
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
start,
|
|
143
|
+
stop,
|
|
144
|
+
instance
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=createServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","middie","createDevMiddleware","debuggerUIMiddleware","openURLMiddleware","openStackFrameInEditorMiddleware","multipartPlugin","compilerPlugin","apiPlugin","wssPlugin","faviconPlugin","Internal","symbolicatePlugin","devtoolsPlugin","createServer","config","delegate","instance","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","options","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","devMiddleware","projectRoot","rootDir","serverBaseUrl","host","port","unstable_experiments","enableNewDebugger","experiments","experimentalDebugger","register","endpoints","websocketEndpoints","prefix","use","addHook","request","reply","payload","header","pathname","url","split","endsWith","middleware","get","messages","getHello","getStatus","start","listen","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport Fastify from 'fastify';\nimport fastifySensible from '@fastify/sensible';\nimport middie from '@fastify/middie';\n// eslint-disable-next-line import/no-unresolved -- no main field in package.json\nimport { createDevMiddleware } from '@react-native/dev-middleware';\nimport { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';\nimport {\n openURLMiddleware,\n openStackFrameInEditorMiddleware,\n} from '@react-native-community/cli-server-api';\nimport multipartPlugin from './plugins/multipart';\nimport compilerPlugin from './plugins/compiler';\nimport apiPlugin from './plugins/api';\nimport wssPlugin from './plugins/wss';\nimport faviconPlugin from './plugins/favicon';\nimport { Internal, Server } from './types';\nimport symbolicatePlugin from './plugins/symbolicate';\nimport devtoolsPlugin from './plugins/devtools';\n\n/**\n * Create instance of development server, powered by Fastify.\n *\n * @param config Server configuration.\n * @returns `start` and `stop` functions as well as an underlying Fastify `instance`.\n */\nexport async function createServer(config: Server.Config) {\n let delegate: Server.Delegate;\n\n /** Fastify instance powering the development server. */\n const instance = Fastify({\n logger: {\n level: 'trace',\n stream: new Writable({\n write: (chunk, _encoding, callback) => {\n const log = JSON.parse(chunk.toString());\n delegate?.logger.onMessage(log);\n instance.wss?.apiServer.send(log);\n callback();\n },\n }),\n },\n ...(config.options.https ? { https: config.options.https } : undefined),\n });\n\n delegate = config.delegate({\n log: instance.log,\n notifyBuildStart: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildStart,\n platform,\n });\n },\n notifyBuildEnd: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildEnd,\n platform,\n });\n },\n broadcastToHmrClients: (event, platform, clientIds) => {\n instance.wss.hmrServer.send(event, platform, clientIds);\n },\n broadcastToMessageClients: ({ method, params }) => {\n instance.wss.messageServer.broadcast(method, params);\n },\n });\n\n const devMiddleware = createDevMiddleware({\n projectRoot: config.options.rootDir,\n serverBaseUrl: `http://${config.options.host}:${config.options.port}`,\n logger: instance.log,\n unstable_experiments: {\n enableNewDebugger: config.experiments?.experimentalDebugger,\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(middie);\n await instance.register(wssPlugin, {\n options: {\n ...config.options,\n endpoints: devMiddleware.websocketEndpoints,\n },\n delegate,\n });\n await instance.register(multipartPlugin);\n await instance.register(apiPlugin, {\n delegate,\n prefix: '/api',\n });\n await instance.register(compilerPlugin, {\n delegate,\n });\n\n // TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after\n // the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.\n // When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui\n // from the dependencies.\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n instance.use('/debugger-ui', debuggerUIMiddleware());\n instance.use('/open-url', openURLMiddleware);\n instance.use('/open-stack-frame', openStackFrameInEditorMiddleware);\n\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n\n // below is to prevent showing `GET 400 /favicon.ico`\n // errors in console when requesting the bundle via browser\n await instance.register(faviconPlugin);\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n reply.header('X-React-Native-Project-Root', config.options.rootDir);\n\n const [pathname] = request.url.split('?');\n if (pathname.endsWith('.map')) {\n reply.header('Access-Control-Allow-Origin', 'devtools://devtools');\n }\n\n return payload;\n });\n\n // Register dev middleware\n instance.use(devMiddleware.middleware);\n\n // Register routes\n instance.get('/', async () => delegate.messages.getHello());\n instance.get('/status', async () => delegate.messages.getStatus());\n\n /** Start the development server. */\n async function start() {\n await instance.listen({\n port: config.options.port,\n host: config.options.host,\n });\n }\n\n /** Stop the development server. */\n async function stop() {\n await instance.close();\n }\n\n return {\n start,\n stop,\n instance,\n };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,OAAOC,OAAO,MAAM,SAAS;AAC7B,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,MAAM,MAAM,iBAAiB;AACpC;AACA,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,SAASC,oBAAoB,QAAQ,yCAAyC;AAC9E,SACEC,iBAAiB,EACjBC,gCAAgC,QAC3B,wCAAwC;AAAC,OACzCC,eAAe;AAAA,OACfC,cAAc;AAAA,OACdC,SAAS;AAAA,OACTC,SAAS;AAAA,OACTC,aAAa;AAAA,SACXC,QAAQ;AAAA,OACVC,iBAAiB;AAAA,OACjBC,cAAc;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAACC,MAAqB,EAAE;EACxD,IA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ACkB,OAAO,CAACuB,IAAI;MACzBD,IAAI,EAAExC,MAAM,CAACkB,OAAO,CAACsB;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAe2B,IAAIA,CAAA,EAAG;IACpB,MAAMjE,QAAQ,CAACkE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJjE;EACF,CAAC;AACH","ignoreList":[]}
|
|
Binary file
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './createServer';\nexport * from './types';\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const paramsSchema = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
platform: {
|
|
5
|
+
type: 'string'
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
required: ['platform']
|
|
9
|
+
};
|
|
10
|
+
async function apiPlugin(instance, {
|
|
11
|
+
delegate
|
|
12
|
+
}) {
|
|
13
|
+
instance.get('/platforms', async (_request, reply) => delegate.api ? reply.send({
|
|
14
|
+
data: await delegate.api.getPlatforms()
|
|
15
|
+
}) : reply.notImplemented('Missing API delegate implementation'));
|
|
16
|
+
instance.get('/:platform/assets', {
|
|
17
|
+
schema: {
|
|
18
|
+
params: paramsSchema
|
|
19
|
+
}
|
|
20
|
+
}, async (request, reply) => delegate.api ? reply.send({
|
|
21
|
+
data: await delegate.api.getAssets(request.params.platform)
|
|
22
|
+
}) : reply.notImplemented('Missing API delegate implementation'));
|
|
23
|
+
instance.get('/:platform/stats', {
|
|
24
|
+
schema: {
|
|
25
|
+
params: paramsSchema
|
|
26
|
+
}
|
|
27
|
+
}, async (request, reply) => delegate.api ? reply.send({
|
|
28
|
+
data: await delegate.api?.getCompilationStats(request.params.platform)
|
|
29
|
+
}) : reply.notImplemented('Missing API delegate implementation'));
|
|
30
|
+
}
|
|
31
|
+
export default apiPlugin;
|
|
32
|
+
//# sourceMappingURL=apiPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiPlugin.js","names":["paramsSchema","type","properties","platform","required","apiPlugin","instance","delegate","get","_request","reply","api","send","data","getPlatforms","notImplemented","schema","params","request","getAssets","getCompilationStats"],"sources":["../../../src/plugins/api/apiPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport type { Server } from '../../types';\n\nconst paramsSchema = {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n required: ['platform'],\n};\n\ntype Params = { platform: string };\n\nasync function apiPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.get('/platforms', async (_request, reply) =>\n delegate.api\n ? reply.send({ data: await delegate.api.getPlatforms() })\n : reply.notImplemented('Missing API delegate implementation')\n );\n\n instance.get<{ Params: Params }>(\n '/:platform/assets',\n { schema: { params: paramsSchema } },\n async (request, reply) =>\n delegate.api\n ? reply.send({\n data: await delegate.api.getAssets(request.params.platform),\n })\n : reply.notImplemented('Missing API delegate implementation')\n );\n\n instance.get<{ Params: Params }>(\n '/:platform/stats',\n { schema: { params: paramsSchema } },\n async (request, reply) =>\n delegate.api\n ? reply.send({\n data: await delegate.api?.getCompilationStats(\n request.params.platform\n ),\n })\n : reply.notImplemented('Missing API delegate implementation')\n );\n}\n\nexport default apiPlugin;\n"],"mappings":"AAGA,MAAMA,YAAY,GAAG;EACnBC,IAAI,EAAE,QAAQ;EACdC,UAAU,EAAE;IACVC,QAAQ,EAAE;MACRF,IAAI,EAAE;IACR;EACF,CAAC;EACDG,QAAQ,EAAE,CAAC,UAAU;AACvB,CAAC;AAID,eAAeC,SAASA,CACtBC,QAAyB,EACzB;EAAEC;AAAwC,CAAC,EAC3C;EACAD,QAAQ,CAACE,GAAG,CAAC,YAAY,EAAE,OAAOC,QAAQ,EAAEC,KAAK,KAC/CH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IAAEC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,CAACG,YAAY,CAAC;EAAE,CAAC,CAAC,GACvDJ,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAChE,CAAC;EAEDT,QAAQ,CAACE,GAAG,CACV,mBAAmB,EACnB;IAAEQ,MAAM,EAAE;MAAEC,MAAM,EAAEjB;IAAa;EAAE,CAAC,EACpC,OAAOkB,OAAO,EAAER,KAAK,KACnBH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IACTC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,CAACQ,SAAS,CAACD,OAAO,CAACD,MAAM,CAACd,QAAQ;EAC5D,CAAC,CAAC,GACFO,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAClE,CAAC;EAEDT,QAAQ,CAACE,GAAG,CACV,kBAAkB,EAClB;IAAEQ,MAAM,EAAE;MAAEC,MAAM,EAAEjB;IAAa;EAAE,CAAC,EACpC,OAAOkB,OAAO,EAAER,KAAK,KACnBH,QAAQ,CAACI,GAAG,GACRD,KAAK,CAACE,IAAI,CAAC;IACTC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAG,EAAES,mBAAmB,CAC3CF,OAAO,CAACD,MAAM,CAACd,QACjB;EACF,CAAC,CAAC,GACFO,KAAK,CAACK,cAAc,CAAC,qCAAqC,CAClE,CAAC;AACH;AAEA,eAAeV,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './apiPlugin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/api/index.ts"],"sourcesContent":["export { default } from './apiPlugin';\n"],"mappings":"SAASA,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { Server } from '../../types';
|
|
3
|
+
declare function compilerPlugin(instance: FastifyInstance, { delegate }: {
|
|
4
|
+
delegate: Server.Delegate;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
declare const _default: typeof compilerPlugin;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
+
async function compilerPlugin(instance, {
|
|
3
|
+
delegate
|
|
4
|
+
}) {
|
|
5
|
+
instance.route({
|
|
6
|
+
method: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],
|
|
7
|
+
url: '/*',
|
|
8
|
+
schema: {
|
|
9
|
+
querystring: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
platform: {
|
|
13
|
+
type: 'string'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
handler: async (request, reply) => {
|
|
19
|
+
let file = request.params['*'];
|
|
20
|
+
let {
|
|
21
|
+
platform
|
|
22
|
+
} = request.query;
|
|
23
|
+
if (!file) {
|
|
24
|
+
// This technically should never happen - this route should not be called if file is missing.
|
|
25
|
+
request.log.error(`File was not provided`);
|
|
26
|
+
return reply.notFound();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Let consumer infer the platform. If function is not provided fallback
|
|
30
|
+
// to platform query param.
|
|
31
|
+
platform = delegate.compiler.inferPlatform?.(request.url) ?? platform;
|
|
32
|
+
if (!platform) {
|
|
33
|
+
request.log.error('Cannot detect platform');
|
|
34
|
+
return reply.badRequest('Cannot detect platform');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// If platform happens to be in front of an asset remove it.
|
|
38
|
+
if (file.startsWith(`${platform}/`)) {
|
|
39
|
+
file = file.replace(`${platform}/`, '');
|
|
40
|
+
}
|
|
41
|
+
const multipart = reply.asMultipart();
|
|
42
|
+
const sendProgress = ({
|
|
43
|
+
completed,
|
|
44
|
+
total
|
|
45
|
+
}) => {
|
|
46
|
+
multipart?.writeChunk({
|
|
47
|
+
'Content-Type': 'application/json'
|
|
48
|
+
}, JSON.stringify({
|
|
49
|
+
done: completed,
|
|
50
|
+
total
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
const asset = await delegate.compiler.getAsset(file, platform, sendProgress);
|
|
55
|
+
const mimeType = delegate.compiler.getMimeType(file, platform, asset);
|
|
56
|
+
if (multipart) {
|
|
57
|
+
const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);
|
|
58
|
+
multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);
|
|
59
|
+
multipart.setHeader('Content-Length', String(Buffer.byteLength(buffer)));
|
|
60
|
+
multipart.end(buffer);
|
|
61
|
+
} else {
|
|
62
|
+
return reply.code(200).type(mimeType).send(asset);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
request.log.error(error);
|
|
66
|
+
return reply.notFound(error.message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export default fastifyPlugin(compilerPlugin, {
|
|
72
|
+
name: 'compiler-plugin',
|
|
73
|
+
dependencies: ['@fastify/sensible', 'multipart-plugin']
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=compilerPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compilerPlugin.js","names":["fastifyPlugin","compilerPlugin","instance","delegate","route","method","url","schema","querystring","type","properties","platform","handler","request","reply","file","params","query","log","error","notFound","compiler","inferPlatform","badRequest","startsWith","replace","multipart","asMultipart","sendProgress","completed","total","writeChunk","JSON","stringify","done","asset","getAsset","mimeType","getMimeType","buffer","Buffer","isBuffer","from","setHeader","String","byteLength","end","code","send","message","name","dependencies"],"sources":["../../../src/plugins/compiler/compilerPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\nimport type { SendProgress } from '../../types';\n\nasync function compilerPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.route({\n method: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],\n url: '/*',\n schema: {\n querystring: {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n },\n },\n handler: async (request, reply) => {\n let file = (request.params as { '*'?: string })['*'];\n let { platform } = request.query as { platform?: string };\n\n if (!file) {\n // This technically should never happen - this route should not be called if file is missing.\n request.log.error(`File was not provided`);\n return reply.notFound();\n }\n\n // Let consumer infer the platform. If function is not provided fallback\n // to platform query param.\n platform = delegate.compiler.inferPlatform?.(request.url) ?? platform;\n\n if (!platform) {\n request.log.error('Cannot detect platform');\n return reply.badRequest('Cannot detect platform');\n }\n\n // If platform happens to be in front of an asset remove it.\n if (file.startsWith(`${platform}/`)) {\n file = file.replace(`${platform}/`, '');\n }\n\n const multipart = reply.asMultipart();\n\n const sendProgress: SendProgress = ({ completed, total }) => {\n multipart?.writeChunk(\n { 'Content-Type': 'application/json' },\n JSON.stringify({\n done: completed,\n total,\n })\n );\n };\n\n try {\n const asset = await delegate.compiler.getAsset(\n file,\n platform,\n sendProgress\n );\n const mimeType = delegate.compiler.getMimeType(file, platform, asset);\n\n if (multipart) {\n const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);\n multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);\n multipart.setHeader(\n 'Content-Length',\n String(Buffer.byteLength(buffer))\n );\n multipart.end(buffer);\n } else {\n return reply.code(200).type(mimeType).send(asset);\n }\n } catch (error) {\n request.log.error(error);\n return reply.notFound((error as Error).message);\n }\n },\n });\n}\n\nexport default fastifyPlugin(compilerPlugin, {\n name: 'compiler-plugin',\n dependencies: ['@fastify/sensible', 'multipart-plugin'],\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAI1C,eAAeC,cAAcA,CAC3BC,QAAy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 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/compiler/index.ts"],"sourcesContent":["export { default } from './compilerPlugin';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { SendProgress } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Delegate with implementation for compiler-specific functions.
|
|
5
|
+
*/
|
|
6
|
+
export interface CompilerDelegate {
|
|
7
|
+
/**
|
|
8
|
+
* Get compiled asset content.
|
|
9
|
+
*
|
|
10
|
+
* If the compilation is in progress, it should wait until compilation finishes and then return the asset.
|
|
11
|
+
*
|
|
12
|
+
* @param filename Filename of the asset to get.
|
|
13
|
+
* @param platform Platform of the asset to get.
|
|
14
|
+
* @param sendProgress Function to notify the client who requested the asset about compilation progress.
|
|
15
|
+
*/
|
|
16
|
+
getAsset: (filename: string, platform: string, sendProgress?: SendProgress) => Promise<string | Buffer>;
|
|
17
|
+
/**
|
|
18
|
+
* Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).
|
|
19
|
+
*
|
|
20
|
+
* @param filename Filename of the asset.
|
|
21
|
+
* @param platform Platform of the asset.
|
|
22
|
+
* @param data Asset's content.
|
|
23
|
+
*/
|
|
24
|
+
getMimeType: (filename: string, platform: string, data: string | Buffer) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Detect the platform from the URI - either from filename, query params or both.
|
|
27
|
+
*
|
|
28
|
+
* @param uri URI string.
|
|
29
|
+
*/
|
|
30
|
+
inferPlatform?: (uri: string) => string | undefined;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/compiler/types.ts"],"sourcesContent":["import type { SendProgress } from '../../types';\n\n/**\n * Delegate with implementation for compiler-specific functions.\n */\nexport interface CompilerDelegate {\n /**\n * Get compiled asset content.\n *\n * If the compilation is in progress, it should wait until compilation finishes and then return the asset.\n *\n * @param filename Filename of the asset to get.\n * @param platform Platform of the asset to get.\n * @param sendProgress Function to notify the client who requested the asset about compilation progress.\n */\n getAsset: (\n filename: string,\n platform: string,\n sendProgress?: SendProgress\n ) => Promise<string | Buffer>;\n\n /**\n * Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).\n *\n * @param filename Filename of the asset.\n * @param platform Platform of the asset.\n * @param data Asset's content.\n */\n getMimeType: (\n filename: string,\n platform: string,\n data: string | Buffer\n ) => string;\n\n /**\n * Detect the platform from the URI - either from filename, query params or both.\n *\n * @param uri URI string.\n */\n inferPlatform?: (uri: string) => string | undefined;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { Server } from '../../types';
|
|
3
|
+
declare function devtoolsPlugin(instance: FastifyInstance, { options }: {
|
|
4
|
+
options: Server.Options;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
declare const _default: typeof devtoolsPlugin;
|
|
7
|
+
export default _default;
|