import * as babel from "@babel/core";
const validAstroGlobalNames = new Set(["Astro", "Astro2"]);
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" || !validAstroGlobalNames.has(path.parent.callee.object.name) || 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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL3ZpdGUtcGx1Z2luLWFzdHJvLXBvc3Rwcm9jZXNzL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIkFBTUE7QUFRQSxNQUFNLHdCQUF3QixJQUFJLElBQUksQ0FBQyxTQUFTO0FBRWpDLGVBQWUsQ0FBRSxRQUFRLFlBQXlDO0FBQy9FLFNBQU87QUFBQSxJQUNMLE1BQU07QUFBQSxVQUNBLFVBQVUsTUFBTSxJQUFJO0FBRXhCLFVBQUksQ0FBQyxHQUFHLFNBQVMsYUFBYSxDQUFDLEdBQUcsU0FBUyxRQUFRO0FBQ2pELGVBQU87QUFBQTtBQUtULFVBQUksQ0FBQyxLQUFLLFNBQVM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