From 346cfa0e2ca2c315e3426cb78429312be797a036 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 9 Mar 2018 00:08:23 -0800 Subject: [PATCH] remove URLSearchParams --- package-lock.json | 62 +++++++++++++++++------------- package.json | 4 +- routes/_utils/ajax.js | 11 ++++-- routes/_utils/asyncModules.js | 11 ------ routes/_utils/loadPolyfills.js | 2 - routes/_utils/marks.js | 17 +++----- routes/_utils/thunk.js | 11 ------ routes/settings/instances/add.html | 6 +-- 8 files changed, 52 insertions(+), 72 deletions(-) delete mode 100644 routes/_utils/thunk.js diff --git a/package-lock.json b/package-lock.json index 1836f766..229ef326 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8106,9 +8106,9 @@ } }, "sapper": { - "version": "github:nolanlawson/sapper#6f6c17aa0763bf1c9e1f268ff2e220551803992d", + "version": "github:nolanlawson/sapper#ec86bbb81d6b7346d3332b3d31fd507a01010f2f", "requires": { - "chalk": "2.3.0", + "chalk": "2.3.2", "chokidar": "1.7.0", "escape-html": "1.0.3", "mkdirp": "0.5.1", @@ -8116,7 +8116,7 @@ "require-relative": "0.8.7", "rimraf": "2.6.2", "webpack": "3.11.0", - "webpack-hot-middleware": "2.21.0" + "webpack-hot-middleware": "2.21.2" }, "dependencies": { "acorn-dynamic-import": { @@ -8150,9 +8150,9 @@ "integrity": "sha1-rCsnk5xUPpXSwG5/f1wnvkqlQ74=" }, "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "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==", "requires": { "color-convert": "1.9.1" } @@ -8195,13 +8195,13 @@ "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=" }, "chalk": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz", - "integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz", + "integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==", "requires": { - "ansi-styles": "3.2.0", + "ansi-styles": "3.2.1", "escape-string-regexp": "1.0.5", - "supports-color": "4.5.0" + "supports-color": "5.3.0" } }, "chokidar": { @@ -8278,9 +8278,9 @@ } }, "has-flag": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", - "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, "is-extglob": { "version": "1.0.0", @@ -8316,11 +8316,11 @@ } }, "supports-color": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", - "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz", + "integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==", "requires": { - "has-flag": "2.0.0" + "has-flag": "3.0.0" } }, "tapable": { @@ -8365,6 +8365,21 @@ "watchpack": "1.5.0", "webpack-sources": "1.1.0", "yargs": "8.0.2" + }, + "dependencies": { + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" + }, + "supports-color": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", + "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", + "requires": { + "has-flag": "2.0.0" + } + } } }, "yargs": { @@ -10235,11 +10250,6 @@ } } }, - "url-search-params": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/url-search-params/-/url-search-params-0.10.0.tgz", - "integrity": "sha512-oFPzmbPAbdthStgffGq8alULe47skPDt1X3KW6NOQnKkcLHP4IS1NfdfHG/CBP5lGsr2gDzNp87pfWLx/eIxjw==" - }, "use": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/use/-/use-2.0.2.tgz", @@ -10707,9 +10717,9 @@ } }, "webpack-hot-middleware": { - "version": "2.21.0", - "resolved": "https://registry.npmjs.org/webpack-hot-middleware/-/webpack-hot-middleware-2.21.0.tgz", - "integrity": "sha512-P6xiOLy10QlSVSO7GanU9PLxN6zLLQ7RG16MPTvmFwf2KUG7jMp6m+fmdgsR7xoaVVLA7OlX3YO6JjoZEKjCuA==", + "version": "2.21.2", + "resolved": "https://registry.npmjs.org/webpack-hot-middleware/-/webpack-hot-middleware-2.21.2.tgz", + "integrity": "sha512-N5c80o31E0COFJV8HRjiX3hJetDOwQ2Ajt5TTORKA9diOimhFtmaZKSfO3pQKMeQngb7I4TUnNDroJiUzPFhKQ==", "requires": { "ansi-html": "0.0.7", "html-entities": "1.2.1", diff --git a/package.json b/package.json index 2b96a8bf..cfb73f29 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "pify": "^3.0.0", "quick-lru": "^1.1.0", "requestidlecallback": "^0.3.0", - "sapper": "nolanlawson/sapper#fix-style-loader-built", + "sapper": "nolanlawson/sapper#monkey-patches", "serve-static": "^1.13.1", "standard": "^10.0.3", "stringz": "^0.4.0", @@ -67,7 +67,6 @@ "testcafe": "^0.19.0-alpha1", "timeago.js": "^3.0.2", "tiny-queue": "^0.2.1", - "url-search-params": "^0.10.0", "webpack": "^4.1.0", "webpack-bundle-analyzer": "^2.11.1", "workerize-loader": "^1.0.1", @@ -86,7 +85,6 @@ "requestIdleCallback", "location", "localStorage", - "URLSearchParams", "IntersectionObserver", "URL", "Event", diff --git a/routes/_utils/ajax.js b/routes/_utils/ajax.js index ae26834d..f28c9e72 100644 --- a/routes/_utils/ajax.js +++ b/routes/_utils/ajax.js @@ -69,9 +69,12 @@ export async function get (url, headers = {}) { } export function paramsString (paramsObject) { - let params = new URLSearchParams() - Object.keys(paramsObject).forEach(key => { - params.set(key, paramsObject[key]) + let res = '' + Object.keys(paramsObject).forEach((key, i) => { + if (i > 0) { + res += '&' + } + res += encodeURIComponent(key) + '=' + encodeURIComponent(paramsObject[key]) }) - return params.toString() + return res } diff --git a/routes/_utils/asyncModules.js b/routes/_utils/asyncModules.js index 48b25117..e5aae720 100644 --- a/routes/_utils/asyncModules.js +++ b/routes/_utils/asyncModules.js @@ -1,14 +1,3 @@ -export const importURLSearchParams = () => import( - /* webpackChunkName: 'url-search-params' */ 'url-search-params' - ).then(Params => { - window.URLSearchParams = Params - Object.defineProperty(window.URL.prototype, 'searchParams', { - get() { - return new Params(this.search) - } - }) -}) - export const importTimeline = () => import( /* webpackChunkName: 'Timeline' */ '../_components/timeline/Timeline.html' ).then(mod => mod.default) diff --git a/routes/_utils/loadPolyfills.js b/routes/_utils/loadPolyfills.js index 4dc2ceb5..6bf27cc7 100644 --- a/routes/_utils/loadPolyfills.js +++ b/routes/_utils/loadPolyfills.js @@ -1,5 +1,4 @@ import { - importURLSearchParams, importIntersectionObserver, importRequestIdleCallback, importIndexedDBGetAllShim @@ -7,7 +6,6 @@ import { export function loadPolyfills () { return Promise.all([ - typeof URLSearchParams === 'undefined' && importURLSearchParams(), typeof IntersectionObserver === 'undefined' && importIntersectionObserver(), typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(), !IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim() diff --git a/routes/_utils/marks.js b/routes/_utils/marks.js index 2108ff02..fc178308 100644 --- a/routes/_utils/marks.js +++ b/routes/_utils/marks.js @@ -1,25 +1,18 @@ -import { thunk } from './thunk' - -// Lazily invoke because URLSearchParams isn't supported in Edge 16, -// so we need the polyfill. -const enabled = thunk(() => process.browser && - performance.mark && - ( - process.env.NODE_ENV !== 'production' || - new URLSearchParams(location.search).get('marks') === 'true' - ) +const enabled = process.browser && performance.mark && ( + process.env.NODE_ENV !== 'production' || + location.search.includes('marks=true') ) const perf = process.browser && performance export function mark (name) { - if (enabled()) { + if (enabled) { perf.mark(`start ${name}`) } } export function stop (name) { - if (enabled()) { + if (enabled) { perf.mark(`end ${name}`) perf.measure(name, `start ${name}`, `end ${name}`) } diff --git a/routes/_utils/thunk.js b/routes/_utils/thunk.js deleted file mode 100644 index 153be560..00000000 --- a/routes/_utils/thunk.js +++ /dev/null @@ -1,11 +0,0 @@ -export function thunk (fn) { - let value - let called - return () => { - if (!called) { - value = fn() - called = true - } - return value - } -} diff --git a/routes/settings/instances/add.html b/routes/settings/instances/add.html index 714e5031..d6b1b122 100644 --- a/routes/settings/instances/add.html +++ b/routes/settings/instances/add.html @@ -77,9 +77,9 @@ export default { async oncreate () { - let params = new URLSearchParams(location.search) - if (params.has('code')) { - handleOauthCode(params.get('code')) + let codeMatch = location.search.match(/code=([^&]+)/) + if (codeMatch) { + handleOauthCode(codeMatch[1]) } }, components: {