-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathlightningcss-loader.ts
More file actions
59 lines (51 loc) · 1.56 KB
/
lightningcss-loader.ts
File metadata and controls
59 lines (51 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-disable @typescript-eslint/no-require-imports */
export function lightningcssLoader() {
let lightningcssPath: string | undefined;
// Try to resolve the path to lightningcss from the @expo/metro-config package
// lightningcss is a direct dependency of @expo/metro-config
try {
lightningcssPath = require.resolve("lightningcss", {
paths: [
require
.resolve("@expo/metro-config/package.json")
.replace("/package.json", ""),
],
});
} catch {
// Intentionally left empty
}
// If @expo/metro-config is not being used (non-metro bundler?), try and resolve it directly
try {
lightningcssPath ??= require.resolve("lightningcss");
} catch {
// Intentionally left empty
}
if (!lightningcssPath) {
throw new Error(
"react-native-css was unable to determine the path to lightningcss",
);
}
const { transform: lightningcss, Features } = require(
lightningcssPath,
) as typeof import("lightningcss");
try {
const lightningcssPackageJSONPath = require.resolve("../../package.json", {
paths: [lightningcssPath],
});
const packageJSON = require(lightningcssPackageJSONPath) as Record<
string,
unknown
>;
if (packageJSON.version === "1.30.2") {
throw new Error(
"[react-native-css] lightningcss version 1.30.2 has a critical bug that breaks compilation. Please pin the version of lightningcss to 1.30.1; or try upgrading.",
);
}
} catch {
// Intentionally left empty
}
return {
lightningcss,
Features,
};
}