From 18d8fbdd69e17fa0e84924ef334c2f54222fa417 Mon Sep 17 00:00:00 2001 From: Badri Sunderarajan Date: Tue, 26 Mar 2024 17:14:21 +0530 Subject: [PATCH] Bump ConverseJS from 9.1.1 to 10.1.7 and *make it work* This was somewhat harder than you'd imagine, because ConverseJS and Strophe have changed a bit in the meantime. Nothing major, but a small change had unintended consequences. Some backstory: we use Rollup for bundling Convo into a format that KaiOS' ageing engine can understand. The bad news: due to a weird bug/issue/something, Rollup doesn't like the UMD format that ConverseJS dependency Strophe bundles into. This bug has been affecting a lot of people and has been extensively documented in issues like this one: https://github.com/rollup/rollup-plugin-commonjs/issues/139 (I think Strophe also bundles into other formats, but for some reason the default one picked by Rollup is dist/strophe.umd.js that it then immediately raises a complaint about). The good news was that @converse/headless was inadvertently sidestepping this issue because it imported the Strophe object from a specific file in Strophe's src like this: import { Strophe } from 'strophe.js/src/strophe'; which completely bypassed the problematic dist folder. Since Rollup eventually bundled everything anyway, reading from source to start with wasn't a problem. The bad news was that, at some point, ConverseJS was updated to use a newer version of Strophe. Unfortunately, the new Strophe had renamed its src/strophe.js to src/index.js: https://github.com/strophe/strophejs/commit/26f94b15f0ba94f9ec49377d7143ce05038decf2 That is in itself a good practice, but it broke the import in @converse/headless, which was still looking for the old file instead of the new one. Not a big problem either; a few days later @converse/headless implemented the best practice of importing straight from 'strophe' instead of trying to specify where exacly to import from, allowing the Strophe package to take on that job: https://github.com/conversejs/converse.js/commit/72f659cd1a4f1eda31c8fecb5ac1bf4290f044e0 The only problem is, that "take it from wherever the package decides" proved disastrous for Convo's Rollup setup, because Rollup stopped looking in src/ at all. Instead, it went straight to the dist/ folder like any sensible bundler would do. Except that the first option in the dist/ folder happened to be the strophe.umd.js file that Rollup had issues with as mentioned in the beginning of this commit message! I didn't know all this backstory at the time. All I knew was that Rollup was producing the somewhat cryptic error: 'Strophe' is not exported by node_modules/strophe.js/dist/strophe.umd.js which made no sense to me because of course it was! With some DuckDuckGo'ing I realised that this is a not uncommon problem with UMD packages in Rollup when using the commonjs plugin. But though the problem was quite common, the workarounds weren't. None of the workarounds (I wouldn't deign to call them solutions) that were described, semi-described, or hinted-at worked for me. After sleeping over it, I decided to inspect the ConverseJS code and see what exacly changed, which is when I realised the whole setup described above. The hacky solution implemented here is to override the clean import { ... } from 'strophe.js'; statements with the more explicit import { ... } from 'strophe.js/src'; ...which is at least somewhat cleaner, given that 'strophe.js/src' automatically resolves to 'strophe.js/src/index.js'. In conclusion: bumping to a newer version of a JavaScript dependency, despite being a seemingly innocous task, can be way more complicated than you'd expect! --- package.json | 2 +- rollup.config.js | 8 ++++ yarn.lock | 110 +++++++++++++++++++---------------------------- 3 files changed, 54 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index 425edd5..2f305a8 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-transform-runtime": "^7.16.4", "@babel/preset-env": "^7.16.4", - "@converse/headless": "^9.1.1", + "@converse/headless": "^10.1.7", "@rollup/plugin-babel": "^5.3.1", "@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-json": "^4.1.0", diff --git a/rollup.config.js b/rollup.config.js index d27b5cb..7b48e57 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -97,6 +97,14 @@ export default { 'process.env.NODE_ENV': !production ? "'development'" : "'production'", }), + replace({ + // Rollup doesn't like strophe.js' UMD bundle, so we will import + // directly from source instead. We assume that the close-parens + // and `from 'strophe.js'` directly follows an `import {` tag. + "} from 'strophe.js';": "} from 'strophe.js/src';", + delimiters: ['', ''], + }), + json(), // If you have external dependencies installed from diff --git a/yarn.lock b/yarn.lock index b3ab3e9..463e5f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1045,38 +1045,45 @@ "@babel/helper-validator-identifier" "^7.18.6" to-fast-properties "^2.0.0" -"@converse/headless@^9.1.1": - version "9.1.1" - resolved "https://registry.yarnpkg.com/@converse/headless/-/headless-9.1.1.tgz#ee163676b89b9523e1e7c7246ad235972a8c3e57" - integrity sha512-in1thm8+Chxzx9MsTBoeRl4YILNQ48ehCH4yXQlvpxeKh9BzuFsL2BIu1tH1BpdF5zPH60tOcC4Zqzk4gSpmOg== +"@converse/headless@^10.1.7": + version "10.1.7" + resolved "https://registry.yarnpkg.com/@converse/headless/-/headless-10.1.7.tgz#20a4ffdb46336a5f208d6c1d78bfdd697fa835a6" + integrity sha512-W0E/0Wdbc5gf/RjgnlhDmE1Bg1KzPBaqLBuLzD2ZW6Ovflb6ZkZOhgVNN5/0ETWnjS+cYyd3oHIOHwx+3kDNPg== dependencies: "@converse/openpromise" "^0.0.1" - "@converse/skeletor" "0.0.7" - dayjs "1.11.1" + "@converse/skeletor" "^0.0.8" + dayjs "^1.11.8" dompurify "^2.3.1" - filesize "^7.0.0" + filesize "^10.0.7" localforage-webextensionstorage-driver "^3.0.0" lodash-es "^4.17.21" pluggable.js "3.0.1" sizzle "^2.3.5" sprintf-js "^1.1.2" - strophe.js "1.5.0" + strophe.js "2.0.0" urijs "^1.19.10" +"@converse/localforage-getitems@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@converse/localforage-getitems/-/localforage-getitems-1.4.3.tgz#476860a6b9ba800f16db36f56787fd3ea176b414" + integrity sha512-ofch1Zv9+CxU4xYxBq+QmsJFKLi6FZ69REPoTc56eeWN6ps0/+g5gD4/gwukEFhAuE8jsBpjcrnizXsa4WsMxQ== + dependencies: + localforage ">=1.4.0" + "@converse/openpromise@0.0.1", "@converse/openpromise@^0.0.1": version "0.0.1" resolved "https://registry.yarnpkg.com/@converse/openpromise/-/openpromise-0.0.1.tgz#cfa352423b6c830df199f824784f2d6b0d9161b1" integrity sha512-oA1TKrm6H838isYZJxMWXpXyOUezkD49eMJ6bkI+FfL2MsVuOV3ZbhBV+c07mLSknKXO7pUbWTVa5f7bXJXYjQ== -"@converse/skeletor@0.0.7": - version "0.0.7" - resolved "https://registry.yarnpkg.com/@converse/skeletor/-/skeletor-0.0.7.tgz#594ebd7102b4425dc72c6e373d142a92b9c96116" - integrity sha512-JqK1lND0R1l9UEH/0cA7AGcP7EzB+NdPoMmCYNHBaSBins7ir+HHsGxw9eIHWJMPNXIN4ERG2oKwUTwVLryxmA== +"@converse/skeletor@^0.0.8": + version "0.0.8" + resolved "https://registry.yarnpkg.com/@converse/skeletor/-/skeletor-0.0.8.tgz#3f817239bfa6942f28b61a35077dd8cf892cbdf3" + integrity sha512-8/wAenuk7QKOHaOsk89e5zFyQZz5HhsuqWBzrzDxmepiBVlRvnxjVdB6619IFyW0VWf0ezcm5Rl4JndUx2sbqg== dependencies: + "@converse/localforage-getitems" "1.4.3" lit-html "^2.0.0-rc.2" localforage "^1.10.0" localforage-driver-memory "^1.0.5" - localforage-getitems conversejs/localForage-getItems#0f129c5c9bb0d23f8dbb64c9dfbb003c8cdf7285 localforage-setitems "^1.4.0" lodash-es "^4.17.21" mergebounce "0.1.1" @@ -1264,10 +1271,17 @@ resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.2.tgz#fc25ad9943bcac11cceb8168db4f275e0e72e756" integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg== -"@xmldom/xmldom@0.8.2": - version "0.8.2" - resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.8.2.tgz#b695ff674e8216efa632a3d36ad51ae9843380c0" - integrity sha512-+R0juSseERyoPvnBQ/cZih6bpF7IpCXlWbHRoCRzYzqpz6gWHOgf8o4MOEf6KBVuOyqU+gCNLkCWVIJAro8XyQ== +"@types/ws@^8.5.5": + version "8.5.10" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787" + integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A== + dependencies: + "@types/node" "*" + +"@xmldom/xmldom@0.8.8": + version "0.8.8" + resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.8.8.tgz#d0d11511cbc1de77e53342ad1546a4d487d6ea72" + integrity sha512-0LNz4EY8B/8xXY86wMrQ4tz6zEHZv9ehFMJPm8u2gq5lQ71cfRKdaKyxfJAx5aUoyzx0qzgURblTisPGgz3d+Q== abab@^2.0.3: version "2.0.6" @@ -1441,21 +1455,6 @@ chalk@^4.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chokidar@^3.3.1: - version "3.5.3" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" - integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== - dependencies: - anymatch "~3.1.2" - braces "~3.0.2" - glob-parent "~5.1.2" - is-binary-path "~2.1.0" - is-glob "~4.0.1" - normalize-path "~3.0.0" - readdirp "~3.6.0" - optionalDependencies: - fsevents "~2.3.2" - chokidar@^3.4.1, chokidar@^3.5.0: version "3.5.2" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" @@ -1540,15 +1539,10 @@ core-js@^3.25.1: resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.25.1.tgz#5818e09de0db8956e16bf10e2a7141e931b7c69c" integrity sha512-sr0FY4lnO1hkQ4gLDr24K0DGnweGO1QwSj5BpfQjpSJPdqWalja4cTps29Y/PJVG/P7FYlPDkH3hO+Tr0CvDgQ== -dayjs@1.11.1: - version "1.11.1" - resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.1.tgz#90b33a3dda3417258d48ad2771b415def6545eb0" - integrity sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA== - -debounce@^1.2.0: - version "1.2.1" - resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.1.tgz#38881d8f4166a5c5848020c11827b834bcb3e0a5" - integrity sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug== +dayjs@^1.11.8: + version "1.11.10" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.10.tgz#68acea85317a6e164457d6d6947564029a6a16a0" + integrity sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ== debug@^4.1.0, debug@^4.1.1: version "4.3.2" @@ -1642,10 +1636,10 @@ fastq@^1.6.0: dependencies: reusify "^1.0.4" -filesize@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/filesize/-/filesize-7.0.0.tgz#9d4b3ce384ec7731a9e68c64ee29fb4934ad657d" - integrity sha512-Wsstw+O1lZ9gVmOI1thyeQvODsaoId2qw14lCqIzUhoHKXX7T2hVpB7BR6SvgodMBgWccrx/y2eyV8L7tDmY6A== +filesize@^10.0.7: + version "10.1.1" + resolved "https://registry.yarnpkg.com/filesize/-/filesize-10.1.1.tgz#eb98ce885aa73741199748e70e5b7339cc22c5ff" + integrity sha512-L0cdwZrKlwZQkMSFnCflJ6J2Y+5egO/p3vgRSDQGxQt++QbUZe5gMbRO6kg6gzwQDPvq2Fk9AmoxUNfZ5gdqaQ== fill-range@^7.0.1: version "7.0.1" @@ -1837,14 +1831,6 @@ json5@^2.2.1: resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c" integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA== -karma-rollup-preprocessor@^7.0.8: - version "7.0.8" - resolved "https://registry.yarnpkg.com/karma-rollup-preprocessor/-/karma-rollup-preprocessor-7.0.8.tgz#5cf5ca22c815afce1ba876b56da81e81e989823e" - integrity sha512-WiuBCS9qsatJuR17dghiTARBZ7LF+ml+eb7qJXhw7IbsdY0lTWELDRQC/93J9i6636CsAXVBL3VJF4WtaFLZzA== - dependencies: - chokidar "^3.3.1" - debounce "^1.2.0" - kleur@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" @@ -1914,12 +1900,6 @@ localforage-driver-memory@^1.0.5: localforage-driver-commons "^1.0.1" tslib "^1.6.0" -localforage-getitems@conversejs/localForage-getItems#0f129c5c9bb0d23f8dbb64c9dfbb003c8cdf7285: - version "1.4.2" - resolved "https://codeload.github.com/conversejs/localForage-getItems/tar.gz/0f129c5c9bb0d23f8dbb64c9dfbb003c8cdf7285" - dependencies: - localforage ">=1.4.0" - localforage-setitems@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/localforage-setitems/-/localforage-setitems-1.4.0.tgz#36b8590d507dfb5c804033e287ece58d88996d5f" @@ -2409,15 +2389,15 @@ strip-indent@^3.0.0: dependencies: min-indent "^1.0.0" -strophe.js@1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/strophe.js/-/strophe.js-1.5.0.tgz#2cdea512286a6bfc5372afae100873241f5c7e61" - integrity sha512-H5tE/tZxPR5xP3jhXyQwsjnMSwQMf7vrn9r1OkufTApyGHYe8WjzhsfxtL3AFhVu7vFjXPPZBrmUOTm1ccYgOA== +strophe.js@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/strophe.js/-/strophe.js-2.0.0.tgz#1605076e9578bbf6abd46dcb257e69266619a3fa" + integrity sha512-2YKE5Lbjg3H+X5f2tIApmf/5WUZ8cGnWlaIvLMZ3ksKtCN7ib5VhNU53DPzSqhV4JgXbb6jGPj0Jv8Un/fOORQ== dependencies: abab "^2.0.3" - karma-rollup-preprocessor "^7.0.8" optionalDependencies: - "@xmldom/xmldom" "0.8.2" + "@types/ws" "^8.5.5" + "@xmldom/xmldom" "0.8.8" ws "^8.5.0" supports-color@^5.3.0: