Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up multiple typescript projects #9

Merged
merged 17 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codechecks.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
- name: Lint
run: yarn run lint-ci
- name: Typescript
run: yarn run tsc
run: yarn run tsc --build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ lib
.eslintcache
.tmp
playwright/synapselogs
.typescript
2 changes: 1 addition & 1 deletion scripts/build-plugins/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getBuildHash(hashedFileNames, unhashedFileContentMap) {
const NON_PRECACHED_JS = [
"hydrogen-legacy",
"olm_legacy.js",
// most environments don't need the worker
// most environments don't need the olm worker.
"main.js"
];

Expand Down
7 changes: 6 additions & 1 deletion scripts/sdk/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ yarn run vite build -c vite.sdk-lib-config.js
# Remove sync-worker.js from SDK build.
# TODO: Once SameSessionInMultipleTabs feature flag is globally enabled, remove the following line.
rm -rf target/lib-build/assets
yarn tsc -p tsconfig-declaration.json

# Build typescript declarations.
rm -rf .typescript/sdk .typescript/sdk.tsbuildinfo
yarn tsc -p tsconfig.sdk.json
cp -r .typescript/sdk target/types

./scripts/sdk/create-manifest.js ./target/package.json
mkdir target/paths
# this doesn't work, the ?url imports need to be in the consuming project, so disable for now
Expand Down
2 changes: 1 addition & 1 deletion src/platform/web/sdk/paths/vite.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore
import _downloadSandboxPath from "../../assets/download-sandbox.html?url";
// @ts-ignore
import _workerPath from "../../worker/main.js?url";
import _workerPath from "../../../workers/main.js?url";
// @ts-ignore
import olmWasmPath from "@matrix-org/olm/olm.wasm?url";
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion src/platform/web/sync/SyncProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class SyncProxy implements ISync {
}

async start(): Promise<void> {
this._worker = new SharedWorker(new URL("./sync-worker", import.meta.url), {
this._worker = new SharedWorker(new URL("../../workers/sync-worker", import.meta.url), {
type: "module",
});
this._worker.port.onmessage = (event: MessageEvent) => {
Expand Down
57 changes: 0 additions & 57 deletions src/platform/web/worker/polyfill.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Despite being called main.js, this is the Olm worker.
// TODO: Rename this file to olm-worker.js in a way that is backwards-compatible with the SDK.

function asErrorMessage(err) {
return {
type: "error",
Expand Down
2 changes: 1 addition & 1 deletion src/platform/web/sw.js → src/platform/workers/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import NOTIFICATION_BADGE_ICON from "./assets/icon.png?url";
import NOTIFICATION_BADGE_ICON from "../web/assets/icon.png?url";
// replaced by the service worker build plugin
const UNHASHED_PRECACHED_ASSETS = DEFINE_UNHASHED_PRECACHED_ASSETS;
const HASHED_PRECACHED_ASSETS = DEFINE_HASHED_PRECACHED_ASSETS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// TODO: Figure out how to get WebWorkers Typescript lib working. For now we just disable checks on the whole file.
// @ts-nocheck

// The empty export makes this a module. It can be removed once there's at least one import.
export {}

Expand Down
14 changes: 0 additions & 14 deletions tsconfig-declaration.json

This file was deleted.

15 changes: 15 additions & 0 deletions tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": ".typescript/app",
"tsBuildInfoFile": ".typescript/app.tsbuildinfo",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
},
"include": [
"src/**/*"
],
"exclude": [
"src/platform/workers"
]
}
18 changes: 18 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"composite": true,
"emitDeclarationOnly": true,
"rootDir": "src",
"types": [],
"lib": ["ES2020"],
"strictNullChecks": true,
"noImplicitAny": false,
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true
},
"exclude": [
"src/sdk/paths/*"
]
}
17 changes: 5 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{
"compilerOptions": {
"strictNullChecks": true,
"noImplicitAny": false,
"noEmit": true,
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true
},
"exclude": [
"src/sdk/paths/*"
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.workers.json" },
{ "path": "./tsconfig.sdk.json" }
],
"include": ["src/**/*"],
"files": []
}
17 changes: 17 additions & 0 deletions tsconfig.sdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": ".typescript/sdk",
"tsBuildInfoFile": ".typescript/sdk.tsbuildinfo",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"emitDeclarationOnly": true,
"declaration": true,
},
"include": [
"src/**/*"
],
"exclude": [
"src/platform/workers"
]
}
13 changes: 13 additions & 0 deletions tsconfig.workers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": ".typescript/workers",
"tsBuildInfoFile": ".typescript/workers.tsbuildinfo",
"lib": ["ES2020", "WebWorker"],
"emitDeclarationOnly": false
},
"include": [
"src/platform/workers/**/*"
]
}
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default defineConfig(({mode}) => {
// important this comes before service worker
// otherwise the manifest and the icons it refers to won't be cached
injectWebManifest("assets/manifest.json"),
injectServiceWorker("./src/platform/web/sw.js", findUnhashedFileNamesFromBundle, {
injectServiceWorker("./src/platform/workers/sw.js", findUnhashedFileNamesFromBundle, {
// placeholders to replace at end of build by chunk name
index: {
DEFINE_GLOBAL_HASH: definePlaceholders.DEFINE_GLOBAL_HASH,
Expand Down