index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const {createWrapper} = require('./wrapper');
  2. let name = `@parcel/watcher-${process.platform}-${process.arch}`;
  3. if (process.platform === 'linux') {
  4. const { MUSL, familySync } = require('detect-libc');
  5. const family = familySync();
  6. if (family === MUSL) {
  7. name += '-musl';
  8. } else {
  9. name += '-glibc';
  10. }
  11. }
  12. let binding;
  13. try {
  14. binding = require(name);
  15. } catch (err) {
  16. handleError(err);
  17. try {
  18. binding = require('./build/Release/watcher.node');
  19. } catch (err) {
  20. handleError(err);
  21. try {
  22. binding = require('./build/Debug/watcher.node');
  23. } catch (err) {
  24. handleError(err);
  25. 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.`);
  26. }
  27. }
  28. }
  29. function handleError(err) {
  30. if (err?.code !== 'MODULE_NOT_FOUND') {
  31. throw err;
  32. }
  33. }
  34. const wrapper = createWrapper(binding);
  35. exports.writeSnapshot = wrapper.writeSnapshot;
  36. exports.getEventsSince = wrapper.getEventsSince;
  37. exports.subscribe = wrapper.subscribe;
  38. exports.unsubscribe = wrapper.unsubscribe;