import * as babel from "@babel/core";
function astro({config, devServer}) {
  return {
    name: "@astrojs/vite-plugin-astro-postprocess",
    async transform(code, id) {
      if (!id.endsWith(".astro") && !id.endsWith(".md")) {
        return null;
      }
      if (!code.includes("fetchContent")) {
        return null;
      }
      const result = await babel.transformAsync(code, {
        sourceType: "module",
        sourceMaps: true,
        plugins: [
          () => {
            return {
              visitor: {
                StringLiteral(path) {
                  if (path.parent.type !== "CallExpression" || path.parent.callee.type !== "MemberExpression" || path.parent.callee.object.name !== "Astro" || path.parent.callee.property.name !== "fetchContent") {
                    return;
                  }
                  const {value} = path.node;
                  if (/[a-z]\:\/\//.test(value)) {
                    return;
                  }
                  path.replaceWith({
                    type: "CallExpression",
                    callee: {
                      type: "MemberExpression",
                      object: {type: "MetaProperty", meta: {type: "Identifier", name: "import"}, property: {type: "Identifier", name: "meta"}},
                      property: {type: "Identifier", name: "globEager"},
                      computed: false
                    },
                    arguments: [path.node]
                  });
                }
              }
            };
          }
        ]
      });
      if (!result || !result.code) {
        return null;
      }
      return {code: result.code, map: result.map};
    }
  };
}
export {
  astro as default
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL3ZpdGUtcGx1Z2luLWFzdHJvLXBvc3Rwcm9jZXNzL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIkFBTUE7QUFPZSxlQUFlLENBQUUsUUFBUSxZQUF5QztBQUMvRSxTQUFPO0FBQUEsSUFDTCxNQUFNO0FBQUEsVUFDQSxVQUFVLE1BQU0sSUFBSTtBQUV4QixVQUFJLENBQUMsR0FBRyxTQUFTLGFBQWEsQ0FBQyxHQUFHLFNBQVMsUUFBUTtBQUNqRCxlQUFPO0FBQUE7QUFLVCxVQUFJLENBQUMsS0FBSyxTQUFTLGlCQUFpQjtBQUNsQyxlQUFPO0FBQUE7QUFJVCxZQUFNLFNBQVMsTUFBTSxNQUFNLGVBQWUsTUFBTTtBQUFBLFFB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