Skip to content

Commit

Permalink
remove truthy() helper function (#3341)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina authored Oct 2, 2024
1 parent 5fbce2f commit edc6c29
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-coins-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextra': patch
---

remove `truthy()` helper function
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.next/
.tsup/
node_modules/
*.log
dist/
Expand Down
8 changes: 4 additions & 4 deletions packages/nextra/src/server/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
remarkStaticImage,
remarkStructurize
} from './remark-plugins/index.js'
import { logger, truthy } from './utils.js'
import { logger } from './utils.js'

const cachedCompilerForFormat: Record<
Exclude<ProcessorOptions['format'], undefined | null>,
Expand Down Expand Up @@ -252,7 +252,7 @@ export async function compileMdx(
}
] satisfies Pluggable,
remarkSmartypants
].filter(truthy),
].filter(v => !!v),
rehypePlugins: [
...(rehypePlugins || []),
format === 'md' && [
Expand Down Expand Up @@ -295,7 +295,7 @@ export async function compileMdx(
rehypeAttachCodeMeta
]),
[rehypeExtractTocContent, { isRemoteContent }]
].filter(truthy),
].filter(v => !!v),
recmaPlugins: [
(() => (ast: Program, file) => {
const mdxContentIndex = ast.body.findIndex(node => {
Expand Down Expand Up @@ -347,7 +347,7 @@ export async function compileMdx(
}) satisfies Plugin<[], Program>,
isRemoteContent ? recmaRewriteFunctionBody : recmaRewriteJsx,
...(recmaPlugins || [])
].filter(truthy)
].filter(v => !!v)
})
}
}
5 changes: 2 additions & 3 deletions packages/nextra/src/server/page-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
createAstExportConst,
createAstObject,
normalizePageRoute,
pageTitleFromFilename,
truthy
pageTitleFromFilename
} from './utils.js'

const fs = gracefulFs.promises
Expand Down Expand Up @@ -164,7 +163,7 @@ async function collectFiles({
})
})

const pageMap = (await Promise.all(promises)).filter(truthy)
const pageMap = (await Promise.all(promises)).filter(v => !!v)

return {
// @ts-expect-error -- fixme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import slash from 'slash'
import type { Plugin } from 'unified'
import { visit } from 'unist-util-visit'
import { EXTERNAL_URL_REGEX, PUBLIC_DIR } from '../constants.js'
import { truthy } from '../utils.js'

/**
* @link https://github.com/vercel/next.js/blob/6cfebfb02c2a52a1f99fca59a2eac2d704d053db/packages/next/build/webpack/loaders/next-image-loader.js#L6
Expand Down Expand Up @@ -99,7 +98,7 @@ export const remarkStaticImage: Plugin<[], Root> = () => ast => {
}
}
}
].filter(truthy)
].filter(v => !!v)
})
}

Expand Down
6 changes: 0 additions & 6 deletions packages/nextra/src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import slash from 'slash'
import title from 'title'
import { DEFAULT_PROPERTY_PROPS } from './constants.js'

type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T // from lodash

export function truthy<T>(value: T): value is Truthy<T> {
return !!value
}

export const logger = {
info: console.log.bind(null, '-', '\x1b[36minfo\x1b[0m', '[nextra]'),
warn: console.log.bind(null, '-', '\x1b[33mwarn\x1b[0m', '[nextra]'),
Expand Down

0 comments on commit edc6c29

Please sign in to comment.