@expo/cli 0.10.10 → 0.10.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,11 +39,6 @@ describe("router.push()", ()=>{
39
39
  it("can accept any external url", ()=>{
40
40
  (0, _tsdLite).expectType(router.push("http://expo.dev"));
41
41
  });
42
- it("throws if using inline search params", ()=>{
43
- // While this is allowed in Expo Router, the Typed Routes version throws as we cannot type it
44
- (0, _tsdLite).expectError(router.push("/colors?color=blue"));
45
- (0, _tsdLite).expectError(router.push("/animals/bear?color=blue"));
46
- });
47
42
  });
48
43
  describe("HrefObject", ()=>{
49
44
  it("will error on non-urls", ()=>{
@@ -100,6 +95,19 @@ describe("router.push()", ()=>{
100
95
  }
101
96
  }));
102
97
  });
98
+ it("allows numeric inputs", ()=>{
99
+ (0, _tsdLite).expectType(router.push({
100
+ pathname: "/mix/[fruit]/[color]/[...animals]",
101
+ params: {
102
+ color: 1,
103
+ fruit: "apple",
104
+ animals: [
105
+ 2,
106
+ "cat"
107
+ ]
108
+ }
109
+ }));
110
+ });
103
111
  it("requires an array for catch all routes", ()=>{
104
112
  (0, _tsdLite).expectError(router.push({
105
113
  pathname: "/animals/[...animal]",
@@ -114,10 +122,7 @@ describe("router.push()", ()=>{
114
122
  params: {
115
123
  color: "red",
116
124
  fruit: "apple",
117
- animals: [
118
- "cat",
119
- "dog"
120
- ]
125
+ animals: []
121
126
  }
122
127
  }));
123
128
  });
@@ -141,6 +146,12 @@ describe("useSearchParams", ()=>{
141
146
  (0, _tsdLite).expectError((0, _basic).useSearchParams());
142
147
  (0, _tsdLite).expectError((0, _basic).useSearchParams());
143
148
  });
149
+ describe("useLocalSearchParams", ()=>{
150
+ (0, _tsdLite).expectType((0, _basic).useLocalSearchParams());
151
+ (0, _tsdLite).expectType((0, _basic).useLocalSearchParams());
152
+ (0, _tsdLite).expectError((0, _basic).useSearchParams());
153
+ (0, _tsdLite).expectError((0, _basic).useSearchParams());
154
+ });
144
155
  describe("useGlobalSearchParams", ()=>{
145
156
  (0, _tsdLite).expectType((0, _basic).useGlobalSearchParams());
146
157
  (0, _tsdLite).expectType((0, _basic).useGlobalSearchParams());
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/start/server/type-generation/__typetests__/route.test.ts"],"sourcesContent":["import { expectType, expectError } from 'tsd-lite';\n\nimport { useGlobalSearchParams, useSegments, useRouter, useSearchParams } from './fixtures/basic';\n\n// eslint-disable-next-line react-hooks/rules-of-hooks\nconst router = useRouter();\n\ndescribe('router.push()', () => {\n // router.push will return void when the type matches, otherwise it should error\n\n describe('href', () => {\n it('will error on non-urls', () => {\n expectError(router.push('should-error'));\n });\n\n it('can accept an absolute url', () => {\n expectType<void>(router.push('/apple'));\n expectType<void>(router.push('/banana'));\n });\n\n it('can accept a ANY relative url', () => {\n // We only type-check absolute urls\n expectType<void>(router.push('./this/work/but/is/not/valid'));\n });\n\n it('works for dynamic urls', () => {\n expectType<void>(router.push('/colors/blue'));\n });\n\n it('works for CatchAll routes', () => {\n expectType<void>(router.push('/animals/bear'));\n expectType<void>(router.push('/animals/bear/cat/dog'));\n expectType<void>(router.push('/mix/apple/blue/cat/dog'));\n });\n\n it.skip('works for optional CatchAll routes', () => {\n // CatchAll routes are not currently optional\n // expectType<void>(router.push('/animals/'));\n });\n\n it('will error when providing extra parameters', () => {\n expectError(router.push('/colors/blue/test'));\n });\n\n it('will error when providing too few parameters', () => {\n expectError(router.push('/mix/apple'));\n expectError(router.push('/mix/apple/cat'));\n });\n\n it('can accept any external url', () => {\n expectType<void>(router.push('http://expo.dev'));\n });\n\n it('throws if using inline search params', () => {\n // While this is allowed in Expo Router, the Typed Routes version throws as we cannot type it\n expectError(router.push('/colors?color=blue'));\n expectError(router.push('/animals/bear?color=blue'));\n });\n });\n\n describe('HrefObject', () => {\n it('will error on non-urls', () => {\n expectError(router.push({ pathname: 'should-error' }));\n });\n\n it('can accept an absolute url', () => {\n expectType<void>(router.push({ pathname: '/apple' }));\n expectType<void>(router.push({ pathname: '/banana' }));\n });\n\n it('can accept a ANY relative url', () => {\n // We only type-check absolute urls\n expectType<void>(router.push({ pathname: './this/work/but/is/not/valid' }));\n });\n\n it('works for dynamic urls', () => {\n expectType<void>(\n router.push({\n pathname: '/colors/[color]',\n params: { color: 'blue' },\n })\n );\n });\n\n it('requires a valid pathname', () => {\n expectError(\n router.push({\n pathname: '/colors/[invalid]',\n params: { color: 'blue' },\n })\n );\n });\n\n it('requires a valid param', () => {\n expectError(\n router.push({\n pathname: '/colors/[color]',\n params: { invalid: 'blue' },\n })\n );\n });\n\n it('works for catch all routes', () => {\n expectType<void>(\n router.push({\n pathname: '/animals/[...animal]',\n params: { animal: ['cat', 'dog'] },\n })\n );\n });\n\n it('requires an array for catch all routes', () => {\n expectError(\n router.push({\n pathname: '/animals/[...animal]',\n params: { animal: 'cat' },\n })\n );\n });\n\n it('works for mixed routes', () => {\n expectType<void>(\n router.push({\n pathname: '/mix/[fruit]/[color]/[...animals]',\n params: { color: 'red', fruit: 'apple', animals: ['cat', 'dog'] },\n })\n );\n });\n\n it('requires all params in mixed routes', () => {\n expectError(\n router.push({\n pathname: '/mix/[fruit]/[color]/[...animals]',\n params: { color: 'red', animals: ['cat', 'dog'] },\n })\n );\n });\n });\n});\n\ndescribe('useSearchParams', () => {\n expectType<Record<'color', string>>(useSearchParams<'/colors/[color]'>());\n expectType<Record<'color', string>>(useSearchParams<Record<'color', string>>());\n expectError(useSearchParams<'/invalid'>());\n expectError(useSearchParams<Record<'custom', string>>());\n});\n\ndescribe('useGlobalSearchParams', () => {\n expectType<Record<'color', string>>(useGlobalSearchParams<'/colors/[color]'>());\n expectType<Record<'color', string>>(useGlobalSearchParams<Record<'color', string>>());\n expectError(useGlobalSearchParams<'/invalid'>());\n expectError(useGlobalSearchParams<Record<'custom', string>>());\n});\n\ndescribe('useSegments', () => {\n it('can accept an absolute url', () => {\n expectType<['apple']>(useSegments<'/apple'>());\n });\n\n it('only accepts valid possible urls', () => {\n expectError(useSegments<'/invalid'>());\n });\n\n it('can accept an array of segments', () => {\n expectType<['apple']>(useSegments<['apple']>());\n });\n\n it('only accepts valid possible segments', () => {\n expectError(useSegments<['invalid segment']>());\n });\n});\n"],"names":["router","useRouter","describe","it","expectError","push","expectType","skip","pathname","params","color","invalid","animal","fruit","animals","useSearchParams","useGlobalSearchParams","useSegments"],"mappings":"AAAA;AAAwC,IAAA,QAAU,WAAV,UAAU,CAAA;AAE6B,IAAA,MAAkB,WAAlB,kBAAkB,CAAA;AAEjG,sDAAsD;AACtD,MAAMA,MAAM,GAAGC,CAAAA,GAAAA,MAAS,AAAE,CAAA,UAAF,EAAE,AAAC;AAE3BC,QAAQ,CAAC,eAAe,EAAE,IAAM;IAC9B,gFAAgF;IAEhFA,QAAQ,CAAC,MAAM,EAAE,IAAM;QACrBC,EAAE,CAAC,wBAAwB,EAAE,IAAM;YACjCC,CAAAA,GAAAA,QAAW,AAA6B,CAAA,YAA7B,CAACJ,MAAM,CAACK,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;SAC1C,CAAC,CAAC;QAEHF,EAAE,CAAC,4BAA4B,EAAE,IAAM;YACrCG,CAAAA,GAAAA,QAAU,AAA6B,CAAA,WAA7B,CAAON,MAAM,CAACK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACxCC,CAAAA,GAAAA,QAAU,AAA8B,CAAA,WAA9B,CAAON,MAAM,CAACK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;SAC1C,CAAC,CAAC;QAEHF,EAAE,CAAC,+BAA+B,EAAE,IAAM;YACxC,mCAAmC;YACnCG,CAAAA,GAAAA,QAAU,AAAmD,CAAA,WAAnD,CAAON,MAAM,CAACK,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;SAC/D,CAAC,CAAC;QAEHF,EAAE,CAAC,wBAAwB,EAAE,IAAM;YACjCG,CAAAA,GAAAA,QAAU,AAAmC,CAAA,WAAnC,CAAON,MAAM,CAACK,IAAI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,AAAc,CAAA,sBAAd,EAAc,CAAC,CAAC;IACjDZ,CAAAA,GAAAA,QAAW,AAAmD,CAAA,YAAnD,CAACY,CAAAA,GAAAA,MAAqB,AAA4B,CAAA,sBAA5B,EAA4B,CAAC,CAAC;CAChE,CAAC,CAAC;AAEHd,QAAQ,CAAC,aAAa,EAAE,IAAM;IAC5BC,EAAE,CAAC,4BAA4B,EAAE,IAAM;QACrCG,CAAAA,GAAAA,QAAU,AAAoC,CAAA,WAApC,CAAYW,CAAAA,GAAAA,MAAW,AAAY,CAAA,YAAZ,EAAY,CAAC,CAAC;KAChD,CAAC,CAAC;IAEHd,EAAE,CAAC,kCAAkC,EAAE,IAAM;QAC3CC,CAAAA,GAAAA,QAAW,AAA2B,CAAA,YAA3B,CAACa,CAAAA,GAAAA,MAAW,AAAc,CAAA,YAAd,EAAc,CAAC,CAAC;KACxC,CAAC,CAAC;IAEHd,EAAE,CAAC,iCAAiC,EAAE,IAAM;QAC1CG,CAAAA,GAAAA,QAAU,AAAqC,CAAA,WAArC,CAAYW,CAAAA,GAAAA,MAAW,AAAa,CAAA,YAAb,EAAa,CAAC,CAAC;KACjD,CAAC,CAAC;IAEHd,EAAE,CAAC,sCAAsC,EAAE,IAAM;QAC/CC,CAAAA,GAAAA,QAAW,AAAoC,CAAA,YAApC,CAACa,CAAAA,GAAAA,MAAW,AAAuB,CAAA,YAAvB,EAAuB,CAAC,CAAC;KACjD,CAAC,CAAC;CACJ,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../../../../src/start/server/type-generation/__typetests__/route.test.ts"],"sourcesContent":["import { expectType, expectError } from 'tsd-lite';\n\nimport {\n useGlobalSearchParams,\n useSegments,\n useRouter,\n useSearchParams,\n useLocalSearchParams,\n} from './fixtures/basic';\n\n// eslint-disable-next-line react-hooks/rules-of-hooks\nconst router = useRouter();\n\ndescribe('router.push()', () => {\n // router.push will return void when the type matches, otherwise it should error\n\n describe('href', () => {\n it('will error on non-urls', () => {\n expectError(router.push('should-error'));\n });\n\n it('can accept an absolute url', () => {\n expectType<void>(router.push('/apple'));\n expectType<void>(router.push('/banana'));\n });\n\n it('can accept a ANY relative url', () => {\n // We only type-check absolute urls\n expectType<void>(router.push('./this/work/but/is/not/valid'));\n });\n\n it('works for dynamic urls', () => {\n expectType<void>(router.push('/colors/blue'));\n });\n\n it('works for CatchAll routes', () => {\n expectType<void>(router.push('/animals/bear'));\n expectType<void>(router.push('/animals/bear/cat/dog'));\n expectType<void>(router.push('/mix/apple/blue/cat/dog'));\n });\n\n it.skip('works for optional CatchAll routes', () => {\n // CatchAll routes are not currently optional\n // expectType<void>(router.push('/animals/'));\n });\n\n it('will error when providing extra parameters', () => {\n expectError(router.push('/colors/blue/test'));\n });\n\n it('will error when providing too few parameters', () => {\n expectError(router.push('/mix/apple'));\n expectError(router.push('/mix/apple/cat'));\n });\n\n it('can accept any external url', () => {\n expectType<void>(router.push('http://expo.dev'));\n });\n });\n\n describe('HrefObject', () => {\n it('will error on non-urls', () => {\n expectError(router.push({ pathname: 'should-error' }));\n });\n\n it('can accept an absolute url', () => {\n expectType<void>(router.push({ pathname: '/apple' }));\n expectType<void>(router.push({ pathname: '/banana' }));\n });\n\n it('can accept a ANY relative url', () => {\n // We only type-check absolute urls\n expectType<void>(router.push({ pathname: './this/work/but/is/not/valid' }));\n });\n\n it('works for dynamic urls', () => {\n expectType<void>(\n router.push({\n pathname: '/colors/[color]',\n params: { color: 'blue' },\n })\n );\n });\n\n it('requires a valid pathname', () => {\n expectError(\n router.push({\n pathname: '/colors/[invalid]',\n params: { color: 'blue' },\n })\n );\n });\n\n it('requires a valid param', () => {\n expectError(\n router.push({\n pathname: '/colors/[color]',\n params: { invalid: 'blue' },\n })\n );\n });\n\n it('works for catch all routes', () => {\n expectType<void>(\n router.push({\n pathname: '/animals/[...animal]',\n params: { animal: ['cat', 'dog'] },\n })\n );\n });\n\n it('allows numeric inputs', () => {\n expectType<void>(\n router.push({\n pathname: '/mix/[fruit]/[color]/[...animals]',\n params: { color: 1, fruit: 'apple', animals: [2, 'cat'] },\n })\n );\n });\n\n it('requires an array for catch all routes', () => {\n expectError(\n router.push({\n pathname: '/animals/[...animal]',\n params: { animal: 'cat' },\n })\n );\n });\n\n it('works for mixed routes', () => {\n expectType<void>(\n router.push({\n pathname: '/mix/[fruit]/[color]/[...animals]',\n params: { color: 'red', fruit: 'apple', animals: [] },\n })\n );\n });\n\n it('requires all params in mixed routes', () => {\n expectError(\n router.push({\n pathname: '/mix/[fruit]/[color]/[...animals]',\n params: { color: 'red', animals: ['cat', 'dog'] },\n })\n );\n });\n });\n});\n\ndescribe('useSearchParams', () => {\n expectType<Record<'color', string>>(useSearchParams<Record<'color', string>>());\n expectType<Record<'color', string> & Record<string, string | string[]>>(\n useSearchParams<'/colors/[color]'>()\n );\n\n expectError(useSearchParams<'/invalid'>());\n expectError(useSearchParams<Record<'custom', Function>>());\n});\n\ndescribe('useLocalSearchParams', () => {\n expectType<Record<'color', string>>(useLocalSearchParams<Record<'color', string>>());\n expectType<Record<'color', string> & Record<string, string | string[]>>(\n useLocalSearchParams<'/colors/[color]'>()\n );\n\n expectError(useSearchParams<'/invalid'>());\n expectError(useSearchParams<Record<'custom', Function>>());\n});\n\ndescribe('useGlobalSearchParams', () => {\n expectType<Record<'color', string>>(useGlobalSearchParams<Record<'color', string>>());\n expectType<Record<'color', string> & Record<string, string | string[]>>(\n useGlobalSearchParams<'/colors/[color]'>()\n );\n\n expectError(useGlobalSearchParams<'/invalid'>());\n expectError(useGlobalSearchParams<Record<'custom', Function>>());\n});\n\ndescribe('useSegments', () => {\n it('can accept an absolute url', () => {\n expectType<['apple']>(useSegments<'/apple'>());\n });\n\n it('only accepts valid possible urls', () => {\n expectError(useSegments<'/invalid'>());\n });\n\n it('can accept an array of segments', () => {\n expectType<['apple']>(useSegments<['apple']>());\n });\n\n it('only accepts valid possible segments', () => {\n expectError(useSegments<['invalid segment']>());\n });\n});\n"],"names":["router","useRouter","describe","it","expectError","push","expectType","skip","pathname","params","color","invalid","animal","fruit","animals","useSearchParams","useLocalSearchParams","useGlobalSearchParams","useSegments"],"mappings":"AAAA;AAAwC,IAAA,QAAU,WAAV,UAAU,CAAA;AAQ3C,IAAA,MAAkB,WAAlB,kBAAkB,CAAA;AAEzB,sDAAsD;AACtD,MAAMA,MAAM,GAAGC,CAAAA,GAAAA,MAAS,AAAE,CAAA,UAAF,EAAE,AAAC;AAE3BC,QAAQ,CAAC,eAAe,EAAE,IAAM;IAC9B,gFAAgF;IAEhFA,QAAQ,CAAC,MAAM,EAAE,IAAM;QACrBC,EAAE,CAAC,wBAAwB,EAAE,IAAM;YACjCC,CAAAA,GAAAA,QAAW,AAA6B,CAAA,YAA7B,CAACJ,MAAM,CAACK,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;SAC1C,CAAC,CAAC;QAEHF,EAAE,CAAC,4BAA4B,EAAE,IAAM;YACrCG,CAAAA,GAAAA,QAAU,AAA6B,CAAA,WAA7B,CAAON,MAAM,CAACK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACxCC,CAAAA,GAAAA,QAAU,AAA8B,CAAA,WAA9B,CAAON,MAAM,CAACK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;SAC1C,CAAC,CAAC;QAEHF,EAAE,CAAC,+BAA+B,EAAE,IAAM;YACxC,mCAAmC;YACnCG,CAAAA,GAAAA,QAAU,AAAmD,CAAA,WAAnD,CAAON,MAAM,CAACK,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;SAC/D,CAAC,CAAC;QAEHF,EAAE,CAAC,wBAAwB,EAAE,IAAM;YACjCG,CAAAA,GAAAA,QAAU,AAAmC,CAAA,WAAnC,CAAON,MAAM,CAACK,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;SAC/C,CAAC,CAAC;QAEHF,EAAE,CAAC,2BAA2B,EAAE,IAAM;YACpCG,CAAAA,GAAAA,QAAU,AAAoC,CAAA,WAApC,CAAON,MAAM,CAACK,IAAI,CAAC,eAAe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AC;CACJ,CAAC,CAAC"}
@@ -10,6 +10,7 @@ exports.setToUnionType = exports.CAPTURE_GROUP_REGEX = exports.ARRAY_GROUP_REGEX
10
10
  var _promises = _interopRequireDefault(require("fs/promises"));
11
11
  var _lodash = require("lodash");
12
12
  var _path = _interopRequireDefault(require("path"));
13
+ var _dir = require("../../../utils/dir");
13
14
  var _template = require("../../../utils/template");
14
15
  var _metroWatchTypeScriptFiles = require("../metro/metroWatchTypeScriptFiles");
15
16
  function _interopRequireDefault(obj) {
@@ -23,17 +24,17 @@ const CATCH_ALL = /\[\.\.\..+?\]/g;
23
24
  exports.CATCH_ALL = CATCH_ALL;
24
25
  const SLUG = /\[.+?\]/g;
25
26
  exports.SLUG = SLUG;
26
- const ARRAY_GROUP_REGEX = /\(\w+?,.*?\)/g;
27
+ const ARRAY_GROUP_REGEX = /\(\s*\w[\w\s]*?,.*?\)/g;
27
28
  exports.ARRAY_GROUP_REGEX = ARRAY_GROUP_REGEX;
28
- const CAPTURE_GROUP_REGEX = /[\\(,](\w+?)(?=[,\\)])/g;
29
+ const CAPTURE_GROUP_REGEX = /[\\(,]\s*(\w[\w\s]*?)\s*(?=[,\\)])/g;
29
30
  exports.CAPTURE_GROUP_REGEX = CAPTURE_GROUP_REGEX;
30
31
  async function setupTypedRoutes({ server , metro , typesDirectory , projectRoot , routerDirectory }) {
31
- const appRoot = _path.default.join(projectRoot, routerDirectory);
32
- const { filePathToRoute , staticRoutes , dynamicRoutes , addFilePath } = getTypedRoutesUtils(appRoot);
32
+ const absoluteRouterDirectory = _path.default.join(projectRoot, routerDirectory);
33
+ const { filePathToRoute , staticRoutes , dynamicRoutes , addFilePath , isRouteFile } = getTypedRoutesUtils(absoluteRouterDirectory);
33
34
  if (metro) {
34
35
  // Setup out watcher first
35
36
  (0, _metroWatchTypeScriptFiles).metroWatchTypeScriptFiles({
36
- projectRoot: appRoot,
37
+ projectRoot,
37
38
  server,
38
39
  metro,
39
40
  eventTypes: [
@@ -42,6 +43,9 @@ async function setupTypedRoutes({ server , metro , typesDirectory , projectRoot
42
43
  "change"
43
44
  ],
44
45
  async callback ({ filePath , type }) {
46
+ if (!isRouteFile(filePath)) {
47
+ return;
48
+ }
45
49
  let shouldRegenerate = false;
46
50
  if (type === "delete") {
47
51
  const route = filePathToRoute(filePath);
@@ -63,9 +67,11 @@ async function setupTypedRoutes({ server , metro , typesDirectory , projectRoot
63
67
  }
64
68
  });
65
69
  }
66
- // Do we need to walk the entire tree on startup?
67
- // Idea: Store the list of files in the last write, then simply check Git for what files have changed
68
- await walk(appRoot, addFilePath);
70
+ if (await (0, _dir).directoryExistsAsync(absoluteRouterDirectory)) {
71
+ // Do we need to walk the entire tree on startup?
72
+ // Idea: Store the list of files in the last write, then simply check Git for what files have changed
73
+ await walk(absoluteRouterDirectory, addFilePath);
74
+ }
69
75
  regenerateRouterDotTS(typesDirectory, new Set([
70
76
  ...staticRoutes.values()
71
77
  ].flatMap((v)=>Array.from(v)
@@ -77,8 +83,11 @@ async function setupTypedRoutes({ server , metro , typesDirectory , projectRoot
77
83
  /**
78
84
  * Generate a router.d.ts file that contains all of the routes in the project.
79
85
  * Should be debounced as its very common for developers to make changes to multiple files at once (eg Save All)
80
- */ const regenerateRouterDotTS = (0, _lodash).debounce((typesDir, staticRoutes, dynamicRoutes, dynamicRouteTemplates)=>{
81
- _promises.default.writeFile(_path.default.resolve(typesDir, "./router.d.ts"), getTemplateString(staticRoutes, dynamicRoutes, dynamicRouteTemplates));
86
+ */ const regenerateRouterDotTS = (0, _lodash).debounce(async (typesDir, staticRoutes, dynamicRoutes, dynamicRouteTemplates)=>{
87
+ await _promises.default.mkdir(typesDir, {
88
+ recursive: true
89
+ });
90
+ await _promises.default.writeFile(_path.default.resolve(typesDir, "./router.d.ts"), getTemplateString(staticRoutes, dynamicRoutes, dynamicRouteTemplates));
82
91
  }, 100);
83
92
  function getTemplateString(staticRoutes, dynamicRoutes, dynamicRouteTemplates) {
84
93
  return routerDotTSTemplate({
@@ -87,7 +96,7 @@ function getTemplateString(staticRoutes, dynamicRoutes, dynamicRouteTemplates) {
87
96
  dynamicRouteParams: setToUnionType(dynamicRouteTemplates)
88
97
  });
89
98
  }
90
- function getTypedRoutesUtils(appRoot) {
99
+ function getTypedRoutesUtils(appRoot, filePathSeperator = _path.default.sep) {
91
100
  /*
92
101
  * staticRoutes are a map where the key if the route without groups and the value
93
102
  * is another set of all group versions of the route. e.g,
@@ -110,13 +119,23 @@ function getTypedRoutesUtils(appRoot) {
110
119
  * The keys of this map are also important, as they can be used as "static" types
111
120
  * <Link href={{ pathname: "/[...fruits]",params: { fruits: ["apple"] } }} />
112
121
  */ const dynamicRoutes = new Map();
122
+ function normalizedFilePath(filePath) {
123
+ return filePath.replaceAll(filePathSeperator, "/");
124
+ }
125
+ const normalizedAppRoot = normalizedFilePath(appRoot);
113
126
  const filePathToRoute = (filePath)=>{
114
- return filePath.replace(appRoot, "").replace(/index.[jt]sx?/, "").replace(/\.[jt]sx?$/, "");
127
+ return normalizedFilePath(filePath).replace(normalizedAppRoot, "").replace(/index\.[jt]sx?/, "").replace(/\.[jt]sx?$/, "");
115
128
  };
116
- const addFilePath = (filePath)=>{
117
- if (filePath.match(/_layout\.[tj]sx?$/)) {
129
+ const isRouteFile = (filePath)=>{
130
+ // Layout and filenames starting with `+` are not routes
131
+ if (filePath.match(/_layout\.[tj]sx?$/) || filePath.match(/\/\+/)) {
118
132
  return false;
119
133
  }
134
+ // Route files must be nested with in the appRoot
135
+ const relative = _path.default.relative(appRoot, filePath);
136
+ return relative && !relative.startsWith("..") && !_path.default.isAbsolute(relative);
137
+ };
138
+ const addFilePath = (filePath)=>{
120
139
  const route1 = filePathToRoute(filePath);
121
140
  // We have already processed this file
122
141
  if (staticRoutes.has(route1) || dynamicRoutes.has(route1)) {
@@ -163,7 +182,8 @@ function getTypedRoutesUtils(appRoot) {
163
182
  staticRoutes,
164
183
  dynamicRoutes,
165
184
  filePathToRoute,
166
- addFilePath
185
+ addFilePath,
186
+ isRouteFile
167
187
  };
168
188
  }
169
189
  const setToUnionType = (set)=>{
@@ -183,7 +203,7 @@ exports.setToUnionType = setToUnionType;
183
203
  await walk(p, callback);
184
204
  } else {
185
205
  // Normalise the paths so they are easier to convert to URLs
186
- const normalizedPath = p.replaceAll(_path.default.sep, "/").replaceAll(" ", "_");
206
+ const normalizedPath = p.replaceAll(_path.default.sep, "/");
187
207
  callback(normalizedPath);
188
208
  }
189
209
  }
@@ -198,7 +218,7 @@ function extrapolateGroupRoutes(route, routes = new Set()) {
198
218
  }
199
219
  const groupsMatch = match[0];
200
220
  for (const group of groupsMatch.matchAll(CAPTURE_GROUP_REGEX)){
201
- extrapolateGroupRoutes(route.replace(groupsMatch, `(${group[1]})`), routes);
221
+ extrapolateGroupRoutes(route.replace(groupsMatch, `(${group[1].trim()})`), routes);
202
222
  }
203
223
  return routes;
204
224
  }
@@ -211,6 +231,7 @@ function extrapolateGroupRoutes(route, routes = new Set()) {
211
231
  /* eslint-disable @typescript-eslint/ban-types */
212
232
  declare module "expo-router" {
213
233
  import type { LinkProps as OriginalLinkProps } from 'expo-router/build/link/Link';
234
+ import type { Router as OriginalRouter } from 'expo-router/src/types';
214
235
  export * from 'expo-router/build';
215
236
 
216
237
  // prettier-ignore
@@ -231,6 +252,8 @@ declare module "expo-router" {
231
252
  ****************/
232
253
 
233
254
  type SearchOrHash = \`?\${string}\` | \`#\${string}\`;
255
+ type UnknownInputParams = Record<string, string | number | (string | number)[]>;
256
+ type UnknownOutputParams = Record<string, string | string[]>;
234
257
 
235
258
  /**
236
259
  * Return only the RoutePart of a string. If the string has multiple parts return never
@@ -250,6 +273,10 @@ declare module "expo-router" {
250
273
  ? never
251
274
  : S extends ''
252
275
  ? never
276
+ : S extends \`(\${string})\`
277
+ ? never
278
+ : S extends \`[\${string}]\`
279
+ ? never
253
280
  : S;
254
281
 
255
282
  /**
@@ -259,6 +286,10 @@ declare module "expo-router" {
259
286
  ? never
260
287
  : S extends ''
261
288
  ? never
289
+ : S extends \`\${string}(\${string})\${string}\`
290
+ ? never
291
+ : S extends \`\${string}[\${string}]\${string}\`
292
+ ? never
262
293
  : S;
263
294
 
264
295
  // type OptionalCatchAllRoutePart<S extends string> = S extends \`\${string}\${SearchOrHash}\` ? never : S
@@ -295,25 +326,34 @@ declare module "expo-router" {
295
326
  : [Path];
296
327
 
297
328
  /**
298
- * Returns a Record of the routes parameters as strings and CatchAll parameters as string[]
329
+ * Returns a Record of the routes parameters as strings and CatchAll parameters
330
+ *
331
+ * There are two versions, input and output, as you can input 'string | number' but
332
+ * the output will always be 'string'
299
333
  *
300
334
  * /[id]/[...rest] -> { id: string, rest: string[] }
301
335
  * /no-params -> {}
302
336
  */
303
- type RouteParams<Path> = {
337
+ type InputRouteParams<Path> = {
338
+ [Key in ParameterNames<Path> as Key extends \`...\${infer Name}\`
339
+ ? Name
340
+ : Key]: Key extends \`...\${string}\` ? (string | number)[] : string | number;
341
+ } & UnknownInputParams;
342
+
343
+ type OutputRouteParams<Path> = {
304
344
  [Key in ParameterNames<Path> as Key extends \`...\${infer Name}\`
305
345
  ? Name
306
346
  : Key]: Key extends \`...\${string}\` ? string[] : string;
307
- };
347
+ } & UnknownOutputParams;
308
348
 
309
349
  /**
310
- * Returns the search parameters for a route
350
+ * Returns the search parameters for a route.
311
351
  */
312
352
  export type SearchParams<T extends AllRoutes> = T extends DynamicRouteTemplate
313
- ? RouteParams<T>
353
+ ? OutputRouteParams<T>
314
354
  : T extends StaticRoutes
315
355
  ? never
316
- : Record<string, string>;
356
+ : UnknownOutputParams;
317
357
 
318
358
  /**
319
359
  * Route is mostly used as part of Href to ensure that a valid route is provided
@@ -328,71 +368,98 @@ declare module "expo-router" {
328
368
  *
329
369
  * This is named Route to prevent confusion, as users they will often see it in tooltips
330
370
  */
331
- export type Route<T> = T extends DynamicRouteTemplate
332
- ? never
333
- :
334
- | StaticRoutes
335
- | RelativePathString
336
- | ExternalPathString
337
- | (T extends DynamicRoutes<infer _> ? T : never);
371
+ export type Route<T> = T extends string
372
+ ? T extends DynamicRouteTemplate
373
+ ? never
374
+ :
375
+ | StaticRoutes
376
+ | RelativePathString
377
+ | ExternalPathString
378
+ | (T extends \`\${infer P}\${SearchOrHash}\`
379
+ ? P extends DynamicRoutes<infer _>
380
+ ? T
381
+ : never
382
+ : T extends DynamicRoutes<infer _>
383
+ ? T
384
+ : never)
385
+ : never;
338
386
 
339
387
  /*********
340
388
  * Href *
341
389
  *********/
342
390
 
343
- export type Href<T extends string> = Route<T> | HrefObject<T>;
391
+ export type Href<T> = T extends Record<'pathname', string> ? HrefObject<T> : Route<T>;
344
392
 
345
- export type HrefObject<T = AllRoutes> = T extends DynamicRouteTemplate
346
- ? { pathname: T; params: RouteParams<T> }
347
- : T extends Route<T>
348
- ? { pathname: Route<T>; params?: never }
393
+ export type HrefObject<
394
+ R extends Record<'pathname', string>,
395
+ P = R['pathname']
396
+ > = P extends DynamicRouteTemplate
397
+ ? { pathname: P; params: InputRouteParams<P> }
398
+ : P extends Route<P>
399
+ ? { pathname: Route<P> | DynamicRouteTemplate; params?: never | InputRouteParams<never> }
349
400
  : never;
350
401
 
351
402
  /***********************
352
403
  * Expo Router Exports *
353
404
  ***********************/
354
405
 
355
- export type Router = {
406
+ export type Router = Omit<OriginalRouter, 'push' | 'replace' | 'setParams'> & {
356
407
  /** Navigate to the provided href. */
357
- push: <T extends string>(href: Href<T>) => void;
408
+ push: <T>(href: Href<T>) => void;
358
409
  /** Navigate to route without appending to the history. */
359
- replace: <T extends string>(href: Href<T>) => void;
360
- /** Go back in the history. */
361
- back: () => void;
410
+ replace: <T>(href: Href<T>) => void;
362
411
  /** Update the current route query params. */
363
- setParams: <T extends string = ''>(
364
- params?: T extends '' ? Record<string, string> : RouteParams<T>
365
- ) => void;
412
+ setParams: <T = ''>(params?: T extends '' ? Record<string, string> : InputRouteParams<T>) => void;
366
413
  };
367
414
 
415
+ /** The imperative router. */
416
+ export const router: Router;
417
+
368
418
  /************
369
419
  * <Link /> *
370
420
  ************/
371
- export interface LinkProps<T extends string> extends OriginalLinkProps {
372
- href: T extends DynamicRouteTemplate ? HrefObject<T> : Href<T>;
421
+ export interface LinkProps<T> extends OriginalLinkProps {
422
+ href: Href<T>;
373
423
  }
374
424
 
375
425
  export interface LinkComponent {
376
- <T extends string>(props: React.PropsWithChildren<LinkProps<T>>): JSX.Element;
426
+ <T>(props: React.PropsWithChildren<LinkProps<T>>): JSX.Element;
377
427
  /** Helper method to resolve an Href object into a string. */
378
- resolveHref: <T extends string>(href: Href<T>) => string;
428
+ resolveHref: <T>(href: Href<T>) => string;
379
429
  }
380
430
 
431
+ /**
432
+ * Component to render link to another route using a path.
433
+ * Uses an anchor tag on the web.
434
+ *
435
+ * @param props.href Absolute path to route (e.g. \`/feeds/hot\`).
436
+ * @param props.replace Should replace the current route without adding to the history.
437
+ * @param props.asChild Forward props to child component. Useful for custom buttons.
438
+ * @param props.children Child elements to render the content.
439
+ */
381
440
  export const Link: LinkComponent;
441
+
442
+ /** Redirects to the href as soon as the component is mounted. */
443
+ export const Redirect: <T>(
444
+ props: React.PropsWithChildren<{ href: Href<T> }>
445
+ ) => JSX.Element;
382
446
 
383
447
  /************
384
448
  * Hooks *
385
449
  ************/
386
450
  export function useRouter(): Router;
451
+
387
452
  export function useLocalSearchParams<
388
- T extends DynamicRouteTemplate | StaticRoutes | RelativePathString
389
- >(): SearchParams<T>;
453
+ T extends AllRoutes | UnknownOutputParams = UnknownOutputParams
454
+ >(): T extends AllRoutes ? SearchParams<T> : T;
455
+
456
+ /** @deprecated renamed to \`useGlobalSearchParams\` */
390
457
  export function useSearchParams<
391
- T extends AllRoutes | SearchParams<DynamicRouteTemplate>
458
+ T extends AllRoutes | UnknownOutputParams = UnknownOutputParams
392
459
  >(): T extends AllRoutes ? SearchParams<T> : T;
393
460
 
394
461
  export function useGlobalSearchParams<
395
- T extends AllRoutes | SearchParams<DynamicRouteTemplate>
462
+ T extends AllRoutes | UnknownOutputParams = UnknownOutputParams
396
463
  >(): T extends AllRoutes ? SearchParams<T> : T;
397
464
 
398
465
  export function useSegments<
@@ -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 { 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 = /\\(\\w+?,.*?\\)/g;\n// /(group1,group2,group3)/test - captures [\"group1\", \"group2\", \"group3\"]\nexport const CAPTURE_GROUP_REGEX = /[\\\\(,](\\w+?)(?=[,\\\\)])/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 appRoot = path.join(projectRoot, routerDirectory);\n\n const { filePathToRoute, staticRoutes, dynamicRoutes, addFilePath } =\n getTypedRoutesUtils(appRoot);\n\n if (metro) {\n // Setup out watcher first\n metroWatchTypeScriptFiles({\n projectRoot: appRoot,\n server,\n metro,\n eventTypes: ['add', 'delete', 'change'],\n async callback({ filePath, type }) {\n let shouldRegenerate = false;\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 // 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(appRoot, addFilePath);\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 (\n typesDir: string,\n staticRoutes: Set<string>,\n dynamicRoutes: Set<string>,\n dynamicRouteTemplates: Set<string>\n ) => {\n 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) {\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 const filePathToRoute = (filePath: string) => {\n return filePath\n .replace(appRoot, '')\n .replace(/index.[jt]sx?/, '')\n .replace(/\\.[jt]sx?$/, '');\n };\n\n const addFilePath = (filePath: string): boolean => {\n if (filePath.match(/_layout\\.[tj]sx?$/)) {\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 };\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, '/').replaceAll(' ', '_');\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]})`), 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 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\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;\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;\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 as string[]\n *\n * /[id]/[...rest] -> { id: string, rest: string[] }\n * /no-params -> {}\n */\n type RouteParams<Path> = {\n [Key in ParameterNames<Path> as Key extends \\`...\\${infer Name}\\`\n ? Name\n : Key]: Key extends \\`...\\${string}\\` ? string[] : string;\n };\n\n /**\n * Returns the search parameters for a route\n */\n export type SearchParams<T extends AllRoutes> = T extends DynamicRouteTemplate\n ? RouteParams<T>\n : T extends StaticRoutes\n ? never\n : Record<string, string>;\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 DynamicRouteTemplate\n ? never\n :\n | StaticRoutes\n | RelativePathString\n | ExternalPathString\n | (T extends DynamicRoutes<infer _> ? T : never);\n\n /*********\n * Href *\n *********/\n\n export type Href<T extends string> = Route<T> | HrefObject<T>;\n\n export type HrefObject<T = AllRoutes> = T extends DynamicRouteTemplate\n ? { pathname: T; params: RouteParams<T> }\n : T extends Route<T>\n ? { pathname: Route<T>; params?: never }\n : never;\n\n /***********************\n * Expo Router Exports *\n ***********************/\n\n export type Router = {\n /** Navigate to the provided href. */\n push: <T extends string>(href: Href<T>) => void;\n /** Navigate to route without appending to the history. */\n replace: <T extends string>(href: Href<T>) => void;\n /** Go back in the history. */\n back: () => void;\n /** Update the current route query params. */\n setParams: <T extends string = ''>(\n params?: T extends '' ? Record<string, string> : RouteParams<T>\n ) => void;\n };\n\n /************\n * <Link /> *\n ************/\n export interface LinkProps<T extends string> extends OriginalLinkProps {\n href: T extends DynamicRouteTemplate ? HrefObject<T> : Href<T>;\n }\n\n export interface LinkComponent {\n <T extends string>(props: React.PropsWithChildren<LinkProps<T>>): JSX.Element;\n /** Helper method to resolve an Href object into a string. */\n resolveHref: <T extends string>(href: Href<T>) => string;\n }\n\n export const Link: LinkComponent;\n\n /************\n * Hooks *\n ************/\n export function useRouter(): Router;\n export function useLocalSearchParams<\n T extends DynamicRouteTemplate | StaticRoutes | RelativePathString\n >(): SearchParams<T>;\n export function useSearchParams<\n T extends AllRoutes | SearchParams<DynamicRouteTemplate>\n >(): T extends AllRoutes ? SearchParams<T> : T;\n\n export function useGlobalSearchParams<\n T extends AllRoutes | SearchParams<DynamicRouteTemplate>\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","appRoot","path","join","filePathToRoute","staticRoutes","dynamicRoutes","addFilePath","metroWatchTypeScriptFiles","eventTypes","callback","filePath","type","shouldRegenerate","route","delete","regenerateRouterDotTS","Set","values","flatMap","v","Array","from","keys","walk","debounce","typesDir","dynamicRouteTemplates","fs","writeFile","resolve","routerDotTSTemplate","setToUnionType","dynamicRouteParams","Map","replace","match","has","dynamicParams","matchAll","map","isDynamic","size","addRoute","originalRoute","set","get","add","replaceAll","includes","routeWithoutGroups","routeWithSingleGroup","s","directory","files","readdir","file","p","stat","isDirectory","normalizedPath","sep","routes","groupsMatch","group","unsafeTemplate"],"mappings":"AAAA;;;;QA4BsBA,gBAAgB,GAAhBA,gBAAgB;QA4EtBC,iBAAiB,GAAjBA,iBAAiB;QAiBjBC,mBAAmB,GAAnBA,mBAAmB;QA0HnBC,sBAAsB,GAAtBA,sBAAsB;;AAnPvB,IAAA,SAAa,kCAAb,aAAa,EAAA;AACH,IAAA,OAAQ,WAAR,QAAQ,CAAA;AAEhB,IAAA,KAAM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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqLrD,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 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) {\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 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;QAwInBC,sBAAsB,GAAtBA,sBAAsB;;AA1QvB,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,gBAAgB,CAAC,EACrCS,MAAM,CAAA,EACNC,KAAK,CAAA,EACLC,cAAc,CAAA,EACdC,WAAW,CAAA,EACXC,eAAe,CAAA,EACS,EAAE;IAC1B,MAAMC,uBAAuB,GAAGC,KAAI,QAAA,CAACC,IAAI,CAACJ,WAAW,EAAEC,eAAe,CAAC,AAAC;IAExE,MAAM,EAAEI,eAAe,CAAA,EAAEC,YAAY,CAAA,EAAEC,aAAa,CAAA,EAAEC,WAAW,CAAA,EAAEC,WAAW,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G,CACH,MAAMtC,mBAAmB,GAAG0C,SAAc,eAAA,CAAC;;;;;;;;;sBASrB,EAAE,cAAc,CAAC;;yCAEE,EAAE,eAAe,CAAC;;8BAE7B,EAAE,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmOrD,CAAC,AAAC"}
@@ -11,12 +11,15 @@ function createDebuggerTelemetryMiddleware(projectRoot, exp) {
11
11
  let hasReported = false;
12
12
  // This only works for Hermes apps, disable when telemetry is turned off
13
13
  if (_env.env.EXPO_NO_TELEMETRY || exp.jsEngine !== "hermes") {
14
- return (req, res, next)=>next(undefined)
15
- ;
14
+ return (req, res, next)=>{
15
+ if (typeof next === "function") {
16
+ next(undefined);
17
+ }
18
+ };
16
19
  }
17
20
  return (req, res, next)=>{
18
21
  // Only report once
19
- if (hasReported) {
22
+ if (hasReported && typeof next === "function") {
20
23
  return next(undefined);
21
24
  }
22
25
  const debugTool = findDebugTool(req);
@@ -24,7 +27,9 @@ function createDebuggerTelemetryMiddleware(projectRoot, exp) {
24
27
  hasReported = true;
25
28
  (0, _rudderstackClient).logEventAsync("metro debug", (0, _getMetroDebugProperties).getMetroDebugProperties(projectRoot, exp, debugTool));
26
29
  }
27
- return next(undefined);
30
+ if (typeof next === "function") {
31
+ return next(undefined);
32
+ }
28
33
  };
29
34
  }
30
35
  function findDebugTool(req) {