-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy path@parcel__watcher@2.5.0.patch
67 lines (64 loc) · 2.49 KB
/
@parcel__watcher@2.5.0.patch
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
60
61
62
63
64
65
66
67
diff --git a/index.js b/index.js
index 8afb2b1126dcc687b7ff9b631589da252c1f9c22..f3b1158eb5612235388ff5f5347f6edcbf323090 100644
--- a/index.js
+++ b/index.js
@@ -1,41 +1,27 @@
-const {createWrapper} = require('./wrapper');
+const { createWrapper } = require('./wrapper')
-let name = `@parcel/watcher-${process.platform}-${process.arch}`;
-if (process.platform === 'linux') {
- const { MUSL, family } = require('detect-libc');
- if (family === MUSL) {
- name += '-musl';
- } else {
- name += '-glibc';
- }
-}
+function loadPackage() {
+ if (process.platform === 'linux') {
+ let { MUSL, GLIBC, family, familySync } = require('detect-libc')
+ // Bun polyfills `detect-libc` in compiled binaries. We rely on
+ // detect-libc@1.0.3 but the polyfilled version is 2.x. In detect-libc@2x
+ // there is a `familySync` function that we can use instead.
+ if (typeof familySync === 'function') family = familySync()
-let binding;
-try {
- binding = require(name);
-} catch (err) {
- handleError(err);
- try {
- binding = require('./build/Release/watcher.node');
- } catch (err) {
- handleError(err);
- try {
- binding = require('./build/Debug/watcher.node');
- } catch (err) {
- handleError(err);
- throw new Error(`No prebuild or local build of @parcel/watcher found. Tried ${name}. Please ensure it is installed (don't use --no-optional when installing with npm). Otherwise it is possible we don't support your platform yet. If this is the case, please report an issue to https://github.com/parcel-bundler/watcher.`);
+ if (family === MUSL) {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-musl`)
+ } else if (family === GLIBC) {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-glibc`)
+ } else {
+ throw new Error(`Unsupported libc on: ${process.platform}-${process.arch}`)
}
+ } else {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}`)
}
}
-function handleError(err) {
- if (err?.code !== 'MODULE_NOT_FOUND') {
- throw err;
- }
-}
-
-const wrapper = createWrapper(binding);
-exports.writeSnapshot = wrapper.writeSnapshot;
-exports.getEventsSince = wrapper.getEventsSince;
-exports.subscribe = wrapper.subscribe;
-exports.unsubscribe = wrapper.unsubscribe;
+const wrapper = createWrapper(loadPackage())
+exports.writeSnapshot = wrapper.writeSnapshot
+exports.getEventsSince = wrapper.getEventsSince
+exports.subscribe = wrapper.subscribe
+exports.unsubscribe = wrapper.unsubscribe