@parcel__watcher@2.4.1.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. diff --git a/index.js b/index.js
  2. index 8afb2b1126dcc687b7ff9b631589da252c1f9c22..97975cf342ff8c204b5731840a89b8ea88b0dbbc 100644
  3. --- a/index.js
  4. +++ b/index.js
  5. @@ -1,40 +1,26 @@
  6. const {createWrapper} = require('./wrapper');
  7. -let name = `@parcel/watcher-${process.platform}-${process.arch}`;
  8. -if (process.platform === 'linux') {
  9. - const { MUSL, family } = require('detect-libc');
  10. - if (family === MUSL) {
  11. - name += '-musl';
  12. - } else {
  13. - name += '-glibc';
  14. - }
  15. -}
  16. +function loadPackage() {
  17. + if (process.platform === 'linux') {
  18. + let { MUSL, GLIBC, family, familySync } = require("detect-libc");
  19. + // Bun polyfills `detect-libc` in compiled binaries. We rely on
  20. + // detect-libc@1.0.3 but the polyfilled version is 2.x. In detect-libc@2x
  21. + // there is a `familySync` function that we can use instead.
  22. + if (typeof familySync === 'function') family = familySync()
  23. -let binding;
  24. -try {
  25. - binding = require(name);
  26. -} catch (err) {
  27. - handleError(err);
  28. - try {
  29. - binding = require('./build/Release/watcher.node');
  30. - } catch (err) {
  31. - handleError(err);
  32. - try {
  33. - binding = require('./build/Debug/watcher.node');
  34. - } catch (err) {
  35. - handleError(err);
  36. - 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.`);
  37. + if (family === MUSL) {
  38. + return require(`@parcel/watcher-${process.platform}-${process.arch}-musl`);
  39. + } else if (family === GLIBC) {
  40. + return require(`@parcel/watcher-${process.platform}-${process.arch}-glibc`);
  41. + } else {
  42. + throw new Error(`Unsupported libc on: ${process.platform}-${process.arch}`);
  43. }
  44. + } else {
  45. + return require(`@parcel/watcher-${process.platform}-${process.arch}`);
  46. }
  47. }
  48. -function handleError(err) {
  49. - if (err?.code !== 'MODULE_NOT_FOUND') {
  50. - throw err;
  51. - }
  52. -}
  53. -
  54. -const wrapper = createWrapper(binding);
  55. +const wrapper = createWrapper(loadPackage());
  56. exports.writeSnapshot = wrapper.writeSnapshot;
  57. exports.getEventsSince = wrapper.getEventsSince;
  58. exports.subscribe = wrapper.subscribe;