-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(fluid-build): Add support for declarative tasks #22663
Open
tylerbutler
wants to merge
26
commits into
microsoft:main
Choose a base branch
from
tylerbutler:bt-input-output-task
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
62688bc
Squished branch: bt-input-output-task
tylerbutler 71aeb38
feat(fluid-build): Add support for declarative tasks
tylerbutler c91b771
cleanup
tylerbutler f5561a4
improvement(fluid-build): Pass BuildContext object to tasks
tylerbutler daae5a1
policy
tylerbutler e75fba6
docs
tylerbutler a7d0127
Merge branch 'bt-fluid-build-context' into bt-input-output-task
tylerbutler 2e6c64b
Merge branch 'main' into bt-fluid-build-context
tylerbutler 1f3cd06
separate statsContext from buildContext
tylerbutler 3b7c133
cache the config reader
tylerbutler 2e32ca8
implement buildCOntext in graphContext and rename property to context
tylerbutler aea52f3
Merge branch 'bt-fluid-build-context' into bt-input-output-task
tylerbutler 2183750
policy
tylerbutler b66a057
Merge branch 'main' into bt-input-output-task
tylerbutler 0950619
Merge branch 'main' into bt-input-output-task
tylerbutler ad3042d
updates
tylerbutler 5cd7e68
Apply suggestions from code review
tylerbutler f03465d
feedback
tylerbutler 1df8f5f
docs
tylerbutler e72f148
rm overrides
tylerbutler 62b7c34
Merge branch 'main' into bt-input-output-task
tylerbutler 128b606
Merge branch 'main' into bt-input-output-task
tylerbutler 29efcf3
add gitignore config
tylerbutler 8457833
Merge branch 'main' into bt-input-output-task
tylerbutler 710c5b2
Merge branch 'main' into bt-input-output-task
tylerbutler 930535d
Merge branch 'main' into bt-input-output-task
tylerbutler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
build-tools/packages/build-tools/src/fluidBuild/tasks/leaf/declarativeTask.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import globby from "globby"; | ||
|
||
import type { BuildContext } from "../../buildContext"; | ||
import type { BuildPackage } from "../../buildGraph"; | ||
import type { DeclarativeTask } from "../../fluidBuildConfig"; | ||
import type { TaskHandlerFunction } from "../taskHandlers"; | ||
import { LeafTask, LeafWithFileStatDoneFileTask } from "./leafTask"; | ||
|
||
class DeclarativeTaskHandler extends LeafWithFileStatDoneFileTask { | ||
constructor( | ||
node: BuildPackage, | ||
command: string, | ||
context: BuildContext, | ||
taskName: string | undefined, | ||
private readonly taskDefinition: DeclarativeTask, | ||
) { | ||
super(node, command, context, taskName); | ||
} | ||
|
||
/** | ||
* Use hashes instead of modified times in donefile. | ||
*/ | ||
protected get useHashes(): boolean { | ||
return true; | ||
} | ||
|
||
protected async getInputFiles(): Promise<string[]> { | ||
const { inputGlobs, gitignore: gitignoreSetting } = this.taskDefinition; | ||
|
||
// Ignore gitignored files if the setting is undefined, since the default is ["input"]. Otherwise check that it | ||
// includes "input". | ||
const gitignore: boolean = | ||
gitignoreSetting === undefined || gitignoreSetting.indexOf("input") !== -1; | ||
const inputFiles = await globby(inputGlobs, { | ||
cwd: this.node.pkg.directory, | ||
// file paths returned from getInputFiles and getOutputFiles should always be absolute | ||
absolute: true, | ||
gitignore, | ||
}); | ||
return inputFiles; | ||
} | ||
|
||
protected async getOutputFiles(): Promise<string[]> { | ||
const { outputGlobs, gitignore: gitignoreSetting } = this.taskDefinition; | ||
|
||
const gitignore: boolean = gitignoreSetting?.indexOf("output") !== -1; | ||
const outputFiles = await globby(outputGlobs, { | ||
cwd: this.node.pkg.directory, | ||
// file paths returned from getInputFiles and getOutputFiles should always be absolute | ||
absolute: true, | ||
gitignore, | ||
}); | ||
return outputFiles; | ||
} | ||
} | ||
|
||
/** | ||
* Generates a task handler for a declarative task dynamically. | ||
* | ||
* @param taskDefinition - The declarative task definition. | ||
* @returns a function that can be used to instantiate a LeafTask to handle a task. | ||
*/ | ||
export function createDeclarativeTaskHandler( | ||
taskDefinition: DeclarativeTask, | ||
): TaskHandlerFunction { | ||
const handler: TaskHandlerFunction = ( | ||
node: BuildPackage, | ||
command: string, | ||
context: BuildContext, | ||
taskName?: string, | ||
): LeafTask => { | ||
return new DeclarativeTaskHandler(node, command, context, taskName, taskDefinition); | ||
}; | ||
return handler; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
build-tools/packages/build-tools/src/fluidBuild/tasks/taskHandlers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import type { BuildContext } from "../buildContext"; | ||
import type { BuildPackage } from "../buildGraph"; | ||
import type { LeafTask } from "./leaf/leafTask"; | ||
|
||
/** | ||
* The definition of a free function that returns a LeafTask subclass. | ||
*/ | ||
export type TaskHandlerFunction = ( | ||
node: BuildPackage, | ||
command: string, | ||
context: BuildContext, | ||
taskName?: string, | ||
) => LeafTask; | ||
|
||
/** | ||
* The definition of a constructor function that returns a LeafTask subclass. | ||
*/ | ||
export type TaskHandlerConstructor = new ( | ||
tylerbutler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
node: BuildPackage, | ||
command: string, | ||
context: BuildContext, | ||
taskName?: string, | ||
) => LeafTask; | ||
|
||
/** | ||
* A TaskHandler is a function that can be used to generate a `LeafTask` that will handle a particular fluid-build task. | ||
* The function can either be a constructor for a `LeafTask` subclass, or it can be a free function that returns a | ||
* `LeafTask`. | ||
*/ | ||
export type TaskHandler = TaskHandlerConstructor | TaskHandlerFunction; | ||
|
||
/** | ||
* Type guard to check if a TaskHandler is a constructor function. | ||
*/ | ||
export function isConstructorFunction( | ||
handler: TaskHandler, | ||
): handler is TaskHandlerConstructor { | ||
return typeof handler === "function" && !!handler.prototype; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments are outdated; fix.