@callstack/repack-dev-server 4.3.0-canary-20240822091832 → 4.3.0
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
CHANGED
|
@@ -16,11 +16,11 @@ async function compilerPlugin(instance, {
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
handler: async (request, reply) => {
|
|
19
|
-
|
|
19
|
+
let file = request.params['*'];
|
|
20
20
|
let {
|
|
21
21
|
platform
|
|
22
22
|
} = request.query;
|
|
23
|
-
if (!
|
|
23
|
+
if (!file) {
|
|
24
24
|
// This technically should never happen - this route should not be called if file is missing.
|
|
25
25
|
request.log.error(`File was not provided`);
|
|
26
26
|
return reply.notFound();
|
|
@@ -29,6 +29,15 @@ async function compilerPlugin(instance, {
|
|
|
29
29
|
// Let consumer infer the platform. If function is not provided fallback
|
|
30
30
|
// to platform query param.
|
|
31
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
|
+
}
|
|
32
41
|
const multipart = reply.asMultipart();
|
|
33
42
|
const sendProgress = ({
|
|
34
43
|
completed,
|
|
@@ -42,8 +51,8 @@ async function compilerPlugin(instance, {
|
|
|
42
51
|
}));
|
|
43
52
|
};
|
|
44
53
|
try {
|
|
45
|
-
const asset = await delegate.compiler.getAsset(
|
|
46
|
-
const mimeType = delegate.compiler.getMimeType(
|
|
54
|
+
const asset = await delegate.compiler.getAsset(file, platform, sendProgress);
|
|
55
|
+
const mimeType = delegate.compiler.getMimeType(file, platform, asset);
|
|
47
56
|
if (multipart) {
|
|
48
57
|
const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);
|
|
49
58
|
multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilerPlugin.js","names":["fastifyPlugin","compilerPlugin","instance","delegate","route","method","url","schema","querystring","type","properties","platform","handler","request","reply","
|
|
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,QAAyB,EACzB;EAAEC;AAAwC,CAAC,EAC3C;EACAD,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC;IAC3DC,GAAG,EAAE,IAAI;IACTC,MAAM,EAAE;MACNC,WAAW,EAAE;QACXC,IAAI,EAAE,QAAQ;QACdC,UAAU,EAAE;UACVC,QAAQ,EAAE;YACRF,IAAI,EAAE;UACR;QACF;MACF;IACF,CAAC;IACDG,OAAO,EAAE,MAAAA,CAAOC,OAAO,EAAEC,KAAK,KAAK;MACjC,IAAIC,IAAI,GAAIF,OAAO,CAACG,MAAM,CAAsB,GAAG,CAAC;MACpD,IAAI;QAAEL;MAAS,CAAC,GAAGE,OAAO,CAACI,KAA8B;MAEzD,IAAI,CAACF,IAAI,EAAE;QACT;QACAF,OAAO,CAACK,GAAG,CAACC,KAAK,CAAC,uBAAuB,CAAC;QAC1C,OAAOL,KAAK,CAACM,QAAQ,CAAC,CAAC;MACz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,MAAM,CAACK,UAAU,CAACN,MAAM,CAAC,CAClC,CAAC;UACDb,SAAS,CAACoB,GAAG,CAACP,MAAM,CAAC;QACvB,CAAC,MAAM;UACL,OAAOzB,KAAK,CAACiC,IAAI,CAAC,GAAG,CAAC,CAACtC,IAAI,CAAC4B,QAAQ,CAAC,CAACW,IAAI,CAACb,KAAK,CAAC;QACnD;MACF,CAAC,CAAC,OAAOhB,KAAK,EAAE;QACdN,OAAO,CAACK,GAAG,CAACC,KAAK,CAACA,KAAK,CAAC;QACxB,OAAOL,KAAK,CAACM,QAAQ,CAAED,KAAK,CAAW8B,OAAO,CAAC;MACjD;IACF;EACF,CAAC,CAAC;AACJ;AAEA,eAAejD,aAAa,CAACC,cAAc,EAAE;EAC3CiD,IAAI,EAAE,iBAAiB;EACvBC,YAAY,EAAE,CAAC,mBAAmB,EAAE,kBAAkB;AACxD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -12,7 +12,7 @@ export interface CompilerDelegate {
|
|
|
12
12
|
* @param platform Platform of the asset to get.
|
|
13
13
|
* @param sendProgress Function to notify the client who requested the asset about compilation progress.
|
|
14
14
|
*/
|
|
15
|
-
getAsset: (filename: string, platform: string
|
|
15
|
+
getAsset: (filename: string, platform: string, sendProgress?: SendProgress) => Promise<string | Buffer>;
|
|
16
16
|
/**
|
|
17
17
|
* Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).
|
|
18
18
|
*
|
|
@@ -20,7 +20,7 @@ export interface CompilerDelegate {
|
|
|
20
20
|
* @param platform Platform of the asset.
|
|
21
21
|
* @param data Asset's content.
|
|
22
22
|
*/
|
|
23
|
-
getMimeType: (filename: string, platform: string
|
|
23
|
+
getMimeType: (filename: string, platform: string, data: string | Buffer) => string;
|
|
24
24
|
/**
|
|
25
25
|
* Detect the platform from the URI - either from filename, query params or both.
|
|
26
26
|
*
|
|
@@ -1 +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
|
|
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":[]}
|
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": "4.3.0
|
|
5
|
+
"version": "4.3.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|