hereby icon indicating copy to clipboard operation
hereby copied to clipboard

it would be nice if task name only needed to be specified once

Open iambumblehead opened this issue 1 year ago • 3 comments

Probably there are reasons 'build' must declare twice (the exported name and again at the name property.) Feel free to close this issue as just a casual suggestion...

export const build = task({
    name: "build",
    run: async () => {
        await execa("tsc", ["-b", "./src"]);
    },
})

Imo it would be cool if something like this could be used instead,

export default [
  task({
    name: "build",
    run: async () => {
        await execa("tsc", ["-b", "./src"]);
    }
  })
]

Two reasons the latter pattern could be preferred,

  1. the task name is defined in one place and one way only,
  2. allows task name to more-easily be used as a variable name used by the task

The named-variables reason of point 2 is difficult to explain, however the below example would be easier to do using the suggested interface, because 'buildsitemap' is more easily imported to 'buildsitemap' while being simultaneously used as a task name 'buildsitemap',

import buildsitemap from './buildsitemap.js'

export default [
  task({
    name: 'buildsitemap',
    run: async () => {
        await buildsitemap()
  })
]

thanks for hereby.js and regards :)

iambumblehead avatar Apr 29 '24 23:04 iambumblehead

I don't think I would allow exporting an array; export default is explicitly used for specifying which task should run when hereby is not given a task name.

However, I have a change locally that I never pushed which does something like this but from the other direction; it allows you to omit the name in the object and infer it from the export name, so long as there's only one export of it (besides default). Perhaps that would be helpful?

(If so, the so long my 500 LoC 😄)

jakebailey avatar Apr 29 '24 23:04 jakebailey

Also, out of curiousity, where are you using hereby?

jakebailey avatar Apr 29 '24 23:04 jakebailey

Thanks for the reply.

Also, out of curiousity, where are you using hereby?

I'm using hereby in something I've been developing solo for awhile and it may never see a public release.

iambumblehead avatar Apr 30 '24 00:04 iambumblehead