From 8922d2aaf2c83b505f23cea8386093d3725b0f3e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 1 Dec 2021 18:58:19 +0100 Subject: [PATCH 01/18] prototype of sdk build --- sdk-vite.config.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 sdk-vite.config.js diff --git a/sdk-vite.config.js b/sdk-vite.config.js new file mode 100644 index 00000000..87eea633 --- /dev/null +++ b/sdk-vite.config.js @@ -0,0 +1,88 @@ +const cssvariables = require("postcss-css-variables"); +const autoprefixer = require("autoprefixer"); +const flexbugsFixes = require("postcss-flexbugs-fixes"); + +const fs = require("fs"); +const path = require("path"); + +const injectWebManifest = require("./scripts/build-plugins/manifest"); +const injectServiceWorker = require("./scripts/build-plugins/service-worker"); +// const legacyBuild = require("./scripts/build-plugins/legacy-build"); + +// we could also just import {version} from "../../package.json" where needed, +// but this won't work in the service worker yet as it is not transformed yet +// TODO: we should emit a chunk early on and then transform the asset again once we know all the other assets to cache +const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version; +const {defineConfig} = require("vite"); + +const srcDir = path.join(__dirname, "src/"); +const modulesDir = path.join(srcDir, "node_modules/"); +const mocksDir = path.join(srcDir, "mocks/"); +const fixturesDir = path.join(srcDir, "fixtures/"); + +export default { + public: false, + root: "src/", + server: { + hmr: false + }, + resolve: { + alias: { + // these should only be imported by the base-x package in any runtime code + // and works in the browser with a Uint8Array shim, + // rather than including a ton of polyfill code + "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", + "buffer": "./scripts/package-overrides/buffer/index.js", + } + }, + build: { + outDir: "../target", + lib: { + entry: "lib.ts", + name: "hydrogen", + formats: ["cjs", "es"] + }, + emptyOutDir: true, + sourcemap: false, + assetsInlineLimit: 0, + polyfillModulePreload: false, + rollupOptions: { + external: id => id.startsWith(modulesDir) || id.startsWith(mocksDir) || id.startsWith(fixturesDir), + output: { + manualChunks: (id) => { + if (id.startsWith(srcDir)) { + const idPath = id.substring(srcDir.length); + const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf(".")); + return pathWithoutExt; + } else { + console.log("putting", id.substring(srcDir.length), "in index"); + return "index"; + } + }, + chunkFileNames: `[format]/[name].js`, + } + } + }, + define: { + "HYDROGEN_VERSION": JSON.stringify(version) + }, + css: { + postcss: { + plugins: [ + cssvariables({ + preserve: (declaration) => { + return declaration.value.indexOf("var(--ios-") == 0; + } + }), + // the grid option creates some source fragment that causes the vite warning reporter to crash because + // it wants to log a warning on a line that does not exist in the source fragment. + // autoprefixer({overrideBrowserslist: ["IE 11"], grid: "no-autoplace"}), + flexbugsFixes() + ] + } + } +}; + +function scriptTagPath(htmlFile, index) { + return `${htmlFile}?html-proxy&index=${index}.js`; +} From 363cd5b04617876296fb1da4a49c2e6230fad884 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 1 Dec 2021 18:58:33 +0100 Subject: [PATCH 02/18] include css --- src/lib.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.ts b/src/lib.ts index 27290fb5..a4a9f4c5 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -31,3 +31,6 @@ export {RoomViewModel} from "./domain/session/room/RoomViewModel.js"; export {RoomView} from "./platform/web/ui/session/room/RoomView.js"; export {TimelineViewModel} from "./domain/session/room/timeline/TimelineViewModel.js"; export {TimelineView} from "./platform/web/ui/session/room/TimelineView"; + +export * from "./platform/web/ui/css/main.css"; +export * from "./platform/web/ui/css/themes/element/theme.css"; From 2d2005934a63b29f1f2d9efad4e8dd01682bc9ec Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 9 Dec 2021 19:25:10 +0100 Subject: [PATCH 03/18] WIP --- sdk-vite.config.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sdk-vite.config.js b/sdk-vite.config.js index 87eea633..5e896421 100644 --- a/sdk-vite.config.js +++ b/sdk-vite.config.js @@ -1,5 +1,4 @@ const cssvariables = require("postcss-css-variables"); -const autoprefixer = require("autoprefixer"); const flexbugsFixes = require("postcss-flexbugs-fixes"); const fs = require("fs"); @@ -37,15 +36,16 @@ export default { }, build: { outDir: "../target", + emptyOutDir: true, + minify: false, + sourcemap: false, + assetsInlineLimit: 0, + polyfillModulePreload: false, lib: { entry: "lib.ts", name: "hydrogen", formats: ["cjs", "es"] }, - emptyOutDir: true, - sourcemap: false, - assetsInlineLimit: 0, - polyfillModulePreload: false, rollupOptions: { external: id => id.startsWith(modulesDir) || id.startsWith(mocksDir) || id.startsWith(fixturesDir), output: { @@ -60,11 +60,12 @@ export default { } }, chunkFileNames: `[format]/[name].js`, + // preserveModules: true, } } }, define: { - "HYDROGEN_VERSION": JSON.stringify(version) + "DEFINE_VERSION": JSON.stringify(version) }, css: { postcss: { From f2b822e5d29ffc2fae5027bd969ab32b104d88d7 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 10 Dec 2021 16:02:34 +0100 Subject: [PATCH 04/18] move deps that are not used for sdk to devDependencies --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d90747ab..46faf089 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ "devDependencies": { "@typescript-eslint/eslint-plugin": "^4.29.2", "@typescript-eslint/parser": "^4.29.2", + "aes-js": "^3.1.2", "core-js": "^3.6.5", + "es6-promise": "https://github.com/bwindels/es6-promise.git#bwindels/expose-flush", "eslint": "^7.32.0", "fake-indexeddb": "^3.1.2", "impunity": "^1.0.9", @@ -36,18 +38,16 @@ "postcss-css-variables": "^0.18.0", "postcss-flexbugs-fixes": "^5.0.2", "regenerator-runtime": "^0.13.7", + "text-encoding": "^0.7.0", "typescript": "^4.3.5", "vite": "^2.6.14", "xxhashjs": "^0.2.2" }, "dependencies": { "@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.3.tgz", - "aes-js": "^3.1.2", "another-json": "^0.2.0", "base64-arraybuffer": "^0.2.0", "bs58": "^4.0.1", - "dompurify": "^2.3.0", - "es6-promise": "https://github.com/bwindels/es6-promise.git#bwindels/expose-flush", - "text-encoding": "^0.7.0" + "dompurify": "^2.3.0" } } From c11f0774eba98f3bc47fa0bb3189cac1c534fb3d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 10 Dec 2021 16:03:17 +0100 Subject: [PATCH 05/18] move common parts of build config to separate file and merge with it --- package.json | 1 + vite.common-config.js | 50 +++++++++++++++++++++++++++++++++++++++ vite.config.js | 55 ++++--------------------------------------- yarn.lock | 12 ++++++++++ 4 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 vite.common-config.js diff --git a/package.json b/package.json index 46faf089..59c10352 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "fake-indexeddb": "^3.1.2", "impunity": "^1.0.9", "mdn-polyfills": "^5.20.0", + "merge-options": "^3.0.4", "node-html-parser": "^4.0.0", "postcss-css-variables": "^0.18.0", "postcss-flexbugs-fixes": "^5.0.2", diff --git a/vite.common-config.js b/vite.common-config.js new file mode 100644 index 00000000..b120ee59 --- /dev/null +++ b/vite.common-config.js @@ -0,0 +1,50 @@ +const cssvariables = require("postcss-css-variables"); +const flexbugsFixes = require("postcss-flexbugs-fixes"); +const fs = require("fs"); +const path = require("path"); +const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version; + +const commonOptions = { + logLevel: "warn", + public: false, + server: { + hmr: false + }, + resolve: { + alias: { + // these should only be imported by the base-x package in any runtime code + // and works in the browser with a Uint8Array shim, + // rather than including a ton of polyfill code + "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", + "buffer": "./scripts/package-overrides/buffer/index.js", + } + }, + build: { + emptyOutDir: true, + minify: true, + sourcemap: true, + assetsInlineLimit: 0, + polyfillModulePreload: false, + }, + define: { + DEFINE_VERSION: JSON.stringify(version), + DEFINE_GLOBAL_HASH: JSON.stringify(null), + }, + css: { + postcss: { + plugins: [ + cssvariables({ + preserve: (declaration) => { + return declaration.value.indexOf("var(--ios-") == 0; + } + }), + // the grid option creates some source fragment that causes the vite warning reporter to crash because + // it wants to log a warning on a line that does not exist in the source fragment. + // autoprefixer({overrideBrowserslist: ["IE 11"], grid: "no-autoplace"}), + flexbugsFixes() + ] + } + } +}; + +module.exports = commonOptions; diff --git a/vite.config.js b/vite.config.js index 1562269e..f3f43be2 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,39 +1,16 @@ -const cssvariables = require("postcss-css-variables"); -const flexbugsFixes = require("postcss-flexbugs-fixes"); - -const fs = require("fs"); -const path = require("path"); - const injectWebManifest = require("./scripts/build-plugins/manifest"); const {injectServiceWorker, createPlaceholderValues} = require("./scripts/build-plugins/service-worker"); const {defineConfig} = require('vite'); -const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version; +const mergeOptions = require('merge-options').bind({concatArrays: true}); +const commonOptions = require("./vite.common-config.js"); export default defineConfig(({mode}) => { const definePlaceholders = createPlaceholderValues(mode); - return { - public: false, + return mergeOptions(commonOptions, { root: "src/platform/web", base: "./", - server: { - hmr: false - }, - resolve: { - alias: { - // these should only be imported by the base-x package in any runtime code - // and works in the browser with a Uint8Array shim, - // rather than including a ton of polyfill code - "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", - "buffer": "./scripts/package-overrides/buffer/index.js", - } - }, build: { outDir: "../../../target", - emptyOutDir: true, - minify: true, - sourcemap: true, - assetsInlineLimit: 0, - polyfillModulePreload: false, }, plugins: [ // important this comes before service worker @@ -45,28 +22,6 @@ export default defineConfig(({mode}) => { "sw": definePlaceholders }), ], - define: { - DEFINE_VERSION: JSON.stringify(version), - ...definePlaceholders - }, - css: { - postcss: { - plugins: [ - cssvariables({ - preserve: (declaration) => { - return declaration.value.indexOf("var(--ios-") == 0; - } - }), - // the grid option creates some source fragment that causes the vite warning reporter to crash because - // it wants to log a warning on a line that does not exist in the source fragment. - // autoprefixer({overrideBrowserslist: ["IE 11"], grid: "no-autoplace"}), - flexbugsFixes() - ] - } - } - }; + define: definePlaceholders, + }); }); - -function scriptTagPath(htmlFile, index) { - return `${htmlFile}?html-proxy&index=${index}.js`; -} diff --git a/yarn.lock b/yarn.lock index 87d39fac..c564dbe5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -963,6 +963,11 @@ is-number@^7.0.0: resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== +is-plain-obj@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287" + integrity sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA== + isexe@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" @@ -1036,6 +1041,13 @@ mdn-polyfills@^5.20.0: resolved "https://registry.yarnpkg.com/mdn-polyfills/-/mdn-polyfills-5.20.0.tgz#ca8247edf20a4f60dec6804372229812b348260b" integrity sha512-AbTv1ytcoOUAkxw6u5oo2QPf27kEZgxBAQr49jFb4i2VnTnFGfJbcIQ9UDBOdfNECeXsgkYFwB2BkdeTfOzztw== +merge-options@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/merge-options/-/merge-options-3.0.4.tgz#84709c2aa2a4b24c1981f66c179fe5565cc6dbb7" + integrity sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ== + dependencies: + is-plain-obj "^2.1.0" + merge2@^1.3.0: version "1.4.1" resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" From df6000c706abdf5eaf0c6dea93d7ae7976cbd314 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 10 Dec 2021 16:03:34 +0100 Subject: [PATCH 06/18] basic sdk build config file for es and cjs --- sdk-vite.config.js | 74 +++++++++------------------------------------- 1 file changed, 14 insertions(+), 60 deletions(-) diff --git a/sdk-vite.config.js b/sdk-vite.config.js index 5e896421..b95470f5 100644 --- a/sdk-vite.config.js +++ b/sdk-vite.config.js @@ -1,53 +1,27 @@ -const cssvariables = require("postcss-css-variables"); -const flexbugsFixes = require("postcss-flexbugs-fixes"); - -const fs = require("fs"); const path = require("path"); - -const injectWebManifest = require("./scripts/build-plugins/manifest"); -const injectServiceWorker = require("./scripts/build-plugins/service-worker"); -// const legacyBuild = require("./scripts/build-plugins/legacy-build"); - -// we could also just import {version} from "../../package.json" where needed, -// but this won't work in the service worker yet as it is not transformed yet -// TODO: we should emit a chunk early on and then transform the asset again once we know all the other assets to cache -const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version; -const {defineConfig} = require("vite"); +const mergeOptions = require('merge-options').bind({concatArrays: true}); +const commonOptions = require("./vite.common-config.js"); const srcDir = path.join(__dirname, "src/"); const modulesDir = path.join(srcDir, "node_modules/"); const mocksDir = path.join(srcDir, "mocks/"); const fixturesDir = path.join(srcDir, "fixtures/"); -export default { - public: false, + +export default mergeOptions(commonOptions, { root: "src/", - server: { - hmr: false - }, - resolve: { - alias: { - // these should only be imported by the base-x package in any runtime code - // and works in the browser with a Uint8Array shim, - // rather than including a ton of polyfill code - "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", - "buffer": "./scripts/package-overrides/buffer/index.js", - } - }, build: { outDir: "../target", - emptyOutDir: true, - minify: false, - sourcemap: false, - assetsInlineLimit: 0, - polyfillModulePreload: false, lib: { entry: "lib.ts", - name: "hydrogen", + fileName: "hydrogen", formats: ["cjs", "es"] }, rollupOptions: { - external: id => id.startsWith(modulesDir) || id.startsWith(mocksDir) || id.startsWith(fixturesDir), + external: (id, parentId) => { + const resolveId = (id.startsWith("./") || id.startsWith("../")) ? path.join(path.dirname(parentId), id) : id; + return !resolveId.startsWith(srcDir) || resolveId.startsWith(mocksDir) || resolveId.startsWith(fixturesDir); + }, output: { manualChunks: (id) => { if (id.startsWith(srcDir)) { @@ -55,35 +29,15 @@ export default { const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf(".")); return pathWithoutExt; } else { - console.log("putting", id.substring(srcDir.length), "in index"); return "index"; } }, chunkFileNames: `[format]/[name].js`, - // preserveModules: true, + // important to preserve export names of every module + // so we can still override the file and provider alternative impls + minifyInternalExports: false, + preferConst: true, } } }, - define: { - "DEFINE_VERSION": JSON.stringify(version) - }, - css: { - postcss: { - plugins: [ - cssvariables({ - preserve: (declaration) => { - return declaration.value.indexOf("var(--ios-") == 0; - } - }), - // the grid option creates some source fragment that causes the vite warning reporter to crash because - // it wants to log a warning on a line that does not exist in the source fragment. - // autoprefixer({overrideBrowserslist: ["IE 11"], grid: "no-autoplace"}), - flexbugsFixes() - ] - } - } -}; - -function scriptTagPath(htmlFile, index) { - return `${htmlFile}?html-proxy&index=${index}.js`; -} +}); From 14b854ad4f2245c4e441ba9e209d77cf620a2694 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 10 Dec 2021 19:13:44 +0100 Subject: [PATCH 07/18] make tsconfig file to build declaration files --- tsconfig-declaration.json | 14 ++++++++++++++ tsconfig.json | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tsconfig-declaration.json diff --git a/tsconfig-declaration.json b/tsconfig-declaration.json new file mode 100644 index 00000000..8ba13448 --- /dev/null +++ b/tsconfig-declaration.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "emitDeclarationOnly": true, + "declaration": true, + "outDir": "dist/types", + "rootDir": "src" + }, + "exclude": [ + "src/sdk/paths/*" + ], + "include": ["src/**/*"], +} diff --git a/tsconfig.json b/tsconfig.json index e3fae938..f46cc7eb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,12 @@ { "compilerOptions": { "strictNullChecks": true, + "noImplicitAny": false, "noEmit": true, "target": "ES2020", - "moduleResolution": "node" + "module": "ES2020", + "moduleResolution": "node", + "esModuleInterop": true }, "exclude": [ "src/sdk/paths/*" From ceb0b5793ba7561f4befefb94e3679ca3a7fb2d2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 17 Dec 2021 14:28:25 +0100 Subject: [PATCH 08/18] somewhat works, but not everything we need it's missing still: - non-css assets like the download sandbox and the olm worker aren't written for some reason - the es and cjs lib.js entry points end up in assets with a hash for some reason - in these entry files, apart from our exports, something is adding an import statement for every import that was found in the tree - all assets are hashed even though the config tries to disable that - tests are included --- package.json | 4 +- scripts/build-plugins/service-worker.js | 4 +- scripts/sdk/build.sh | 3 ++ scripts/sdk/create-manifest.js | 21 +++++++++ sdk-vite.config.js | 43 ----------------- src/foo-index.html | 16 +++++++ src/lib.ts | 6 +++ tsconfig-declaration.json | 2 +- vite.common-config.js | 4 +- vite.config.js | 2 + vite.sdk-config.js | 63 +++++++++++++++++++++++++ 11 files changed, 118 insertions(+), 50 deletions(-) create mode 100755 scripts/sdk/build.sh create mode 100755 scripts/sdk/create-manifest.js delete mode 100644 sdk-vite.config.js create mode 100644 src/foo-index.html create mode 100644 vite.sdk-config.js diff --git a/package.json b/package.json index 59c10352..b6299896 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "hydrogen-web", "version": "0.2.22", "description": "A javascript matrix client prototype, trying to minize RAM usage by offloading as much as possible to IndexedDB", - "main": "src/lib.ts", "directories": { "doc": "doc" }, @@ -12,7 +11,8 @@ "lint-ci": "eslint src/", "test": "impunity --entry-point src/platform/web/main.js src/platform/web/Platform.js --force-esm-dirs lib/ src/ --root-dir src/", "start": "vite --port 3000", - "build": "vite build" + "build": "vite build", + "build:sdk": "./scripts/sdk/build.sh" }, "repository": { "type": "git", diff --git a/scripts/build-plugins/service-worker.js b/scripts/build-plugins/service-worker.js index 19ae793f..805f6000 100644 --- a/scripts/build-plugins/service-worker.js +++ b/scripts/build-plugins/service-worker.js @@ -12,6 +12,7 @@ function injectServiceWorker(swFile, otherUnhashedFiles, placeholdersPerChunk) { const swName = path.basename(swFile); let root; let version; + let logger; return { name: "hydrogen:injectServiceWorker", @@ -27,6 +28,7 @@ function injectServiceWorker(swFile, otherUnhashedFiles, placeholdersPerChunk) { configResolved: config => { root = config.root; version = JSON.parse(config.define.DEFINE_VERSION); // unquote + logger = config.logger; }, generateBundle: async function(options, bundle) { const unhashedFilenames = [swName].concat(otherUnhashedFiles); @@ -46,7 +48,7 @@ function injectServiceWorker(swFile, otherUnhashedFiles, placeholdersPerChunk) { ...getCacheFileNamePlaceholderValues(swName, unhashedFilenames, assets, placeholdersPerChunk) }; replacePlaceholdersInChunks(assets, placeholdersPerChunk, placeholderValues); - console.log(`\nBuilt ${version} (${globalHash})`); + logger.info(`\nBuilt ${version} (${globalHash})`); } }; } diff --git a/scripts/sdk/build.sh b/scripts/sdk/build.sh new file mode 100755 index 00000000..71c98438 --- /dev/null +++ b/scripts/sdk/build.sh @@ -0,0 +1,3 @@ +yarn run vite build -c vite.sdk-config.js +yarn tsc -p tsconfig-declaration.json +./scripts/sdk/create-manifest.js ./target/package.json diff --git a/scripts/sdk/create-manifest.js b/scripts/sdk/create-manifest.js new file mode 100755 index 00000000..93074c55 --- /dev/null +++ b/scripts/sdk/create-manifest.js @@ -0,0 +1,21 @@ +#!/usr/bin/env node +const fs = require("fs"); +const baseManifest = JSON.parse(fs.readFileSync("package.json", "utf8")); +const mergeOptions = require('merge-options'); + +const manifestExtension = { + name: "hydrogen-sdk", + main: "./hydrogen.cjs.js", + exports: { + import: "./hydrogen.es.js", + require: "./hydrogen.cjs.js" + }, + files: [], + types: "types/lib.d.ts", + devDependencies: undefined, + scripts: undefined, +}; +const manifest = mergeOptions(baseManifest, manifestExtension); +const json = JSON.stringify(manifest, undefined, 2); +const outFile = process.argv[2]; +fs.writeFileSync(outFile, json, {encoding: "utf8"}); diff --git a/sdk-vite.config.js b/sdk-vite.config.js deleted file mode 100644 index b95470f5..00000000 --- a/sdk-vite.config.js +++ /dev/null @@ -1,43 +0,0 @@ -const path = require("path"); -const mergeOptions = require('merge-options').bind({concatArrays: true}); -const commonOptions = require("./vite.common-config.js"); - -const srcDir = path.join(__dirname, "src/"); -const modulesDir = path.join(srcDir, "node_modules/"); -const mocksDir = path.join(srcDir, "mocks/"); -const fixturesDir = path.join(srcDir, "fixtures/"); - - -export default mergeOptions(commonOptions, { - root: "src/", - build: { - outDir: "../target", - lib: { - entry: "lib.ts", - fileName: "hydrogen", - formats: ["cjs", "es"] - }, - rollupOptions: { - external: (id, parentId) => { - const resolveId = (id.startsWith("./") || id.startsWith("../")) ? path.join(path.dirname(parentId), id) : id; - return !resolveId.startsWith(srcDir) || resolveId.startsWith(mocksDir) || resolveId.startsWith(fixturesDir); - }, - output: { - manualChunks: (id) => { - if (id.startsWith(srcDir)) { - const idPath = id.substring(srcDir.length); - const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf(".")); - return pathWithoutExt; - } else { - return "index"; - } - }, - chunkFileNames: `[format]/[name].js`, - // important to preserve export names of every module - // so we can still override the file and provider alternative impls - minifyInternalExports: false, - preferConst: true, - } - } - }, -}); diff --git a/src/foo-index.html b/src/foo-index.html new file mode 100644 index 00000000..c6bfa098 --- /dev/null +++ b/src/foo-index.html @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/src/lib.ts b/src/lib.ts index a4a9f4c5..6a5f6581 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -32,5 +32,11 @@ export {RoomView} from "./platform/web/ui/session/room/RoomView.js"; export {TimelineViewModel} from "./domain/session/room/timeline/TimelineViewModel.js"; export {TimelineView} from "./platform/web/ui/session/room/TimelineView"; +// @ts-ignore export * from "./platform/web/ui/css/main.css"; +// @ts-ignore export * from "./platform/web/ui/css/themes/element/theme.css"; +// @ts-ignore +import _downloadSandboxPath from "./platform/web/assets/download-sandbox.html?url"; +// @ts-ignore +import _workerPath from "./platform/web/worker/main.js?url"; diff --git a/tsconfig-declaration.json b/tsconfig-declaration.json index 8ba13448..472e1698 100644 --- a/tsconfig-declaration.json +++ b/tsconfig-declaration.json @@ -4,7 +4,7 @@ "noEmit": false, "emitDeclarationOnly": true, "declaration": true, - "outDir": "dist/types", + "outDir": "target/types", "rootDir": "src" }, "exclude": [ diff --git a/vite.common-config.js b/vite.common-config.js index b120ee59..39b2845b 100644 --- a/vite.common-config.js +++ b/vite.common-config.js @@ -5,7 +5,7 @@ const path = require("path"); const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version; const commonOptions = { - logLevel: "warn", + logLevel: "info", public: false, server: { hmr: false @@ -21,8 +21,6 @@ const commonOptions = { }, build: { emptyOutDir: true, - minify: true, - sourcemap: true, assetsInlineLimit: 0, polyfillModulePreload: false, }, diff --git a/vite.config.js b/vite.config.js index f3f43be2..b6ec597d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -11,6 +11,8 @@ export default defineConfig(({mode}) => { base: "./", build: { outDir: "../../../target", + minify: true, + sourcemap: true, }, plugins: [ // important this comes before service worker diff --git a/vite.sdk-config.js b/vite.sdk-config.js new file mode 100644 index 00000000..afeabbaa --- /dev/null +++ b/vite.sdk-config.js @@ -0,0 +1,63 @@ +const path = require("path"); +const mergeOptions = require('merge-options').bind({concatArrays: true}); +const commonOptions = require("./vite.common-config.js"); + +const srcDir = path.join(__dirname, "src/"); +const modulesDir = path.join(srcDir, "node_modules/"); +const mocksDir = path.join(srcDir, "mocks/"); +const fixturesDir = path.join(srcDir, "fixtures/"); + +const commonOutput = { + manualChunks: (id) => { + if (id.endsWith("/lib.ts")) { + console.log(id, arguments); + return "es/lib"; + } + if (id.startsWith(srcDir)) { + const idPath = id.substring(srcDir.length); + const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf(".")); + return pathWithoutExt; + } else { + return "index"; + } + }, + chunkFileNames: `[format]/[name].js`, + assetFileNames: `assets/[name][extname]`, + // important to preserve export names of every module + // so we can still override the file and provider alternative impls + minifyInternalExports: false, + preferConst: true, +}; + +export default mergeOptions(commonOptions, { + root: "src/", + plugins: [ + { + name: "showconfig", + buildStart(rollupOptions) { + console.dir(rollupOptions, {depth: 100}); + }, + resolveId(source, importer) { + console.log(source, importer); + } + } + ], + build: { + minify: false, + sourcemap: false, + outDir: "../target", + rollupOptions: { + input: "./src/lib.ts", + treeshake: false, + external: (id, parentId) => { + const resolveId = (id.startsWith("./") || id.startsWith("../")) ? path.join(path.dirname(parentId), id) : id; + return !resolveId.startsWith(srcDir) || resolveId.startsWith(mocksDir) || resolveId.startsWith(fixturesDir); + }, + preserveEntrySignatures: "strict", + output: [ + Object.assign({}, commonOutput, {format: "es"}), + Object.assign({}, commonOutput, {format: "cjs"}), + ] + } + }, +}); From 6add3f1da35a1f0fd455d571683f83c7dde5f1ae Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 17 Dec 2021 16:13:26 +0100 Subject: [PATCH 09/18] WIP --- vite.common-config.js | 3 ++- vite.sdk-config.js | 37 +++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/vite.common-config.js b/vite.common-config.js index 39b2845b..08d17b3a 100644 --- a/vite.common-config.js +++ b/vite.common-config.js @@ -2,7 +2,8 @@ const cssvariables = require("postcss-css-variables"); const flexbugsFixes = require("postcss-flexbugs-fixes"); const fs = require("fs"); const path = require("path"); -const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version; +const manifest = require("./package.json"); +const version = manifest.version; const commonOptions = { logLevel: "info", diff --git a/vite.sdk-config.js b/vite.sdk-config.js index afeabbaa..194513fb 100644 --- a/vite.sdk-config.js +++ b/vite.sdk-config.js @@ -1,6 +1,7 @@ const path = require("path"); const mergeOptions = require('merge-options').bind({concatArrays: true}); const commonOptions = require("./vite.common-config.js"); +const manifest = require("./package.json"); const srcDir = path.join(__dirname, "src/"); const modulesDir = path.join(srcDir, "node_modules/"); @@ -8,19 +9,19 @@ const mocksDir = path.join(srcDir, "mocks/"); const fixturesDir = path.join(srcDir, "fixtures/"); const commonOutput = { - manualChunks: (id) => { - if (id.endsWith("/lib.ts")) { - console.log(id, arguments); - return "es/lib"; - } - if (id.startsWith(srcDir)) { - const idPath = id.substring(srcDir.length); - const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf(".")); - return pathWithoutExt; - } else { - return "index"; - } - }, + // manualChunks: (id) => { + // if (id.endsWith("/lib.ts")) { + // console.log(id, arguments); + // return "es/lib"; + // } + // if (id.startsWith(srcDir)) { + // const idPath = id.substring(srcDir.length); + // const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf(".")); + // return pathWithoutExt; + // } else { + // return "index"; + // } + // }, chunkFileNames: `[format]/[name].js`, assetFileNames: `assets/[name][extname]`, // important to preserve export names of every module @@ -29,6 +30,9 @@ const commonOutput = { preferConst: true, }; +const externalDependencies = Object.keys(manifest.dependencies).concat(Object.keys(manifest.devDependencies)).filter(d => d !== "@matrix-org/olm").map(d => path.join(__dirname, "node_modules", d)); +console.log("external", externalDependencies); + export default mergeOptions(commonOptions, { root: "src/", plugins: [ @@ -51,7 +55,12 @@ export default mergeOptions(commonOptions, { treeshake: false, external: (id, parentId) => { const resolveId = (id.startsWith("./") || id.startsWith("../")) ? path.join(path.dirname(parentId), id) : id; - return !resolveId.startsWith(srcDir) || resolveId.startsWith(mocksDir) || resolveId.startsWith(fixturesDir); + const external = externalDependencies.some(d => resolveId.startsWith(d)); + if (external) { + console.log("external", resolveId); + } + return external; + //return !resolveId.startsWith(srcDir);// || resolveId.startsWith(mocksDir) || resolveId.startsWith(fixturesDir); }, preserveEntrySignatures: "strict", output: [ From c921091957fd5c135b6317a8ba1e7cf5e1e9e40f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 20 Dec 2021 19:17:31 +0100 Subject: [PATCH 10/18] run two vite builds for the sdk build, assets & js separately --- scripts/sdk/base-manifest.json | 11 +++++ scripts/sdk/build.sh | 3 +- scripts/sdk/create-manifest.js | 14 ++---- src/{foo-index.html => index.html} | 7 +-- src/lib.ts | 9 ---- vite.common-config.js | 11 +---- vite.config.js | 9 ++++ vite.sdk-assets-config.js | 11 +++++ vite.sdk-config.js | 72 ------------------------------ vite.sdk-lib-config.js | 54 ++++++++++++++++++++++ 10 files changed, 94 insertions(+), 107 deletions(-) create mode 100644 scripts/sdk/base-manifest.json rename src/{foo-index.html => index.html} (54%) create mode 100644 vite.sdk-assets-config.js delete mode 100644 vite.sdk-config.js create mode 100644 vite.sdk-lib-config.js diff --git a/scripts/sdk/base-manifest.json b/scripts/sdk/base-manifest.json new file mode 100644 index 00000000..829cd3a6 --- /dev/null +++ b/scripts/sdk/base-manifest.json @@ -0,0 +1,11 @@ +{ + "name": "hydrogen-sdk", + "version": "0.0.1", + "main": "./hydrogen.cjs.js", + "exports": { + "import": "./hydrogen.es.js", + "require": "./hydrogen.cjs.js" + }, + "files": [], + "types": "types/lib.d.ts" +} diff --git a/scripts/sdk/build.sh b/scripts/sdk/build.sh index 71c98438..90b43534 100755 --- a/scripts/sdk/build.sh +++ b/scripts/sdk/build.sh @@ -1,3 +1,4 @@ -yarn run vite build -c vite.sdk-config.js +yarn run vite build -c vite.sdk-assets-config.js +yarn run vite build -c vite.sdk-lib-config.js yarn tsc -p tsconfig-declaration.json ./scripts/sdk/create-manifest.js ./target/package.json diff --git a/scripts/sdk/create-manifest.js b/scripts/sdk/create-manifest.js index 93074c55..7a01de0a 100755 --- a/scripts/sdk/create-manifest.js +++ b/scripts/sdk/create-manifest.js @@ -1,21 +1,15 @@ #!/usr/bin/env node const fs = require("fs"); -const baseManifest = JSON.parse(fs.readFileSync("package.json", "utf8")); +const appManifest = require("../../package.json") +const baseSDKManifest = require("./base-manifest.json") const mergeOptions = require('merge-options'); const manifestExtension = { - name: "hydrogen-sdk", - main: "./hydrogen.cjs.js", - exports: { - import: "./hydrogen.es.js", - require: "./hydrogen.cjs.js" - }, - files: [], - types: "types/lib.d.ts", devDependencies: undefined, scripts: undefined, }; -const manifest = mergeOptions(baseManifest, manifestExtension); + +const manifest = mergeOptions(appManifest, baseSDKManifest, manifestExtension); const json = JSON.stringify(manifest, undefined, 2); const outFile = process.argv[2]; fs.writeFileSync(outFile, json, {encoding: "utf8"}); diff --git a/src/foo-index.html b/src/index.html similarity index 54% rename from src/foo-index.html rename to src/index.html index c6bfa098..bec701d9 100644 --- a/src/foo-index.html +++ b/src/index.html @@ -1,16 +1,13 @@ + - - diff --git a/src/lib.ts b/src/lib.ts index 6a5f6581..27290fb5 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -31,12 +31,3 @@ export {RoomViewModel} from "./domain/session/room/RoomViewModel.js"; export {RoomView} from "./platform/web/ui/session/room/RoomView.js"; export {TimelineViewModel} from "./domain/session/room/timeline/TimelineViewModel.js"; export {TimelineView} from "./platform/web/ui/session/room/TimelineView"; - -// @ts-ignore -export * from "./platform/web/ui/css/main.css"; -// @ts-ignore -export * from "./platform/web/ui/css/themes/element/theme.css"; -// @ts-ignore -import _downloadSandboxPath from "./platform/web/assets/download-sandbox.html?url"; -// @ts-ignore -import _workerPath from "./platform/web/worker/main.js?url"; diff --git a/vite.common-config.js b/vite.common-config.js index 08d17b3a..b253d1fe 100644 --- a/vite.common-config.js +++ b/vite.common-config.js @@ -7,19 +7,10 @@ const version = manifest.version; const commonOptions = { logLevel: "info", - public: false, + publicDir: false, server: { hmr: false }, - resolve: { - alias: { - // these should only be imported by the base-x package in any runtime code - // and works in the browser with a Uint8Array shim, - // rather than including a ton of polyfill code - "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", - "buffer": "./scripts/package-overrides/buffer/index.js", - } - }, build: { emptyOutDir: true, assetsInlineLimit: 0, diff --git a/vite.config.js b/vite.config.js index b6ec597d..e11c61d8 100644 --- a/vite.config.js +++ b/vite.config.js @@ -9,6 +9,15 @@ export default defineConfig(({mode}) => { return mergeOptions(commonOptions, { root: "src/platform/web", base: "./", + resolve: { + alias: { + // these should only be imported by the base-x package in any runtime code + // and works in the browser with a Uint8Array shim, + // rather than including a ton of polyfill code + "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", + "buffer": "./scripts/package-overrides/buffer/index.js", + } + }, build: { outDir: "../../../target", minify: true, diff --git a/vite.sdk-assets-config.js b/vite.sdk-assets-config.js new file mode 100644 index 00000000..90720966 --- /dev/null +++ b/vite.sdk-assets-config.js @@ -0,0 +1,11 @@ +const path = require("path"); +const mergeOptions = require('merge-options'); +const commonOptions = require("./vite.common-config.js"); + +export default mergeOptions(commonOptions, { + root: "src/", + base: "./", + build: { + outDir: "../target/asset-build/", + }, +}); diff --git a/vite.sdk-config.js b/vite.sdk-config.js deleted file mode 100644 index 194513fb..00000000 --- a/vite.sdk-config.js +++ /dev/null @@ -1,72 +0,0 @@ -const path = require("path"); -const mergeOptions = require('merge-options').bind({concatArrays: true}); -const commonOptions = require("./vite.common-config.js"); -const manifest = require("./package.json"); - -const srcDir = path.join(__dirname, "src/"); -const modulesDir = path.join(srcDir, "node_modules/"); -const mocksDir = path.join(srcDir, "mocks/"); -const fixturesDir = path.join(srcDir, "fixtures/"); - -const commonOutput = { - // manualChunks: (id) => { - // if (id.endsWith("/lib.ts")) { - // console.log(id, arguments); - // return "es/lib"; - // } - // if (id.startsWith(srcDir)) { - // const idPath = id.substring(srcDir.length); - // const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf(".")); - // return pathWithoutExt; - // } else { - // return "index"; - // } - // }, - chunkFileNames: `[format]/[name].js`, - assetFileNames: `assets/[name][extname]`, - // important to preserve export names of every module - // so we can still override the file and provider alternative impls - minifyInternalExports: false, - preferConst: true, -}; - -const externalDependencies = Object.keys(manifest.dependencies).concat(Object.keys(manifest.devDependencies)).filter(d => d !== "@matrix-org/olm").map(d => path.join(__dirname, "node_modules", d)); -console.log("external", externalDependencies); - -export default mergeOptions(commonOptions, { - root: "src/", - plugins: [ - { - name: "showconfig", - buildStart(rollupOptions) { - console.dir(rollupOptions, {depth: 100}); - }, - resolveId(source, importer) { - console.log(source, importer); - } - } - ], - build: { - minify: false, - sourcemap: false, - outDir: "../target", - rollupOptions: { - input: "./src/lib.ts", - treeshake: false, - external: (id, parentId) => { - const resolveId = (id.startsWith("./") || id.startsWith("../")) ? path.join(path.dirname(parentId), id) : id; - const external = externalDependencies.some(d => resolveId.startsWith(d)); - if (external) { - console.log("external", resolveId); - } - return external; - //return !resolveId.startsWith(srcDir);// || resolveId.startsWith(mocksDir) || resolveId.startsWith(fixturesDir); - }, - preserveEntrySignatures: "strict", - output: [ - Object.assign({}, commonOutput, {format: "es"}), - Object.assign({}, commonOutput, {format: "cjs"}), - ] - } - }, -}); diff --git a/vite.sdk-lib-config.js b/vite.sdk-lib-config.js new file mode 100644 index 00000000..bd2250af --- /dev/null +++ b/vite.sdk-lib-config.js @@ -0,0 +1,54 @@ +const path = require("path"); +const mergeOptions = require('merge-options'); +const commonOptions = require("./vite.common-config.js"); +const manifest = require("./package.json") + +// const srcDir = path.join(__dirname, "src/"); +// const modulesDir = path.join(srcDir, "node_modules/"); +// const mocksDir = path.join(srcDir, "mocks/"); +// const fixturesDir = path.join(srcDir, "fixtures/"); + +const externalDependencies = Object.keys(manifest.dependencies) + .concat(Object.keys(manifest.devDependencies)) + .map(d => path.join(__dirname, "node_modules", d)); + +export default mergeOptions(commonOptions, { + root: "src/", + build: { + lib: { + entry: path.resolve(__dirname, 'src/lib.ts'), + formats: ["cjs", "es"], + fileName: format => `hydrogen.${format}.js`, + }, + minify: false, + sourcemap: false, + outDir: "../target/lib-build", + // don't bundle any dependencies, they should be imported/required + rollupOptions: { + external(id, parentId) { + const isRelativePath = id.startsWith("./") || id.startsWith("../"); + const isModuleIdentifier = !isRelativePath && !id.startsWith("/"); + const resolveId = isRelativePath ? path.join(path.dirname(parentId), id) : id; + const external = isModuleIdentifier || + externalDependencies.some(d => resolveId.startsWith(d)); + // resolveId.startsWith(fixturesDir) || + // resolveId.startsWith(mocksDir); + return external; + }, + /* don't bundle, so we can override imports per file at build time to replace components */ + // output: { + // manualChunks: (id) => { + // if (id.startsWith(srcDir)) { + // const idPath = id.substring(srcDir.length); + // const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf(".")); + // return pathWithoutExt; + // } else { + // return "index"; + // } + // }, + // minifyInternalExports: false, + // chunkFileNames: "[format]/[name].js" + // } + } + }, +}); From 163dae647b0531c01ed6396cb7ac19a6fb72595d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 21 Dec 2021 12:24:33 +0100 Subject: [PATCH 11/18] move output of both lib and asset build around for coherent package --- scripts/sdk/base-manifest.json | 1 - scripts/sdk/build.sh | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) mode change 100755 => 100644 scripts/sdk/build.sh diff --git a/scripts/sdk/base-manifest.json b/scripts/sdk/base-manifest.json index 829cd3a6..d8e30dd2 100644 --- a/scripts/sdk/base-manifest.json +++ b/scripts/sdk/base-manifest.json @@ -6,6 +6,5 @@ "import": "./hydrogen.es.js", "require": "./hydrogen.cjs.js" }, - "files": [], "types": "types/lib.d.ts" } diff --git a/scripts/sdk/build.sh b/scripts/sdk/build.sh old mode 100755 new mode 100644 index 90b43534..c9f7a79d --- a/scripts/sdk/build.sh +++ b/scripts/sdk/build.sh @@ -1,4 +1,17 @@ +rm -rf target yarn run vite build -c vite.sdk-assets-config.js yarn run vite build -c vite.sdk-lib-config.js yarn tsc -p tsconfig-declaration.json ./scripts/sdk/create-manifest.js ./target/package.json +pushd target +pushd asset-build/assets +mv main.*.js ../../main.js +mv index.*.css ../../style.css +mv download-sandbox.*.html ../../download-sandbox.html +rm *.js *.wasm +mv ./* ../../ +popd +rm -rf asset-build +mv lib-build/* . +rm -rf lib-build +popd From b48280905ee77e9c8073892ca05b9b55a6ce4206 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 21 Dec 2021 15:28:34 +0100 Subject: [PATCH 12/18] include path/vite in sdk bundle --- package.json | 3 + scripts/sdk/base-manifest.json | 7 +- scripts/sdk/build.sh | 2 + scripts/sdk/transform-paths.js | 36 ++++++++++ src/index.html | 2 +- .../web/sdk/paths/{vite.ts => vite.js} | 0 yarn.lock | 70 ++++++++++++++++++- 7 files changed, 114 insertions(+), 6 deletions(-) mode change 100644 => 100755 scripts/sdk/build.sh create mode 100755 scripts/sdk/transform-paths.js rename src/platform/web/sdk/paths/{vite.ts => vite.js} (100%) diff --git a/package.json b/package.json index b6299896..1efafb16 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,12 @@ "devDependencies": { "@typescript-eslint/eslint-plugin": "^4.29.2", "@typescript-eslint/parser": "^4.29.2", + "acorn": "^8.6.0", + "acorn-walk": "^8.2.0", "aes-js": "^3.1.2", "core-js": "^3.6.5", "es6-promise": "https://github.com/bwindels/es6-promise.git#bwindels/expose-flush", + "escodegen": "^2.0.0", "eslint": "^7.32.0", "fake-indexeddb": "^3.1.2", "impunity": "^1.0.9", diff --git a/scripts/sdk/base-manifest.json b/scripts/sdk/base-manifest.json index d8e30dd2..90061a4b 100644 --- a/scripts/sdk/base-manifest.json +++ b/scripts/sdk/base-manifest.json @@ -3,8 +3,11 @@ "version": "0.0.1", "main": "./hydrogen.cjs.js", "exports": { - "import": "./hydrogen.es.js", - "require": "./hydrogen.cjs.js" + ".": { + "import": "./hydrogen.es.js", + "require": "./hydrogen.cjs.js" + }, + "./paths/vite": "./paths/vite.js" }, "types": "types/lib.d.ts" } diff --git a/scripts/sdk/build.sh b/scripts/sdk/build.sh old mode 100644 new mode 100755 index c9f7a79d..c22eb4ec --- a/scripts/sdk/build.sh +++ b/scripts/sdk/build.sh @@ -3,6 +3,8 @@ yarn run vite build -c vite.sdk-assets-config.js yarn run vite build -c vite.sdk-lib-config.js yarn tsc -p tsconfig-declaration.json ./scripts/sdk/create-manifest.js ./target/package.json +mkdir target/paths +./scripts/sdk/transform-paths.js ./src/platform/web/sdk/paths/vite.js ./target/paths/vite.js pushd target pushd asset-build/assets mv main.*.js ../../main.js diff --git a/scripts/sdk/transform-paths.js b/scripts/sdk/transform-paths.js new file mode 100755 index 00000000..60724c21 --- /dev/null +++ b/scripts/sdk/transform-paths.js @@ -0,0 +1,36 @@ +#!/usr/bin/env node + +/** +This script transforms the string literals in the sdk path files to adjust paths +from what they are at development time to what they will be in the sdk package. + +It does this by looking in all string literals in the paths file and looking for file names +that we expect and need replacing (as they are bundled with the sdk). + +Usage: ./transform-paths.js +*/ + +const acorn = require("acorn"); +const walk = require("acorn-walk") +const escodegen = require("escodegen"); +const fs = require("fs"); + +const code = fs.readFileSync(process.argv[2], {encoding: "utf8"}); +const ast = acorn.parse(code, {ecmaVersion: "13", sourceType: "module"}); + +function changePrefix(value, file, newPrefix = "") { + const idx = value.indexOf(file); + if (idx !== -1) { + return newPrefix + value.substr(idx); + } + return value; +} + +walk.simple(ast, { + Literal(node) { + node.value = changePrefix(node.value, "download-sandbox.html", "../"); + node.value = changePrefix(node.value, "main.js", "../"); + } +}); +const transformedCode = escodegen.generate(ast); +fs.writeFileSync(process.argv[3], transformedCode, {encoding: "utf8"}) diff --git a/src/index.html b/src/index.html index bec701d9..456f095a 100644 --- a/src/index.html +++ b/src/index.html @@ -7,7 +7,7 @@ diff --git a/src/platform/web/sdk/paths/vite.ts b/src/platform/web/sdk/paths/vite.js similarity index 100% rename from src/platform/web/sdk/paths/vite.ts rename to src/platform/web/sdk/paths/vite.js diff --git a/yarn.lock b/yarn.lock index c564dbe5..87b8ef96 100644 --- a/yarn.lock +++ b/yarn.lock @@ -156,11 +156,21 @@ acorn-jsx@^5.3.1: resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b" integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng== +acorn-walk@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" + integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== + acorn@^7.4.0: version "7.4.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== +acorn@^8.6.0: + version "8.6.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.6.0.tgz#e3692ba0eb1a0c83eaa4f37f5fa7368dd7142895" + integrity sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw== + aes-js@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.1.2.tgz#db9aabde85d5caabbfc0d4f2a4446960f627146a" @@ -401,6 +411,11 @@ deep-is@^0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= +deep-is@~0.1.3: + version "0.1.4" + resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831" + integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ== + dir-glob@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" @@ -608,6 +623,18 @@ escape-string-regexp@^4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +escodegen@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-2.0.0.tgz#5e32b12833e8aa8fa35e1bf0befa89380484c7dd" + integrity sha512-mmHKys/C8BFUGI+MAWNcSYoORYLMdPzjrknd2Vc+bUsjN5bXcr8EhrNB+UTqfL1y3I9c4fw2ihgtMPQLBRiQxw== + dependencies: + esprima "^4.0.1" + estraverse "^5.2.0" + esutils "^2.0.2" + optionator "^0.8.1" + optionalDependencies: + source-map "~0.6.1" + eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" @@ -695,7 +722,7 @@ espree@^7.3.0, espree@^7.3.1: acorn-jsx "^5.3.1" eslint-visitor-keys "^1.3.0" -esprima@^4.0.0: +esprima@^4.0.0, esprima@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== @@ -763,7 +790,7 @@ fast-json-stable-stringify@^2.0.0: resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== -fast-levenshtein@^2.0.6: +fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= @@ -1009,6 +1036,14 @@ levn@^0.4.1: prelude-ls "^1.2.1" type-check "~0.4.0" +levn@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" + integrity sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4= + dependencies: + prelude-ls "~1.1.2" + type-check "~0.3.2" + lodash.clonedeep@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" @@ -1105,6 +1140,18 @@ once@^1.3.0: dependencies: wrappy "1" +optionator@^0.8.1: + version "0.8.3" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" + integrity sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA== + dependencies: + deep-is "~0.1.3" + fast-levenshtein "~2.0.6" + levn "~0.3.0" + prelude-ls "~1.1.2" + type-check "~0.3.2" + word-wrap "~1.2.3" + optionator@^0.9.1: version "0.9.1" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499" @@ -1182,6 +1229,11 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== +prelude-ls@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" + integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= + progress@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" @@ -1309,6 +1361,11 @@ source-map-js@^0.6.2: resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-0.6.2.tgz#0bb5de631b41cfbda6cfba8bd05a80efdfd2385e" integrity sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug== +source-map@~0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== + sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" @@ -1404,6 +1461,13 @@ type-check@^0.4.0, type-check@~0.4.0: dependencies: prelude-ls "^1.2.1" +type-check@~0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" + integrity sha1-WITKtRLPHTVeP7eE8wgEsrUg23I= + dependencies: + prelude-ls "~1.1.2" + type-fest@^0.20.2: version "0.20.2" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4" @@ -1483,7 +1547,7 @@ which@^2.0.1: dependencies: isexe "^2.0.0" -word-wrap@^1.2.3: +word-wrap@^1.2.3, word-wrap@~1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== From 3bee4b4585ec0d2e55b66d2b05c6139d88c18801 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 21 Dec 2021 15:28:55 +0100 Subject: [PATCH 13/18] bundle bs58 to avoid pain of bundle transitive dependency for lib users bs58 depends on safe-buffer, which depends on buffer, which is a bit of a pain to bundle as it is a built-in node module. You'd typically replace buffer with a browser polyfill in your build system but: a) this is somewhat a pain to setup for simple apps b) the polyfill is way more than we need (6kb), so we prefer to bundle our minimal buffer replacement that uses Uint8Array. Since it is a transitive dependency, we need to bundle bs58 and all of its transitive dependencies (2.5kb) as well, so if users of hydrogen-sdk also use any of these, they'll be double included in their bundle. --- vite.common-config.js | 9 +++++++++ vite.config.js | 9 --------- vite.sdk-lib-config.js | 25 +++++++++---------------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/vite.common-config.js b/vite.common-config.js index b253d1fe..bfade3e2 100644 --- a/vite.common-config.js +++ b/vite.common-config.js @@ -11,6 +11,15 @@ const commonOptions = { server: { hmr: false }, + resolve: { + alias: { + // these should only be imported by the base-x package in any runtime code + // and works in the browser with a Uint8Array shim, + // rather than including a ton of polyfill code + "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", + "buffer": "./scripts/package-overrides/buffer/index.js", + } + }, build: { emptyOutDir: true, assetsInlineLimit: 0, diff --git a/vite.config.js b/vite.config.js index e11c61d8..b6ec597d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -9,15 +9,6 @@ export default defineConfig(({mode}) => { return mergeOptions(commonOptions, { root: "src/platform/web", base: "./", - resolve: { - alias: { - // these should only be imported by the base-x package in any runtime code - // and works in the browser with a Uint8Array shim, - // rather than including a ton of polyfill code - "safe-buffer": "./scripts/package-overrides/safe-buffer/index.js", - "buffer": "./scripts/package-overrides/buffer/index.js", - } - }, build: { outDir: "../../../target", minify: true, diff --git a/vite.sdk-lib-config.js b/vite.sdk-lib-config.js index bd2250af..c1678d8b 100644 --- a/vite.sdk-lib-config.js +++ b/vite.sdk-lib-config.js @@ -1,16 +1,16 @@ const path = require("path"); const mergeOptions = require('merge-options'); const commonOptions = require("./vite.common-config.js"); -const manifest = require("./package.json") - -// const srcDir = path.join(__dirname, "src/"); -// const modulesDir = path.join(srcDir, "node_modules/"); -// const mocksDir = path.join(srcDir, "mocks/"); -// const fixturesDir = path.join(srcDir, "fixtures/"); +const manifest = require("./package.json"); const externalDependencies = Object.keys(manifest.dependencies) + // just in case for safety in case fake-indexeddb wouldn't be + // treeshake'd out of the bundle .concat(Object.keys(manifest.devDependencies)) - .map(d => path.join(__dirname, "node_modules", d)); + // bundle bs58 because it uses buffer indirectly, which is a pain to bundle, + // so we don't annoy our library users with it. + .filter(d => d !== "bs58"); +const moduleDir = path.join(__dirname, "node_modules"); export default mergeOptions(commonOptions, { root: "src/", @@ -25,15 +25,8 @@ export default mergeOptions(commonOptions, { outDir: "../target/lib-build", // don't bundle any dependencies, they should be imported/required rollupOptions: { - external(id, parentId) { - const isRelativePath = id.startsWith("./") || id.startsWith("../"); - const isModuleIdentifier = !isRelativePath && !id.startsWith("/"); - const resolveId = isRelativePath ? path.join(path.dirname(parentId), id) : id; - const external = isModuleIdentifier || - externalDependencies.some(d => resolveId.startsWith(d)); - // resolveId.startsWith(fixturesDir) || - // resolveId.startsWith(mocksDir); - return external; + external(id) { + return externalDependencies.some(d => id === d || id.startsWith(d + "/")); }, /* don't bundle, so we can override imports per file at build time to replace components */ // output: { From 441fa13bfdc7ff3657f0ba208941ecb5f894e800 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Dec 2021 15:56:21 +0100 Subject: [PATCH 14/18] change sdk package name to hydrogen-view-sdk as we might want to also have a lower level sdk later on --- scripts/sdk/base-manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sdk/base-manifest.json b/scripts/sdk/base-manifest.json index 90061a4b..4104b70e 100644 --- a/scripts/sdk/base-manifest.json +++ b/scripts/sdk/base-manifest.json @@ -1,5 +1,5 @@ { - "name": "hydrogen-sdk", + "name": "hydrogen-view-sdk", "version": "0.0.1", "main": "./hydrogen.cjs.js", "exports": { From c3ff571af742eda8af6a07e3c15f6beba6cd794e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Dec 2021 16:20:54 +0100 Subject: [PATCH 15/18] update SDK doc, use it as sdk package readme --- doc/SDK.md | 122 +++++++++++++++++++++++-------------------- scripts/sdk/build.sh | 1 + 2 files changed, 67 insertions(+), 56 deletions(-) diff --git a/doc/SDK.md b/doc/SDK.md index 4cd6c68c..c9897844 100644 --- a/doc/SDK.md +++ b/doc/SDK.md @@ -1,80 +1,90 @@ -# How to use Hydrogen as an SDK +# Hydrogen View SDK -If you want to use end-to-end encryption, it is recommended to use a [supported build system](../src/sdk/paths/) (currently only vite) to be able to locate the olm library files. -**NOTE**: For now, these instructions will only work at development time, support when building (e.g. `vite build`) is being worked on and tracked in [#529](https://github.com/vector-im/hydrogen-web/issues/529). +The Hydrogen view SDK allows developers to integrate parts of the Hydrogen application into the UI of their own application. Hydrogen is written with the MVVM pattern, so to construct a view, you'd first construct a view model, which you then pass into the view. For most view models, you will first need a running client. -You can create a project using the following commands +## Example + +The Hydrogen SDK requires some assets to be shipped along with your app for things like downloading attachments, and end-to-end encryption. A convenient way to make this happen is provided by the SDK (importing `hydrogen-view-sdk/paths/vite`) but depends on your build system. Currently, only [vite](https://vitejs.dev/) is supported, so that's what we'll be using in the example below. + +You can create a vite project using the following commands: ```sh # you can pick "vanilla-ts" here for project type if you're not using react or vue yarn create vite cd yarn -yarn add https://github.com/vector-im/hydrogen-web.git +yarn add hydrogen-view-sdk ``` -If you go into the `src` directory, you should see a `main.ts` file. If you put this code in there, you should see a basic timeline after login and initial sync have finished. +You should see a `index.html` in the project root directory, containing an element with `id="app"`. Add the attribute `class="hydrogen"` to this element, as the CSS we'll include from the SDK assumes for now that the app is rendered in an element with this classname. + +If you go into the `src` directory, you should see a `main.ts` file. If you put this code in there, you should see a basic timeline after login and initial sync have finished (might take a while before you see anything on the screen actually). + +You'll need to provide the username and password of a user that is already in the [#element-dev:matrix.org](https://matrix.to/#/#element-dev:matrix.org) room (or change the room id). ```ts import { Platform, - SessionContainer, + Client, LoadStatus, createNavigation, createRouter, RoomViewModel, TimelineView -} from "hydrogen-web"; -import {olmPaths, downloadSandboxPath} from "hydrogen-web/src/sdk/paths/vite"; +} from "hydrogen-view-sdk"; +import assetPaths from "hydrogen-view-sdk/paths/vite"; +import "hydrogen-view-sdk/style.css"; -const app = document.querySelector('#app')! - -// bootstrap a session container -const platform = new Platform(app, { - downloadSandbox: downloadSandboxPath, - olm: olmPaths, -}, null, { development: true }); -const navigation = createNavigation(); -platform.setNavigation(navigation); -const urlRouter = createRouter({ - navigation: navigation, - history: platform.history -}); -urlRouter.attach(); -const sessionContainer = new SessionContainer({ - platform, - olmPromise: platform.loadOlm(), - workerPromise: platform.loadOlmWorker() -}); - -// wait for login and first sync to finish -const loginOptions = await sessionContainer.queryLogin("matrix.org").result; -sessionContainer.startWithLogin(loginOptions.password("user", "password")); -await sessionContainer.loadStatus.waitFor((status: string) => { - return status === LoadStatus.Ready || - status === LoadStatus.Error || - status === LoadStatus.LoginFailed; -}).promise; -// check the result -if (sessionContainer.loginFailure) { - alert("login failed: " + sessionContainer.loginFailure); -} else if (sessionContainer.loadError) { - alert("load failed: " + sessionContainer.loadError.message); -} else { - // we're logged in, we can access the room now - const {session} = sessionContainer; - // room id for #element-dev:matrix.org - const room = session.rooms.get("!bEWtlqtDwCLFIAKAcv:matrix.org"); - const vm = new RoomViewModel({ - room, - ownUserId: session.userId, - platform, - urlCreator: urlRouter, - navigation, +async function main() { + const app = document.querySelector('#app')! + const platform = new Platform(app, assetPaths, { development: import.meta.env.DEV }); + const navigation = createNavigation(); + platform.setNavigation(navigation); + const urlRouter = createRouter({ + navigation: navigation, + history: platform.history }); - await vm.load(); - const view = new TimelineView(vm.timelineViewModel); - app.appendChild(view.mount()); + urlRouter.attach(); + const client = new Client(platform); + + const loginOptions = await client.queryLogin("matrix.org").result; + client.startWithLogin(loginOptions.password("username", "password")); + + await client.loadStatus.waitFor((status: string) => { + return status === LoadStatus.Ready || + status === LoadStatus.Error || + status === LoadStatus.LoginFailed; + }).promise; + + if (client.loginFailure) { + alert("login failed: " + client.loginFailure); + } else if (client.loadError) { + alert("load failed: " + client.loadError.message); + } else { + const {session} = client; + // looks for room corresponding to #element-dev:matrix.org, assuming it is already joined + const room = session.rooms.get("!bEWtlqtDwCLFIAKAcv:matrix.org"); + const vm = new RoomViewModel({ + room, + ownUserId: session.userId, + platform, + urlCreator: urlRouter, + navigation, + }); + await vm.load(); + const view = new TimelineView(vm.timelineViewModel); + app.appendChild(view.mount()); + } } + +main(); ``` + +## Typescript support + +There is partial typescript support while we are still in the process of converting the Hydrogen codebase to typesccript. + +## API Stability + +This library follows semantic versioning; there is no API stability promised as long as the major version is still 0. Once 1.0.0 is released, breaking changes will be released with a change in major versioning. diff --git a/scripts/sdk/build.sh b/scripts/sdk/build.sh index c22eb4ec..3145df80 100755 --- a/scripts/sdk/build.sh +++ b/scripts/sdk/build.sh @@ -5,6 +5,7 @@ yarn tsc -p tsconfig-declaration.json ./scripts/sdk/create-manifest.js ./target/package.json mkdir target/paths ./scripts/sdk/transform-paths.js ./src/platform/web/sdk/paths/vite.js ./target/paths/vite.js +cp doc/SDK.md target/README.md pushd target pushd asset-build/assets mv main.*.js ../../main.js From c31215bc2a99204911886db7f171b07e78e18983 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Dec 2021 16:25:09 +0100 Subject: [PATCH 16/18] less logging during build --- vite.common-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vite.common-config.js b/vite.common-config.js index bfade3e2..44c884bd 100644 --- a/vite.common-config.js +++ b/vite.common-config.js @@ -6,7 +6,7 @@ const manifest = require("./package.json"); const version = manifest.version; const commonOptions = { - logLevel: "info", + logLevel: "warn", publicDir: false, server: { hmr: false From 5f389e654ab75cb918ba9f8726f8691583332db4 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Dec 2021 16:37:53 +0100 Subject: [PATCH 17/18] add description --- scripts/sdk/base-manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/sdk/base-manifest.json b/scripts/sdk/base-manifest.json index 4104b70e..612d69a4 100644 --- a/scripts/sdk/base-manifest.json +++ b/scripts/sdk/base-manifest.json @@ -1,5 +1,6 @@ { "name": "hydrogen-view-sdk", + "description": "Embeddable matrix client library, including view components", "version": "0.0.1", "main": "./hydrogen.cjs.js", "exports": { From 24afe1e496862d650c9b6a097945a7fc4570e52e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Dec 2021 16:45:08 +0100 Subject: [PATCH 18/18] add licenses to readme of things we actually bundle rather than just depend on --- doc/SDK.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/SDK.md b/doc/SDK.md index c9897844..87e7c897 100644 --- a/doc/SDK.md +++ b/doc/SDK.md @@ -88,3 +88,7 @@ There is partial typescript support while we are still in the process of convert ## API Stability This library follows semantic versioning; there is no API stability promised as long as the major version is still 0. Once 1.0.0 is released, breaking changes will be released with a change in major versioning. + +## Third-party licenses + +This package bundles the bs58 package ([license](https://github.com/cryptocoinjs/bs58/blob/master/LICENSE)), and the Inter font ([license](https://github.com/rsms/inter/blob/master/LICENSE.txt)).