swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.78k stars 75 forks source link

[request] Consider adding an option to ignore `files` / `includes` property of tsconfig #659

Open joshuafcole opened 2 years ago

joshuafcole commented 2 years ago

The Problem

swc-node respects the files and includes properties of tsconfig, which is normally sensible but interferes with monorepo workflows that depend on directly importing typescript files from sibling packages.

The Motivation

I've been using swc-node alongside a small HMR package I built for node as a lightning-fast alternative to ts-node-dev for the last couple months. It's made for a great development workflow, with the small exception that setup is a bit clunkier than it needs to be. Because @swc-node/register respects the files and includes properties of tsconfig, it refuses to transform TS files outside of the project directory when it encounters them. I found experimentally that removing includes and setting files to [] causes swc-node to default to a compile-everything state, which is perfect for my monorepo development flow.

Unfortunately, all of my other tooling requires those properties to be set in order to associate the tsconfig file to them.

Desired Behavior

A flag or alternate entrypoint (e.g. @swc-node/register-wildcard) to explicitly opt into the "compile every TS file I come across" behavior that automatically applies when files is set to an empty array.

Existing Workaround

Create a tsconfig.swc.json which overwrites files and invoke node via SWC_NODE_PROJECT='./tsconfig.swc.json' node -r @swc-node/register ./src/index.ts:

// tsconfig.swc.json
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "extends": "./tsconfig.json",
  "files": []
}

If you believe this feature makes sense as part of @swc-node, I'd be happy to get a PR together for you.

morgs32 commented 1 year ago

This would be lovely. @joshuafcole did you find a decent alternative? Or fork this?

Kagami commented 8 months ago

Just SWC_NODE_PROJECT= node arg1 arg2 (i.e. empty string) SWC will ignore default tsconfig.json and run everything just fine.