diff --git a/.changeset/stale-chairs-relate.md b/.changeset/stale-chairs-relate.md new file mode 100644 index 0000000000..001156f60e --- /dev/null +++ b/.changeset/stale-chairs-relate.md @@ -0,0 +1,5 @@ +--- +"nextra": patch +--- + +fix(nextra): ignore in loader files from `pages/api` folder diff --git a/packages/nextra/scripts/dev.js b/packages/nextra/scripts/dev.js index 5e77f8b134..4f630ea96d 100644 --- a/packages/nextra/scripts/dev.js +++ b/packages/nextra/scripts/dev.js @@ -1,7 +1,7 @@ const esbuild = require('esbuild') const packageJson = require('../package.json') -console.log('Watching...') +console.log('[nextra] Watching...') const BUILD_OPTIONS = { platform: 'node', @@ -11,9 +11,9 @@ const BUILD_OPTIONS = { watch: { onRebuild(error) { if (error) { - console.error('Watch build failed:', error) + console.error('[nextra] Watch build failed:', error) } else { - console.log('Watch build succeeded.') + console.log('[nextra] Watch build succeeded.') } } } diff --git a/packages/nextra/src/compile.ts b/packages/nextra/src/compile.ts index 2b9da11fc8..b5a6d28c4f 100644 --- a/packages/nextra/src/compile.ts +++ b/packages/nextra/src/compile.ts @@ -89,8 +89,7 @@ export async function compileMdx( structurizedData } } catch (err) { - console.error(`\nError compiling ${resourcePath}`) - console.error(`${err}\n`) + console.error(`[nextra] Error compiling ${resourcePath}.`) throw err } } diff --git a/packages/nextra/src/index.js b/packages/nextra/src/index.js index 7ec1817b62..be3618c3cb 100644 --- a/packages/nextra/src/index.js +++ b/packages/nextra/src/index.js @@ -23,7 +23,7 @@ module.exports = if (locales) { console.log( - '[Nextra] You have Next.js i18n enabled, read here (TODO: link) for the docs.' + '[nextra] You have Next.js i18n enabled, read here (TODO: link) for the docs.' ) } diff --git a/packages/nextra/src/loader.ts b/packages/nextra/src/loader.ts index b843571760..060c289346 100644 --- a/packages/nextra/src/loader.ts +++ b/packages/nextra/src/loader.ts @@ -27,7 +27,7 @@ const [repository, gitRoot] = (function () { const gitRoot = path.join(repo.path(), '..') return [repo, gitRoot] } catch (e) { - console.warn('Init git repository failed', e) + console.warn('[nextra] Init git repository failed', e) return [] } })() @@ -50,6 +50,11 @@ async function loader( } = options const { resourcePath } = context + if (resourcePath.includes('/pages/api/')) { + console.warn(`[nextra] Ignoring ${resourcePath} because it is located in the "pages/api" folder.`) + return '' + } + const filename = resourcePath.slice(resourcePath.lastIndexOf('/') + 1) const fileLocale = getLocaleFromFilename(filename) @@ -137,15 +142,15 @@ async function loader( if (repository.isShallow()) { if (process.env.VERCEL) { console.warn( - `The repository is shallow cloned, so the latest modified time will not be presented. Set the VERCEL_DEEP_CLONE=true environment variable to enable deep cloning.` + '[nextra] The repository is shallow cloned, so the latest modified time will not be presented. Set the VERCEL_DEEP_CLONE=true environment variable to enable deep cloning.' ) } else if (process.env.GITHUB_ACTION) { console.warn( - `The repository is shallow cloned, so the latest modified time will not be presented. See https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches to fetch all the history.` + '[nextra] The repository is shallow cloned, so the latest modified time will not be presented. See https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches to fetch all the history.' ) } else { console.warn( - `The repository is shallow cloned, so the latest modified time will not be presented.` + '[nextra] The repository is shallow cloned, so the latest modified time will not be presented.' ) } } diff --git a/packages/nextra/src/utils.ts b/packages/nextra/src/utils.ts index 24f0cb855c..36de082202 100644 --- a/packages/nextra/src/utils.ts +++ b/packages/nextra/src/utils.ts @@ -23,7 +23,7 @@ export const parseJsonFile: ( try { return JSON.parse(content) } catch (err) { - console.error(`Error parsing ${path}, make sure it's a valid JSON \n` + err) + console.error(`[nextra] Error parsing ${path}, make sure it's a valid JSON`, err) return {} } }