Skip to content

Conversation

@jablko
Copy link
Contributor

@jablko jablko commented Sep 17, 2021

What do you think of adding more links from tsconfig options to their definitions in the reference?

I found this helpful when tracking down the default moduleResolution value, which depends on module, which depends on target.

Roughly I did a search/replace on the option names in packages/tsconfig-reference/data/tsconfigOpts.json, and manually reviewed until I arrived at the propsed edits. They're the result of the following commands:

set $(jq --raw-output '.options[].name' packages/tsconfig-reference/data/tsconfigOpts.json)
IFS='|'
git ls-files -z |
  xargs --null perl -p -Mstrict -MFile::Basename -i -e '
    # Exclude Markdown headings and code comments
    !m(^#|(?:^| )// ) && s(
      (?<behind>\b(?:flag|option|setting)\ )?
      (?:
        (?<!!)\[["`]*(?<dashDash>-*)(?<option>'"$*"')["`]*\]\((?<url>.*?)\)
        |
        (?<!\[)"?`"?(?<dashDash>-*)(?<option>'"$*"')"?`"?
      )
      (?<ahead>\ (?:compiler\ )?(?:flag|option|setting)\b)?
      (?![^[]*])
    )(
      my %g = %+;
      # Build options special case
      my $text = $g{option} eq "force" || $g{option} eq "verbose"
        ? "--$g{option}"
        : $g{option};
      # Existing non-tsconfig-reference links
      my $url = $g{url} && $g{url} !~ /tsconfig|^#/
        ? $g{url}
        : "/tsconfig#$g{option}";
      (
        (
          # Not really flags
          $g{option} eq "lib" ||
          $g{option} eq "module" ||
          $g{option} eq "moduleResolution" ||
          $g{option} eq "outFile" ||
          $g{option} eq "target" ||
          $g{option} eq "tsBuildInfoFile"
        ) && $g{behind} eq "flag "
          ? "option "
          : $g{behind}
      ) .
      (
        (
          # Ambiguous names
          $g{option} eq "exclude" ||
          $g{option} eq "extends" ||
          $g{option} eq "jsx" ||
          $g{option} eq "lib" ||
          $g{option} eq "module" ||
          $g{option} eq "out" ||
          $g{option} eq "synchronousWatchDirectory" ||
          $g{option} eq "types"
        ) && !$g{behind} && !$g{ahead} && !$g{dashDash} && !$g{url} ||
        basename($ARGV) eq "$g{option}.md"
          ? "`$text`"
          : "[`$text`]($url)"
      ) .
      (
        (
          # Not really flags
          $g{option} eq "lib" ||
          $g{option} eq "module" ||
          $g{option} eq "moduleResolution" ||
          $g{option} eq "outFile" ||
          $g{option} eq "target" ||
          $g{option} eq "tsBuildInfoFile"
        ) && $g{ahead} eq " flag"
          ? " option"
          : $g{ahead}
      )
    )xge
  '
unset IFS
# Clean up
git ls-files -z | xargs --null sed --in-place 's%(/tsconfig/#%(/tsconfig#%g'
git ls-files -z packages/tsconfig-reference | xargs --null sed --in-place 's%(/tsconfig#%(#%g'
git checkout @ \
  .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs \
  packages/tsconfig-reference/scripts/schema \
  README.md \
  '**/README.md' \

@orta
Copy link
Contributor

orta commented Sep 23, 2021

I'm a fan, I'll read through each diff later 👍🏻

@orta
Copy link
Contributor

orta commented Sep 24, 2021

Read it all, and pretty much all of this is fine IMO. There might be an issue with the tsconfig onliners being used elsewhere ( I think the playground renders them too) but I think that's an easy fix once I see it in prod.

Great work! Thanks!

@orta orta merged commit 064dc8d into microsoft:v2 Sep 24, 2021
@jablko
Copy link
Contributor Author

jablko commented Sep 24, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants