Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move 3rd party types to dev dependencies in CLI NPM package #3425

Merged
merged 29 commits into from
Mar 5, 2019

Conversation

bahmutov
Copy link
Contributor

@bahmutov bahmutov commented Feb 11, 2019

@bahmutov
Copy link
Contributor Author

@tgriesser can you take a look at the typescript changes - read the issue for motivation, trying to prevent type clashes between our bundled types and users' (like Lodash)

@NicholasBoll if you can take a quick look, we would appreciate it. Chai and jQuery are weird types since they are global and I had to delete node_modules/@types/chai/index.d.ts and node_modules/@types/jquery/index.d.ts to get dtslint to pass

@tgriesser
Copy link
Member

This makes sense that we'd want to avoid including types that would conflict with users' installed types.

I'm wondering if there's any tooling that exists already that will solve this problem more generally for us, by effectively bundling them inline when they're imported so we have one (or two) big d.ts files which handles the namespacing, etc.

https://github.com/timocov/dts-bundle-generator
https://github.com/SitePen/dts-generator
https://github.com/TypeStrong/dts-bundle

I might play around with this because I've been wanting to solve this problem for knex as well, as it currently has @types/bluebird as a dependency for similar reasons as Cypress.

But generally I think the approach here makes sense, without getting it running i'm not sure if there's any issues with it.

@bahmutov bahmutov changed the title wip: move lodash types to dev dependencies move lodash types to dev dependencies Feb 12, 2019
@bahmutov
Copy link
Contributor Author

@tgriesser I have looked at the TS bundle generators, they would need to tested well, since all require extensive configuration, and I have never used them. For now I think copying dependencies would do, and I will open a separate issue to find and use TS bundler.

@bahmutov bahmutov changed the title move lodash types to dev dependencies move 3rd party types to dev dependencies in CLI NPM package Feb 15, 2019
@NicholasBoll
Copy link
Contributor

At first I thought this was a terrible idea, but now I like it. The problem is around global definitions (namespaces) that collide. I looked into jQuery type definitions and chai type definitions. It looks like jQuery breaks up namespacing into different files, but chai looks like its namespace is in the same file. Does deleting it cause type errors where the chai type is not found?

Do you want me to try out these changes to verify it will work externally?

@bahmutov
Copy link
Contributor Author

bahmutov commented Mar 1, 2019

ughh, typescript@next does not like this change at all

Installing to /root/.dts/typescript-installs/next...
Installed!
Error: /root/cypress/cli/types/cy-chai.d.ts:3:22
ERROR: 3:22      expect  TypeScript@next compile error: 
File '/root/cypress/cli/types/chai/index.d.ts' not found.
ERROR: 9:28      expect  TypeScript@next compile error: 
Cannot find name 'chai'.
ERROR: 10:30     expect  TypeScript@next compile error: 
Cannot find name 'chai'.
ERROR: 11:30     expect  TypeScript@next compile error: 
Cannot find name 'chai'.

/root/cypress/cli/types/index.d.ts:19:22
ERROR: 19:22     expect  TypeScript@next compile error: 
File '/root/cypress/cli/types/jquery/index.d.ts' not found.
ERROR: 82:8      expect  TypeScript@next compile error: 
Cannot find name 'JQueryStatic'.
ERROR: 274:25    expect  TypeScript@next compile error: 
Cannot find name 'JQuery'.

and so on in https://circleci.com/gh/cypress-io/cypress/75061

@bahmutov
Copy link
Contributor Author

bahmutov commented Mar 4, 2019

Testing build NPM package

$ npm i https://cdn.cypress.io/beta/npm/3.1.6/circle-move-ts-types-to-dev-dependencies-3371-02202412002cfd0541cae6096fc614863750795d-76512/cypress.tgz --ignore-scripts

against kitchensink still has a problem

$ npm run types

> cypress-example-kitchensink@0.0.0-development types /Users/gleb/git/cypress-example-kitchensink
> tsc --noEmit

node_modules/cypress/types/cy-minimatch.d.ts:5:28 - error TS7016: Could not find a declaration file for module 'minimatch'. '/Users/gleb/git/cypress-example-kitchensink/node_modules/minimatch/minimatch.js' implicitly has an 'any' type.
  Try `npm install @types/minimatch` if it exists or add a new declaration (.d.ts) file containing `declare module 'minimatch';`

5 import * as mimimatch from 'minimatch'
                             ~~~~~~~~~~~

node_modules/cypress/types/sinon-chai/index.d.ts:12:24 - error TS2307: Cannot find module 'sinon'.

12 import * as Sinon from 'sinon';

@bahmutov
Copy link
Contributor Author

bahmutov commented Mar 4, 2019

I think the TS problems have been solved, all 3rd party deps use relative paths, tested against types in Kitchensink and TodoMVC, both are happy with new types

@bahmutov bahmutov requested a review from brian-mann March 4, 2019 22:08
@bahmutov bahmutov merged commit f81dc7a into develop Mar 5, 2019
@@ -754,6 +763,7 @@ linux-workflow: &linux-workflow
branches:
only:
- develop
- move-ts-types-to-dev-dependencies-3371
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be deleted

@avahe-kellenberger
Copy link

Is this supposed to solve cypress installed @types/ packages? It's still installing @types/chai-jquery for me, currently.

I also saw post-install.js which seemed like it would take care of it, but yarn install cypress -D is still installing chai-jquery under types.

kuceb pushed a commit to kuceb/cypress that referenced this pull request Apr 23, 2019
…io#3425)

* wip: move lodash types to dev dependencies

* move blob-util types

* move types for minimatch

* do not lint types from minimatch

* move types sinon to dev dependencies

* move sinon-chai types to dev dependencies

* update tslint

* move types bluebird to dev dependencies

* move mocha types

* move jquery types to dev dependencies

* rename moment local wrapper

* move chai and chai-jquery

* refactor code for building CLI and dealing with folders

* linting

* include types subfolders

* replace types with relative paths

* transform sinon path to relative

* linting

* do not delete d.ts files

* linting

* chore: build npm package from this branch

* add minimatch relative reference

* work around minimatch

* set sinon to be relative load

* add readme to CLI

* linting readme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move all @types CLI dependencies from prod to dev list
6 participants