Skip to content

feat: enhance transform and evalModule to support async callbacks#364

Open
productdevbook wants to merge 5 commits intounjs:mainfrom
productdevbook:feat-evalmodule-1
Open

feat: enhance transform and evalModule to support async callbacks#364
productdevbook wants to merge 5 commits intounjs:mainfrom
productdevbook:feat-evalmodule-1

Conversation

@productdevbook
Copy link

@productdevbook productdevbook commented Feb 10, 2025

close: #363

In some setups like Unimport, we need to modify the source to add imports at the beginning of each content. Since sourceTransformer is empty every time the eval mode transform runs, I store and cache it to reuse later.

Example code:

  const jiti = createJiti(test.options.rootDir, {
    fsCache: false,
    moduleCache: false,
    debug: true,
    alias: test.options.alias,
  })


  const test = await jiti.evalModule(
    injectedResult.code,
    {
      filename: path,
      async: true,
      conditions: test.options.conditions,

    },
    async (data, name) => {
      return (await test.unimport!.injectImports(data, name)).code
    },
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unimport support

1 participant