Skip to content

Commit 5082b6a

Browse files
committed
fix duplicate modules on Windows when bundling with Rollup and Genes (closes #3)
Another case of incorrect separators. We now detect the separator from the importer and use that for our generated id. This ensures that the separator is correct for both Vite and Rollup.
1 parent 62b52de commit 5082b6a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

vite-plugin-openfl.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ export default function openflPlugin() {
5151
config = resolvedConfig;
5252
},
5353
resolveId(source, importer) {
54-
if (!/[\/\\]project\.xml$/.test(importer)) {
54+
const matched = /([\/\\])project\.xml$/.exec(importer);
55+
if (!matched) {
5556
return;
5657
}
58+
const sep = matched[1];
5759

5860
const hxml = getHXML(importer);
5961
if (!hxml) {
@@ -71,9 +73,12 @@ export default function openflPlugin() {
7173
const absoluteSource = path.resolve(outDir, source);
7274
if (fs.existsSync(absoluteSource)) {
7375
return {
74-
// force / on all platforms, including windows
75-
// otherwise, there may be duplicates of some modules
76-
id: absoluteSource.replaceAll(path.sep, path.posix.sep),
76+
// vite and rollup provide different default ids on windows.
77+
// vite always normalizes to forward slash, but rollup does not,
78+
// so detect the correct separator to use from the importer.
79+
// this is to ensure that the ids returned for imports in the entry
80+
// point match the ids for those same imports in other files.
81+
id: absoluteSource.replaceAll(/[\/\\]/g, sep),
7782
};
7883
}
7984
}

0 commit comments

Comments
 (0)