/** Component name resolver for unplugin-vue-components. */

export function CoalesceVuetifyResolver() {
  return {
    type: "component",
    resolve: (name: string) => {
      if (name.match(/^C[A-Z]/))
        return { name, from: "coalesce-vue-vuetify/lib" };
    },
  } as const;
}

/** Component name resolver for unplugin-vue-components. */

let moduleName: Promise<string>;
export function CoalesceVuetifyResolver() {
  moduleName = (async () => {
    // See if coalesce-vue-vuetify2 was aliased in package.json as coalesce-vue-vuetify.
    // We have to do so in a way that will work in both ESM and CJS.

    if ("require" in global) {
      try {
        require.resolve("coalesce-vue-vuetify");
        return "coalesce-vue-vuetify";
      } catch {}
    } else {
      try {
        if (await import.meta.resolve?.("coalesce-vue-vuetify"))
          return "coalesce-vue-vuetify";
      } catch {}
    }
    return "coalesce-vue-vuetify2";
  })();

  return {
    type: "component",
    resolve: async (name: string) => {
      if (name.match(/^C[A-Z]/))
        return { name, from: (await moduleName) + "/lib" };
    },
  } as const;
}

Make CoalesceVuetifyResolver automatically detect if coalesce-vue-vuetify2 was aliased as coalesce-vue-vuetify via package.json
Make CoalesceVuetifyResolver automatically detect if coalesce-vue-vuetify2 was aliased as coalesce-vue-vuetify via package.json
