quokka icon indicating copy to clipboard operation
quokka copied to clipboard

Expose `--experimental-loader` API inside plugins

Open vjpr opened this issue 4 years ago • 0 comments

Issue description or question

Related: https://github.com/wallabyjs/quokka/issues/696#issuecomment-949127319

Plugins like https://github.com/Nodman/quokka-plugin-subdir are not possible in ESM environments without access to it.

Would be nice to allow hooking into this via the plugin API.

Alternative

Support subdir functionality in Quokka's hook.

Allow specifying the context.parentURL to use in the Loader.resolve hook from a plugin API.

module.exports = {
  before: async (config, setProjectDir) => { 
     const {pkgDir, pkg} = config
     // Also, allow user to locate the `pkgDir` from the package name (`pkg`) themselves.
    setProjectDir(pkgDir)
  }
}
({
  pkg: '@foo/bar',
})

// quokka scratch file

When I add my own experimental loader, Quokka adds theirs to the end:

  env: { params: { runner: '--experimental-loader=file:///my/esm-loader-wallaby.js --experimental-specifier-resolution=node --experimental-import-meta-resolve --experimental-vm-modules --experimental-top-level-await --experimental-loader "file:///Users/Vaughan/Library/Application%20Support/JetBrains/IntelliJIdeaVaughan/config/plugins/quokka-intellij/dist/runners/node/[email protected]/hooks.mjs"' } }

Otherwise, you could just add your loader and import Quokka's loader.

Chaining hooks is coming to Node.js soon - still in development which would solve this.


FYI, the hook api was recently changed too.

Note: In a previous version of this API, this was split across 3 separate, now deprecated, hooks (getFormat, getSource, and transformSource). https://nodejs.org/api/esm.html#loadurl-context-defaultload

vjpr avatar Oct 22 '21 15:10 vjpr