@expo/cli 0.12.0 → 0.13.1
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/build/bin/cli +2 -2
- package/build/src/export/createBundles.js +0 -30
- package/build/src/export/createBundles.js.map +1 -1
- package/build/src/export/createMetadataJson.js +1 -0
- package/build/src/export/createMetadataJson.js.map +1 -1
- package/build/src/export/embed/exportEmbedAsync.js +2 -0
- package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
- package/build/src/export/exportApp.js +42 -15
- package/build/src/export/exportApp.js.map +1 -1
- package/build/src/export/exportAssets.js +2 -2
- package/build/src/export/exportAssets.js.map +1 -1
- package/build/src/export/exportHermes.js +204 -0
- package/build/src/export/exportHermes.js.map +1 -0
- package/build/src/export/exportStaticAsync.js +58 -3
- package/build/src/export/exportStaticAsync.js.map +1 -1
- package/build/src/export/favicon.js +7 -7
- package/build/src/export/favicon.js.map +1 -1
- package/build/src/export/fork-bundleAsync.js +9 -11
- package/build/src/export/fork-bundleAsync.js.map +1 -1
- package/build/src/export/persistMetroAssets.js +118 -0
- package/build/src/export/persistMetroAssets.js.map +1 -0
- package/build/src/export/saveAssets.js.map +1 -1
- package/build/src/export/writeContents.js +2 -2
- package/build/src/export/writeContents.js.map +1 -1
- package/build/src/install/index.js +1 -0
- package/build/src/install/index.js.map +1 -1
- package/build/src/install/installAsync.js +1 -0
- package/build/src/install/installAsync.js.map +1 -1
- package/build/src/install/resolveOptions.js +7 -4
- package/build/src/install/resolveOptions.js.map +1 -1
- package/build/src/prebuild/index.js +2 -0
- package/build/src/prebuild/index.js.map +1 -1
- package/build/src/prebuild/prebuildAsync.js +2 -1
- package/build/src/prebuild/prebuildAsync.js.map +1 -1
- package/build/src/prebuild/resolveOptions.js +4 -2
- package/build/src/prebuild/resolveOptions.js.map +1 -1
- package/build/src/run/android/runAndroidAsync.js +5 -0
- package/build/src/run/android/runAndroidAsync.js.map +1 -1
- package/build/src/run/ios/runIosAsync.js +5 -0
- package/build/src/run/ios/runIosAsync.js.map +1 -1
- package/build/src/start/interface/interactiveActions.js +3 -3
- package/build/src/start/interface/interactiveActions.js.map +1 -1
- package/build/src/start/server/BundlerDevServer.js.map +1 -1
- package/build/src/start/server/getStaticRenderFunctions.js +7 -12
- package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
- package/build/src/start/server/metro/MetroBundlerDevServer.js +78 -54
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/MetroTerminalReporter.js +1 -1
- package/build/src/start/server/metro/MetroTerminalReporter.js.map +1 -1
- package/build/src/start/server/metro/bundleApiRoutes.js +67 -0
- package/build/src/start/server/metro/bundleApiRoutes.js.map +1 -0
- package/build/src/start/server/metro/createServerRouteMiddleware.js +112 -0
- package/build/src/start/server/metro/createServerRouteMiddleware.js.map +1 -0
- package/build/src/start/server/metro/fetchRouterManifest.js +60 -0
- package/build/src/start/server/metro/fetchRouterManifest.js.map +1 -0
- package/build/src/start/server/metro/instantiateMetro.js +31 -11
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/metroErrorInterface.js +70 -10
- package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
- package/build/src/start/server/metro/resolveFromProject.js +13 -0
- package/build/src/start/server/metro/resolveFromProject.js.map +1 -1
- package/build/src/start/server/metro/router.js +32 -0
- package/build/src/start/server/metro/router.js.map +1 -1
- package/build/src/start/server/metro/waitForMetroToObserveTypeScriptFile.js +22 -0
- package/build/src/start/server/metro/waitForMetroToObserveTypeScriptFile.js.map +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js +18 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js +1 -1
- package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/InterstitialPageMiddleware.js +3 -3
- package/build/src/start/server/middleware/InterstitialPageMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/ManifestMiddleware.js +5 -1
- package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/inspector/JsInspector.js +69 -0
- package/build/src/start/server/middleware/inspector/JsInspector.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowser.js +57 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowser.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowser.types.js +13 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowser.types.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplLinux.js +79 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplLinux.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplMacOS.js +78 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplMacOS.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js +123 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js.map +1 -0
- package/build/src/start/server/middleware/inspector/createJsInspectorMiddleware.js +64 -0
- package/build/src/start/server/middleware/inspector/createJsInspectorMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/inspector/middlwareMutations.js +19 -0
- package/build/src/start/server/middleware/inspector/middlwareMutations.js.map +1 -0
- package/build/src/start/server/middleware/mutations.js +19 -0
- package/build/src/start/server/middleware/mutations.js.map +1 -0
- package/build/src/start/server/middleware/remoteDevtoolsCorsMiddleware.js +31 -0
- package/build/src/start/server/middleware/remoteDevtoolsCorsMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/remoteDevtoolsSecurityHeadersMiddleware.js +17 -0
- package/build/src/start/server/middleware/remoteDevtoolsSecurityHeadersMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/resolveAssets.js.map +1 -1
- package/build/src/start/server/middleware/suppressErrorMiddleware.js +16 -0
- package/build/src/start/server/middleware/suppressErrorMiddleware.js.map +1 -0
- package/build/src/start/server/type-generation/routes.js +3 -4
- package/build/src/start/server/type-generation/routes.js.map +1 -1
- package/build/src/start/server/type-generation/startTypescriptTypeGeneration.js +1 -3
- package/build/src/start/server/type-generation/startTypescriptTypeGeneration.js.map +1 -1
- package/build/src/start/server/webpack/WebpackBundlerDevServer.js +9 -82
- package/build/src/start/server/webpack/WebpackBundlerDevServer.js.map +1 -1
- package/build/src/utils/analytics/rudderstackClient.js +2 -2
- package/build/src/utils/codesigning.js.map +1 -1
- package/build/src/utils/port.js +45 -17
- package/build/src/utils/port.js.map +1 -1
- package/package.json +18 -12
- package/build/src/start/server/middleware/createDevServerMiddleware.js +0 -24
- package/build/src/start/server/middleware/createDevServerMiddleware.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.remoteDevtoolsCorsMiddleware = remoteDevtoolsCorsMiddleware;
|
|
6
|
+
var _url = require("url");
|
|
7
|
+
function remoteDevtoolsCorsMiddleware(req, res, next) {
|
|
8
|
+
if (req.url) {
|
|
9
|
+
var ref;
|
|
10
|
+
const url = (0, _url).parse(req.url);
|
|
11
|
+
const origin = req.headers.origin;
|
|
12
|
+
const isValidOrigin = origin && [
|
|
13
|
+
"devtools://devtools",
|
|
14
|
+
"https://chrome-devtools-frontend.appspot.com"
|
|
15
|
+
].includes(origin);
|
|
16
|
+
if (((ref = url.pathname) == null ? void 0 : ref.endsWith(".map")) && origin && isValidOrigin) {
|
|
17
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
18
|
+
// Prevent metro overwrite Access-Control-Allow-Origin header
|
|
19
|
+
const setHeader = res.setHeader.bind(res);
|
|
20
|
+
res.setHeader = (key, ...args)=>{
|
|
21
|
+
if (key !== "Access-Control-Allow-Origin") {
|
|
22
|
+
setHeader(key, ...args);
|
|
23
|
+
}
|
|
24
|
+
return res;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
next();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=remoteDevtoolsCorsMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/middleware/remoteDevtoolsCorsMiddleware.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from 'http';\nimport { parse as parseUrl } from 'url';\n\n// Middleware that accepts multiple Access-Control-Allow-Origin for processing *.map.\n// This is a hook middleware before metro processing *.map,\n// which originally allow only devtools://devtools\nexport function remoteDevtoolsCorsMiddleware(\n req: IncomingMessage,\n res: ServerResponse,\n next: (err?: Error) => void\n) {\n if (req.url) {\n const url = parseUrl(req.url);\n const origin = req.headers.origin;\n const isValidOrigin =\n origin &&\n ['devtools://devtools', 'https://chrome-devtools-frontend.appspot.com'].includes(origin);\n if (url.pathname?.endsWith('.map') && origin && isValidOrigin) {\n res.setHeader('Access-Control-Allow-Origin', origin);\n\n // Prevent metro overwrite Access-Control-Allow-Origin header\n const setHeader = res.setHeader.bind(res);\n res.setHeader = (key, ...args) => {\n if (key !== 'Access-Control-Allow-Origin') {\n setHeader(key, ...args);\n }\n return res;\n };\n }\n }\n next();\n}\n"],"names":["remoteDevtoolsCorsMiddleware","req","res","next","url","parseUrl","origin","headers","isValidOrigin","includes","pathname","endsWith","setHeader","bind","key","args"],"mappings":"AAAA;;;;QAMgBA,4BAA4B,GAA5BA,4BAA4B;AALV,IAAA,IAAK,WAAL,KAAK,CAAA;AAKhC,SAASA,4BAA4B,CAC1CC,GAAoB,EACpBC,GAAmB,EACnBC,IAA2B,EAC3B;IACA,IAAIF,GAAG,CAACG,GAAG,EAAE;YAMPA,GAAY;QALhB,MAAMA,GAAG,GAAGC,CAAAA,GAAAA,IAAQ,AAAS,CAAA,MAAT,CAACJ,GAAG,CAACG,GAAG,CAAC,AAAC;QAC9B,MAAME,MAAM,GAAGL,GAAG,CAACM,OAAO,CAACD,MAAM,AAAC;QAClC,MAAME,aAAa,GACjBF,MAAM,IACN;YAAC,qBAAqB;YAAE,8CAA8C;SAAC,CAACG,QAAQ,CAACH,MAAM,CAAC,AAAC;QAC3F,IAAIF,CAAAA,CAAAA,GAAY,GAAZA,GAAG,CAACM,QAAQ,SAAU,GAAtBN,KAAAA,CAAsB,GAAtBA,GAAY,CAAEO,QAAQ,CAAC,MAAM,CAAC,KAAIL,MAAM,IAAIE,aAAa,EAAE;YAC7DN,GAAG,CAACU,SAAS,CAAC,6BAA6B,EAAEN,MAAM,CAAC,CAAC;YAErD,6DAA6D;YAC7D,MAAMM,SAAS,GAAGV,GAAG,CAACU,SAAS,CAACC,IAAI,CAACX,GAAG,CAAC,AAAC;YAC1CA,GAAG,CAACU,SAAS,GAAG,CAACE,GAAG,EAAKC,GAAAA,IAAI,GAAK;gBAChC,IAAID,GAAG,KAAK,6BAA6B,EAAE;oBACzCF,SAAS,CAACE,GAAG,KAAKC,IAAI,CAAC,CAAC;iBACzB;gBACD,OAAOb,GAAG,CAAC;aACZ,CAAC;SACH;KACF;IACDC,IAAI,EAAE,CAAC;CACR"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.remoteDevtoolsSecurityHeadersMiddleware = remoteDevtoolsSecurityHeadersMiddleware;
|
|
6
|
+
function remoteDevtoolsSecurityHeadersMiddleware(req, res, next) {
|
|
7
|
+
// Block any cross origin request.
|
|
8
|
+
if (typeof req.headers.origin === "string" && !req.headers.origin.match(/^https?:\/\/localhost:/) && !req.headers.origin.match(/^https:\/\/chrome-devtools-frontend\.appspot\.com/)) {
|
|
9
|
+
next(new Error(`Unauthorized request from ${req.headers.origin}. ` + "This may happen because of a conflicting browser extension to intercept HTTP requests. " + "Please try again without browser extensions or using incognito mode."));
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
// Block MIME-type sniffing.
|
|
13
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
14
|
+
next();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=remoteDevtoolsSecurityHeadersMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/middleware/remoteDevtoolsSecurityHeadersMiddleware.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from 'http';\n\n// Like securityHeadersMiddleware but further allow cross-origin requests\n// from https://chrome-devtools-frontend.appspot.com/\nexport function remoteDevtoolsSecurityHeadersMiddleware(\n req: IncomingMessage,\n res: ServerResponse,\n next: (err?: Error) => void\n) {\n // Block any cross origin request.\n if (\n typeof req.headers.origin === 'string' &&\n !req.headers.origin.match(/^https?:\\/\\/localhost:/) &&\n !req.headers.origin.match(/^https:\\/\\/chrome-devtools-frontend\\.appspot\\.com/)\n ) {\n next(\n new Error(\n `Unauthorized request from ${req.headers.origin}. ` +\n 'This may happen because of a conflicting browser extension to intercept HTTP requests. ' +\n 'Please try again without browser extensions or using incognito mode.'\n )\n );\n return;\n }\n\n // Block MIME-type sniffing.\n res.setHeader('X-Content-Type-Options', 'nosniff');\n\n next();\n}\n"],"names":["remoteDevtoolsSecurityHeadersMiddleware","req","res","next","headers","origin","match","Error","setHeader"],"mappings":"AAAA;;;;QAIgBA,uCAAuC,GAAvCA,uCAAuC;AAAhD,SAASA,uCAAuC,CACrDC,GAAoB,EACpBC,GAAmB,EACnBC,IAA2B,EAC3B;IACA,kCAAkC;IAClC,IACE,OAAOF,GAAG,CAACG,OAAO,CAACC,MAAM,KAAK,QAAQ,IACtC,CAACJ,GAAG,CAACG,OAAO,CAACC,MAAM,CAACC,KAAK,0BAA0B,IACnD,CAACL,GAAG,CAACG,OAAO,CAACC,MAAM,CAACC,KAAK,qDAAqD,EAC9E;QACAH,IAAI,CACF,IAAII,KAAK,CACP,CAAC,0BAA0B,EAAEN,GAAG,CAACG,OAAO,CAACC,MAAM,CAAC,EAAE,CAAC,GACjD,yFAAyF,GACzF,sEAAsE,CACzE,CACF,CAAC;QACF,OAAO;KACR;IAED,4BAA4B;IAC5BH,GAAG,CAACM,SAAS,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IAEnDL,IAAI,EAAE,CAAC;CACR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/middleware/resolveAssets.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config';\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/middleware/resolveAssets.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { getAssetSchemasAsync } from '../../../api/getExpoSchema';\nimport { BundleAssetWithFileHashes } from '../../../export/fork-bundleAsync';\nimport * as Log from '../../../log';\nimport { fileExistsAsync } from '../../../utils/dir';\nimport { CommandError } from '../../../utils/errors';\nimport { get, set } from '../../../utils/obj';\nimport { validateUrl } from '../../../utils/url';\n\ntype ManifestAsset = { fileHashes: string[]; files: string[]; hash: string };\n\nexport type Asset = ManifestAsset | BundleAssetWithFileHashes;\n\ntype ManifestResolutionError = Error & {\n localAssetPath?: string;\n manifestField?: string;\n};\n\n/** Inline the contents of each platform's `googleServicesFile` so runtimes can access them. */\nexport async function resolveGoogleServicesFile(\n projectRoot: string,\n manifest: Pick<ExpoConfig, 'android' | 'ios'>\n) {\n if (manifest.android?.googleServicesFile) {\n try {\n const contents = await fs.readFile(\n path.resolve(projectRoot, manifest.android.googleServicesFile),\n 'utf8'\n );\n manifest.android.googleServicesFile = contents;\n } catch {\n Log.warn(\n `Could not parse Expo config: android.googleServicesFile: \"${manifest.android.googleServicesFile}\"`\n );\n // Delete the field so Expo Go doesn't attempt to read it.\n delete manifest.android.googleServicesFile;\n }\n }\n if (manifest.ios?.googleServicesFile) {\n try {\n const contents = await fs.readFile(\n path.resolve(projectRoot, manifest.ios.googleServicesFile),\n 'base64'\n );\n manifest.ios.googleServicesFile = contents;\n } catch {\n Log.warn(\n `Could not parse Expo config: ios.googleServicesFile: \"${manifest.ios.googleServicesFile}\"`\n );\n // Delete the field so Expo Go doesn't attempt to read it.\n delete manifest.ios.googleServicesFile;\n }\n }\n return manifest;\n}\n\n/**\n * Get all fields in the manifest that match assets, then filter the ones that aren't set.\n *\n * @param manifest\n * @returns Asset fields that the user has set like [\"icon\", \"splash.image\", ...]\n */\nexport async function getAssetFieldPathsForManifestAsync(manifest: ExpoConfig): Promise<string[]> {\n // String array like [\"icon\", \"notification.icon\", \"loading.icon\", \"loading.backgroundImage\", \"ios.icon\", ...]\n const sdkAssetFieldPaths = await getAssetSchemasAsync(manifest.sdkVersion);\n return sdkAssetFieldPaths.filter((assetSchema) => get(manifest, assetSchema));\n}\n\n/** Resolve all assets in the app.json inline. */\nexport async function resolveManifestAssets(\n projectRoot: string,\n {\n manifest,\n resolver,\n strict,\n }: {\n manifest: ExpoConfig;\n resolver: (assetPath: string) => Promise<string>;\n strict?: boolean;\n }\n) {\n try {\n // Asset fields that the user has set like [\"icon\", \"splash.image\"]\n const assetSchemas = await getAssetFieldPathsForManifestAsync(manifest);\n // Get the URLs\n const urls = await Promise.all(\n assetSchemas.map(async (manifestField) => {\n const pathOrURL = get(manifest, manifestField);\n // URL\n if (validateUrl(pathOrURL, { requireProtocol: true })) {\n return pathOrURL;\n }\n\n // File path\n if (await fileExistsAsync(path.resolve(projectRoot, pathOrURL))) {\n return await resolver(pathOrURL);\n }\n\n // Unknown\n const err: ManifestResolutionError = new CommandError(\n 'MANIFEST_ASSET',\n 'Could not resolve local asset: ' + pathOrURL\n );\n err.localAssetPath = pathOrURL;\n err.manifestField = manifestField;\n throw err;\n })\n );\n\n // Set the corresponding URL fields\n assetSchemas.forEach((manifestField, index: number) =>\n set(manifest, `${manifestField}Url`, urls[index])\n );\n } catch (error: any) {\n if (error.localAssetPath) {\n Log.warn(\n `Unable to resolve asset \"${error.localAssetPath}\" from \"${error.manifestField}\" in your app.json or app.config.js`\n );\n } else {\n Log.warn(\n `Warning: Unable to resolve manifest assets. Icons and fonts might not work. ${error.message}.`\n );\n }\n\n if (strict) {\n throw new CommandError(\n 'MANIFEST_ASSET',\n 'Failed to export manifest assets: ' + error.message\n );\n }\n }\n}\n"],"names":["resolveGoogleServicesFile","getAssetFieldPathsForManifestAsync","resolveManifestAssets","Log","projectRoot","manifest","android","googleServicesFile","contents","fs","readFile","path","resolve","warn","ios","sdkAssetFieldPaths","getAssetSchemasAsync","sdkVersion","filter","assetSchema","get","resolver","strict","assetSchemas","urls","Promise","all","map","manifestField","pathOrURL","validateUrl","requireProtocol","fileExistsAsync","err","CommandError","localAssetPath","forEach","index","set","error","message"],"mappings":"AAAA;;;;QAsBsBA,yBAAyB,GAAzBA,yBAAyB;QA2CzBC,kCAAkC,GAAlCA,kCAAkC;QAOlCC,qBAAqB,GAArBA,qBAAqB;AAvE5B,IAAA,SAAa,kCAAb,aAAa,EAAA;AACX,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEc,IAAA,cAA4B,WAA5B,4BAA4B,CAAA;AAErDC,IAAAA,GAAG,mCAAM,cAAc,EAApB;AACiB,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AACvB,IAAA,OAAuB,WAAvB,uBAAuB,CAAA;AAC3B,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AACjB,IAAA,IAAoB,WAApB,oBAAoB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYzC,eAAeH,yBAAyB,CAC7CI,WAAmB,EACnBC,QAA6C,EAC7C;QACIA,GAAgB,EAehBA,IAAY;IAfhB,IAAIA,CAAAA,GAAgB,GAAhBA,QAAQ,CAACC,OAAO,SAAoB,GAApCD,KAAAA,CAAoC,GAApCA,GAAgB,CAAEE,kBAAkB,EAAE;QACxC,IAAI;YACF,MAAMC,QAAQ,GAAG,MAAMC,SAAE,QAAA,CAACC,QAAQ,CAChCC,KAAI,Q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C,CAACjC,QAAQ,EAAE,CAAC,EAAEuB,aAAa,CAAC,GAAG,CAAC,EAAEJ,IAAI,CAACa,KAAK,CAAC,CAAC;QAAA,CAClD,CAAC;KACH,CAAC,OAAOE,KAAK,EAAO;QACnB,IAAIA,KAAK,CAACJ,cAAc,EAAE;YACxBhC,GAAG,CAACU,IAAI,CACN,CAAC,yBAAyB,EAAE0B,KAAK,CAACJ,cAAc,CAAC,QAAQ,EAAEI,KAAK,CAACX,aAAa,CAAC,mCAAmC,CAAC,CACpH,CAAC;SACH,MAAM;YACLzB,GAAG,CAACU,IAAI,CACN,CAAC,4EAA4E,EAAE0B,KAAK,CAACC,OAAO,CAAC,CAAC,CAAC,CAChG,CAAC;SACH;QAED,IAAIlB,MAAM,EAAE;YACV,MAAM,IAAIY,OAAY,aAAA,CACpB,gBAAgB,EAChB,oCAAoC,GAAGK,KAAK,CAACC,OAAO,CACrD,CAAC;SACH;KACF;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.suppressRemoteDebuggingErrorMiddleware = suppressRemoteDebuggingErrorMiddleware;
|
|
6
|
+
function suppressRemoteDebuggingErrorMiddleware(req, res, next) {
|
|
7
|
+
var ref;
|
|
8
|
+
if ((ref = req.url) == null ? void 0 : ref.match(/\/debugger-ui\/.+\.map$/)) {
|
|
9
|
+
res.writeHead(404);
|
|
10
|
+
res.end("Sourcemap for /debugger-ui/ is not supported.");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
next();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=suppressErrorMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/middleware/suppressErrorMiddleware.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from 'http';\n\n// Middleware to suppress `EISDIR` error when opening javascript inspector in remote debugging.\n// A workaround for https://github.com/facebook/react-native/issues/28844\n// The root cause is that metro cannot serve sourcemap requests for /debugger-ui/\nexport function suppressRemoteDebuggingErrorMiddleware(\n req: IncomingMessage,\n res: ServerResponse,\n next: (err?: Error) => void\n) {\n if (req.url?.match(/\\/debugger-ui\\/.+\\.map$/)) {\n res.writeHead(404);\n res.end('Sourcemap for /debugger-ui/ is not supported.');\n return;\n }\n next();\n}\n"],"names":["suppressRemoteDebuggingErrorMiddleware","req","res","next","url","match","writeHead","end"],"mappings":"AAAA;;;;QAKgBA,sCAAsC,GAAtCA,sCAAsC;AAA/C,SAASA,sCAAsC,CACpDC,GAAoB,EACpBC,GAAmB,EACnBC,IAA2B,EAC3B;QACIF,GAAO;IAAX,IAAIA,CAAAA,GAAO,GAAPA,GAAG,CAACG,GAAG,SAAO,GAAdH,KAAAA,CAAc,GAAdA,GAAO,CAAEI,KAAK,2BAA2B,EAAE;QAC7CH,GAAG,CAACI,SAAS,CAAC,GAAG,CAAC,CAAC;QACnBJ,GAAG,CAACK,GAAG,CAAC,+CAA+C,CAAC,CAAC;QACzD,OAAO;KACR;IACDJ,IAAI,EAAE,CAAC;CACR"}
|
|
@@ -29,8 +29,7 @@ exports.ARRAY_GROUP_REGEX = ARRAY_GROUP_REGEX;
|
|
|
29
29
|
const CAPTURE_GROUP_REGEX = /[\\(,]\s*(\w[\w\s]*?)\s*(?=[,\\)])/g;
|
|
30
30
|
exports.CAPTURE_GROUP_REGEX = CAPTURE_GROUP_REGEX;
|
|
31
31
|
async function setupTypedRoutes({ server , metro , typesDirectory , projectRoot , routerDirectory }) {
|
|
32
|
-
const
|
|
33
|
-
const { filePathToRoute , staticRoutes , dynamicRoutes , addFilePath , isRouteFile } = getTypedRoutesUtils(absoluteRouterDirectory);
|
|
32
|
+
const { filePathToRoute , staticRoutes , dynamicRoutes , addFilePath , isRouteFile } = getTypedRoutesUtils(routerDirectory);
|
|
34
33
|
if (metro && server) {
|
|
35
34
|
// Setup out watcher first
|
|
36
35
|
(0, _metroWatchTypeScriptFiles).metroWatchTypeScriptFiles({
|
|
@@ -67,10 +66,10 @@ async function setupTypedRoutes({ server , metro , typesDirectory , projectRoot
|
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
68
|
}
|
|
70
|
-
if (await (0, _dir).directoryExistsAsync(
|
|
69
|
+
if (await (0, _dir).directoryExistsAsync(routerDirectory)) {
|
|
71
70
|
// Do we need to walk the entire tree on startup?
|
|
72
71
|
// Idea: Store the list of files in the last write, then simply check Git for what files have changed
|
|
73
|
-
await walk(
|
|
72
|
+
await walk(routerDirectory, addFilePath);
|
|
74
73
|
}
|
|
75
74
|
regenerateRouterDotTS(typesDirectory, new Set([
|
|
76
75
|
...staticRoutes.values()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/type-generation/routes.ts"],"sourcesContent":["import fs from 'fs/promises';\nimport { debounce } from 'lodash';\nimport { Server } from 'metro';\nimport path from 'path';\n\nimport { directoryExistsAsync } from '../../../utils/dir';\nimport { unsafeTemplate } from '../../../utils/template';\nimport { ServerLike } from '../BundlerDevServer';\nimport { metroWatchTypeScriptFiles } from '../metro/metroWatchTypeScriptFiles';\n\n// /test/[...param1]/[param2]/[param3] - captures [\"param1\", \"param2\", \"param3\"]\nexport const CAPTURE_DYNAMIC_PARAMS = /\\[(?:\\.{3})?(\\w*?)[\\]$]/g;\n// /[...param1]/ - Match [...param1]\nexport const CATCH_ALL = /\\[\\.\\.\\..+?\\]/g;\n// /[param1] - Match [param1]\nexport const SLUG = /\\[.+?\\]/g;\n// /(group1,group2,group3)/test - match (group1,group2,group3)\nexport const ARRAY_GROUP_REGEX = /\\(\\s*\\w[\\w\\s]*?,.*?\\)/g;\n// /(group1,group2,group3)/test - captures [\"group1\", \"group2\", \"group3\"]\nexport const CAPTURE_GROUP_REGEX = /[\\\\(,]\\s*(\\w[\\w\\s]*?)\\s*(?=[,\\\\)])/g;\n\nexport interface SetupTypedRoutesOptions {\n server?: ServerLike;\n metro?: Server | null;\n typesDirectory: string;\n projectRoot: string;\n routerDirectory: string;\n}\n\nexport async function setupTypedRoutes({\n server,\n metro,\n typesDirectory,\n projectRoot,\n routerDirectory,\n}: SetupTypedRoutesOptions) {\n const absoluteRouterDirectory = path.join(projectRoot, routerDirectory);\n\n const { filePathToRoute, staticRoutes, dynamicRoutes, addFilePath, isRouteFile } =\n getTypedRoutesUtils(absoluteRouterDirectory);\n\n if (metro && server) {\n // Setup out watcher first\n metroWatchTypeScriptFiles({\n projectRoot,\n server,\n metro,\n eventTypes: ['add', 'delete', 'change'],\n async callback({ filePath, type }) {\n if (!isRouteFile(filePath)) {\n return;\n }\n\n let shouldRegenerate = false;\n\n if (type === 'delete') {\n const route = filePathToRoute(filePath);\n staticRoutes.delete(route);\n dynamicRoutes.delete(route);\n shouldRegenerate = true;\n } else {\n shouldRegenerate = addFilePath(filePath);\n }\n\n if (shouldRegenerate) {\n regenerateRouterDotTS(\n typesDirectory,\n new Set([...staticRoutes.values()].flatMap((v) => Array.from(v))),\n new Set([...dynamicRoutes.values()].flatMap((v) => Array.from(v))),\n new Set(dynamicRoutes.keys())\n );\n }\n },\n });\n }\n\n if (await directoryExistsAsync(absoluteRouterDirectory)) {\n // Do we need to walk the entire tree on startup?\n // Idea: Store the list of files in the last write, then simply check Git for what files have changed\n await walk(absoluteRouterDirectory, addFilePath);\n }\n\n regenerateRouterDotTS(\n typesDirectory,\n new Set([...staticRoutes.values()].flatMap((v) => Array.from(v))),\n new Set([...dynamicRoutes.values()].flatMap((v) => Array.from(v))),\n new Set(dynamicRoutes.keys())\n );\n}\n\n/**\n * Generate a router.d.ts file that contains all of the routes in the project.\n * Should be debounced as its very common for developers to make changes to multiple files at once (eg Save All)\n */\nconst regenerateRouterDotTS = debounce(\n async (\n typesDir: string,\n staticRoutes: Set<string>,\n dynamicRoutes: Set<string>,\n dynamicRouteTemplates: Set<string>\n ) => {\n await fs.mkdir(typesDir, { recursive: true });\n await fs.writeFile(\n path.resolve(typesDir, './router.d.ts'),\n getTemplateString(staticRoutes, dynamicRoutes, dynamicRouteTemplates)\n );\n },\n 100\n);\n\n/*\n * This is exported for testing purposes\n */\nexport function getTemplateString(\n staticRoutes: Set<string>,\n dynamicRoutes: Set<string>,\n dynamicRouteTemplates: Set<string>\n) {\n return routerDotTSTemplate({\n staticRoutes: setToUnionType(staticRoutes),\n dynamicRoutes: setToUnionType(dynamicRoutes),\n dynamicRouteParams: setToUnionType(dynamicRouteTemplates),\n });\n}\n\n/**\n * Utility functions for typed routes\n *\n * These are extracted for easier testing\n */\nexport function getTypedRoutesUtils(appRoot: string, filePathSeperator = path.sep) {\n /*\n * staticRoutes are a map where the key if the route without groups and the value\n * is another set of all group versions of the route. e.g,\n * Map([\n * [\"/\", [\"/(app)/(notes)\", \"/(app)/(profile)\"]\n * ])\n */\n const staticRoutes = new Map<string, Set<string>>([['/', new Set('/')]]);\n /*\n * dynamicRoutes are the same as staticRoutes (key if the resolved route,\n * and the value is a set of possible routes). e.g:\n *\n * /[...fruits] -> /${CatchAllRoutePart<T>}\n * /color/[color] -> /color/${SingleRoutePart<T>}\n *\n * The keys of this map are also important, as they can be used as \"static\" types\n * <Link href={{ pathname: \"/[...fruits]\",params: { fruits: [\"apple\"] } }} />\n */\n const dynamicRoutes = new Map<string, Set<string>>();\n\n function normalizedFilePath(filePath: string) {\n return filePath.replaceAll(filePathSeperator, '/');\n }\n\n const normalizedAppRoot = normalizedFilePath(appRoot);\n\n const filePathToRoute = (filePath: string) => {\n return normalizedFilePath(filePath)\n .replace(normalizedAppRoot, '')\n .replace(/index\\.[jt]sx?/, '')\n .replace(/\\.[jt]sx?$/, '');\n };\n\n const isRouteFile = (filePath: string) => {\n // Layout and filenames starting with `+` are not routes\n if (filePath.match(/_layout\\.[tj]sx?$/) || filePath.match(/\\/\\+/)) {\n return false;\n }\n\n // Route files must be nested with in the appRoot\n const relative = path.relative(appRoot, filePath);\n return relative && !relative.startsWith('..') && !path.isAbsolute(relative);\n };\n\n const addFilePath = (filePath: string): boolean => {\n if (!isRouteFile(filePath)) {\n return false;\n }\n\n const route = filePathToRoute(filePath);\n\n // We have already processed this file\n if (staticRoutes.has(route) || dynamicRoutes.has(route)) {\n return false;\n }\n\n const dynamicParams = new Set(\n [...route.matchAll(CAPTURE_DYNAMIC_PARAMS)].map((match) => match[1])\n );\n const isDynamic = dynamicParams.size > 0;\n\n const addRoute = (originalRoute: string, route: string) => {\n if (isDynamic) {\n let set = dynamicRoutes.get(originalRoute);\n\n if (!set) {\n set = new Set();\n dynamicRoutes.set(originalRoute, set);\n }\n\n set.add(\n route\n .replaceAll(CATCH_ALL, '${CatchAllRoutePart<T>}')\n .replaceAll(SLUG, '${SingleRoutePart<T>}')\n );\n } else {\n let set = staticRoutes.get(originalRoute);\n\n if (!set) {\n set = new Set();\n staticRoutes.set(originalRoute, set);\n }\n\n set.add(route);\n }\n };\n\n if (!route.match(ARRAY_GROUP_REGEX)) {\n addRoute(route, route);\n }\n\n // Does this route have a group? eg /(group)\n if (route.includes('/(')) {\n const routeWithoutGroups = route.replace(/\\/\\(.+?\\)/g, '');\n addRoute(route, routeWithoutGroups);\n\n // If there are multiple groups, we need to expand them\n // eg /(test1,test2)/page => /test1/page & /test2/page\n for (const routeWithSingleGroup of extrapolateGroupRoutes(route)) {\n addRoute(route, routeWithSingleGroup);\n }\n }\n\n return true;\n };\n\n return {\n staticRoutes,\n dynamicRoutes,\n filePathToRoute,\n addFilePath,\n isRouteFile,\n };\n}\n\nexport const setToUnionType = <T>(set: Set<T>) => {\n return set.size > 0 ? [...set].map((s) => `\\`${s}\\``).join(' | ') : 'never';\n};\n\n/**\n * Recursively walk a directory and call the callback with the file path.\n */\nasync function walk(directory: string, callback: (filePath: string) => void) {\n const files = await fs.readdir(directory);\n for (const file of files) {\n const p = path.join(directory, file);\n if ((await fs.stat(p)).isDirectory()) {\n await walk(p, callback);\n } else {\n // Normalise the paths so they are easier to convert to URLs\n const normalizedPath = p.replaceAll(path.sep, '/');\n callback(normalizedPath);\n }\n }\n}\n\n/**\n * Given a route, return all possible routes that could be generated from it.\n */\nexport function extrapolateGroupRoutes(\n route: string,\n routes: Set<string> = new Set()\n): Set<string> {\n // Create a version with no groups. We will then need to cleanup double and/or trailing slashes\n routes.add(route.replaceAll(ARRAY_GROUP_REGEX, '').replaceAll(/\\/+/g, '/').replace(/\\/$/, ''));\n\n const match = route.match(ARRAY_GROUP_REGEX);\n\n if (!match) {\n routes.add(route);\n return routes;\n }\n\n const groupsMatch = match[0];\n\n for (const group of groupsMatch.matchAll(CAPTURE_GROUP_REGEX)) {\n extrapolateGroupRoutes(route.replace(groupsMatch, `(${group[1].trim()})`), routes);\n }\n\n return routes;\n}\n\n/**\n * NOTE: This code refers to a specific version of `expo-router` and is therefore unsafe to\n * mix with arbitrary versions.\n * TODO: Version this code with `expo-router` or version expo-router with `@expo/cli`.\n */\nconst routerDotTSTemplate = unsafeTemplate`/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable import/export */\n/* eslint-disable @typescript-eslint/ban-types */\ndeclare module \"expo-router\" {\n import type { LinkProps as OriginalLinkProps } from 'expo-router/build/link/Link';\n import type { Router as OriginalRouter } from 'expo-router/src/types';\n export * from 'expo-router/build';\n\n // prettier-ignore\n type StaticRoutes = ${'staticRoutes'};\n // prettier-ignore\n type DynamicRoutes<T extends string> = ${'dynamicRoutes'};\n // prettier-ignore\n type DynamicRouteTemplate = ${'dynamicRouteParams'};\n\n type RelativePathString = \\`./\\${string}\\` | \\`../\\${string}\\` | '..';\n type AbsoluteRoute = DynamicRouteTemplate | StaticRoutes;\n type ExternalPathString = \\`http\\${string}\\`;\n type ExpoRouterRoutes = DynamicRouteTemplate | StaticRoutes | RelativePathString;\n type AllRoutes = ExpoRouterRoutes | ExternalPathString;\n\n /****************\n * Route Utils *\n ****************/\n\n type SearchOrHash = \\`?\\${string}\\` | \\`#\\${string}\\`;\n type UnknownInputParams = Record<string, string | number | (string | number)[]>;\n type UnknownOutputParams = Record<string, string | string[]>;\n\n /**\n * Return only the RoutePart of a string. If the string has multiple parts return never\n *\n * string | type\n * ---------|------\n * 123 | 123\n * /123/abc | never\n * 123?abc | never\n * ./123 | never\n * /123 | never\n * 123/../ | never\n */\n type SingleRoutePart<S extends string> = S extends \\`\\${string}/\\${string}\\`\n ? never\n : S extends \\`\\${string}\\${SearchOrHash}\\`\n ? never\n : S extends ''\n ? never\n : S extends \\`(\\${string})\\`\n ? never\n : S extends \\`[\\${string}]\\`\n ? never\n : S;\n\n /**\n * Return only the CatchAll router part. If the string has search parameters or a hash return never\n */\n type CatchAllRoutePart<S extends string> = S extends \\`\\${string}\\${SearchOrHash}\\`\n ? never\n : S extends ''\n ? never\n : S extends \\`\\${string}(\\${string})\\${string}\\`\n ? never\n : S extends \\`\\${string}[\\${string}]\\${string}\\`\n ? never\n : S;\n\n // type OptionalCatchAllRoutePart<S extends string> = S extends \\`\\${string}\\${SearchOrHash}\\` ? never : S\n\n /**\n * Return the name of a route parameter\n * '[test]' -> 'test'\n * 'test' -> never\n * '[...test]' -> '...test'\n */\n type IsParameter<Part> = Part extends \\`[\\${infer ParamName}]\\` ? ParamName : never;\n\n /**\n * Return a union of all parameter names. If there are no names return never\n *\n * /[test] -> 'test'\n * /[abc]/[...def] -> 'abc'|'...def'\n */\n type ParameterNames<Path> = Path extends \\`\\${infer PartA}/\\${infer PartB}\\`\n ? IsParameter<PartA> | ParameterNames<PartB>\n : IsParameter<Path>;\n\n /**\n * Returns all segements of a route.\n *\n * /(group)/123/abc/[id]/[...rest] -> ['(group)', '123', 'abc', '[id]', '[...rest]'\n */\n type RouteSegments<Path> = Path extends \\`\\${infer PartA}/\\${infer PartB}\\`\n ? PartA extends '' | '.'\n ? [...RouteSegments<PartB>]\n : [PartA, ...RouteSegments<PartB>]\n : Path extends ''\n ? []\n : [Path];\n\n /**\n * Returns a Record of the routes parameters as strings and CatchAll parameters\n *\n * There are two versions, input and output, as you can input 'string | number' but\n * the output will always be 'string'\n *\n * /[id]/[...rest] -> { id: string, rest: string[] }\n * /no-params -> {}\n */\n type InputRouteParams<Path> = {\n [Key in ParameterNames<Path> as Key extends \\`...\\${infer Name}\\`\n ? Name\n : Key]: Key extends \\`...\\${string}\\` ? (string | number)[] : string | number;\n } & UnknownInputParams;\n\n type OutputRouteParams<Path> = {\n [Key in ParameterNames<Path> as Key extends \\`...\\${infer Name}\\`\n ? Name\n : Key]: Key extends \\`...\\${string}\\` ? string[] : string;\n } & UnknownOutputParams;\n\n /**\n * Returns the search parameters for a route.\n */\n export type SearchParams<T extends AllRoutes> = T extends DynamicRouteTemplate\n ? OutputRouteParams<T>\n : T extends StaticRoutes\n ? never\n : UnknownOutputParams;\n\n /**\n * Route is mostly used as part of Href to ensure that a valid route is provided\n *\n * Given a dynamic route, this will return never. This is helpful for conditional logic\n *\n * /test -> /test, /test2, etc\n * /test/[abc] -> never\n * /test/resolve -> /test, /test2, etc\n *\n * Note that if we provide a value for [abc] then the route is allowed\n *\n * This is named Route to prevent confusion, as users they will often see it in tooltips\n */\n export type Route<T> = T extends string\n ? T extends DynamicRouteTemplate\n ? never\n :\n | StaticRoutes\n | RelativePathString\n | ExternalPathString\n | (T extends \\`\\${infer P}\\${SearchOrHash}\\`\n ? P extends DynamicRoutes<infer _>\n ? T\n : never\n : T extends DynamicRoutes<infer _>\n ? T\n : never)\n : never;\n\n /*********\n * Href *\n *********/\n\n export type Href<T> = T extends Record<'pathname', string> ? HrefObject<T> : Route<T>;\n\n export type HrefObject<\n R extends Record<'pathname', string>,\n P = R['pathname'],\n > = P extends DynamicRouteTemplate\n ? { pathname: P; params: InputRouteParams<P> }\n : P extends Route<P>\n ? { pathname: Route<P> | DynamicRouteTemplate; params?: never | InputRouteParams<never> }\n : never;\n\n /***********************\n * Expo Router Exports *\n ***********************/\n\n export type Router = Omit<OriginalRouter, 'push' | 'replace' | 'setParams'> & {\n /** Navigate to the provided href. */\n push: <T>(href: Href<T>) => void;\n /** Navigate to route without appending to the history. */\n replace: <T>(href: Href<T>) => void;\n /** Update the current route query params. */\n setParams: <T = ''>(params?: T extends '' ? Record<string, string> : InputRouteParams<T>) => void;\n };\n\n /** The imperative router. */\n export const router: Router;\n\n /************\n * <Link /> *\n ************/\n export interface LinkProps<T> extends OriginalLinkProps {\n href: Href<T>;\n }\n\n export interface LinkComponent {\n <T>(props: React.PropsWithChildren<LinkProps<T>>): JSX.Element;\n /** Helper method to resolve an Href object into a string. */\n resolveHref: <T>(href: Href<T>) => string;\n }\n\n /**\n * Component to render link to another route using a path.\n * Uses an anchor tag on the web.\n *\n * @param props.href Absolute path to route (e.g. \\`/feeds/hot\\`).\n * @param props.replace Should replace the current route without adding to the history.\n * @param props.asChild Forward props to child component. Useful for custom buttons.\n * @param props.children Child elements to render the content.\n */\n export const Link: LinkComponent;\n \n /** Redirects to the href as soon as the component is mounted. */\n export const Redirect: <T>(\n props: React.PropsWithChildren<{ href: Href<T> }>\n ) => JSX.Element;\n\n /************\n * Hooks *\n ************/\n export function useRouter(): Router;\n\n export function useLocalSearchParams<\n T extends AllRoutes | UnknownOutputParams = UnknownOutputParams,\n >(): T extends AllRoutes ? SearchParams<T> : T;\n\n /** @deprecated renamed to \\`useGlobalSearchParams\\` */\n export function useSearchParams<\n T extends AllRoutes | UnknownOutputParams = UnknownOutputParams,\n >(): T extends AllRoutes ? SearchParams<T> : T;\n\n export function useGlobalSearchParams<\n T extends AllRoutes | UnknownOutputParams = UnknownOutputParams,\n >(): T extends AllRoutes ? SearchParams<T> : T;\n\n export function useSegments<\n T extends AbsoluteRoute | RouteSegments<AbsoluteRoute> | RelativePathString,\n >(): T extends AbsoluteRoute ? RouteSegments<T> : T extends string ? string[] : T;\n}\n`;\n"],"names":["setupTypedRoutes","getTemplateString","getTypedRoutesUtils","extrapolateGroupRoutes","CAPTURE_DYNAMIC_PARAMS","CATCH_ALL","SLUG","ARRAY_GROUP_REGEX","CAPTURE_GROUP_REGEX","server","metro","typesDirectory","projectRoot","routerDirectory","absoluteRouterDirectory","path","join","filePathToRoute","staticRoutes","dynamicRoutes","addFilePath","isRouteFile","metroWatchTypeScriptFiles","eventTypes","callback","filePath","type","shouldRegenerate","route","delete","regenerateRouterDotTS","Set","values","flatMap","v","Array","from","keys","directoryExistsAsync","walk","debounce","typesDir","dynamicRouteTemplates","fs","mkdir","recursive","writeFile","resolve","routerDotTSTemplate","setToUnionType","dynamicRouteParams","appRoot","filePathSeperator","sep","Map","normalizedFilePath","replaceAll","normalizedAppRoot","replace","match","relative","startsWith","isAbsolute","has","dynamicParams","matchAll","map","isDynamic","size","addRoute","originalRoute","set","get","add","includes","routeWithoutGroups","routeWithSingleGroup","s","directory","files","readdir","file","p","stat","isDirectory","normalizedPath","routes","groupsMatch","group","trim","unsafeTemplate"],"mappings":"AAAA;;;;QA6BsBA,gBAAgB,GAAhBA,gBAAgB;QAoFtBC,iBAAiB,GAAjBA,iBAAiB;QAiBjBC,mBAAmB,GAAnBA,mBAAmB;QA4InBC,sBAAsB,GAAtBA,sBAAsB;;AA9QvB,IAAA,SAAa,kCAAb,aAAa,EAAA;AACH,IAAA,OAAQ,WAAR,QAAQ,CAAA;AAEhB,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEc,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AAC1B,IAAA,SAAyB,WAAzB,yBAAyB,CAAA;AAEd,IAAA,0BAAoC,WAApC,oCAAoC,CAAA;;;;;;AAGvE,MAAMC,sBAAsB,6BAA6B,AAAC;QAApDA,sBAAsB,GAAtBA,sBAAsB;AAE5B,MAAMC,SAAS,mBAAmB,AAAC;QAA7BA,SAAS,GAATA,SAAS;AAEf,MAAMC,IAAI,aAAa,AAAC;QAAlBA,IAAI,GAAJA,IAAI;AAEV,MAAMC,iBAAiB,2BAA2B,AAAC;QAA7CA,iBAAiB,GAAjBA,iBAAiB;AAEvB,MAAMC,mBAAmB,wCAAwC,AAAC;QAA5DA,mBAAmB,GAAnBA,mBAAmB;AAUzB,eAAeR,g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CAAC,CAAC;QAClB,OAAO0D,MAAM,CAAC;KACf;IAED,MAAMC,WAAW,GAAG5B,KAAK,CAAC,CAAC,CAAC,AAAC;IAE7B,KAAK,MAAM6B,KAAK,IAAID,WAAW,CAACtB,QAAQ,CAACzD,mBAAmB,CAAC,CAAE;QAC7DL,sBAAsB,CAACyB,KAAK,CAAC8B,OAAO,CAAC6B,WAAW,EAAE,CAAC,CAAC,EAAEC,KAAK,CAAC,CAAC,CAAC,CAACC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAEH,MAAM,CAAC,CAAC;KACpF;IAED,OAAOA,MAAM,CAAC;CACf;AAED;;;;GAIG,CACH,MAAMtC,mBAAmB,GAAG0C,SAAc,eAAA,CAAC;;;;;;;;;sBASrB,EAAE,cAAc,CAAC;;yCAEE,EAAE,eAAe,CAAC;;8BAE7B,EAAE,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmOrD,CAAC,AAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/type-generation/routes.ts"],"sourcesContent":["import fs from 'fs/promises';\nimport { debounce } from 'lodash';\nimport { Server } from 'metro';\nimport path from 'path';\n\nimport { directoryExistsAsync } from '../../../utils/dir';\nimport { unsafeTemplate } from '../../../utils/template';\nimport { ServerLike } from '../BundlerDevServer';\nimport { metroWatchTypeScriptFiles } from '../metro/metroWatchTypeScriptFiles';\n\n// /test/[...param1]/[param2]/[param3] - captures [\"param1\", \"param2\", \"param3\"]\nexport const CAPTURE_DYNAMIC_PARAMS = /\\[(?:\\.{3})?(\\w*?)[\\]$]/g;\n// /[...param1]/ - Match [...param1]\nexport const CATCH_ALL = /\\[\\.\\.\\..+?\\]/g;\n// /[param1] - Match [param1]\nexport const SLUG = /\\[.+?\\]/g;\n// /(group1,group2,group3)/test - match (group1,group2,group3)\nexport const ARRAY_GROUP_REGEX = /\\(\\s*\\w[\\w\\s]*?,.*?\\)/g;\n// /(group1,group2,group3)/test - captures [\"group1\", \"group2\", \"group3\"]\nexport const CAPTURE_GROUP_REGEX = /[\\\\(,]\\s*(\\w[\\w\\s]*?)\\s*(?=[,\\\\)])/g;\n\nexport interface SetupTypedRoutesOptions {\n server?: ServerLike;\n metro?: Server | null;\n typesDirectory: string;\n projectRoot: string;\n /** Absolute expo router routes directory. */\n routerDirectory: string;\n}\n\nexport async function setupTypedRoutes({\n server,\n metro,\n typesDirectory,\n projectRoot,\n routerDirectory,\n}: SetupTypedRoutesOptions) {\n const { filePathToRoute, staticRoutes, dynamicRoutes, addFilePath, isRouteFile } =\n getTypedRoutesUtils(routerDirectory);\n\n if (metro && server) {\n // Setup out watcher first\n metroWatchTypeScriptFiles({\n projectRoot,\n server,\n metro,\n eventTypes: ['add', 'delete', 'change'],\n async callback({ filePath, type }) {\n if (!isRouteFile(filePath)) {\n return;\n }\n\n let shouldRegenerate = false;\n\n if (type === 'delete') {\n const route = filePathToRoute(filePath);\n staticRoutes.delete(route);\n dynamicRoutes.delete(route);\n shouldRegenerate = true;\n } else {\n shouldRegenerate = addFilePath(filePath);\n }\n\n if (shouldRegenerate) {\n regenerateRouterDotTS(\n typesDirectory,\n new Set([...staticRoutes.values()].flatMap((v) => Array.from(v))),\n new Set([...dynamicRoutes.values()].flatMap((v) => Array.from(v))),\n new Set(dynamicRoutes.keys())\n );\n }\n },\n });\n }\n\n if (await directoryExistsAsync(routerDirectory)) {\n // Do we need to walk the entire tree on startup?\n // Idea: Store the list of files in the last write, then simply check Git for what files have changed\n await walk(routerDirectory, addFilePath);\n }\n\n regenerateRouterDotTS(\n typesDirectory,\n new Set([...staticRoutes.values()].flatMap((v) => Array.from(v))),\n new Set([...dynamicRoutes.values()].flatMap((v) => Array.from(v))),\n new Set(dynamicRoutes.keys())\n );\n}\n\n/**\n * Generate a router.d.ts file that contains all of the routes in the project.\n * Should be debounced as its very common for developers to make changes to multiple files at once (eg Save All)\n */\nconst regenerateRouterDotTS = debounce(\n async (\n typesDir: string,\n staticRoutes: Set<string>,\n dynamicRoutes: Set<string>,\n dynamicRouteTemplates: Set<string>\n ) => {\n await fs.mkdir(typesDir, { recursive: true });\n await fs.writeFile(\n path.resolve(typesDir, './router.d.ts'),\n getTemplateString(staticRoutes, dynamicRoutes, dynamicRouteTemplates)\n );\n },\n 100\n);\n\n/*\n * This is exported for testing purposes\n */\nexport function getTemplateString(\n staticRoutes: Set<string>,\n dynamicRoutes: Set<string>,\n dynamicRouteTemplates: Set<string>\n) {\n return routerDotTSTemplate({\n staticRoutes: setToUnionType(staticRoutes),\n dynamicRoutes: setToUnionType(dynamicRoutes),\n dynamicRouteParams: setToUnionType(dynamicRouteTemplates),\n });\n}\n\n/**\n * Utility functions for typed routes\n *\n * These are extracted for easier testing\n */\nexport function getTypedRoutesUtils(appRoot: string, filePathSeperator = path.sep) {\n /*\n * staticRoutes are a map where the key if the route without groups and the value\n * is another set of all group versions of the route. e.g,\n * Map([\n * [\"/\", [\"/(app)/(notes)\", \"/(app)/(profile)\"]\n * ])\n */\n const staticRoutes = new Map<string, Set<string>>([['/', new Set('/')]]);\n /*\n * dynamicRoutes are the same as staticRoutes (key if the resolved route,\n * and the value is a set of possible routes). e.g:\n *\n * /[...fruits] -> /${CatchAllRoutePart<T>}\n * /color/[color] -> /color/${SingleRoutePart<T>}\n *\n * The keys of this map are also important, as they can be used as \"static\" types\n * <Link href={{ pathname: \"/[...fruits]\",params: { fruits: [\"apple\"] } }} />\n */\n const dynamicRoutes = new Map<string, Set<string>>();\n\n function normalizedFilePath(filePath: string) {\n return filePath.replaceAll(filePathSeperator, '/');\n }\n\n const normalizedAppRoot = normalizedFilePath(appRoot);\n\n const filePathToRoute = (filePath: string) => {\n return normalizedFilePath(filePath)\n .replace(normalizedAppRoot, '')\n .replace(/index\\.[jt]sx?/, '')\n .replace(/\\.[jt]sx?$/, '');\n };\n\n const isRouteFile = (filePath: string) => {\n // Layout and filenames starting with `+` are not routes\n if (filePath.match(/_layout\\.[tj]sx?$/) || filePath.match(/\\/\\+/)) {\n return false;\n }\n\n // Route files must be nested with in the appRoot\n const relative = path.relative(appRoot, filePath);\n return relative && !relative.startsWith('..') && !path.isAbsolute(relative);\n };\n\n const addFilePath = (filePath: string): boolean => {\n if (!isRouteFile(filePath)) {\n return false;\n }\n\n const route = filePathToRoute(filePath);\n\n // We have already processed this file\n if (staticRoutes.has(route) || dynamicRoutes.has(route)) {\n return false;\n }\n\n const dynamicParams = new Set(\n [...route.matchAll(CAPTURE_DYNAMIC_PARAMS)].map((match) => match[1])\n );\n const isDynamic = dynamicParams.size > 0;\n\n const addRoute = (originalRoute: string, route: string) => {\n if (isDynamic) {\n let set = dynamicRoutes.get(originalRoute);\n\n if (!set) {\n set = new Set();\n dynamicRoutes.set(originalRoute, set);\n }\n\n set.add(\n route\n .replaceAll(CATCH_ALL, '${CatchAllRoutePart<T>}')\n .replaceAll(SLUG, '${SingleRoutePart<T>}')\n );\n } else {\n let set = staticRoutes.get(originalRoute);\n\n if (!set) {\n set = new Set();\n staticRoutes.set(originalRoute, set);\n }\n\n set.add(route);\n }\n };\n\n if (!route.match(ARRAY_GROUP_REGEX)) {\n addRoute(route, route);\n }\n\n // Does this route have a group? eg /(group)\n if (route.includes('/(')) {\n const routeWithoutGroups = route.replace(/\\/\\(.+?\\)/g, '');\n addRoute(route, routeWithoutGroups);\n\n // If there are multiple groups, we need to expand them\n // eg /(test1,test2)/page => /test1/page & /test2/page\n for (const routeWithSingleGroup of extrapolateGroupRoutes(route)) {\n addRoute(route, routeWithSingleGroup);\n }\n }\n\n return true;\n };\n\n return {\n staticRoutes,\n dynamicRoutes,\n filePathToRoute,\n addFilePath,\n isRouteFile,\n };\n}\n\nexport const setToUnionType = <T>(set: Set<T>) => {\n return set.size > 0 ? [...set].map((s) => `\\`${s}\\``).join(' | ') : 'never';\n};\n\n/**\n * Recursively walk a directory and call the callback with the file path.\n */\nasync function walk(directory: string, callback: (filePath: string) => void) {\n const files = await fs.readdir(directory);\n for (const file of files) {\n const p = path.join(directory, file);\n if ((await fs.stat(p)).isDirectory()) {\n await walk(p, callback);\n } else {\n // Normalise the paths so they are easier to convert to URLs\n const normalizedPath = p.replaceAll(path.sep, '/');\n callback(normalizedPath);\n }\n }\n}\n\n/**\n * Given a route, return all possible routes that could be generated from it.\n */\nexport function extrapolateGroupRoutes(\n route: string,\n routes: Set<string> = new Set()\n): Set<string> {\n // Create a version with no groups. We will then need to cleanup double and/or trailing slashes\n routes.add(route.replaceAll(ARRAY_GROUP_REGEX, '').replaceAll(/\\/+/g, '/').replace(/\\/$/, ''));\n\n const match = route.match(ARRAY_GROUP_REGEX);\n\n if (!match) {\n routes.add(route);\n return routes;\n }\n\n const groupsMatch = match[0];\n\n for (const group of groupsMatch.matchAll(CAPTURE_GROUP_REGEX)) {\n extrapolateGroupRoutes(route.replace(groupsMatch, `(${group[1].trim()})`), routes);\n }\n\n return routes;\n}\n\n/**\n * NOTE: This code refers to a specific version of `expo-router` and is therefore unsafe to\n * mix with arbitrary versions.\n * TODO: Version this code with `expo-router` or version expo-router with `@expo/cli`.\n */\nconst routerDotTSTemplate = unsafeTemplate`/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable import/export */\n/* eslint-disable @typescript-eslint/ban-types */\ndeclare module \"expo-router\" {\n import type { LinkProps as OriginalLinkProps } from 'expo-router/build/link/Link';\n import type { Router as OriginalRouter } from 'expo-router/src/types';\n export * from 'expo-router/build';\n\n // prettier-ignore\n type StaticRoutes = ${'staticRoutes'};\n // prettier-ignore\n type DynamicRoutes<T extends string> = ${'dynamicRoutes'};\n // prettier-ignore\n type DynamicRouteTemplate = ${'dynamicRouteParams'};\n\n type RelativePathString = \\`./\\${string}\\` | \\`../\\${string}\\` | '..';\n type AbsoluteRoute = DynamicRouteTemplate | StaticRoutes;\n type ExternalPathString = \\`http\\${string}\\`;\n type ExpoRouterRoutes = DynamicRouteTemplate | StaticRoutes | RelativePathString;\n type AllRoutes = ExpoRouterRoutes | ExternalPathString;\n\n /****************\n * Route Utils *\n ****************/\n\n type SearchOrHash = \\`?\\${string}\\` | \\`#\\${string}\\`;\n type UnknownInputParams = Record<string, string | number | (string | number)[]>;\n type UnknownOutputParams = Record<string, string | string[]>;\n\n /**\n * Return only the RoutePart of a string. If the string has multiple parts return never\n *\n * string | type\n * ---------|------\n * 123 | 123\n * /123/abc | never\n * 123?abc | never\n * ./123 | never\n * /123 | never\n * 123/../ | never\n */\n type SingleRoutePart<S extends string> = S extends \\`\\${string}/\\${string}\\`\n ? never\n : S extends \\`\\${string}\\${SearchOrHash}\\`\n ? never\n : S extends ''\n ? never\n : S extends \\`(\\${string})\\`\n ? never\n : S extends \\`[\\${string}]\\`\n ? never\n : S;\n\n /**\n * Return only the CatchAll router part. If the string has search parameters or a hash return never\n */\n type CatchAllRoutePart<S extends string> = S extends \\`\\${string}\\${SearchOrHash}\\`\n ? never\n : S extends ''\n ? never\n : S extends \\`\\${string}(\\${string})\\${string}\\`\n ? never\n : S extends \\`\\${string}[\\${string}]\\${string}\\`\n ? never\n : S;\n\n // type OptionalCatchAllRoutePart<S extends string> = S extends \\`\\${string}\\${SearchOrHash}\\` ? never : S\n\n /**\n * Return the name of a route parameter\n * '[test]' -> 'test'\n * 'test' -> never\n * '[...test]' -> '...test'\n */\n type IsParameter<Part> = Part extends \\`[\\${infer ParamName}]\\` ? ParamName : never;\n\n /**\n * Return a union of all parameter names. If there are no names return never\n *\n * /[test] -> 'test'\n * /[abc]/[...def] -> 'abc'|'...def'\n */\n type ParameterNames<Path> = Path extends \\`\\${infer PartA}/\\${infer PartB}\\`\n ? IsParameter<PartA> | ParameterNames<PartB>\n : IsParameter<Path>;\n\n /**\n * Returns all segements of a route.\n *\n * /(group)/123/abc/[id]/[...rest] -> ['(group)', '123', 'abc', '[id]', '[...rest]'\n */\n type RouteSegments<Path> = Path extends \\`\\${infer PartA}/\\${infer PartB}\\`\n ? PartA extends '' | '.'\n ? [...RouteSegments<PartB>]\n : [PartA, ...RouteSegments<PartB>]\n : Path extends ''\n ? []\n : [Path];\n\n /**\n * Returns a Record of the routes parameters as strings and CatchAll parameters\n *\n * There are two versions, input and output, as you can input 'string | number' but\n * the output will always be 'string'\n *\n * /[id]/[...rest] -> { id: string, rest: string[] }\n * /no-params -> {}\n */\n type InputRouteParams<Path> = {\n [Key in ParameterNames<Path> as Key extends \\`...\\${infer Name}\\`\n ? Name\n : Key]: Key extends \\`...\\${string}\\` ? (string | number)[] : string | number;\n } & UnknownInputParams;\n\n type OutputRouteParams<Path> = {\n [Key in ParameterNames<Path> as Key extends \\`...\\${infer Name}\\`\n ? Name\n : Key]: Key extends \\`...\\${string}\\` ? string[] : string;\n } & UnknownOutputParams;\n\n /**\n * Returns the search parameters for a route.\n */\n export type SearchParams<T extends AllRoutes> = T extends DynamicRouteTemplate\n ? OutputRouteParams<T>\n : T extends StaticRoutes\n ? never\n : UnknownOutputParams;\n\n /**\n * Route is mostly used as part of Href to ensure that a valid route is provided\n *\n * Given a dynamic route, this will return never. This is helpful for conditional logic\n *\n * /test -> /test, /test2, etc\n * /test/[abc] -> never\n * /test/resolve -> /test, /test2, etc\n *\n * Note that if we provide a value for [abc] then the route is allowed\n *\n * This is named Route to prevent confusion, as users they will often see it in tooltips\n */\n export type Route<T> = T extends string\n ? T extends DynamicRouteTemplate\n ? never\n :\n | StaticRoutes\n | RelativePathString\n | ExternalPathString\n | (T extends \\`\\${infer P}\\${SearchOrHash}\\`\n ? P extends DynamicRoutes<infer _>\n ? T\n : never\n : T extends DynamicRoutes<infer _>\n ? T\n : never)\n : never;\n\n /*********\n * Href *\n *********/\n\n export type Href<T> = T extends Record<'pathname', string> ? HrefObject<T> : Route<T>;\n\n export type HrefObject<\n R extends Record<'pathname', string>,\n P = R['pathname'],\n > = P extends DynamicRouteTemplate\n ? { pathname: P; params: InputRouteParams<P> }\n : P extends Route<P>\n ? { pathname: Route<P> | DynamicRouteTemplate; params?: never | InputRouteParams<never> }\n : never;\n\n /***********************\n * Expo Router Exports *\n ***********************/\n\n export type Router = Omit<OriginalRouter, 'push' | 'replace' | 'setParams'> & {\n /** Navigate to the provided href. */\n push: <T>(href: Href<T>) => void;\n /** Navigate to route without appending to the history. */\n replace: <T>(href: Href<T>) => void;\n /** Update the current route query params. */\n setParams: <T = ''>(params?: T extends '' ? Record<string, string> : InputRouteParams<T>) => void;\n };\n\n /** The imperative router. */\n export const router: Router;\n\n /************\n * <Link /> *\n ************/\n export interface LinkProps<T> extends OriginalLinkProps {\n href: Href<T>;\n }\n\n export interface LinkComponent {\n <T>(props: React.PropsWithChildren<LinkProps<T>>): JSX.Element;\n /** Helper method to resolve an Href object into a string. */\n resolveHref: <T>(href: Href<T>) => string;\n }\n\n /**\n * Component to render link to another route using a path.\n * Uses an anchor tag on the web.\n *\n * @param props.href Absolute path to route (e.g. \\`/feeds/hot\\`).\n * @param props.replace Should replace the current route without adding to the history.\n * @param props.asChild Forward props to child component. Useful for custom buttons.\n * @param props.children Child elements to render the content.\n */\n export const Link: LinkComponent;\n \n /** Redirects to the href as soon as the component is mounted. */\n export const Redirect: <T>(\n props: React.PropsWithChildren<{ href: Href<T> }>\n ) => JSX.Element;\n\n /************\n * Hooks *\n ************/\n export function useRouter(): Router;\n\n export function useLocalSearchParams<\n T extends AllRoutes | UnknownOutputParams = UnknownOutputParams,\n >(): T extends AllRoutes ? SearchParams<T> : T;\n\n /** @deprecated renamed to \\`useGlobalSearchParams\\` */\n export function useSearchParams<\n T extends AllRoutes | UnknownOutputParams = UnknownOutputParams,\n >(): T extends AllRoutes ? SearchParams<T> : T;\n\n export function useGlobalSearchParams<\n T extends AllRoutes | UnknownOutputParams = UnknownOutputParams,\n >(): T extends AllRoutes ? SearchParams<T> : T;\n\n export function useSegments<\n T extends AbsoluteRoute | RouteSegments<AbsoluteRoute> | RelativePathString,\n >(): T extends AbsoluteRoute ? RouteSegments<T> : T extends string ? string[] : T;\n}\n`;\n"],"names":["setupTypedRoutes","getTemplateString","getTypedRoutesUtils","extrapolateGroupRoutes","CAPTURE_DYNAMIC_PARAMS","CATCH_ALL","SLUG","ARRAY_GROUP_REGEX","CAPTURE_GROUP_REGEX","server","metro","typesDirectory","projectRoot","routerDirectory","filePathToRoute","staticRoutes","dynamicRoutes","addFilePath","isRouteFile","metroWatchTypeScriptFiles","eventTypes","callback","filePath","type","shouldRegenerate","route","delete","regenerateRouterDotTS","Set","values","flatMap","v","Array","from","keys","directoryExistsAsync","walk","debounce","typesDir","dynamicRouteTemplates","fs","mkdir","recursive","writeFile","path","resolve","routerDotTSTemplate","setToUnionType","dynamicRouteParams","appRoot","filePathSeperator","sep","Map","normalizedFilePath","replaceAll","normalizedAppRoot","replace","match","relative","startsWith","isAbsolute","has","dynamicParams","matchAll","map","isDynamic","size","addRoute","originalRoute","set","get","add","includes","routeWithoutGroups","routeWithSingleGroup","s","join","directory","files","readdir","file","p","stat","isDirectory","normalizedPath","routes","groupsMatch","group","trim","unsafeTemplate"],"mappings":"AAAA;;;;QA8BsBA,gBAAgB,GAAhBA,gBAAgB;QAkFtBC,iBAAiB,GAAjBA,iBAAiB;QAiBjBC,mBAAmB,GAAnBA,mBAAmB;QA4InBC,sBAAsB,GAAtBA,sBAAsB;;AA7QvB,IAAA,SAAa,kCAAb,aAAa,EAAA;AACH,IAAA,OAAQ,WAAR,QAAQ,CAAA;AAEhB,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEc,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AAC1B,IAAA,SAAyB,WAAzB,yBAAyB,CAAA;AAEd,IAAA,0BAAoC,WAApC,oCAAoC,CAAA;;;;;;AAGvE,MAAMC,sBAAsB,6BAA6B,AAAC;QAApDA,sBAAsB,G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AQ,EAAE,CAAC,CAAC,CAAC;IAE/F,MAAMC,KAAK,GAAGhC,KAAK,CAACgC,KAAK,CAAClD,iBAAiB,CAAC,AAAC;IAE7C,IAAI,CAACkD,KAAK,EAAE;QACV4B,MAAM,CAACd,GAAG,CAAC9C,KAAK,CAAC,CAAC;QAClB,OAAO4D,MAAM,CAAC;KACf;IAED,MAAMC,WAAW,GAAG7B,KAAK,CAAC,CAAC,CAAC,AAAC;IAE7B,KAAK,MAAM8B,KAAK,IAAID,WAAW,CAACvB,QAAQ,CAACvD,mBAAmB,CAAC,CAAE;QAC7DL,sBAAsB,CAACsB,KAAK,CAAC+B,OAAO,CAAC8B,WAAW,EAAE,CAAC,CAAC,EAAEC,KAAK,CAAC,CAAC,CAAC,CAACC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAEH,MAAM,CAAC,CAAC;KACpF;IAED,OAAOA,MAAM,CAAC;CACf;AAED;;;;GAIG,CACH,MAAMvC,mBAAmB,GAAG2C,SAAc,eAAA,CAAC;;;;;;;;;sBASrB,EAAE,cAAc,CAAC;;yCAEE,EAAE,eAAe,CAAC;;8BAE7B,EAAE,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmOrD,CAAC,AAAC"}
|
|
@@ -31,7 +31,6 @@ async function startTypescriptTypeGenerationAsync({ metro , projectRoot , server
|
|
|
31
31
|
(0, _mergeGitIgnorePaths).removeFromGitIgnore(gitIgnorePath, "expo-env.d.ts"),
|
|
32
32
|
]);
|
|
33
33
|
} else {
|
|
34
|
-
var ref1, ref2;
|
|
35
34
|
const dotExpoDir = (0, _dotExpo).ensureDotExpoProjectDirectoryInitialized(projectRoot);
|
|
36
35
|
const typesDirectory = _path.default.resolve(dotExpoDir, "./types");
|
|
37
36
|
debug("Ensuring typed routes side-effects are setup (experiments.typedRoutes: true, typesDirectory: %s)", typesDirectory);
|
|
@@ -39,7 +38,6 @@ async function startTypescriptTypeGenerationAsync({ metro , projectRoot , server
|
|
|
39
38
|
await _promises.default.mkdir(typesDirectory, {
|
|
40
39
|
recursive: true
|
|
41
40
|
});
|
|
42
|
-
var ref3;
|
|
43
41
|
await Promise.all([
|
|
44
42
|
(0, _mergeGitIgnorePaths).upsertGitIgnoreContents(_path.default.join(projectRoot, ".gitignore"), "expo-env.d.ts"),
|
|
45
43
|
(0, _expoEnv).writeExpoEnvDTS(projectRoot),
|
|
@@ -49,7 +47,7 @@ async function startTypescriptTypeGenerationAsync({ metro , projectRoot , server
|
|
|
49
47
|
server,
|
|
50
48
|
typesDirectory,
|
|
51
49
|
projectRoot,
|
|
52
|
-
routerDirectory: (
|
|
50
|
+
routerDirectory: (0, _router).getRouterDirectoryWithManifest(projectRoot, exp)
|
|
53
51
|
}),
|
|
54
52
|
]);
|
|
55
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/server/type-generation/startTypescriptTypeGeneration.ts"],"sourcesContent":["import { getConfig } from '@expo/config';\nimport fs from 'fs/promises';\nimport { Server } from 'metro';\nimport path from 'path';\n\nimport { removeExpoEnvDTS, writeExpoEnvDTS } from './expo-env';\nimport { setupTypedRoutes } from './routes';\nimport { forceRemovalTSConfig, forceUpdateTSConfig } from './tsconfig';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/type-generation/startTypescriptTypeGeneration.ts"],"sourcesContent":["import { getConfig } from '@expo/config';\nimport fs from 'fs/promises';\nimport { Server } from 'metro';\nimport path from 'path';\n\nimport { removeExpoEnvDTS, writeExpoEnvDTS } from './expo-env';\nimport { setupTypedRoutes } from './routes';\nimport { forceRemovalTSConfig, forceUpdateTSConfig } from './tsconfig';\nimport { removeFromGitIgnore, upsertGitIgnoreContents } from '../../../utils/mergeGitIgnorePaths';\nimport { ensureDotExpoProjectDirectoryInitialized } from '../../project/dotExpo';\nimport { ServerLike } from '../BundlerDevServer';\nimport { getRouterDirectoryWithManifest } from '../metro/router';\n\nexport interface TypeScriptTypeGenerationOptions {\n server?: ServerLike;\n metro?: Server | null;\n projectRoot: string;\n}\n\nconst debug = require('debug')('expo:typed-routes') as typeof console.log;\n\n/** Setup all requisite features for statically typed routes in Expo Router v2 / SDK +49. */\nexport async function startTypescriptTypeGenerationAsync({\n metro,\n projectRoot,\n server,\n}: TypeScriptTypeGenerationOptions) {\n const { exp } = getConfig(projectRoot);\n\n // If typed routes are disabled, remove any files that were added.\n if (!exp.experiments?.typedRoutes) {\n debug('Removing typed routes side-effects (experiments.typedRoutes: false)');\n const gitIgnorePath = path.join(projectRoot, '.gitignore');\n await Promise.all([\n forceRemovalTSConfig(projectRoot),\n removeExpoEnvDTS(projectRoot),\n removeFromGitIgnore(gitIgnorePath, 'expo-env.d.ts'),\n ]);\n } else {\n const dotExpoDir = ensureDotExpoProjectDirectoryInitialized(projectRoot);\n const typesDirectory = path.resolve(dotExpoDir, './types');\n debug(\n 'Ensuring typed routes side-effects are setup (experiments.typedRoutes: true, typesDirectory: %s)',\n typesDirectory\n );\n\n // Ensure the types directory exists.\n await fs.mkdir(typesDirectory, { recursive: true });\n\n await Promise.all([\n upsertGitIgnoreContents(path.join(projectRoot, '.gitignore'), 'expo-env.d.ts'),\n writeExpoEnvDTS(projectRoot),\n forceUpdateTSConfig(projectRoot),\n setupTypedRoutes({\n metro,\n server,\n typesDirectory,\n projectRoot,\n routerDirectory: getRouterDirectoryWithManifest(projectRoot, exp),\n }),\n ]);\n }\n}\n"],"names":["startTypescriptTypeGenerationAsync","debug","require","metro","projectRoot","server","exp","getConfig","experiments","typedRoutes","gitIgnorePath","path","join","Promise","all","forceRemovalTSConfig","removeExpoEnvDTS","removeFromGitIgnore","dotExpoDir","ensureDotExpoProjectDirectoryInitialized","typesDirectory","resolve","fs","mkdir","recursive","upsertGitIgnoreContents","writeExpoEnvDTS","forceUpdateTSConfig","setupTypedRoutes","routerDirectory","getRouterDirectoryWithManifest"],"mappings":"AAAA;;;;QAsBsBA,kCAAkC,GAAlCA,kCAAkC;AAtB9B,IAAA,OAAc,WAAd,cAAc,CAAA;AACzB,IAAA,SAAa,kCAAb,aAAa,EAAA;AAEX,IAAA,KAAM,kCAAN,MAAM,EAAA;AAE2B,IAAA,QAAY,WAAZ,YAAY,CAAA;AAC7B,IAAA,OAAU,WAAV,UAAU,CAAA;AACe,IAAA,SAAY,WAAZ,YAAY,CAAA;AACT,IAAA,oBAAoC,WAApC,oCAAoC,CAAA;AACxC,IAAA,QAAuB,WAAvB,uBAAuB,CAAA;AAEjC,IAAA,OAAiB,WAAjB,iBAAiB,CAAA;;;;;;AAQhE,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC,AAAsB,AAAC;AAGnE,eAAeF,kCAAkC,CAAC,EACvDG,KAAK,CAAA,EACLC,WAAW,CAAA,EACXC,MAAM,CAAA,EAC0B,EAAE;QAI7BC,GAAe;IAHpB,MAAM,EAAEA,GAAG,CAAA,EAAE,GAAGC,CAAAA,GAAAA,OAAS,AAAa,CAAA,UAAb,CAACH,WAAW,CAAC,AAAC;IAEvC,kEAAkE;IAClE,IAAI,CAACE,CAAAA,CAAAA,GAAe,GAAfA,GAAG,CAACE,WAAW,SAAa,GAA5BF,KAAAA,CAA4B,GAA5BA,GAAe,CAAEG,WAAW,CAAA,EAAE;QACjCR,KAAK,CAAC,qEAAqE,CAAC,CAAC;QAC7E,MAAMS,aAAa,GAAGC,KAAI,QAAA,CAACC,IAAI,CAACR,WAAW,EAAE,YAAY,CAAC,AAAC;QAC3D,MAAMS,OAAO,CAACC,GAAG,CAAC;YAChBC,CAAAA,GAAAA,SAAoB,AAAa,C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packDevServer((ref = this.instance) == null ? void 0 : ref.server);
|
|
69
|
-
// Allow any message on native
|
|
70
|
-
if (this.customMessageSocketBroadcaster) {
|
|
71
|
-
this.customMessageSocketBroadcaster(method, params);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
69
|
// TODO(EvanBacon): Custom Webpack overlay.
|
|
75
70
|
// Default webpack-dev-server sockets use "content-changed" instead of "reload" (what we use on native).
|
|
76
71
|
// For now, just manually convert the value so our CLI interface can be unified.
|
|
@@ -82,52 +77,8 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
82
77
|
this.instance.server.sockWrite(this.instance.server.sockets, hackyConvertedMessage, params);
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
|
-
async attachNativeDevServerMiddlewareToDevServer({ server , middleware , attachToServer , logger }) {
|
|
86
|
-
const { attachInspectorProxy , LogReporter } = await Promise.resolve().then(function() {
|
|
87
|
-
return _interopRequireWildcard(require("@expo/dev-server"));
|
|
88
|
-
});
|
|
89
|
-
// Hook up the React Native WebSockets to the Webpack dev server.
|
|
90
|
-
const { messageSocket , debuggerProxy , eventsSocket } = attachToServer(server);
|
|
91
|
-
this.customMessageSocketBroadcaster = messageSocket.broadcast;
|
|
92
|
-
const logReporter = new LogReporter(logger);
|
|
93
|
-
logReporter.reportEvent = eventsSocket.reportEvent;
|
|
94
|
-
const { inspectorProxy } = attachInspectorProxy(this.projectRoot, {
|
|
95
|
-
middleware,
|
|
96
|
-
server
|
|
97
|
-
});
|
|
98
|
-
return {
|
|
99
|
-
messageSocket,
|
|
100
|
-
eventsSocket,
|
|
101
|
-
debuggerProxy,
|
|
102
|
-
logReporter,
|
|
103
|
-
inspectorProxy
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
80
|
isTargetingNative() {
|
|
107
|
-
|
|
108
|
-
return [
|
|
109
|
-
"ios",
|
|
110
|
-
"android"
|
|
111
|
-
].includes(process.env.EXPO_WEBPACK_PLATFORM || "");
|
|
112
|
-
}
|
|
113
|
-
async createNativeDevServerMiddleware({ port , options }) {
|
|
114
|
-
if (!this.isTargetingNative()) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
const { createDevServerMiddleware } = await Promise.resolve().then(function() {
|
|
118
|
-
return _interopRequireWildcard(require("../middleware/createDevServerMiddleware"));
|
|
119
|
-
});
|
|
120
|
-
const nativeMiddleware = createDevServerMiddleware(this.projectRoot, {
|
|
121
|
-
port,
|
|
122
|
-
watchFolders: [
|
|
123
|
-
this.projectRoot
|
|
124
|
-
]
|
|
125
|
-
});
|
|
126
|
-
// Add manifest middleware to the other middleware.
|
|
127
|
-
// TODO: Move this in to expo/dev-server.
|
|
128
|
-
const middleware = await this.getManifestMiddlewareAsync(options);
|
|
129
|
-
nativeMiddleware.middleware.use(middleware.getHandler());
|
|
130
|
-
return nativeMiddleware;
|
|
81
|
+
return false;
|
|
131
82
|
}
|
|
132
83
|
async getAvailablePortAsync(options) {
|
|
133
84
|
try {
|
|
@@ -186,7 +137,6 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
186
137
|
}
|
|
187
138
|
}
|
|
188
139
|
async startImplementationAsync(options) {
|
|
189
|
-
var ref;
|
|
190
140
|
// Do this first to fail faster.
|
|
191
141
|
const webpack = (0, _resolveFromProject).importWebpackFromProject(this.projectRoot);
|
|
192
142
|
const WebpackDevServer = (0, _resolveFromProject).importWebpackDevServerFromProject(this.projectRoot);
|
|
@@ -214,41 +164,18 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
214
164
|
const config = await this.loadConfigAsync(options);
|
|
215
165
|
Log.log(_chalk.default`Starting Webpack on port ${port} in {underline ${mode}} mode.`);
|
|
216
166
|
// Create a webpack compiler that is configured with custom messages.
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
// Create the middleware required for interacting with a native runtime (Expo Go, or a development build).
|
|
221
|
-
nativeMiddleware = await this.createNativeDevServerMiddleware({
|
|
222
|
-
port,
|
|
223
|
-
options
|
|
224
|
-
});
|
|
225
|
-
// Inject the native manifest middleware.
|
|
226
|
-
const originalBefore = config.devServer.before.bind(config.devServer.before);
|
|
227
|
-
config.devServer.before = (app, server, compiler)=>{
|
|
228
|
-
originalBefore(app, server, compiler);
|
|
229
|
-
if (nativeMiddleware == null ? void 0 : nativeMiddleware.middleware) {
|
|
230
|
-
app.use(nativeMiddleware.middleware);
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
const { attachNativeDevServerMiddlewareToDevServer } = this;
|
|
235
|
-
const server1 = new WebpackDevServer(// @ts-expect-error: type mismatch -- Webpack types aren't great.
|
|
236
|
-
compiler1, config.devServer);
|
|
167
|
+
const compiler = webpack(config);
|
|
168
|
+
const server = new WebpackDevServer(// @ts-expect-error: type mismatch -- Webpack types aren't great.
|
|
169
|
+
compiler, config.devServer);
|
|
237
170
|
// Launch WebpackDevServer.
|
|
238
|
-
|
|
239
|
-
if (nativeMiddleware) {
|
|
240
|
-
attachNativeDevServerMiddlewareToDevServer({
|
|
241
|
-
server: this,
|
|
242
|
-
...nativeMiddleware
|
|
243
|
-
});
|
|
244
|
-
}
|
|
171
|
+
server.listen(port, _env.env.WEB_HOST, function(error) {
|
|
245
172
|
if (error) {
|
|
246
173
|
Log.error(error.message);
|
|
247
174
|
}
|
|
248
175
|
});
|
|
249
176
|
// Extend the close method to ensure that we clean up the local info.
|
|
250
|
-
const originalClose =
|
|
251
|
-
|
|
177
|
+
const originalClose = server.close.bind(server);
|
|
178
|
+
server.close = (callback)=>{
|
|
252
179
|
return originalClose((err)=>{
|
|
253
180
|
this.instance = null;
|
|
254
181
|
callback == null ? void 0 : callback(err);
|
|
@@ -258,7 +185,7 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
258
185
|
const protocol = https ? "https" : "http";
|
|
259
186
|
return {
|
|
260
187
|
// Server instance
|
|
261
|
-
server
|
|
188
|
+
server,
|
|
262
189
|
// URL Info
|
|
263
190
|
location: {
|
|
264
191
|
url: `${protocol}://${_host}:${port}`,
|
|
@@ -266,7 +193,7 @@ class WebpackBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
266
193
|
protocol,
|
|
267
194
|
host: _host
|
|
268
195
|
},
|
|
269
|
-
middleware:
|
|
196
|
+
middleware: null,
|
|
270
197
|
// Match the native protocol.
|
|
271
198
|
messageSocket: {
|
|
272
199
|
broadcast: this.broadcastMessage
|