1 | const { existsSync } = require('node:fs');
|
---|
2 | const path = require('node:path');
|
---|
3 | const { platform, arch, report } = require('node:process');
|
---|
4 |
|
---|
5 | const isMusl = () => !report.getReport().header.glibcVersionRuntime;
|
---|
6 |
|
---|
7 | const bindingsByPlatformAndArch = {
|
---|
8 | android: {
|
---|
9 | arm: { base: 'android-arm-eabi' },
|
---|
10 | arm64: { base: 'android-arm64' }
|
---|
11 | },
|
---|
12 | darwin: {
|
---|
13 | arm64: { base: 'darwin-arm64' },
|
---|
14 | x64: { base: 'darwin-x64' }
|
---|
15 | },
|
---|
16 | freebsd: {
|
---|
17 | arm64: { base: 'freebsd-arm64' },
|
---|
18 | x64: { base: 'freebsd-x64' }
|
---|
19 | },
|
---|
20 | linux: {
|
---|
21 | arm: { base: 'linux-arm-gnueabihf', musl: 'linux-arm-musleabihf' },
|
---|
22 | arm64: { base: 'linux-arm64-gnu', musl: 'linux-arm64-musl' },
|
---|
23 | ppc64: { base: 'linux-powerpc64le-gnu', musl: null },
|
---|
24 | riscv64: { base: 'linux-riscv64-gnu', musl: null },
|
---|
25 | s390x: { base: 'linux-s390x-gnu', musl: null },
|
---|
26 | x64: { base: 'linux-x64-gnu', musl: 'linux-x64-musl' }
|
---|
27 | },
|
---|
28 | win32: {
|
---|
29 | arm64: { base: 'win32-arm64-msvc' },
|
---|
30 | ia32: { base: 'win32-ia32-msvc' },
|
---|
31 | x64: { base: 'win32-x64-msvc' }
|
---|
32 | }
|
---|
33 | };
|
---|
34 |
|
---|
35 | const msvcLinkFilenameByArch = {
|
---|
36 | arm64: 'vc_redist.arm64.exe',
|
---|
37 | ia32: 'vc_redist.x86.exe',
|
---|
38 | x64: 'vc_redist.x64.exe'
|
---|
39 | };
|
---|
40 |
|
---|
41 | const packageBase = getPackageBase();
|
---|
42 | const localName = `./rollup.${packageBase}.node`;
|
---|
43 | const requireWithFriendlyError = id => {
|
---|
44 | try {
|
---|
45 | return require(id);
|
---|
46 | } catch (error) {
|
---|
47 | if (
|
---|
48 | platform === 'win32' &&
|
---|
49 | error instanceof Error &&
|
---|
50 | error.code === 'ERR_DLOPEN_FAILED' &&
|
---|
51 | error.message.includes('The specified module could not be found')
|
---|
52 | ) {
|
---|
53 | const msvcDownloadLink = `https://aka.ms/vs/17/release/${msvcLinkFilenameByArch[arch]}`;
|
---|
54 | throw new Error(
|
---|
55 | `Failed to load module ${id}. ` +
|
---|
56 | 'Required DLL was not found. ' +
|
---|
57 | 'This error usually happens when Microsoft Visual C++ Redistributable is not installed. ' +
|
---|
58 | `You can download it from ${msvcDownloadLink}`,
|
---|
59 | { cause: error }
|
---|
60 | );
|
---|
61 | }
|
---|
62 |
|
---|
63 | throw new Error(
|
---|
64 | `Cannot find module ${id}. ` +
|
---|
65 | `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
---|
66 | 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
---|
67 | { cause: error }
|
---|
68 | );
|
---|
69 | }
|
---|
70 | };
|
---|
71 |
|
---|
72 | const { parse, parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } = requireWithFriendlyError(
|
---|
73 | existsSync(path.join(__dirname, localName)) ? localName : `@rollup/rollup-${packageBase}`
|
---|
74 | );
|
---|
75 |
|
---|
76 | function getPackageBase() {
|
---|
77 | const imported = bindingsByPlatformAndArch[platform]?.[arch];
|
---|
78 | if (!imported) {
|
---|
79 | throwUnsupportedError(false);
|
---|
80 | }
|
---|
81 | if ('musl' in imported && isMusl()) {
|
---|
82 | return imported.musl || throwUnsupportedError(true);
|
---|
83 | }
|
---|
84 | return imported.base;
|
---|
85 | }
|
---|
86 |
|
---|
87 | function throwUnsupportedError(isMusl) {
|
---|
88 | throw new Error(
|
---|
89 | `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.
|
---|
90 |
|
---|
91 | The following platform-architecture combinations are supported:
|
---|
92 | ${Object.entries(bindingsByPlatformAndArch)
|
---|
93 | .flatMap(([platformName, architectures]) =>
|
---|
94 | Object.entries(architectures).flatMap(([architectureName, { musl }]) => {
|
---|
95 | const name = `${platformName}-${architectureName}`;
|
---|
96 | return musl ? [name, `${name} (musl)`] : [name];
|
---|
97 | })
|
---|
98 | )
|
---|
99 | .join('\n')}
|
---|
100 |
|
---|
101 | If this is important to you, please consider supporting Rollup to make a native build for your platform and architecture available.`
|
---|
102 | );
|
---|
103 | }
|
---|
104 |
|
---|
105 | module.exports.parse = parse;
|
---|
106 | module.exports.parseAsync = parseAsync;
|
---|
107 | module.exports.xxhashBase64Url = xxhashBase64Url;
|
---|
108 | module.exports.xxhashBase36 = xxhashBase36;
|
---|
109 | module.exports.xxhashBase16 = xxhashBase16;
|
---|