Comparing version 1.0.0-beta.5 to 1.0.0-beta.6
@@ -42,3 +42,5 @@ // register service worker | ||
console.log('[vite] connecting...'); | ||
const socket = new WebSocket(`ws://${location.hostname}:24678`); | ||
const socketProtocol = location.protocol === 'https:' ? 'wss' : 'ws'; | ||
const socketUrl = `${socketProtocol}://${location.host}`; | ||
const socket = new WebSocket(socketUrl, 'vite-hmr'); | ||
function warnFailedFetch(err, path) { | ||
@@ -88,6 +90,3 @@ if (!err.message.match('fetch')) { | ||
case 'style-remove': | ||
const link = document.getElementById(`vite-css-${id}`); | ||
if (link) { | ||
document.head.removeChild(link); | ||
} | ||
removeStyle(id); | ||
break; | ||
@@ -123,4 +122,8 @@ case 'js-update': | ||
setInterval(() => { | ||
new WebSocket(`ws://${location.hostname}:24678`).addEventListener('open', () => { | ||
fetch('/') | ||
.then(() => { | ||
location.reload(); | ||
}) | ||
.catch((e) => { | ||
/* ignore */ | ||
}); | ||
@@ -147,2 +150,3 @@ }, 1000); | ||
document.adoptedStyleSheets = [...document.adoptedStyleSheets, style]; | ||
sheetsMap.set(id, style); | ||
} | ||
@@ -159,2 +163,3 @@ else { | ||
document.head.appendChild(style); | ||
sheetsMap.set(id, style); | ||
} | ||
@@ -166,2 +171,17 @@ else { | ||
} | ||
function removeStyle(id) { | ||
let style = sheetsMap.get(id); | ||
if (style) { | ||
if (supportsConstructedSheet) { | ||
// @ts-ignore | ||
const index = document.adoptedStyleSheets.indexOf(style); | ||
// @ts-ignore | ||
document.adoptedStyleSheets.splice(index, 1); | ||
} | ||
else { | ||
document.head.removeChild(style); | ||
} | ||
sheetsMap.delete(id); | ||
} | ||
} | ||
async function updateModule(id, changedPath, timestamp) { | ||
@@ -168,0 +188,0 @@ const mod = hotModulesMap.get(id); |
@@ -243,19 +243,23 @@ "use strict"; | ||
resolveRelativeRequest(importer, importee) { | ||
let resolved = path_1.default.posix.resolve(path_1.default.posix.dirname(importer), importee); | ||
for (const alias in literalDirAlias) { | ||
if (importer.startsWith(alias)) { | ||
if (!resolved.startsWith(alias)) { | ||
// resolved path is outside of alias directory, we need to use | ||
// its full path instead | ||
const importerFilePath = resolver.requestToFile(importer); | ||
const importeeFilePath = path_1.default.resolve(path_1.default.dirname(importerFilePath), importee); | ||
resolved = resolver.fileToRequest(importeeFilePath); | ||
const queryMatch = importee.match(utils_1.queryRE); | ||
let resolved = importee; | ||
if (importee.startsWith('.')) { | ||
resolved = path_1.default.posix.resolve(path_1.default.posix.dirname(importer), importee); | ||
for (const alias in literalDirAlias) { | ||
if (importer.startsWith(alias)) { | ||
if (!resolved.startsWith(alias)) { | ||
// resolved path is outside of alias directory, we need to use | ||
// its full path instead | ||
const importerFilePath = resolver.requestToFile(importer); | ||
const importeeFilePath = path_1.default.resolve(path_1.default.dirname(importerFilePath), importee); | ||
resolved = resolver.fileToRequest(importeeFilePath); | ||
} | ||
break; | ||
} | ||
break; | ||
} | ||
} | ||
const queryMatch = importee.match(utils_1.queryRE); | ||
return { | ||
// path resolve strips ending / which should be preserved | ||
pathname: utils_1.cleanUrl(resolved) + (importee.endsWith('/') ? '/' : ''), | ||
pathname: utils_1.cleanUrl(resolved) + | ||
// path resolve strips ending / which should be preserved | ||
(importee.endsWith('/') && !resolved.endsWith('/') ? '/' : ''), | ||
query: queryMatch ? queryMatch[0] : '' | ||
@@ -262,0 +266,0 @@ }; |
@@ -92,3 +92,6 @@ "use strict"; | ||
if (https) { | ||
return require('http2').createSecureServer(resolveHttpsConfig(httpsOptions), requestListener); | ||
return require('http2').createSecureServer({ | ||
...resolveHttpsConfig(httpsOptions), | ||
allowHTTP1: true | ||
}, requestListener); | ||
} | ||
@@ -95,0 +98,0 @@ else { |
@@ -65,3 +65,10 @@ "use strict"; | ||
// start a websocket server to send hmr notifications to the client | ||
const wss = new ws_1.default.Server({ port: 24678 }); | ||
const wss = new ws_1.default.Server({ noServer: true }); | ||
server.on('upgrade', (req, socket, head) => { | ||
if (req.headers['sec-websocket-protocol'] === 'vite-hmr') { | ||
wss.handleUpgrade(req, socket, head, (ws) => { | ||
wss.emit('connection', ws, req); | ||
}); | ||
} | ||
}); | ||
wss.on('connection', (socket) => { | ||
@@ -68,0 +75,0 @@ exports.debugHmr('ws client connected'); |
@@ -10,2 +10,7 @@ "use strict"; | ||
const resolver_1 = require("../resolver"); | ||
let isRunningWithYarnPnp; | ||
try { | ||
isRunningWithYarnPnp = Boolean(require('pnpapi')); | ||
} | ||
catch { } | ||
exports.resolveFrom = (root, id) => resolve_1.default.sync(id, { | ||
@@ -15,3 +20,3 @@ basedir: root, | ||
// necessary to work with pnpm | ||
preserveSymlinks: false | ||
preserveSymlinks: isRunningWithYarnPnp || false | ||
}); | ||
@@ -18,0 +23,0 @@ exports.queryRE = /\?.*$/; |
{ | ||
"name": "vite", | ||
"version": "1.0.0-beta.5", | ||
"version": "1.0.0-beta.6", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "Evan You", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
332645
5901
6