Skip to content

Commit

Permalink
fix: messages type generation not watching locale files (#3224)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Nov 14, 2024
1 parent bc8a25f commit c0532a9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
10 changes: 9 additions & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@ import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: ['src/module'],
externals: ['node:fs', 'node:url', 'webpack', '@babel/parser', 'unplugin-vue-router', 'unplugin-vue-router/options']
externals: [
'node:fs',
'node:url',
'webpack',
'@babel/parser',
'unplugin-vue-router',
'unplugin-vue-router/options',
'chokidar'
]
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"@unhead/vue": "^1.8.8",
"bumpp": "^9.4.1",
"changelogithub": "^0.13.7",
"chokidar": "^4.0.1",
"consola": "^3",
"eslint": "^9.5.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
37 changes: 20 additions & 17 deletions pnpm-lock.yaml

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

21 changes: 19 additions & 2 deletions src/prepare/type-generation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { relative, resolve } from 'pathe'
import { addServerHandler, addTypeTemplate, updateTemplates, useNitro } from '@nuxt/kit'
import { normalize, relative, resolve } from 'pathe'
import { addServerHandler, addTypeTemplate, isIgnored, updateTemplates, useNitro } from '@nuxt/kit'
import { watch as chokidarWatch } from 'chokidar'

import type { Nuxt } from '@nuxt/schema'
import type { I18nOptions } from 'vue-i18n'
Expand Down Expand Up @@ -112,6 +113,22 @@ export {}`
}
})

// setup watcher when using restructureDir - folders outside srcDir are not watched
if (nuxt.options.future?.compatibilityVersion === 4 || options.restructureDir === false) {
const watcher = chokidarWatch(
localeInfo.flatMap(x => x.files.map(f => resolve(nuxt.options.srcDir, f.path))),
{
awaitWriteFinish: true,
ignoreInitial: true,
ignored: [isIgnored, 'node_modules']
}
)

// eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/no-unsafe-argument
watcher.on('all', (event, path) => nuxt.callHook('builder:watch', event, normalize(path)))
nuxt.hook('close', () => watcher?.close())
}

// watch locale files for changes and update template
// TODO: consider conditionally checking absolute paths for Nuxt 4
const localePaths = localeInfo.flatMap(x => x.files.map(f => relative(nuxt.options.srcDir, f.path)))
Expand Down

0 comments on commit c0532a9

Please sign in to comment.