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): .swcrc path option should follow existing conventions #10127

Merged
merged 7 commits into from May 6, 2022
Merged

fix(js): .swcrc path option should follow existing conventions #10127

merged 7 commits into from May 6, 2022

Conversation

djgrant
Copy link
Contributor

@djgrant djgrant commented May 4, 2022

Current Behavior

While testing #10118 locally, I noticed a couple of potential issues that should perhaps be addressed before release:

  • swcrcPath is not named consistently with other options e.g. tsConfig, packageJson
  • swcrcPath is resolved relative to the project roots, whereas tsConfig and packageJson are resolved relative to the workspace root

Expected Behavior

The implementation follows the same approach as the main option – the option is resolved relative to the project path if the project path is not in the string.

Update: swcrc path is alway resolved relative to the workspace root.

{
  "targets": {
    "build": {
      "executor": "@nrwl/js:swc",
      "options": {
         // path relative to project root",
-        "swcrcPath": "config/swcrc.json"
         // path relative to workspace root (consistent with `tsConfig` and `packageJson`
+        "swcrc": "/packages/my-package/config/swcrc.json",
      }
    }
  }
}

The reason for following this implentation is that the default value defined in schema.json is static so cannot include the relative project path (unless we introduce some kind of string replacement e.g. $projectRoot/.lib.swcrc). This is not an issue withtsConfig and packageJson as they are required options.

Related Issue(s)

#10058

@nx-cloud
Copy link

nx-cloud bot commented May 4, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 9c20834. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 12 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented May 4, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
nx-dev ⬜️ Ignored (Inspect) May 6, 2022 at 4:08PM (UTC)

@djgrant
Copy link
Contributor Author

djgrant commented May 4, 2022

@AgentEnder, I noticed a couple of issues with #10118, which I've PRd a fix for here. I don't think this is the right solution because the behaviour is now unpredictable (i.e. it looks like you can provide a path relative to the workspace root, but it always resolves ot the package root) but wanted to put something out there to get the ball rolling.

If having a default value in schema.json is a fixed constraint could we do one of the following:

  • support string substitution e.g. "default": "$projectRoot/.lib.swcrc"
  • support a default flag e.g. "default": true, and define the default value in swc.impl.ts

I appreciate there are different types of misdirection from each of these solutions.

@AgentEnder
Copy link
Member

@djgrant, I see where you are coming from on this, and it's probably a good thing to standardize them. We are looking at supporting the <projectRoot> token in paths set inside project.json, but we don't have that to use just yet.

I'd recommend holding off on string replacement for that reason.

Additionally, this has already been released as of this morning since 14.1.0 was pushed out. We can still change this, but it'll require a migration now in case anyone has already taken it up. If you feel comfortable writing a migration, here's how I'd imagine the implementation:

  • swcrc is an optional property in schema.json and schema.d.ts
  • schema.json includes a description for the swcrc property that includes the default value, despite it not having an actual default set.
  • If options.swcrc is null, fall back on default value inside the implementation file
  • Migrator setup to run on version 14.1.1-beta.0
    • set options.swcrc if options.swcrcPath exists, should be joinPathFragments(project.root, options.swcrcPath)
    • should use forEachExecutorOptions

BREAKING CHANGE:
swcrcPath –> swcrc
BREAKING CHANGE:
swcrcPath –> swcrc
As the default needs to be defined in swc.impl.ts to resolve relative to the project root, the
default is documented in the schema.json description.
As the default needs to be defined in swc.impl.ts to resolve relative to the project root,
the
default is documented in the schema.json description.
@djgrant
Copy link
Contributor Author

djgrant commented May 6, 2022

@AgentEnder thanks for the guidance on this. I've had a crack at it and tested locally. Let me know if there's anything I've missed.

Copy link
Member

@AgentEnder AgentEnder left a comment

Choose a reason for hiding this comment

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

This looks good, do you care to update the migration version and we can get it merged?

},
"update-swcrc-path": {
"cli": "nx",
"version": "14.1.1-beta.0",
Copy link
Member

Choose a reason for hiding this comment

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

14.1.1 has been released already, can you bump this to 14.1.5-beta.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

@AgentEnder AgentEnder self-requested a review May 6, 2022 16:21
@AgentEnder AgentEnder merged commit 63006b7 into nrwl:master May 6, 2022
@djgrant djgrant deleted the fix/js/swcrc-path-resolution branch May 6, 2022 18:05
@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.

None yet

2 participants