From eca5308742f239a747bed4fede699ab1255e912f Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 7 Jul 2021 12:21:10 -0700 Subject: [PATCH] Move deserialization into domain and fix tests. --- package.json | 1 + scripts/post-install.js | 9 ++++++++- .../dom => domain/session/room/timeline}/deserialize.js | 5 ++--- src/domain/session/room/timeline/tiles/TextTile.js | 2 +- yarn.lock | 9 ++++++++- 5 files changed, 20 insertions(+), 6 deletions(-) rename src/{platform/web/dom => domain/session/room/timeline}/deserialize.js (97%) diff --git a/package.json b/package.json index 0546f09d..3e9f1a54 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@babel/preset-env": "^7.11.0", "@rollup/plugin-babel": "^5.1.0", "@rollup/plugin-commonjs": "^15.0.0", + "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-multi-entry": "^4.0.0", "@rollup/plugin-node-resolve": "^9.0.0", "autoprefixer": "^10.2.6", diff --git a/scripts/post-install.js b/scripts/post-install.js index 150807c3..4d51cd2e 100644 --- a/scripts/post-install.js +++ b/scripts/post-install.js @@ -22,6 +22,7 @@ const { fileURLToPath } = require('url'); const { dirname } = require('path'); // needed to translate commonjs modules to esm const commonjs = require('@rollup/plugin-commonjs'); +const json = require('@rollup/plugin-json'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); const projectDir = path.join(__dirname, "../"); @@ -53,7 +54,7 @@ async function commonjsToESM(src, dst) { const bundle = await rollup({ treeshake: {moduleSideEffects: false}, input: src, - plugins: [commonjs(), nodeResolve({ + plugins: [commonjs(), json(), nodeResolve({ browser: true, preferBuiltins: false, customResolveOptions: {packageIterator} @@ -77,6 +78,12 @@ async function populateLib() { await fs.symlink(path.join(olmSrcDir, file), path.join(olmDstDir, file)); } // transpile another-json to esm + await fs.mkdir(path.join(libDir, "node-html-parser/")); + await commonjsToESM( + require.resolve('node-html-parser/dist/index.js'), + path.join(libDir, "node-html-parser/index.js") + ); + // transpile another-json to esm await fs.mkdir(path.join(libDir, "another-json/")); await commonjsToESM( require.resolve('another-json/another-json.js'), diff --git a/src/platform/web/dom/deserialize.js b/src/domain/session/room/timeline/deserialize.js similarity index 97% rename from src/platform/web/dom/deserialize.js rename to src/domain/session/room/timeline/deserialize.js index fdf8ae04..420d0010 100644 --- a/src/platform/web/dom/deserialize.js +++ b/src/domain/session/room/timeline/deserialize.js @@ -1,4 +1,4 @@ -import { MessageBody, HeaderBlock, ListBlock, CodeBlock, FormatPart, NewLinePart, RulePart, TextPart, LinkPart } from "../../../domain/session/room/timeline/MessageBody.js" +import { MessageBody, HeaderBlock, ListBlock, CodeBlock, FormatPart, NewLinePart, RulePart, TextPart, LinkPart } from "./MessageBody.js" /* At the time of writing (Jul 1 2021), Matrix Spec recommends @@ -141,8 +141,7 @@ export function parseHTMLBody(platform, html) { return new MessageBody(html, parts); } -import parser from 'node-html-parser'; -const { parse } = parser; +import parse from '../../../../../lib/node-html-parser/index.js'; export class HTMLParseResult { constructor(bodyNode) { diff --git a/src/domain/session/room/timeline/tiles/TextTile.js b/src/domain/session/room/timeline/tiles/TextTile.js index f7e1d8c2..cbd35b72 100644 --- a/src/domain/session/room/timeline/tiles/TextTile.js +++ b/src/domain/session/room/timeline/tiles/TextTile.js @@ -16,7 +16,7 @@ limitations under the License. import {BaseTextTile} from "./BaseTextTile.js"; import {parsePlainBody} from "../MessageBody.js"; -import {parseHTMLBody} from "../../../../../platform/web/dom/deserialize.js"; +import {parseHTMLBody} from "../deserialize.js"; export class TextTile extends BaseTextTile { _getContentString(key, format, fallback = null) { diff --git a/yarn.lock b/yarn.lock index 28a240cc..211749b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -886,6 +886,13 @@ magic-string "^0.25.7" resolve "^1.17.0" +"@rollup/plugin-json@^4.1.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3" + integrity sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw== + dependencies: + "@rollup/pluginutils" "^3.0.8" + "@rollup/plugin-multi-entry@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@rollup/plugin-multi-entry/-/plugin-multi-entry-4.0.0.tgz#8e105f16ec1bb26639eb3302c8db5665f44b9939" @@ -911,7 +918,7 @@ resolved "https://registry.yarnpkg.com/@rollup/plugin-virtual/-/plugin-virtual-2.0.3.tgz#0afc88d75c1e1378ab290b8e9898d4edb5be0d74" integrity sha512-pw6ziJcyjZtntQ//bkad9qXaBx665SgEL8C8KI5wO8G5iU5MPxvdWrQyVaAvjojGm9tJoS8M9Z/EEepbqieYmw== -"@rollup/pluginutils@^3.1.0": +"@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==