Skip to content

Commit

Permalink
Remove all eval for hmr
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgv committed Nov 10, 2023
1 parent 74aa2da commit 1874593
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 255 deletions.
2 changes: 1 addition & 1 deletion cli/create-plasmo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-plasmo",
"version": "0.83.1",
"version": "0.84.0",
"description": "Create Plasmo Framework Browser Extension",
"main": "dist/index.js",
"bin": "bin/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion cli/plasmo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plasmo",
"version": "0.83.1",
"version": "0.84.0",
"description": "The Plasmo Framework CLI",
"publishConfig": {
"types": "dist/type.d.ts"
Expand Down
4 changes: 2 additions & 2 deletions core/parcel-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plasmohq/parcel-config",
"version": "0.39.5",
"version": "0.40.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -14,7 +14,7 @@
"@parcel/optimizer-data-url": "2.9.3",
"@parcel/reporter-bundle-buddy": "2.9.3",
"@parcel/resolver-default": "2.9.3",
"@parcel/runtime-js": "2.9.3",
"@parcel/runtime-js": "2.8.3",
"@parcel/runtime-service-worker": "2.9.3",
"@parcel/source-map": "2.1.1",
"@parcel/transformer-babel": "2.9.3",
Expand Down
2 changes: 1 addition & 1 deletion core/parcel-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plasmohq/parcel-runtime",
"version": "0.22.1",
"version": "0.23.0",
"description": "Plasmo Parcel Runtime",
"files": [
"dist"
Expand Down
17 changes: 1 addition & 16 deletions core/parcel-runtime/src/utils/hmr-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ export function hmrDownload(asset: HmrAsset) {
}
}

let supportsSourceURL = false
try {
;(0, eval)('throw new Error("test"); //# sourceURL=test.js')
} catch (err) {
supportsSourceURL = err.stack.includes("test.js")
}

export async function hmrApplyUpdates(assets: Array<HmrAsset>) {
global.parcelHotUpdate = Object.create(null)

Expand All @@ -49,9 +42,7 @@ export async function hmrApplyUpdates(assets: Array<HmrAsset>) {
)
})

const scriptsToRemove = await Promise.all(
supportsSourceURL ? [] : assets.map(hmrDownload)
)
const scriptsToRemove = await Promise.all(assets.map(hmrDownload))

try {
assets.forEach(function (asset) {
Expand Down Expand Up @@ -146,12 +137,6 @@ function hmrApply(bundle: ParcelBundle, asset: HmrAsset) {
}
}

if (supportsSourceURL) {
// Global eval. We would use `new Function` here but browser
// support for source maps is better with eval.
;(0, eval)(asset.output)
}

const fn = global.parcelHotUpdate[asset.id]
modules[asset.id] = [fn, deps]
} else if (bundle.parent) {
Expand Down
Loading

0 comments on commit 1874593

Please sign in to comment.