diff options
author | 2020-05-30 14:47:23 +0200 | |
---|---|---|
committer | 2020-05-30 14:47:23 +0200 | |
commit | 2a81048d4336b7a307d8b712a6362e9c34f03013 (patch) | |
tree | 3b8fe21eb8ff5fd933f31774e52fe44d91c25565 | |
parent | 7589633720493550e359468ffdb4294858b74646 (diff) | |
download | refined-github-2a81048d4336b7a307d8b712a6362e9c34f03013.tar.gz refined-github-2a81048d4336b7a307d8b712a6362e9c34f03013.tar.zst refined-github-2a81048d4336b7a307d8b712a6362e9c34f03013.zip |
Meta: config and build cleanup (#3157)
-rw-r--r-- | .xo-config.js | 60 | ||||
-rw-r--r-- | package-lock.json | 197 | ||||
-rw-r--r-- | package.json | 135 | ||||
-rw-r--r-- | size-plugin.json | 0 | ||||
-rw-r--r-- | source/features/clean-sidebar.tsx | 2 | ||||
-rw-r--r-- | source/features/index.tsx | 2 | ||||
-rw-r--r-- | source/features/mark-unread.tsx | 6 | ||||
-rw-r--r-- | source/features/preview-hidden-comments.tsx | 4 | ||||
-rw-r--r-- | source/features/sticky-discussion-sidebar.tsx | 2 | ||||
-rw-r--r-- | source/helpers/on-replaced-element.ts | 3 | ||||
-rw-r--r-- | webpack.config.ts | 47 |
11 files changed, 129 insertions, 329 deletions
diff --git a/.xo-config.js b/.xo-config.js new file mode 100644 index 00000000..9f44d8d0 --- /dev/null +++ b/.xo-config.js @@ -0,0 +1,60 @@ +module.exports = { + envs: [ + 'browser' + ], + extends: 'xo-react', + globals: [ + 'browser', + '__featuresOptionDefaults__', + '__featuresMeta__', + '__filebasename' + ], + rules: { + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-floating-promises': 'off', + '@typescript-eslint/no-non-null-asserted-optional-chain': 'off', + '@typescript-eslint/prefer-readonly-parameter-types': 'off', + 'no-alert': 'off', + 'no-void': 'off', + 'react/function-component-definition': [ + 'error', + { + namedComponents: 'function-declaration' + } + ], + 'react/jsx-first-prop-new-line': 'error', + 'react/jsx-key': 'off', + 'import/order': [ + 'error', + { + groups: [ + [ + 'builtin', + 'external' + ] + ], + 'newlines-between': 'always-and-inside-groups' + } + ], + 'import/first': 'error', + 'import/newline-after-import': 'error', + 'import/no-anonymous-default-export': 'error', + 'import/no-commonjs': 'error', + 'import/no-named-default': 'error', + 'import/no-unassigned-import': 'off', + 'import/prefer-default-export': 'error', + 'import/extensions': [ + 'error', + 'never', + { + svg: 'always' + } + ], + 'unicorn/no-fn-reference-in-iterator': 'off' + }, + settings: { + react: { + version: '16.3' + } + } +}; diff --git a/package-lock.json b/package-lock.json index e9a05bfd..31dbcde6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6966,188 +6966,6 @@ "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", "dev": true }, - "fork-ts-checker-webpack-plugin": { - "version": "4.1.4", - "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-4.1.4.tgz", - "integrity": "sha512-R0nTlZSyV0uCCzYe1kgR7Ve8mXyDvMm1pJwUFb6zzRVF5rTNb24G6gn2DFQy+W5aJYp2eq8aexpCOO+1SCyCSA==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.5.5", - "chalk": "^2.4.1", - "micromatch": "^3.1.10", - "minimatch": "^3.0.4", - "semver": "^5.6.0", - "tapable": "^1.0.0", - "worker-rpc": "^0.1.0" - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "braces": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-2.3.2.tgz", - "integrity": "sha512-aNdbnj9P8PjdXU4ybaWLK2IF3jc/EoDYbC7AazW6to3TRsfXxscC9UXOB5iDiEQrkyIbWp2SLQda4+QAa7nc3w==", - "dev": true, - "requires": { - "arr-flatten": "^1.1.0", - "array-unique": "^0.3.2", - "extend-shallow": "^2.0.1", - "fill-range": "^4.0.0", - "isobject": "^3.0.1", - "repeat-element": "^1.1.2", - "snapdragon": "^0.8.1", - "snapdragon-node": "^2.0.1", - "split-string": "^3.0.2", - "to-regex": "^3.0.1" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - } - } - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "fill-range": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz", - "integrity": "sha1-1USBHUKPmOsGpj3EAtJAPDKMOPc=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-number": "^3.0.0", - "repeat-string": "^1.6.1", - "to-regex-range": "^2.1.0" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - } - } - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "is-number": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", - "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", - "dev": true, - "requires": { - "kind-of": "^3.0.2" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } - }, - "isobject": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", - "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", - "dev": true - }, - "micromatch": { - "version": "3.1.10", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", - "integrity": "sha512-MWikgl9n9M3w+bpsY3He8L+w9eF9338xRl8IAO5viDizwSzziFEyUzo2xrrloB64ADbTf8uA8vRqqttDTOmccg==", - "dev": true, - "requires": { - "arr-diff": "^4.0.0", - "array-unique": "^0.3.2", - "braces": "^2.3.1", - "define-property": "^2.0.2", - "extend-shallow": "^3.0.2", - "extglob": "^2.0.4", - "fragment-cache": "^0.2.1", - "kind-of": "^6.0.2", - "nanomatch": "^1.2.9", - "object.pick": "^1.3.0", - "regex-not": "^1.0.0", - "snapdragon": "^0.8.1", - "to-regex": "^3.0.2" - } - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - }, - "to-regex-range": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-2.1.1.tgz", - "integrity": "sha1-fIDBe53+vlmeJzZ+DU3VWQFB2zg=", - "dev": true, - "requires": { - "is-number": "^3.0.0", - "repeat-string": "^1.6.1" - } - } - } - }, "form-data": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", @@ -9366,12 +9184,6 @@ "integrity": "sha512-lkJ3Rj/mtjlRcHk6YyCbvZhyWTOzdBvTHsxMmZSk5jxN1YyVSQ+JETAom55mdzfcyDrY/49Z7UCW760BK30crg==", "dev": true }, - "microevent.ts": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/microevent.ts/-/microevent.ts-0.1.1.tgz", - "integrity": "sha512-jo1OfR4TaEwd5HOrt5+tAZ9mqT4jmpNAusXtyfNzqVm9uiSYFZlKM1wYL4oU7azZW/PxQW53wM0S6OR1JHNa2g==", - "dev": true - }, "micromatch": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", @@ -15922,15 +15734,6 @@ "errno": "~0.1.7" } }, - "worker-rpc": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/worker-rpc/-/worker-rpc-0.1.1.tgz", - "integrity": "sha512-P1WjMrUB3qgJNI9jfmpZ/htmBEjFh//6l/5y8SD9hg1Ef5zTTVVoRjTrTEzPrNBQvmhMxkoTsjOXN10GWU7aCg==", - "dev": true, - "requires": { - "microevent.ts": "~0.1.1" - } - }, "wrap-ansi": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", diff --git a/package.json b/package.json index 2af9b5f8..49cc8385 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,48 @@ { "private": true, "scripts": { - "lint": "run-p --silent lint:*", - "lint:js": "xo", - "lint:css": "stylelint 'source/**/*.css'", - "lint-fix": "run-p --silent 'lint:* -- --fix'", - "test": "run-s ava lint:* build", "ava": "TS_NODE_FILES=true ava", - "build": "webpack --mode=production", - "watch": "webpack --mode=development --watch", - "version": "dot-json distribution/manifest.json version $VER", - "release:cws": "webstore upload --source=distribution --auto-publish", - "release:amo": "web-ext-submit --source-dir distribution", + "build": "run-p build:* --continue-on-error", + "build:typescript": "tsc --noEmit", + "build:webpack": "webpack --mode=production", + "fix": "run-p 'lint:* -- --fix'", + "lint": "run-p lint:* --continue-on-error", + "lint:css": "stylelint 'source/**/*.css'", + "lint:js": "xo", "release": "VER=$(daily-version) run-s build version release:*", + "release:amo": "web-ext-submit --source-dir distribution", + "release:cws": "webstore upload --source=distribution --auto-publish", "start": "web-ext run --target=chromium", - "start:firefox": "web-ext run" + "start:firefox": "web-ext run", + "test": "run-p ava lint:* build:*", + "version": "dot-json distribution/manifest.json version $VER", + "watch": "run-p watch:* --continue-on-error", + "watch:typescript": "tsc --noEmit --watch --preserveWatchOutput", + "watch:webpack": "webpack --mode=development --watch" + }, + "stylelint": { + "extends": "stylelint-config-xo", + "rules": { + "selector-type-no-unknown": null, + "declaration-no-important": null, + "property-no-vendor-prefix": null, + "selector-class-pattern": null, + "selector-id-pattern": null, + "at-rule-empty-line-before": null + } + }, + "ava": { + "extensions": [ + "ts" + ], + "files": [ + "test/*.ts" + ], + "require": [ + "esm", + "ts-node/register" + ], + "timeout": "30s" }, "dependencies": { "@primer/octicons": "^9.6.0", @@ -72,7 +100,6 @@ "eslint-plugin-react": "^7.20.0", "eslint-plugin-react-hooks": "^4.0.2", "esm": "^3.2.25", - "fork-ts-checker-webpack-plugin": "^4.1.4", "jsdom": "^16.2.2", "mini-css-extract-plugin": "^0.9.0", "npm-run-all": "^4.1.5", @@ -91,90 +118,6 @@ "webpack-cli": "^3.3.11", "xo": "^0.30.0" }, - "xo": { - "extends": "xo-react", - "envs": [ - "browser" - ], - "globals": [ - "browser", - "__featuresOptionDefaults__", - "__featuresMeta__", - "__filebasename" - ], - "rules": { - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-floating-promises": "off", - "@typescript-eslint/no-non-null-asserted-optional-chain": "off", - "@typescript-eslint/prefer-readonly-parameter-types": "off", - "no-alert": "off", - "react/function-component-definition": [ - "error", - { - "namedComponents": "function-declaration" - } - ], - "react/jsx-first-prop-new-line": "error", - "react/jsx-key": "off", - "import/order": [ - "error", - { - "groups": [ - [ - "builtin", - "external" - ] - ], - "newlines-between": "always-and-inside-groups" - } - ], - "import/first": "error", - "import/newline-after-import": "error", - "import/no-anonymous-default-export": "error", - "import/no-commonjs": "error", - "import/no-named-default": "error", - "import/prefer-default-export": "error", - "import/extensions": [ - "error", - "never", - { - "svg": "always" - } - ], - "import/no-unassigned-import": "off", - "unicorn/no-fn-reference-in-iterator": "off", - "unicorn/prefer-set-has": "off" - }, - "settings": { - "react": { - "version": "16.3" - } - } - }, - "ava": { - "files": [ - "test/*.ts" - ], - "extensions": [ - "ts" - ], - "require": [ - "esm", - "ts-node/register" - ], - "timeout": "30s" - }, - "stylelint": { - "extends": "stylelint-config-xo", - "rules": { - "selector-type-no-unknown": null, - "declaration-no-important": null, - "property-no-vendor-prefix": null, - "selector-class-pattern": null, - "selector-id-pattern": null, - "at-rule-empty-line-before": null - } - }, "webExt": { "sourceDir": "distribution", "run": { diff --git a/size-plugin.json b/size-plugin.json deleted file mode 100644 index e69de29b..00000000 --- a/size-plugin.json +++ /dev/null diff --git a/source/features/clean-sidebar.tsx b/source/features/clean-sidebar.tsx index 1aea092e..281b1595 100644 --- a/source/features/clean-sidebar.tsx +++ b/source/features/clean-sidebar.tsx @@ -119,7 +119,7 @@ features.add({ pageDetect.isPRConversation ], additionalListeners: [ - () => onReplacedElement('#partial-discussion-sidebar', clean) + () => void onReplacedElement('#partial-discussion-sidebar', clean) ], init: clean }); diff --git a/source/features/index.tsx b/source/features/index.tsx index f330ed90..dd1b4a27 100644 --- a/source/features/index.tsx +++ b/source/features/index.tsx @@ -117,7 +117,7 @@ const globalReady: Promise<RGHOptions> = new Promise(async resolve => { } // Create logging function - log = options.logging ? console.log : () => { }; + log = options.logging ? console.log : () => {/* No logging */}; resolve(options); }); diff --git a/source/features/mark-unread.tsx b/source/features/mark-unread.tsx index d1706104..9fa41e60 100644 --- a/source/features/mark-unread.tsx +++ b/source/features/mark-unread.tsx @@ -84,16 +84,16 @@ async function markRead(urls: string|string[]): Promise<void> { urls = [urls]; } - const cleanUrls = urls.map(stripHash); + const cleanUrls = new Set(urls.map(stripHash)); for (const a of select.all<HTMLAnchorElement>('a.js-notification-target')) { - if (cleanUrls.includes(a.getAttribute('href')!)) { + if (cleanUrls.has(a.getAttribute('href')!)) { a.closest('li.js-notification')!.classList.replace('unread', 'read'); } } const notifications = await getNotifications(); - const updated = notifications.filter(({url}) => !cleanUrls.includes(url)); + const updated = notifications.filter(({url}) => !cleanUrls.has(url)); await setNotifications(updated); } diff --git a/source/features/preview-hidden-comments.tsx b/source/features/preview-hidden-comments.tsx index ae5bbf5e..dcb49e83 100644 --- a/source/features/preview-hidden-comments.tsx +++ b/source/features/preview-hidden-comments.tsx @@ -5,7 +5,7 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; -const allowedReasons = ['resolved', 'outdated', 'off-topic']; +const allowedReasons = new Set(['resolved', 'outdated', 'off-topic']); const capitalize = (text: string): string => text.charAt(0).toUpperCase() + text.slice(1); @@ -24,7 +24,7 @@ const init = (): void => { `, details)!; const reason = /was marked as ([^.]+)/.exec(header.textContent!)?.[1] ?? ''; - if (!allowedReasons.includes(reason)) { + if (!allowedReasons.has(reason)) { continue; } diff --git a/source/features/sticky-discussion-sidebar.tsx b/source/features/sticky-discussion-sidebar.tsx index 861b1135..edbe89ae 100644 --- a/source/features/sticky-discussion-sidebar.tsx +++ b/source/features/sticky-discussion-sidebar.tsx @@ -31,7 +31,7 @@ features.add({ ], additionalListeners: [ () => window.addEventListener('resize', onResize), - () => onReplacedElement(sideBarSelector, updateStickiness) + () => void onReplacedElement(sideBarSelector, updateStickiness) ], init: updateStickiness, deinit diff --git a/source/helpers/on-replaced-element.ts b/source/helpers/on-replaced-element.ts index 3ef75caf..12594a95 100644 --- a/source/helpers/on-replaced-element.ts +++ b/source/helpers/on-replaced-element.ts @@ -8,7 +8,8 @@ Tracks the replacement of an element, identified via selector. @param selector The unique selector used to find the element and its future replacements @param callback The function to call after it's replaced */ -export default async function onReplacedElement(selector: string, callback: VoidCallback): void { + +export default async function onReplacedElement(selector: string, callback: VoidCallback): Promise<void> { let trackedElement = select(selector); if (!trackedElement) { throw new Error('The element can’t be found'); diff --git a/webpack.config.ts b/webpack.config.ts index dcda6b36..9f2b2008 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -9,7 +9,6 @@ import SizePlugin from 'size-plugin'; import TerserPlugin from 'terser-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin'; import MiniCssExtractPlugin from 'mini-css-extract-plugin'; -import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; function parseFeatureDetails(id: FeatureID): FeatureMeta { const content = readFileSync(`source/features/${id}.tsx`, {encoding: 'utf-8'}); @@ -49,12 +48,15 @@ const config: Configuration = { errors: true, builtAt: true }, - entry: { - 'refined-github': './source/refined-github', - background: './source/background', - options: './source/options', - 'resolve-conflicts': './source/resolve-conflicts' - }, + entry: [ + 'refined-github', + 'background', + 'options', + 'resolve-conflicts' + ].reduce<Record<string, string>>((entries, entry) => { + entries[entry] = `./source/${entry}`; + return entries; + }, {}), output: { path: path.join(__dirname, 'distribution'), filename: '[name].js' @@ -63,20 +65,17 @@ const config: Configuration = { rules: [ { test: /\.tsx?$/, - use: [ - { - loader: 'ts-loader', - options: { - compilerOptions: { - // Enables ModuleConcatenation. It must be in here to avoid conflict with ts-node - module: 'es2015' - }, + loader: { + loader: 'ts-loader', + options: { + compilerOptions: { + // Enables ModuleConcatenation. It must be in here to avoid conflict with ts-node + module: 'es2015' + }, - // Make compilation faster with `fork-ts-checker-webpack-plugin` - transpileOnly: true - } + transpileOnly: true } - ], + }, exclude: /node_modules/ }, { @@ -96,7 +95,6 @@ const config: Configuration = { ] }, plugins: [ - new ForkTsCheckerWebpackPlugin(), new webpack.DefinePlugin({ // Passing `true` as the second argument makes these values dynamic — so every file change will update their value. __featuresOptionDefaults__: webpack.DefinePlugin.runtimeValue(() => { @@ -150,10 +148,8 @@ const config: Configuration = { ] }, optimization: { - // Without this, function names will be garbled and enableFeature won't work - concatenateModules: true, - - // Automatically enabled on production; keeps it somewhat readable for AMO reviewers + // Automatically enabled on production; + // Keeps it somewhat readable for AMO reviewers minimizer: [ new TerserPlugin({ parallel: true, @@ -179,7 +175,4 @@ const config: Configuration = { } }; -// Webpack types don't have this -(config.module as any).strictThisContextOnImports = false; - export default config; |