@parcel/transformer-react-refresh-wrap
Advanced tools
Comparing version 2.0.0-canary.1761 to 2.0.0-canary.1764
"use strict"; | ||
var Refresh = require('react-refresh/runtime'); | ||
var { | ||
version | ||
} = require('react-refresh/package.json'); | ||
function debounce(func, delay) { | ||
@@ -38,2 +35,26 @@ if (process.env.NODE_ENV === 'test') { | ||
}, 30); | ||
module.exports.init = function () { | ||
if (!globalThis.$RefreshReg$) { | ||
Refresh.injectIntoGlobalHook(globalThis); | ||
globalThis.$RefreshReg$ = function () {}; | ||
globalThis.$RefreshSig$ = function () { | ||
return function (type) { | ||
return type; | ||
}; | ||
}; | ||
if (typeof window !== 'undefined') { | ||
let ErrorOverlay = require('react-error-overlay'); | ||
ErrorOverlay.setEditorHandler(function (errorLocation) { | ||
let file = `${errorLocation.fileName}:${errorLocation.lineNumber || 1}:${errorLocation.colNumber || 1}`; | ||
fetch(`/__parcel_launch_editor?file=${encodeURIComponent(file)}`); | ||
}); | ||
ErrorOverlay.startReportingRuntimeErrors({ | ||
onError: function () {} | ||
}); | ||
window.addEventListener('parcelhmraccept', () => { | ||
ErrorOverlay.dismissRuntimeErrors(); | ||
}); | ||
} | ||
} | ||
}; | ||
@@ -45,13 +66,11 @@ // Everything below is either adapted or copied from | ||
module.exports.prelude = function (module) { | ||
window.__REACT_REFRESH_VERSION_TRANSFORMER = version; | ||
window.$RefreshReg$ = function (type, id) { | ||
if (window.__REACT_REFRESH_VERSION_TRANSFORMER && window.__REACT_REFRESH_VERSION_RUNTIME && window.__REACT_REFRESH_VERSION_TRANSFORMER !== window.__REACT_REFRESH_VERSION_RUNTIME) { | ||
// Both versions were set and they did not match | ||
throw new Error(`react-refresh versions did not match between transformer and runtime. Please check your dependencies. Transformer: ${window.__REACT_REFRESH_VERSION_TRANSFORMER}, Runtime: ${window.__REACT_REFRESH_VERSION_RUNTIME}`); | ||
} | ||
globalThis.$RefreshReg$ = function (type, id) { | ||
Refresh.register(type, module.id + ' ' + id); | ||
}; | ||
window.$RefreshSig$ = Refresh.createSignatureFunctionForTransform; | ||
globalThis.$RefreshSig$ = Refresh.createSignatureFunctionForTransform; | ||
}; | ||
module.exports.postlude = function (module) { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
if (isReactRefreshBoundary(module.exports)) { | ||
@@ -58,0 +77,0 @@ registerExportsForReactRefresh(module); |
@@ -38,4 +38,5 @@ "use strict"; | ||
code = `var ${name} = require(${JSON.stringify(wrapperPath)}); | ||
var prevRefreshReg = window.$RefreshReg$; | ||
var prevRefreshSig = window.$RefreshSig$; | ||
${name}.init(); | ||
var prevRefreshReg = globalThis.$RefreshReg$; | ||
var prevRefreshSig = globalThis.$RefreshSig$; | ||
${name}.prelude(module); | ||
@@ -47,4 +48,4 @@ | ||
} finally { | ||
window.$RefreshReg$ = prevRefreshReg; | ||
window.$RefreshSig$ = prevRefreshSig; | ||
globalThis.$RefreshReg$ = prevRefreshReg; | ||
globalThis.$RefreshSig$ = prevRefreshSig; | ||
}`; | ||
@@ -51,0 +52,0 @@ asset.setCode(code); |
{ | ||
"name": "@parcel/transformer-react-refresh-wrap", | ||
"version": "2.0.0-canary.1761+d19b1f6bd", | ||
"version": "2.0.0-canary.1764+8a15d0c64", | ||
"license": "MIT", | ||
@@ -20,10 +20,11 @@ "publishConfig": { | ||
"node": ">= 16.0.0", | ||
"parcel": "^2.0.0-canary.1759+d19b1f6bd" | ||
"parcel": "^2.0.0-canary.1762+8a15d0c64" | ||
}, | ||
"dependencies": { | ||
"@parcel/plugin": "2.0.0-canary.1761+d19b1f6bd", | ||
"@parcel/utils": "2.0.0-canary.1761+d19b1f6bd", | ||
"react-refresh": ">=0.9 <=0.14" | ||
"@parcel/plugin": "2.0.0-canary.1764+8a15d0c64", | ||
"@parcel/utils": "2.0.0-canary.1764+8a15d0c64", | ||
"react-error-overlay": "6.0.9", | ||
"react-refresh": ">=0.9 <=0.16" | ||
}, | ||
"gitHead": "d19b1f6bdb05eb5a3085f44daae15c0fe2709ab9" | ||
"gitHead": "8a15d0c64fc95a151bcf8b3f0428acc4cda745ee" | ||
} |
var Refresh = require('react-refresh/runtime'); | ||
var {version} = require('react-refresh/package.json'); | ||
@@ -36,2 +35,32 @@ function debounce(func, delay) { | ||
module.exports.init = function () { | ||
if (!globalThis.$RefreshReg$) { | ||
Refresh.injectIntoGlobalHook(globalThis); | ||
globalThis.$RefreshReg$ = function () {}; | ||
globalThis.$RefreshSig$ = function () { | ||
return function (type) { | ||
return type; | ||
}; | ||
}; | ||
if (typeof window !== 'undefined') { | ||
let ErrorOverlay = require('react-error-overlay'); | ||
ErrorOverlay.setEditorHandler(function editorHandler(errorLocation) { | ||
let file = `${errorLocation.fileName}:${ | ||
errorLocation.lineNumber || 1 | ||
}:${errorLocation.colNumber || 1}`; | ||
fetch(`/__parcel_launch_editor?file=${encodeURIComponent(file)}`); | ||
}); | ||
ErrorOverlay.startReportingRuntimeErrors({ | ||
onError: function () {}, | ||
}); | ||
window.addEventListener('parcelhmraccept', () => { | ||
ErrorOverlay.dismissRuntimeErrors(); | ||
}); | ||
} | ||
} | ||
}; | ||
// Everything below is either adapted or copied from | ||
@@ -42,21 +71,13 @@ // https://github.com/facebook/metro/blob/61de16bd1edd7e738dd0311c89555a644023ab2d/packages/metro/src/lib/polyfills/require.js | ||
module.exports.prelude = function (module) { | ||
window.__REACT_REFRESH_VERSION_TRANSFORMER = version; | ||
window.$RefreshReg$ = function (type, id) { | ||
if ( | ||
window.__REACT_REFRESH_VERSION_TRANSFORMER && | ||
window.__REACT_REFRESH_VERSION_RUNTIME && | ||
window.__REACT_REFRESH_VERSION_TRANSFORMER !== | ||
window.__REACT_REFRESH_VERSION_RUNTIME | ||
) { | ||
// Both versions were set and they did not match | ||
throw new Error( | ||
`react-refresh versions did not match between transformer and runtime. Please check your dependencies. Transformer: ${window.__REACT_REFRESH_VERSION_TRANSFORMER}, Runtime: ${window.__REACT_REFRESH_VERSION_RUNTIME}`, | ||
); | ||
} | ||
globalThis.$RefreshReg$ = function (type, id) { | ||
Refresh.register(type, module.id + ' ' + id); | ||
}; | ||
window.$RefreshSig$ = Refresh.createSignatureFunctionForTransform; | ||
globalThis.$RefreshSig$ = Refresh.createSignatureFunctionForTransform; | ||
}; | ||
module.exports.postlude = function (module) { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
if (isReactRefreshBoundary(module.exports)) { | ||
@@ -63,0 +84,0 @@ registerExportsForReactRefresh(module); |
@@ -44,4 +44,5 @@ // @flow | ||
code = `var ${name} = require(${JSON.stringify(wrapperPath)}); | ||
var prevRefreshReg = window.$RefreshReg$; | ||
var prevRefreshSig = window.$RefreshSig$; | ||
${name}.init(); | ||
var prevRefreshReg = globalThis.$RefreshReg$; | ||
var prevRefreshSig = globalThis.$RefreshSig$; | ||
${name}.prelude(module); | ||
@@ -53,4 +54,4 @@ | ||
} finally { | ||
window.$RefreshReg$ = prevRefreshReg; | ||
window.$RefreshSig$ = prevRefreshSig; | ||
globalThis.$RefreshReg$ = prevRefreshReg; | ||
globalThis.$RefreshSig$ = prevRefreshSig; | ||
}`; | ||
@@ -57,0 +58,0 @@ |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
19639
521
4
3
+ Addedreact-error-overlay@6.0.9
+ Addedreact-error-overlay@6.0.9(transitive)
+ Addedreact-refresh@0.16.0(transitive)
- Removedreact-refresh@0.14.2(transitive)
Updatedreact-refresh@>=0.9 <=0.16