import type { InputPluginOption } from "@rollup/browser"; /** * Adds a plugin that handles very last check to see if a file exists and that it can be loaded. * This plugin also provides a web based filesystem that can be used by all other plugins in this package. * This plugin must be declared FIRST in the rollup config. This plugin is ideally injected at runtime by * the IDE. If the desired filesystem does not exist, it will fall back to the available node filesystem. */ export default (): InputPluginOption => { return { name: "web-fs-loader", resolveId: { order: "post", async handler(importee, importer) { try { await this.fs.stat(importee); return importee; } catch (_) {} throw new Error( `Could not resolve import "${importee}" from "${importer}"`, ); }, }, load: { order: "post", handler(id) { return this.fs.readFile(id, { encoding: "utf8" }); }, }, }; };