vite 3.2.1 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import require$$0$1 from 'postcss';
2
- import { A as commonjsGlobal } from './dep-d29b4e33.js';
2
+ import { A as commonjsGlobal } from './dep-c842e491.js';
3
3
  import require$$0 from 'path';
4
4
  import require$$5 from 'crypto';
5
5
  import require$$0__default from 'fs';
@@ -13379,15 +13379,12 @@ async function transformWithEsbuild(code, filename, options, inMap) {
13379
13379
  // these fields would affect the compilation result
13380
13380
  // https://esbuild.github.io/content-types/#tsconfig-json
13381
13381
  const meaningfulFields = [
13382
- 'alwaysStrict',
13383
- 'importsNotUsedAsValues',
13384
- 'jsx',
13382
+ 'target',
13385
13383
  'jsxFactory',
13386
13384
  'jsxFragmentFactory',
13387
- 'jsxImportSource',
13388
- 'preserveValueImports',
13389
- 'target',
13390
- 'useDefineForClassFields'
13385
+ 'useDefineForClassFields',
13386
+ 'importsNotUsedAsValues',
13387
+ 'preserveValueImports'
13391
13388
  ];
13392
13389
  const compilerOptionsForFile = {};
13393
13390
  if (loader === 'ts' || loader === 'tsx') {
@@ -37773,6 +37770,7 @@ async function loadAndTransform(id, url, server, options, timestamp) {
37773
37770
  try {
37774
37771
  map = (convertSourceMap.fromSource(code) ||
37775
37772
  convertSourceMap.fromMapFileSource(code, path$n.dirname(file)))?.toObject();
37773
+ code = code.replace(convertSourceMap.mapFileCommentRegex, blankReplacer);
37776
37774
  }
37777
37775
  catch (e) {
37778
37776
  logger.warn(`Failed to load source map for ${url}.`, {
@@ -41250,6 +41248,10 @@ async function createPluginContainer(config, moduleGraph, watcher) {
41250
41248
  this.filename = filename;
41251
41249
  this.originalCode = code;
41252
41250
  if (inMap) {
41251
+ if (isDebugSourcemapCombineFocused) {
41252
+ // @ts-expect-error inject name for debug purpose
41253
+ inMap.name = '$inMap';
41254
+ }
41253
41255
  this.sourcemapChain.push(inMap);
41254
41256
  }
41255
41257
  }
@@ -44968,7 +44970,7 @@ async function compileCSS(id, code, config, urlReplacer) {
44968
44970
  }));
44969
44971
  }
44970
44972
  if (isModule) {
44971
- postcssPlugins.unshift((await import('./dep-9055f77d.js').then(function (n) { return n.i; })).default({
44973
+ postcssPlugins.unshift((await import('./dep-6873f27c.js').then(function (n) { return n.i; })).default({
44972
44974
  ...modulesOptions,
44973
44975
  getJSON(cssFileName, _modules, outputFileName) {
44974
44976
  modules = _modules;
@@ -59651,7 +59653,7 @@ var debug_1 = function () {
59651
59653
  if (!debug$3) {
59652
59654
  try {
59653
59655
  /* eslint global-require: off */
59654
- debug$3 = src$2.exports("follow-redirects");
59656
+ debug$3 = require("debug")("follow-redirects");
59655
59657
  }
59656
59658
  catch (error) { /* */ }
59657
59659
  if (typeof debug$3 !== "function") {
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { EventEmitter } from 'events';
3
- import { z as picocolors, v as createLogger, g as resolveConfig } from './chunks/dep-d29b4e33.js';
3
+ import { z as picocolors, v as createLogger, g as resolveConfig } from './chunks/dep-c842e491.js';
4
4
  import { VERSION } from './constants.js';
5
5
  import 'node:fs';
6
6
  import 'node:path';
@@ -702,7 +702,7 @@ cli
702
702
  filterDuplicateOptions(options);
703
703
  // output structure is preserved even after bundling so require()
704
704
  // is ok here
705
- const { createServer } = await import('./chunks/dep-d29b4e33.js').then(function (n) { return n.D; });
705
+ const { createServer } = await import('./chunks/dep-c842e491.js').then(function (n) { return n.D; });
706
706
  try {
707
707
  const server = await createServer({
708
708
  root,
@@ -750,7 +750,7 @@ cli
750
750
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
751
751
  .action(async (root, options) => {
752
752
  filterDuplicateOptions(options);
753
- const { build } = await import('./chunks/dep-d29b4e33.js').then(function (n) { return n.C; });
753
+ const { build } = await import('./chunks/dep-c842e491.js').then(function (n) { return n.C; });
754
754
  const buildOptions = cleanOptions(options);
755
755
  try {
756
756
  await build({
@@ -775,7 +775,7 @@ cli
775
775
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
776
776
  .action(async (root, options) => {
777
777
  filterDuplicateOptions(options);
778
- const { optimizeDeps } = await import('./chunks/dep-d29b4e33.js').then(function (n) { return n.B; });
778
+ const { optimizeDeps } = await import('./chunks/dep-c842e491.js').then(function (n) { return n.B; });
779
779
  try {
780
780
  const config = await resolveConfig({
781
781
  root,
@@ -800,7 +800,7 @@ cli
800
800
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
801
801
  .action(async (root, options) => {
802
802
  filterDuplicateOptions(options);
803
- const { preview } = await import('./chunks/dep-d29b4e33.js').then(function (n) { return n.E; });
803
+ const { preview } = await import('./chunks/dep-c842e491.js').then(function (n) { return n.E; });
804
804
  try {
805
805
  const server = await preview({
806
806
  root,
@@ -1,7 +1,7 @@
1
1
  import path, { resolve } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
 
4
- var version = "3.2.1";
4
+ var version = "3.2.2";
5
5
 
6
6
  const VERSION = version;
7
7
  const DEFAULT_MAIN_FIELDS = [
@@ -1,4 +1,4 @@
1
- export { b as build, q as createFilter, v as createLogger, c as createServer, e as defineConfig, f as formatPostcssSourceMap, i as getDepOptimizationConfig, j as isDepsOptimizerEnabled, l as loadConfigFromFile, x as loadEnv, k as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, h as resolveBaseUrl, g as resolveConfig, y as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-d29b4e33.js';
1
+ export { b as build, q as createFilter, v as createLogger, c as createServer, e as defineConfig, f as formatPostcssSourceMap, i as getDepOptimizationConfig, j as isDepsOptimizerEnabled, l as loadConfigFromFile, x as loadEnv, k as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, h as resolveBaseUrl, g as resolveConfig, y as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-c842e491.js';
2
2
  export { VERSION as version } from './constants.js';
3
3
  export { version as esbuildVersion } from 'esbuild';
4
4
  export { VERSION as rollupVersion } from 'rollup';
@@ -31,7 +31,7 @@ var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
31
31
  var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
32
32
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
33
33
 
34
- var version = "3.2.1";
34
+ var version = "3.2.2";
35
35
 
36
36
  const VERSION = version;
37
37
  const VITE_PACKAGE_DIR = path$3.resolve(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -28,7 +28,6 @@
28
28
  "dist",
29
29
  "client.d.ts",
30
30
  "index.cjs",
31
- "src/client",
32
31
  "types"
33
32
  ],
34
33
  "engines": {
@@ -69,8 +68,8 @@
69
68
  },
70
69
  "devDependencies": {
71
70
  "@ampproject/remapping": "^2.2.0",
72
- "@babel/parser": "^7.19.6",
73
- "@babel/types": "^7.19.4",
71
+ "@babel/parser": "^7.20.0",
72
+ "@babel/types": "^7.20.0",
74
73
  "@jridgewell/trace-mapping": "^0.3.17",
75
74
  "@rollup/plugin-alias": "^4.0.2",
76
75
  "@rollup/plugin-commonjs": "^22.0.2",
@@ -1,593 +0,0 @@
1
- import type { ErrorPayload, HMRPayload, Update } from 'types/hmrPayload'
2
- import type { ModuleNamespace, ViteHotContext } from 'types/hot'
3
- import type { InferCustomEventPayload } from 'types/customEvent'
4
- import { ErrorOverlay, overlayId } from './overlay'
5
- // eslint-disable-next-line node/no-missing-import
6
- import '@vite/env'
7
-
8
- // injected by the hmr plugin when served
9
- declare const __BASE__: string
10
- declare const __SERVER_HOST__: string
11
- declare const __HMR_PROTOCOL__: string | null
12
- declare const __HMR_HOSTNAME__: string | null
13
- declare const __HMR_PORT__: number | null
14
- declare const __HMR_DIRECT_TARGET__: string
15
- declare const __HMR_BASE__: string
16
- declare const __HMR_TIMEOUT__: number
17
- declare const __HMR_ENABLE_OVERLAY__: boolean
18
-
19
- console.debug('[vite] connecting...')
20
-
21
- const importMetaUrl = new URL(import.meta.url)
22
-
23
- // use server configuration, then fallback to inference
24
- const serverHost = __SERVER_HOST__
25
- const socketProtocol =
26
- __HMR_PROTOCOL__ || (location.protocol === 'https:' ? 'wss' : 'ws')
27
- const hmrPort = __HMR_PORT__
28
- const socketHost = `${__HMR_HOSTNAME__ || importMetaUrl.hostname}:${
29
- hmrPort || importMetaUrl.port
30
- }${__HMR_BASE__}`
31
- const directSocketHost = __HMR_DIRECT_TARGET__
32
- const base = __BASE__ || '/'
33
- const messageBuffer: string[] = []
34
-
35
- let socket: WebSocket
36
- try {
37
- let fallback: (() => void) | undefined
38
- // only use fallback when port is inferred to prevent confusion
39
- if (!hmrPort) {
40
- fallback = () => {
41
- // fallback to connecting directly to the hmr server
42
- // for servers which does not support proxying websocket
43
- socket = setupWebSocket(socketProtocol, directSocketHost, () => {
44
- const currentScriptHostURL = new URL(import.meta.url)
45
- const currentScriptHost =
46
- currentScriptHostURL.host +
47
- currentScriptHostURL.pathname.replace(/@vite\/client$/, '')
48
- console.error(
49
- '[vite] failed to connect to websocket.\n' +
50
- 'your current setup:\n' +
51
- ` (browser) ${currentScriptHost} <--[HTTP]--> ${serverHost} (server)\n` +
52
- ` (browser) ${socketHost} <--[WebSocket (failing)]--> ${directSocketHost} (server)\n` +
53
- 'Check out your Vite / network configuration and https://vitejs.dev/config/server-options.html#server-hmr .'
54
- )
55
- })
56
- socket.addEventListener(
57
- 'open',
58
- () => {
59
- console.info(
60
- '[vite] Direct websocket connection fallback. Check out https://vitejs.dev/config/server-options.html#server-hmr to remove the previous connection error.'
61
- )
62
- },
63
- { once: true }
64
- )
65
- }
66
- }
67
-
68
- socket = setupWebSocket(socketProtocol, socketHost, fallback)
69
- } catch (error) {
70
- console.error(`[vite] failed to connect to websocket (${error}). `)
71
- }
72
-
73
- function setupWebSocket(
74
- protocol: string,
75
- hostAndPath: string,
76
- onCloseWithoutOpen?: () => void
77
- ) {
78
- const socket = new WebSocket(`${protocol}://${hostAndPath}`, 'vite-hmr')
79
- let isOpened = false
80
-
81
- socket.addEventListener(
82
- 'open',
83
- () => {
84
- isOpened = true
85
- },
86
- { once: true }
87
- )
88
-
89
- // Listen for messages
90
- socket.addEventListener('message', async ({ data }) => {
91
- handleMessage(JSON.parse(data))
92
- })
93
-
94
- // ping server
95
- socket.addEventListener('close', async ({ wasClean }) => {
96
- if (wasClean) return
97
-
98
- if (!isOpened && onCloseWithoutOpen) {
99
- onCloseWithoutOpen()
100
- return
101
- }
102
-
103
- console.log(`[vite] server connection lost. polling for restart...`)
104
- await waitForSuccessfulPing(protocol, hostAndPath)
105
- location.reload()
106
- })
107
-
108
- return socket
109
- }
110
-
111
- function warnFailedFetch(err: Error, path: string | string[]) {
112
- if (!err.message.match('fetch')) {
113
- console.error(err)
114
- }
115
- console.error(
116
- `[hmr] Failed to reload ${path}. ` +
117
- `This could be due to syntax errors or importing non-existent ` +
118
- `modules. (see errors above)`
119
- )
120
- }
121
-
122
- function cleanUrl(pathname: string): string {
123
- const url = new URL(pathname, location.toString())
124
- url.searchParams.delete('direct')
125
- return url.pathname + url.search
126
- }
127
-
128
- let isFirstUpdate = true
129
- const outdatedLinkTags = new WeakSet<HTMLLinkElement>()
130
-
131
- async function handleMessage(payload: HMRPayload) {
132
- switch (payload.type) {
133
- case 'connected':
134
- console.debug(`[vite] connected.`)
135
- sendMessageBuffer()
136
- // proxy(nginx, docker) hmr ws maybe caused timeout,
137
- // so send ping package let ws keep alive.
138
- setInterval(() => {
139
- if (socket.readyState === socket.OPEN) {
140
- socket.send('{"type":"ping"}')
141
- }
142
- }, __HMR_TIMEOUT__)
143
- break
144
- case 'update':
145
- notifyListeners('vite:beforeUpdate', payload)
146
- // if this is the first update and there's already an error overlay, it
147
- // means the page opened with existing server compile error and the whole
148
- // module script failed to load (since one of the nested imports is 500).
149
- // in this case a normal update won't work and a full reload is needed.
150
- if (isFirstUpdate && hasErrorOverlay()) {
151
- window.location.reload()
152
- return
153
- } else {
154
- clearErrorOverlay()
155
- isFirstUpdate = false
156
- }
157
- payload.updates.forEach((update) => {
158
- if (update.type === 'js-update') {
159
- queueUpdate(fetchUpdate(update))
160
- } else {
161
- // css-update
162
- // this is only sent when a css file referenced with <link> is updated
163
- const { path, timestamp } = update
164
- const searchUrl = cleanUrl(path)
165
- // can't use querySelector with `[href*=]` here since the link may be
166
- // using relative paths so we need to use link.href to grab the full
167
- // URL for the include check.
168
- const el = Array.from(
169
- document.querySelectorAll<HTMLLinkElement>('link')
170
- ).find(
171
- (e) =>
172
- !outdatedLinkTags.has(e) && cleanUrl(e.href).includes(searchUrl)
173
- )
174
- if (el) {
175
- const newPath = `${base}${searchUrl.slice(1)}${
176
- searchUrl.includes('?') ? '&' : '?'
177
- }t=${timestamp}`
178
-
179
- // rather than swapping the href on the existing tag, we will
180
- // create a new link tag. Once the new stylesheet has loaded we
181
- // will remove the existing link tag. This removes a Flash Of
182
- // Unstyled Content that can occur when swapping out the tag href
183
- // directly, as the new stylesheet has not yet been loaded.
184
- const newLinkTag = el.cloneNode() as HTMLLinkElement
185
- newLinkTag.href = new URL(newPath, el.href).href
186
- const removeOldEl = () => el.remove()
187
- newLinkTag.addEventListener('load', removeOldEl)
188
- newLinkTag.addEventListener('error', removeOldEl)
189
- outdatedLinkTags.add(el)
190
- el.after(newLinkTag)
191
- }
192
- console.debug(`[vite] css hot updated: ${searchUrl}`)
193
- }
194
- })
195
- break
196
- case 'custom': {
197
- notifyListeners(payload.event, payload.data)
198
- break
199
- }
200
- case 'full-reload':
201
- notifyListeners('vite:beforeFullReload', payload)
202
- if (payload.path && payload.path.endsWith('.html')) {
203
- // if html file is edited, only reload the page if the browser is
204
- // currently on that page.
205
- const pagePath = decodeURI(location.pathname)
206
- const payloadPath = base + payload.path.slice(1)
207
- if (
208
- pagePath === payloadPath ||
209
- payload.path === '/index.html' ||
210
- (pagePath.endsWith('/') && pagePath + 'index.html' === payloadPath)
211
- ) {
212
- location.reload()
213
- }
214
- return
215
- } else {
216
- location.reload()
217
- }
218
- break
219
- case 'prune':
220
- notifyListeners('vite:beforePrune', payload)
221
- // After an HMR update, some modules are no longer imported on the page
222
- // but they may have left behind side effects that need to be cleaned up
223
- // (.e.g style injections)
224
- // TODO Trigger their dispose callbacks.
225
- payload.paths.forEach((path) => {
226
- const fn = pruneMap.get(path)
227
- if (fn) {
228
- fn(dataMap.get(path))
229
- }
230
- })
231
- break
232
- case 'error': {
233
- notifyListeners('vite:error', payload)
234
- const err = payload.err
235
- if (enableOverlay) {
236
- createErrorOverlay(err)
237
- } else {
238
- console.error(
239
- `[vite] Internal Server Error\n${err.message}\n${err.stack}`
240
- )
241
- }
242
- break
243
- }
244
- default: {
245
- const check: never = payload
246
- return check
247
- }
248
- }
249
- }
250
-
251
- function notifyListeners<T extends string>(
252
- event: T,
253
- data: InferCustomEventPayload<T>
254
- ): void
255
- function notifyListeners(event: string, data: any): void {
256
- const cbs = customListenersMap.get(event)
257
- if (cbs) {
258
- cbs.forEach((cb) => cb(data))
259
- }
260
- }
261
-
262
- const enableOverlay = __HMR_ENABLE_OVERLAY__
263
-
264
- function createErrorOverlay(err: ErrorPayload['err']) {
265
- if (!enableOverlay) return
266
- clearErrorOverlay()
267
- document.body.appendChild(new ErrorOverlay(err))
268
- }
269
-
270
- function clearErrorOverlay() {
271
- document
272
- .querySelectorAll(overlayId)
273
- .forEach((n) => (n as ErrorOverlay).close())
274
- }
275
-
276
- function hasErrorOverlay() {
277
- return document.querySelectorAll(overlayId).length
278
- }
279
-
280
- let pending = false
281
- let queued: Promise<(() => void) | undefined>[] = []
282
-
283
- /**
284
- * buffer multiple hot updates triggered by the same src change
285
- * so that they are invoked in the same order they were sent.
286
- * (otherwise the order may be inconsistent because of the http request round trip)
287
- */
288
- async function queueUpdate(p: Promise<(() => void) | undefined>) {
289
- queued.push(p)
290
- if (!pending) {
291
- pending = true
292
- await Promise.resolve()
293
- pending = false
294
- const loading = [...queued]
295
- queued = []
296
- ;(await Promise.all(loading)).forEach((fn) => fn && fn())
297
- }
298
- }
299
-
300
- async function waitForSuccessfulPing(
301
- socketProtocol: string,
302
- hostAndPath: string,
303
- ms = 1000
304
- ) {
305
- const pingHostProtocol = socketProtocol === 'wss' ? 'https' : 'http'
306
-
307
- // eslint-disable-next-line no-constant-condition
308
- while (true) {
309
- try {
310
- // A fetch on a websocket URL will return a successful promise with status 400,
311
- // but will reject a networking error.
312
- // When running on middleware mode, it returns status 426, and an cors error happens if mode is not no-cors
313
- await fetch(`${pingHostProtocol}://${hostAndPath}`, {
314
- mode: 'no-cors'
315
- })
316
- break
317
- } catch (e) {
318
- // wait ms before attempting to ping again
319
- await new Promise((resolve) => setTimeout(resolve, ms))
320
- }
321
- }
322
- }
323
-
324
- // https://wicg.github.io/construct-stylesheets
325
- const supportsConstructedSheet = (() => {
326
- // TODO: re-enable this try block once Chrome fixes the performance of
327
- // rule insertion in really big stylesheets
328
- // try {
329
- // new CSSStyleSheet()
330
- // return true
331
- // } catch (e) {}
332
- return false
333
- })()
334
-
335
- const sheetsMap = new Map<
336
- string,
337
- HTMLStyleElement | CSSStyleSheet | undefined
338
- >()
339
-
340
- export function updateStyle(id: string, content: string): void {
341
- let style = sheetsMap.get(id)
342
- if (supportsConstructedSheet && !content.includes('@import')) {
343
- if (style && !(style instanceof CSSStyleSheet)) {
344
- removeStyle(id)
345
- style = undefined
346
- }
347
-
348
- if (!style) {
349
- style = new CSSStyleSheet()
350
- // @ts-expect-error: using experimental API
351
- style.replaceSync(content)
352
- // @ts-expect-error: using experimental API
353
- document.adoptedStyleSheets = [...document.adoptedStyleSheets, style]
354
- } else {
355
- // @ts-expect-error: using experimental API
356
- style.replaceSync(content)
357
- }
358
- } else {
359
- if (style && !(style instanceof HTMLStyleElement)) {
360
- removeStyle(id)
361
- style = undefined
362
- }
363
-
364
- if (!style) {
365
- style = document.createElement('style')
366
- style.setAttribute('type', 'text/css')
367
- style.setAttribute('data-vite-dev-id', id)
368
- style.innerHTML = content
369
- document.head.appendChild(style)
370
- } else {
371
- style.innerHTML = content
372
- }
373
- }
374
- sheetsMap.set(id, style)
375
- }
376
-
377
- export function removeStyle(id: string): void {
378
- const style = sheetsMap.get(id)
379
- if (style) {
380
- if (style instanceof CSSStyleSheet) {
381
- // @ts-expect-error: using experimental API
382
- document.adoptedStyleSheets = document.adoptedStyleSheets.filter(
383
- (s: CSSStyleSheet) => s !== style
384
- )
385
- } else {
386
- document.head.removeChild(style)
387
- }
388
- sheetsMap.delete(id)
389
- }
390
- }
391
-
392
- async function fetchUpdate({
393
- path,
394
- acceptedPath,
395
- timestamp,
396
- explicitImportRequired
397
- }: Update) {
398
- const mod = hotModulesMap.get(path)
399
- if (!mod) {
400
- // In a code-splitting project,
401
- // it is common that the hot-updating module is not loaded yet.
402
- // https://github.com/vitejs/vite/issues/721
403
- return
404
- }
405
-
406
- const moduleMap = new Map<string, ModuleNamespace>()
407
- const isSelfUpdate = path === acceptedPath
408
-
409
- // determine the qualified callbacks before we re-import the modules
410
- const qualifiedCallbacks = mod.callbacks.filter(({ deps }) =>
411
- deps.includes(acceptedPath)
412
- )
413
-
414
- if (isSelfUpdate || qualifiedCallbacks.length > 0) {
415
- const dep = acceptedPath
416
- const disposer = disposeMap.get(dep)
417
- if (disposer) await disposer(dataMap.get(dep))
418
- const [path, query] = dep.split(`?`)
419
- try {
420
- const newMod: ModuleNamespace = await import(
421
- /* @vite-ignore */
422
- base +
423
- path.slice(1) +
424
- `?${explicitImportRequired ? 'import&' : ''}t=${timestamp}${
425
- query ? `&${query}` : ''
426
- }`
427
- )
428
- moduleMap.set(dep, newMod)
429
- } catch (e) {
430
- warnFailedFetch(e, dep)
431
- }
432
- }
433
-
434
- return () => {
435
- for (const { deps, fn } of qualifiedCallbacks) {
436
- fn(deps.map((dep) => moduleMap.get(dep)))
437
- }
438
- const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`
439
- console.debug(`[vite] hot updated: ${loggedPath}`)
440
- }
441
- }
442
-
443
- function sendMessageBuffer() {
444
- if (socket.readyState === 1) {
445
- messageBuffer.forEach((msg) => socket.send(msg))
446
- messageBuffer.length = 0
447
- }
448
- }
449
-
450
- interface HotModule {
451
- id: string
452
- callbacks: HotCallback[]
453
- }
454
-
455
- interface HotCallback {
456
- // the dependencies must be fetchable paths
457
- deps: string[]
458
- fn: (modules: Array<ModuleNamespace | undefined>) => void
459
- }
460
-
461
- type CustomListenersMap = Map<string, ((data: any) => void)[]>
462
-
463
- const hotModulesMap = new Map<string, HotModule>()
464
- const disposeMap = new Map<string, (data: any) => void | Promise<void>>()
465
- const pruneMap = new Map<string, (data: any) => void | Promise<void>>()
466
- const dataMap = new Map<string, any>()
467
- const customListenersMap: CustomListenersMap = new Map()
468
- const ctxToListenersMap = new Map<string, CustomListenersMap>()
469
-
470
- export function createHotContext(ownerPath: string): ViteHotContext {
471
- if (!dataMap.has(ownerPath)) {
472
- dataMap.set(ownerPath, {})
473
- }
474
-
475
- // when a file is hot updated, a new context is created
476
- // clear its stale callbacks
477
- const mod = hotModulesMap.get(ownerPath)
478
- if (mod) {
479
- mod.callbacks = []
480
- }
481
-
482
- // clear stale custom event listeners
483
- const staleListeners = ctxToListenersMap.get(ownerPath)
484
- if (staleListeners) {
485
- for (const [event, staleFns] of staleListeners) {
486
- const listeners = customListenersMap.get(event)
487
- if (listeners) {
488
- customListenersMap.set(
489
- event,
490
- listeners.filter((l) => !staleFns.includes(l))
491
- )
492
- }
493
- }
494
- }
495
-
496
- const newListeners: CustomListenersMap = new Map()
497
- ctxToListenersMap.set(ownerPath, newListeners)
498
-
499
- function acceptDeps(deps: string[], callback: HotCallback['fn'] = () => {}) {
500
- const mod: HotModule = hotModulesMap.get(ownerPath) || {
501
- id: ownerPath,
502
- callbacks: []
503
- }
504
- mod.callbacks.push({
505
- deps,
506
- fn: callback
507
- })
508
- hotModulesMap.set(ownerPath, mod)
509
- }
510
-
511
- const hot: ViteHotContext = {
512
- get data() {
513
- return dataMap.get(ownerPath)
514
- },
515
-
516
- accept(deps?: any, callback?: any) {
517
- if (typeof deps === 'function' || !deps) {
518
- // self-accept: hot.accept(() => {})
519
- acceptDeps([ownerPath], ([mod]) => deps && deps(mod))
520
- } else if (typeof deps === 'string') {
521
- // explicit deps
522
- acceptDeps([deps], ([mod]) => callback && callback(mod))
523
- } else if (Array.isArray(deps)) {
524
- acceptDeps(deps, callback)
525
- } else {
526
- throw new Error(`invalid hot.accept() usage.`)
527
- }
528
- },
529
-
530
- // export names (first arg) are irrelevant on the client side, they're
531
- // extracted in the server for propagation
532
- acceptExports(_: string | readonly string[], callback?: any) {
533
- acceptDeps([ownerPath], callback && (([mod]) => callback(mod)))
534
- },
535
-
536
- dispose(cb) {
537
- disposeMap.set(ownerPath, cb)
538
- },
539
-
540
- // @ts-expect-error untyped
541
- prune(cb: (data: any) => void) {
542
- pruneMap.set(ownerPath, cb)
543
- },
544
-
545
- // TODO
546
- // eslint-disable-next-line @typescript-eslint/no-empty-function
547
- decline() {},
548
-
549
- // tell the server to re-perform hmr propagation from this module as root
550
- invalidate() {
551
- notifyListeners('vite:invalidate', { path: ownerPath })
552
- this.send('vite:invalidate', { path: ownerPath })
553
- },
554
-
555
- // custom events
556
- on(event, cb) {
557
- const addToMap = (map: Map<string, any[]>) => {
558
- const existing = map.get(event) || []
559
- existing.push(cb)
560
- map.set(event, existing)
561
- }
562
- addToMap(customListenersMap)
563
- addToMap(newListeners)
564
- },
565
-
566
- send(event, data) {
567
- messageBuffer.push(JSON.stringify({ type: 'custom', event, data }))
568
- sendMessageBuffer()
569
- }
570
- }
571
-
572
- return hot
573
- }
574
-
575
- /**
576
- * urls here are dynamic import() urls that couldn't be statically analyzed
577
- */
578
- export function injectQuery(url: string, queryToInject: string): string {
579
- // skip urls that won't be handled by vite
580
- if (!url.startsWith('.') && !url.startsWith('/')) {
581
- return url
582
- }
583
-
584
- // can't use pathname from URL since it may be relative like ../
585
- const pathname = url.replace(/#.*$/, '').replace(/\?.*$/, '')
586
- const { search, hash } = new URL(url, 'http://vitejs.dev')
587
-
588
- return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ''}${
589
- hash || ''
590
- }`
591
- }
592
-
593
- export { ErrorOverlay }
package/src/client/env.ts DELETED
@@ -1,29 +0,0 @@
1
- declare const __MODE__: string
2
- declare const __DEFINES__: Record<string, any>
3
-
4
- const context = (() => {
5
- if (typeof globalThis !== 'undefined') {
6
- return globalThis
7
- } else if (typeof self !== 'undefined') {
8
- return self
9
- } else if (typeof window !== 'undefined') {
10
- return window
11
- } else {
12
- return Function('return this')()
13
- }
14
- })()
15
-
16
- // assign defines
17
- const defines = __DEFINES__
18
- Object.keys(defines).forEach((key) => {
19
- const segments = key.split('.')
20
- let target = context
21
- for (let i = 0; i < segments.length; i++) {
22
- const segment = segments[i]
23
- if (i === segments.length - 1) {
24
- target[segment] = defines[key]
25
- } else {
26
- target = target[segment] || (target[segment] = {})
27
- }
28
- }
29
- })
@@ -1,208 +0,0 @@
1
- import type { ErrorPayload } from 'types/hmrPayload'
2
-
3
- // set :host styles to make playwright detect the element as visible
4
- const template = /*html*/ `
5
- <style>
6
- :host {
7
- position: fixed;
8
- top: 0;
9
- left: 0;
10
- width: 100%;
11
- height: 100%;
12
- z-index: 99999;
13
- --monospace: 'SFMono-Regular', Consolas,
14
- 'Liberation Mono', Menlo, Courier, monospace;
15
- --red: #ff5555;
16
- --yellow: #e2aa53;
17
- --purple: #cfa4ff;
18
- --cyan: #2dd9da;
19
- --dim: #c9c9c9;
20
-
21
- --window-background: #181818;
22
- --window-color: #d8d8d8;
23
- }
24
-
25
- .backdrop {
26
- position: fixed;
27
- z-index: 99999;
28
- top: 0;
29
- left: 0;
30
- width: 100%;
31
- height: 100%;
32
- overflow-y: scroll;
33
- margin: 0;
34
- background: rgba(0, 0, 0, 0.66);
35
- }
36
-
37
- .window {
38
- font-family: var(--monospace);
39
- line-height: 1.5;
40
- width: 800px;
41
- color: var(--window-color);
42
- margin: 30px auto;
43
- padding: 25px 40px;
44
- position: relative;
45
- background: var(--window-background);
46
- border-radius: 6px 6px 8px 8px;
47
- box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
48
- overflow: hidden;
49
- border-top: 8px solid var(--red);
50
- direction: ltr;
51
- text-align: left;
52
- }
53
-
54
- pre {
55
- font-family: var(--monospace);
56
- font-size: 16px;
57
- margin-top: 0;
58
- margin-bottom: 1em;
59
- overflow-x: scroll;
60
- scrollbar-width: none;
61
- }
62
-
63
- pre::-webkit-scrollbar {
64
- display: none;
65
- }
66
-
67
- .message {
68
- line-height: 1.3;
69
- font-weight: 600;
70
- white-space: pre-wrap;
71
- }
72
-
73
- .message-body {
74
- color: var(--red);
75
- }
76
-
77
- .plugin {
78
- color: var(--purple);
79
- }
80
-
81
- .file {
82
- color: var(--cyan);
83
- margin-bottom: 0;
84
- white-space: pre-wrap;
85
- word-break: break-all;
86
- }
87
-
88
- .frame {
89
- color: var(--yellow);
90
- }
91
-
92
- .stack {
93
- font-size: 13px;
94
- color: var(--dim);
95
- }
96
-
97
- .tip {
98
- font-size: 13px;
99
- color: #999;
100
- border-top: 1px dotted #999;
101
- padding-top: 13px;
102
- }
103
-
104
- code {
105
- font-size: 13px;
106
- font-family: var(--monospace);
107
- color: var(--yellow);
108
- }
109
-
110
- .file-link {
111
- text-decoration: underline;
112
- cursor: pointer;
113
- }
114
- </style>
115
- <div class="backdrop" part="backdrop">
116
- <div class="window" part="window">
117
- <pre class="message" part="message"><span class="plugin"></span><span class="message-body"></span></pre>
118
- <pre class="file" part="file"></pre>
119
- <pre class="frame" part="frame"></pre>
120
- <pre class="stack" part="stack"></pre>
121
- <div class="tip" part="tip">
122
- Click outside or fix the code to dismiss.<br>
123
- You can also disable this overlay by setting
124
- <code>server.hmr.overlay</code> to <code>false</code> in <code>vite.config.js.</code>
125
- </div>
126
- </div>
127
- </div>
128
- `
129
-
130
- const fileRE = /(?:[a-zA-Z]:\\|\/).*?:\d+:\d+/g
131
- const codeframeRE = /^(?:>?\s+\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm
132
-
133
- // Allow `ErrorOverlay` to extend `HTMLElement` even in environments where
134
- // `HTMLElement` was not originally defined.
135
- const { HTMLElement = class {} as typeof globalThis.HTMLElement } = globalThis
136
- export class ErrorOverlay extends HTMLElement {
137
- root: ShadowRoot
138
-
139
- constructor(err: ErrorPayload['err'], links = true) {
140
- super()
141
- this.root = this.attachShadow({ mode: 'open' })
142
- this.root.innerHTML = template
143
-
144
- codeframeRE.lastIndex = 0
145
- const hasFrame = err.frame && codeframeRE.test(err.frame)
146
- const message = hasFrame
147
- ? err.message.replace(codeframeRE, '')
148
- : err.message
149
- if (err.plugin) {
150
- this.text('.plugin', `[plugin:${err.plugin}] `)
151
- }
152
- this.text('.message-body', message.trim())
153
-
154
- const [file] = (err.loc?.file || err.id || 'unknown file').split(`?`)
155
- if (err.loc) {
156
- this.text('.file', `${file}:${err.loc.line}:${err.loc.column}`, links)
157
- } else if (err.id) {
158
- this.text('.file', file)
159
- }
160
-
161
- if (hasFrame) {
162
- this.text('.frame', err.frame!.trim())
163
- }
164
- this.text('.stack', err.stack, links)
165
-
166
- this.root.querySelector('.window')!.addEventListener('click', (e) => {
167
- e.stopPropagation()
168
- })
169
- this.addEventListener('click', () => {
170
- this.close()
171
- })
172
- }
173
-
174
- text(selector: string, text: string, linkFiles = false): void {
175
- const el = this.root.querySelector(selector)!
176
- if (!linkFiles) {
177
- el.textContent = text
178
- } else {
179
- let curIndex = 0
180
- let match: RegExpExecArray | null
181
- while ((match = fileRE.exec(text))) {
182
- const { 0: file, index } = match
183
- if (index != null) {
184
- const frag = text.slice(curIndex, index)
185
- el.appendChild(document.createTextNode(frag))
186
- const link = document.createElement('a')
187
- link.textContent = file
188
- link.className = 'file-link'
189
- link.onclick = () => {
190
- fetch('/__open-in-editor?file=' + encodeURIComponent(file))
191
- }
192
- el.appendChild(link)
193
- curIndex += frag.length + file.length
194
- }
195
- }
196
- }
197
- }
198
-
199
- close(): void {
200
- this.parentNode?.removeChild(this)
201
- }
202
- }
203
-
204
- export const overlayId = 'vite-error-overlay'
205
- const { customElements } = globalThis // Ensure `customElements` is defined before the next line.
206
- if (customElements && !customElements.get(overlayId)) {
207
- customElements.define(overlayId, ErrorOverlay)
208
- }
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "include": ["./", "../types"],
4
- "compilerOptions": {
5
- "types": [],
6
- "target": "ES2019",
7
- "lib": ["ESNext", "DOM"],
8
- "declaration": false
9
- }
10
- }