Skip to content

Commit 3f60956

Browse files
Simekjonsamp
andauthored
[docs] convert app to ESM, update MDX to v2 (expo#18947)
Co-authored-by: Jon Samp <[email protected]>
1 parent efdfa17 commit 3f60956

File tree

227 files changed

+4487
-5344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+4487
-5344
lines changed

docs/.eslintrc.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ module.exports = {
1111
'lodash/import-scope': [2, 'method'],
1212
'@next/next/no-img-element': 0,
1313
'react/jsx-curly-brace-presence': [1, { propElementValues: 'ignore' }],
14+
// https://github.com/emotion-js/emotion/issues/2878
15+
'react/no-unknown-property': ['error', { 'ignore': ['css'] }]
1416
},
1517
};

docs/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ out/
55

66
# copied in next.config.js
77
pages/versions/latest/
8+
9+
# staticly generated constants
10+
public/static/constants

docs/README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Expo Documentation
22

3-
This is the public documentation for **Expo**, its SDK, client, and services.
3+
This is the public documentation for **Expo**, its SDK, client, and services, like **EAS**.
44

5-
You can access this documentation online at https://docs.expo.dev/. It's built using Next.js on top of the https://github.com/vercel/docs codebase.
5+
This documentation is built using Next.js and you can access it online at https://docs.expo.dev/.
66

7+
> **Note**
78
> **Contributors:** Please make sure that you edit the docs in the `pages/versions/unversioned` directory if you want your changes to apply to the next SDK version too!
89
10+
> **Note**
911
> If you are looking for Expo Documentation Writing Style guidelines, please refer [Expo Documentation Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md).
1012
1113
## Running Locally
@@ -41,7 +43,8 @@ yarn run export-server
4143

