Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
100 additions
and
100 deletions.
There are no files selected for viewing
72 changes: 36 additions & 36 deletions
72
packages/next/bundles/webpack/packages/lazy-compilation-node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
/* global __resourceQuery */ | ||
|
||
'use strict' | ||
"use strict"; | ||
|
||
var urlBase = decodeURIComponent(__resourceQuery.slice(1)) | ||
var urlBase = decodeURIComponent(__resourceQuery.slice(1)); | ||
exports.keepAlive = function (options) { | ||
var data = options.data | ||
var onError = options.onError | ||
var active = options.active | ||
var module = options.module | ||
var response | ||
var request = ( | ||
urlBase.startsWith('https') ? require('https') : require('http') | ||
).request( | ||
urlBase + data, | ||
{ | ||
agent: false, | ||
headers: { accept: 'text/event-stream' }, | ||
}, | ||
function (res) { | ||
response = res | ||
response.on('error', errorHandler) | ||
if (!active && !module.hot) { | ||
console.log( | ||
'Hot Module Replacement is not enabled. Waiting for process restart...' | ||
) | ||
} | ||
} | ||
) | ||
function errorHandler(err) { | ||
err.message = | ||
'Problem communicating active modules to the server: ' + err.message | ||
onError(err) | ||
} | ||
request.on('error', errorHandler) | ||
request.end() | ||
return function () { | ||
response.destroy() | ||
} | ||
} | ||
var data = options.data; | ||
var onError = options.onError; | ||
var active = options.active; | ||
var module = options.module; | ||
var response; | ||
var request = ( | ||
urlBase.startsWith("https") ? require("https") : require("http") | ||
).request( | ||
urlBase + data, | ||
{ | ||
agent: false, | ||
headers: { accept: "text/event-stream" } | ||
}, | ||
function (res) { | ||
response = res; | ||
response.on("error", errorHandler); | ||
if (!active && !module.hot) { | ||
console.log( | ||
"Hot Module Replacement is not enabled. Waiting for process restart..." | ||
); | ||
} | ||
} | ||
); | ||
function errorHandler(err) { | ||
err.message = | ||
"Problem communicating active modules to the server: " + err.message; | ||
onError(err); | ||
} | ||
request.on("error", errorHandler); | ||
request.end(); | ||
return function () { | ||
response.destroy(); | ||
}; | ||
}; |
128 changes: 64 additions & 64 deletions
128
packages/next/bundles/webpack/packages/lazy-compilation-web.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
/* global __resourceQuery */ | ||
|
||
'use strict' | ||
"use strict"; | ||
|
||
if (typeof EventSource !== 'function') { | ||
throw new Error( | ||
"Environment doesn't support lazy compilation (requires EventSource)" | ||
) | ||
if (typeof EventSource !== "function") { | ||
throw new Error( | ||
"Environment doesn't support lazy compilation (requires EventSource)" | ||
); | ||
} | ||
|
||
var urlBase = decodeURIComponent(__resourceQuery.slice(1)) | ||
var activeEventSource | ||
var activeKeys = new Map() | ||
var errorHandlers = new Set() | ||
var urlBase = decodeURIComponent(__resourceQuery.slice(1)); | ||
var activeEventSource; | ||
var activeKeys = new Map(); | ||
var errorHandlers = new Set(); | ||
|
||
var updateEventSource = function updateEventSource() { | ||
if (activeEventSource) activeEventSource.close() | ||
if (activeKeys.size) { | ||
activeEventSource = new EventSource( | ||
urlBase + Array.from(activeKeys.keys()).join('@') | ||
) | ||
activeEventSource.onerror = function (event) { | ||
errorHandlers.forEach(function (onError) { | ||
onError( | ||
new Error( | ||
'Problem communicating active modules to the server: ' + | ||
event.message + | ||
' ' + | ||
event.filename + | ||
':' + | ||
event.lineno + | ||
':' + | ||
event.colno + | ||
' ' + | ||
event.error | ||
) | ||
) | ||
}) | ||
} | ||
} else { | ||
activeEventSource = undefined | ||
} | ||
} | ||
if (activeEventSource) activeEventSource.close(); | ||
if (activeKeys.size) { | ||
activeEventSource = new EventSource( | ||
urlBase + Array.from(activeKeys.keys()).join("@") | ||
); | ||
activeEventSource.onerror = function (event) { | ||
errorHandlers.forEach(function (onError) { | ||
onError( | ||
new Error( | ||
"Problem communicating active modules to the server: " + | ||
event.message + | ||
" " + | ||
event.filename + | ||
":" + | ||
event.lineno + | ||
":" + | ||
event.colno + | ||
" " + | ||
event.error | ||
) | ||
); | ||
}); | ||
}; | ||
} else { | ||
activeEventSource = undefined; | ||
} | ||
}; | ||
|
||
exports.keepAlive = function (options) { | ||
var data = options.data | ||
var onError = options.onError | ||
var active = options.active | ||
var module = options.module | ||
errorHandlers.add(onError) | ||
var value = activeKeys.get(data) || 0 | ||
activeKeys.set(data, value + 1) | ||
if (value === 0) { | ||
updateEventSource() | ||
} | ||
if (!active && !module.hot) { | ||
console.log( | ||
'Hot Module Replacement is not enabled. Waiting for process restart...' | ||
) | ||
} | ||
var data = options.data; | ||
var onError = options.onError; | ||
var active = options.active; | ||
var module = options.module; | ||
errorHandlers.add(onError); | ||
var value = activeKeys.get(data) || 0; | ||
activeKeys.set(data, value + 1); | ||
if (value === 0) { | ||
updateEventSource(); | ||
} | ||
if (!active && !module.hot) { | ||
console.log( | ||
"Hot Module Replacement is not enabled. Waiting for process restart..." | ||
); | ||
} | ||
|
||
return function () { | ||
errorHandlers.delete(onError) | ||
setTimeout(function () { | ||
var value = activeKeys.get(data) | ||
if (value === 1) { | ||
activeKeys.delete(data) | ||
updateEventSource() | ||
} else { | ||
activeKeys.set(data, value - 1) | ||
} | ||
}, 1000) | ||
} | ||
} | ||
return function () { | ||
errorHandlers.delete(onError); | ||
setTimeout(function () { | ||
var value = activeKeys.get(data); | ||
if (value === 1) { | ||
activeKeys.delete(data); | ||
updateEventSource(); | ||
} else { | ||
activeKeys.set(data, value - 1); | ||
} | ||
}, 1000); | ||
}; | ||
}; |