facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.7k stars 26.84k forks source link

Move TypeScript dependencies out of createReactApp.js #7918

Closed zachwolf closed 4 years ago

zachwolf commented 4 years ago

Is your proposal related to a problem?

The npm ecosystem has the expectation that package.json contains information for its package. Currently, when updating dependencies, it's one more thing to remember when TypeScript dependencies are maintained inside of createReactApp.js. This makes tools like npm outdated not able to find these dependencies.

Describe the solution you'd like

What has worked well for my team's project, is to add another package that can maintain and export its own dependencies. For example:

 πŸ“‚ create-react-app
  β”œ πŸ“ babel-plugin-named-asset-import
  β”œ πŸ“ babel-preset-react-app
  β”œ πŸ“ confusing-browser-globals
  β”œ πŸ“ cra-template-typescript
  β”œ πŸ“ cra-template
  β”œ πŸ“ create-react-app
  β”œ πŸ“ eslint-config-react-app
  β”œ πŸ“ react-app-polyfill
  β”œ πŸ“ react-dev-utils
  β”œ πŸ“ react-error-overlay
  β”œ πŸ“ react-scripts
+ β”” πŸ“‚ typescript-dependencies
+   β”œ πŸ“‚ index.js      # reads package.json and exports values
+   β”” πŸ“‚ package.json  # define dependencies

Then, in createReactApp.js:

if (!supportsTemplates && (template || '').includes('typescript')) {
-  allDependencies.push(
-    '@types/node',
-    '@types/react',
-    '@types/react-dom',
-    '@types/jest',
-    'typescript'
-  );
+  const typeScriptDependencies = require('typescript-dependencies')()
+  allDependencies = allDependencies.concat(typeScriptDependencies)
}

Describe alternatives you've considered

I'm missing context around create-react-app's roadmap. Forgive me if this issue is already solved with the recent and upcoming changes around how templates are maintained. I see that cra-template-typescript/template.json might have already solved the problem. However, the TypeScript dependency check is still in place in createReactApp.js.

heyimalex commented 4 years ago

I don’t understand how npm outdated can’t find the dependencies? I’m pretty sure they end up in the root package.json, not nested inside of react-scripts or anything like that.

ianschmitz commented 4 years ago

You're correct, they do @heyimalex. I'm not quite following the OP. These dependencies are controlled by the developer within their application.

zachwolf commented 4 years ago

Ahh, sorry, let me clarify.

When running npm outdated inside of create-react-app's monorepo, the dependencies are not discoverable. E.g.:

$ cd create-react-app
$ lerna exec npm outdated

I'm using npm outdated only an example. My intention isn't to focus on that functionality specifically.

My end goal is for CRA contributors to be able to use the tools built for the JavaScript ecosystem.

zachwolf commented 4 years ago

No longer an issue with 3.3.0 πŸ€