diff --git a/packages/nuxt/playground/pergel/test.docker-compose.yml b/packages/nuxt/playground/pergel/test.docker-compose.yml index 80b15a85..01b2fa7a 100644 --- a/packages/nuxt/playground/pergel/test.docker-compose.yml +++ b/packages/nuxt/playground/pergel/test.docker-compose.yml @@ -7,6 +7,9 @@ services: - type: volume source: pergel-postgres target: /var/lib/postgresql/data + ports: + - target: 5432 + published: 5432 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index 11d9ff53..79c2f2b9 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -1,4 +1,4 @@ -import { join } from 'node:path' +import { join, relative } from 'node:path' import { writeFileSync } from 'node:fs' import { addTemplate, @@ -155,6 +155,20 @@ export default defineNuxtModule({ nuxt._pergel.exitPergelFolder && writeFileSync(file, envTemplate, { encoding: 'utf8', }) + + nuxt._pergel.watchDirs = nuxt._pergel.projects + ? Object.keys(nuxt._pergel.projects).map((projectName) => { + const project = nuxt._pergel.projects[projectName] as any + + return Object.keys(project).map(moduleName => ({ + projectName, + moduleName, + serverDir: relative(nuxt.options.rootDir, project[moduleName].serverDir), + rootModuleDir: relative(nuxt.options.rootDir, project[moduleName].rootModuleDir), + })) + }, + ).flat() + : [] }, }) diff --git a/packages/nuxt/src/runtime/core/types/nuxtModule.ts b/packages/nuxt/src/runtime/core/types/nuxtModule.ts index 9cc5be29..147d3438 100644 --- a/packages/nuxt/src/runtime/core/types/nuxtModule.ts +++ b/packages/nuxt/src/runtime/core/types/nuxtModule.ts @@ -211,6 +211,13 @@ export interface ResolvedPergelOptions { workspaceMode: boolean serverDir: string + + watchDirs: { + serverDir: string + rootModuleDir: string + projectName: string + moduleName: string + }[] } export interface NuxtPergel extends Nuxt { diff --git a/packages/nuxt/src/runtime/core/utils/globs.ts b/packages/nuxt/src/runtime/core/utils/globs.ts index 84657744..86697914 100644 --- a/packages/nuxt/src/runtime/core/utils/globs.ts +++ b/packages/nuxt/src/runtime/core/utils/globs.ts @@ -1,24 +1,36 @@ -import { join, relative, resolve } from 'node:path' +import { join, resolve } from 'node:path' import { matchGlobs } from '../../modules/graphqlYoga/utils' -import type { NuxtPergel, PergelModuleNames } from '../types/nuxtModule' +import type { NuxtPergel } from '../types/nuxtModule' export function globsBuilderWatch( nuxt: NuxtPergel, path: string, - folder: string, - ext: string, ) { const absolutePath = resolve(nuxt.options.rootDir, path) - const relativePath = relative(nuxt.options.rootDir, path) + const dirs = nuxt._pergel.watchDirs + const match = matchGlobs( + absolutePath, + [...dirs.map(({ serverDir }) => { + return join('**', serverDir, '**') + }), ...dirs.map(({ rootModuleDir }) => { + return join('**', rootModuleDir, '**') + })], + ) - const groups = relativePath.match(/pergel\/(?[^\/]+)\/(?[^\/]+)/)?.groups - const { projectName, moduleName } = groups || {} + if (!match) { + return { + match: false, + } + } - const match = matchGlobs(absolutePath, [join('**', folder, '**', `*${ext}`)]) + const { serverDir, projectName, moduleName } = dirs.find(({ serverDir, rootModuleDir }) => { + return match.glob.includes(serverDir) || match.glob.includes(rootModuleDir) + })! return { - match, + match: true, + serverDir, projectName, - moduleName: moduleName as PergelModuleNames, + moduleName, } } diff --git a/packages/nuxt/src/runtime/modules/drizzle/drivers/postgres/index.ts b/packages/nuxt/src/runtime/modules/drizzle/drivers/postgres/index.ts index 32c536e2..2faf7274 100644 --- a/packages/nuxt/src/runtime/modules/drizzle/drivers/postgres/index.ts +++ b/packages/nuxt/src/runtime/modules/drizzle/drivers/postgres/index.ts @@ -151,6 +151,12 @@ export default { target: '/var/lib/postgresql/data', }, ], + ports: [ + { + target: 5432, + published: 5432, + }, + ], environment: { POSTGRES_USER: 'postgres', POSTGRES_PASSWORD: 'postgres', diff --git a/packages/nuxt/src/runtime/modules/drizzle/index.ts b/packages/nuxt/src/runtime/modules/drizzle/index.ts index 5a5408a4..8a15b0d1 100644 --- a/packages/nuxt/src/runtime/modules/drizzle/index.ts +++ b/packages/nuxt/src/runtime/modules/drizzle/index.ts @@ -175,17 +175,15 @@ export default definePergelModule({ }, ` + // Watch for changes nuxt.hook('builder:watch', async (event, path) => { - // TODO: add support module name const { match, projectName, moduleName } = globsBuilderWatch( nuxt, path, - 'drizzle', - '.ts', ) if (projectName) { - const activeProject = nuxt._pergel.rootOptions.projects[projectName][moduleName] as DrizzleConfig + const activeProject = (nuxt._pergel.rootOptions.projects as any)[projectName][moduleName] as DrizzleConfig if (!activeProject) return diff --git a/packages/nuxt/src/runtime/modules/graphqlYoga/utils.ts b/packages/nuxt/src/runtime/modules/graphqlYoga/utils.ts index 4a59cb90..65b9de4e 100644 --- a/packages/nuxt/src/runtime/modules/graphqlYoga/utils.ts +++ b/packages/nuxt/src/runtime/modules/graphqlYoga/utils.ts @@ -3,8 +3,12 @@ import { join } from 'pathe' export function matchGlobs(filepath: string, globs: string[]) { for (const glob of globs) { - if (minimatch(join(filepath), glob)) - return true + if (minimatch(join(filepath), glob)) { + return { + glob, + status: true, + } + } } return false }