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

Allow arbitrary Sucrase configuration in sucrase/register and the CLI #792

Closed
alangpierce opened this issue Apr 1, 2023 · 1 comment · Fixed by #813
Closed

Allow arbitrary Sucrase configuration in sucrase/register and the CLI #792

alangpierce opened this issue Apr 1, 2023 · 1 comment · Fixed by #813

Comments

@alangpierce
Copy link
Owner

The original hope of this project was to keep configuration so minimal and opinionated that config is only needed for advanced use cases where you'd already be invoking Sucrase directly from JS. Unfortunately, JSX and Node ESM have both moved in a direction that make configuration more necessary, so it's harder to keep a zero-config mindset, so this issue tracks:

  • A mechanism for specifying config when using sucrase/register.
  • Catching up on CLI config options, and also adding a mechanism to specify JSON config when using the CLI.

I'm still hoping to avoid the need for a config file and the complexity that that entails, at least for now.

Some of the need for config could be avoided via a semver-major release with better defaults (e.g. disableESTransforms on by default), though with a major release also comes the need to configure the system for the old behavior, so I think a more accessible system is probably necessary regardless.

Current plan:

  • When using sucrase/register or sucrase-node, a SUCRASE_OPTIONS environment variable can hold a JSON value setting any options that are merged in before transform.
  • When using the sucrase CLI, the missing CLI options should be added as direct flags (e.g. Add cli option --disable-es-transforms #670 , plus the other new ones since then), and there should also be an --options-json option to specify the options as JSON.
alangpierce added a commit that referenced this issue Jul 18, 2023
Supersedes #670
Progress toward #792

This PR adds to the CLI a number of options that had been added. The CLI could
still use some work in terms of error reporting and behavior, but this should
hopefully get it closer to parity with other use cases.

The CLI previously had no tests, so this also adds an integration test suite
exercising each new and existing Sucrase option (though it's not yet at full
coverage).
alangpierce added a commit that referenced this issue Jul 18, 2023
Supersedes #670
Progress toward #792

This PR adds to the CLI a number of options that had been added. The CLI could
still use some work in terms of error reporting and behavior, but this should
hopefully get it closer to parity with other use cases.

The CLI previously had no tests, so this also adds an integration test suite
exercising each new and existing Sucrase option (though it's not yet at full
coverage).
alangpierce added a commit that referenced this issue Jul 18, 2023
Fixes #792

This PR adds a new environment variable SUCRASE_OPTIONS that works with the
require hook and other tools that are based on the require hook (`sucrase-node`
and programmatically registering a hook). Its format is simply a JSON string
that is parsed and merged with the usual options. Hopefully this will be rare,
especially after a semver-major change to better defaults, but it's important
for some cases.
alangpierce added a commit that referenced this issue Jul 19, 2023
Fixes #792

This PR adds a new environment variable SUCRASE_OPTIONS that works with the
require hook and other tools that are based on the require hook (`sucrase-node`
and programmatically registering a hook). Its format is simply a JSON string
that is parsed and merged with the usual options. Hopefully this will be rare,
especially after a semver-major change to better defaults, but it's important
for some cases.
@alangpierce
Copy link
Owner Author

Implemented via the two above PRs. I was originally planning to have a --options-json=... CLI option, but decided against it for now, mostly because my hope is that people would only use one or two options anyway and it felt pretty clunky from a usage standpoint. It certainly could be added later if there's demand, though.

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 a pull request may close this issue.

1 participant