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

Code before:
      return;
    }

    let sourceAssetType = nullthrows(dependency.sourceAssetType);
    let sourceFile = nullthrows(
      dependency.resolveFrom ?? dependency.sourcePath,
    );

    let error;
    if (sourceAssetType !== 'js' && sourceAssetType !== 'css') {
      error = `Glob imports are not supported in ${sourceAssetType} files.`;
    } else if (
      dependency.specifierType === 'url' &&
      !dependency.meta?.isCSSImport
    ) {
      error = 'Glob imports are not supported in URL dependencies.';
    }

    if (error) {
      throw errorToThrowableDiagnostic(error, dependency);
    }

    // if the specifier does not start with /, ~, or . then it's not a path but package-ish - we resolve
    // the package first, and then append the rest of the path
    if (!/^[/~.]/.test(specifier)) {
      specifier = path.normalize(specifier);
      let splitOn = specifier.indexOf(path.sep);
      if (specifier.charAt(0) === '@') {
        splitOn = specifier.indexOf(path.sep, splitOn + 1);
      }

      // Since we've already asserted earlier that there is a glob present, it shouldn't be
      // possible for there to be only a package here without any other path parts (e.g. `import('pkg')`)
      invariant(splitOn !== -1);

      let pkg = specifier.substring(0, splitOn);
      let rest = specifier.substring(splitOn + 1);

      // This initialisation code is copied from the DefaultResolver
      const resolver = new NodeResolver({
        fs: options.inputFS,
        projectRoot: options.projectRoot,
        // Extensions are always required in URL dependencies.
        extensions:
          dependency.specifierType === 'commonjs' ||
          dependency.specifierType === 'esm'
            ? ['ts', 'tsx', 'js', 'jsx', 'json']
            : [],
        mainFields: ['source', 'browser', 'module', 'main'],
        packageManager: options.shouldAutoInstall
          ? options.packageManager

Review comment (suggestion):
I _think_ globs are supposed to always use `/` as a separator, even on Windows. See https://github.com/micromatch/micromatch#backslashes. So this might not be needed.

Code after:
      return;
    }

    let sourceAssetType = nullthrows(dependency.sourceAssetType);
    let sourceFile = nullthrows(
      dependency.resolveFrom ?? dependency.sourcePath,
    );

    let error;
    if (sourceAssetType !== 'js' && sourceAssetType !== 'css') {
      error = `Glob imports are not supported in ${sourceAssetType} files.`;
    } else if (
      dependency.specifierType === 'url' &&
      !dependency.meta?.isCSSImport
    ) {
      error = 'Glob imports are not supported in URL dependencies.';
    }

    if (error) {
      throw errorToThrowableDiagnostic(error, dependency);
    }

    // if the specifier does not start with /, ~, or . then it's not a path but package-ish - we resolve
    // the package first, and then append the rest of the path
    if (!/^[/~.]/.test(specifier)) {
      // Globs are not paths - so they always use / (see https://github.com/micromatch/micromatch#backslashes)
      let splitOn = specifier.indexOf('/');
      if (specifier.charAt(0) === '@') {
        splitOn = specifier.indexOf('/', splitOn + 1);
      }

      // Since we've already asserted earlier that there is a glob present, it shouldn't be
      // possible for there to be only a package here without any other path parts (e.g. `import('pkg')`)
      invariant(splitOn !== -1);

      let pkg = specifier.substring(0, splitOn);
      let rest = specifier.substring(splitOn + 1);

      // This initialisation code is copied from the DefaultResolver
      const resolver = new NodeResolver({
        fs: options.inputFS,
        projectRoot: options.projectRoot,
        // Extensions are always required in URL dependencies.
        extensions:
          dependency.specifierType === 'commonjs' ||
          dependency.specifierType === 'esm'
            ? ['ts', 'tsx', 'js', 'jsx', 'json']
            : [],
        mainFields: ['source', 'browser', 'module', 'main'],
        packageManager: options.shouldAutoInstall
          ? options.packageManager