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

Take "target" from base tsconfig when present #55

Closed
wants to merge 1 commit into from

Conversation

timovv
Copy link
Contributor

@timovv timovv commented Mar 21, 2024

Following up on #54 with the suggested fix. It works for us when we try to build in our Azure SDK repo, but unsure if it would cause issues for folks who have their own tsconfig.json with target unset and are relying on tshy to set the target?

@isaacs
Copy link
Owner

isaacs commented Mar 21, 2024

Hm, yeah, the upgrade story here is a little bit concerning, and it seems like a small thing to do a semver major bump for (though that's not out of the question, of course). Maybe we could have tshy check to see if target is set in a pre-existing tsconfig.json, and add to .tshy/build.json if it's missing?

@mpodwysocki
Copy link

@isaacs I agree that we should keep it as ES2022 or whatever default we have now if it is not present in the base tsconfig. @timovv Thoughts?

@mpodwysocki
Copy link

@isaacs one way we could also do it not to break people is to have it opt in like other configuration items like selfLink and other options.

@timovv
Copy link
Contributor Author

timovv commented Mar 22, 2024

I don't have a strong opinion here, other than that I agree it seems like a small thing to do a breaking change for. Out of the options, I lean towards setting the target only if it's not set in the tsconfig -- I think that's the most intuitive behavior we'd be able to get without breaking. Let me have a go at implementing that.

Otherwise if going with an extra configuration option for this I would say let's just have the option be "target", defaulting to es2022, and continue to ignore the tsconfig field entirely as we do today.

@timovv timovv force-pushed the remove-target-from-build-json branch from b852694 to 79ae570 Compare March 22, 2024 19:03
@timovv timovv changed the title Remove "target" from build.json Take "target" from base tsconfig when present Mar 22, 2024
@timovv
Copy link
Contributor Author

timovv commented Mar 22, 2024

OK, I have changed this so the behavior is:

  • If target is specified in the base tsconfig.json (this includes the recommended config if it is created), then build.json doesn't specify a target.
  • Otherwise, target es2022 is added to the build.json

@@ -116,7 +116,6 @@ Object {
"module": "nodenext",
"moduleResolution": "nodenext",
"rootDir": "../src",
"target": "es2022",

Choose a reason for hiding this comment

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

Should we have tests for whether we preserve the target and when we don't?

Copy link
Contributor Author

@timovv timovv Mar 22, 2024

Choose a reason for hiding this comment

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

The existing test case actually covers that case already, since it

  • Generates everything from scratch, including the recommended tsconfig.json (which sets target to es2022)
  • Then it makes a snapshot -- this is the snapshot you're commenting on, and the target field is no longer present, as expected with the new behavior
  • Then the tsconfig.json is overwritten with a custom configuration, which omits the target field
  • Finally it takes another snapshot, which is there is no diff for since target is still being set to es2022 as it used to be

@timovv timovv force-pushed the remove-target-from-build-json branch from 79ae570 to c887959 Compare March 22, 2024 20:41
target:
readTypescriptConfig().options.target === undefined
? 'es2022'
: undefined,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
: undefined,
target: readTypeScriptConfig().options.target ?? 'es2022'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we're doing here is subtly different from that:

  • if the target is undefined in the tsconfig.json, then we set es2022
  • if the target is defined, then we don't set it at all, so that it inherits from the base tsconfig.

With your suggestion we are instead setting the target in build.json to be the same as in the base tsconfig -- we could do that, but then we'd need to pull in a bit more logic from TS to stringify the value again (the parsed value is actually a ScriptTarget, which TS defines as a numeric enum).

Copy link
Owner

Choose a reason for hiding this comment

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

Oic, that makes sense. Thanks for the clarification.

@isaacs
Copy link
Owner

isaacs commented Mar 22, 2024

This looks great. Minor style nit, I can get to it if you don't before it lands. Thanks!

@timovv
Copy link
Contributor Author

timovv commented Mar 28, 2024

@isaacs: just wanted to check if there's anything outstanding we can help with to get this in? We have some customers waiting on the fix, we're happy to vendor it in the interim if need be to unblock them but would be great to see this upstream :)

@isaacs isaacs force-pushed the remove-target-from-build-json branch from c887959 to 1b4b73a Compare March 28, 2024 21:17
@isaacs isaacs closed this in 1b4b73a Mar 28, 2024
timovv added a commit to Azure/azure-sdk-for-js that referenced this pull request Mar 28, 2024
### Packages impacted by this PR

- Core packages using ESM migration

### Issues associated with this PR

- #28940
- #28918

### Describe the problem that is addressed by this PR

Upgrade to new version of `tshy` which does not force `target` to
`ES2022` (see [PR](isaacs/tshy#55)). This should
resolve some issues for people whose environments do not support newer
syntax (e.g. Node 14 and the Webpack 4 bundler).
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.

None yet

3 participants