Skip to content

Commit 37355d9

Browse files
authored
Merge pull request #9 from Automattic/workers-typescript
Set up multiple typescript projects
2 parents cd6c759 + ea0c336 commit 37355d9

File tree

17 files changed

+84
-93
lines changed

17 files changed

+84
-93
lines changed

.github/workflows/codechecks.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ jobs:
4444
- name: Lint
4545
run: yarn run lint-ci
4646
- name: Typescript
47-
run: yarn run tsc
47+
run: yarn run tsc --build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ lib
1111
.eslintcache
1212
.tmp
1313
playwright/synapselogs
14+
.typescript

scripts/build-plugins/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function getBuildHash(hashedFileNames, unhashedFileContentMap) {
6666
const NON_PRECACHED_JS = [
6767
"hydrogen-legacy",
6868
"olm_legacy.js",
69-
// most environments don't need the worker
69+
// most environments don't need the olm worker.
7070
"main.js"
7171
];
7272

scripts/sdk/build.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ yarn run vite build -c vite.sdk-lib-config.js
1313
# Remove sync-worker.js from SDK build.
1414
# TODO: Once SameSessionInMultipleTabs feature flag is globally enabled, remove the following line.
1515
rm -rf target/lib-build/assets
16-
yarn tsc -p tsconfig-declaration.json
16+
17+
# Build typescript declarations.
18+
rm -rf .typescript/sdk .typescript/sdk.tsbuildinfo
19+
yarn tsc -p tsconfig.sdk.json
20+
cp -r .typescript/sdk target/types
21+
1722
./scripts/sdk/create-manifest.js ./target/package.json
1823
mkdir target/paths
1924
# this doesn't work, the ?url imports need to be in the consuming project, so disable for now

src/platform/web/sdk/paths/vite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-ignore
22
import _downloadSandboxPath from "../../assets/download-sandbox.html?url";
33
// @ts-ignore
4-
import _workerPath from "../../worker/main.js?url";
4+
import _workerPath from "../../../workers/main.js?url";
55
// @ts-ignore
66
import olmWasmPath from "@matrix-org/olm/olm.wasm?url";
77
// @ts-ignore

src/platform/web/sync/SyncProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class SyncProxy implements ISync {
4343
}
4444

4545
async start(): Promise<void> {
46-
this._worker = new SharedWorker(new URL("./sync-worker", import.meta.url), {
46+
this._worker = new SharedWorker(new URL("../../workers/sync-worker", import.meta.url), {
4747
type: "module",
4848
});
4949
this._worker.port.onmessage = (event: MessageEvent) => {

src/platform/web/worker/polyfill.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/platform/web/worker/main.js renamed to src/platform/workers/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Despite being called main.js, this is the Olm worker.
18+
// TODO: Rename this file to olm-worker.js in a way that is backwards-compatible with the SDK.
19+
1720
function asErrorMessage(err) {
1821
return {
1922
type: "error",

src/platform/web/sw.js renamed to src/platform/workers/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
import NOTIFICATION_BADGE_ICON from "./assets/icon.png?url";
18+
import NOTIFICATION_BADGE_ICON from "../web/assets/icon.png?url";
1919
// replaced by the service worker build plugin
2020
const UNHASHED_PRECACHED_ASSETS = DEFINE_UNHASHED_PRECACHED_ASSETS;
2121
const HASHED_PRECACHED_ASSETS = DEFINE_HASHED_PRECACHED_ASSETS;

src/platform/web/sync/sync-worker.ts renamed to src/platform/workers/sync-worker.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// TODO: Figure out how to get WebWorkers Typescript lib working. For now we just disable checks on the whole file.
18-
// @ts-nocheck
19-
2017
// The empty export makes this a module. It can be removed once there's at least one import.
2118
export {}
2219

0 commit comments

Comments
 (0)