Open ricko-th opened 1 year ago
Not to be "that guy" but it works for me even without SWCRC=true
.
$ cat .swcrc
{
"env": { "debug": true }
}
This causes a whole bunch of extra debug to be printed when I run with SWCRC=1
(& technically the docs say SWCRC=true
I think but both work for me).
Oh interesting. But it doesn't work if I'm using @swc-node/register/esm
as the -r
flag. So I wonder if you're in a similar code path.
Aren't you supposed to use --loader
instead of -r
for @swc-node/register/esm
?
Overview
There does not seem to be a way to run something along the lines of this, and have it pick up the
.swcrc
file:Even the suggested
SWCRC
environment variable doesn't work:Configuration
Create a simple project which uses decorators, which are not enabled by default in swc. (There's nothing special about decorators, just that they are something which requires enabling explicitly in the config.)
.swcrc
Note decorators are enabled here.
package.json
Note that this includes ts-node as a way to show the expected behavior.
tsconfig.json
src/cached.ts
The decorator implementation — a really simple memoizer. Again, the details here don't actually matter, but I wanted something working.
src/color.ts
This is where the problems will happen, as it's where the decorator is used.
src/test.ts
The script which will actually be run.
Steps to reproduce
Run:
npm run swc-cli
. Note that it compiles just fine:Temporarily rename
.swcrc
to something else and retry that previous step. Note the expected failure, as swc doesn't like decorators but can no longer see the config:Rename the config file back to
.swcrc
and ensure the cli can compile successfully again.Run
npm run ts-node
. Note that it runs just fine:Run
npm run swc-node
. Note that it fails with the above error. (This is poor developer experience, based on how swc-cli picks up the config correctly, but y'all do you.)Run
npm run swc-node:withConfig
, which uses the documentedSWCRC
environment variable. Note that it still fails.Expected behavior
Personally, I'd prefer if register did the intuitive thing and picked up the
.swcrc
file. Barring that, I'd be happy if theSWCRC
environment variable worked as documented. That's a bit awful, as it means all my scripts which look likenode -r @swc-node/register ...
will now needSWCRC=1
prefixed to them ... but that's not the end of the world.Or, if there is some other way to make register see the
.swcrc
, I'm all ears.