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