Skip to content

Commit 6951bd3

Browse files
authored
fix: handle multiple installs of Photon (#40)
* fix: handle multiple installs of Photon * docs(changeset): fix: handle multiple installs of Photon
1 parent 12ee518 commit 6951bd3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.changeset/sour-planes-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@photonjs/core": patch
3+
---
4+
5+
fix: handle multiple installs of Photon

packages/core/src/plugin/plugins/resolvePhotonConfigPlugin.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { yellow } from "ansis";
12
import type { Plugin } from "vite";
23
import type { Photon } from "../../types.js";
34
import { PhotonConfigError } from "../../utils/assert.js";
@@ -25,8 +26,19 @@ export function resolvePhotonConfigPlugin(pluginConfig?: Photon.Config): Plugin[
2526
handler(config) {
2627
// Ensures that a unique photon config exists across all envs
2728
if (resolvedPhotonConfig === null) {
28-
// biome-ignore lint/suspicious/noExplicitAny: any
29-
resolvedPhotonConfig = resolvePhotonConfig(config.photon as any);
29+
if (Array.isArray(config.photon.entries)) {
30+
// If `entries` is already an Array, it means that `config.photon` is already resolved,
31+
// most probably because another version of this plugin is installed.
32+
console.warn(
33+
yellow(
34+
"[photon] Multiple versions of @photonjs/core detected. This may cause unexpected behavior. Try running 'npm dedupe' or 'yarn dedupe' to resolve version conflicts.",
35+
),
36+
);
37+
resolvedPhotonConfig = config.photon;
38+
} else {
39+
// biome-ignore lint/suspicious/noExplicitAny: any
40+
resolvedPhotonConfig = resolvePhotonConfig(config.photon as any);
41+
}
3042
}
3143
if (resolvedPhotonConfig.codeSplitting.framework) {
3244
const serverConfigEntries = resolvedPhotonConfig.entries.filter((e) => e.type === "server-config");

0 commit comments

Comments
 (0)