Skip to content

Commit

Permalink
locate wasm/data/so in the same directory with js
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Aug 23, 2024
1 parent d73378e commit e3a62dc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import antfu from '@antfu/eslint-config'

export default antfu({
ignores: ['page/pre.js']
ignores: ['page/pre.ts']
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"devDependencies": {
"@antfu/eslint-config": "^2.25.1",
"@types/textarea-caret": "^3.0.3",
"error-stack-parser": "^2.1.4",
"esbuild": "^0.23.0",
"eslint": "^9.9.0",
"textarea-caret": "^3.1.0",
Expand Down
15 changes: 0 additions & 15 deletions page/pre.js

This file was deleted.

34 changes: 34 additions & 0 deletions page/pre.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import ErrorStackParser from 'error-stack-parser'

const urlPrefix = (() => {
let err: Error
try {
throw new Error()
}
catch (e) {
err = e as Error
}
const fileName = ErrorStackParser.parse(err)[0].fileName!
return fileName.slice(0, fileName.lastIndexOf('/') + 1)
})()

// @ts-expect-error defined by emscripten
Module = {
printErr(message: string) {
const match = message.match(/^[EWID]/)
if (match) {
({
E: console.error,
W: console.warn,
I: console.info,
D: console.debug,
})[message[0] as 'E' | 'W' | 'I' | 'D'](message.slice(1))
}
else {
console.error(message)
}
},
locateFile(file: string) {
return urlPrefix + file
},
}
18 changes: 14 additions & 4 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { build } from 'esbuild'

await build({
entryPoints: ['page/index.ts'],
const common = {
bundle: true,
outfile: 'build/index.js',
target: 'es2020',
format: 'esm',
platform: 'browser',
minify: true,
minify: false, // avoid name conflict since pre.js and index.js are simply concatenated
sourcemap: false, // meaningless as index.js is appended to Fcitx5.js
}

await build({
...common,
entryPoints: ['page/index.ts'],
outfile: 'build/index.js',
})

await build({
...common,
entryPoints: ['page/pre.ts'],
outfile: 'build/pre.js',
})
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ target_link_libraries(Fcitx5
"-sMAXIMUM_MEMORY=4GB"
"-sEXPORTED_RUNTIME_METHODS=['ccall','FS']"
"-sENVIRONMENT=web" # disable require("ws") in Fcitx5.js which is rejected by project user's bundler
"--extern-pre-js ${PROJECT_SOURCE_DIR}/page/pre.js"
"--extern-pre-js ${PROJECT_BINARY_DIR}/pre.js"
"--extern-post-js ${PROJECT_BINARY_DIR}/index.js"
"--preload-file ${PROJECT_BINARY_DIR}/sysroot/usr/share/fcitx5@/usr/share/fcitx5"
"--preload-file ${PROJECT_BINARY_DIR}/sysroot/usr/share/X11@/usr/share/X11"
Expand Down

0 comments on commit e3a62dc

Please sign in to comment.