Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add way to test whether SDK works in ESM and CommonJS
- Loading branch information
1 parent
dd06d78
commit 2401b7f
Showing
8 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Keep TypeScripts from complaining about hydrogen-view-sdk not having types yet | ||
declare module "hydrogen-view-sdk"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as hydrogenViewSdk from "hydrogen-view-sdk"; | ||
import downloadSandboxPath from 'hydrogen-view-sdk/download-sandbox.html?url'; | ||
import workerPath from 'hydrogen-view-sdk/main.js?url'; | ||
import olmWasmPath from '@matrix-org/olm/olm.wasm?url'; | ||
import olmJsPath from '@matrix-org/olm/olm.js?url'; | ||
import olmLegacyJsPath from '@matrix-org/olm/olm_legacy.js?url'; | ||
const assetPaths = { | ||
downloadSandbox: downloadSandboxPath, | ||
worker: workerPath, | ||
olm: { | ||
wasm: olmWasmPath, | ||
legacyBundle: olmLegacyJsPath, | ||
wasmBundle: olmJsPath | ||
} | ||
}; | ||
import "hydrogen-view-sdk/style.css"; | ||
|
||
console.log('hydrogenViewSdk', hydrogenViewSdk); | ||
console.log('assetPaths', assetPaths); | ||
|
||
console.log('Entry ESM works ✅'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="app" class="hydrogen"></div> | ||
<script type="module" src="./esm-entry.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "test-sdk", | ||
"version": "0.0.0", | ||
"description": "", | ||
"dependencies": { | ||
"hydrogen-view-sdk": "link:../../../target" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Make sure the SDK can be used in a CommonJS environment. | ||
// Usage: node scripts/sdk/test/test-sdk-in-commonjs-env.js | ||
const hydrogenViewSdk = require('hydrogen-view-sdk'); | ||
|
||
// Test that the "exports" are available: | ||
// Worker | ||
require.resolve('hydrogen-view-sdk/main.js'); | ||
// Styles | ||
require.resolve('hydrogen-view-sdk/style.css'); | ||
// Can access files in the assets/* directory | ||
require.resolve('hydrogen-view-sdk/assets/main.js'); | ||
|
||
console.log('SDK works in CommonJS ✅'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { resolve } = require('path'); | ||
const { build } = require('vite'); | ||
|
||
async function main() { | ||
await build({ | ||
outDir: './dist', | ||
build: { | ||
rollupOptions: { | ||
input: { | ||
main: resolve(__dirname, 'index.html') | ||
} | ||
} | ||
} | ||
}); | ||
|
||
console.log('SDK works in Vite build ✅'); | ||
} | ||
|
||
main(); |