Fix issues with missing sourcemaps (#6572)

* Fix issues with missing sourcemaps

* Change sourcemap back from `'inline'` to `true`

* Specialcase `/preload.cjs.map` in server

* Address review
This commit is contained in:
somebody1234 2023-05-10 19:03:24 +10:00 committed by GitHub
parent 739a7316fb
commit 0d9186b23c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 25 deletions

View File

@ -10,6 +10,8 @@ import createServer from 'create-servers'
import * as contentConfig from 'enso-content-config' import * as contentConfig from 'enso-content-config'
import * as paths from '../paths'
const logger = contentConfig.logger const logger = contentConfig.logger
// ================= // =================
@ -18,20 +20,6 @@ const logger = contentConfig.logger
const HTTP_STATUS_OK = 200 const HTTP_STATUS_OK = 200
// ======================
// === URL Parameters ===
// ======================
/** Construct URL query with the given parameters. For each `key` - `value` pair,
* `key=value` will be added to the query. */
export function urlParamsFromObject(obj: Record<string, string>) {
const params = []
for (const [key, value] of Object.entries(obj)) {
params.push(`${key}=${encodeURIComponent(value)}`)
}
return params.length === 0 ? '' : '?' + params.join('&')
}
// ============== // ==============
// === Config === // === Config ===
// ============== // ==============
@ -110,7 +98,13 @@ export class Server {
} else { } else {
const url = requestUrl.split('?')[0] const url = requestUrl.split('?')[0]
const resource = url === '/' ? '/index.html' : requestUrl const resource = url === '/' ? '/index.html' : requestUrl
const resourceFile = `${this.config.dir}${resource}` // `preload.cjs` must be specialcased here as it is loaded by electron from the root,
// in contrast to all assets loaded by the window, which are loaded from `assets/` via
// this server.
const resourceFile =
resource === '/preload.cjs.map'
? `${paths.APP_PATH}${resource}`
: `${this.config.dir}${resource}`
fs.readFile(resourceFile, (err, data) => { fs.readFile(resourceFile, (err, data) => {
if (err) { if (err) {
logger.error(`Resource '${resource}' not found.`) logger.error(`Resource '${resource}' not found.`)

View File

@ -345,16 +345,17 @@ class App {
/** Redirect the web view to `localhost:<port>` to see the served website. */ /** Redirect the web view to `localhost:<port>` to see the served website. */
loadWindowContent() { loadWindowContent() {
if (this.window != null) { if (this.window != null) {
const urlCfg: Record<string, string> = {} const searchParams: Record<string, string> = {}
for (const option of this.args.optionsRecursive()) { for (const option of this.args.optionsRecursive()) {
if (option.value !== option.default && option.passToWebApplication) { if (option.value !== option.default && option.passToWebApplication) {
urlCfg[option.qualifiedName()] = String(option.value) searchParams[option.qualifiedName()] = option.value.toString()
} }
} }
const params = server.urlParamsFromObject(urlCfg) const address = new URL('http://localhost')
const address = `http://localhost:${this.serverPort()}${params}` address.port = this.serverPort().toString()
logger.log(`Loading the window address '${address}'.`) address.search = new URLSearchParams(searchParams).toString()
void this.window.loadURL(address) logger.log(`Loading the window address '${address.toString()}'.`)
void this.window.loadURL(address.toString())
} }
} }
@ -423,7 +424,7 @@ class App {
// =================== // ===================
process.on('uncaughtException', (err, origin) => { process.on('uncaughtException', (err, origin) => {
console.error(`Uncaught exception: ${String(err)}\nException origin: ${origin}`) console.error(`Uncaught exception: ${err.toString()}\nException origin: ${origin}`)
electron.dialog.showErrorBox(common.PRODUCT_NAME, err.stack ?? err.toString()) electron.dialog.showErrorBox(common.PRODUCT_NAME, err.stack ?? err.toString())
electron.app.exit(1) electron.app.exit(1)
}) })

View File

@ -88,6 +88,7 @@ export function bundlerOptions(args: Arguments) {
loader: { loader: {
'.html': 'copy', '.html': 'copy',
'.css': 'copy', '.css': 'copy',
'.map': 'copy',
'.wasm': 'copy', '.wasm': 'copy',
'.svg': 'copy', '.svg': 'copy',
'.png': 'copy', '.png': 'copy',

View File

@ -47,7 +47,7 @@
gui/: gui/:
assets/: assets/:
dynamic-assets/: # Assets used by the WASM application. dynamic-assets/: # Assets used by the WASM application.
pkg.js: # The `pks.js` artifact of wasm-pack WITH bundled snippets. pkg.js: # The `pkg.js` artifact of wasm-pack WITH bundled snippets.
pkg.js.map: # The sourcemap mapping to `pkg.js` generated by wasm-pack. pkg.js.map: # The sourcemap mapping to `pkg.js` generated by wasm-pack.
pkg-opt.wasm: # The optimized WASM artifact. pkg-opt.wasm: # The optimized WASM artifact.
index.js: index.js:
@ -60,7 +60,8 @@
index.js: # The main JS bundle to load WASM and JS wasm-pack bundles. index.js: # The main JS bundle to load WASM and JS wasm-pack bundles.
index.d.ts: # TypeScript types interface file. index.d.ts: # TypeScript types interface file.
index.js.map: # The sourcemap mapping to `index.js`. index.js.map: # The sourcemap mapping to `index.js`.
pkg.js: # The `pks.js` artifact of wasm-pack WITH bundled snippets. pkg.js: # The `pkg.js` artifact of wasm-pack WITH bundled snippets.
pkg.js.map: # The sourcemap mapping to `pkg.js` generated by wasm-pack.
pkg.wasm: # The `pks_bg.wasm` artifact of wasm-pack. pkg.wasm: # The `pks_bg.wasm` artifact of wasm-pack.
pkg-opt.wasm: # The optimized `pks_bg.wasm`. pkg-opt.wasm: # The optimized `pks_bg.wasm`.
distribution/: distribution/:

View File

@ -451,10 +451,16 @@ impl Artifact {
index_d_ts: _, index_d_ts: _,
index_js_map: _, index_js_map: _,
pkg_js, pkg_js,
pkg_js_map,
pkg_wasm: _, pkg_wasm: _,
pkg_opt_wasm, pkg_opt_wasm,
} = &self.0; } = &self.0;
vec![dynamic_assets.as_path(), pkg_js.as_path(), pkg_opt_wasm.as_path()] vec![
dynamic_assets.as_path(),
pkg_js.as_path(),
pkg_js_map.as_path(),
pkg_opt_wasm.as_path(),
]
} }
pub fn symlink_ensogl_dist(&self, linked_dist: &RepoRootTargetEnsoglPackLinkedDist) -> Result { pub fn symlink_ensogl_dist(&self, linked_dist: &RepoRootTargetEnsoglPackLinkedDist) -> Result {