Skip to content

Commit

Permalink
Throw original error when it is not MODULE_NOT_FOUND
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Feb 23, 2024
1 parent 93e911c commit cc904f8
Showing 1 changed file with 6 additions and 34 deletions.
40 changes: 6 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,24 @@ 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.`);
}
}
}

function normalizeOptions(dir, opts = {}) {
const { ignore, ...rest } = opts;

if (Array.isArray(ignore)) {
opts = { ...rest };

for (const value of ignore) {
if (isGlob(value)) {
if (!opts.ignoreGlobs) {
opts.ignoreGlobs = [];
}

const regex = micromatch.makeRe(value, {
// We set `dot: true` to workaround an issue with the
// regular expression on Linux where the resulting
// negative lookahead `(?!(\\/|^)` was never matching
// in some cases. See also https://bit.ly/3UZlQDm
dot: true,
// C++ does not support lookbehind regex patterns, they
// were only added later to JavaScript engines
// (https://bit.ly/3V7S6UL)
lookbehinds: false
});
opts.ignoreGlobs.push(regex.source);
} else {
if (!opts.ignorePaths) {
opts.ignorePaths = [];
}

opts.ignorePaths.push(path.resolve(dir, value));
}
}
function handleError(err) {
if (err?.code !== 'MODULE_NOT_FOUND') {
throw err;
}

return opts;
}

const wrapper = createWrapper(binding);
Expand Down

0 comments on commit cc904f8

Please sign in to comment.