Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use common TSConfig for all packages #2872

Closed
wants to merge 7 commits into from

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Oct 5, 2021

Issue

Internal: JS-2844
Refs: #1307

Description

Update clients and protocol_tests to use root TSConfig

Shell script for renaming tsconfig.json to tsconfig.cjs.json
foreach parentDir ("clients" "protocol_tests")
  for dir in ./$parentDir/*; do (cd "$dir" && sed -i 's/tsconfig.json/tsconfig.cjs.json/g' ./package.json); done
  for dir in ./$parentDir/*; do (cd "$dir" && mv tsconfig.json tsconfig.cjs.json); done
end
Script used for updating tsconfig
// @ts-check
import { readdirSync, readFileSync, writeFileSync } from "fs";
import { join } from "path";

const clients = ["clients/*", "protocol_tests/*"];

clients
  .map((dir) => dir.replace("/*", ""))
  .forEach((workspacesDir) => {
    // Process each workspace in workspace directory
    readdirSync(join(process.cwd(), workspacesDir), { withFileTypes: true })
      .filter((dirent) => dirent.isDirectory())
      .map((dirent) => dirent.name)
      .forEach((workspaceDir) => {
        const cwd = join(process.cwd(), workspacesDir, workspaceDir);

        const customTsConfig = {
          "tsconfig.cjs.json": {
            outDir: "dist-cjs",
          },
          "tsconfig.es.json": {
            outDir: "dist-es",
          },
          "tsconfig.types.json": {
            declarationDir: "dist-types",
          },
        };

        const extendsTsConfig = {
          "tsconfig.cjs.json": "../../tsconfig.cjs.json",
          "tsconfig.es.json": "../../tsconfig.es.json",
          "tsconfig.types.json": "../../tsconfig.types.json",
        };

        for (const tsconfigFileName of ["tsconfig.cjs.json", "tsconfig.es.json", "tsconfig.types.json"]) {
          const tsconfigFilePath = join(cwd, tsconfigFileName);
          const tsconfig = JSON.parse(readFileSync(tsconfigFilePath, "utf8").toString());
          writeFileSync(
            tsconfigFilePath,
            JSON.stringify(
              {
                ...tsconfig,
                compilerOptions: {
                  baseUrl: ".",
                  rootDir: "src",
                  ...customTsConfig[tsconfigFileName],
                  ...(tsconfig?.compilerOptions?.lib && { lib: tsconfig.compilerOptions.lib }),
                  ...(tsconfig?.compilerOptions?.types && { types: tsconfig.compilerOptions.types }),
                },
                extends: extendsTsConfig[tsconfigFileName],
                include: ["src/"],
              },
              null,
              2
            ).concat(`\n`)
          );
        }
      });
  });

Testing

CI

Additional context

Attempt to use common TSConfig without bumping Jest #2864


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

foreach parentDir ("clients" "protocol_tests")
  for dir in ./$parentDir/*; do (cd "$dir" && sed -i 's/tsconfig.json/tsconfig.cjs.json/g' ./package.json); done
  for dir in ./$parentDir/*; do (cd "$dir" && mv tsconfig.json tsconfig.cjs.json); done
end
@trivikr trivikr marked this pull request as draft October 5, 2021 22:07
@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2021

Codecov Report

Merging #2872 (00ff8df) into main (10d64df) will decrease coverage by 25.95%.
The diff coverage is n/a.

❗ Current head 00ff8df differs from pull request most recent head b51f27d. Consider uploading reports for the commit b51f27d to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2872       +/-   ##
===========================================
- Coverage   60.42%   34.46%   -25.96%     
===========================================
  Files         554      554               
  Lines       28886    30459     +1573     
  Branches     7072     7283      +211     
===========================================
- Hits        17453    10499     -6954     
- Misses      11433    19960     +8527     
Impacted Files Coverage Δ
.../commands/HttpPayloadTraitsWithMediaTypeCommand.ts 34.61% <0.00%> (-65.39%) ⬇️
.../commands/HttpPayloadTraitsWithMediaTypeCommand.ts 34.61% <0.00%> (-65.39%) ⬇️
...nds/HttpPayloadWithXmlNamespaceAndPrefixCommand.ts 34.61% <0.00%> (-65.39%) ⬇️
...s/src/commands/AssumeRoleWithWebIdentityCommand.ts 36.00% <0.00%> (-64.00%) ⬇️
...l/src/commands/InputAndOutputWithHeadersCommand.ts 36.00% <0.00%> (-64.00%) ⬇️
...n/src/commands/InputAndOutputWithHeadersCommand.ts 36.00% <0.00%> (-64.00%) ⬇️
.../src/commands/FlattenedXmlMapWithXmlNameCommand.ts 36.00% <0.00%> (-64.00%) ⬇️
...src/commands/HttpPayloadWithXmlNamespaceCommand.ts 36.00% <0.00%> (-64.00%) ⬇️
...rc/commands/HttpPayloadWithMemberXmlNameCommand.ts 36.00% <0.00%> (-64.00%) ⬇️
...rc/commands/StreamingTraitsRequireLengthCommand.ts 36.00% <0.00%> (-64.00%) ⬇️
... and 263 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10d64df...b51f27d. Read the comment docs.

@trivikr trivikr closed this Oct 5, 2021
@trivikr trivikr deleted the root-tsconfig branch October 5, 2021 23:54
@trivikr
Copy link
Member Author

trivikr commented Oct 12, 2021

Superceded by #2864

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2021
@trivikr trivikr restored the root-tsconfig branch January 4, 2022 16:20
@trivikr trivikr deleted the root-tsconfig branch August 26, 2022 02:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants