vite 2.9.12 → 3.0.0-alpha.10

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.
package/index.cjs ADDED
@@ -0,0 +1,33 @@
1
+ /* eslint-disable no-restricted-globals */
2
+
3
+ // type utils
4
+ module.exports.defineConfig = (config) => config
5
+
6
+ // proxy cjs utils (sync functions)
7
+ Object.assign(module.exports, require('./dist/node-cjs/publicUtils.cjs'))
8
+
9
+ // async functions, can be redirect from ESM build
10
+ const asyncFunctions = [
11
+ 'build',
12
+ 'createServer',
13
+ 'preview',
14
+ 'transformWithEsbuild',
15
+ 'resolveConfig',
16
+ 'optimizeDeps',
17
+ 'formatPostcssSourceMap',
18
+ 'loadConfigFromFile'
19
+ ]
20
+ asyncFunctions.forEach((name) => {
21
+ module.exports[name] = (...args) =>
22
+ import('./dist/node/index.js').then((i) => i[name](...args))
23
+ })
24
+
25
+ // some sync functions are marked not supported due to their complexity and uncommon usage
26
+ const unsupportedCJS = ['resolvePackageEntry', 'resolvePackageData']
27
+ unsupportedCJS.forEach((name) => {
28
+ module.exports[name] = () => {
29
+ throw new Error(
30
+ `"${name}" is not supported in CJS build of Vite 3.\nPlease use ESM or dynamic imports \`const { ${name} } = await import('vite')\`.`
31
+ )
32
+ }
33
+ })
package/package.json CHANGED
@@ -1,23 +1,37 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "2.9.12",
3
+ "version": "3.0.0-alpha.10",
4
+ "type": "module",
4
5
  "license": "MIT",
5
6
  "author": "Evan You",
6
7
  "description": "Native-ESM powered web dev build tool",
7
8
  "bin": {
8
9
  "vite": "bin/vite.js"
9
10
  },
10
- "main": "dist/node/index.js",
11
- "types": "dist/node/index.d.ts",
11
+ "main": "./dist/node/index.js",
12
+ "module": "./dist/node/index.js",
13
+ "types": "./dist/node/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/node/index.d.ts",
17
+ "import": "./dist/node/index.js",
18
+ "require": "./index.cjs"
19
+ },
20
+ "./client": {
21
+ "types": "./client.d.ts"
22
+ },
23
+ "./dist/client/*": "./dist/client/*"
24
+ },
12
25
  "files": [
13
26
  "bin",
14
27
  "dist",
15
28
  "client.d.ts",
29
+ "index.cjs",
16
30
  "src/client",
17
31
  "types"
18
32
  ],
19
33
  "engines": {
20
- "node": ">=12.2.0"
34
+ "node": ">=14.6.0"
21
35
  },
22
36
  "repository": {
23
37
  "type": "git",
@@ -29,54 +43,41 @@
29
43
  },
30
44
  "homepage": "https://github.com/vitejs/vite/tree/main/#readme",
31
45
  "scripts": {
32
- "dev": "rimraf dist && rollup -c -w",
33
- "build": "rimraf dist && npm run lint && run-s build-bundle build-types",
34
- "build-bundle": "rollup -c",
35
- "build-types": "run-s build-temp-types patch-types roll-types",
46
+ "dev": "rimraf dist && pnpm run build-bundle -w",
47
+ "build": "rimraf dist && run-s build-bundle build-types",
48
+ "build-bundle": "rollup --config rollup.config.ts --configPlugin typescript",
49
+ "build-types": "run-s build-temp-types patch-types roll-types check-dist-types",
36
50
  "build-temp-types": "tsc --emitDeclarationOnly --outDir temp/node -p src/node",
37
- "ci-build": "rimraf dist && run-s build-bundle build-types",
38
- "patch-types": "ts-node scripts/patchTypes.ts",
51
+ "patch-types": "esno scripts/patchTypes.ts",
39
52
  "roll-types": "api-extractor run && rimraf temp",
53
+ "check-dist-types": "tsc --project tsconfig.check.json",
40
54
  "lint": "eslint --ext .ts src/**",
41
55
  "format": "prettier --write --parser typescript \"src/**/*.ts\"",
42
56
  "prepublishOnly": "npm run build"
43
57
  },
44
58
  "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
45
59
  "dependencies": {
46
- "esbuild": "^0.14.27",
47
- "postcss": "^8.4.13",
60
+ "esbuild": "^0.14.38",
61
+ "postcss": "^8.4.14",
48
62
  "resolve": "^1.22.0",
49
- "rollup": "^2.59.0"
63
+ "rollup": "^2.72.1"
50
64
  },
51
65
  "optionalDependencies": {
52
66
  "fsevents": "~2.3.2"
53
67
  },
54
68
  "devDependencies": {
55
69
  "@ampproject/remapping": "^2.2.0",
56
- "@babel/parser": "^7.17.10",
57
- "@babel/types": "^7.17.10",
58
- "@jridgewell/trace-mapping": "^0.3.9",
70
+ "@babel/parser": "^7.18.4",
71
+ "@babel/types": "^7.18.4",
72
+ "@jridgewell/trace-mapping": "^0.3.13",
59
73
  "@rollup/plugin-alias": "^3.1.9",
60
74
  "@rollup/plugin-commonjs": "^21.1.0",
61
75
  "@rollup/plugin-dynamic-import-vars": "^1.4.3",
62
76
  "@rollup/plugin-json": "^4.1.0",
63
- "@rollup/plugin-node-resolve": "13.2.1",
77
+ "@rollup/plugin-node-resolve": "13.3.0",
64
78
  "@rollup/plugin-typescript": "^8.3.2",
65
79
  "@rollup/pluginutils": "^4.2.1",
66
- "@types/convert-source-map": "^1.5.2",
67
- "@types/cross-spawn": "^6.0.2",
68
- "@types/debug": "^4.1.7",
69
- "@types/estree": "^0.0.51",
70
- "@types/etag": "^1.8.1",
71
- "@types/less": "^3.0.3",
72
- "@types/micromatch": "^4.0.2",
73
- "@types/mime": "^2.0.3",
74
- "@types/node": "^17.0.25",
75
- "@types/resolve": "^1.20.2",
76
- "@types/sass": "~1.43.1",
77
- "@types/stylus": "^0.48.37",
78
- "@types/ws": "^8.5.3",
79
- "@vue/compiler-dom": "^3.2.33",
80
+ "@vue/compiler-dom": "^3.2.37",
80
81
  "acorn": "^8.7.1",
81
82
  "cac": "6.7.9",
82
83
  "chokidar": "^3.5.3",
@@ -89,13 +90,14 @@
89
90
  "dotenv": "^14.3.2",
90
91
  "dotenv-expand": "^5.1.0",
91
92
  "es-module-lexer": "^0.10.5",
93
+ "esno": "^0.16.3",
92
94
  "estree-walker": "^2.0.2",
93
95
  "etag": "^1.8.1",
94
96
  "fast-glob": "^3.2.11",
95
97
  "http-proxy": "^1.18.1",
96
98
  "json5": "^2.2.1",
97
- "launch-editor-middleware": "^2.3.0",
98
- "magic-string": "^0.26.1",
99
+ "launch-editor-middleware": "^2.4.0",
100
+ "magic-string": "^0.26.2",
99
101
  "micromatch": "^4.0.5",
100
102
  "mrmime": "^1.0.0",
101
103
  "node-forge": "^1.3.1",
@@ -107,22 +109,23 @@
107
109
  "postcss-load-config": "^3.1.4",
108
110
  "postcss-modules": "^4.3.1",
109
111
  "resolve.exports": "^1.1.0",
110
- "rollup-plugin-license": "^2.7.0",
112
+ "rollup-plugin-license": "^2.8.0",
111
113
  "sirv": "^2.0.2",
112
114
  "source-map-js": "^1.0.2",
113
115
  "source-map-support": "^0.5.21",
114
116
  "strip-ansi": "^6.0.1",
115
- "strip-literal": "^0.2.0",
116
- "terser": "^5.13.1",
117
- "tsconfck": "^1.2.2",
117
+ "strip-literal": "^0.3.0",
118
+ "tsconfck": "^2.0.1",
118
119
  "tslib": "^2.4.0",
119
120
  "types": "link:./types",
120
- "ws": "^8.6.0"
121
+ "ufo": "^0.8.4",
122
+ "ws": "^8.7.0"
121
123
  },
122
124
  "peerDependencies": {
123
125
  "less": "*",
124
126
  "sass": "*",
125
- "stylus": "*"
127
+ "stylus": "*",
128
+ "terser": "^5.4.0"
126
129
  },
127
130
  "peerDependenciesMeta": {
128
131
  "sass": {
@@ -133,6 +136,9 @@
133
136
  },
134
137
  "less": {
135
138
  "optional": true
139
+ },
140
+ "terser": {
141
+ "optional": true
136
142
  }
137
143
  }
138
144
  }
@@ -13,16 +13,35 @@ declare const __HMR_PORT__: string
13
13
  declare const __HMR_TIMEOUT__: number
14
14
  declare const __HMR_ENABLE_OVERLAY__: boolean
15
15
 
16
- console.log('[vite] connecting...')
16
+ console.debug('[vite] connecting...')
17
17
 
18
18
  // use server configuration, then fallback to inference
19
19
  const socketProtocol =
20
20
  __HMR_PROTOCOL__ || (location.protocol === 'https:' ? 'wss' : 'ws')
21
21
  const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`
22
- const socket = new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr')
23
22
  const base = __BASE__ || '/'
24
23
  const messageBuffer: string[] = []
25
24
 
25
+ let socket: WebSocket
26
+ try {
27
+ socket = new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr')
28
+
29
+ // Listen for messages
30
+ socket.addEventListener('message', async ({ data }) => {
31
+ handleMessage(JSON.parse(data))
32
+ })
33
+
34
+ // ping server
35
+ socket.addEventListener('close', async ({ wasClean }) => {
36
+ if (wasClean) return
37
+ console.log(`[vite] server connection lost. polling for restart...`)
38
+ await waitForSuccessfulPing()
39
+ location.reload()
40
+ })
41
+ } catch (error) {
42
+ console.error(`[vite] failed to connect to websocket (${error}). `)
43
+ }
44
+
26
45
  function warnFailedFetch(err: Error, path: string | string[]) {
27
46
  if (!err.message.match('fetch')) {
28
47
  console.error(err)
@@ -40,17 +59,12 @@ function cleanUrl(pathname: string): string {
40
59
  return url.pathname + url.search
41
60
  }
42
61
 
43
- // Listen for messages
44
- socket.addEventListener('message', async ({ data }) => {
45
- handleMessage(JSON.parse(data))
46
- })
47
-
48
62
  let isFirstUpdate = true
49
63
 
50
64
  async function handleMessage(payload: HMRPayload) {
51
65
  switch (payload.type) {
52
66
  case 'connected':
53
- console.log(`[vite] connected.`)
67
+ console.debug(`[vite] connected.`)
54
68
  sendMessageBuffer()
55
69
  // proxy(nginx, docker) hmr ws maybe caused timeout,
56
70
  // so send ping package let ws keep alive.
@@ -117,6 +131,7 @@ async function handleMessage(payload: HMRPayload) {
117
131
  const payloadPath = base + payload.path.slice(1)
118
132
  if (
119
133
  pagePath === payloadPath ||
134
+ payload.path === '/index.html' ||
120
135
  (pagePath.endsWith('/') && pagePath + 'index.html' === payloadPath)
121
136
  ) {
122
137
  location.reload()
@@ -211,12 +226,10 @@ async function waitForSuccessfulPing(ms = 1000) {
211
226
  // eslint-disable-next-line no-constant-condition
212
227
  while (true) {
213
228
  try {
214
- const pingResponse = await fetch(`${base}__vite_ping`)
215
-
216
- // success - 2xx status code
217
- if (pingResponse.ok) break
218
- // failure - non-2xx status code
219
- else throw new Error()
229
+ // A fetch on a websocket URL will return a successful promise with status 400,
230
+ // but will reject a networking error.
231
+ await fetch(`${location.protocol}//${socketHost}`)
232
+ break
220
233
  } catch (e) {
221
234
  // wait ms before attempting to ping again
222
235
  await new Promise((resolve) => setTimeout(resolve, ms))
@@ -224,14 +237,6 @@ async function waitForSuccessfulPing(ms = 1000) {
224
237
  }
225
238
  }
226
239
 
227
- // ping server
228
- socket.addEventListener('close', async ({ wasClean }) => {
229
- if (wasClean) return
230
- console.log(`[vite] server connection lost. polling for restart...`)
231
- await waitForSuccessfulPing()
232
- location.reload()
233
- })
234
-
235
240
  // https://wicg.github.io/construct-stylesheets
236
241
  const supportsConstructedSheet = (() => {
237
242
  // TODO: re-enable this try block once Chrome fixes the performance of
@@ -443,13 +448,6 @@ export function createHotContext(ownerPath: string): ViteHotContext {
443
448
  }
444
449
  },
445
450
 
446
- acceptDeps() {
447
- throw new Error(
448
- `hot.acceptDeps() is deprecated. ` +
449
- `Use hot.accept() with the same signature instead.`
450
- )
451
- },
452
-
453
451
  dispose(cb) {
454
452
  disposeMap.set(ownerPath, cb)
455
453
  },
@@ -3,7 +3,7 @@
3
3
  "include": ["./", "../../types"],
4
4
  "compilerOptions": {
5
5
  "outDir": "../../dist/client",
6
- "module": "esnext",
6
+ "module": "ESNext",
7
7
  "types": [],
8
8
  "lib": ["ESNext", "DOM"],
9
9
  "declaration": false
@@ -140,8 +140,10 @@ export interface WatchOptions {
140
140
  cwd?: string
141
141
 
142
142
  /**
143
- * If set to true then the strings passed to .watch() and .add() are treated as literal path
144
- * names, even if they look like globs. Default: false.
143
+ * If set to true then the strings passed to .watch() and .add() are treated as literal path
144
+ * names, even if they look like globs.
145
+ *
146
+ * @default false
145
147
  */
146
148
  disableGlobbing?: boolean
147
149
 
package/types/hot.d.ts CHANGED
@@ -7,12 +7,6 @@ export interface ViteHotContext {
7
7
  accept(cb: (mod: any) => void): void
8
8
  accept(dep: string, cb: (mod: any) => void): void
9
9
  accept(deps: readonly string[], cb: (mods: any[]) => void): void
10
-
11
- /**
12
- * @deprecated
13
- */
14
- acceptDeps(): never
15
-
16
10
  dispose(cb: (data: any) => void): void
17
11
  decline(): void
18
12
  invalidate(): void
@@ -0,0 +1,87 @@
1
+ export interface ImportGlobOptions<
2
+ Eager extends boolean,
3
+ AsType extends string
4
+ > {
5
+ /**
6
+ * Import type for the import url.
7
+ */
8
+ as?: AsType
9
+ /**
10
+ * Import as static or dynamic
11
+ *
12
+ * @default false
13
+ */
14
+ eager?: Eager
15
+ /**
16
+ * Import only the specific named export. Set to `default` to import the default export.
17
+ */
18
+ import?: string
19
+ /**
20
+ * Custom queries
21
+ */
22
+ query?: string | Record<string, string | number | boolean>
23
+ /**
24
+ * Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
25
+ *
26
+ * @default false
27
+ */
28
+ exhaustive?: boolean
29
+ }
30
+
31
+ export type GeneralImportGlobOptions = ImportGlobOptions<boolean, string>
32
+
33
+ export interface KnownAsTypeMap {
34
+ raw: string
35
+ url: string
36
+ worker: Worker
37
+ }
38
+
39
+ export interface ImportGlobFunction {
40
+ /**
41
+ * 1. No generic provided, infer the type from `eager` and `as`
42
+ */
43
+ <
44
+ Eager extends boolean,
45
+ As extends string,
46
+ T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown
47
+ >(
48
+ glob: string | string[],
49
+ options?: ImportGlobOptions<Eager, As>
50
+ ): (Eager extends true ? true : false) extends true
51
+ ? Record<string, T>
52
+ : Record<string, () => Promise<T>>
53
+ /**
54
+ * 2. Module generic provided, infer the type from `eager: false`
55
+ */
56
+ <M>(
57
+ glob: string | string[],
58
+ options?: ImportGlobOptions<false, string>
59
+ ): Record<string, () => Promise<M>>
60
+ /**
61
+ * 3. Module generic provided, infer the type from `eager: true`
62
+ */
63
+ <M>(
64
+ glob: string | string[],
65
+ options: ImportGlobOptions<true, string>
66
+ ): Record<string, M>
67
+ }
68
+
69
+ export interface ImportGlobEagerFunction {
70
+ /**
71
+ * 1. No generic provided, infer the type from `as`
72
+ */
73
+ <
74
+ As extends string,
75
+ T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown
76
+ >(
77
+ glob: string | string[],
78
+ options?: Omit<ImportGlobOptions<boolean, As>, 'eager'>
79
+ ): Record<string, T>
80
+ /**
81
+ * 2. Module generic provided
82
+ */
83
+ <M>(
84
+ glob: string | string[],
85
+ options?: Omit<ImportGlobOptions<boolean, string>, 'eager'>
86
+ ): Record<string, M>
87
+ }
@@ -9,12 +9,6 @@
9
9
  // in vite/client.d.ts and in production src/node/importGlob.ts doesn't exist.
10
10
  interface GlobOptions {
11
11
  as?: string
12
- /**
13
- * @deprecated
14
- */
15
- assert?: {
16
- type: string
17
- }
18
12
  }
19
13
 
20
14
  interface ImportMeta {
@@ -24,15 +18,11 @@ interface ImportMeta {
24
18
 
25
19
  readonly env: ImportMetaEnv
26
20
 
27
- glob<Module = { [key: string]: any }>(
28
- pattern: string,
29
- options?: GlobOptions
30
- ): Record<string, () => Promise<Module>>
31
-
32
- globEager<Module = { [key: string]: any }>(
33
- pattern: string,
34
- options?: GlobOptions
35
- ): Record<string, Module>
21
+ glob: import('./importGlob').ImportGlobFunction
22
+ /**
23
+ * @deprecated Use `import.meta.glob('*', { eager: true })` instead
24
+ */
25
+ globEager: import('./importGlob').ImportGlobEagerFunction
36
26
  }
37
27
 
38
28
  interface ImportMetaEnv {
package/types/shims.d.ts CHANGED
@@ -59,6 +59,7 @@ declare module 'postcss-modules' {
59
59
 
60
60
  declare module '@rollup/plugin-dynamic-import-vars' {
61
61
  import type { Plugin } from 'rollup'
62
+ import type { BaseNode } from 'estree'
62
63
 
63
64
  interface Options {
64
65
  include?: string | RegExp | (string | RegExp)[]
@@ -68,6 +69,10 @@ declare module '@rollup/plugin-dynamic-import-vars' {
68
69
 
69
70
  const p: (o?: Options) => Plugin
70
71
  export default p
72
+ export function dynamicImportToGlob(
73
+ ast: BaseNode,
74
+ source: string
75
+ ): null | string
71
76
  }
72
77
 
73
78
  declare module 'rollup-plugin-web-worker-loader' {
@@ -85,14 +90,6 @@ declare module 'rollup-plugin-web-worker-loader' {
85
90
  export default p
86
91
  }
87
92
 
88
- declare module 'micromatch' {
89
- export function isMatch(
90
- path: string,
91
- pattern: string,
92
- options?: { matchBase?: boolean }
93
- ): boolean
94
- }
95
-
96
93
  // LESS' types somewhat references this which doesn't make sense in Node,
97
94
  // so we have to shim it
98
95
  declare interface HTMLLinkElement {}
package/types/terser.d.ts CHANGED
@@ -185,8 +185,6 @@ export namespace Terser {
185
185
  module?: boolean
186
186
  nameCache?: object
187
187
  format?: FormatOptions
188
- /** @deprecated use format instead */
189
- output?: FormatOptions
190
188
  parse?: ParseOptions
191
189
  safari10?: boolean
192
190
  sourceMap?: boolean | SourceMapOptions