Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[feature] Arbitrary watch criteria #494

Open
Assignees
Labels
enhancementNew feature or request
@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'))
 };
 },
});

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /