@callstack/repack-dev-server 4.3.0-canary-20240822085232 → 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
@@ -1,6 +1,6 @@
1
1
  # @callstack/repack-dev-server
2
2
 
3
- ## 4.3.0-canary-20240822085232
3
+ ## 4.3.0
4
4
 
5
5
  ## 4.2.0
6
6
 
@@ -16,11 +16,11 @@ async function compilerPlugin(instance, {
16
16
  }
17
17
  },
18
18
  handler: async (request, reply) => {
19
- const filename = request.params['*'];
19
+ let file = request.params['*'];
20
20
  let {
21
21
  platform
22
22
  } = request.query;
23
- if (!filename) {
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();
@@ -33,6 +33,11 @@ async function compilerPlugin(instance, {
33
33
  request.log.error('Cannot detect platform');
34
34
  return reply.badRequest('Cannot detect platform');
35
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
+ }
36
41
  const multipart = reply.asMultipart();
37
42
  const sendProgress = ({
38
43
  completed,
@@ -46,8 +51,8 @@ async function compilerPlugin(instance, {
46
51
  }));
47
52
  };
48
53
  try {
49
- const asset = await delegate.compiler.getAsset(filename, platform, sendProgress);
50
- const mimeType = delegate.compiler.getMimeType(filename, platform, asset);
54
+ const asset = await delegate.compiler.getAsset(file, platform, sendProgress);
55
+ const mimeType = delegate.compiler.getMimeType(file, platform, asset);
51
56
  if (multipart) {
52
57
  const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);
53
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","filename","params","query","log","error","notFound","compiler","inferPlatform","badRequest","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 const filename = (request.params as { '*'?: string })['*'];\n let { platform } = request.query as { platform?: string };\n\n if (!filename) {\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 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 filename,\n platform,\n sendProgress\n );\n const mimeType = delegate.compiler.getMimeType(\n filename,\n platform,\n asset\n );\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,MAAMC,QAAQ,GAAIF,OAAO,CAACG,MAAM,CAAsB,GAAG,CAAC;MAC1D,IAAI;QAAEL;MAAS,CAAC,GAAGE,OAAO,CAACI,KAA8B;MAEzD,IAAI,CAACF,QAAQ,EAAE;QACb;QACAF,OAAO,CAACK,GAAG,CAACC,KAAK,CAAC,uBAAuB,CAAC;QAC1C,OAAOL,KAAK,CAACM,QAAQ,CAAC,CAAC;MACzB;;MAEA;MACA;MACAT,QAAQ,GAAGR,QAAQ,CAACkB,QAAQ,CAACC,aAAa,GAAGT,OAAO,CAACP,GAAG,CAAC,IAAIK,QAAQ;MAErE,IAAI,CAACA,QAAQ,EAAE;QACbE,OAAO,CAACK,GAAG,CAACC,KAAK,CAAC,wBAAwB,CAAC;QAC3C,OAAOL,KAAK,CAACS,UAAU,CAAC,wBAAwB,CAAC;MACnD;MAEA,MAAMC,SAAS,GAAGV,KAAK,CAACW,WAAW,CAAC,CAAC;MAErC,MAAMC,YAA0B,GAAGA,CAAC;QAAEC,SAAS;QAAEC;MAAM,CAAC,KAAK;QAC3DJ,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
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;MACzB;;MAEA;MACA;MACAT,QAAQ,GAAGR,QAAQ,CAACkB,QAAQ,CAACC,aAAa,GAAGT,OAAO,CAACP,GAAG,CAAC,IAAIK,QAAQ;MAErE,IAAI,CAACA,QAAQ,EAAE;QACbE,OAAO,CAACK,GAAG,CAACC,KAAK,CAAC,wBAAwB,CAAC;QAC3C,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AACb,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":[]}
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-canary-20240822085232",
5
+ "version": "4.3.0",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",