Skip to content

Commit

Permalink
fix(server): Fix source map retrieval for updated builds (#542)
Browse files Browse the repository at this point in the history
* fix (server): Fix source map retrieval for updated builds

This PR adds the fix submitted in Remix PR #8174. The issue is caused when the build server imports an updated server build with a ?t=timestamp suffix. This causes the source map support library to fail to load the source map.

remix-run/remix#8174

* Update index.js

* fix lint/build issues

---------

Co-authored-by: Kent C. Dodds <[email protected]>
  • Loading branch information
kiliman and kentcdodds authored Nov 30, 2023
1 parent 5397661 commit 66c19d4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import 'dotenv/config'
import 'source-map-support/register.js'
import * as fs from 'fs'
import { installGlobals } from '@remix-run/node'
import chalk from 'chalk'
import closeWithGrace from 'close-with-grace'
import sourceMapSupport from 'source-map-support'

sourceMapSupport.install({
retrieveSourceMap: function (source) {
// get source file without the `file://` prefix or `?t=...` suffix
const match = source.match(/^file:\/\/(.*)\?t=[.\d]+$/)
if (match) {
return {
url: source,
map: fs.readFileSync(`${match[1]}.map`, 'utf8'),
}
}
return null
},
})

installGlobals()

Expand Down

0 comments on commit 66c19d4

Please sign in to comment.