From 8c581c7e5259b3a5363c65c8c959bb36d05f2b43 Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Mon, 16 Mar 2020 15:23:54 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"feat(gatsby-plugin-typescript):=20Sup?= =?UTF-8?q?ports=20linting=20(#187=E2=80=A6=20(#22308)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "fix(gatsby-plugin-typescript): Broader webpack support (#22003)" This reverts commit 4b9382663771b8e9bbe7e84179547ff369832212. * Revert "feat(gatsby-plugin-typescript): Supports linting (#18721)" This reverts commit d28a0bdab49f323cb37cde2a51e4fec8ba3e6d50. --- packages/gatsby-plugin-typescript/README.md | 6 - .../gatsby-plugin-typescript/package.json | 8 +- .../src/__tests__/gatsby-node.js | 165 +----------------- .../src/gatsby-node.js | 44 +---- 4 files changed, 4 insertions(+), 219 deletions(-) diff --git a/packages/gatsby-plugin-typescript/README.md b/packages/gatsby-plugin-typescript/README.md index 60c05d7dcd1fc..622c21848e44a 100644 --- a/packages/gatsby-plugin-typescript/README.md +++ b/packages/gatsby-plugin-typescript/README.md @@ -77,9 +77,3 @@ Visual Studio Code is very good in this regard. In addition, you can see the instructions in [TypeScript-Babel-Starter](https://github.com/Microsoft/TypeScript-Babel-Starter) for setting up a `type-check` task. - -## ESLint - -This plugin supports linting TSX with [typescript-eslint](https://typescript-eslint.io) using [Gatsby's default ESLint config](https://www.gatsbyjs.org/docs/eslint/). To enable linting TSX, install `typescript`. - -`npm install typescript` diff --git a/packages/gatsby-plugin-typescript/package.json b/packages/gatsby-plugin-typescript/package.json index 0b607b29eb25b..e938341170db6 100644 --- a/packages/gatsby-plugin-typescript/package.json +++ b/packages/gatsby-plugin-typescript/package.json @@ -33,13 +33,7 @@ "license": "MIT", "main": "index.js", "peerDependencies": { - "gatsby": "^2.0.0", - "typescript": "^3.2.1" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "gatsby": "^2.0.0" }, "repository": { "type": "git", diff --git a/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js index 4f31701a182ac..46426487607c3 100644 --- a/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js @@ -49,65 +49,7 @@ describe(`gatsby-plugin-typescript`, () => { const actions = { setWebpackConfig: jest.fn() } const jsLoader = {} const loaders = { js: jest.fn(() => jsLoader) } - const stage = `develop` - const eslintLoader = { loader: `eslint-loader` } - const webpackConfig = { - module: { - rules: [ - { - enforce: `pre`, - test: /\.jsx?$/, - exclude: /(node_modules|bower_components)/, - use: [eslintLoader], - }, - ], - }, - } - const getConfig = jest.fn(() => webpackConfig) - onCreateWebpackConfig({ actions, getConfig, loaders, stage }) - expect(actions.setWebpackConfig).toHaveBeenCalledWith({ - module: { - rules: [ - { - test: /\.tsx?$/, - use: jsLoader, - }, - ], - }, - }) - expect(actions.setWebpackConfig).toHaveBeenCalledWith({ - module: { - rules: [ - { - enforce: `pre`, - test: /\.tsx?$/, - exclude: /(node_modules|bower_components)/, - use: [eslintLoader], - }, - ], - }, - }) - }) - - it(`sets the correct webpack config with rule.loader shortcut`, () => { - const actions = { setWebpackConfig: jest.fn() } - const jsLoader = {} - const loaders = { js: jest.fn(() => jsLoader) } - const stage = `develop` - const webpackConfig = { - module: { - rules: [ - { - enforce: `pre`, - test: /\.jsx?$/, - exclude: /(node_modules|bower_components)/, - loader: `eslint-loader`, - }, - ], - }, - } - const getConfig = jest.fn(() => webpackConfig) - onCreateWebpackConfig({ actions, getConfig, loaders, stage }) + onCreateWebpackConfig({ actions, loaders }) expect(actions.setWebpackConfig).toHaveBeenCalledWith({ module: { rules: [ @@ -118,116 +60,13 @@ describe(`gatsby-plugin-typescript`, () => { ], }, }) - expect(actions.setWebpackConfig).toHaveBeenCalledWith({ - module: { - rules: [ - { - enforce: `pre`, - test: /\.tsx?$/, - exclude: /(node_modules|bower_components)/, - loader: `eslint-loader`, - }, - ], - }, - }) }) it(`does not set the webpack config if there isn't a js loader`, () => { const actions = { setWebpackConfig: jest.fn() } const loaders = { js: jest.fn() } - const stage = `develop` - const getConfig = jest.fn() - onCreateWebpackConfig({ actions, getConfig, loaders, stage }) + onCreateWebpackConfig({ actions, loaders }) expect(actions.setWebpackConfig).not.toHaveBeenCalled() }) - - it(`does not set the typescript-eslint webpack config if the built-in eslint-loader isn't set`, () => { - const actions = { setWebpackConfig: jest.fn() } - const jsLoader = {} - const loaders = { - js: jest.fn(() => jsLoader), - } - const stage = `develop` - const webpackConfig = { - module: { - rules: [ - { - enforce: `pre`, - test: /\.jsx?$/, - exclude: /(node_modules|bower_components)/, - use: [], - }, - ], - }, - } - const getConfig = jest.fn(() => webpackConfig) - onCreateWebpackConfig({ actions, getConfig, loaders, stage }) - expect(actions.setWebpackConfig).toHaveBeenCalledWith({ - module: { - rules: [ - { - test: /\.tsx?$/, - use: jsLoader, - }, - ], - }, - }) - expect(actions.setWebpackConfig).not.toHaveBeenCalledWith({ - module: { - rules: [ - { - enforce: `pre`, - test: /\.tsx?$/, - exclude: /(node_modules|bower_components)/, - use: [], - }, - ], - }, - }) - }) - - it(`set the typescript-eslint webpack config only if in develop stage`, () => { - const actions = { setWebpackConfig: jest.fn() } - const jsLoader = {} - const loaders = { js: jest.fn(() => jsLoader) } - const stage = `build-html` - const eslintLoader = { loader: `eslint-loader` } - const webpackConfig = { - module: { - rules: [ - { - enforce: `pre`, - test: /\.jsx?$/, - exclude: /(node_modules|bower_components)/, - use: [eslintLoader], - }, - ], - }, - } - const getConfig = jest.fn(() => webpackConfig) - onCreateWebpackConfig({ actions, getConfig, loaders, stage }) - expect(actions.setWebpackConfig).toHaveBeenCalledWith({ - module: { - rules: [ - { - test: /\.tsx?$/, - use: jsLoader, - }, - ], - }, - }) - expect(actions.setWebpackConfig).not.toHaveBeenCalledWith({ - module: { - rules: [ - { - enforce: `pre`, - test: /\.tsx?$/, - exclude: /(node_modules|bower_components)/, - use: [eslintLoader], - }, - ], - }, - }) - }) }) }) diff --git a/packages/gatsby-plugin-typescript/src/gatsby-node.js b/packages/gatsby-plugin-typescript/src/gatsby-node.js index 4704be8de533d..90e8b8c8de51f 100644 --- a/packages/gatsby-plugin-typescript/src/gatsby-node.js +++ b/packages/gatsby-plugin-typescript/src/gatsby-node.js @@ -16,13 +16,7 @@ function onCreateBabelConfig({ actions }, options) { }) } -function onCreateWebpackConfig({ - actions, - getConfig, - loaders, - stage, - reporter, -}) { +function onCreateWebpackConfig({ actions, loaders }) { const jsLoader = loaders.js() if (!jsLoader) { @@ -39,42 +33,6 @@ function onCreateWebpackConfig({ ], }, }) - - if (stage === `develop`) { - let isTypescriptDepAvailable - try { - isTypescriptDepAvailable = require.resolve(`typescript`) - } catch (e) { - reporter.warn( - `"typescript" is not installed. Builtin ESLint won't be working on typescript files.` - ) - } - - if (isTypescriptDepAvailable) { - const builtInEslintRule = getConfig().module.rules.find(rule => { - if (rule.enforce === `pre`) { - if (rule.use) { - return rule.use.some(use => /eslint-loader/.test(use.loader)) - } else { - return /eslint-loader/.test(rule.loader) - } - } - return false - }) - - if (builtInEslintRule) { - const typescriptEslintRule = { - ...builtInEslintRule, - test: /\.tsx?$/, - } - actions.setWebpackConfig({ - module: { - rules: [typescriptEslintRule], - }, - }) - } - } - } } exports.resolvableExtensions = resolvableExtensions