const { Runtime } = require("@parcel/plugin");

module.exports = new Runtime({
  apply({bundle}) {
    let dep;
    bundle.traverse((node, _, actions) => {
      if (node.type === "dependency" && node.value.specifier === "foo") {
        dep = node.value;
        actions.stop();
      }
    });

    if (dep.meta.customValue != null) {
      return [
        {
          filePath: __filename,
          code: `sideEffect(${dep.meta.customValue});`,
          dependency: dep,
        },
      ];
    }
  },
});
