From 9a8f5758670999a8b935a901188b0e24017353cd Mon Sep 17 00:00:00 2001 From: abhijithvijayan <34790378+abhijithvijayan@users.noreply.github.com> Date: Fri, 17 Apr 2020 13:00:43 +0530 Subject: [PATCH] fix: apply new prettier rules --- package.json | 4 +- source/scripts/background.js | 12 +- source/scripts/popup.js | 44 +++--- webpack.config.js | 297 ++++++++++++++++++----------------- yarn.lock | 8 +- 5 files changed, 185 insertions(+), 180 deletions(-) diff --git a/package.json b/package.json index 69b6a73..e7c9b1f 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "webextension-polyfill": "^0.6.0" }, "devDependencies": { - "@abhijithvijayan/eslint-config": "0.14.1", + "@abhijithvijayan/eslint-config": "^1.3.0", "@babel/core": "^7.9.0", "@babel/plugin-proposal-object-rest-spread": "^7.9.0", "@babel/plugin-transform-destructuring": "^7.8.8", @@ -75,4 +75,4 @@ "wext-manifest-webpack-plugin": "^1.0.3", "zip-webpack-plugin": "^3.0.0" } -} \ No newline at end of file +} diff --git a/source/scripts/background.js b/source/scripts/background.js index cee53fe..a12308e 100644 --- a/source/scripts/background.js +++ b/source/scripts/background.js @@ -1,14 +1,14 @@ import browser from 'webextension-polyfill'; browser.runtime.onInstalled.addListener(() => { - // eslint-disable-next-line no-console - console.log('onInstalled....'); + // eslint-disable-next-line no-console + console.log('onInstalled....'); }); browser.runtime.onMessage.addListener((_request, _sender, _sendResponse) => { - // Do something with the message! - // alert(request.url); + // Do something with the message! + // alert(request.url); - // And respond back to the sender. - return Promise.resolve('got your message, thanks!'); + // And respond back to the sender. + return Promise.resolve('got your message, thanks!'); }); diff --git a/source/scripts/popup.js b/source/scripts/popup.js index 76067f5..72a24ba 100644 --- a/source/scripts/popup.js +++ b/source/scripts/popup.js @@ -1,34 +1,36 @@ import browser from 'webextension-polyfill'; function openWebPage(url) { - return browser.tabs.create({ url }); + return browser.tabs.create({url}); } document.addEventListener('DOMContentLoaded', async () => { - const tabs = await browser.tabs.query({ - active: true, - lastFocusedWindow: true, - }); + const tabs = await browser.tabs.query({ + active: true, + lastFocusedWindow: true, + }); - const url = tabs.length && tabs[0].url; + const url = tabs.length && tabs[0].url; - const response = await browser.runtime.sendMessage({ - msg: 'hello', - url, - }); + const response = await browser.runtime.sendMessage({ + msg: 'hello', + url, + }); - // eslint-disable-next-line no-console - console.log(response); + // eslint-disable-next-line no-console + console.log(response); - document.getElementById('github__button').addEventListener('click', () => { - return openWebPage('https://github.com/abhijithvijayan/web-extension-starter'); - }); + document.getElementById('github__button').addEventListener('click', () => { + return openWebPage( + 'https://github.com/abhijithvijayan/web-extension-starter' + ); + }); - document.getElementById('donate__button').addEventListener('click', () => { - return openWebPage('https://www.buymeacoffee.com/abhijithvijayan'); - }); + document.getElementById('donate__button').addEventListener('click', () => { + return openWebPage('https://www.buymeacoffee.com/abhijithvijayan'); + }); - document.getElementById('options__button').addEventListener('click', () => { - return openWebPage('options.html'); - }); + document.getElementById('options__button').addEventListener('click', () => { + return openWebPage('options.html'); + }); }); diff --git a/webpack.config.js b/webpack.config.js index fc90981..7e41097 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,7 +4,7 @@ const ZipPlugin = require('zip-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); +const {CleanWebpackPlugin} = require('clean-webpack-plugin'); const ExtensionReloader = require('webpack-extension-reloader'); const WextManifestWebpackPlugin = require('wext-manifest-webpack-plugin'); const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries'); @@ -14,163 +14,166 @@ const nodeEnv = process.env.NODE_ENV || 'development'; const targetBrowser = process.env.TARGET_BROWSER; const extensionReloaderPlugin = - nodeEnv === 'development' - ? new ExtensionReloader({ - port: 9090, - reloadPage: true, - entries: { - // TODO: reload manifest on update - contentScript: 'contentScript', - background: 'background', - extensionPage: ['popup', 'options'], - }, - }) - : () => { - this.apply = () => {}; - }; + nodeEnv === 'development' + ? new ExtensionReloader({ + port: 9090, + reloadPage: true, + entries: { + // TODO: reload manifest on update + contentScript: 'contentScript', + background: 'background', + extensionPage: ['popup', 'options'], + }, + }) + : () => { + this.apply = () => {}; + }; const getExtensionFileType = (browser) => { - if (browser === 'opera') { - return 'crx'; - } - if (browser === 'firefox') { - return 'xpi'; - } + if (browser === 'opera') { + return 'crx'; + } + if (browser === 'firefox') { + return 'xpi'; + } - return 'zip'; + return 'zip'; }; module.exports = { - mode: nodeEnv, + mode: nodeEnv, - entry: { - manifest: './source/manifest.json', - background: './source/scripts/background.js', - contentScript: './source/scripts/contentScript.js', - popup: './source/scripts/popup.js', - options: './source/scripts/options.js', - styles: ['./source/styles/popup.scss', './source/styles/options.scss'], - }, + entry: { + manifest: './source/manifest.json', + background: './source/scripts/background.js', + contentScript: './source/scripts/contentScript.js', + popup: './source/scripts/popup.js', + options: './source/scripts/options.js', + styles: ['./source/styles/popup.scss', './source/styles/options.scss'], + }, - output: { - path: path.resolve(__dirname, 'extension', targetBrowser), - filename: 'js/[name].bundle.js', - }, + output: { + path: path.resolve(__dirname, 'extension', targetBrowser), + filename: 'js/[name].bundle.js', + }, - module: { - rules: [ - { - type: 'javascript/auto', // prevent webpack handling json with its own loaders, - test: /manifest\.json$/, - use: { - loader: 'wext-manifest-loader', - options: { - usePackageJSONVersion: true, // set to false to not use package.json version for manifest - }, - }, - }, - { - test: /.(js|jsx)$/, - include: [path.resolve(__dirname, 'source/scripts')], - loader: 'babel-loader', + module: { + rules: [ + { + type: 'javascript/auto', // prevent webpack handling json with its own loaders, + test: /manifest\.json$/, + use: { + loader: 'wext-manifest-loader', + options: { + usePackageJSONVersion: true, // set to false to not use package.json version for manifest + }, + }, + }, + { + test: /.(js|jsx)$/, + include: [path.resolve(__dirname, 'source/scripts')], + loader: 'babel-loader', - options: { - plugins: ['syntax-dynamic-import'], + options: { + plugins: ['syntax-dynamic-import'], - presets: [ - [ - '@babel/preset-env', - { - modules: false, - }, - ], - ], - }, - }, - { - test: /\.scss$/, - use: [ - { - loader: 'file-loader', - options: { - name: '[name].css', - context: './source/styles/', - outputPath: 'css/', - }, - }, - 'extract-loader', - { - loader: 'css-loader', - options: { - sourceMap: nodeEnv === 'development', - }, - }, - { - loader: 'postcss-loader', - options: { - ident: 'postcss', - // eslint-disable-next-line global-require - plugins: [require('autoprefixer')()], - }, - }, - 'resolve-url-loader', - 'sass-loader', - ], - }, - ], - }, - - plugins: [ - new webpack.ProgressPlugin(), - new WextManifestWebpackPlugin(), - new FixStyleOnlyEntriesPlugin({ silent: true }), - new webpack.EnvironmentPlugin(['NODE_ENV', 'TARGET_BROWSER']), - new CleanWebpackPlugin({ - cleanOnceBeforeBuildPatterns: [ - path.join(process.cwd(), `extension/${targetBrowser}`), - path.join(process.cwd(), `extension/${targetBrowser}.${getExtensionFileType(targetBrowser)}`), + presets: [ + [ + '@babel/preset-env', + { + modules: false, + }, ], - cleanStaleWebpackAssets: false, - verbose: true, - }), - new HtmlWebpackPlugin({ - template: 'source/options.html', - // inject: false, - chunks: ['options'], - filename: 'options.html', - }), - new HtmlWebpackPlugin({ - template: 'source/popup.html', - // inject: false, - chunks: ['popup'], - filename: 'popup.html', - }), - new CopyWebpackPlugin([{ from: 'source/assets', to: 'assets' }]), - extensionReloaderPlugin, - ], - - optimization: { - minimizer: [ - new TerserPlugin({ - cache: true, - parallel: true, - terserOptions: { - output: { - comments: false, - }, - }, - extractComments: false, - }), - new OptimizeCSSAssetsPlugin({ - cssProcessorPluginOptions: { - preset: ['default', { discardComments: { removeAll: true } }], - }, - }), - new ZipPlugin({ - path: path.resolve(__dirname, 'extension'), - extension: `${getExtensionFileType(targetBrowser)}`, - filename: `${targetBrowser}`, - }), + ], + }, + }, + { + test: /\.scss$/, + use: [ + { + loader: 'file-loader', + options: { + name: '[name].css', + context: './source/styles/', + outputPath: 'css/', + }, + }, + 'extract-loader', + { + loader: 'css-loader', + options: { + sourceMap: nodeEnv === 'development', + }, + }, + { + loader: 'postcss-loader', + options: { + ident: 'postcss', + // eslint-disable-next-line global-require + plugins: [require('autoprefixer')()], + }, + }, + 'resolve-url-loader', + 'sass-loader', ], - }, + }, + ], + }, + + plugins: [ + new webpack.ProgressPlugin(), + new WextManifestWebpackPlugin(), + new FixStyleOnlyEntriesPlugin({silent: true}), + new webpack.EnvironmentPlugin(['NODE_ENV', 'TARGET_BROWSER']), + new CleanWebpackPlugin({ + cleanOnceBeforeBuildPatterns: [ + path.join(process.cwd(), `extension/${targetBrowser}`), + path.join( + process.cwd(), + `extension/${targetBrowser}.${getExtensionFileType(targetBrowser)}` + ), + ], + cleanStaleWebpackAssets: false, + verbose: true, + }), + new HtmlWebpackPlugin({ + template: 'source/options.html', + // inject: false, + chunks: ['options'], + filename: 'options.html', + }), + new HtmlWebpackPlugin({ + template: 'source/popup.html', + // inject: false, + chunks: ['popup'], + filename: 'popup.html', + }), + new CopyWebpackPlugin([{from: 'source/assets', to: 'assets'}]), + extensionReloaderPlugin, + ], + + optimization: { + minimizer: [ + new TerserPlugin({ + cache: true, + parallel: true, + terserOptions: { + output: { + comments: false, + }, + }, + extractComments: false, + }), + new OptimizeCSSAssetsPlugin({ + cssProcessorPluginOptions: { + preset: ['default', {discardComments: {removeAll: true}}], + }, + }), + new ZipPlugin({ + path: path.resolve(__dirname, 'extension'), + extension: `${getExtensionFileType(targetBrowser)}`, + filename: `${targetBrowser}`, + }), + ], + }, }; diff --git a/yarn.lock b/yarn.lock index 8c24f59..8d9df4b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@abhijithvijayan/eslint-config@0.14.1": - version "0.14.1" - resolved "https://registry.npmjs.org/@abhijithvijayan/eslint-config/-/eslint-config-0.14.1.tgz#ca6a0e0da188cb9d6be1be44a1e054f76be74c69" - integrity sha512-fx/n434sXdKAyKNxtdy91Wn8uqeyfd4fcIC8I1/xb7JTVlqB4uAdp2xVu5KG5hEFL+liauieT97wXNTTJBLTJg== +"@abhijithvijayan/eslint-config@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@abhijithvijayan/eslint-config/-/eslint-config-1.3.0.tgz#cfe741a97f04725fa931e918014dfabc33aefdb1" + integrity sha512-b823i+e8Tw9auspey0U+3fVziydJ3d0bxUfd+HJdSuuHV/48EO6erPEy3acusqwSQ9uGB3contePze9Yt/n+eA== "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.8.3": version "7.8.3"