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

fix(js): mimic the behavior of tsc compilation for runTypeCheck #9240

Merged
merged 2 commits into from Mar 21, 2022

Conversation

nartc
Copy link
Contributor

@nartc nartc commented Mar 9, 2022

ISSUES CLOSED: #9203

Current Behavior

On Windows, the runTypeCheck with emitDeclarationOnly emits the type definitions to the wrong output directory.

Expected Behavior

runTypeCheck now mimics the behavior of compilationTypescript (from nrwl/workspace which nrwl/js:tsc is utilizing) to ensure the behavior is consistent across different executors on different OS's

Related Issue(s)

Fixes #9203

@nx-cloud
Copy link

nx-cloud bot commented Mar 9, 2022

☁️ Nx Cloud Report

CI ran the following commands for commit 41d8b18. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 7 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented Mar 9, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nrwl/nx-dev/GNmX4QVGiGqs2Wy1REJJt835PFg5
✅ Preview: Canceled

[Deployment for 41d8b18 canceled]

Copy link

@thecodeboss thecodeboss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into this issue myself in an Ubuntu environment. I pulled and tested with this branch locally, and my builds are no longer failing (they were unable to resolve imports due to types being outputted to the wrong place).

This change looks solid to me, I'm not sure there is ever a case where outputPath.replace(`/${projectRoot}`, '') made any sense. Users could simply change the value of the outputPath if they didn't want the projectRoot included in it.

@thecodeboss
Copy link

Actually I did some more thinking on this, and I could see one alternative here.

Imagine I have these settings in the project.json:

{
  projectRoot: "libs/mylibrary",
  sourceRoot: "libs/mylibrary/src",
  outputPath: "dist/libs/mylibrary"
}

With this PR as it is, running nx build mylibrary would output .js and .d.ts files as follows:

dist/libs/mylibrary/src/index.js
dist/libs/mylibrary/index.d.ts

Perhaps a more logical layout might be

dist/libs/mylibrary/src/index.js
dist/libs/mylibrary/src/index.d.ts

which could be accomplished with outputPath.replace(`/${projectRoot}`, `/${sourceRoot}`).

Just some food for thought

@nartc
Copy link
Contributor Author

nartc commented Mar 21, 2022

@thecodeboss thank you for testing it. I'm not seeing the behavior you're seeing though

{
  "root": "packages/buildable-lib",
  "sourceRoot": "packages/buildable-lib/src",
  "targets": {
    "build": {
      "executor": "@nrwl/js:swc",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/packages/buildable-lib",
        "main": "packages/buildable-lib/src/index.ts",
        "tsConfig": "packages/buildable-lib/tsconfig.lib.json",
        "assets": ["packages/buildable-lib/*.md"]
      }
    },
  }
}

So with this project.json, I have:

{
   projectRoot: "packages/buildable-lib",
   outputPath: "dist/packages/buildable-lib",
   sourceRoot: "packages/buildable-lib/src"
}

and running nx build buildable-lib yields the following:

dist/packages
└── buildable-lib
    ├── README.md
    ├── package.json
    └── src
        ├── index.d.ts
        ├── index.js
        ├── index.js.map
        └── lib
            ├── buildable-lib.d.ts
            ├── buildable-lib.js
            └── buildable-lib.js.map

Can you double check the configuration for your case?

Copy link
Member

@jaysoo jaysoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you also add a check for type defs location to existing e2e tests?

@thecodeboss
Copy link

@nartc I was using an older version of nx@13.4.6 where I patched your changes onto it, so I just tested again on nx@13.9.3 and I get the expected behavior now. Sorry for the false alarm, thanks for checking!

@nartc nartc merged commit cb1fc02 into master Mar 21, 2022
FrozenPandaz pushed a commit that referenced this pull request Mar 21, 2022
* fix(js): mimic the behavior of tsc compilation for runTypeCheck

ISSUES CLOSED: #9203

* chore(js): add check for type defs files in e2e

Co-authored-by: Chau Tran <ctran@Chaus-MacBook-Pro.local>
@FrozenPandaz FrozenPandaz deleted the fix-typecheck-windows branch June 7, 2022 23:32
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2023
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.

SWC produces type definitions in the wrong folder structure
3 participants