jaredpalmer / tsdx

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

How to specify typescript version? #852

Closed wizardnet972 closed 4 years ago

wizardnet972 commented 4 years ago
npx tsdx create mylib

this command creates mylib with the lastest of typescript package (v4).

but I want to change to typescript: "^3.9.3".

Is there a way to configure this? like a config file such as:

{
 "typescript": "^3.9.3"
}

if not supplier config the default is latest.

@agilgur5

agilgur5 commented 4 years ago

Yes, TSDX uses whatever version of TS is in your node_modules. So if you change your package.json to use 3.9, it'll use 3.9 (once you've npm install'd that version).

wizardnet972 commented 4 years ago

@agilgur5 not sure what you mean. I mean the package.json who generated from create action has typescript dependency of v4.

Lets say I create a folder foo. then in foo I run the create command. its create a package json inside I have typescript with version of 4.

In the source code you do: npm i typescript as part of the basic template.

so how tsdx uses another version of typescript if the node_modules doen't exist yet?

I can send a PR -> create read config file (if exist) and merge (using lodash) the dependencies list with whatever write in the config file. the config file will have something like that:

module.exports = {
 packageJson: {
  dependencies: ['typescript@3.9.3']
 }
}

I just say let me decided what version I want to install in those dependencies. because sometimes I use monorepo with one version and otherwise it will mess up my repo.

agilgur5 commented 4 years ago

so how tsdx uses another version of typescript if the node_modules doen't exist yet?

You can do:

npx tsdx create mylib
cd mylib
npm i typescript@3

In the source code you do: npm i typescript as part of the basic template.

You can also use patch-package to change this to typescript@3 if that's what you want.

I can send a PR -> create read config file (if exist) and merge (using lodash) the dependencies list with whatever write in the config file. [...] I just say let me decided what version I want to install in those dependencies. because sometimes I use monorepo with one version and otherwise it will mess up my repo.

No I think this is out of scope and too large of a request, it increases the API surface and maintenance burden therein tremendously for little value. We can't accept every request and that creates sprawl; meanwhile TSDX's mission is enabling zero-config as much as possible.

If you want to use different versions of dependencies and customize your templates heavily, you don't have to use tsdx create, can use your own templates, and are more than welcome to do so. These templates should really be seen as starter templates that you can base your own opinions and templates off of, they cannot by nature be all inclusive of everyone's wants and needs and opinions. As an example, I use TSDX plenty but personally do not use the templates

See also #441 and related PRs, which invert your ask but still introduce a new API