source: frontend/node_modules/@babel/plugin-transform-runtime/src/get-runtime-path/index.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import path from "node:path";
2
3import { createRequire } from "node:module";
4const require = createRequire(import.meta.url);
5
6export default function (
7 moduleName: string,
8 dirname: string,
9 absoluteRuntime: string | boolean,
10) {
11 if (absoluteRuntime === false) return moduleName;
12
13 return resolveAbsoluteRuntime(
14 moduleName,
15 path.resolve(dirname, absoluteRuntime === true ? "." : absoluteRuntime),
16 );
17}
18
19function resolveAbsoluteRuntime(moduleName: string, dirname: string) {
20 try {
21 return path
22 .dirname(
23 require.resolve(`${moduleName}/package.json`, { paths: [dirname] }),
24 )
25 .replace(/\\/g, "/");
26 } catch (err) {
27 if (err.code !== "MODULE_NOT_FOUND") throw err;
28
29 throw Object.assign(
30 new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`),
31 {
32 code: "BABEL_RUNTIME_NOT_FOUND",
33 runtime: moduleName,
34 dirname,
35 },
36 );
37 }
38}
39
40export function resolveFSPath(path: string) {
41 return require.resolve(path).replace(/\\/g, "/");
42}
Note: See TracBrowser for help on using the repository browser.