Skip to content

Commit 901cc4a

Browse files
committed
update platform extraction from file name
1 parent a6617e8 commit 901cc4a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

scripts/add-platform-exports.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,28 @@ const PLATFORMS = ['browser', 'node', 'react_native'];
2323

2424
function getPlatformFromFilename(filename) {
2525
const platforms = [];
26-
for (const platform of PLATFORMS) {
27-
if (filename.includes(`.${platform}.`)) {
28-
platforms.push(platform);
26+
const basename = path.basename(filename);
27+
28+
// Extract all parts before the extension
29+
// e.g., "file.browser.node.ts" -> ["file", "browser", "node"]
30+
const parts = basename.split('.');
31+
32+
// Skip the last part (extension)
33+
if (parts.length < 2) {
34+
return null;
35+
}
36+
37+
// Check parts from right to left (excluding extension) for platform names
38+
for (let i = parts.length - 2; i >= 0; i--) {
39+
const part = parts[i];
40+
if (PLATFORMS.includes(part)) {
41+
platforms.unshift(part); // Add to beginning to maintain order
42+
} else {
43+
// Stop when we encounter a non-platform part
44+
break;
2945
}
3046
}
47+
3148
return platforms.length > 0 ? platforms : null;
3249
}
3350

0 commit comments

Comments
 (0)