2024-09-02 15:23:46 +02:00
diff --git a/index.js b/index.js
2026-08-04 13:55:03 +02:00
index 78ee744d74900c39a839cafa46b295258fc86307..f28fd092644ccfb8aff2618b966cb5219a181a02 100644
2024-09-02 15:23:46 +02:00
--- a/index.js
+++ b/index.js
2026-08-04 13:55:03 +02:00
@@ -1,43 +1,32 @@
2026-03-18 15:57:52 +01:00
const {createWrapper} = require('./wrapper');
2024-09-02 15:23:46 +02:00
-let name = `@parcel/watcher-${process.platform}-${process.arch}`;
-if (process.platform === 'linux') {
2026-08-04 13:55:03 +02:00
- const {MUSL, familySync} = require('detect-libc');
- const family = familySync();
2024-09-02 15:23:46 +02:00
- if (family === MUSL) {
- name += '-musl';
- } else {
- name += '-glibc';
- }
-}
2026-03-18 15:57:52 +01:00
+// We need to take the `process.env.PLATFORM_LIBC` into account, and we also
+// need static analysis, so we can't make use of the `parts.push(…)` approach.
2024-09-02 15:23:46 +02:00
+function loadPackage() {
+ if (process.platform === 'linux') {
2025-01-09 09:24:33 -05:00
+ if (process.env.PLATFORM_LIBC === "musl") {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-musl`)
+ } else if (process.env.PLATFORM_LIBC === "glibc") {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-glibc`)
+ } else {
2026-03-18 15:57:52 +01:00
+ let { MUSL, GLIBC, familySync } = require('detect-libc')
+ let family = familySync()
2024-09-02 15:23:46 +02:00
-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);
2026-08-04 13:55:03 +02:00
- 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.`,
- );
2025-01-09 09:24:33 -05:00
- }
- }
-}
-function handleError(err) {
- if (err?.code !== 'MODULE_NOT_FOUND') {
- throw err;
+ 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}`)
+ }
+ }
2024-09-02 15:23:46 +02:00
+ } else {
2024-11-13 11:38:43 +01:00
+ return require(`@parcel/watcher-${process.platform}-${process.arch}`)
2024-09-02 15:23:46 +02:00
}
}
-const wrapper = createWrapper(binding);
2026-03-18 15:57:52 +01:00
+const wrapper = createWrapper(loadPackage());
exports.writeSnapshot = wrapper.writeSnapshot;
exports.getEventsSince = wrapper.getEventsSince;
exports.subscribe = wrapper.subscribe;