4244
You can find the content source of the documentation inside the `pages/` directory. Documentation is mostly written in markdown with the help of some React components (for Snack embeds, etc). Our API documentation can all be found under `pages/versions/`; we keep separate versions of the documentation for each SDK version currently supported in Expo Go, see ["A note about versioning"](#a-note-about-versioning) for more info. The routes and navbar are automatically inferred from the directory structure within `versions`.
4345

44-
> Note: We are currently in the process of moving our API documentation to being auto-generated using `expotools`'s `GenerateDocsAPIData` command.
46+
> **Note**
47+
> We are currently in the process of moving our API documentation to being auto-generated using `expotools`'s `GenerateDocsAPIData` command.
4548
4649
Each markdown page can be provided metadata in the heading, distinguished by:
4750

@@ -151,13 +154,14 @@ You can validate all current links by running `yarn lint-links`.
151154

152155
### Updating latest version of docs
153156

154-
When we release a new SDK, we copy the `unversioned` directory, and rename it to the new version. Latest version of docs is read from **package.json** so make sure to update the `version` key there as well. However, if you update the `version` key there, you need to `rm -rf node_modules/.cache/` before the change is picked up (why? [read this](https://github.com/vercel/next.js/blob/4.0.0/examples/with-universal-configuration/README.md#caveats)).
157+
When we release a new SDK, we copy the `unversioned` directory, and rename it to the new version. Latest version of docs is read from **package.json** so make sure to update the `version` key there as well.
155158

156159
Make sure to also grab the upgrade instructions from the release notes blog post and put them in `upgrading-expo-sdk-walkthrough.md`.
157160

158161
That's all you need to do. The `versions` directory is listed on server start to find all available versions. The routes and navbar contents are automatically inferred from the directory structure within `versions`.
159162

160-
Because the navbar is automatically generated from the directory structure, the default ordering of the links under each section is alphabetical. However, for many sections, this is not ideal UX. So, if you wish to override the alphabetical ordering, manipulate page titles in **navigation.js**.
163+
Because the navbar is automatically generated from the directory structure, the default ordering of the links under each section is alphabetical. However, for many sections, this is not ideal UX.
164+
So, if you wish to override the alphabetical ordering, manipulate page titles in **constants/navigation.js**.
161165

162166
### Syncing app.json / app.config.js with the schema
163167

@@ -226,7 +230,8 @@ import SnackInline from '~/components/plugins/SnackInline';
226230

227231
### Embedding multiple options of code
228232

229-
Sometimes it's useful to show multiple ways of doing something, for instance maybe you'd like to have an example using a React class component, and also an example of a functional component. The `Tabs` plugin is really useful for this, and this is how you'd use it an a markdown file:
233+
Sometimes it's useful to show multiple ways of doing something, for instance maybe you'd like to have an example using a React class component, and also an example of a functional component.
234+
The `Tabs` plugin is really useful for this, and this is how you'd use it in a markdown file:
230235

231236
<!-- prettier-ignore -->
232237
```jsx
@@ -241,11 +246,9 @@ import { Tab, Tabs } from '~/components/plugins/Tabs';
241246
/* @end */
242247
};
243248

244-
245249
</Tab>
246250
<Tab label="Add 1 Another Way">
247251

248-
249252
addOne = async x => {
250253
/* @info This text will be shown onHover */
251254
return x++;
@@ -258,15 +261,16 @@ import { Tab, Tabs } from '~/components/plugins/Tabs';
258261

259262
n.b. The components should not be indented or they will not be parsed correctly.
260263

261-
### Excluding pages from Docsearch
264+
### Excluding pages from DocSearch
262265

263266
To ignore a page from the search result, use `hideFromSearch: true` on that page. This removes the `<meta name="docsearch:version">` tag from that page and filters it from our facet-based search.
264267

265-
Please note that `hideFromSearch` only prevents the page from showing up in the internal docs search (Algolia). The page will still show up in search engine results like Google. For a page to be hidden even from search engine results, you need to edit the sitemap that is generated via our Next.js config (**config.js**).
268+
Please note that `hideFromSearch` only prevents the page from showing up in the internal docs search (Algolia). The page will still show up in search engine results like Google.
269+
For a page to be hidden even from search engine results, you need to edit the sitemap that is generated via our Next.js config (**next.config.js**).
266270

267271
### Excluding directories from the sidebar
268272

269-
Certain directories are excluded from the sidebar in order to prevent it from getting too long and unnavigable. You can find a list of these directories, and add new ones, in **navigation.js** under `hiddenSections`.
273+
Certain directories are excluded from the sidebar in order to prevent it from getting too long and unnavigable. You can find a list of these directories, and add new ones, in **constants/navigation.js** under `hiddenSections`.
270274

271275
If you just want to hide a single page from the sidebar, set `hideInSidebar: true` in the page metadata.
272276

@@ -296,10 +300,9 @@ import { Terminal } from '~/ui/components/Snippet';
296300

297301
Please commit any sizeable diffs that are the result of `prettier` separately to make reviews as easy as possible.
298302

299-
If you have a codeblock using `/* @info */` highlighting, use `<!-- prettier-ignore -->` on the block and take care to preview the block in the browser to ensure that the indentation is correct - the highlighting annotation will sometimes swallow newlines.
303+
If you have a code block using `/* @info */` highlighting, use `{/* prettier-ignore */}` on the block and take care to preview the block in the browser to ensure that the indentation is correct - the highlighting annotation will sometimes swallow newlines.
300304

301305
## TODOs:
302306

303307
- Handle image sizing in imports better
304-
- Read from the appropriate version (configurable) of the React Native docs, not just main
305308
- Make Snack embeds work; these are marked in some of the React Native docs but they are just imported as plain JS code blocks
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as React from 'react';
2+
3+
import { AdditionalProps, HeadingType } from '~/common/headingManager';
4+
import Permalink from '~/components/Permalink';
5+
6+
type Options = {
7+
customIconStyle?: React.CSSProperties;
8+
baseNestingLevel?: number;
9+
sidebarType?: HeadingType;
10+
};
11+
12+
type PermalinkedComponentProps = React.PropsWithChildren<{ level?: number } & AdditionalProps>;
13+
14+
const isDev = process.env.NODE_ENV === 'development';
15+
16+
export const createPermalinkedComponent = (
17+
BaseComponent: React.ComponentType<React.PropsWithChildren<object>>,
18+
options?: Options
19+
) => {
20+
const { customIconStyle, baseNestingLevel, sidebarType = HeadingType.Text } = options || {};
21+
return ({ children, level, ...props }: PermalinkedComponentProps) => {
22+
const cleanChildren = React.Children.map(children, child => {
23+
if (React.isValidElement(child) && child?.props?.href) {
24+
isDev &&
25+
console.warn(
26+
`It looks like the header on this page includes a link, this is an invalid pattern, nested link will be removed!`,
27+
child?.props?.href
28+
);
29+
return child?.props?.children;
30+
}
31+
return child;
32+
});
33+
const nestingLevel = baseNestingLevel != null ? (level ?? 0) + baseNestingLevel : undefined;
34+
return (
35+
<Permalink
36+
nestingLevel={nestingLevel}
37+
customIconStyle={customIconStyle}
38+
additionalProps={{ ...props, sidebarType }}>
39+
<BaseComponent>{cleanChildren}</BaseComponent>
40+
</Permalink>
41+
);
42+
};
43+
};

docs/common/error-utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { VERSIONS } from '~/constants/versions.cjs';
1+
import versions from '~/public/static/constants/versions.json';
22

33
export function getRedirectPath(redirectPath: string): string {
44
// index.html is no longer a thing in our docs
@@ -73,7 +73,7 @@ function getVersionFromPath(path: string) {
7373
}
7474

7575
// Filter unversioned and latest out, so we end up with v34, etc.
76-
const supportedVersions = VERSIONS.filter(v => v.match(/^v/));
76+
const supportedVersions = versions.VERSIONS.filter(v => v.match(/^v/));
7777

7878
// Return true if the version is still included in documentation
7979
function isVersionDocumented(path: string) {

docs/common/test-utilities.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { render, RenderOptions } from '@testing-library/react';
2+
import GithubSlugger from 'github-slugger';
3+
import { PropsWithChildren, ReactElement } from 'react';
4+
5+
import { HeadingManager } from '~/common/headingManager';
6+
import { HeadingsContext } from '~/components/page-higher-order/withHeadingManager';
7+
8+
const Wrapper = ({ children }: PropsWithChildren<object>) => (
9+
<HeadingsContext.Provider value={new HeadingManager(new GithubSlugger(), { headings: [] })}>
10+
{children}
11+
</HeadingsContext.Provider>
12+
);
13+
14+
export const renderWithHeadings = (
15+
element: ReactElement,
16+
options?: Omit<RenderOptions, 'wrapper'>
17+
) => render(element, { wrapper: Wrapper, ...options });

docs/common/translate-markdown.tsx

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
1-
import * as React from 'react';
1+
import { createPermalinkedComponent } from './create-permalinked-component';
22

3-
import { AdditionalProps } from './headingManager';
4-
5-
import Permalink from '~/components/Permalink';
63
import { Code, InlineCode } from '~/components/base/code';
74
import { H1, H2, H3, H4 } from '~/components/base/headings';
85
import Link from '~/components/base/link';
96
import { UL, OL, LI } from '~/components/base/list';
107
import { PDIV, B, Quote } from '~/components/base/paragraph';
11-
import { BareWorkflowCollapsible, ExpoKitCollapsible } from '~/ui/components/Collapsible';
128
import { Cell, HeaderCell, Row, Table, TableHead } from '~/ui/components/Table';
139
import { KBD } from '~/ui/components/Text';
1410

15-
type Options = {
16-
customIconStyle?: React.CSSProperties;
17-
baseNestingLevel?: number;
18-
};
19-
20-
type PermalinkedComponentProps = React.PropsWithChildren<{ level?: number } & AdditionalProps>;
21-
22-
const createPermalinkedComponent = (
23-
BaseComponent: React.ComponentType<React.PropsWithChildren<object>>,
24-
options?: Options
25-
) => {
26-
const { customIconStyle, baseNestingLevel } = options || {};
27-
return ({ children, level, ...props }: PermalinkedComponentProps) => {
28-
const nestingLevel = baseNestingLevel != null ? (level ?? 0) + baseNestingLevel : undefined;
29-
return (
30-
<Permalink
31-
nestingLevel={nestingLevel}
32-
customIconStyle={customIconStyle}
33-
additionalProps={props}>
34-
<BaseComponent>{children}</BaseComponent>
35-
</Permalink>
36-
);
37-
};
38-
};
39-
4011
// When using inline markdown, we need to remove the document layout wrapper.
4112
// Always set this to `null` to overwrite the global MDX provider.
4213
export const wrapper = null;
@@ -50,8 +21,8 @@ export const h1 = createPermalinkedComponent(H1, { baseNestingLevel: 1 });
5021
export const h2 = createPermalinkedComponent(H2, { baseNestingLevel: 2 });
5122
export const h3 = createPermalinkedComponent(H3, { baseNestingLevel: 3 });
5223
export const h4 = createPermalinkedComponent(H4, { baseNestingLevel: 4 });
53-
export const code = Code;
54-
export const inlineCode = InlineCode;
24+
export const code = InlineCode;
25+
export const pre = Code;
5526
export const a = Link;
5627
export const blockquote = Quote;
5728
export const table = Table;
@@ -60,11 +31,3 @@ export const tr = Row;
6031
export const th = HeaderCell;
6132
export const td = Cell;
6233
export const kbd = KBD;
63-
export const expokitDetails = ExpoKitCollapsible;
64-
export const bareworkflowDetails = BareWorkflowCollapsible;
65-
export const propertyAnchor = createPermalinkedComponent(PDIV, {
66-
baseNestingLevel: 3,
67-
});
68-
export const subpropertyAnchor = createPermalinkedComponent(PDIV, {
69-
baseNestingLevel: 3,
70-
});

docs/components/DocumentationPage.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from '@emotion/react';
2-
import { theme } from '@expo/styleguide';
2+
import { breakpoints, theme } from '@expo/styleguide';
33
import some from 'lodash/some';
44
import Router, { NextRouter } from 'next/router';
55
import * as React from 'react';
@@ -13,9 +13,8 @@ import DocumentationSidebarRight, {
1313
} from '~/components/DocumentationSidebarRight';
1414
import Head from '~/components/Head';
1515
import { H1 } from '~/components/base/headings';
16-
import navigation from '~/constants/navigation.cjs';
17-
import * as Constants from '~/constants/theme';
18-
import { usePageApiVersion } from '~/providers/page-api-version';
16+
import { PageApiVersionContextType, usePageApiVersion } from '~/providers/page-api-version';
17+
import navigation from '~/public/static/constants/navigation.json';
1918
import { NavigationRoute } from '~/types/common';
2019
import { Header } from '~/ui/components/Header';
2120
import { Sidebar } from '~/ui/components/Sidebar';
@@ -31,7 +30,7 @@ const STYLES_DOCUMENT = css`
3130
background-color: ${theme.border.default};
3231
}
3332
34-
@media screen and (max-width: ${Constants.breakpoints.mobile}) {
33+
@media screen and (max-width: ${breakpoints.medium + 124}px) {
3534
padding: 20px 16px 48px 16px;
3635
}
3736
`;
@@ -43,7 +42,7 @@ type Props = React.PropsWithChildren<{
4342
tocVisible: boolean;
4443
/** If the page should not show up in the Algolia Docsearch results */
4544
hideFromSearch?: boolean;
46-
version: string;
45+
version: PageApiVersionContextType['version'];
4746
}>;
4847

4948
type State = {
@@ -76,7 +75,7 @@ class DocumentationPageWithApiVersion extends React.Component<Props, State> {
7675
}
7776

7877
private handleResize = () => {
79-
if (WindowUtils.getViewportSize().width >= Constants.breakpoints.mobileValue) {
78+
if (WindowUtils.getViewportSize().width >= breakpoints.medium + 124) {
8079
this.setState({ isMobileMenuVisible: false });
8180
window.scrollTo(0, 0);
8281
}
@@ -135,9 +134,9 @@ class DocumentationPageWithApiVersion extends React.Component<Props, State> {
135134

136135
private getRoutes = (): NavigationRoute[] => {
137136
if (this.isReferencePath()) {
138-
return (navigation as any).reference[this.props.version];
137+
return navigation.reference[this.props.version] as NavigationRoute[];
139138
} else {
140-
return (navigation as any)[this.getActiveTopLevelSection()];
139+
return navigation[this.getActiveTopLevelSection()] as NavigationRoute[];
141140
}
142141
};
143142

docs/components/DocumentationSidebarRight.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { css } from '@emotion/react';
2+
import { breakpoints } from '@expo/styleguide';
23
import * as React from 'react';
34

4-
import { BASE_HEADING_LEVEL, Heading, HeadingManager } from '../common/headingManager';
55
import DocumentationSidebarRightLink from './DocumentationSidebarRightLink';
66

7+
import { BASE_HEADING_LEVEL, Heading, HeadingManager } from '~/common/headingManager';
78
import withHeadingManager, {
89
HeadingManagerProps,
910
} from '~/components/page-higher-order/withHeadingManager';
10-
import * as Constants from '~/constants/theme';
1111

1212
const STYLES_SIDEBAR = css`
1313
padding: 20px 24px 24px 24px;
1414
width: 280px;
1515
16-
@media screen and (max-width: ${Constants.breakpoints.mobile}) {
16+
@media screen and (max-width: ${breakpoints.medium + 124}px) {
1717
width: 100%;
1818
}
1919
`;

0 commit comments

Comments
 (0)