Skip to content

Commit 7ae6bdd

Browse files
authored
🐛 fix: Expose typing for drupal config file (#164)
1 parent d991677 commit 7ae6bdd

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

packages/drupal-vite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
},
3939
"peerDependencies": {
4040
"typescript": "^5",
41-
"vite": "^6.0.0",
42-
"@urql/core": "^5.1.1"
41+
"vite": ">=6",
42+
"@urql/core": ">=5"
4343
},
4444
"dependencies": {
4545
"@types/fs-extra": "^11.0.4",

packages/drupal-vite/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,18 @@ export function drupal(options?: DrupalPluginOptions): Plugin {
131131
path.resolve(process.cwd(), "drupal-decoupled.config.ts")
132132
);
133133

134+
const importLine = hasCustomConfig
135+
? `import customConfig from "./drupal-decoupled.config.ts";`
136+
: "";
137+
138+
const exchanges = hasCustomConfig
139+
? "customConfig.exchanges ?? [fetchExchange]"
140+
: "[fetchExchange]";
141+
134142
const module = `
135143
import { drupalAuthClient } from "drupal-auth-client";
136144
import { Client, fetchExchange } from "@urql/core";
137-
${hasCustomConfig ? `import customConfig from "./drupal-decoupled.config.ts";` : ""}
145+
${importLine}
138146
139147
export async function getDrupalAuth() {
140148
return await drupalAuthClient("${sanitizedDrupalUrl}", {
@@ -147,7 +155,7 @@ export async function getDrupalClient() {
147155
const auth = await getDrupalAuth();
148156
return new Client({
149157
url: "${fullGraphqlEndpoint}",
150-
exchanges: ${hasCustomConfig ? "customConfig.exchanges ?? [fetchExchange]" : "[fetchExchange]"},
158+
exchanges: ${exchanges},
151159
fetchOptions: {
152160
headers: {
153161
Authorization: \`\${auth.token_type} \${auth.access_token}\`,
@@ -162,3 +170,5 @@ export async function getDrupalClient() {
162170
},
163171
};
164172
}
173+
174+
export type { DrupalViteConfig } from "./types";

packages/drupal-vite/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Exchange } from "@urql/core";
22

3-
export interface DrupalDecoupledConfig {
3+
export interface DrupalViteConfig {
44
/** Custom exchanges for the GraphQL client */
55
exchanges?: Exchange[];
66
}

0 commit comments

Comments
 (0)