Repository: parcel-bundler/parcel
File: packages/resolvers/glob/src/GlobResolver.js (JavaScript)

Code before:
        specifierType: dependency.specifierType,
        parent: dependency.resolveFrom,
        env: dependency.env,
        sourcePath: dependency.sourcePath,
        loc: dependency.loc,
      });

      if (!result || !result.filePath) {
        throw errorToThrowableDiagnostic(
          `Unable to resolve ${pkg} from ${sourceFile} when resolving specifier ${specifier}`,
          dependency,
        );
      } else if (result.diagnostics) {
        throw new ThrowableDiagnostic({diagnostic: result.diagnostics});
      }
      // We keep Flow happy by copying the filePath at a point we know it's defined
      const filePath = result.filePath;

      const ctx = {
        invalidateOnFileCreate: result.invalidateOnFileCreate || [],
        invalidateOnFileChange: new Set(result.invalidateOnFileChange),
        specifierType: dependency.specifierType,
        loc: dependency.loc,
      };

      const resolvedPackage = await resolver.findPackage(filePath, ctx);
      if (!resolvedPackage) {
        throw errorToThrowableDiagnostic(
          `Unable to find package from ${filePath} when resolving specifier ${specifier}`,
          dependency,
        );
      }
      specifier = path.resolve(resolvedPackage.pkgdir, rest);
    } else {
      specifier = path.resolve(path.dirname(sourceFile), specifier);
    }

    let normalized = normalizeSeparators(specifier);
    let files = await glob(normalized, options.inputFS, {
      onlyFiles: true,
    });

    let dir = path.dirname(specifier);
    let results = files.map(file => {
      let relative = relativePath(dir, file);
      if (pipeline) {
        relative = `${pipeline}:${relative}`;
      }

      return [file, relative];
    });

Review comment (suggestion):
I'm not sure this is quite right because there could be another package.json inside a sub-directory of the module. We can use the `resolver.resolveModule` method for this I think.

Code after:

      let ctx = {
        invalidateOnFileCreate,
        invalidateOnFileChange,
        specifierType: dependency.specifierType,
        loc: dependency.loc,
      };

      let result;
      try {
        result = await resolver.resolveModule({
          filename: pkg,
          parent: dependency.resolveFrom,
          env: dependency.env,
          sourcePath: dependency.sourcePath,
          ctx,
        });
      } catch (err) {
        if (err instanceof ThrowableDiagnostic) {
          // Return instead of throwing so we can provide invalidations.
          return {
            diagnostics: err.diagnostics,
            invalidateOnFileCreate,
            invalidateOnFileChange: [...invalidateOnFileChange],
          };
        } else {
          throw err;
        }
      }

      if (!result || !result.moduleDir) {
        throw errorToThrowableDiagnostic(
          `Unable to resolve ${pkg} from ${sourceFile} when resolving specifier ${specifier}`,
          dependency,
        );
      }

      specifier = path.resolve(result.moduleDir, rest);
    } else {
      specifier = path.resolve(path.dirname(sourceFile), specifier);
    }

    let normalized = normalizeSeparators(specifier);
    let files = await glob(normalized, options.inputFS, {
      onlyFiles: true,
    });

    let dir = path.dirname(specifier);
    let results = files.map(file => {
      let relative = relativePath(dir, file);
      if (pipeline) {