From 7172aae082e88396d397d656d9e0d4a2edd1daa8 Mon Sep 17 00:00:00 2001 From: Jon Robson Date: Fri, 2 Feb 2024 10:29:27 -0800 Subject: [PATCH] Reference previews should no longer use Webpack As a precursor to moving this code to the Cite extension move it off of webpack and switch to using require rather than import Bug: T355194 Change-Id: Ib6486ad38b79a3b67a9744b716b1a2f5d3779795 --- extension.json | 11 +++-- package.json | 4 -- resources/dist/referencePreviews.js | Bin 5488 -> 0 bytes resources/dist/referencePreviews.js.map.json | Bin 20930 -> 0 bytes .../ext.popups.referencePreviews/OWNERS.md | 0 .../ext.popups.referencePreviews/constants.js | 4 ++ .../createReferenceGateway.js | 4 +- .../createReferencePreview.js | 6 ++- .../ext.popups.referencePreviews/index.js | 38 +++++++++++++++++- .../isReferencePreviewsEnabled.js | 6 ++- .../referencePreviews.js | 12 ++++-- .../setUserConfigFlags.js | 2 +- src/ext.popups.referencePreviews/constants.js | 2 - src/ext.popups.referencePreviews/index.js | 37 ----------------- .../gateway.test.js | 2 +- .../isReferencePreviewsEnabled.test.js | 2 +- .../renderer.test.js | 35 ++++------------ .../setUserConfigFlags.test.js | 2 +- webpack.config.js | 3 +- 19 files changed, 81 insertions(+), 89 deletions(-) delete mode 100644 resources/dist/referencePreviews.js delete mode 100644 resources/dist/referencePreviews.js.map.json rename {src => resources}/ext.popups.referencePreviews/OWNERS.md (100%) create mode 100644 resources/ext.popups.referencePreviews/constants.js rename {src => resources}/ext.popups.referencePreviews/createReferenceGateway.js (96%) rename {src => resources}/ext.popups.referencePreviews/createReferencePreview.js (97%) rename {src => resources}/ext.popups.referencePreviews/isReferencePreviewsEnabled.js (87%) rename {src => resources}/ext.popups.referencePreviews/referencePreviews.js (57%) rename {src => resources}/ext.popups.referencePreviews/setUserConfigFlags.js (91%) delete mode 100644 src/ext.popups.referencePreviews/constants.js delete mode 100644 src/ext.popups.referencePreviews/index.js diff --git a/extension.json b/extension.json index 4bd241927..37b67eb67 100644 --- a/extension.json +++ b/extension.json @@ -159,9 +159,14 @@ "styles": [ "resources/ext.popups.referencePreviews/referencePreview.less" ], - "scripts": [ - "resources/dist/referencePreviews.js", - "resources/ext.popups.referencePreviews/index.js" + "packageFiles": [ + "resources/ext.popups.referencePreviews/index.js", + "resources/ext.popups.referencePreviews/constants.js", + "resources/ext.popups.referencePreviews/createReferenceGateway.js", + "resources/ext.popups.referencePreviews/createReferencePreview.js", + "resources/ext.popups.referencePreviews/isReferencePreviewsEnabled.js", + "resources/ext.popups.referencePreviews/referencePreviews.js", + "resources/ext.popups.referencePreviews/setUserConfigFlags.js" ] }, "ext.popups.main": { diff --git a/package.json b/package.json index 486b7b01d..71c7de5f8 100644 --- a/package.json +++ b/package.json @@ -72,10 +72,6 @@ { "path": "resources/dist/index.js", "maxSize": "13.5kB" - }, - { - "path": "resources/dist/referencePreviews.js", - "maxSize": "2.1kB" } ] } diff --git a/resources/dist/referencePreviews.js b/resources/dist/referencePreviews.js deleted file mode 100644 index 78e3a74b76e31201c088fe133f14250d62b1bf96..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5488 zcmb7IZFAeW5&qs^AtN(3*^;!~X}?gRGj1ln%S@IeneHKv^7iTNBbYkSZm8ECnTW&|9U{*|p6}l8G@x{Suq6;Q& zh4$Ik?!y-=Zl$<$UrfEM9UD)Vy7bcMk&WV&6@F>;$gfGADJoMg7qq&xf_w2n33`f{ z7mHfq1&hZflUfV=^VKh(ilcA(Z6$9kGPdQoy)2c z`s|zj=JzX0OQSuP*pvmSXXV7bw;Zu)rJj{@r8P=z#2|>M8a;dJNb03mVkk<&HP@YJ z<8LZqBRhM0OrQGgzxf^EO;j4aDS}#xxltAQ_GC3)1hWPT-%cudwjHLl=GFY3YBG+5nfZT=sH zOfD0b)J2z?kw|>JVwCE7#)^XS#!N^4oj~%zSASl8N8q%lEQ}bR!Z4vLlt7$|4DrCH z&!!R?uWP)2KbNYCe4L2PiiNoqQM}%ifr>=DqV)F#eQ(R@3R^xtvY9~I$&w{yvAD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PVbL(YEGYruXunt^vp7iH4!$*-X)aE?Kxf|_2xX0bM*knYn6c>q diff --git a/resources/dist/referencePreviews.js.map.json b/resources/dist/referencePreviews.js.map.json deleted file mode 100644 index f325c30830925f0d378af1ab761b725024f9291e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20930 zcmbtciFVt@lKmCf@101Axp?0aX99o_#mEvZOS0k@`Pd){l8``v20$%#G-tkMK5V{Z z?yc?yK#-FCUQQAbOLukcRb5@k*SqIInuSSx_vNF;-EkNNcVFI3gK>}s@i2Ik2IpaL zk+n{8o^9{i4bQeir}5skA2@EKYui4ac)z>)`NXv+&biY# zum@bDOyL#Brwu8od+x_Bh@%cfwab(-?8`+s-FPzkA z^xV;7mn*m_e>#3gmK$=qCzrcK#ocLyKy>a9N%xNqVeNPgBA+;oV}R^nl$W~dO_z^= z!+X%M%@;2m^AOe*a15Pll?yg;CoPa@W6S)8#Ch!Gp0_D0yv`l>|WzO zDfojFJXI7tar@ONpb%3aa|-R4Z+6d!YIhC=*~Oi!p^+ahuyD_vkpKupUKkuww4yW+ zCj{9MHN!O)Jph)T5~k+~S4htG+!4jXWGwiN7hRIx=QNK@KPO?m&YQK!*}FB|5|IB{ z;r7BIa$gh{XQBn~FPD_KZ@UlNg}gcXqh#Vv;~tpwMF~|{)c>+H4+@vM7cy_>U)6ac z#)p_3i!^rMlid9W^~t$=C6jjt)ybbB%+!%75CZgk_<$7H-G_q7PU9&CJaI$^k3bwP z;hxZVu1vu^oQPD;om3X_)l$L$7jo#?U1b+LL=MhDnI%|tDW+&2pNeuEMIy6(=%)M3 znF$oA{sauBM zuB>eDJcoJ$LnvB6JP!cQJ*Nt2qQyo-XWG%eLL>$yZ@c$|!T^?8Skq3!hZMx5AcL6; z&*U~BUi-1rxWLbq(|AsE+7U&ciE;<0OQ6XUcOs1P!TbtnS((-f&{u$xD@BFx0|zoE zs)2djnRj4Ak2-cJ&=PopH97($q0>FW2)eYn{ViI7))4)Ojunp-%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$#$#Q&m%2CyG>z$hlt6WR#+*v!VWUDE{{w{5AuOe|3I^WdvH+n>d5$O)y_xd z*9Z!VYOfthOGS=whJz244P?qN>Bm^RMr8%nk>>yX&;RP3IW_#PcW}sja|EwDlA5*{ zC;=;tCl9h9_>O#&sosL$2eiApeY-tKlZz~9V*?J%+EF-YBTPB1(IdGwZN zadH7)gR#mpg56E)nEAMGeUfq+k~N6z8+VTwiM zT*R+nV3rh3QhHReq^iA??4ns{ynZv5rEE?m5$fITmIWqmE<-fsGSgnLv)4b~lMe_E zU}b+=8*Dwp)?h=om+_Jsq`$y%=V zsvaDURsB#O;6pW-Tbr&d16~gJ)aeIfkM61!r_e@=4!fY398k^9f?#f;+b@=u3`8BR z590($inendjH!Vow+Ky1L8De2G!(?Ly=@OwK9XyywW6->#pCh1{_eQvkJyn)%Q*DIYENKdA7KNsmsFzA|63e3#{$5O@soTP@rZ_$WdfOJvP8*? z4$i`P=@?iWM((3b1;Ll!Loks>u8t$I0ixu^6y}LWuVDZ_wI;37z5fsovU#C7o7VEG z)jkH4CBhjp3Y@&v2AMuzt@Ea1w8#Jp<no7yXx;398FZf4&qJb+Af_fA#)b|R!h}2_d%Dgh)74TYr zQGm;(>=^eX53>To6L34Wmssw*7Vi0AAJ#}zxn@w2oJ zavePK@tn6gZ;2eK+*A%X#MCV0{+6nma920`P*h6#T3!n#f}oS#Y6Cck-y7M`fjZQ9eROl@E2{0#DaDJ3JPf$CFW&@W9$9z!a+SMCeOQw(CkpHR7oKNNd98knHJkc=(S2`5oN}>*amrro; zfQK^pnU}{hxKk%5xPTfM1;CxDcHmM@GGqYV?iNK}ZFs<~>T=)(jwtX`d@haa@`LH} PGxoR0c { + if ( data.previewType === TYPE_REFERENCE ) { + mw.track( REFERENCE_PREVIEWS_LOGGING_SCHEMA, data ); + } +} ); + +module.exports = referencePreviewsState !== null ? { + type: TYPE_REFERENCE, + selector: '#mw-content-text .reference a[ href*="#" ]', + delay: FETCH_DELAY_REFERENCE_TYPE, + gateway, + renderFn, + init: () => { + initReferencePreviewsInstrumentation(); + } +} : null; diff --git a/src/ext.popups.referencePreviews/isReferencePreviewsEnabled.js b/resources/ext.popups.referencePreviews/isReferencePreviewsEnabled.js similarity index 87% rename from src/ext.popups.referencePreviews/isReferencePreviewsEnabled.js rename to resources/ext.popups.referencePreviews/isReferencePreviewsEnabled.js index cd02facb4..e1dff0819 100644 --- a/src/ext.popups.referencePreviews/isReferencePreviewsEnabled.js +++ b/resources/ext.popups.referencePreviews/isReferencePreviewsEnabled.js @@ -1,4 +1,4 @@ -import { TYPE_REFERENCE } from './constants.js'; +const { TYPE_REFERENCE } = require( './constants.js' ); /** * @module isReferencePreviewsEnabled @@ -14,7 +14,7 @@ import { TYPE_REFERENCE } from './constants.js'; * * @return {boolean|null} Null when there is no way the popup type can be enabled at run-time. */ -export default function isReferencePreviewsEnabled( user, isPreviewTypeEnabled, config ) { +function isReferencePreviewsEnabled( user, isPreviewTypeEnabled, config ) { // TODO: This and the final `mw.user.options` check are currently redundant. Only this here // should be removed when the wgPopupsReferencePreviews feature flag is not needed any more. if ( !config.get( 'wgPopupsReferencePreviews' ) ) { @@ -37,3 +37,5 @@ export default function isReferencePreviewsEnabled( user, isPreviewTypeEnabled, // Registered users never can enable popup types at run-time. return user.options.get( 'popups-reference-previews' ) === '1' ? true : null; } + +module.exports = isReferencePreviewsEnabled; diff --git a/src/ext.popups.referencePreviews/referencePreviews.js b/resources/ext.popups.referencePreviews/referencePreviews.js similarity index 57% rename from src/ext.popups.referencePreviews/referencePreviews.js rename to resources/ext.popups.referencePreviews/referencePreviews.js index b19d03630..ab62159d7 100644 --- a/src/ext.popups.referencePreviews/referencePreviews.js +++ b/resources/ext.popups.referencePreviews/referencePreviews.js @@ -1,11 +1,11 @@ let isTracking = false; -export const LOGGING_SCHEMA = 'event.ReferencePreviewsPopups'; +const LOGGING_SCHEMA = 'event.ReferencePreviewsPopups'; /** * Run once the preview is initialized. */ -export function initReferencePreviewsInstrumentation() { +function initReferencePreviewsInstrumentation() { if ( mw.config.get( 'wgPopupsReferencePreviews' ) && navigator.sendBeacon && mw.config.get( 'wgIsArticle' ) && @@ -16,6 +16,12 @@ export function initReferencePreviewsInstrumentation() { } } -export function isTrackingEnabled() { +function isTrackingEnabled() { return isTracking; } + +module.exports = { + LOGGING_SCHEMA, + initReferencePreviewsInstrumentation, + isTrackingEnabled +}; diff --git a/src/ext.popups.referencePreviews/setUserConfigFlags.js b/resources/ext.popups.referencePreviews/setUserConfigFlags.js similarity index 91% rename from src/ext.popups.referencePreviews/setUserConfigFlags.js rename to resources/ext.popups.referencePreviews/setUserConfigFlags.js index 06bf718b7..25d67215c 100644 --- a/src/ext.popups.referencePreviews/setUserConfigFlags.js +++ b/resources/ext.popups.referencePreviews/setUserConfigFlags.js @@ -13,7 +13,7 @@ const REF_TOOLTIPS_ENABLED = 2, * * @param {mw.Map} config */ -export default function setUserConfigFlags( config ) { +module.exports = function setUserConfigFlags( config ) { const popupsFlags = parseInt( config.get( 'wgPopupsFlags' ), 10 ); /* eslint-disable no-bitwise */ diff --git a/src/ext.popups.referencePreviews/constants.js b/src/ext.popups.referencePreviews/constants.js deleted file mode 100644 index 03b0e44de..000000000 --- a/src/ext.popups.referencePreviews/constants.js +++ /dev/null @@ -1,2 +0,0 @@ -export const TYPE_REFERENCE = 'reference'; -export const FETCH_DELAY_REFERENCE_TYPE = 150; // ms. diff --git a/src/ext.popups.referencePreviews/index.js b/src/ext.popups.referencePreviews/index.js deleted file mode 100644 index 361de2f16..000000000 --- a/src/ext.popups.referencePreviews/index.js +++ /dev/null @@ -1,37 +0,0 @@ -import isReferencePreviewsEnabled from './isReferencePreviewsEnabled'; -import { initReferencePreviewsInstrumentation } from './referencePreviews'; -import createReferenceGateway from './createReferenceGateway'; -import renderFn from './createReferencePreview'; -import { TYPE_REFERENCE, FETCH_DELAY_REFERENCE_TYPE } from './constants'; -import setUserConfigFlags from './setUserConfigFlags'; - -const REFERENCE_PREVIEWS_LOGGING_SCHEMA = 'event.ReferencePreviewsPopups'; - -setUserConfigFlags( mw.config ); -const referencePreviewsState = isReferencePreviewsEnabled( - mw.user, mw.popups.isEnabled, - mw.config -); -const gateway = createReferenceGateway(); - -// For tracking baseline stats in the Cite extension https://phabricator.wikimedia.org/T353798 -// FIXME: This might be obsolete when the code moves to the Cite extension and the tracking there -// can check that state differently. -mw.config.set( 'wgPopupsReferencePreviewsVisible', !!referencePreviewsState ); - -mw.trackSubscribe( 'Popups.SettingChange', ( data ) => { - if ( data.previewType === TYPE_REFERENCE ) { - mw.track( REFERENCE_PREVIEWS_LOGGING_SCHEMA, data ); - } -} ); - -window.refPreviews = referencePreviewsState !== null ? { - type: TYPE_REFERENCE, - selector: '#mw-content-text .reference a[ href*="#" ]', - delay: FETCH_DELAY_REFERENCE_TYPE, - gateway, - renderFn, - init: () => { - initReferencePreviewsInstrumentation(); - } -} : null; diff --git a/tests/node-qunit/ext.popups.referencePreviews/gateway.test.js b/tests/node-qunit/ext.popups.referencePreviews/gateway.test.js index a625ca598..b0be5ce91 100644 --- a/tests/node-qunit/ext.popups.referencePreviews/gateway.test.js +++ b/tests/node-qunit/ext.popups.referencePreviews/gateway.test.js @@ -1,5 +1,5 @@ import { createStubTitle } from '../stubs'; -import createReferenceGateway from '../../../src/ext.popups.referencePreviews/createReferenceGateway'; +import createReferenceGateway from '../../../resources/ext.popups.referencePreviews/createReferenceGateway'; QUnit.module( 'ext.popups.referencePreviews/createReferenceGateway', { beforeEach() { diff --git a/tests/node-qunit/ext.popups.referencePreviews/isReferencePreviewsEnabled.test.js b/tests/node-qunit/ext.popups.referencePreviews/isReferencePreviewsEnabled.test.js index 696e529ba..75b694475 100644 --- a/tests/node-qunit/ext.popups.referencePreviews/isReferencePreviewsEnabled.test.js +++ b/tests/node-qunit/ext.popups.referencePreviews/isReferencePreviewsEnabled.test.js @@ -1,5 +1,5 @@ import * as stubs from '../stubs'; -import isReferencePreviewsEnabled from '../../../src/ext.popups.referencePreviews/isReferencePreviewsEnabled'; +import isReferencePreviewsEnabled from '../../../resources/ext.popups.referencePreviews/isReferencePreviewsEnabled'; function createStubUserSettings( expectEnabled ) { return { diff --git a/tests/node-qunit/ext.popups.referencePreviews/renderer.test.js b/tests/node-qunit/ext.popups.referencePreviews/renderer.test.js index 75a5c9040..77e6ba9ef 100644 --- a/tests/node-qunit/ext.popups.referencePreviews/renderer.test.js +++ b/tests/node-qunit/ext.popups.referencePreviews/renderer.test.js @@ -1,12 +1,10 @@ -import * as renderer from '../../../src/ui/renderer'; -import * as constants from '../../../src/constants'; -import { previewTypes } from '../../../src/preview/model'; -import createReferencePreview from '../../../src/ext.popups.referencePreviews/createReferencePreview'; +import createReferencePreview from '../../../resources/ext.popups.referencePreviews/createReferencePreview'; +import { TYPE_REFERENCE } from '../../../resources/ext.popups.referencePreviews/constants'; + +const previewTypes = { TYPE_REFERENCE }; QUnit.module( 'ext.popups.referencePreviews#renderer', { beforeEach() { - this.sandbox.stub( constants.default, 'BRACKETED_DEVICE_PIXEL_RATIO' ).value( 1 ); - mw.msg = ( key ) => `<${ key }>`; mw.message = ( key ) => { return { exists: () => !key.endsWith( 'generic' ), text: () => `<${ key }>` }; @@ -31,22 +29,17 @@ QUnit.module( 'ext.popups.referencePreviews#renderer', { mw.msg = null; mw.message = null; mw.html = null; - renderer.test.reset(); } } ); QUnit.test( 'createReferencePreview(model)', ( assert ) => { - renderer.registerPreviewUI( - previewTypes.TYPE_REFERENCE, - createReferencePreview - ); const model = { url: '#custom_id', extract: 'Custom extract with an internal and an external link', type: previewTypes.TYPE_REFERENCE, referenceType: 'web' }, - preview = renderer.createPreviewWithType( model ); + preview = createReferencePreview( model ); assert.strictEqual( preview.hasThumbnail, false ); assert.strictEqual( preview.isTall, false ); @@ -67,16 +60,12 @@ QUnit.test( 'createReferencePreview(model)', ( assert ) => { } ); QUnit.test( 'createReferencePreview default title', ( assert ) => { - renderer.registerPreviewUI( - previewTypes.TYPE_REFERENCE, - createReferencePreview - ); const model = { url: '', extract: '', type: previewTypes.TYPE_REFERENCE }, - preview = renderer.createPreviewWithType( model ); + preview = createReferencePreview( model ); assert.strictEqual( $( preview.el ).find( '.mwe-popups-title' ).text().trim(), @@ -85,16 +74,12 @@ QUnit.test( 'createReferencePreview default title', ( assert ) => { } ); QUnit.test( 'createReferencePreview updates fade-out effect on scroll', ( assert ) => { - renderer.registerPreviewUI( - previewTypes.TYPE_REFERENCE, - createReferencePreview - ); const model = { url: '', extract: '', type: previewTypes.TYPE_REFERENCE }, - preview = renderer.createPreviewWithType( model ), + preview = createReferencePreview( model ), $extract = $( preview.el ).find( '.mwe-popups-extract' ); $extract.children()[ 0 ].dispatchEvent( new Event( 'scroll' ) ); @@ -104,17 +89,13 @@ QUnit.test( 'createReferencePreview updates fade-out effect on scroll', ( assert } ); QUnit.test( 'createReferencePreview collapsible/sortable handling', ( assert ) => { - renderer.registerPreviewUI( - previewTypes.TYPE_REFERENCE, - createReferencePreview - ); const model = { url: '', extract: '
' + '
', type: previewTypes.TYPE_REFERENCE }, - preview = renderer.createPreviewWithType( model ); + preview = createReferencePreview( model ); assert.strictEqual( $( preview.el ).find( '.mw-collapsible, .sortable, .headerSort' ).length, 0 ); assert.strictEqual( $( preview.el ).find( 'th' ).attr( 'tabindex' ), undefined ); diff --git a/tests/node-qunit/ext.popups.referencePreviews/setUserConfigFlags.test.js b/tests/node-qunit/ext.popups.referencePreviews/setUserConfigFlags.test.js index aaad84932..ab94765a4 100644 --- a/tests/node-qunit/ext.popups.referencePreviews/setUserConfigFlags.test.js +++ b/tests/node-qunit/ext.popups.referencePreviews/setUserConfigFlags.test.js @@ -1,4 +1,4 @@ -import setUserConfigFlags from '../../../src/ext.popups.referencePreviews/setUserConfigFlags'; +import setUserConfigFlags from '../../../resources/ext.popups.referencePreviews/setUserConfigFlags'; QUnit.module( 'ext.popups.referencePreviews#setUserConfigFlags' ); diff --git a/webpack.config.js b/webpack.config.js index c2b51f70b..280036ce5 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -29,8 +29,7 @@ module.exports = ( env, argv ) => ( { context: __dirname, entry: { - index: './src', - referencePreviews: './src/ext.popups.referencePreviews/index.js' + index: './src' }, resolve: {