jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.28k stars 507 forks source link

[Question] How to use a TS file as NPM script? #704

Closed jneuendorf closed 4 years ago

jneuendorf commented 4 years ago

Hi,

I am fairly new to TypeScript and use NPM scripts for creating cache file or generating some code. Currently I have to use JS files for that because I couldn't find a way to use .ts files instead and get them transpiled correctly.

My code lives in /src and I want to have the scripts in a /script directory and there are even output files in /lib/script/ but they are empty.

My goal is being able to run something like node lib/script/myscript.js.

I guess my tsconfig.json is not correctly set up for this...

{
    "compileOnSave": true,
    "compilerOptions": {
        "baseUrl": "./",
        "declaration": true,
        "esModuleInterop": true,
        "importHelpers": true,
        "lib": ["esnext"],
        "module": "esnext",
        "moduleResolution": "node",
        "noFallthroughCasesInSwitch": true,
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "outDir": "./lib",
        "paths": {
            "*": ["src/*", "script/*", "node_modules/*"]
        },
        "preserveConstEnums": true,
        "removeComments": true,
        "resolveJsonModule": true,
        "rootDir": "./src",
        "sourceMap": true,
        "strict": true,
        "target": "es2015",
    },
    "exclude": [
        "node_modules"
    ]
}

This config is the result of some patchwor: I started without tsdx and a manually created config and later tried to include parts of tsdx's config. So I am not sure how and whether baseUrl, paths, rootDir, outDir and exclude play together. 😕

For more details on the actual code, see my repo theycanuse.

agilgur5 commented 4 years ago

Sorry this isn't a support forum, we don't have the resources to help with everyone's TS (I am an unpaid volunteer solo maintaining right now). This also isn't related to TSDX, TSDX is for bundling code for libraries, not running scripts -- you probably want to use ts-node or something for running scripts or just plain tsc.

On your specific options: your exclude is redundant, it's less than the default exclude. baseUrl and paths are just for writing imports differently per platform (TSDX doesn't really support them, tsc won't actually rewrite them), outDir isn't supported by TSDX. Please look at the tsconfig reference if you're not sure how these options work.

jneuendorf commented 4 years ago

@agilgur5 Thanks for the quick and helpful reply! I will check out your hints.

The reason I asked here was that I couldn't find any information on where to ask and StackOverflow has no tsdx tag so I figured the chances for an answers would be bad. Is there an official channel for discussions for the community?

agilgur5 commented 4 years ago

Regular issues are fine for discussions, several are tagged as such. We also have RFCs, but historically those haven't had much response even if they're in direct response to a pattern of user needs 😕

I think you're asking about Q&A, not discussions.

I've thought about starting a gitter or Slack, but:

  1. I don't have enough time as is, so either I spend less time on actually maintaining and improving to respond there, or don't respond at all
  2. Without more maintainers or moderators, your chances wouldn't be high there anyway. I'm part of some community Slacks that are basically wastelands, and that's demotivating and misleading for all parties
  3. Chat-style options don't preserve Q&A well, things get lost in a waterfall view, can't be moderated, and aren't that searchable -- they're not built for that.

There's another option that is forum-style, which is more searchable and can be moderated to an extent, but:

  1. Has the same issue on time
  2. Has the same issue that chances wouldn't be high

At least on StackOverflow, you know what you're getting yourself into, there aren't false expectations of a high chance of response like an "official" chat or forum. There's also some form of "reward" to it, but:

  1. It isn't nearly as moderatable as an official forum. At least not by me or other official maintainers/moderators of the library, only by people with very high scores. Also has historically been quite toxic and gamed a lot.
  2. Creating a tag is a privilege

So I don't see that any of those options really solve this problem well, and each of those, including using issues, create more of a support burden, either explicitly or implicitly (e.g. me wanting those avenues to have accurate, up-to-date information). There have only been a handful of core contributors to TSDX in its lifetime to handle that.

Also, as I said above, your question is not really a TSDX question anyway, but a more general TypeScript question.

agilgur5 commented 4 years ago

There is now a TSDX tag on StackOverflow and also GitHub Discussions have been opened for forum-style Q&A.