Repository: denoland/deno
File: cli/tools/registry/module_content.rs (Rust)

Code before:
        "jsxImportSource": "react",
        "jsxImportSourceTypes": "@types/react",
      },
      "imports": {
        "react": "npm:react"
        "@types/react": "npm:@types/react"
      }
    }"#,
        None,
      ),
      ("/package-b/deno.json", "{}", None),
      (
        "/package-a/main.tsx",
        "export const component = <div></div>;",
        Some("/** @jsxRuntime automatic *//** @jsxImportSource npm:react *//** @jsxImportSourceTypes npm:@types/react *//** @jsxFactory React.createElement *//** @jsxFragmentFactory React.Fragment */export const component = <div></div>;"),
      ),
      (
        "/package-a/other.tsx",
        "/** @jsxImportSource npm:preact */
        /** @jsxFragmentFactory h1 */
        /** @jsxImportSourceTypes npm:@types/example */
        /** @jsxFactory h2 */
        /** @jsxRuntime automatic */
        export const component = <div></div>;",
        Some(
        "/** @jsxImportSource npm:preact */
        /** @jsxFragmentFactory h1 */
        /** @jsxImportSourceTypes npm:@types/example */
        /** @jsxFactory h2 */
        /** @jsxRuntime automatic */
        export const component = <div></div>;",
        )
      ),
    ]);
  }

  fn get_path(path: &str) -> PathBuf {
    PathBuf::from(if cfg!(windows) {
      format!("C:{}", path.replace('/', "\\"))
    } else {
      path.to_string()
    })
  }

  fn run_test(files: &[(&'static str, &'static str, Option<&'static str>)]) {
    let in_memory_sys = InMemorySys::default();
    for (path, text, _) in files {
      let path = get_path(path);
      in_memory_sys
        .fs_create_dir_all(path.parent().unwrap())
        .unwrap();

Review comment (bug):
I just realized this is an interesting edge case where at runtime it would actually resolve to `npm:@types/react` instead of `npm:react`... so maybe this is not exactly correct. This is at least better than before where these wouldn't be inserted.

Code after:
        "jsxImportSource": "react",
        "jsxImportSourceTypes": "@types/react",
      },
      "imports": {
        "react": "npm:react"
        "@types/react": "npm:@types/react"
      }
    }"#,
        None,
      ),
      ("/package-b/deno.json", r#"{
        "compilerOptions": { "jsx": "react-jsx" },
        "imports": {
          "react": "npm:react"
          "@types/react": "npm:@types/react"
        }
      }"#, None),
      (
        "/package-a/main.tsx",
        "export const component = <div></div>;",
        Some("/** @jsxRuntime automatic *//** @jsxImportSource npm:react *//** @jsxImportSourceTypes npm:@types/react *//** @jsxFactory React.createElement *//** @jsxFragmentFactory React.Fragment */export const component = <div></div>;"),
      ),
      (
        "/package-b/main.tsx",
        "export const componentB = <div></div>;",
        Some("/** @jsxRuntime automatic *//** @jsxImportSource npm:react *//** @jsxImportSourceTypes npm:react *//** @jsxFactory React.createElement *//** @jsxFragmentFactory React.Fragment */export const componentB = <div></div>;"),
      ),
      (
        "/package-a/other.tsx",
        "/** @jsxImportSource npm:preact */
        /** @jsxFragmentFactory h1 */
        /** @jsxImportSourceTypes npm:@types/example */
        /** @jsxFactory h2 */
        /** @jsxRuntime automatic */
        export const component = <div></div>;",
        Some(
        "/** @jsxImportSource npm:preact */
        /** @jsxFragmentFactory h1 */
        /** @jsxImportSourceTypes npm:@types/example */
        /** @jsxFactory h2 */
        /** @jsxRuntime automatic */
        export const component = <div></div>;",
        )
      ),
    ]);
  }

  fn get_path(path: &str) -> PathBuf {
    PathBuf::from(if cfg!(windows) {
      format!("C:{}", path.replace('/', "\\"))
    } else {