Skip to content

Commit 555982a

Browse files
authored
Improve error message when running on unsupported MUSL Linux (#5454)
1 parent edc1504 commit 555982a

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

native.js

+29-30
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,6 @@ const msvcLinkFilenameByArch = {
3535
};
3636

3737
const packageBase = getPackageBase();
38-
39-
if (!packageBase) {
40-
throw new Error(
41-
`Your current platform "${platform}" and architecture "${arch}" combination is not yet supported by the native Rollup build. Please use the WASM build "@rollup/wasm-node" instead.
42-
43-
The following platform-architecture combinations are supported:
44-
${Object.entries(bindingsByPlatformAndArch)
45-
.flatMap(([platformName, architectures]) =>
46-
Object.entries(architectures).flatMap(([architectureName, { musl }]) => {
47-
const name = `${platformName}-${architectureName}`;
48-
return musl ? [name, `${name} (musl)`] : [name];
49-
})
50-
)
51-
.join('\n')}
52-
53-
If this is important to you, please consider supporting Rollup to make a native build for your platform and architecture available.`
54-
);
55-
}
56-
57-
function getPackageBase() {
58-
const imported = bindingsByPlatformAndArch[platform]?.[arch];
59-
if (!imported) {
60-
return null;
61-
}
62-
if ('musl' in imported && isMusl()) {
63-
return imported.musl;
64-
}
65-
return imported.base;
66-
}
67-
6838
const localName = `./rollup.${packageBase}.node`;
6939
const requireWithFriendlyError = id => {
7040
try {
@@ -99,6 +69,35 @@ const { parse, parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } = requi
9969
existsSync(join(__dirname, localName)) ? localName : `@rollup/rollup-${packageBase}`
10070
);
10171

72+
function getPackageBase() {
73+
const imported = bindingsByPlatformAndArch[platform]?.[arch];
74+
if (!imported) {
75+
throwUnsupportedError(false);
76+
}
77+
if ('musl' in imported && isMusl()) {
78+
return imported.musl || throwUnsupportedError(true);
79+
}
80+
return imported.base;
81+
}
82+
83+
function throwUnsupportedError(isMusl) {
84+
throw new Error(
85+
`Your current platform "${platform}${isMusl ? ' (musl)' : ''}" and architecture "${arch}" combination is not yet supported by the native Rollup build. Please use the WASM build "@rollup/wasm-node" instead.
86+
87+
The following platform-architecture combinations are supported:
88+
${Object.entries(bindingsByPlatformAndArch)
89+
.flatMap(([platformName, architectures]) =>
90+
Object.entries(architectures).flatMap(([architectureName, { musl }]) => {
91+
const name = `${platformName}-${architectureName}`;
92+
return musl ? [name, `${name} (musl)`] : [name];
93+
})
94+
)
95+
.join('\n')}
96+
97+
If this is important to you, please consider supporting Rollup to make a native build for your platform and architecture available.`
98+
);
99+
}
100+
102101
module.exports.parse = parse;
103102
module.exports.parseAsync = parseAsync;
104103
module.exports.xxhashBase64Url = xxhashBase64Url;

0 commit comments

Comments
 (0)