Repository: facebook/docusaurus
File: packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts (TypeScript)

Code before:
    if (assetFilePath) {
      return assetFilePath;
    }
  } else {
    const assetFilePath = path.join(path.dirname(filePath), assetPath);
    if (await fs.pathExists(assetFilePath)) {
      return assetFilePath;
    }
  }
  return null;
}

async function processLinkNode(target: Target, context: Context) {
  const [node] = target;
  if (!node.url) {
    node.url =
      context.onBrokenMarkdownLinks({
        url: node.url,
        sourceFilePath: context.filePath,
        node,
      }) ?? node.url;
    return;
  }

  const parsedUrl = parseURLOrPath(node.url);
  if (parsedUrl.protocol || !parsedUrl.pathname) {
    // Don't process pathname:// here, it's used by the <Link> component
    return;
  }
  const hasSiteAlias = parsedUrl.pathname.startsWith('@site/');
  const hasAssetLikeExtension =
    path.extname(parsedUrl.pathname) &&
    !parsedUrl.pathname.match(/\.(?:mdx?|html)(?:#|$)/);
  if (!hasSiteAlias && !hasAssetLikeExtension) {
    return;
  }

  const localFilePath = await getLocalFileAbsolutePath(
    decodeURIComponent(parsedUrl.pathname),
    context,
  );

  if (localFilePath) {
    await toAssetRequireNode(target, localFilePath, context);
  } else {
    // The @site alias is the only way to believe that the user wants an asset.
    if (hasSiteAlias) {
      node.url =
        context.onBrokenMarkdownLinks({
          url: node.url,
          sourceFilePath: context.filePath,

Review comment (suggestion):
The condition `!parsedUrl.pathname` is now effectively dead code. The modern `URL` object returned by `parseURLOrPath()` always has a non-empty `pathname` property (minimum value is `/`), unlike the deprecated `url.parse()` which could return null/undefined. Consider removing this part of the condition since `parsedUrl.protocol` alone is sufficient to filter out URLs with protocols. Alternatively, add a comment explaining this is a defensive check for future-proofing.
```suggestion
  if (parsedUrl.protocol) {
```

Code after:
    );
    if (assetFilePath) {
      return assetFilePath;
    }
  } else {
    const assetFilePath = path.join(path.dirname(filePath), assetPath);
    if (await fs.pathExists(assetFilePath)) {
      return assetFilePath;
    }
  }
  return null;
}

async function processLinkNode(target: Target, context: Context) {
  const [node] = target;
  if (!node.url) {
    node.url =
      context.onBrokenMarkdownLinks({
        url: node.url,
        sourceFilePath: context.filePath,
        node,
      }) ?? node.url;
    return;
  }

  const localUrlPath = parseLocalURLPath(node.url);
  if (!localUrlPath) {
    // Don't process pathname:// here, it's used by the <Link> component
    return;
  }

  const hasSiteAlias = localUrlPath.pathname.startsWith('@site/');
  const hasAssetLikeExtension =
    path.extname(localUrlPath.pathname) &&
    !localUrlPath.pathname.match(/\.(?:mdx?|html)(?:#|$)/);
  if (!hasSiteAlias && !hasAssetLikeExtension) {
    return;
  }

  const localFilePath = await getLocalFileAbsolutePath(
    decodeURIComponent(localUrlPath.pathname),
    context,
  );

  if (localFilePath) {
    await toAssetRequireNode(target, localFilePath, context);
  } else {
    // The @site alias is the only way to believe that the user wants an asset.
    if (hasSiteAlias) {
      node.url =
        context.onBrokenMarkdownLinks({