Skip to content

Commit

Permalink
Typecheck service worker separately to avoid DOM and Webworker lib ty…
Browse files Browse the repository at this point in the history
…pe clashs

Typecheck service worker separately with ts WebWorker lib, and the rest of the Keyguard
with ts DOM lib. Previously, both libs were active in all files (even though webworker
was referenced only in the ServiceWorker via a triple slash directive, this enables it
globally), which by itself is inappropriate, but also causes type clashs between the
DOM and the WebWorker types, which previously were silenced by skipping lib checks.

Now, with this change, and typescript having been updated to a recent version, checking
libs has been enabled again.
  • Loading branch information
danimoh committed Sep 6, 2024
1 parent cc0b7ba commit 4c1cd7e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:bitcoinjs": "yarn --silent browserify tools/bitcoinjs-parts.js -s BitcoinJS | yarn terser --compress --mangle --source-map --output src/lib/bitcoin/BitcoinJS.js",
"build:opengsn": "yarn --silent browserify -r @opengsn/common/dist/EIP712/TypedRequestData -s OpenGSN | yarn terser --compress --mangle --source-map --output src/lib/polygon/OpenGSN.js",
"test": "karma start",
"typecheck": "tsc",
"typecheck": "tsc && tsc -p src/service-worker/tsconfig.json",
"lint": "yarn i18n:build-dictionary && eslint src tools && if ( grep 'fit\\|fdescribe' tests/lib/* ); then exit 1; else exit 0; fi",
"lintfix": "eslint --fix src tools",
"checkdeps": "node tools/dependencyValidator.js",
Expand Down
3 changes: 0 additions & 3 deletions src/ServiceWorker.js → src/service-worker/ServiceWorker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// eslint-disable-next-line spaced-comment
/// <reference lib='webworker' />

/**
* Simplified definition of the browser's native CookieStore. Not to be confused with our CookieStorage.
* @typedef {{get: (name: string) => Promise<{ value: string } | undefined>}} CookieStore
Expand Down
8 changes: 8 additions & 0 deletions src/service-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"lib": ["WebWorker"]
},
"include": ["*.js"],
"exclude": [] // Overwrite exclusion of service worker
}
2 changes: 1 addition & 1 deletion tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ cp -rv src/assets/* dist/assets/
cp -v src/lib/QrScannerWorker.js dist/lib/
cp -v node_modules/@nimiq/style/nimiq-style.icons.svg dist/assets/
# copy service worker (which has to be in root to work)
cp -v src/ServiceWorker.js dist
cp -v src/service-worker/ServiceWorker.js dist

# copy Nimiq files
output "‼️ Copying Nimiq files"
Expand Down
8 changes: 2 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["DOM"], /* Specify library files to be included in the compilation. */
"skipLibCheck": true, /* Skip checking .d.ts files. We need this currently, because types in */
/* lib.webworker.d.ts referenced in ServiceWorker.js clash with types */
/* in lib.dom.d.ts, and also because our typescript version is too old */
/* to handle the types of ethers. */
/* TODO once typescript has been updated, this can be removed. */
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down Expand Up @@ -72,8 +67,9 @@
"instrumented",
"coverage",
"src/lib/QrScannerWorker.js",
"src/translations/index.js",
"src/lib/bitcoin/BitcoinJS.js",
"src/lib/polygon/OpenGSN.js",
"src/service-worker", // Service worker is checked with a separate tsconfig in src/service-worker
"src/translations/index.js"
]
}

0 comments on commit 4c1cd7e

Please sign in to comment.