batijs / bati

Next-gen scaffolder. Get started with fully-functional apps, and choose any tool you want.
https://batijs.dev
MIT License
194 stars 11 forks source link

Smarter detection of imported dependency files #275

Closed magne4000 closed 3 days ago

magne4000 commented 1 week ago

Shared files are files that can be imported by 0, 1 or multiple other files. Currently, those files are put in dedicated shared-* folders. They are created on file system if the bati.flags condition in package.json is true.

It's a bit cumbersome to maintain, and for complex flags combinations, it will become more and more difficult to not break things (i.e. ensuring that these files are not created when they shouldn't be).

The goal of this RFC will be to ensure that some files are only generated on file system if at least one other regular file imports it. It mostly impact shared files, but can be used anywhere in boilerplates.

How to tag a file as "dependency"

Possible solutions (TODO: pick one):

  1. files starting with comment: /* BATI dependency */
    • could be adapted in the future to support other tags: /* BATI dependency,tag1,tag2 */
  2. files with names containing [dependency], like handler[dependency].ts
    • could be adapted in the future to support other tags: handler[dependency,tag1,tag2].ts
magne4000 commented 1 week ago

Solution 1. could also be adapted for other use cases, such as generating a whole file only if some conditions are met (e.g. generate file server.node.ts only if no serverless deployment target has been chosen)