Allow `build.resolve` call that bypasses all plugins
Some kind of skipPlugins option that could be true or an array of plugin names.
Context
I'm adding a build.onResolved hook (note the past tense) to esbuild-extra. Its purpose is to be able to adjust onResolve results (i.e. edit the suffix based on import kind).
To achieve this, I have to mimic esbuild's fallback resolution logic, or else the onResolved hooks wouldn't be called when all onResolve hooks return null.
Currently, I do this with enhanced-resolve, but it would be nice to simply call build.resolve with skipPlugins: true instead.
I think the standard way to do this today is to just put extra data on the otherOptions that allows it checks to prevent cycles:
export function wrapResolvePlugin() {
return {
name: 'wrap-resolve',
setup(build) {
build.onResolve({ filter: /./ }, async ({ path: importPath, ...otherOptions }) => {
// These lines are to prevent infinite recursion when we call `build.resolve`.
if (otherOptions.pluginData) {
return;
}
const result = await build.resolve(importPath, {
pluginData: true,
...otherOptions
});
return {
// Futz with result
...result,
};
});
},
};
}
You could do anything with pluginData, even use it as the array you mention with names to skip. But this way you prevent the recursion.
I dunno if that helps you, and I still wouldn't mind a general "just do the raw resolve" option myself.