Skip to content
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

fix: make scheduledTasks types consistent #2284

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/nitro.ts
Expand Up @@ -128,6 +128,12 @@ export async function createNitro(
nitro.options.virtual["#internal/nitro/virtual/tasks"] = () => {
const _scheduledTasks = Object.entries(nitro.options.scheduledTasks || {})
.map(([cron, _tasks]) => {
if (!Array.isArray(_tasks)) {
nitro.logger.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still like to support non array format.

`[DEPRECATION] \`scheduledTasks\` must be an array. This will be removed in a future release`
);
}
// @todo: Remove isArray condition check when deprecation is effective
const tasks = (Array.isArray(_tasks) ? _tasks : [_tasks]).filter(
(name) => {
if (!nitro.options.tasks[name]) {
Expand Down
1 change: 1 addition & 0 deletions src/options.ts
Expand Up @@ -55,6 +55,7 @@ const NitroDefaults: NitroConfig = {
serverAssets: [],
plugins: [],
tasks: {},
scheduledTasks: {},
imports: {
exclude: [],
dirs: [],
Expand Down
2 changes: 1 addition & 1 deletion src/types/nitro.ts
Expand Up @@ -339,7 +339,7 @@ export interface NitroOptions extends PresetOptions {
modules?: NitroModuleInput[];
plugins: string[];
tasks: { [name: string]: { handler: string; description: string } };
scheduledTasks: { [cron: string]: string | string[] };
scheduledTasks: { [cron: string]: string[] };
virtual: Record<string, string | (() => string | Promise<string>)>;
compressPublicAssets: boolean | CompressOptions;
ignore: string[];
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/nitro.config.ts
Expand Up @@ -101,7 +101,7 @@ export default defineNitroConfig({
tasks: true,
},
scheduledTasks: {
"* * * * *": "test",
"* * * * *": ["test"],
},
cloudflare: {
pages: {
Expand Down