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

Various fixes to TypeScript integration #431

Merged
merged 4 commits into from Feb 25, 2020
Merged

Various fixes to TypeScript integration #431

merged 4 commits into from Feb 25, 2020

Conversation

pvdlg
Copy link
Contributor

@pvdlg pvdlg commented Feb 24, 2020

Fix an issues introduced in #426

The key used to cache and group config wasn't working properly and had ts always be undefined, preventing to split JS and TS files in two groups.

As we were generating the temporary tsconfig.json with a different name every run the ESLint cache wasn't working properly has it would determine the config changed in between runs (due to parserOptions.project) being different.
We now generate those files in the XO cache with a consistent name, so in each run, the same set of files/tsconfig.json would result in the same temporary tsconfig.json file name.

Finally this solve a very rare case with a project with multiple XO configs. In such case were generating one temporary tsconfig.json per XO config. We now correctly generate temporary tsconfig per original one (and just one if the project doesn't have a tsconfig).
That would have created a situation were @typescript-eslint/eslint-plugin would have been unaware of the TS files that are not part of the currently linted group.

Important for the release note:
After updating XO to a version with this fix, users will need to delete the current XO cache:

$ rm node_modules/.cache/xo

That's because now node_modules/.cache/xo should be a directory instead of a file so we can save both the ESLint cache and the temporary tsconfig.json.

@pvdlg pvdlg changed the title Correctly geenerrate the config cache key Correctly generrate the config cache key Feb 24, 2020
@pvdlg pvdlg changed the title Correctly generrate the config cache key Various fixes to TypeScript integration Feb 25, 2020
lib/options-manager.js Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Member

I encountered an issue with the new TS integration. Clone this branch: https://github.com/sindresorhus/emittery/tree/upgrade-xo And npm install && npm test, and you'll get this error:

Error: Failed to load parser '/Users/sindresorhus/dev/oss/emittery/node_modules/@typescript-eslint/parser/dist/parser.js' declared in 'BaseConfig': Cannot find module 'typescript'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/sindresorhus/dev/oss/emittery/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:20:25)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm ERR! Test failed.  See above for more details.

@pvdlg
Copy link
Contributor Author

pvdlg commented Feb 25, 2020

You need typescript in your project dependencies to be able to lint either .ts or .d.ts files.

I didn't add typescript as a dependency of XO because we don't want to install it for users that don't use typescript nor force a specific version to used.

I didn't think of the case of a project that doesn't have it in it's dependencies. Maybe I can add that to the readme.

@sindresorhus
Copy link
Member

XO is all about convenience though. I don't really want to install typescript manually in every JS project that has a d.ts (which is most of my JS projects these days). Couldn't we add it with a loose semver range? Then the user could specify their own more specific range if needed and it would be deduplicated to that. It could be "typescript": "^3.0.0".

@pvdlg
Copy link
Contributor Author

pvdlg commented Feb 25, 2020

See PR #434

That would mean every XO user issue will download typescript on npm install even if they don't use it. Personally I don't mind, disk space is cheap.

@fregante
Copy link
Member

fregante commented Feb 28, 2020

Are @typescript-eslint/parser and @typescript-eslint/eslint-plugin still required as additional dependencies? I'm trying on Refined GitHub and it's complaining

❯ xo --fix
Error: Failed to load plugin '@typescript-eslint' declared in 'BaseConfig » eslint-config-xo-typescript': Cannot find module '@typescript-eslint/eslint-plugin'
Require stack:
- ./__placeholder__.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.resolve (internal/modules/cjs/helpers.js:80:19)
    at Object.resolve (./node_modules/eslint/lib/shared/relative-module-resolver.js:44:50)
    at ConfigArrayFactory._loadPlugin (./node_modules/eslint/lib/cli-engine/config-array-factory.js:959:39)
    at ./node_modules/eslint/lib/cli-engine/config-array-factory.js:848:33
    at Array.reduce (<anonymous>)
    at ConfigArrayFactory._loadPlugins (./node_modules/eslint/lib/cli-engine/config-array-factory.js:844:22)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (./node_modules/eslint/lib/cli-engine/config-array-factory.js:667:32)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (./node_modules/eslint/lib/cli-engine/config-array-factory.js:596:20)

@pvdlg
Copy link
Contributor Author

pvdlg commented Feb 28, 2020

Try rm -rf node_modules && rm package-lock.json && npm install

@fregante
Copy link
Member

The usual then.

@sindresorhus
Copy link
Member

@pvdlg This change turned out to be really annoying because of Travis caching. Every time I upgrade XO, it will fail, and I have to manually clear Travis cache and then rerun.

How about we change the cache directory .xo-cache/ => .xo-cache2/ just for now, and sometime in the future we can change it back?

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.

None yet

3 participants