-
-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Assignees
@steveluscher
Description
Background
Imagine that you're making a collection that produces a source code AST for each package in a monorepo.
Conceptually, you want to watch each package.
const packages = defineCollection({ name: 'packages', directory: 'packages', include: '**/package.json', schema: () => ({}), async transform(doc) { return { ...doc, ast: getAstFromEntrypoint(join('packages', doc.filePath, 'src', 'index.ts')) }; }, });
But what you actually want to watch is the source code inside the package.
Proposal
Add a watch function to context. Every time transform runs, you can use this function to declare which files should trigger a re-transform when they change.
const packages = defineCollection({ name: 'packages', directory: 'packages', include: '**/package.json', schema: () => ({}), async transform(doc, { watch }) { watch(join('packages', doc.filePath, 'src', '**', '*.ts')); // Watch all TypeScript files in `src/` return { ...doc, ast: getAstFromEntrypoint(join('packages', doc.filePath, 'src', 'index.ts')) }; }, });