xref: /expo/packages/expo-router/plugin/src/index.ts (revision 26ad19fc)
1import { ConfigPlugin, withInfoPlist } from 'expo/config-plugins';
2import { validate } from 'schema-utils';
3
4const schema = require('../options.json');
5
6const withExpoHeadIos: ConfigPlugin = (config) => {
7  return withInfoPlist(config, (config) => {
8    // TODO: Add a way to enable this...
9    // config.modResults.CoreSpotlightContinuation = true;
10
11    // $(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route
12    if (!Array.isArray(config.modResults.NSUserActivityTypes)) {
13      config.modResults.NSUserActivityTypes = [];
14    }
15    // This ensures that stored `NSUserActivityType`s can be opened in-app.
16    // This is important for moving between native devices or from opening a link that was saved
17    // in a Quick Note or Siri Reminder.
18    config.modResults.NSUserActivityTypes.push('$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route');
19    return config;
20  });
21};
22
23const withRouter: ConfigPlugin<
24  {
25    /** Production origin URL where assets in the public folder are hosted. The fetch function is polyfilled to support relative requests from this origin in production, development origin is inferred using the Expo CLI development server. */
26    origin?: string;
27    /** A more specific origin URL used in the `expo-router/head` module for iOS handoff. Defaults to `origin`. */
28    headOrigin?: string;
29    /** Changes the routes directory from `app` to another value. Defaults to `app`. Avoid using this property. */
30    unstable_src?: string;
31    /** Should Async Routes be enabled, currently only `development` is supported. */
32    asyncRoutes?: string | { android?: string; ios?: string; web?: string; default?: string };
33  } | void
34> = (config, _props) => {
35  const props = _props || {};
36  validate(schema, props);
37
38  withExpoHeadIos(config);
39
40  return {
41    ...config,
42    extra: {
43      ...config.extra,
44      router: {
45        origin: false,
46        ...config.extra?.router,
47        ...props,
48      },
49    },
50  };
51};
52
53export default withRouter;
54