Skip to content

Commit

Permalink
format imports, package.json fields with prettier (shuding#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed May 24, 2023
1 parent 0ad0ff9 commit a099b14
Show file tree
Hide file tree
Showing 41 changed files with 292 additions and 249 deletions.
160 changes: 106 additions & 54 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions __test__/collect-catch-all.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { collectCatchAllRoutes } from '../src/setup-page'
import { describe, it, expect } from 'vitest'
import { describe, expect, it } from 'vitest'
import { createCatchAllMeta } from '../src/catch-all'
import { collectCatchAllRoutes } from '../src/setup-page'

describe('collectCatchAllRoutes', () => {
it('should collect', () => {
Expand Down
2 changes: 1 addition & 1 deletion __test__/compile.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import { describe, expect, it } from 'vitest'
import { compileMdx } from '../src/compile'
import { it, describe, expect } from 'vitest'
import { CWD } from '../src/constants'

type Name =
Expand Down
6 changes: 3 additions & 3 deletions __test__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { describe, it, expect, beforeAll } from 'vitest'
import path from 'node:path'
import { beforeAll, describe, expect, it } from 'vitest'
import { CWD, NEXTRA_INTERNAL } from '../src/constants'
import {
getAllPages,
getCurrentLevelPages,
getPagesUnderRoute
} from '../src/context'
import { collectFiles } from '../src/plugin'
import { CWD, NEXTRA_INTERNAL } from '../src/constants'
import path from 'node:path'
import type { NextraInternalGlobal } from '../src/types'

describe('context', () => {
Expand Down
2 changes: 1 addition & 1 deletion __test__/loader.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest'
import fs from 'node:fs/promises'
import path from 'node:path'
import { describe, expect, it } from 'vitest'
import { CWD } from '../src/constants'

describe('tree shaking', async () => {
Expand Down
5 changes: 3 additions & 2 deletions __test__/locale-with-base-path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// on `__NEXT_ROUTER_BASEPATH` environment variable that must be set before
// importing middleware
process.env.__NEXT_ROUTER_BASEPATH = '/testBasePath'
import { locales as originalLocales } from '../src/locales'
import { describe, expect, it, vi } from 'vitest'

import { NextRequest } from 'next/server'
import type NextServer from 'next/server'
import { describe, expect, it, vi } from 'vitest'
import { locales as originalLocales } from '../src/locales'

vi.mock('next/server', async () => {
const mod = await vi.importActual<typeof NextServer>('next/server')
Expand Down
4 changes: 2 additions & 2 deletions __test__/locale.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi } from 'vitest'
import { NextRequest } from 'next/server'
import { locales as originalLocales } from '../src/locales'
import type NextServer from 'next/server'
import { describe, expect, it, vi } from 'vitest'
import { locales as originalLocales } from '../src/locales'

vi.mock('next/server', async () => {
const mod = await vi.importActual<typeof NextServer>('next/server')
Expand Down
4 changes: 2 additions & 2 deletions __test__/normalize-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest'
import { cnPageMap, usPageMap } from './fixture/page-maps/pageMap'
import { describe, expect, it } from 'vitest'
import { normalizePages } from '../src/normalize-pages'
import { cnPageMap, usPageMap } from './fixture/page-maps/pageMap'

const defaultLocale = 'en-US'

Expand Down
4 changes: 2 additions & 2 deletions __test__/page-map.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, it, expect, beforeAll } from 'vitest'
import path from 'node:path'
import { beforeAll, describe, expect, it } from 'vitest'
import { CWD } from '../src/constants'
import { getDynamicMeta, resolvePageMap } from '../src/page-map'
import { collectFiles } from '../src/plugin'
import type { FileMap, PageMapItem } from '../src/types'
import { CWD } from '../src/constants'

const PAGES_DIR = path.join(CWD, '..', '..', 'examples', 'swr-site', 'pages')
const filePath = (name: string) => path.join(PAGES_DIR, name)
Expand Down
2 changes: 1 addition & 1 deletion __test__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest'
import { describe, expect, it } from 'vitest'
import { parseFileName } from '../src/utils'

describe('Utils', () => {
Expand Down
126 changes: 63 additions & 63 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,55 @@
"name": "nextra",
"version": "2.6.0",
"description": "Next.js and MDX based site generator.",
"files": [
"dist/*",
"icons/*",
"loader.js",
"styles/*"
],
"types": "./dist/types.d.ts",
"repository": "https://github.com/shuding/nextra",
"license": "MIT",
"engines": {
"node": ">=16"
},
"main": "./dist/index.js",
"exports": {
"./package.json": "./package.json",
".": "./dist/index.js",
"./catch-all": "./dist/catch-all.js",
"./data": {
"import": "./dist/ssg.js",
"types": "./dist/ssg.d.ts"
},
"./ssg": {
"import": "./dist/ssg.js",
"types": "./dist/ssg.d.ts"
},
"./loader": "./loader.js",
"./setup-page": {
"import": "./dist/setup-page.js",
"types": "./dist/setup-page.d.ts"
},
"./mdx": {
"import": "./dist/mdx.js",
"types": "./dist/mdx.d.ts"
},
"./normalize-pages": {
"import": "./dist/normalize-pages.js",
"types": "./dist/normalize-pages.d.ts"
},
"./components": {
"import": "./dist/components/index.js",
"types": "./dist/components/index.d.ts"
},
"./hooks": {
"import": "./dist/hooks/index.js",
"types": "./dist/hooks/index.d.ts"
},
"./icons": {
"import": "./dist/icons/index.js",
"types": "./dist/icons/index.d.ts"
},
"./*": {
"import": "./dist/*.mjs",
"types": "./dist/*.d.ts"
}
},
"types": "./dist/types.d.ts",
"typesVersions": {
"*": {
"compile": [
Expand Down Expand Up @@ -53,58 +94,25 @@
]
}
},
"exports": {
"./package.json": "./package.json",
".": "./dist/index.js",
"./catch-all": "./dist/catch-all.js",
"./data": {
"import": "./dist/ssg.js",
"types": "./dist/ssg.d.ts"
},
"./ssg": {
"import": "./dist/ssg.js",
"types": "./dist/ssg.d.ts"
},
"./loader": "./loader.js",
"./setup-page": {
"import": "./dist/setup-page.js",
"types": "./dist/setup-page.d.ts"
},
"./mdx": {
"import": "./dist/mdx.js",
"types": "./dist/mdx.d.ts"
},
"./normalize-pages": {
"import": "./dist/normalize-pages.js",
"types": "./dist/normalize-pages.d.ts"
},
"./components": {
"import": "./dist/components/index.js",
"types": "./dist/components/index.d.ts"
},
"./hooks": {
"import": "./dist/hooks/index.js",
"types": "./dist/hooks/index.d.ts"
},
"./icons": {
"import": "./dist/icons/index.js",
"types": "./dist/icons/index.d.ts"
},
"./*": {
"import": "./dist/*.mjs",
"types": "./dist/*.d.ts"
}
},
"repository": "https://github.com/shuding/nextra",
"license": "MIT",
"files": [
"dist/*",
"icons/*",
"loader.js",
"styles/*"
],
"scripts": {
"build": "tsup",
"clean": "rimraf ./dist ./style.css",
"dev": "tsup --watch",
"types": "tsup --dts-only",
"types:check": "tsc --noEmit",
"test": "vitest run",
"prepublishOnly": "pnpm build",
"clean": "rimraf ./dist ./style.css"
"test": "vitest run",
"types": "tsup --dts-only",
"types:check": "tsc --noEmit"
},
"peerDependencies": {
"next": ">=9.5.3",
"react": ">=16.13.1",
"react-dom": ">=16.13.1"
},
"dependencies": {
"@mdx-js/mdx": "^2.3.0",
Expand All @@ -130,11 +138,6 @@
"unist-util-visit": "^4.1.1",
"zod": "^3.20.2"
},
"peerDependencies": {
"next": ">=9.5.3",
"react": ">=16.13.1",
"react-dom": ">=16.13.1"
},
"devDependencies": {
"@types/github-slugger": "^2.0.0",
"@types/graceful-fs": "^4.1.6",
Expand All @@ -150,8 +153,5 @@
"react-dom": "^18.2.0",
"unified": "^10.1.2",
"vitest": "^0.31.0"
},
"engines": {
"node": ">=16"
}
}
2 changes: 1 addition & 1 deletion src/catch-all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MARKDOWN_EXTENSION_REGEX } from './constants'
import type { DynamicMeta, DynamicFolder } from './types'
import type { DynamicFolder, DynamicMeta } from './types'

function appendSlashForFolders(obj: DynamicMeta): DynamicMeta {
return Object.fromEntries(
Expand Down
37 changes: 18 additions & 19 deletions src/compile.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import path from 'node:path'
import { createRequire } from 'node:module'
import path from 'node:path'
import type { ProcessorOptions } from '@mdx-js/mdx'
import { createProcessor } from '@mdx-js/mdx'
import type { Processor } from '@mdx-js/mdx/lib/core'
import remarkGfm from 'remark-gfm'
import grayMatter from 'gray-matter'
import rehypeKatex from 'rehype-katex'
import type { Options as RehypePrettyCodeOptions } from 'rehype-pretty-code'
import rehypePrettyCode from 'rehype-pretty-code'
import remarkReadingTime from 'remark-reading-time'
import grayMatter from 'gray-matter'
import remarkGfm from 'remark-gfm'
import remarkMath from 'remark-math'
import rehypeKatex from 'rehype-katex'
import remarkReadingTime from 'remark-reading-time'
import type { Pluggable } from 'unified'

import {
remarkStaticImage,
remarkCustomHeadingId,
remarkHeadings,
remarkReplaceImports,
structurize,
parseMeta,
attachMeta,
remarkRemoveImports,
remarkLinkRewrite
} from './mdx-plugins'
import type { LoaderOptions, PageOpts, ReadingTime } from './types'
import { truthy } from './utils'
import {
CODE_BLOCK_FILENAME_REGEX,
CWD,
DEFAULT_LOCALE,
MARKDOWN_URL_EXTENSION_REGEX
} from './constants'
import {
attachMeta,
parseMeta,
remarkCustomHeadingId,
remarkHeadings,
remarkLinkRewrite,
remarkRemoveImports,
remarkReplaceImports,
remarkStaticImage,
structurize
} from './mdx-plugins'
import theme from './theme.json'
import type { LoaderOptions, PageOpts, ReadingTime } from './types'
import { truthy } from './utils'

globalThis.__nextra_temp_do_not_use = () => {
import('./__temp__')
Expand Down
2 changes: 1 addition & 1 deletion src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ComponentProps, ReactElement } from 'react'
import cn from 'clsx'
import type { ComponentProps, ReactElement } from 'react'

export const Button = ({
children,
Expand Down
3 changes: 1 addition & 2 deletions src/components/callout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ReactElement, ReactNode } from 'react'
import cn from 'clsx'

import type { ReactElement, ReactNode } from 'react'
import { InformationCircleIcon } from '../icons'

const TypeToEmoji = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/code.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ComponentProps, ReactElement } from 'react'
import cn from 'clsx'
import type { ComponentProps, ReactElement } from 'react'

export const Code = ({
children,
Expand Down
6 changes: 3 additions & 3 deletions src/components/pre.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import cn from 'clsx'
import type { ComponentProps, ReactElement } from 'react'
import { useCallback, useRef } from 'react'
import { CopyToClipboard } from './copy-to-clipboard'
import { Button } from './button'
import { WordWrapIcon } from '../icons'
import cn from 'clsx'
import { Button } from './button'
import { CopyToClipboard } from './copy-to-clipboard'

export const Pre = ({
children,
Expand Down
8 changes: 4 additions & 4 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { normalizeMeta } from './utils'
import { NEXTRA_INTERNAL } from './constants'
import type {
MetaJsonFile,
PageMapItem,
NextraInternalGlobal,
Page,
NextraInternalGlobal
PageMapItem
} from './types'
import { NEXTRA_INTERNAL } from './constants'
import { normalizeMeta } from './utils'

function getContext(name: string): {
pageMap: PageMapItem[]
Expand Down
2 changes: 1 addition & 1 deletion src/filter-route-locale.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { META_FILENAME } from './constants'
import type { PageMapItem } from './types'
import { truthy } from './utils'
import { META_FILENAME } from './constants'

export default function filterRouteLocale(
pageMap: PageMapItem[],
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-fs-route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react'
import { useRouter } from 'next/router'
import { useMemo } from 'react'
import { DEFAULT_LOCALE, ERROR_ROUTES } from '../constants'

const template = 'https://nextra.vercel.app'
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-env node */
import { NextraPlugin, pageMapCache } from './plugin'
import { NextraSearchPlugin } from './search/plugin'
import {
DEFAULT_LOCALE,
DEFAULT_CONFIG,
DEFAULT_LOCALE,
DEFAULT_LOCALES,
MARKDOWN_EXTENSION_REGEX,
MARKDOWN_EXTENSIONS,
DEFAULT_LOCALES
MARKDOWN_EXTENSIONS
} from './constants'
import { NextraPlugin, pageMapCache } from './plugin'
import { NextraSearchPlugin } from './search/plugin'

const DEFAULT_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx']

Expand Down

0 comments on commit a099b14

Please sign in to comment.