diff options
author | 2021-12-30 21:47:46 +0100 | |
---|---|---|
committer | 2021-12-30 21:47:46 +0100 | |
commit | 1383dde6aa0d25b5fa23d7a7b64ba7de21ec5b99 (patch) | |
tree | 94739ff48121a1d69358acf5f2c60124d1b1cdec /packages/service-inject | |
parent | build: Only use vite typings in renderer (diff) | |
download | sophie-1383dde6aa0d25b5fa23d7a7b64ba7de21ec5b99.tar.gz sophie-1383dde6aa0d25b5fa23d7a7b64ba7de21ec5b99.tar.zst sophie-1383dde6aa0d25b5fa23d7a7b64ba7de21ec5b99.zip |
build: Fully switch over to ESM
Now we can run with ESM at build and test time and transpile into
commonjs for electron. This greatly simplifies testing, since we treat
everything as ESM during build with esbuild anyways. Now the test
environment and the build scripts match the apparent (but not the actual
for the main, preload, and inject modules) runtime environment.
Caveats:
- We may use top-level async expressions in tests and script, but not in
code that gets transpiled into commonjs or scripts that get imported
by vite. The limitation w.r.t. commonjs seems fundamental.
- Jest only experimentally supports ESM and there are some limitations
with mocking. Most limitations (except the lack of automatic mocks)
can be worked around by async importing code that uses mocks.
- There are packages marked as modules (so that node reads any scripts
in them as ESM) that nevertheless get transpiled into commonjs
modules. However, these should be clearly marked by using a .cjs
extension as their bundle. The worst offender is the root package,
which has a .cjs as its main entry point that gets read by electron,
but is in fact marked as a module. This doesn't seem to bother electron
at all. The service-inject package is an IIFE with a .js extension,
but it outputs a fully self-contained bundle, so the choice of module
format should be irrelevant.
Diffstat (limited to 'packages/service-inject')
-rw-r--r-- | packages/service-inject/esbuild.config.js | 10 | ||||
-rw-r--r-- | packages/service-inject/package.json | 2 |
2 files changed, 5 insertions, 7 deletions
diff --git a/packages/service-inject/esbuild.config.js b/packages/service-inject/esbuild.config.js index 38e5b7d..3f1d6d0 100644 --- a/packages/service-inject/esbuild.config.js +++ b/packages/service-inject/esbuild.config.js | |||
@@ -1,10 +1,8 @@ | |||
1 | // @ts-check | 1 | import { chrome, fileURLToDirname } from '../../config/build-common.js'; |
2 | import { getConfig } from '../../config/esbuild-config.js'; | ||
2 | 3 | ||
3 | const { chrome } = require('../../config/build-common'); | 4 | export default getConfig({ |
4 | const { getConfig } = require('../../config/esbuild-config'); | 5 | absWorkingDir: fileURLToDirname(import.meta.url), |
5 | |||
6 | module.exports = getConfig({ | ||
7 | absWorkingDir: __dirname, | ||
8 | entryPoints: [ | 6 | entryPoints: [ |
9 | 'src/index.ts', | 7 | 'src/index.ts', |
10 | ], | 8 | ], |
diff --git a/packages/service-inject/package.json b/packages/service-inject/package.json index 825de24..7c496fd 100644 --- a/packages/service-inject/package.json +++ b/packages/service-inject/package.json | |||
@@ -3,7 +3,7 @@ | |||
3 | "version": "0.1.0", | 3 | "version": "0.1.0", |
4 | "private": true, | 4 | "private": true, |
5 | "sideEffects": false, | 5 | "sideEffects": false, |
6 | "main": "dist/index.cjs", | 6 | "type": "module", |
7 | "types": "dist-types/index.d.ts", | 7 | "types": "dist-types/index.d.ts", |
8 | "scripts": { | 8 | "scripts": { |
9 | "typecheck": "tsc" | 9 | "typecheck": "tsc" |