unjs/unimport

Get imports as object

ennioVisco opened this issue · 2 comments

Describe the feature

I'm trying to incorporate unimport in a serverless.js building pipeline with the goal of automating part of the bindings that are currently done manually to connect the lambdas.

However, while it works fine for not having to manually import the lambda in the config file, you still must add it to the functions object. The code looks more or less like this:

// import hello from functions/hello/index.ts // automated by unimport

const config = {
// ...
  functions: {
    hello,
    // ...
  }
}

I was wondering whether unimport imported exports could be grouped in an object, so to get something like:

const config = {
// ...
  functions: {
    ... unimport()
  }
}

Additional information

  • Would you be willing to help implement this feature?

I would like to work on this @ennioVisco

antfu commented

Thanks for the proposal and thanks @ashutosh887 for your interest.

I don't know if this is a good thing to have. If the unimport() returns all imports registered, it means there will be no tree-shaking, and not extensible (adding new imports would also change the behavior of the function).

I would suggest explicitly using exports/imports - or maybe other tools for it. I think unimport might not be the right tool here. Closing as not planned.