source: imaps-frontend/node_modules/rollup/dist/native.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.4 KB
Line 
1const { existsSync } = require('node:fs');
2const path = require('node:path');
3const { platform, arch, report } = require('node:process');
4
5const isMusl = () => !report.getReport().header.glibcVersionRuntime;
6
7const 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 linux: {
17 arm: { base: 'linux-arm-gnueabihf', musl: 'linux-arm-musleabihf' },
18 arm64: { base: 'linux-arm64-gnu', musl: 'linux-arm64-musl' },
19 ppc64: { base: 'linux-powerpc64le-gnu', musl: null },
20 riscv64: { base: 'linux-riscv64-gnu', musl: null },
21 s390x: { base: 'linux-s390x-gnu', musl: null },
22 x64: { base: 'linux-x64-gnu', musl: 'linux-x64-musl' }
23 },
24 win32: {
25 arm64: { base: 'win32-arm64-msvc' },
26 ia32: { base: 'win32-ia32-msvc' },
27 x64: { base: 'win32-x64-msvc' }
28 }
29};
30
31const msvcLinkFilenameByArch = {
32 arm64: 'vc_redist.arm64.exe',
33 ia32: 'vc_redist.x86.exe',
34 x64: 'vc_redist.x64.exe'
35};
36
37const packageBase = getPackageBase();
38const localName = `./rollup.${packageBase}.node`;
39const requireWithFriendlyError = id => {
40 try {
41 return require(id);
42 } catch (error) {
43 if (
44 platform === 'win32' &&
45 error instanceof Error &&
46 error.code === 'ERR_DLOPEN_FAILED' &&
47 error.message.includes('The specified module could not be found')
48 ) {
49 const msvcDownloadLink = `https://aka.ms/vs/17/release/${msvcLinkFilenameByArch[arch]}`;
50 throw new Error(
51 `Failed to load module ${id}. ` +
52 'Required DLL was not found. ' +
53 'This error usually happens when Microsoft Visual C++ Redistributable is not installed. ' +
54 `You can download it from ${msvcDownloadLink}`,
55 { cause: error }
56 );
57 }
58
59 throw new Error(
60 `Cannot find module ${id}. ` +
61 `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
62 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
63 { cause: error }
64 );
65 }
66};
67
68const { parse, parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } = requireWithFriendlyError(
69 existsSync(path.join(__dirname, localName)) ? localName : `@rollup/rollup-${packageBase}`
70);
71
72function 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
83function 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
87The 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
97If this is important to you, please consider supporting Rollup to make a native build for your platform and architecture available.`
98 );
99}
100
101module.exports.parse = parse;
102module.exports.parseAsync = parseAsync;
103module.exports.xxhashBase64Url = xxhashBase64Url;
104module.exports.xxhashBase36 = xxhashBase36;
105module.exports.xxhashBase16 = xxhashBase16;
Note: See TracBrowser for help on using the repository browser.