Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove all eval for HMR #814

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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