Skip to content

Commit

Permalink
fix: support @nuxtjs/robots v4 merge
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jul 15, 2024
1 parent e5eecb2 commit 8279e56
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { resolve } from 'node:path'
import { defineNuxtConfig } from 'nuxt/config'
import { defineNuxtModule } from '@nuxt/kit'
import { startSubprocess } from '@nuxt/devtools-kit'
import NuxtSimpleSitemap from '../src/module'
import NuxtSitemap from '../src/module'

export default defineNuxtConfig({
modules: [
NuxtSimpleSitemap,
'nuxt-simple-robots',
NuxtSitemap,
'@nuxtjs/robots',
'@nuxtjs/i18n',
'@nuxt/content',
'@nuxt/ui',
Expand Down
2 changes: 1 addition & 1 deletion .playground/pages/blocked-by-robots-txt/foo.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<template>
<div>This should be blocked by nuxt-simple-robots integration automatically.</div>
<div>This should be blocked by @nuxtjs/robots integration automatically.</div>
</template>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"execa": "^9.3.0",
"nuxt": "^3.12.3",
"nuxt-icon": "1.0.0-beta.7",
"nuxt-simple-robots": "4.0.0-rc.20",
"@nuxtjs/robots": "4.0.0-rc.22",
"typescript": "5.4.5",
"vitest": "^2.0.2"
},
Expand Down
94 changes: 47 additions & 47 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,20 @@ export default defineNuxtModule<ModuleOptions>({
}

let needsRobotsPolyfill = true
if (hasNuxtModule('nuxt-simple-robots')) {
const robotsVersion = await getNuxtModuleVersion('nuxt-simple-robots')
const robotsModuleName = hasNuxtModule('nuxt-simple-robots') ? 'nuxt-simple-robots' : hasNuxtModule('@nuxtjs/robots') ? '@nuxtjs/robots' : false
if (robotsModuleName) {
const robotsVersion = await getNuxtModuleVersion(robotsModuleName)
// we want to keep versions in sync
if (!await hasNuxtModuleCompatibility('nuxt-simple-robots', '>=4'))
logger.warn(`You are using nuxt-simple-robots v${robotsVersion}. For the best compatibility, please upgrade to nuxt-simple-robots v4.0.0 or higher.`)
if (!await hasNuxtModuleCompatibility(robotsModuleName, '>=4'))
logger.warn(`You are using ${robotsModuleName} v${robotsVersion}. For the best compatibility, please upgrade to ${robotsModuleName} v4.0.0 or higher.`)
else
needsRobotsPolyfill = false
// @ts-expect-error untyped
nuxt.hooks.hook('robots:config', (robotsConfig) => {
robotsConfig.sitemap.push(usingMultiSitemaps ? '/sitemap_index.xml' : `/${config.sitemapName}`)
})
}
// this is added in v4 of Nuxt Simple Robots
// this is added in v4 of Nuxt Robots
if (needsRobotsPolyfill) {
addServerImports([{
name: 'getPathRobotConfigPolyfill',
Expand Down

0 comments on commit 8279e56

Please sign in to comment.